From: SnickerSun Date: Mon, 1 Jan 2024 11:22:31 +0000 (+0800) Subject: 添加lis2doc驱动,测试读取id失败,需要确认 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=b76a8ec81416e0452bc54a0616ab8cae58f3f16c;p=mirrors%2FFD230.git 添加lis2doc驱动,测试读取id失败,需要确认 --- diff --git a/code/sdk/application/brandy/brandy_standard/service_init.c b/code/sdk/application/brandy/brandy_standard/service_init.c index f7547eb57..4dc7ca312 100755 --- a/code/sdk/application/brandy/brandy_standard/service_init.c +++ b/code/sdk/application/brandy/brandy_standard/service_init.c @@ -41,6 +41,11 @@ #ifdef SUPPORT_AT_HX3695 #include "hx3695_at_cmd.h" #endif + +#ifdef SUPPORT_AT_LIS2DOC +#include "lis2doc_at_cmd.h" +#endif + #include "log_file.h" #ifdef CONFIG_OTA_UPDATE_SUPPORT #include "upg.h" @@ -85,6 +90,14 @@ static void register_at_service(void) at_cmd_table_t *hx3695_table = get_hx3695_cmd_table(&hx3695_cmd_count); at_cmd_add_moudle(hx3695_table, hx3695_cmd_count); #endif + +#ifdef SUPPORT_AT_LIS2DOC + uint32_t lis2doc_cmd_count; + at_cmd_table_t *lis2doc_table = get_lis2doc_cmd_table(&lis2doc_cmd_count); + at_cmd_add_moudle(lis2doc_table, lis2doc_cmd_count); +#endif + + } #ifdef CONFIG_OTA_UPDATE_SUPPORT diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 32dd3712f..cb624c372 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -117,6 +117,7 @@ target = { 'ENABLE_ECC', 'FT_SINGLE_UART', 'PPG_HX3695', + 'ACC_LIS2DOC', #'CONFIG_ADC_SUPPORT_AUTO_SCAN','CONFIG_ADC_SUPPORT_LONG_SAMPLE', 'MIPI_ULPS_SUPPORT', 'TPTYPE_FT6X46'], 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", @@ -127,6 +128,7 @@ target = { 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', 'ohosfwk_at_service', "audio_proc", "audio_dump", "audio_probe", "power_manager", "gpu_proc", "ppg_sensor", + "acc_sensor", "batterry_service"], 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'alipay_set'], 'dsp_version': 'max', diff --git a/code/sdk/drivers/peripheral/acc/CMakeLists.txt b/code/sdk/drivers/peripheral/acc/CMakeLists.txt index 12d59f5b1..583644d08 100644 --- a/code/sdk/drivers/peripheral/acc/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/acc/CMakeLists.txt @@ -4,43 +4,62 @@ #=============================================================================== set(COMPONENT_NAME "acc_sensor") -set(SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/touch_screen_drv.c - ${CMAKE_CURRENT_SOURCE_DIR}/touch_screen_queue1.c -) - if("ACC_LIS2DOC" IN_LIST DEFINES) set(SOURCES ${SOURCES} - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/Customer.c - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/main_sample.c - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/MMC5603.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/lis2doc_porting.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/lis2doc_at_cmd.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/driver/lis2doc_reg.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_activity.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_free_fall.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_orientation.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_data_polling.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_data_single.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_fifo.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_self_test.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_wake_up.c +) +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC +) +set(PUBLIC_DEFINES + SUPPORT_AT_LIS2DOC ) +set(PRIVATE_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/driver +) + else() + set(SOURCES ${SOURCES} - ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/Customer.c - ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/main_sample.c - ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/MMC5603.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/lis2doc_porting.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/lis2doc_at_cmd.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/driver/lis2doc_reg.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_activity.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_free_fall.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_orientation.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_data_polling.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_data_single.c + # ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_read_fifo.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_self_test.c + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/examples/lis2doc_wake_up.c ) -endif() - -if("ACC_LIS2DOC" IN_LIST DEFINES) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC ) -else() -set(PUBLIC_HEADER - {CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC +set(PUBLIC_DEFINES + SUPPORT_AT_LIS2DOC ) -endif() - set(PRIVATE_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/lis2doc_STdC/driver ) +endif() + + set(PRIVATE_DEFINES ) -set(PUBLIC_DEFINES -) + # use this when you want to add ccflags like -include xxx set(COMPONENT_PUBLIC_CCFLAGS diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/driver/lis2doc_reg.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/driver/lis2doc_reg.c index 90d9b53af..886eedee0 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/driver/lis2doc_reg.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/driver/lis2doc_reg.c @@ -46,7 +46,8 @@ * @retval interface status (MANDATORY: return 0 -> no Error) * */ -int32_t __weak lis2doc_read_reg(stmdev_ctx_t *ctx, uint8_t reg, +// int32_t __weak lis2doc_read_reg(stmdev_ctx_t *ctx, uint8_t reg, +int32_t lis2doc_read_reg(stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data, uint16_t len) { diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/driver/lis2doc_reg.h b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/driver/lis2doc_reg.h index 05dad3626..285f3d760 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/driver/lis2doc_reg.h +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/driver/lis2doc_reg.h @@ -30,6 +30,7 @@ extern "C" { #include #include #include +#include /** @addtogroup LIS2DOC * @{ diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_activity.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_activity.c index c8ef6456c..635b8047a 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_activity.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_activity.c @@ -83,23 +83,7 @@ #include #include #include "lis2doc_reg.h" - -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif +#include "lis2doc_porting.h" /* Private macro -------------------------------------------------------------*/ #define BOOT_TIME 20 //ms @@ -109,24 +93,6 @@ static lis2doc_mode_t pm; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ - -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); - /* Main Example --------------------------------------------------------------*/ void lis2doc_activity(void) @@ -210,105 +176,3 @@ void lis2doc_activity(void) } } } - -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_free_fall.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_free_fall.c index 1cdfe6dd0..e376d85e4 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_free_fall.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_free_fall.c @@ -83,23 +83,7 @@ #include #include #include "lis2doc_reg.h" - -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif +#include "lis2doc_porting.h" /* Private macro -------------------------------------------------------------*/ #define BOOT_TIME 20 //ms @@ -109,23 +93,6 @@ static lis2doc_mode_t pm; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); - /* Main Example --------------------------------------------------------------*/ void lis2doc_free_fall(void) { @@ -185,105 +152,3 @@ void lis2doc_free_fall(void) } } } - -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_orientation.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_orientation.c index df007e8e5..6e3cb0748 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_orientation.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_orientation.c @@ -61,44 +61,12 @@ * header file of the driver (_reg.h). */ - -#if defined(STEVAL_MKI109V3) -/* MKI109V3: Define communication interface */ -#define SENSOR_BUS hspi2 -/* MKI109V3: Vdd and Vddio power supply values */ -#define PWM_3V3 915 - -#elif defined(NUCLEO_F411RE) -/* NUCLEO_F411RE: Define communication interface */ -#define SENSOR_BUS hi2c1 - -#elif defined(SPC584B_DIS) -/* DISCOVERY_SPC584B: Define communication interface */ -#define SENSOR_BUS I2CD1 - -#endif - /* Includes ------------------------------------------------------------------*/ #include #include #include "lis2doc_reg.h" +#include "lis2doc_porting.h" -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif /* Private macro -------------------------------------------------------------*/ #define BOOT_TIME 20 //ms @@ -108,23 +76,6 @@ static lis2doc_mode_t pm; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); - /* Main Example --------------------------------------------------------------*/ void lis2doc_orientation(void) { @@ -211,104 +162,3 @@ void lis2doc_orientation(void) } } -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_polling.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_polling.c index a50ca78ed..0d308c3fd 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_polling.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_polling.c @@ -62,43 +62,13 @@ */ -#if defined(STEVAL_MKI109V3) -/* MKI109V3: Define communication interface */ -#define SENSOR_BUS hspi2 -/* MKI109V3: Vdd and Vddio power supply values */ -#define PWM_3V3 915 - -#elif defined(NUCLEO_F411RE) -/* NUCLEO_F411RE: Define communication interface */ -#define SENSOR_BUS hi2c1 - -#elif defined(SPC584B_DIS) -/* DISCOVERY_SPC584B: Define communication interface */ -#define SENSOR_BUS I2CD1 - -#endif /* Includes ------------------------------------------------------------------*/ #include #include #include "lis2doc_reg.h" +#include "lis2doc_porting.h" -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif /* Private macro -------------------------------------------------------------*/ #define BOOT_TIME 20 //ms @@ -111,23 +81,6 @@ static float acceleration_mg[3]; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); - /* Main Example --------------------------------------------------------------*/ void lis2doc_read_data_polling(void) { @@ -201,105 +154,3 @@ void lis2doc_read_data_polling(void) } } } - -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_single.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_single.c index fd30d095a..4ee208c90 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_single.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_data_single.c @@ -62,43 +62,13 @@ */ -#if defined(STEVAL_MKI109V3) -/* MKI109V3: Define communication interface */ -#define SENSOR_BUS hspi2 -/* MKI109V3: Vdd and Vddio power supply values */ -#define PWM_3V3 915 - -#elif defined(NUCLEO_F411RE) -/* NUCLEO_F411RE: Define communication interface */ -#define SENSOR_BUS hi2c1 - -#elif defined(SPC584B_DIS) -/* DISCOVERY_SPC584B: Define communication interface */ -#define SENSOR_BUS I2CD1 - -#endif /* Includes ------------------------------------------------------------------*/ #include #include #include "lis2doc_reg.h" +#include "lis2doc_porting.h" -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif /* Private macro -------------------------------------------------------------*/ #define BOOT_TIME 20 //ms @@ -111,22 +81,6 @@ static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; static lis2doc_ctrl4_int1_pad_ctrl_t ctrl4_int1_pad; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); /* Main Example --------------------------------------------------------------*/ void lis2doc_read_data_single(void) @@ -181,7 +135,8 @@ void lis2doc_read_data_single(void) /* Read samples in polling mode (no int) */ while (1) { /* polling on DRDY signal */ - if (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_0)) { + // if (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_0)) { + if (1 == 0) { /* Read acceleration data */ memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t)); lis2doc_acceleration_raw_get(&dev_ctx, data_raw_acceleration); @@ -191,16 +146,7 @@ void lis2doc_read_data_single(void) data_raw_acceleration[1]); acceleration_mg[2] = lis2doc_from_fs2_lp1_to_mg( data_raw_acceleration[2]); -#ifdef STEVAL_MKI109V3 - /* After data ready signal rise, is not possible to set a - * new trigger before 175us. - * I2C read data operation fit this constraint while SPI need - * a wait loop in order to guarantee it. - */ - for (int i = 0; i < 0x3FF; i++); - -#endif lis2doc_data_rate_set(&dev_ctx, LIS2DOC_XL_SET_SW_TRIG); sprintf((char *)tx_buffer, "Acceleration [mg]:%4.2f\t%4.2f\t%4.2f\r\n", @@ -210,104 +156,3 @@ void lis2doc_read_data_single(void) } } -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_fifo.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_fifo.c index bfb71881f..8a6ac8be6 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_fifo.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_read_fifo.c @@ -61,44 +61,11 @@ * header file of the driver (_reg.h). */ - -#if defined(STEVAL_MKI109V3) -/* MKI109V3: Define communication interface */ -#define SENSOR_BUS hspi2 -/* MKI109V3: Vdd and Vddio power supply values */ -#define PWM_3V3 915 - -#elif defined(NUCLEO_F411RE) -/* NUCLEO_F411RE: Define communication interface */ -#define SENSOR_BUS hi2c1 - -#elif defined(SPC584B_DIS) -/* DISCOVERY_SPC584B: Define communication interface */ -#define SENSOR_BUS I2CD1 - -#endif - /* Includes ------------------------------------------------------------------*/ #include #include #include "lis2doc_reg.h" - -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif +#include "lis2doc_porting.h" /* Private macro -------------------------------------------------------------*/ #define BOOT_TIME 20 //ms @@ -110,22 +77,6 @@ static float acceleration_mg[3]; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); /* Main Example --------------------------------------------------------------*/ void lis2doc_read_data_fifo(void) @@ -208,104 +159,3 @@ void lis2doc_read_data_fifo(void) } } -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_self_test.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_self_test.c index a2dbf4432..8f397238b 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_self_test.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_self_test.c @@ -82,23 +82,7 @@ #include #include #include "lis2doc_reg.h" - -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif +#include "lis2doc_porting.h" typedef union { int16_t i16bit[3]; @@ -121,23 +105,6 @@ static float acceleration_mg[SELF_TEST_SAMPLES][3]; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); - /* Utility functions ---------------------------------------------------------*/ static inline float ABSF(float _x) { @@ -188,7 +155,7 @@ static void test_self_test_lis2doc(stmdev_ctx_t *dev_ctx) lis2doc_power_mode_set(dev_ctx, pm); lis2doc_data_rate_set(dev_ctx, LIS2DOC_XL_ODR_50Hz); - HAL_Delay(100); + platform_delay(100); /* Flush old samples */ flush_samples(dev_ctx); @@ -220,7 +187,7 @@ static void test_self_test_lis2doc(stmdev_ctx_t *dev_ctx) /* Enable self test mode */ lis2doc_self_test_set(dev_ctx, LIS2DOC_XL_ST_POSITIVE); - HAL_Delay(100); + platform_delay(100); i = 0; /* Flush old samples */ flush_samples(dev_ctx); @@ -294,104 +261,3 @@ void lis2doc_self_test(void) } } -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_tap_double.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_tap_double.c index 31ab3f1e3..c48dc697c 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_tap_double.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_tap_double.c @@ -62,43 +62,12 @@ */ -#if defined(STEVAL_MKI109V3) -/* MKI109V3: Define communication interface */ -#define SENSOR_BUS hspi2 -/* MKI109V3: Vdd and Vddio power supply values */ -#define PWM_3V3 915 - -#elif defined(NUCLEO_F411RE) -/* NUCLEO_F411RE: Define communication interface */ -#define SENSOR_BUS hi2c1 - -#elif defined(SPC584B_DIS) -/* DISCOVERY_SPC584B: Define communication interface */ -#define SENSOR_BUS I2CD1 - -#endif /* Includes ------------------------------------------------------------------*/ #include #include #include "lis2doc_reg.h" - -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif +#include "lis2doc_porting.h" /* Private macro -------------------------------------------------------------*/ @@ -109,22 +78,6 @@ static lis2doc_mode_t pm; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); /* Main Example --------------------------------------------------------------*/ void lis2doc_double_tap(void) @@ -231,105 +184,3 @@ void lis2doc_double_tap(void) } } } - -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_tap_single.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_tap_single.c index 3a545b21e..47b4e1e20 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_tap_single.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_tap_single.c @@ -62,43 +62,11 @@ */ -#if defined(STEVAL_MKI109V3) -/* MKI109V3: Define communication interface */ -#define SENSOR_BUS hspi2 -/* MKI109V3: Vdd and Vddio power supply values */ -#define PWM_3V3 915 - -#elif defined(NUCLEO_F411RE) -/* NUCLEO_F411RE: Define communication interface */ -#define SENSOR_BUS hi2c1 - -#elif defined(SPC584B_DIS) -/* DISCOVERY_SPC584B: Define communication interface */ -#define SENSOR_BUS I2CD1 - -#endif - /* Includes ------------------------------------------------------------------*/ #include #include #include "lis2doc_reg.h" - -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif +#include "lis2doc_porting.h" /* Private macro -------------------------------------------------------------*/ @@ -109,22 +77,7 @@ static lis2doc_mode_t pm; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); /* Main Example --------------------------------------------------------------*/ void lis2doc_single_tap(void) @@ -208,105 +161,3 @@ void lis2doc_single_tap(void) } } } - -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_wake_up.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_wake_up.c index e4cd954d5..acc8db946 100644 --- a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_wake_up.c +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/examples/lis2doc_wake_up.c @@ -82,24 +82,7 @@ #include #include #include "lis2doc_reg.h" - -#if defined(NUCLEO_F411RE) -#include "stm32f4xx_hal.h" -#include "usart.h" -#include "gpio.h" -#include "i2c.h" - -#elif defined(STEVAL_MKI109V3) -#include "stm32f4xx_hal.h" -#include "usbd_cdc_if.h" -#include "gpio.h" -#include "spi.h" -#include "tim.h" - -#elif defined(SPC584B_DIS) -#include "components.h" -#endif - +#include "lis2doc_porting.h" /* Private macro -------------------------------------------------------------*/ #define BOOT_TIME 20 //ms @@ -108,23 +91,6 @@ static lis2doc_mode_t pm; static uint8_t whoamI, rst; static uint8_t tx_buffer[1000]; -/* Extern variables ----------------------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/* - * WARNING: - * Functions declare in this section are defined at the end of this file - * and are strictly related to the hardware platform used. - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len); -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len); -static void tx_com( uint8_t *tx_buffer, uint16_t len ); -static void platform_delay(uint32_t ms); -static void platform_init(void); - /* Main Example --------------------------------------------------------------*/ void lis2doc_wake_up(void) { @@ -206,105 +172,3 @@ void lis2doc_wake_up(void) } } } - -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len); -#endif - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, - uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg, - I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); -#elif defined(STEVAL_MKI109V3) - reg |= 0x80; - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET); - HAL_SPI_Transmit(handle, ®, 1, 1000); - HAL_SPI_Receive(handle, bufp, len, 1000); - HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET); -#elif defined(SPC584B_DIS) - i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len); -#endif - return 0; -} - -/* - * @brief Write generic device register (platform dependent) - * - * @param tx_buffer buffer to transmit - * @param len number of byte to send - * - */ -static void tx_com(uint8_t *tx_buffer, uint16_t len) -{ -#if defined(NUCLEO_F411RE) - HAL_UART_Transmit(&huart2, tx_buffer, len, 1000); -#elif defined(STEVAL_MKI109V3) - CDC_Transmit_FS(tx_buffer, len); -#elif defined(SPC584B_DIS) - sd_lld_write(&SD2, tx_buffer, len); -#endif -} - -/* - * @brief platform specific delay (platform dependent) - * - * @param ms delay in ms - * - */ -static void platform_delay(uint32_t ms) -{ -#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) - HAL_Delay(ms); -#elif defined(SPC584B_DIS) - osalThreadDelayMilliseconds(ms); -#endif -} - -/* - * @brief platform specific initialization (platform dependent) - */ -static void platform_init(void) -{ -#if defined(STEVAL_MKI109V3) - TIM3->CCR1 = PWM_3V3; - TIM3->CCR2 = PWM_3V3; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); - HAL_Delay(1000); -#endif -} diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.c new file mode 100644 index 000000000..c8579e051 --- /dev/null +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.c @@ -0,0 +1,84 @@ + +// #include "lis2doc.h" + +#ifdef SUPPORT_AT_CMD +#include "at_cmd_api.h" +#include "pm_control.h" +#include "lis2doc_porting.h" + +#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) +#define LIS2DOC_MAX_ARGC 8 +#define LIS2DOC_MAX_ARGV_LEN 64 + +#define LIS2DOC_SUCCESS 0 +#define LIS2DOC_FAILED (-1) + +static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen, + uint8_t argv[LIS2DOC_MAX_ARGC][LIS2DOC_MAX_ARGV_LEN], uint32_t* argc) +{ + uint32_t pos = 0; + *argc = 0; + + for (uint32_t i = 0; i < paraLen; i++) { + if ((para[i] == ' ' || para[i] == '\n') && pos != 0) { + argv[*argc][pos] = '\0'; + *argc += 1; + pos = 0; + if (*argc >= LIS2DOC_MAX_ARGC) { + return LIS2DOC_FAILED; + } + } else { + argv[*argc][pos] = para[i]; + pos++; + if (pos >= LIS2DOC_MAX_ARGV_LEN) { + return LIS2DOC_FAILED; + } + } + } + if (pos != 0) { + *argc += 1; + } + + return LIS2DOC_SUCCESS; +} + + +static uint32_t lis2doc_do_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[LIS2DOC_MAX_ARGC][LIS2DOC_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != LIS2DOC_SUCCESS) { + LIS_ERROR("LIS2DOCTEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + if (argc != 1) { + LIS_ERROR("LIS2DOCTEST ATCMD Set Parameter Failed\n"); + return ERRCODE_FAIL; + } + char *mode = (char*)argv[0]; + if (strcmp(mode, "activity") == 0) { + lis2doc_activity(); + } else if (strcmp(mode, "wakeup") == 0) { + lis2doc_wake_up(); + } else if (strcmp(mode, "selftest") == 0) { + lis2doc_self_test(); + } else if (strcmp(mode, "readsingle") == 0) { + lis2doc_read_data_single(); + } + return ERRCODE_SUCC; +} + +static const at_cmd_table_t g_lis2doc_cmd[] = { + { (char *)"AT^LIS2DOCTEST", lis2doc_do_test, (char *)"aac enable" }, +}; + +at_cmd_table_t *get_lis2doc_cmd_table(uint32_t *cmd_count) +{ + *cmd_count = ARRAY_COUNT(g_lis2doc_cmd); + return (at_cmd_table_t *)g_lis2doc_cmd; +} + +#endif diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.h b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.h new file mode 100644 index 000000000..fc4000adc --- /dev/null +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_at_cmd.h @@ -0,0 +1,32 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Provides at cmd register func \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-07-20, Create file. \n + */ +#ifndef LIS2DOC_AT_PROCESS_H +#define LIS2DOC_AT_PROCESS_H + +#include +#include +#include "errcode.h" +#include "soc_osal.h" +#include "at_cmd_api.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +at_cmd_table_t *get_lis2doc_cmd_table(uint32_t *cmd_count); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c new file mode 100644 index 000000000..97831f054 --- /dev/null +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.c @@ -0,0 +1,235 @@ +/* + * This example was developed using the following STMicroelectronics + * evaluation boards: + * + * - STEVAL_MKI109V3 + STEVAL-MKI179V1 + * - NUCLEO_F411RE + X_NUCLEO_IKS01A3 + * - DISCOVERY_SPC584B + X_NUCLEO_IKS01A3 + * + * and STM32CubeMX tool with STM32CubeF4 MCU Package + * + * Used interfaces: + * + * STEVAL_MKI109V3 - Host side: USB (Virtual COM) + * - Sensor side: SPI(Default) / I2C(supported) + * + * NUCLEO_STM32F411RE - Host side: UART(COM) to USB bridge + * - I2C(Default) / SPI(supported) + * + * DISCOVERY_SPC584B - Host side: UART(COM) to USB bridge + * - Sensor side: I2C(Default) / SPI(supported) + * + * If you need to run this example on a different hardware platform a + * modification of the functions: `platform_write`, `platform_read`, + * `tx_com` and 'platform_init' is required. + * + */ + +//#define STEVAL_MKI109V3 /* little endian */ +//#define NUCLEO_F411RE /* little endian */ +//#define SPC584B_DIS /* big endian */ + +/* ATTENTION: By default the driver is little endian. If you need switch + * to big endian please see "Endianness definitions" in the + * header file of the driver (_reg.h). + */ + + +/* Includes ------------------------------------------------------------------*/ +#include +#include +#include +#include "lis2doc_reg.h" +#include "lis2doc_porting.h" +#include "osal_timer.h" +#include "osal_mutex.h" +#include "pinctrl.h" +#include "chip_io.h" +#include "time.h" +#include "i2c.h" +#include "gpio.h" +#include "hal_gpio.h" +#include "hal_i2c.h" +#include "soc_osal.h" +#include "tcxo.h" +uint8_t SENSOR_BUS = 0; + +typedef union { + int16_t i16bit[3]; +} axis3bit16_t; + +/* Private macro -------------------------------------------------------------*/ +#define BOOT_TIME 20 //ms + +/* Self-test recommended samples */ +#define SELF_TEST_SAMPLES 5 + +/* Self-test positive difference */ +#define ST_MIN_POS 70.0f +#define ST_MAX_POS 1500.0f + +/* Private variables ---------------------------------------------------------*/ +static lis2doc_mode_t pm; +static axis3bit16_t data_raw_acceleration[SELF_TEST_SAMPLES]; +static float acceleration_mg[SELF_TEST_SAMPLES][3]; +static uint8_t whoamI, rst; +static uint8_t tx_buffer[1000]; +uint8_t g_acc_handle=0; +static uint8_t g_acc_installed = 0; + +#define LIS2DOC_I2C_BUS I2C_BUS_2 +#define LIS2DOC_I2C_DEV_8ADDR LIS2DOC_I2C_ADD_H +#define LIS2DOC_I2C_TIME_MAX 3 + +/* Utility functions ---------------------------------------------------------*/ +static inline float ABSF(float _x) +{ + return (_x < 0.0f) ? -(_x) : _x; +} +/* + * @brief platform specific initialization (platform dependent) + */ +void platform_init(void) +{ + errcode_t result; + /* init i2c */ + if ( g_acc_installed == 1 ) + return ; + + result = uapi_i2c_master_init(LIS2DOC_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ + if (result != ERRCODE_SUCC) { + LIS_ERROR("lis2doc i2c init fail! ret=0x%x", result); + return ; + } + + LIS_WARNING("lis2doc:i2c_id = %d i2c_speed = %d slave_addr = 0x%x \r\n", + LIS2DOC_I2C_BUS, 400000, LIS2DOC_I2C_DEV_8ADDR); + + g_acc_installed = 1; + + return ; +} + +/* + * @brief Write generic device register (platform dependent) + * + * @param handle customizable argument. In this examples is used in + * order to select the correct sensor bus handler. + * @param reg register to write + * @param bufp pointer to data to write in register reg + * @param len number of consecutive register to write + * + */ +int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, + uint16_t len) +{ + + errcode_t ret; + uint32_t retry; + i2c_data_t data; + uint8_t *write_data = NULL; + uint16_t send_len; + uint8_t *data_buf=bufp; + uint16_t data_len=len; + + platform_init(); + send_len = data_len + sizeof(uint8_t); + write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); + if (write_data == NULL) { + LIS_ERROR("lis2doc send buff malloc fail!"); + return ERRCODE_FAIL; + } + write_data[0] = reg; + ret = (uint32_t)memcpy_s(write_data + sizeof(uint8_t), send_len - sizeof(uint8_t), data_buf, data_len); + if (ret != EOK) { + LIS_ERROR("lis2doc send_buf content copy fail! ret=0x%x", ret); + return ret; + } + + data.send_buf = write_data; + data.send_len = send_len; + data.receive_buf = NULL; + data.receive_len = 0; + + for (retry = 0; retry < LIS2DOC_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_write(LIS2DOC_I2C_BUS, LIS2DOC_I2C_DEV_8ADDR, &data); + if (ret == ERRCODE_SUCC) { + break; + } + } + if (ret != ERRCODE_SUCC) { + LIS_ERROR("lis2doc data write fail! ret=0x%x", ret); + return ret; + } + + osal_kfree(write_data); + return 0; +} + +/* + * @brief Read generic device register (platform dependent) + * + * @param handle customizable argument. In this examples is used in + * order to select the correct sensor bus handler. + * @param reg register to read + * @param bufp pointer to buffer that store the data read + * @param len number of consecutive register to read + * + */ +int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, + uint16_t len) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + + platform_init(); + memset_s(bufp, len, 0, len); + data.send_buf = ® + data.send_len = 1; + data.receive_buf = bufp; + data.receive_len = len; + + for (retry = 0; retry < LIS2DOC_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_writeread(LIS2DOC_I2C_BUS, LIS2DOC_I2C_DEV_8ADDR, &data); + if (ret == ERRCODE_SUCC) { + break; + } + } + if (ret != ERRCODE_SUCC) { + LIS_ERROR("lis2doc data read fail! ret=0x%x", ret); + return ret; + } + + return ERRCODE_SUCC; +} + +/* + * @brief Write generic device register (platform dependent) + * + * @param tx_buffer buffer to transmit + * @param len number of byte to send + * + */ +void tx_com(uint8_t *tx_buffer, uint16_t len) +{ + //TODO : 打印日志 + LIS_LOG("%s",tx_buffer); +} + +/* + * @brief platform specific delay (platform dependent) + * + * @param ms delay in ms + * + */ +#include "tcxo.h" +void platform_delay(uint32_t ms) +{ + uapi_tcxo_delay_ms(ms); +} + + + + + diff --git a/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.h b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.h new file mode 100644 index 000000000..4cb4a721d --- /dev/null +++ b/code/sdk/drivers/peripheral/acc/lis2doc_STdC/lis2doc_porting.h @@ -0,0 +1,47 @@ +#ifndef __LIS2DOC_PORTING_H__ +#define __LIS2DOC_PORTING_H__ +#include +#include +#include "debug_print.h" +#include "lis2doc_reg.h" + +#define LIS_DEBUG + +#ifdef LIS_DEBUG +#define LIS_LOG(fmt, ...) \ + do { \ + PRINT(fmt"\r\n", ##__VA_ARGS__); \ + } while (0) +#else +#define LIS_LOG(ftm, ...) +#endif + +#define LIS_ERROR(x, ...) \ + do { \ + PRINT("[ERROR]%s(%d): "x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) + +#define LIS_WARNING(x, ...) \ + do { \ + PRINT("[WARNING]%s(%d): "x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) + + + +int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, uint16_t len); +int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len); +void tx_com( uint8_t *tx_buffer, uint16_t len ); +void platform_delay(uint32_t ms); +void platform_init(void); + +extern uint8_t SENSOR_BUS ; + +/******test functions********/ + +void lis2doc_activity(void); +void lis2doc_wake_up(void); +void lis2doc_self_test(void); +void lis2doc_read_data_single(void); + + +#endif \ No newline at end of file