Added ALS, DHT, IMU sensors and ToF

Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
Yilin Sun 2023-07-05 09:41:28 +08:00
parent 525e76391d
commit dd6deb7ab9
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
24 changed files with 835 additions and 33 deletions

12
.clang-format Normal file
View File

@ -0,0 +1,12 @@
BasedOnStyle: Google
IndentWidth: 4
AlignConsecutiveMacros: Consecutive
AlignConsecutiveDeclarations: Consecutive
AlignConsecutiveAssignments: Consecutive
AllowShortFunctionsOnASingleLine: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterEnum: false
AfterStruct: false
SplitEmptyFunction: false
ColumnLimit: 120

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
/MX_Generated/.mxproject
/MX_Generated/Makefile
/build
/cmake-build-*
/.vscode
/*.jdebug*
/*.jflash

6
.gitmodules vendored
View File

@ -1,3 +1,9 @@
[submodule "SDK"]
path = SDK
url = https://github.com/STMicroelectronics/STM32CubeWL.git
[submodule "lib/sensors"]
path = lib/sensors
url = https://git.minori.work/Embedded_Projects/imsensors.git
[submodule "lib/tof/STSW_IMG007"]
path = lib/tof/STSW_IMG007
url = https://git.minori.work/Embedded_SDK/STSW_IMG007.git

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(pudding_lwnode_template)
project(pudding_lwnode_ft)
enable_language(CXX)
enable_language(ASM)
@ -12,6 +12,7 @@ set(TARGET_SOURCES
"BSP/stm32wlxx_nucleo_radio.c"
"BSP/stm32wlxx_nucleo.c"
"MX_Generated/startup_stm32wle5xx.s"
"MX_Generated/Core/Src/adc.c"
"MX_Generated/Core/Src/gpio.c"
"MX_Generated/Core/Src/i2c.c"
"MX_Generated/Core/Src/main.c"
@ -20,6 +21,8 @@ set(TARGET_SOURCES
"MX_Generated/Core/Src/stm32wlxx_it.c"
"MX_Generated/Core/Src/system_stm32wlxx.c"
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal.c"
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_adc.c"
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_adc_ex.c"
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_cortex.c"
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_gpio.c"
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_i2c.c"
@ -30,6 +33,9 @@ set(TARGET_SOURCES
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rcc_ex.c"
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rtc.c"
"SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rtc_ex.c"
"src/app_sensors_impl.c"
"src/app_syscalls.c"
"src/app_ranging_impl.c"
"src/main.c"
)
@ -50,6 +56,8 @@ set(TARGET_C_INCLUDES
# Shared libraries linked with application
set(TARGET_LIBS
"imsensors"
"vl53l1x"
"c"
"m"
"nosys"
@ -78,6 +86,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-common -fno-builtin -f
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
add_subdirectory(lib/sensors)
add_subdirectory(lib/tof)
# Shared sources, includes and definitions
add_compile_definitions(${TARGET_C_DEFINES})
include_directories(${TARGET_C_INCLUDES})

File diff suppressed because one or more lines are too long

View File

@ -34,6 +34,8 @@ void MX_ADC_Init(void)
/* USER CODE END ADC_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC_Init 1 */
/* USER CODE END ADC_Init 1 */
@ -63,6 +65,16 @@ void MX_ADC_Init(void)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC_Init 2 */
/* USER CODE END ADC_Init 2 */

View File

@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Wed Jul 05 08:20:01 CST 2023]
# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Wed Jul 05 09:31:02 CST 2023]
##########################################################################################################################
# ------------------------------------------------
@ -42,29 +42,29 @@ Core/Src/stm32wlxx_hal_msp.c \
Core/Src/system_stm32wlxx.c \
Core/Src/gpio.c \
Core/Src/rtc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rcc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rcc_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_flash.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_flash_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_gpio.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_dma.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_dma_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_pwr.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_pwr_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_cortex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_exti.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rtc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rtc_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_tim.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_tim_ex.c \
Core/Src/i2c.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_i2c.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_i2c_ex.c \
Core/Src/adc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_adc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_adc_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_ll_adc.c
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_adc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_adc_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_ll_adc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rcc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rcc_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_flash.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_flash_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_gpio.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_dma.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_dma_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_pwr.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_pwr_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_cortex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_exti.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_i2c.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_i2c_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rtc.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_rtc_ex.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_tim.c \
/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Src/stm32wlxx_hal_tim_ex.c
# ASM sources
ASM_SOURCES = \
@ -123,10 +123,10 @@ AS_INCLUDES =
# C includes
C_INCLUDES = \
-ICore/Inc \
-I/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Inc \
-I/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/STM32WLxx_HAL_Driver/Inc/Legacy \
-I/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/CMSIS/Device/ST/STM32WLxx/Include \
-I/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/template/SDK/Drivers/CMSIS/Include
-I/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Inc \
-I/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/STM32WLxx_HAL_Driver/Inc/Legacy \
-I/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/CMSIS/Device/ST/STM32WLxx/Include \
-I/home/imi415/Documents/Hardwares/STM32_Projects/Pudding_LWNode/ft/SDK/Drivers/CMSIS/Include
# compile gcc flags

View File

@ -1,6 +1,13 @@
#MicroXplorer Configuration settings - do not modify
ADC.IPParameters=NbrOfConversion,SelectedChannel
ADC.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_8
ADC.ContinuousConvMode=DISABLE
ADC.EnableRegularConversion=ENABLE
ADC.IPParameters=NbrOfConversion,SelectedChannel,ContinuousConvMode,EnableRegularConversion,Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,OversamplingMode
ADC.NbrOfConversion=1
ADC.NbrOfConversionFlag=1
ADC.OversamplingMode=DISABLE
ADC.Rank-0\#ChannelRegularConversion=1
ADC.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1
ADC.SelectedChannel=ADC_CHANNEL_8
CAD.formats=
CAD.pinconfig=

1
SDK Submodule

@ -0,0 +1 @@
Subproject commit 5b47f70ce5f9016b92a8bedb037d00d86b7c8080

View File

@ -0,0 +1,19 @@
#ifndef APP_RANGING_IMPL_H
#define APP_RANGING_IMPL_H
/* HAL Drivers */
#include "stm32wlxx_hal.h"
/* Ranging sensor */
#include "vl53l1_platform.h"
typedef struct {
I2C_HandleTypeDef *hi2c;
uint8_t dev_addr;
} app_ranging_impl_t;
VL53L1_Error app_ranging_delay_us(void *pdev, uint32_t delay_usec);
VL53L1_Error app_ranging_delay_ms(void *pdev, uint32_t delay_msec);
VL53L1_Error app_ranging_i2c_xfer(void *pdev, VL53L1_Dev_Xfer_Desc_t *xfer);
#endif // APP_RANGING_IMPL_H

View File

@ -0,0 +1,18 @@
#ifndef APP_SENSORS_IMPL_H
#define APP_SENSORS_IMPL_H
/* HAL Drivers */
#include "stm32wlxx_hal.h"
/* Sensors */
#include "imsensors/common/sensors_common.h"
typedef struct {
I2C_HandleTypeDef *hi2c;
uint8_t dev_addr;
} app_sensors_impl_t;
ims_ret_t app_sensors_i2c_xfer(void *pdev, ims_i2c_xfer_desc_t *xfer);
ims_ret_t app_sensors_delay(void *pdev, uint32_t delay_msec);
#endif // APP_SENSORS_IMPL_H

1
lib/sensors Submodule

@ -0,0 +1 @@
Subproject commit e6d732b0cfc5189b78ceb4d3fa44e5bef9e1287b

33
lib/tof/CMakeLists.txt Normal file
View File

@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.10)
project(vl53l1x)
option(VL53L1X_2V8_MODE "Enable 2V8 VDDIO support" ON)
set(VL53L1X_SRCS
"platform/src/vl53l1_platform.c"
"STSW_IMG007/API/core/src/vl53l1_api.c"
"STSW_IMG007/API/core/src/vl53l1_api_calibration.c"
"STSW_IMG007/API/core/src/vl53l1_api_core.c"
"STSW_IMG007/API/core/src/vl53l1_api_debug.c"
"STSW_IMG007/API/core/src/vl53l1_api_preset_modes.c"
"STSW_IMG007/API/core/src/vl53l1_api_strings.c"
"STSW_IMG007/API/core/src/vl53l1_core.c"
"STSW_IMG007/API/core/src/vl53l1_core_support.c"
"STSW_IMG007/API/core/src/vl53l1_error_strings.c"
"STSW_IMG007/API/core/src/vl53l1_register_funcs.c"
"STSW_IMG007/API/core/src/vl53l1_silicon_core.c"
"STSW_IMG007/API/core/src/vl53l1_wait.c"
)
set(VL53L1X_INCS
"STSW_IMG007/API/core/inc"
"platform/inc"
)
add_library(${PROJECT_NAME} ${VL53L1X_SRCS})
target_include_directories(${PROJECT_NAME} PUBLIC ${VL53L1X_INCS})
if(VL53L1X_2V8_MODE)
target_compile_definitions(${PROJECT_NAME} PRIVATE "USE_I2C_2V8")
endif()

1
lib/tof/STSW_IMG007 Submodule

@ -0,0 +1 @@
Subproject commit 88ed984b029caa842b07f4fbef4658318881a792

View File

@ -0,0 +1,26 @@
#ifndef VL53L1_PLATFORM_H
#define VL53L1_PLATFORM_H
#include "vl53l1_ll_def.h"
/* Platform */
#include "vl53l1_platform_log.h"
#include "vl53l1_platform_user_data.h"
VL53L1_Error VL53L1_RdByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata);
VL53L1_Error VL53L1_RdWord(VL53L1_Dev_t *pdev, uint16_t index, uint16_t *pdata);
VL53L1_Error VL53L1_ReadMulti(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata, uint32_t count);
VL53L1_Error VL53L1_WrByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t data);
VL53L1_Error VL53L1_WrWord(VL53L1_Dev_t *pdev, uint16_t index, uint16_t data);
VL53L1_Error VL53L1_WriteMulti(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata, uint32_t count);
VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value,
uint8_t mask, uint32_t poll_delay_ms);
/* Delays */
VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us);
VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms);
/* TS */
VL53L1_Error VL53L1_GetTickCount(VL53L1_Dev_t *pdev, uint32_t *ptime_ms);
#endif // VL53L1_PLATFORM_H

View File

@ -0,0 +1,187 @@
#ifndef VL53L1_PLATFORM_LOG_H
#define VL53L1_PLATFORM_LOG_H
#ifdef VL53L1_LOG_ENABLE
#include "vl53l1_platform_user_config.h"
#ifdef _MSC_VER
# define EWOKPLUS_EXPORTS __declspec(dllexport)
#else
# define EWOKPLUS_EXPORTS
#endif
#include "vl53l1_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <time.h>
/**
* @brief Set the level, output and specific functions for module logging.
*
*
* @param filename - full path of output log file, NULL for print to stdout
*
* @param modules - Module or None or All to trace
* VL53L1_TRACE_MODULE_NONE
* VL53L1_TRACE_MODULE_API
* VL53L1_TRACE_MODULE_CORE
* VL53L1_TRACE_MODULE_TUNING
* VL53L1_TRACE_MODULE_CHARACTERISATION
* VL53L1_TRACE_MODULE_PLATFORM
* VL53L1_TRACE_MODULE_ALL
*
* @param level - trace level
* VL53L1_TRACE_LEVEL_NONE
* VL53L1_TRACE_LEVEL_ERRORS
* VL53L1_TRACE_LEVEL_WARNING
* VL53L1_TRACE_LEVEL_INFO
* VL53L1_TRACE_LEVEL_DEBUG
* VL53L1_TRACE_LEVEL_ALL
* VL53L1_TRACE_LEVEL_IGNORE
*
* @param functions - function level to trace;
* VL53L1_TRACE_FUNCTION_NONE
* VL53L1_TRACE_FUNCTION_I2C
* VL53L1_TRACE_FUNCTION_ALL
*
* @return status - always VL53L1_ERROR_NONE
*
*/
#define VL53L1_TRACE_LEVEL_NONE 0x00000000
#define VL53L1_TRACE_LEVEL_ERRORS 0x00000001
#define VL53L1_TRACE_LEVEL_WARNING 0x00000002
#define VL53L1_TRACE_LEVEL_INFO 0x00000004
#define VL53L1_TRACE_LEVEL_DEBUG 0x00000008
#define VL53L1_TRACE_LEVEL_ALL 0x00000010
#define VL53L1_TRACE_LEVEL_IGNORE 0x00000020
#define VL53L1_TRACE_FUNCTION_NONE 0x00000000
#define VL53L1_TRACE_FUNCTION_I2C 0x00000001
#define VL53L1_TRACE_FUNCTION_ALL 0x7fffffff
#define VL53L1_TRACE_MODULE_NONE 0x00000000
#define VL53L1_TRACE_MODULE_API 0x00000001
#define VL53L1_TRACE_MODULE_CORE 0x00000002
#define VL53L1_TRACE_MODULE_PROTECTED 0x00000004
#define VL53L1_TRACE_MODULE_HISTOGRAM 0x00000008
#define VL53L1_TRACE_MODULE_REGISTERS 0x00000010
#define VL53L1_TRACE_MODULE_PLATFORM 0x00000020
#define VL53L1_TRACE_MODULE_NVM 0x00000040
#define VL53L1_TRACE_MODULE_CALIBRATION_DATA 0x00000080
#define VL53L1_TRACE_MODULE_NVM_DATA 0x00000100
#define VL53L1_TRACE_MODULE_HISTOGRAM_DATA 0x00000200
#define VL53L1_TRACE_MODULE_RANGE_RESULTS_DATA 0x00000400
#define VL53L1_TRACE_MODULE_XTALK_DATA 0x00000800
#define VL53L1_TRACE_MODULE_OFFSET_DATA 0x00001000
#define VL53L1_TRACE_MODULE_DATA_INIT 0x00002000
#define VL53L1_TRACE_MODULE_REF_SPAD_CHAR 0x00004000
#define VL53L1_TRACE_MODULE_SPAD_RATE_MAP 0x00008000
#ifdef PAL_EXTENDED
#define VL53L1_TRACE_MODULE_SPAD 0x01000000
#define VL53L1_TRACE_MODULE_FMT 0x02000000
#define VL53L1_TRACE_MODULE_UTILS 0x04000000
#define VL53L1_TRACE_MODULE_BENCH_FUNCS 0x08000000
#endif
#define VL53L1_TRACE_MODULE_CUSTOMER_API 0x40000000
#define VL53L1_TRACE_MODULE_ALL 0x7fffffff
extern uint32_t _trace_level;
/*
* NOTE: dynamically exported if we enable logging.
* this way, Python interfaces can access this function, but we don't
* need to include it in the .def files.
*/
EWOKPLUS_EXPORTS int8_t VL53L1_trace_config(
char *filename,
uint32_t modules,
uint32_t level,
uint32_t functions);
/**
* @brief Print trace module function.
*
* @param module - ??
* @param level - ??
* @param function - ??
* @param format - ??
*
*/
EWOKPLUS_EXPORTS void VL53L1_trace_print_module_function(
uint32_t module,
uint32_t level,
uint32_t function,
const char *format, ...);
/**
* @brief Get global _trace_functions parameter
*
* @return _trace_functions
*/
uint32_t VL53L1_get_trace_functions(void);
/**
* @brief Set global _trace_functions parameter
*
* @param[in] function : new function code
*/
void VL53L1_set_trace_functions(uint32_t function);
/*
* @brief Returns the current system tick count in [ms]
*
* @return time_ms : current time in [ms]
*
*/
uint32_t VL53L1_clock(void);
#define LOG_GET_TIME() \
((int)VL53L1_clock())
#define _LOG_TRACE_PRINT(module, level, function, ...) \
VL53L1_trace_print_module_function(module, level, function, ##__VA_ARGS__);
#define _LOG_FUNCTION_START(module, fmt, ...) \
VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld <START> %s "fmt"\n", LOG_GET_TIME(), __FUNCTION__, ##__VA_ARGS__);
#define _LOG_FUNCTION_END(module, status, ...)\
VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld <END> %s %d\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__)
#define _LOG_FUNCTION_END_FMT(module, status, fmt, ...)\
VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld <END> %s %d "fmt"\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__)
#define _LOG_GET_TRACE_FUNCTIONS()\
VL53L1_get_trace_functions()
#define _LOG_SET_TRACE_FUNCTIONS(functions)\
VL53L1_set_trace_functions(functions)
#define _LOG_STRING_BUFFER(x) char x[VL53L1_MAX_STRING_LENGTH]
#ifdef __cplusplus
}
#endif
#else /* VL53L1_LOG_ENABLE - no logging */
#define _LOG_TRACE_PRINT(module, level, function, ...)
#define _LOG_FUNCTION_START(module, fmt, ...)
#define _LOG_FUNCTION_END(module, status, ...)
#define _LOG_FUNCTION_END_FMT(module, status, fmt, ...)
#define _LOG_GET_TRACE_FUNCTIONS() 0
#define _LOG_SET_TRACE_FUNCTIONS(functions)
#define _LOG_STRING_BUFFER(x)
#endif /* VL53L1_LOG_ENABLE */
#endif // VL53L1_PLATFORM_LOG_H

View File

@ -0,0 +1,19 @@
#ifndef VL53L1_PLATFORM_USER_CONFIG_H
#define VL53L1_PLATFORM_USER_CONFIG_H
#define VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS 0x8000
/* Offset Calibration */
#define VL53L1_OFFSET_CAL_MAX_PRE_PEAK_RATE_MCPS 0x1900
#define VL53L1_OFFSET_CAL_MAX_SIGMA_MM 0x0040
#define VL53L1_OFFSET_CAL_MIN_EFFECTIVE_SPADS 0x0500
/* Timeouts */
#define VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS 500
#define VL53L1_POLLING_DELAY_MS 1
#define VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS 2000
#define VL53L1_TEST_COMPLETION_POLLING_TIMEOUT_MS 60000
#define VL53L1_MAX_STRING_LENGTH 512
#endif // VL53L1_PLATFORM_USER_CONFIG_H

View File

@ -0,0 +1,38 @@
#ifndef VL53L1_PLATFORM_USER_DATA_H
#define VL53L1_PLATFORM_USER_DATA_H
#include "vl53l1_def.h"
#define VL53L1DevStructGetLLDriverHandle(Dev) (&Dev->Data.LLData)
#define VL53L1DevStructGetLLResultsHandle(Dev) (&Dev->Data.llresults)
#define VL53L1DevDataGet(Dev, field) (Dev->Data.field)
#define VL53L1DevDataSet(Dev, field, data) ((Dev->Data.field) = (data))
typedef struct {
uint8_t *TxData;
uint8_t *RxData;
uint16_t TxSize;
uint16_t RxSize;
} VL53L1_Dev_Xfer_Desc_t;
typedef VL53L1_Error (*VL53L1_Delay_Us_t)(void *pdev, uint32_t usec);
typedef VL53L1_Error (*VL53L1_Delay_Ms_t)(void *pdev, uint32_t msec);
typedef VL53L1_Error (*VL53L1_I2C_Xfer_t)(void *pdev, VL53L1_Dev_Xfer_Desc_t *desc);
typedef struct {
VL53L1_Delay_Us_t Delay_Us;
VL53L1_Delay_Ms_t Delay_Ms;
VL53L1_I2C_Xfer_t I2C_Xfer;
} VL53L1_Dev_Ops_t;
typedef struct {
VL53L1_DevData_t Data;
VL53L1_Dev_Ops_t Ops;
void *OpsData;
} VL53L1_Dev_t;
typedef VL53L1_Dev_t *VL53L1_DEV;
#endif // VL53L1_PLATFORM_USER_DATA_H

View File

@ -0,0 +1,9 @@
#ifndef VL53L1_PLATFORM_USER_DEFINES_H
#define VL53L1_PLATFORM_USER_DEFINES_H
#define DISABLE_WARNINGS()
#define ENABLE_WARNINGS()
#define WARN_OVERRIDE_STATUS(__X__) trace_print(VL53L1_TRACE_LEVEL_WARNING, #__X__);
#endif // VL53L1_PLATFORM_USER_DEFINES_H

View File

@ -0,0 +1,13 @@
#ifndef VL53L1_TYPES_H
#define VL53L1_TYPES_H
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Fix point type */
typedef uint32_t FixPoint1616_t;
#endif // VL53L1_TYPES_H

View File

