revised vl53l0x XSHUT, GPIO setting for max 3 TOF sensors

This commit is contained in:
Yunhorn 2023-07-13 14:11:56 +08:00
parent 02ba2481c7
commit 1c393d1043
6 changed files with 131 additions and 80 deletions

View File

@ -96,10 +96,21 @@ void MX_TOF_Init(void);
#define TOF_C_INT_Pin GPIO_PIN_10 #define TOF_C_INT_Pin GPIO_PIN_10
#define TOF_C_INT_GPIO_Port GPIOA #define TOF_C_INT_GPIO_Port GPIOA
#define TOF_C_INT_EXTI_IRQn EXTI15_10_IRQn #define TOF_C_INT_EXTI_IRQn EXTI15_10_IRQn
#define TOF_C_XSHUT_Pin GPIO_PIN_3 #define TOF_C_XSHUT_Pin GPIO_PIN_3
#define TOF_C_XSHUT_GPIO_Port GPIOB #define TOF_C_XSHUT_GPIO_Port GPIOB
#define TOF_L_INT_Pin GPIO_PIN_7
#define TOF_L_INT_GPIO_Port GPIOC
#define TOF_L_INT_EXTI_IRQn EXTI9_5_IRQn
#define TOF_L_XSHUT_Pin GPIO_PIN_10
#define TOF_L_XSHUT_GPIO_Port GPIOB
#define TOF_R_INT_Pin GPIO_PIN_10
#define TOF_R_INT_GPIO_Port GPIOA
#define TOF_R_INT_EXTI_IRQn EXTI15_10_IRQn
#define TOF_R_XSHUT_Pin GPIO_PIN_5
#define TOF_R_XSHUT_GPIO_Port GPIOB
#define STS_SERVICE_MASK_L0 (0) // Service normal , no mask off #define STS_SERVICE_MASK_L0 (0) // Service normal , no mask off
#define STS_SERVICE_MASK_L1 (1) // service mask level 1, sensing data upload in silence mode, node appearance silence (no LED, No display, no sound, no vibration) #define STS_SERVICE_MASK_L1 (1) // service mask level 1, sensing data upload in silence mode, node appearance silence (no LED, No display, no sound, no vibration)
#define STS_SERVICE_MASK_L2 (2) // service mask level 2, NO sensing data upload (event or periodicity) #define STS_SERVICE_MASK_L2 (2) // service mask level 2, NO sensing data upload (event or periodicity)

View File

@ -93,11 +93,21 @@ void MX_GPIO_Init(void)
HAL_GPIO_Init(BUT1_GPIO_Port, &GPIO_InitStruct); HAL_GPIO_Init(BUT1_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : TOF_C_INT_Pin TOF_R_INT_Pin */ /*Configure GPIO pins : TOF_C_INT_Pin */
GPIO_InitStruct.Pin = TOF_C_INT_Pin; GPIO_InitStruct.Pin = TOF_C_INT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(TOF_C_INT_GPIO_Port, &GPIO_InitStruct); HAL_GPIO_Init(TOF_C_INT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : TOF_L_INT_Pin */
GPIO_InitStruct.Pin = TOF_L_INT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(TOF_L_INT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : TOF_R_INT_Pin */
GPIO_InitStruct.Pin = TOF_R_INT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(TOF_R_INT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : TOF_C_XSHUT_Pin */ /*Configure GPIO pins : TOF_C_XSHUT_Pin */
GPIO_InitStruct.Pin = TOF_C_XSHUT_Pin; GPIO_InitStruct.Pin = TOF_C_XSHUT_Pin;
@ -105,6 +115,19 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(TOF_C_XSHUT_GPIO_Port, &GPIO_InitStruct); HAL_GPIO_Init(TOF_C_XSHUT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : TOF_L_XSHUT_Pin */
GPIO_InitStruct.Pin = TOF_L_XSHUT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(TOF_L_XSHUT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : TOF_R_XSHUT_Pin */
GPIO_InitStruct.Pin = TOF_R_XSHUT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(TOF_R_XSHUT_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/ /* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
@ -115,7 +138,10 @@ void MX_GPIO_Init(void)
HAL_NVIC_SetPriority(TOF_C_INT_EXTI_IRQn, 0, 0); HAL_NVIC_SetPriority(TOF_C_INT_EXTI_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TOF_C_INT_EXTI_IRQn); HAL_NVIC_EnableIRQ(TOF_C_INT_EXTI_IRQn);
HAL_NVIC_SetPriority(TOF_L_INT_EXTI_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TOF_L_INT_EXTI_IRQn);
HAL_NVIC_SetPriority(TOF_R_INT_EXTI_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TOF_R_INT_EXTI_IRQn);
} }
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */

View File

@ -270,7 +270,7 @@ void STS_YunhornSTSEventP3_Process(void)
void STS_YunhornSTSEventP4_Process(void) void STS_YunhornSTSEventP4_Process(void)
{ {
STS_SENSOR_Power_ON(0); STS_SENSOR_Power_ON(0);
STS_SENSOR_Power_OFF(0);
APP_LOG(TS_OFF, VLEVEL_L, "\r\n P4 Testing Process\r\n"); APP_LOG(TS_OFF, VLEVEL_L, "\r\n P4 Testing Process\r\n");
STS_TOF_VL53L0X_Range_Process(); STS_TOF_VL53L0X_Range_Process();
@ -452,7 +452,7 @@ void STS_SENSOR_Power_ON(uint8_t cnt)
#if (defined(YUNHORN_STS_M7_ENABLED) || defined(YUNHORN_STS_R0_ENABLED)) #if (defined(YUNHORN_STS_M7_ENABLED) || defined(YUNHORN_STS_R0_ENABLED))
HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET);
#endif #endif
HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET);
break; break;
default: default:
@ -469,7 +469,7 @@ void STS_SENSOR_Power_OFF(uint8_t cnt)
#if (defined(YUNHORN_STS_M7_ENABLED) || defined(YUNHORN_STS_R0_ENABLED)) #if (defined(YUNHORN_STS_M7_ENABLED) || defined(YUNHORN_STS_R0_ENABLED))
HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET);
#endif #endif
HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET);
break; break;
default: default:
break; break;

View File

@ -196,13 +196,23 @@ int XWL55_WLE5_53L0X_Init(void)
} }
void XWL55_WLE5_53L0X_Reset(void) void XWL55_WLE5_53L0X_ResetId(uint8_t DevNo, int state)
{ {
HAL_GPIO_WritePin(TOF_C_XSHUT_GPIO_Port, TOF_C_XSHUT_Pin, GPIO_PIN_RESET); switch(DevNo) {
HAL_Delay(30); case XNUCLEO53L0X_LEFT:
HAL_GPIO_WritePin(TOF_C_XSHUT_GPIO_Port, TOF_C_XSHUT_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(TOF_L_XSHUT_GPIO_Port, TOF_L_XSHUT_Pin, ((state == 1)?GPIO_PIN_SET:GPIO_PIN_RESET));
HAL_Delay(30); break;
case XNUCLEO53L0X_CENTER:
HAL_GPIO_WritePin(TOF_C_XSHUT_GPIO_Port, TOF_C_XSHUT_Pin, ((state == 1)?GPIO_PIN_SET:GPIO_PIN_RESET)); break;
case XNUCLEO53L0X_RIGHT:
HAL_GPIO_WritePin(TOF_R_XSHUT_GPIO_Port, TOF_R_XSHUT_Pin, ((state == 1)?GPIO_PIN_SET:GPIO_PIN_RESET)); break;
default:
break;
}
} }

View File

@ -228,10 +228,8 @@ int XWL55_WLE5_53L0X_Init(void);
* @param state State of the device reset (xsdn) pin @warning reset pin is active low * @param state State of the device reset (xsdn) pin @warning reset pin is active low
* @return 0 on success * @return 0 on success
*/ */
int XNUCLEO53L1A1_ResetId(int DevNo, int state );
void XWL55_WLE5_53L0X_ResetId(uint8_t DevNo, int state);
void XWL55_WLE5_53L0X_Reset(void);
/** /**
* Enable Disable interrupt at MCU level (MSP) * Enable Disable interrupt at MCU level (MSP)
@ -254,6 +252,7 @@ void XWL55_WLE5_53L0X_Reset(void);
* >0 interrupt configured but with potential sharing on EXTI groups see @ref VL53L0X_GPIO1_MAP * >0 interrupt configured but with potential sharing on EXTI groups see @ref VL53L0X_GPIO1_MAP
*/ */
int XNUCLEO53L1A1_SetIntrStateId(int EnableIntr, int DevNo); int XNUCLEO53L1A1_SetIntrStateId(int EnableIntr, int DevNo);
int XWL55_WLE5_53L0X_SetIntrStateId(int EnableIntr, int DevNo);
int sts_tof_vl53l0x_DetectSensors(void); int sts_tof_vl53l0x_DetectSensors(void);
#endif /* _X_WL55_WLE5_53L0X_H_ */ #endif /* _X_WL55_WLE5_53L0X_H_ */

View File

@ -131,19 +131,21 @@ int sts_tof_vl53l0x_DetectSensors(void)
int FinalAddress; int FinalAddress;
nDevPresent = 0; nDevPresent = 0;
XWL55_WLE5_53L0X_Reset(); for (i=0; i < MAX_TOF_COUNT; i++) {
//HAL_GPIO_WritePin(TOF_C_XSHUT_GPIO_Port, TOF_C_XSHUT_Pin, GPIO_PIN_SET); XWL55_WLE5_53L0X_ResetId(i,0);
//HAL_Delay(100); }
//XWL55_WLE5_53L0X_SetIntrStateId(0,0);
/* detect all sensors (even on-board)*/ /* detect all sensors (even on-board)*/
for (i=0; i < MAX_TOF_COUNT; i++) for (i=0; i < MAX_TOF_COUNT; i++)
{ {
VL53L0X_Dev_t *pDev; VL53L0X_Dev_t *pDev;
pDev = &VL53L0XDevs[i]; pDev = &VL53L0XDevs[i];
pDev->I2cDevAddr = 0x52;//+(i*2); pDev->I2cDevAddr = 0x52;
pDev->Present = 0; pDev->Present = 0;
//status = XNUCLEO53L0A1_ResetId(pDev->Id, 1); XWL55_WLE5_53L0X_ResetId(pDev->Id, 1);
//HAL_Delay(2); HAL_Delay(2);
FinalAddress = 0x52+(i+1)*2; FinalAddress = 0x52+(i+1)*2;
APP_LOG(TS_OFF, VLEVEL_L, "\r\n Detect TOF sensors #%u with I2CDevAddr=0x%02x \r\n", i, pDev->I2cDevAddr); APP_LOG(TS_OFF, VLEVEL_L, "\r\n Detect TOF sensors #%u with I2CDevAddr=0x%02x \r\n", i, pDev->I2cDevAddr);
@ -192,6 +194,9 @@ int sts_tof_vl53l0x_DetectSensors(void)
} }
} while(0); } while(0);
/* Display detected sensor(s) */ /* Display detected sensor(s) */
if (status) {
XWL55_WLE5_53L0X_ResetId(i,0);
}
} }
return nDevPresent; return nDevPresent;