Skip to content

Commit d3e161c

Browse files
committed
Adding LIS3DH sample code to low power partition
* ESP will respond to a double tap with its ISR Possibility to add additional actions depending on requirements
1 parent 781021c commit d3e161c

File tree

7 files changed

+59
-25
lines changed

7 files changed

+59
-25
lines changed

eloc610LowPowerPartition/platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ platform = espressif32@~6.1.0
1717
board = esp32dev
1818

1919
framework = espidf
20-
upload_port = COM3
21-
monitor_port = COM3
20+
;upload_port = COM3
21+
;monitor_port = COM3
2222
monitor_speed = 115200
2323
monitor_filters = esp32_exception_decoder
2424
board_build.partitions = elocPartitions.csv

eloc610LowPowerPartition/src/ElocSystem.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ElocSystem
3737
ELOC_IOEXP* mIOExpInstance;
3838
LIS3DH* mLis3DH;
3939
public:
40-
inline static ElocSystem& Get() {
40+
inline static ElocSystem& GetInstance() {
4141
static ElocSystem System;
4242
return System;
4343
}
@@ -54,9 +54,18 @@ class ElocSystem
5454
assert(mLis3DH != NULL);
5555
return *mLis3DH;
5656
}
57+
inline bool hasI2C() const {
58+
return mI2CInstance != NULL;
59+
}
60+
inline bool hasIoExpander() const {
61+
return mIOExpInstance != NULL;
62+
}
63+
inline bool hasLIS3DH() const {
64+
return mLis3DH != NULL;
65+
}
5766
};
5867

5968

6069

6170

62-
#endif // ELOCSYSTEM_HPP_
71+
#endif // ELOCSYSTEM_HPP_

eloc610LowPowerPartition/src/ManualWakeup.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void wakeup_task (void *pvParameters)
7070
lis3dh_int_click_source_t click_src = {};
7171

7272
// get the source of the interrupt and reset *INTx* signals
73-
ElocSystem::Get().getLIS3DH().lis3dh_get_int_click_source (&click_src);
73+
ElocSystem::GetInstance().getLIS3DH().lis3dh_get_int_click_source (&click_src);
7474

7575

7676
// in case of click detection interrupt
@@ -82,9 +82,9 @@ void wakeup_task (void *pvParameters)
8282
}
8383

8484

85-
esp_err_t ManualWakeupConfig() {
85+
esp_err_t ManualWakeupConfig(bool installGpioIsr) {
8686

87-
LIS3DH& lis3dh = ElocSystem::Get().getLIS3DH();
87+
LIS3DH& lis3dh = ElocSystem::GetInstance().getLIS3DH();
8888

8989
/** --- INTERRUPT CONFIGURATION PART ---- */
9090

@@ -103,8 +103,10 @@ esp_err_t ManualWakeupConfig() {
103103

104104
xTaskCreate(wakeup_task, "Click Sense Wakeup", 2048, NULL, 1, NULL);
105105

106-
gpio_install_isr_service(ESP_INTR_FLAG_LEVEL1);
107-
gpio_isr_handler_add(LIS3DH_INT_PIN, int_signal_handler, (void *)LIS3DH_INT_PIN);
106+
if (installGpioIsr) {
107+
ESP_ERROR_CHECK(GPIO_INTR_PRIO);
108+
}
109+
ESP_ERROR_CHECK(gpio_isr_handler_add(LIS3DH_INT_PIN, int_signal_handler, (void *)LIS3DH_INT_PIN));
108110

109111
lis3dh.lis3dh_set_int_click_config (&lis3dh_click_config);
110112
lis3dh.lis3dh_enable_int (lis3dh_int_click, lis3dh_int1_signal, true);

eloc610LowPowerPartition/src/ManualWakeup.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424
#include "esp_err.h"
2525

26-
esp_err_t ManualWakeupConfig();
26+
/// @brief ManualWakeupConfig will setup LIS3DH for waking up ESP on double tap event
27+
/// @param installGpioIsr : true: ManualWakeupConfig will call gpio_install_isr_service()
28+
/// : false: ManualWakeupConfig() will expect gpio isr to be already installed
29+
/// @return
30+
esp_err_t ManualWakeupConfig(bool installGpioIsr);
2731

2832

2933

eloc610LowPowerPartition/src/config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ i2s_config_t i2s_mic_Config = {
1717
#endif
1818

1919
.communication_format = I2S_COMM_FORMAT_I2S,
20-
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
20+
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL3,
2121
.dma_buf_count = gBufferCount, //so 2000 sample buffer at 16khz sr gives us 125ms to do our writing
2222
.dma_buf_len = gBufferLen, // 8 buffers gives us half second
2323
.use_apll = gUseAPLL, //not getting set. gUseAPLL, //the only thing that works with LowPower/APLL is 16khz 12khz??

eloc610LowPowerPartition/src/config.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <freertos/FreeRTOS.h>
22
#include <driver/i2s.h>
3+
#include "lis3dh_types.h"
34

45

56

@@ -39,25 +40,31 @@
3940
#define GPIO_BUTTON GPIO_NUM_0
4041
#define OTHER_GPIO_BUTTON GPIO_NUM_0
4142
#define VOLTAGE_PIN GPIO_NUM_34
43+
44+
/** Interrupt definitions*/
45+
#define GPIO_INTR_PRIO ESP_INTR_FLAG_LEVEL1
4246

4347

4448

4549
#define I2S_MIC_LEFT_RIGHT_CLOCK GPIO_NUM_5
4650
#define I2S_MIC_SERIAL_CLOCK GPIO_NUM_18
4751
#define I2S_MIC_SERIAL_DATA GPIO_NUM_19
4852

49-
// i2c config
50-
#define USE_I2C
51-
52-
#define I2C_PORT I2C_NUM_0
53-
#define I2C_SDA_PIN GPIO_NUM_23
54-
#define I2C_SCL_PIN GPIO_NUM_22
55-
#define I2C_SPEED_HZ 100000
56-
57-
/* LIS3DH Config*/
58-
#define LIS3DH_INT_PIN GPIO_NUM_12
59-
extern lis3dh_config_t lis3dh_config;
60-
extern lis3dh_int_click_config_t lis3dh_click_config;
53+
// i2c config
54+
#define USE_I2C
55+
56+
#define I2C_PORT I2C_NUM_0
57+
#define I2C_SDA_PIN GPIO_NUM_23
58+
#define I2C_SCL_PIN GPIO_NUM_22
59+
#define I2C_SPEED_HZ 100000
60+
61+
/* LIS3DH Config*/
62+
#define LIS3DH_INT_PIN GPIO_NUM_12
63+
extern lis3dh_config_t lis3dh_config;
64+
extern lis3dh_int_click_config_t lis3dh_click_config;
65+
66+
/* Buzzer Config */
67+
#define BUZZER_PIN GPIO_NUM_13
6168

6269

6370
#endif

eloc610LowPowerPartition/src/main.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
#include "esp_sleep.h"
3030
#include "rtc_wdt.h"
3131
//#include "soc/efuse_reg.h"
32+
33+
#include "lis3dh.h"
34+
#include "ElocSystem.hpp"
35+
#include "ManualWakeup.hpp"
36+
3237
static const char *TAG = "main";
3338

3439

@@ -667,6 +672,8 @@ I2SSampler *input;
667672
gpio_set_level(STATUS_LED, 0);
668673
gpio_set_level(BATTERY_LED, 0);
669674

675+
ESP_LOGI(TAG, "Setting up System...");
676+
ElocSystem::GetInstance();
670677

671678

672679
//delay(30000);
@@ -791,9 +798,14 @@ printMemory();
791798

792799

793800

801+
ESP_ERROR_CHECK(gpio_install_isr_service(GPIO_INTR_PRIO));
802+
803+
ESP_LOGI(TAG, "Creating LIS3DH wakeup task...");
804+
if (esp_err_t err = ManualWakeupConfig(false)) {
805+
ESP_LOGI(TAG, "ManualWakeupConfig %s", esp_err_to_name(err));
806+
}
807+
794808

795-
796-
ESP_ERROR_CHECK(gpio_install_isr_service(0));
797809
ESP_ERROR_CHECK(gpio_isr_handler_add(GPIO_BUTTON, buttonISR, (void *)GPIO_BUTTON));
798810
ESP_ERROR_CHECK(gpio_isr_handler_add(GPIO_BUTTON, buttonISR, (void *)OTHER_GPIO_BUTTON));
799811

0 commit comments

Comments
 (0)