@ -0,0 +1,143 @@
/* Platform */
#include "vl53l1_platform.h"
#define PLATFORM_MAXIMUM_MULTI_WRITE_SIZE 256
VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us) {
return pdev->Ops.Delay_Us(pdev->OpsData, wait_us);
}
VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms) {
return pdev->Ops.Delay_Ms(pdev->OpsData, wait_ms);
}
VL53L1_Error VL53L1_RdByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata) {
uint8_t tx_buf[2];
tx_buf[0] = (index >> 8U) & 0xFFU;
tx_buf[1] = (index & 0xFFU);
VL53L1_Dev_Xfer_Desc_t xfer = {
.TxData = tx_buf,
.TxSize = 2,
.RxData = pdata,
.RxSize = 1,
};
return pdev->Ops.I2C_Xfer(pdev->OpsData, &xfer);
}
VL53L1_Error VL53L1_RdWord(VL53L1_Dev_t *pdev, uint16_t index, uint16_t *pdata) {
uint8_t tx_buf[2];
uint8_t rx_buf[2];
tx_buf[0] = (index >> 8U) & 0xFFU;
tx_buf[1] = (index & 0xFFU);
VL53L1_Dev_Xfer_Desc_t xfer = {
.TxData = tx_buf,
.TxSize = 2,
.RxData = rx_buf,
.RxSize = 2,
};
VL53L1_Error ret = pdev->Ops.I2C_Xfer(pdev->OpsData, &xfer);
if (ret != VL53L1_ERROR_NONE) return ret;
*pdata = (rx_buf[0] << 8U) | rx_buf[1];
return ret;
}
VL53L1_Error VL53L1_ReadMulti(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata, uint32_t count) {
uint8_t tx_buf[2];
tx_buf[0] = (index >> 8U) & 0xFFU;
tx_buf[1] = (index & 0xFFU);
VL53L1_Dev_Xfer_Desc_t xfer = {
.TxData = tx_buf,
.TxSize = 2,
.RxData = pdata,
.RxSize = count,
};
return pdev->Ops.I2C_Xfer(pdev->OpsData, &xfer);
}
VL53L1_Error VL53L1_WrByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t data) {
uint8_t tx_buf[3];
tx_buf[0] = (index >> 8U) & 0xFFU;
tx_buf[1] = (index & 0xFFU);
tx_buf[2] = data;
VL53L1_Dev_Xfer_Desc_t xfer = {
.TxData = tx_buf,
.TxSize = 3,
.RxData = NULL,
.RxSize = 0,
};
return pdev->Ops.I2C_Xfer(pdev->OpsData, &xfer);
}
VL53L1_Error VL53L1_WriteMulti(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata, uint32_t count) {
if (count > PLATFORM_MAXIMUM_MULTI_WRITE_SIZE - 2) {
for (;;) {
/* -- */
pdev->Ops.Delay_Ms(pdev->OpsData, 1000);
}
}
uint8_t tx_buf[PLATFORM_MAXIMUM_MULTI_WRITE_SIZE];
tx_buf[0] = (index >> 8U) & 0xFFU;
tx_buf[1] = (index & 0xFFU);
memcpy(&tx_buf[2], pdata, count);
VL53L1_Dev_Xfer_Desc_t xfer = {
.TxData = tx_buf,
.TxSize = count + 2,
.RxData = NULL,
.RxSize = 0,
};
return pdev->Ops.I2C_Xfer(pdev->OpsData, &xfer);
}
VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value,
uint8_t mask, uint32_t poll_delay_ms) {
uint8_t tx_buf[2];
uint8_t rx_buf[1];
tx_buf[0] = (index >> 8U) & 0xFFU;
tx_buf[1] = (index & 0xFFU);
VL53L1_Dev_Xfer_Desc_t xfer = {
.TxData = tx_buf,
.TxSize = 2,
.RxData = rx_buf,
.RxSize = 1,
};
uint8_t ts_count = 0U;
VL53L1_Error ret;
do {
ret = pdev->Ops.I2C_Xfer(pdev->OpsData, &xfer);
if (ret != VL53L1_ERROR_NONE) return ret;
ts_count += poll_delay_ms;
pdev->Ops.Delay_Ms(pdev->OpsData, poll_delay_ms);
if (ts_count > timeout_ms) {
return VL53L1_ERROR_TIME_OUT;
}
} while ((rx_buf[0] & mask) != value);
return VL53L1_ERROR_NONE;
}

38
src/app_ranging_impl.c Normal file
View File

@ -0,0 +1,38 @@
#include "app_ranging_impl.h"
#define APP_I2C_READ(addr) ((addr << 1U) | 0x01U)
#define APP_I2C_WRITE(addr) ((addr << 1U) & (~0x01U))
VL53L1_Error app_ranging_delay_us(void *pdev, uint32_t delay_usec) {
HAL_Delay(1);
return VL53L1_ERROR_NONE;
}
VL53L1_Error app_ranging_delay_ms(void *pdev, uint32_t delay_msec) {
HAL_Delay(delay_msec);
return VL53L1_ERROR_NONE;
}
VL53L1_Error app_ranging_i2c_xfer(void *pdev, VL53L1_Dev_Xfer_Desc_t *xfer) {
app_ranging_impl_t *impl = pdev;
HAL_StatusTypeDef ret;
if (xfer->TxSize) {
ret = HAL_I2C_Master_Transmit(impl->hi2c, APP_I2C_WRITE(impl->dev_addr), xfer->TxData, xfer->TxSize, 1000);
if (ret != HAL_OK) {
return VL53L1_ERROR_CONTROL_INTERFACE;
}
}
if (xfer->RxSize) {
ret = HAL_I2C_Master_Receive(impl->hi2c, APP_I2C_READ(impl->dev_addr), xfer->RxData, xfer->RxSize, 1000);
if (ret != HAL_OK) {
return VL53L1_ERROR_CONTROL_INTERFACE;
}
}
return VL53L1_ERROR_NONE;
}

32
src/app_sensors_impl.c Normal file
View File

@ -0,0 +1,32 @@
#include "app_sensors_impl.h"
#define APP_I2C_READ(addr) ((addr << 1U) | 0x01U)
#define APP_I2C_WRITE(addr) ((addr << 1U) & (~0x01U))
ims_ret_t app_sensors_i2c_xfer(void *pdev, ims_i2c_xfer_desc_t *xfer) {
app_sensors_impl_t *impl = pdev;
HAL_StatusTypeDef ret;
if (xfer->tx_size) {
ret = HAL_I2C_Master_Transmit(impl->hi2c, APP_I2C_WRITE(impl->dev_addr), xfer->tx_data, xfer->tx_size, 1000);
if (ret != HAL_OK) {
return IMS_FAIL;
}
}
if (xfer->rx_size) {
ret = HAL_I2C_Master_Receive(impl->hi2c, APP_I2C_READ(impl->dev_addr), xfer->rx_data, xfer->rx_size, 1000);
if (ret != HAL_OK) {
return IMS_FAIL;
}
}
return IMS_SUCCESS;
}
ims_ret_t app_sensors_delay(void *pdev, uint32_t delay_msec) {
HAL_Delay(delay_msec);
return IMS_SUCCESS;
}

View File

@ -1,8 +1,8 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
/* MX Generated headers */
#include "adc.h"
#include "gpio.h"
#include "i2c.h"
#include "main.h"
@ -12,8 +12,74 @@
#include "stm32wlxx_nucleo.h"
#include "stm32wlxx_nucleo_radio.h"
/* Sensors */
#include "imsensors/als/als_ltr_303als.h"
#include "imsensors/dht/dht_bme280.h"
#include "imsensors/imu/imu_lsm6dsl.h"
#include "vl53l1_api.h"
/* App */
#include "app_ranging_impl.h"
#include "app_sensors_impl.h"
extern void SystemClock_Config(void);
static app_sensors_impl_t s_dht_impl = {
.hi2c = &hi2c1,
.dev_addr = 0x76,
};
static ims_bme280_t s_dht = {
.pdev = &s_dht_impl,
.cb =
{
.i2c_xfer = app_sensors_i2c_xfer,
.delay = app_sensors_delay,
},
};
static app_sensors_impl_t s_als_impl = {
.hi2c = &hi2c1,
.dev_addr = 0x29,
};
static ims_ltr_303als_t s_als = {
.pdev = &s_als_impl,
.cb =
{
.i2c_xfer = app_sensors_i2c_xfer,
.delay = app_sensors_delay,
},
};
static app_sensors_impl_t s_imu_impl = {
.hi2c = &hi2c1,
.dev_addr = 0x6A,
};
static ims_lsm6dsl_t s_imu = {
.pdev = &s_imu_impl,
.cb =
{
.i2c_xfer = app_sensors_i2c_xfer,
.delay = app_sensors_delay,
},
};
static app_ranging_impl_t s_ranging_impl = {
.hi2c = &hi2c1,
.dev_addr = 0x29,
};
static VL53L1_Dev_t s_ranging = {
.Ops =
{
.Delay_Us = app_ranging_delay_us,
.Delay_Ms = app_ranging_delay_ms,
.I2C_Xfer = app_ranging_i2c_xfer,
},
.OpsData = &s_ranging_impl,
};
int main(void) {
/* HAL */
@ -22,17 +88,120 @@ int main(void) {
/* Hardware initialization */
SystemClock_Config();
MX_GPIO_Init();
MX_ADC_Init();
MX_RTC_Init();
MX_I2C1_Init();
printf("Hello world\r\n");
if (ims_bme280_init(&s_dht) != IMS_SUCCESS) {
goto dead_loop;
}
ims_bme280_config_t dht_cfg;
ims_bme280_preset_config(&dht_cfg, IMS_BME280_PRESET_WEATHER);
ims_bme280_apply_config(&s_dht, &dht_cfg);
if (ims_ltr_303als_init(&s_als) != IMS_SUCCESS) {
goto dead_loop;
}
ims_ltr_303als_config_t als_cfg;
ims_ltr_303als_preset_config(&als_cfg);
als_cfg.gain = IMS_LTR_303ALS_GAIN_48X;
if (ims_ltr_303als_config(&s_als, &als_cfg) != IMS_SUCCESS) {
goto dead_loop;
}
if (ims_ltr_303als_set_mode(&s_als, IMS_LTR_303ALS_MODE_ACTIVE) != IMS_SUCCESS) {
goto dead_loop;
}
if (ims_lsm6dsl_init(&s_imu) != IMS_SUCCESS) {
goto dead_loop;
}
HAL_GPIO_WritePin(TOF_XSHUT_GPIO_Port, TOF_XSHUT_Pin, 1U);
HAL_Delay(5);
VL53L1_SetDeviceAddress(&s_ranging, 0x6E);
s_ranging_impl.dev_addr = 0x37U;
VL53L1_WaitDeviceBooted(&s_ranging);
VL53L1_DataInit(&s_ranging);
VL53L1_StaticInit(&s_ranging);
VL53L1_SetDistanceMode(&s_ranging, VL53L1_DISTANCEMODE_MEDIUM);
VL53L1_SetMeasurementTimingBudgetMicroSeconds(&s_ranging, 50000);
VL53L1_SetInterMeasurementPeriodMilliSeconds(&s_ranging, 500);
VL53L1_StartMeasurement(&s_ranging);
if(HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK) {
goto dead_loop;
}
ims_ltr_303als_result_t als_result;
ims_bme280_result_t dht_result;
VL53L1_RangingMeasurementData_t ranging_result;
uint8_t ranging_ready = 0U;
int16_t imu_temp;
volatile uint16_t vbat;
for (;;) {
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
HAL_Delay(500);
if (ims_bme280_measure(&s_dht, &dht_result) != IMS_SUCCESS) {
goto dead_loop;
}
if (ims_ltr_303als_read(&s_als, &als_result) != IMS_SUCCESS) {
goto dead_loop;
}
if (ims_lsm6dsl_read_temperature(&s_imu, &imu_temp) != IMS_SUCCESS) {
goto dead_loop;
}
VL53L1_GetMeasurementDataReady(&s_ranging, &ranging_ready);
if (ranging_ready) {
VL53L1_GetRangingMeasurementData(&s_ranging, &ranging_result);
if (VL53L1_ClearInterruptAndStartMeasurement(&s_ranging) != VL53L1_ERROR_NONE) {
goto dead_loop;
}
}
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 1000);
if(HAL_ADC_GetState(&hadc) & HAL_ADC_STATE_EOC_REG) {
vbat = HAL_ADC_GetValue(&hadc);
}
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
HAL_Delay(500);
/* clang-format off */
/*
dprintf main:printf_point, "T: %.2fC,\tH: %.2f%%,\tP: %.2fhPa,\tI0: %.2flx,\tI1: %.2flx,\tT_IMU: %.2fC\tR: %dmm\tV: %.2fmV\n",
dht_result.temperature / 100.0, dht_result.humidity / 1024.0, dht_result.pressure / 25600.0,
als_result.ch0_value / 48.0,
als_result.ch1_value / 48.0,
(imu_temp / 256.0) + 25.0,
ranging_result.RangeMilliMeter,
(vbat * 3362.0 / 4096.0)
*/
/* clang-format on */
printf_point:
HAL_Delay(100);
}
dead_loop:
for (;;) {
/* -- */
}
}