wip good shown range ---

This commit is contained in:
Yunhorn 2024-11-13 23:21:52 +08:00
parent 20e68b97d5
commit beb751c456
10 changed files with 40 additions and 66 deletions

View File

@ -211,17 +211,15 @@ void Error_Handler(void);
#endif // defined(VL53LX)||defined(VL53L0) #endif // defined(VL53LX)||defined(VL53L0)
/* VL53L8A1 for Power_En, LPn, Int */ /* VL53L8A1 for Power_En, LPn, Int */
/* for Yunhorn STS_RM1.3 Round PCB */
#ifdef L8 #ifdef L8
#define TOF_INT_EXTI_PIN (GPIO_PIN_10) //(GPIO_PIN_4) #define TOF_INT_EXTI_PIN (GPIO_PIN_15) //(GPIO_PIN_4)
#define TOF_INT_EXTI_PORT (GPIOA) //(GPIOA) #define TOF_INT_EXTI_PORT (GPIOA) //(GPIOA)
#define TOF_INT_EXTI_IRQn EXTI15_10_IRQn #define TOF_INT_EXTI_IRQn EXTI15_10_IRQn
#define VL53L8A1_PWR_EN_C_PIN (GPIO_PIN_4) //(GPIO_PIN_7)
#define VL53L8A1_PWR_EN_C_PIN (GPIO_PIN_7) //(GPIO_PIN_7) #define VL53L8A1_PWR_EN_C_PORT (GPIOB) //(GPIOA)
#define VL53L8A1_PWR_EN_C_PORT (GPIOA) //(GPIOA) #define VL53L8A1_LPn_C_PIN (GPIO_PIN_10) //(GPIO_PIN_0)
#define VL53L8A1_LPn_C_PORT (GPIOA) //(GPIOB)
#define VL53L8A1_LPn_C_PIN (GPIO_PIN_4) //(GPIO_PIN_0)
#define VL53L8A1_LPn_C_PORT (GPIOB) //(GPIOB)
#endif #endif
@ -232,9 +230,14 @@ void Error_Handler(void);
// FOR STM32WLE5CCU6 UFQFPN48 PA12 PA11 // FOR STM32WLE5CCU6 UFQFPN48 PA12 PA11
#ifdef STM32WLE5xx #ifdef STM32WLE5xx
#define I2C2_STANDARD_100K 0x00000E14 //#define I2C2_STANDARD_100K 0x00000E14
#define I2C2_FAST_400K 0x00000004 //#define I2C2_FAST_400K 0x00000004
#define I2C2_FAST_PLUS_1M 0x00000000 //#define I2C2_FAST_PLUS_1M 0x00000000
#define I2C2_STANDARD_100K 0x10805D88
#define I2C2_FAST_400K 0x0090194B
#define I2C2_FAST_PLUS_1M 0x00700814
#else #else
/* /*
* FOR STM32WLE5CCU6 UFQFPN48 PA12 PA11 * FOR STM32WLE5CCU6 UFQFPN48 PA12 PA11

View File

@ -80,8 +80,7 @@ void MX_DMA_Init(void)
//HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0); //HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0);
//HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); //HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
} }

View File

@ -124,9 +124,9 @@ int main(void)
while (1) while (1)
{ {
/* USER CODE END WHILE */ /* USER CODE END WHILE */
MX_LoRaWAN_Process();
//MX_TOF_Process(); //MX_TOF_Process();
MX_LoRaWAN_Process();
// MX_TOF_Ranging_Process(); // MX_TOF_Ranging_Process();
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */

View File

@ -400,7 +400,8 @@ __weak HAL_StatusTypeDef MX_I2C2_Init(I2C_HandleTypeDef* hi2c)
HAL_StatusTypeDef ret = HAL_OK; HAL_StatusTypeDef ret = HAL_OK;
hi2c->Instance = I2C2; hi2c->Instance = I2C2;
hi2c->Init.Timing = 0x20303E5D; //hi2c->Init.Timing = 0x20303E5D;
hi2c->Init.Timing = 0x0090194B; // 2024 NOV 13 10:20PM
hi2c->Init.OwnAddress1 = 0; hi2c->Init.OwnAddress1 = 0;
hi2c->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
@ -448,14 +449,14 @@ static void I2C2_MspInit(I2C_HandleTypeDef* i2cHandle)
GPIO_InitStruct.Pin = BUS_I2C2_SCL_GPIO_PIN; GPIO_InitStruct.Pin = BUS_I2C2_SCL_GPIO_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = BUS_I2C2_SCL_GPIO_AF; GPIO_InitStruct.Alternate = BUS_I2C2_SCL_GPIO_AF;
HAL_GPIO_Init(BUS_I2C2_SCL_GPIO_PORT, &GPIO_InitStruct); HAL_GPIO_Init(BUS_I2C2_SCL_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = BUS_I2C2_SDA_GPIO_PIN; GPIO_InitStruct.Pin = BUS_I2C2_SDA_GPIO_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = BUS_I2C2_SDA_GPIO_AF; GPIO_InitStruct.Alternate = BUS_I2C2_SDA_GPIO_AF;
HAL_GPIO_Init(BUS_I2C2_SDA_GPIO_PORT, &GPIO_InitStruct); HAL_GPIO_Init(BUS_I2C2_SDA_GPIO_PORT, &GPIO_InitStruct);

View File

@ -42,7 +42,7 @@ void MX_USART2_UART_Init(void)
/* USER CODE END USART2_Init 1 */ /* USER CODE END USART2_Init 1 */
huart2.Instance = USART2; huart2.Instance = USART2;
#ifdef L8 #ifdef L8
huart2.Init.BaudRate = 460800; huart2.Init.BaudRate = 921600;
#else #else
huart2.Init.BaudRate = 115200; huart2.Init.BaudRate = 115200;
#endif #endif

View File

@ -560,17 +560,21 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
} }
break; break;
#ifndef STS_R4 #ifndef STS_R4
case BUT2_Pin: case BUT2_Pin:
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), CFG_SEQ_Prio_0);
break; break;
#endif #endif
case BUT3_Pin: case BUT3_Pin:
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStoreContextEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStoreContextEvent), CFG_SEQ_Prio_0);
break; break;
#if (defined(VL53L0)||defined(VL53LX)||defined(L8)) #if (defined(VL53L0)||defined(VL53LX)||defined(L8))
case TOF_INT_EXTI_PIN: case TOF_INT_EXTI_PIN:
printf("\r\n ToF Event Detected=%d \r\n", ToF_EventDetected);
ToF_EventDetected = 1; ToF_EventDetected = 1;
printf("\r\n ToF Event Detected=%d \r\n", ToF_EventDetected);
break; break;
#endif #endif
default: default:

View File

@ -121,7 +121,7 @@ volatile uint8_t sensor_data_ready=0;
#if defined(STS_R1)||defined(STS_R5)||defined(STS_R4)||defined(STS_R1D) #if defined(STS_R1)||defined(STS_R5)||defined(STS_R4)||defined(STS_R1D)
volatile uint32_t STS_TOFScanPeriod_msec=50, STS_TxPeriod_sec=30, STS_HeartBeatTimerPeriod_sec=3600; volatile uint32_t STS_TOFScanPeriod_msec=50, STS_TxPeriod_sec=30, STS_HeartBeatTimerPeriod_sec=3600;
#elif defined(STS_L8)||defined(STS_P2)||defined(STS_O6T)||defined(STS_T6) #elif defined(STS_L8)||defined(STS_P2)||defined(STS_O6T)||defined(STS_T6)
volatile uint32_t STS_TOFScanPeriod_msec=500, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60; volatile uint32_t STS_TOFScanPeriod_msec=100, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60;
#endif #endif
static uint8_t outbuf[128]={0x0}; static uint8_t outbuf[128]={0x0};

View File

@ -69,8 +69,8 @@ extern "C" {
#ifdef L8 #ifdef L8
/* for VL53L8A1 */ /* for VL53L8A1 */
#define RANGING_FREQUENCY (10U) /* Ranging frequency Hz (shall be consistent with TimingBudget value) */ #define RANGING_FREQUENCY (10U) /* Ranging frequency Hz (shall be consistent with TimingBudget value) */
#define LOW_THRESHOLD (2000U) #define LOW_THRESHOLD (200U)
#define HIGH_THRESHOLD (2600U) #define HIGH_THRESHOLD (600U)
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
static RANGING_SENSOR_Capabilities_t Cap; static RANGING_SENSOR_Capabilities_t Cap;
@ -241,7 +241,7 @@ static void MX_53L8A1_ThresholdDetection_Init(void)
printf("VL53L8A1_RANGING_SENSOR_Init failed\n"); printf("VL53L8A1_RANGING_SENSOR_Init failed\n");
//while (1); //while (1);
} }
printf("\r\nVL53L8A1_RANGING_SENSOR_Init Success\r\n");
} }
static void MX_53L8A1_ThresholdDetection_Process(void) static void MX_53L8A1_ThresholdDetection_Process(void)
@ -270,36 +270,6 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
VL53L8A1_RANGING_SENSOR_ConfigIT(VL53L8A1_DEV_CENTER, &ITConfig); VL53L8A1_RANGING_SENSOR_ConfigIT(VL53L8A1_DEV_CENTER, &ITConfig);
// L8CX Motion
/*********************************/
/* Program motion indicator */
/*********************************/
Dev.platform.address = 0x52;
/* Create motion indicator with resolution 8x8 */
int status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8);
if(status)
{
printf("Motion indicator init failed with status : %u\n", status);
//return status;
}
/* (Optional) Change the min and max distance used to detect motions. The
* difference between min and max must never be >1500mm, and minimum never be <400mm,
* otherwise the function below returns error 127 */
status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000);
if(status)
{
printf("Motion indicator set distance motion failed with status : %u\n", status);
//return status;
}
/* If user want to change the resolution, he also needs to update the motion indicator resolution */
status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8);
status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8);
// L8CX Motion
status = VL53L8A1_RANGING_SENSOR_Start(VL53L8A1_DEV_CENTER, RS_MODE_ASYNC_CONTINUOUS); status = VL53L8A1_RANGING_SENSOR_Start(VL53L8A1_DEV_CENTER, RS_MODE_ASYNC_CONTINUOUS);
if (status != BSP_ERROR_NONE) if (status != BSP_ERROR_NONE)
@ -322,11 +292,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
ToF_EventDetected = 0; ToF_EventDetected = 0;
status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result); status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
#if 0
L8CXResult.motion_indicator.motion[montion_config. ]
motion_config.
vl53l8cx_get_ranging_data(&Dev, &Result);
#endif
if (status == BSP_ERROR_NONE) if (status == BSP_ERROR_NONE)
{ {
print_result(&Result); print_result(&Result);
@ -391,10 +357,11 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
printf("Zone : %3d, Motion power : %3lu\n", i, Results. printf("Zone : %3d, Motion power : %3lu\n", i, Results.
Results.motion_indicator.motion[motion_config.map_id[i]]); Results.motion_indicator.motion[motion_config.map_id[i]]);
#endif #endif
#if 0
printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ",
(long)Result->ZoneResult[j + k].Distance[l],(j+k), (long)Result->ZoneResult[j + k].Distance[l],(j+k),
(long)Result->ZoneResult[j + k].Status[l]); (long)Result->ZoneResult[j + k].Status[l]);
#endif
} }
printf("\n"); printf("\n");

View File

@ -31,15 +31,15 @@ extern "C" {
#ifdef STS_L8 #ifdef STS_L8
//#define TOF_INT_EXTI_PIN (GPIO_PIN_3) // (GPIO_PIN_4) //#define TOF_INT_EXTI_PIN (GPIO_PIN_3) // (GPIO_PIN_4)
//#define TOF_INT_EXTI_PORT (GPIOB) //#define TOF_INT_EXTI_PORT (GPIOB)
#define TOF_INT_EXTI_PIN (GPIO_PIN_10) //(GPIO_PIN_4) #define TOF_INT_EXTI_PIN (GPIO_PIN_15) //(GPIO_PIN_4)
#define TOF_INT_EXTI_PORT (GPIOA) //(GPIOA) #define TOF_INT_EXTI_PORT (GPIOA) //(GPIOA)
#define TOF_INT_EXTI_IRQn EXTI15_10_IRQn #define TOF_INT_EXTI_IRQn EXTI15_10_IRQn
#define VL53L8A1_PWR_EN_C_PIN (GPIO_PIN_7) //(GPIO_PIN_7) #define VL53L8A1_PWR_EN_C_PIN (GPIO_PIN_4) //(GPIO_PIN_7)
#define VL53L8A1_PWR_EN_C_PORT (GPIOA) //(GPIOA) #define VL53L8A1_PWR_EN_C_PORT (GPIOB) //(GPIOA)
#define VL53L8A1_LPn_C_PIN (GPIO_PIN_4) //(GPIO_PIN_0) #define VL53L8A1_LPn_C_PIN (GPIO_PIN_10) //(GPIO_PIN_0)
#define VL53L8A1_LPn_C_PORT (GPIOB) //(GPIOB) #define VL53L8A1_LPn_C_PORT (GPIOA) //(GPIOB)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }