From be7c1bc20ea475a0015fa81bea1bd08c7b3ee967 Mon Sep 17 00:00:00 2001 From: Mitchell M Date: Fri, 2 Aug 2024 17:53:22 -0500 Subject: [PATCH] wires impl --- components/i2c_lcd_pcf8574 | 1 + main/CMakeLists.txt | 5 +- .../{bottom_half.hpp => bottom_half.cpp} | 62 +++--------- main/drivers/bottom_half.h | 42 ++++++++ main/drivers/wires.hpp | 36 +++---- main/main.cpp | 99 +------------------ main/steps/step0.hpp | 5 +- 7 files changed, 86 insertions(+), 164 deletions(-) create mode 160000 components/i2c_lcd_pcf8574 rename main/drivers/{bottom_half.hpp => bottom_half.cpp} (84%) create mode 100644 main/drivers/bottom_half.h diff --git a/components/i2c_lcd_pcf8574 b/components/i2c_lcd_pcf8574 new file mode 160000 index 0000000..a823212 --- /dev/null +++ b/components/i2c_lcd_pcf8574 @@ -0,0 +1 @@ +Subproject commit a8232125a194497d2b34f2c1419354199d0c2c4c diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 6ff40a6..6391e62 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,2 +1,5 @@ -idf_component_register(SRCS "main.cpp" "drivers/TM1640/TM16xx.cpp" "drivers/TM1640/TM1640.cpp" +idf_component_register(SRCS "main.cpp" "drivers/TM1640/TM16xx.cpp" "drivers/TM1640/TM1640.cpp" "drivers/bottom_half.cpp" INCLUDE_DIRS "") + + +set(EXTRA_COMPONENT_DIRS components) \ No newline at end of file diff --git a/main/drivers/bottom_half.hpp b/main/drivers/bottom_half.cpp similarity index 84% rename from main/drivers/bottom_half.hpp rename to main/drivers/bottom_half.cpp index ed8fa66..20b277b 100644 --- a/main/drivers/bottom_half.hpp +++ b/main/drivers/bottom_half.cpp @@ -1,48 +1,21 @@ -#ifndef BOTTOM_HALF_HPP -#define BOTTOM_HALF_HPP +#include "bottom_half.h" -#include "driver/i2c.h" -#include "driver/gpio.h" +static const char *TAG = "bottom_half"; -#define BOTTOM_I2C_NUM I2C_NUM_0 -#define BOTTOM_I2C_ADDR 126 -#define BOTTOM_PIN_INTERUPT GPIO_NUM_0 +static uint16_t keypad_state; +static uint16_t button_state; +static uint8_t touch_state; -#define DELTA_BIT_KP 0 -#define DELTA_BIT_BUTTON 1 +static uint16_t keypad_pressed; +static uint16_t button_pressed; +static uint8_t touch_pressed; -typedef enum { - k1 = 0, - k4 = 1, - k7 = 2, - star = 3, - k2 = 4, - k5 = 5, - k8 = 6, - k0 = 7, - k3 = 8, - k6 = 9, - k9 = 10, - pound = 11, - ka = 12, - kb = 13, - kc = 14, - kd = 15, -} KeypadKey; +static uint16_t keypad_released; +static uint16_t button_released; +static uint8_t touch_released; -static const char *BOTTOM_TAG = "bottom_half"; - -uint16_t keypad_state; -uint16_t button_state; -uint8_t touch_state; - -uint16_t keypad_pressed; -uint16_t button_pressed; -uint8_t touch_pressed; - -uint16_t keypad_released; -uint16_t button_released; -uint8_t touch_released; +/// read buffer +static uint8_t read_buf[8]; static bool _take_key(KeypadKey* kp, uint16_t* keypad_bitfield) { for (int i = 0; i < 16; i++) { @@ -103,9 +76,6 @@ char char_of_keypad_key(KeypadKey kp) { } } -/// read buffer -static uint8_t read_buf[8]; - static void poll_bottom_task(void *arg); // static void IRAM_ATTR gpio_isr_handler(void* arg) @@ -190,7 +160,7 @@ static void poll_bottom_task(void *arg) { if (new_data) { uint8_t delta = receive_delta(); // ESP_LOGI(_TAG, "delta: %d", delta); - if (delta == 0) ESP_LOGW(BOTTOM_TAG, "delta pin was low, but delta register returned 0"); + if (delta == 0) ESP_LOGW(TAG, "delta pin was low, but delta register returned 0"); if (delta & (1 << DELTA_BIT_KP)) { receive_keypad(); @@ -206,6 +176,4 @@ static void poll_bottom_task(void *arg) { } vTaskDelete(NULL); -} - -#endif /* BOTTOM_HALF_HPP */ \ No newline at end of file +} \ No newline at end of file diff --git a/main/drivers/bottom_half.h b/main/drivers/bottom_half.h new file mode 100644 index 0000000..5c7d484 --- /dev/null +++ b/main/drivers/bottom_half.h @@ -0,0 +1,42 @@ +#ifndef BOTTOM_HALF_HPP +#define BOTTOM_HALF_HPP + +#include "driver/i2c.h" +#include "driver/gpio.h" +#include "esp_log.h" + +#define BOTTOM_I2C_NUM I2C_NUM_0 +#define BOTTOM_I2C_ADDR 126 +#define BOTTOM_PIN_INTERUPT GPIO_NUM_0 + +#define DELTA_BIT_KP 0 +#define DELTA_BIT_BUTTON 1 + +typedef enum { + k1 = 0, + k4 = 1, + k7 = 2, + star = 3, + k2 = 4, + k5 = 5, + k8 = 6, + k0 = 7, + k3 = 8, + k6 = 9, + k9 = 10, + pound = 11, + ka = 12, + kb = 13, + kc = 14, + kd = 15, +} KeypadKey; + +bool get_pressed_keypad(KeypadKey* kp); +bool get_released_keypad(KeypadKey* kp); +char char_of_keypad_key(KeypadKey kp); + +static void poll_bottom_task(void *arg); + +void init_bottom_half(); + +#endif /* BOTTOM_HALF_HPP */ \ No newline at end of file diff --git a/main/drivers/wires.hpp b/main/drivers/wires.hpp index 062b147..b555536 100644 --- a/main/drivers/wires.hpp +++ b/main/drivers/wires.hpp @@ -1,12 +1,16 @@ #ifndef WIRES_HPP #define WIRES_HPP -#define WIRES_PIN_INTERUPT GPIO_NUM_2 +#define WIRES_PIN_DELTA GPIO_NUM_2 #define WIRES_I2C_NUM I2C_NUM_1 #define WIRES_I2C_ADDR 125 +#define DELTA_BIT_WIRES 0 +#define DELTA_BIT_BUTTON 1 + static const char *WIRES_TAG = "wires"; +uint8_t button_state; uint8_t wires_states; uint8_t wires_cut; @@ -24,17 +28,20 @@ void init_wires(void) { } }; + gpio_reset_pin(GPIO_NUM_41); + gpio_reset_pin(GPIO_NUM_42); + ESP_ERROR_CHECK(i2c_param_config(WIRES_I2C_NUM, &wires_conf)); ESP_ERROR_CHECK(i2c_driver_install(WIRES_I2C_NUM, wires_conf.mode, 0, 0, 0)); gpio_config_t int_pin_conf = {}; // delta_pin_conf.intr_type = GPIO_INTR_LOW_LEVEL; int_pin_conf.mode = GPIO_MODE_INPUT; - // GPIO 0 - int_pin_conf.pin_bit_mask = (1ULL<