#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"
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
'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",
'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',
#===============================================================================
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
* @retval interface status (MANDATORY: return 0 -> no Error)\r
*\r
*/\r
-int32_t __weak lis2doc_read_reg(stmdev_ctx_t *ctx, uint8_t reg,\r
+// int32_t __weak lis2doc_read_reg(stmdev_ctx_t *ctx, uint8_t reg,\r
+int32_t lis2doc_read_reg(stmdev_ctx_t *ctx, uint8_t reg,\r
uint8_t *data,\r
uint16_t len)\r
{\r
#include <stdint.h>\r
#include <stddef.h>\r
#include <math.h>\r
+#include <sys/cdefs.h>\r
\r
/** @addtogroup LIS2DOC\r
* @{\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
-\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
+#include "lis2doc_porting.h"\r
\r
/* Private macro -------------------------------------------------------------*/\r
#define BOOT_TIME 20 //ms\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
-\r
\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_activity(void)\r
}\r
}\r
}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}
\ No newline at end of file
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
-\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
+#include "lis2doc_porting.h"\r
\r
/* Private macro -------------------------------------------------------------*/\r
#define BOOT_TIME 20 //ms\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
-\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_free_fall(void)\r
{\r
}\r
}\r
}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}
\ No newline at end of file
* header file of the driver (_reg.h).\r
*/\r
\r
-\r
-#if defined(STEVAL_MKI109V3)\r
-/* MKI109V3: Define communication interface */\r
-#define SENSOR_BUS hspi2\r
-/* MKI109V3: Vdd and Vddio power supply values */\r
-#define PWM_3V3 915\r
-\r
-#elif defined(NUCLEO_F411RE)\r
-/* NUCLEO_F411RE: Define communication interface */\r
-#define SENSOR_BUS hi2c1\r
-\r
-#elif defined(SPC584B_DIS)\r
-/* DISCOVERY_SPC584B: Define communication interface */\r
-#define SENSOR_BUS I2CD1\r
-\r
-#endif\r
-\r
/* Includes ------------------------------------------------------------------*/\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
+#include "lis2doc_porting.h"\r
\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
\r
/* Private macro -------------------------------------------------------------*/\r
#define BOOT_TIME 20 //ms\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
-\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_orientation(void)\r
{\r
}\r
}\r
\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}
\ No newline at end of file
*/\r
\r
\r
-#if defined(STEVAL_MKI109V3)\r
-/* MKI109V3: Define communication interface */\r
-#define SENSOR_BUS hspi2\r
-/* MKI109V3: Vdd and Vddio power supply values */\r
-#define PWM_3V3 915\r
-\r
-#elif defined(NUCLEO_F411RE)\r
-/* NUCLEO_F411RE: Define communication interface */\r
-#define SENSOR_BUS hi2c1\r
-\r
-#elif defined(SPC584B_DIS)\r
-/* DISCOVERY_SPC584B: Define communication interface */\r
-#define SENSOR_BUS I2CD1\r
-\r
-#endif\r
\r
/* Includes ------------------------------------------------------------------*/\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
+#include "lis2doc_porting.h"\r
\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
\r
/* Private macro -------------------------------------------------------------*/\r
#define BOOT_TIME 20 //ms\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
-\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_read_data_polling(void)\r
{\r
}\r
}\r
}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}\r
*/\r
\r
\r
-#if defined(STEVAL_MKI109V3)\r
-/* MKI109V3: Define communication interface */\r
-#define SENSOR_BUS hspi2\r
-/* MKI109V3: Vdd and Vddio power supply values */\r
-#define PWM_3V3 915\r
-\r
-#elif defined(NUCLEO_F411RE)\r
-/* NUCLEO_F411RE: Define communication interface */\r
-#define SENSOR_BUS hi2c1\r
-\r
-#elif defined(SPC584B_DIS)\r
-/* DISCOVERY_SPC584B: Define communication interface */\r
-#define SENSOR_BUS I2CD1\r
-\r
-#endif\r
\r
/* Includes ------------------------------------------------------------------*/\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
+#include "lis2doc_porting.h"\r
\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
\r
/* Private macro -------------------------------------------------------------*/\r
#define BOOT_TIME 20 //ms\r
static uint8_t tx_buffer[1000];\r
static lis2doc_ctrl4_int1_pad_ctrl_t ctrl4_int1_pad;\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_read_data_single(void)\r
/* Read samples in polling mode (no int) */\r
while (1) {\r
/* polling on DRDY signal */\r
- if (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_0)) {\r
+ // if (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_0)) {\r
+ if (1 == 0) {\r
/* Read acceleration data */\r
memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));\r
lis2doc_acceleration_raw_get(&dev_ctx, data_raw_acceleration);\r
data_raw_acceleration[1]);\r
acceleration_mg[2] = lis2doc_from_fs2_lp1_to_mg(\r
data_raw_acceleration[2]);\r
-#ifdef STEVAL_MKI109V3\r
\r
- /* After data ready signal rise, is not possible to set a\r
- * new trigger before 175us.\r
- * I2C read data operation fit this constraint while SPI need\r
- * a wait loop in order to guarantee it.\r
- */\r
- for (int i = 0; i < 0x3FF; i++);\r
-\r
-#endif\r
lis2doc_data_rate_set(&dev_ctx, LIS2DOC_XL_SET_SW_TRIG);\r
sprintf((char *)tx_buffer,\r
"Acceleration [mg]:%4.2f\t%4.2f\t%4.2f\r\n",\r
}\r
}\r
\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}\r
* header file of the driver (_reg.h).\r
*/\r
\r
-\r
-#if defined(STEVAL_MKI109V3)\r
-/* MKI109V3: Define communication interface */\r
-#define SENSOR_BUS hspi2\r
-/* MKI109V3: Vdd and Vddio power supply values */\r
-#define PWM_3V3 915\r
-\r
-#elif defined(NUCLEO_F411RE)\r
-/* NUCLEO_F411RE: Define communication interface */\r
-#define SENSOR_BUS hi2c1\r
-\r
-#elif defined(SPC584B_DIS)\r
-/* DISCOVERY_SPC584B: Define communication interface */\r
-#define SENSOR_BUS I2CD1\r
-\r
-#endif\r
-\r
/* Includes ------------------------------------------------------------------*/\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
-\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
+#include "lis2doc_porting.h"\r
\r
/* Private macro -------------------------------------------------------------*/\r
#define BOOT_TIME 20 //ms\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_read_data_fifo(void)\r
}\r
}\r
\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
-\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
+#include "lis2doc_porting.h"\r
\r
typedef union {\r
int16_t i16bit[3];\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
-\r
/* Utility functions ---------------------------------------------------------*/\r
static inline float ABSF(float _x)\r
{\r
lis2doc_power_mode_set(dev_ctx, pm);\r
\r
lis2doc_data_rate_set(dev_ctx, LIS2DOC_XL_ODR_50Hz);\r
- HAL_Delay(100);\r
+ platform_delay(100);\r
/* Flush old samples */\r
flush_samples(dev_ctx);\r
\r
\r
/* Enable self test mode */\r
lis2doc_self_test_set(dev_ctx, LIS2DOC_XL_ST_POSITIVE);\r
- HAL_Delay(100);\r
+ platform_delay(100);\r
i = 0;\r
/* Flush old samples */\r
flush_samples(dev_ctx);\r
}\r
}\r
\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}\r
*/\r
\r
\r
-#if defined(STEVAL_MKI109V3)\r
-/* MKI109V3: Define communication interface */\r
-#define SENSOR_BUS hspi2\r
-/* MKI109V3: Vdd and Vddio power supply values */\r
-#define PWM_3V3 915\r
-\r
-#elif defined(NUCLEO_F411RE)\r
-/* NUCLEO_F411RE: Define communication interface */\r
-#define SENSOR_BUS hi2c1\r
-\r
-#elif defined(SPC584B_DIS)\r
-/* DISCOVERY_SPC584B: Define communication interface */\r
-#define SENSOR_BUS I2CD1\r
-\r
-#endif\r
\r
/* Includes ------------------------------------------------------------------*/\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
-\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
+#include "lis2doc_porting.h"\r
\r
\r
/* Private macro -------------------------------------------------------------*/\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_double_tap(void)\r
}\r
}\r
}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}
\ No newline at end of file
*/\r
\r
\r
-#if defined(STEVAL_MKI109V3)\r
-/* MKI109V3: Define communication interface */\r
-#define SENSOR_BUS hspi2\r
-/* MKI109V3: Vdd and Vddio power supply values */\r
-#define PWM_3V3 915\r
-\r
-#elif defined(NUCLEO_F411RE)\r
-/* NUCLEO_F411RE: Define communication interface */\r
-#define SENSOR_BUS hi2c1\r
-\r
-#elif defined(SPC584B_DIS)\r
-/* DISCOVERY_SPC584B: Define communication interface */\r
-#define SENSOR_BUS I2CD1\r
-\r
-#endif\r
-\r
/* Includes ------------------------------------------------------------------*/\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
-\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
+#include "lis2doc_porting.h"\r
\r
\r
/* Private macro -------------------------------------------------------------*/\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_single_tap(void)\r
}\r
}\r
}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}\r
#include <string.h>\r
#include <stdio.h>\r
#include "lis2doc_reg.h"\r
-\r
-#if defined(NUCLEO_F411RE)\r
-#include "stm32f4xx_hal.h"\r
-#include "usart.h"\r
-#include "gpio.h"\r
-#include "i2c.h"\r
-\r
-#elif defined(STEVAL_MKI109V3)\r
-#include "stm32f4xx_hal.h"\r
-#include "usbd_cdc_if.h"\r
-#include "gpio.h"\r
-#include "spi.h"\r
-#include "tim.h"\r
-\r
-#elif defined(SPC584B_DIS)\r
-#include "components.h"\r
-#endif\r
-\r
+#include "lis2doc_porting.h"\r
/* Private macro -------------------------------------------------------------*/\r
#define BOOT_TIME 20 //ms\r
\r
static uint8_t whoamI, rst;\r
static uint8_t tx_buffer[1000];\r
\r
-/* Extern variables ----------------------------------------------------------*/\r
-\r
-/* Private functions ---------------------------------------------------------*/\r
-/*\r
- * WARNING:\r
- * Functions declare in this section are defined at the end of this file\r
- * and are strictly related to the hardware platform used.\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len);\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len);\r
-static void tx_com( uint8_t *tx_buffer, uint16_t len );\r
-static void platform_delay(uint32_t ms);\r
-static void platform_init(void);\r
-\r
/* Main Example --------------------------------------------------------------*/\r
void lis2doc_wake_up(void)\r
{\r
}\r
}\r
}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to write\r
- * @param bufp pointer to data to write in register reg\r
- * @param len number of consecutive register to write\r
- *\r
- */\r
-static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Write(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_write(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Read generic device register (platform dependent)\r
- *\r
- * @param handle customizable argument. In this examples is used in\r
- * order to select the correct sensor bus handler.\r
- * @param reg register to read\r
- * @param bufp pointer to buffer that store the data read\r
- * @param len number of consecutive register to read\r
- *\r
- */\r
-static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,\r
- uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_I2C_Mem_Read(handle, LIS2DOC_I2C_ADD_H, reg,\r
- I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- reg |= 0x80;\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);\r
- HAL_SPI_Transmit(handle, ®, 1, 1000);\r
- HAL_SPI_Receive(handle, bufp, len, 1000);\r
- HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);\r
-#elif defined(SPC584B_DIS)\r
- i2c_lld_read(handle, LIS2DOC_I2C_ADD_H & 0xFE, reg, bufp, len);\r
-#endif\r
- return 0;\r
-}\r
-\r
-/*\r
- * @brief Write generic device register (platform dependent)\r
- *\r
- * @param tx_buffer buffer to transmit\r
- * @param len number of byte to send\r
- *\r
- */\r
-static void tx_com(uint8_t *tx_buffer, uint16_t len)\r
-{\r
-#if defined(NUCLEO_F411RE)\r
- HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);\r
-#elif defined(STEVAL_MKI109V3)\r
- CDC_Transmit_FS(tx_buffer, len);\r
-#elif defined(SPC584B_DIS)\r
- sd_lld_write(&SD2, tx_buffer, len);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific delay (platform dependent)\r
- *\r
- * @param ms delay in ms\r
- *\r
- */\r
-static void platform_delay(uint32_t ms)\r
-{\r
-#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)\r
- HAL_Delay(ms);\r
-#elif defined(SPC584B_DIS)\r
- osalThreadDelayMilliseconds(ms);\r
-#endif\r
-}\r
-\r
-/*\r
- * @brief platform specific initialization (platform dependent)\r
- */\r
-static void platform_init(void)\r
-{\r
-#if defined(STEVAL_MKI109V3)\r
- TIM3->CCR1 = PWM_3V3;\r
- TIM3->CCR2 = PWM_3V3;\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);\r
- HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);\r
- HAL_Delay(1000);\r
-#endif\r
-}\r
--- /dev/null
+
+// #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
--- /dev/null
+/**
+ * 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 <stdint.h>
+#include <stdio.h>
+#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
--- /dev/null
+/*
+ * 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 <string.h>
+#include <stdint.h>
+#include <stdio.h>
+#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);
+}
+
+
+
+
+
--- /dev/null
+#ifndef __LIS2DOC_PORTING_H__
+#define __LIS2DOC_PORTING_H__
+#include <string.h>
+#include <stdio.h>
+#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