Commit d022f330 authored by aohui.li's avatar aohui.li

LIS2DW12支持振动唤醒

parent ce5843c9
build/
sdkconfig.old
*.code-workspace
.vscode
.history/
managed_components
.cache/
\ No newline at end of file
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
"C_Cpp.intelliSenseEngine": "default", "C_Cpp.intelliSenseEngine": "default",
"idf.espIdfPath": "/Users/cn/esp/esp-idf", "idf.espIdfPath": "/Users/cn/esp/esp-idf",
"idf.toolsPath": "/Users/cn/.espressif", "idf.toolsPath": "/Users/cn/.espressif",
"idf.pythonInstallPath": "/opt/homebrew/bin/python3", "idf.pythonInstallPath": "/Users/cn/anaconda3/bin/python",
"idf.customExtraVars": { "idf.customExtraVars": {
"IDF_TARGET": "esp32c3" "IDF_TARGET": "esp32c3"
}, },
"idf.openOcdConfigs": [ "idf.openOcdConfigs": [
"board/esp32c3-builtin.cfg" "board/esp32c3-builtin.cfg"
] ],
"idf.port": "/dev/tty.usbserial-11130",
"idf.flashType": "UART"
} }
file(GLOB_RECURSE ALGORITHM_SOURCES ${CMAKE_CURRENT_LIST_DIR}/./*.c)
set(include_dirs ${CMAKE_CURRENT_LIST_DIR}/./)
idf_component_register(SRCS ${ALGORITHM_SOURCES}
INCLUDE_DIRS ${include_dirs})
\ No newline at end of file
## Contributing guide
This document serves as a checklist before contributing to this repository. It includes links to additional information if topics are unclear to you.
This guide mainly focuses on the proper use of Git.
### 1. Before opening an issue
To report a bug/request please enter the issue in the right repository.
Please check the following boxes before posting an issue:
- [ ] `Make sure you are using the latest commit (major releases are Tagged, but corrections are available as new commits).`
- [ ] `Make sure your issue is a question/feedback/suggestion RELATED TO the software provided in this repository.` Otherwise, it should be discussed on the [ST Community forum](https://community.st.com/s/).
- [ ] `Make sure your issue is not already reported/fixed on GitHub or discussed in a previous issue.` Please refer to the tab issue for the list of issues and pull-requests. Do not forget to browse to the **closed** issues.
### 2. Posting the issue
When you have checked the previous boxes, you will find two templates (Bug Report or Other Issue) available in the **Issues** tab of the repository.
### 3. Pull Requests
STMicroelectronics is happy to receive contributions from the community, based on an initial Contributor License Agreement (CLA) procedure.
* If you are an individual writing original source code and you are sure **you own the intellectual property**, then you need to sign an Individual CLA (https://cla.st.com).
* If you work for a company that wants also to allow you to contribute with your work, your company needs to provide a Corporate CLA (https://cla.st.com) mentioning your GitHub account name.
* If you are not sure that a CLA (Individual or Corporate) has been signed for your GitHub account, you can check here (https://cla.st.com).
Please note that:
* The Corporate CLA will always take precedence over the Individual CLA.
* One CLA submission is sufficient for any project proposed by STMicroelectronics.
#### How to proceed
* We recommend to engage first a communication through an issue, in order to present your proposal and just to confirm that it corresponds to a STMicroelectronics domain or scope.
* Then fork the project to your GitHub account to further develop your contribution. Please use the latest commit version.
* Please submit one Pull Request for one new feature or proposal. This will facilitate the analysis and the final merge if accepted.
BSD 3-Clause License
Copyright (c) 2019, STMicroelectronics
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
![latest tag](https://img.shields.io/github/v/tag/STMicroelectronics/lis2dw12-pid.svg?color=brightgreen)
# 1 - Introduction
Sensor driver for LIS2DW12 sensor written in C programming language. This repository contains the sensor driver files (.h and .c) to be included, or linked directly as a git submodule, in your project. The driver is MISRA compliant and the documentation can be generated using the [Doxygen](http://www.doxygen.org/) tool.
In order to `clone` the complete content of the repository folder, use the command:
```
git clone https://github.com/STMicroelectronics/LIS2DW12-PID/
```
Some examples of driver usage can be found [here](https://github.com/STMicroelectronics/STMems_Standard_C_drivers).
------
# 2 - Integration details
The driver is platform-independent, you only need to define two functions for read and write transactions from the sensor hardware bus (ie. SPI or I²C) and an optional one to implement a delay of millisecond granularity. **A few devices integrate an extra bit in the communication protocol in order to enable multi read/write access, this bit must be managed in the read and write functions defined by the user.** Please refer to the read and write implementation in the [reference examples](https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lis2dw12_STdC/examples).
### 2.a Source code integration
- Include in your project the driver files of the sensor (.h and .c)
- Define in your code the read and write functions that use the I²C or SPI platform driver like the following:
```
/** Please note that is MANDATORY: return 0 -> no Error.**/
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)
/** Optional (may be required by driver) **/
void platform_delay(uint32_t millisec)
```
- Declare and initialize the structure of the device interface:
```
xxxxxxx_ctx_t dev_ctx; /** xxxxxxx is the used part number **/
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
dev_ctx.mdelay = platform_delay;
```
- If needed by the platform read and write functions, initialize the handle parameter:
```
dev_ctx.handle = &platform_handle;
```
Some integration examples can be found [here](https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lis2dw12_STdC/examples).
### 2.b Required properties
> - A standard C language compiler for the target MCU
> - A C library for the target MCU and the desired interface (ie. SPI, I²C)
------
**More Information: [http://www.st.com](http://st.com/MEMS)**
**Copyright (C) 2021 STMicroelectronics**
\ No newline at end of file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Release Notes for LIS2DW12 Component</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<link rel="stylesheet" href="_htmresc/mini-st_2020.css" />
<link rel="icon" type="image/x-icon" href="_htmresc/favicon.png" />
</head>
<body>
<div class="row">
<div class="col-sm-12 col-lg-4">
<center>
<h1 id="release-notes-for-lis2dw12-component-driver">Release Notes for LIS2DW12 Component Driver</h1>
<p>Copyright © 2021 STMicroelectronics<br />
</p>
<a href="https://www.st.com" class="logo"><img src="_htmresc/st_logo_2020.png" alt="ST logo" /></a>
</center>
<h1 id="license">License</h1>
<p>This software component is licensed by ST under BSD 3-Clause license, the “License”. You may not use this component except in compliance with the License. You may obtain a copy of the License at:</p>
<p><a href="https://opensource.org/licenses/BSD-3-Clause">BSD 3-Clause license</a></p>
<h1 id="purpose">Purpose</h1>
<p>This directory contains the LIS2DW12 component drivers.</p>
</div>
<div class="col-sm-12 col-lg-8">
<h1 id="update-history">Update history</h1>
<div class="collapse">
<input type="checkbox" id="collapse-section1" aria-hidden="true"> <label for="collapse-section1" aria-hidden="true">V1.0.0 / 18-June-2021</label>
<div>
<h2 id="main-changes">Main changes</h2>
<h3 id="first-release">First release</h3>
<ul>
<li>First official release [ref. DS v8.0]</li>
</ul>
<h2 id="section"></h2>
</div>
<input type="checkbox" id="collapse-section2" aria-hidden="true"> <label for="collapse-section2" aria-hidden="true">V1.1.0 / 18-May-2023</label>
<div>
<h2 id="main-changes-1">Main changes</h2>
<h3 id="section-1"></h3>
<ul>
<li>Fix wrong comment for two ff APIs</li>
<li>Add __weak directive to read/write registers routines</li>
<li>Extend stmdev_ctx_t structure with mdelay callback</li>
<li>repo name changed adding ‘-pid’ extension.</li>
</ul>
<h2 id="section-2"></h2>
</div>
<input type="checkbox" id="collapse-section3" aria-hidden="true"> <label for="collapse-section3" aria-hidden="true">V2.0.0 / 20-Mar-2024</label>
<div>
<h2 id="main-changes-2">Main changes</h2>
<h3 id="section-3"></h3>
<ul>
<li>Fixed code style (Artistic Style Version 3.4.13)</li>
<li>Add “const” to ctx arg for all APIs</li>
</ul>
<h2 id="section-4"></h2>
</div>
<input type="checkbox" id="collapse-section4" aria-hidden="true"> <label for="collapse-section4" aria-hidden="true">V2.0.1 / 20-Jun-2024</label>
<div>
<h2 id="main-changes-3">Main changes</h2>
<h3 id="section-5"></h3>
<ul>
<li>updated README.md file with tag reference and mdelay description</li>
</ul>
<h2 id="section-6"></h2>
</div>
<input type="checkbox" id="collapse-section5" checked aria-hidden="true"> <label for="collapse-section5" aria-hidden="true">V2.1.0 / 07-Jul-2025</label>
<div>
<h2 id="main-changes-4">Main changes</h2>
<h3 id="section-7"></h3>
<ul>
<li>Fix driver formatting options</li>
<li>Added pointer to private data in stmdev_ctx_t</li>
</ul>
<h2 id="section-8"></h2>
</div>
</div>
</div>
</div>
<footer class="sticky">
<div class="columns">
<div class="column" style="width:95%;">
<p>For complete documentation on LIS2DW12, visit: <a href="https://www.st.com/content/st_com/en/products/mems-and-sensors/accelerometers/lis2dw12.html">LIS2DW12</a></p>
</div><div class="column" style="width:5%;">
<p><abbr title="Based on template cx566953 version 2.0">Info</abbr></p>
</div>
</div>
</footer>
</body>
</html>
---
pagetitle: Release Notes for LIS2DW12 Component
lang: en
header-includes: <link rel="icon" type="image/x-icon" href="_htmresc/favicon.png" />
---
::: {.row}
::: {.col-sm-12 .col-lg-4}
<center>
# Release Notes for LIS2DW12 Component Driver
Copyright &copy; 2021 STMicroelectronics\
[![ST logo](_htmresc/st_logo_2020.png)](https://www.st.com){.logo}
</center>
# License
This software component is licensed by ST under BSD 3-Clause license, the "License".
You may not use this component except in compliance with the License. You may obtain a copy of the License at:
[BSD 3-Clause license](https://opensource.org/licenses/BSD-3-Clause)
# Purpose
This directory contains the LIS2DW12 component drivers.
:::
::: {.col-sm-12 .col-lg-8}
# Update history
::: {.collapse}
<input type="checkbox" id="collapse-section1" aria-hidden="true">
<label for="collapse-section1" aria-hidden="true">V1.0.0 / 18-June-2021</label>
<div>
## Main changes
### First release
- First official release [ref. DS v8.0]
##
</div>
<input type="checkbox" id="collapse-section2" aria-hidden="true">
<label for="collapse-section2" aria-hidden="true">V1.1.0 / 18-May-2023</label>
<div>
## Main changes
###
- Fix wrong comment for two ff APIs
- Add __weak directive to read/write registers routines
- Extend stmdev_ctx_t structure with mdelay callback
- repo name changed adding '-pid' extension.
##
</div>
<input type="checkbox" id="collapse-section3" aria-hidden="true">
<label for="collapse-section3" aria-hidden="true">V2.0.0 / 20-Mar-2024</label>
<div>
## Main changes
###
- Fixed code style (Artistic Style Version 3.4.13)
- Add "const" to ctx arg for all APIs
##
</div>
<input type="checkbox" id="collapse-section4" aria-hidden="true">
<label for="collapse-section4" aria-hidden="true">V2.0.1 / 20-Jun-2024</label>
<div>
## Main changes
###
- updated README.md file with tag reference and mdelay description
##
</div>
<input type="checkbox" id="collapse-section5" checked aria-hidden="true">
<label for="collapse-section5" aria-hidden="true">V2.1.0 / 07-Jul-2025</label>
<div>
## Main changes
###
- Fix driver formatting options
- Added pointer to private data in stmdev_ctx_t
##
</div>
:::
:::
:::
<footer class="sticky">
::: {.columns}
::: {.column width="95%"}
For complete documentation on LIS2DW12,
visit:
[LIS2DW12](https://www.st.com/content/st_com/en/products/mems-and-sensors/accelerometers/lis2dw12.html)
:::
::: {.column width="5%"}
<abbr title="Based on template cx566953 version 2.0">Info</abbr>
:::
:::
</footer>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -12,7 +12,7 @@ dependencies: ...@@ -12,7 +12,7 @@ dependencies:
idf: idf:
source: source:
type: idf type: idf
version: 5.4.1 version: 5.5.0
direct_dependencies: direct_dependencies:
- espressif/led_strip - espressif/led_strip
manifest_hash: a9af7824fb34850fbe175d5384052634b3c00880abb2d3a7937e666d07603998 manifest_hash: a9af7824fb34850fbe175d5384052634b3c00880abb2d3a7937e666d07603998
......
Subproject commit f0326c61f95dbd6b69bd323fd5847a81476b7148
idf_component_register(SRCS "blink_example_main.c" idf_component_register(SRCS "blink_example_main.c" "lis2dw12.c"
INCLUDE_DIRS ".") INCLUDE_DIRS "."
REQUIRES "driver" "lis2dw12-pid" "esp_driver_i2c"
)
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "esp_log.h" #include "esp_log.h"
#include "led_strip.h" #include "led_strip.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "lis2dw12.h"
static const char *TAG = "example"; static const char *TAG = "example";
...@@ -76,12 +77,22 @@ static void blink_led(void) ...@@ -76,12 +77,22 @@ static void blink_led(void)
gpio_set_level(BLINK_GPIO, s_led_state); gpio_set_level(BLINK_GPIO, s_led_state);
} }
static void blink_led_g(void)
{
/* Set the GPIO level according to the state (LOW or HIGH)*/
gpio_set_level(9, s_led_state);
}
static void configure_led(void) static void configure_led(void)
{ {
ESP_LOGI(TAG, "Example configured to blink GPIO LED!"); ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
gpio_reset_pin(BLINK_GPIO); gpio_reset_pin(BLINK_GPIO);
/* Set the GPIO as a push/pull output */ /* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
gpio_reset_pin(9);
/* Set the GPIO as a push/pull output */
gpio_set_direction(9, GPIO_MODE_OUTPUT);
} }
#else #else
...@@ -93,12 +104,14 @@ void app_main(void) ...@@ -93,12 +104,14 @@ void app_main(void)
/* Configure the peripheral according to the LED type */ /* Configure the peripheral according to the LED type */
configure_led(); configure_led();
lis2dw12_init();
while (1) { while (1) {
ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF"); ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
blink_led(); blink_led();
blink_led_g();
/* Toggle the LED state */ /* Toggle the LED state */
s_led_state = !s_led_state; s_led_state = !s_led_state;
vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS); vTaskDelay(1000 / portTICK_PERIOD_MS);
} }
} }
#include "lis2dw12.h"
#include "esp_err.h"
#include "driver/i2c_master.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "freertos/idf_additions.h"
#include "lis2dw12_reg.h"
#include "esp_sleep.h"
#include <string.h>
#define I2C_MASTER_SCL_IO 18 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 19 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000
#define SLAVE_ADDR 0x19
#define DEFAULT_WAKEUP_PIN 5
#define DEFAULT_WAKEUP_LEVEL ESP_GPIO_WAKEUP_GPIO_HIGH
#define TAG "LIS2DW12"
stmdev_ctx_t dev_ctx;
i2c_master_bus_handle_t s_bus_handle = NULL;
i2c_master_dev_handle_t s_dev_handle = NULL;
static void lis2dw12_wake_config(void);
/**
* @brief i2c master initialization
*/
static void i2c_master_init(i2c_master_bus_handle_t *bus_handle, i2c_master_dev_handle_t *dev_handle)
{
i2c_master_bus_config_t bus_config = {
.i2c_port = I2C_MASTER_NUM,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, bus_handle));
i2c_device_config_t dev_config = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = SLAVE_ADDR,
.scl_speed_hz = I2C_MASTER_FREQ_HZ,
};
ESP_ERROR_CHECK(i2c_master_bus_add_device(*bus_handle, &dev_config, dev_handle));
}
/**
* @brief Read a sequence of bytes from a lis2dw12 sensor registers
*/
static long int lis2dw12_register_read(void* dev_handle, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
return i2c_master_transmit_receive((i2c_master_dev_handle_t)s_dev_handle, &reg_addr, 1, data, len, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
}
/**
* @brief Write a byte to a lis2dw12 sensor register
*/
static long int lis2dw12_register_write_byte(void* dev_handle, uint8_t reg_addr, const unsigned char *data, short unsigned int len)
{
uint8_t write_buf[2] = {reg_addr, *data};
return i2c_master_transmit((i2c_master_dev_handle_t)s_dev_handle, write_buf, sizeof(write_buf), I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
}
static void i2c_master_delay_ms(uint32_t millisec)
{
vTaskDelay(millisec / portTICK_PERIOD_MS);
}
static void WakeupEnable(void)
{
const gpio_config_t config = {
.pin_bit_mask = BIT(DEFAULT_WAKEUP_PIN),
.mode = GPIO_MODE_INPUT,
};
ESP_ERROR_CHECK(gpio_config(&config));
ESP_ERROR_CHECK(esp_deep_sleep_enable_gpio_wakeup(BIT(DEFAULT_WAKEUP_PIN), DEFAULT_WAKEUP_LEVEL));
}
void lis2dw12_init()
{
static uint8_t whoamI, rst;
uint8_t tx_buffer[1000];
ESP_LOGI(TAG, "LIS2DW12 Init");
gpio_set_direction(I2C_MASTER_SCL_IO, GPIO_MODE_INPUT_OUTPUT_OD);
gpio_set_direction(I2C_MASTER_SDA_IO, GPIO_MODE_INPUT_OUTPUT_OD);
gpio_set_pull_mode(I2C_MASTER_SCL_IO, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(I2C_MASTER_SDA_IO, GPIO_PULLUP_ONLY);
vTaskDelay(pdMS_TO_TICKS(50));
i2c_master_init(&s_bus_handle, &s_dev_handle);
ESP_LOGI(TAG, "LIS2DW12 Init 2");
vTaskDelay(pdMS_TO_TICKS(50));
dev_ctx.handle = &s_dev_handle;
dev_ctx.read_reg = lis2dw12_register_read;
dev_ctx.write_reg = lis2dw12_register_write_byte;
dev_ctx.mdelay = i2c_master_delay_ms;
ESP_LOGI(TAG, "LIS2DW12 Init 3");
while(1){
ESP_LOGI(TAG, "LIS2DW12 Init 4");
// lis2dw12_register_read(s_dev_handle, LIS2DW12_WHO_AM_I, &whoamI, 1);
lis2dw12_device_id_get(&dev_ctx, &whoamI);
if (whoamI != LIS2DW12_ID)
{
ESP_LOGE(TAG, "LIS2DW12 device ID not match (0x%02X)",whoamI);
}
else {
ESP_LOGI(TAG, "LIS2DW12 device ID: 0x%02X", whoamI);
break;
}
vTaskDelay(pdMS_TO_TICKS(50));
}
/* Restore default configuration */
lis2dw12_reset_set(&dev_ctx, PROPERTY_ENABLE);
do {
lis2dw12_reset_get(&dev_ctx, &rst);
} while (rst);
ESP_LOGI(TAG, "LIS2DW12 reset done");
ESP_LOGI(TAG, "LIS2DW12 Start Config Regiseter");
// WakeupEnable();
lis2dw12_wake_config();
ESP_LOGI(TAG, "LIS2DW12 Start Config Done");
while (1) {
lis2dw12_all_sources_t all_source;
/* Check Wake-Up events */
lis2dw12_all_sources_get(&dev_ctx, &all_source);
if (all_source.wake_up_src.wu_ia) {
snprintf((char *)tx_buffer, sizeof(tx_buffer), "Wake-Up event on ");
if (all_source.wake_up_src.x_wu) {
strcat((char *)tx_buffer, "X");
}
if (all_source.wake_up_src.y_wu) {
strcat((char *)tx_buffer, "Y");
}
if (all_source.wake_up_src.z_wu) {
strcat((char *)tx_buffer, "Z");
}
strcat((char *)tx_buffer, " direction\r\n");
ESP_LOGI(TAG, "%s", tx_buffer);
}
}
}
static void lis2dw12_wake_config(void)
{
lis2dw12_reg_t int_route;
lis2dw12_fs_t fs;
/* Set full scale */
lis2dw12_full_scale_set(&dev_ctx, LIS2DW12_16g);
lis2dw12_full_scale_get(&dev_ctx, &fs);
ESP_LOGI(TAG, "LIS2DW12 full scale: %d", fs);
/* Configure power mode */
lis2dw12_power_mode_set(&dev_ctx,
LIS2DW12_CONT_LOW_PWR_LOW_NOISE_12bit);
/* Set Output Data Rate */
lis2dw12_data_rate_set(&dev_ctx, LIS2DW12_XL_ODR_200Hz);
/* Apply high-pass digital filter on Wake-Up function */
lis2dw12_filter_path_set(&dev_ctx, LIS2DW12_HIGH_PASS_ON_OUT);
/* Apply high-pass digital filter on Wake-Up function
* Duration time is set to zero so Wake-Up interrupt signal
* is generated for each X,Y,Z filtered data exceeding the
* configured threshold
*/
lis2dw12_wkup_dur_set(&dev_ctx, 0);
/* Set wake-up threshold
* Set Wake-Up threshold: 1 LSb corresponds to FS_XL/2^6
*/
lis2dw12_wkup_threshold_set(&dev_ctx, 1);
/* Enable interrupt generation on Wake-Up INT1 pin */
lis2dw12_pin_int1_route_get(&dev_ctx, &int_route.ctrl4_int1_pad_ctrl);
int_route.ctrl4_int1_pad_ctrl.int1_wu = PROPERTY_ENABLE;
lis2dw12_pin_int1_route_set(&dev_ctx, &int_route.ctrl4_int1_pad_ctrl);
}
\ No newline at end of file
#ifndef __LIS2DW12_H__
#define __LIS2DW12_H__
#include "stdio.h"
#include "stdlib.h"
void lis2dw12_init();
#endif
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment