wires impl
This commit is contained in:
parent
bb20c66b85
commit
be7c1bc20e
1
components/i2c_lcd_pcf8574
Submodule
1
components/i2c_lcd_pcf8574
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit a8232125a194497d2b34f2c1419354199d0c2c4c
|
||||||
@ -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 "")
|
INCLUDE_DIRS "")
|
||||||
|
|
||||||
|
|
||||||
|
set(EXTRA_COMPONENT_DIRS components)
|
||||||
@ -1,48 +1,21 @@
|
|||||||
#ifndef BOTTOM_HALF_HPP
|
#include "bottom_half.h"
|
||||||
#define BOTTOM_HALF_HPP
|
|
||||||
|
|
||||||
#include "driver/i2c.h"
|
static const char *TAG = "bottom_half";
|
||||||
#include "driver/gpio.h"
|
|
||||||
|
|
||||||
#define BOTTOM_I2C_NUM I2C_NUM_0
|
static uint16_t keypad_state;
|
||||||
#define BOTTOM_I2C_ADDR 126
|
static uint16_t button_state;
|
||||||
#define BOTTOM_PIN_INTERUPT GPIO_NUM_0
|
static uint8_t touch_state;
|
||||||
|
|
||||||
#define DELTA_BIT_KP 0
|
static uint16_t keypad_pressed;
|
||||||
#define DELTA_BIT_BUTTON 1
|
static uint16_t button_pressed;
|
||||||
|
static uint8_t touch_pressed;
|
||||||
|
|
||||||
typedef enum {
|
static uint16_t keypad_released;
|
||||||
k1 = 0,
|
static uint16_t button_released;
|
||||||
k4 = 1,
|
static uint8_t touch_released;
|
||||||
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 const char *BOTTOM_TAG = "bottom_half";
|
/// read buffer
|
||||||
|
static uint8_t read_buf[8];
|
||||||
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;
|
|
||||||
|
|
||||||
static bool _take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
|
static bool _take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
|
||||||
for (int i = 0; i < 16; i++) {
|
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 poll_bottom_task(void *arg);
|
||||||
|
|
||||||
// static void IRAM_ATTR gpio_isr_handler(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) {
|
if (new_data) {
|
||||||
uint8_t delta = receive_delta();
|
uint8_t delta = receive_delta();
|
||||||
// ESP_LOGI(_TAG, "delta: %d", 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)) {
|
if (delta & (1 << DELTA_BIT_KP)) {
|
||||||
receive_keypad();
|
receive_keypad();
|
||||||
@ -206,6 +176,4 @@ static void poll_bottom_task(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* BOTTOM_HALF_HPP */
|
|
||||||
42
main/drivers/bottom_half.h
Normal file
42
main/drivers/bottom_half.h
Normal file
@ -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 */
|
||||||
@ -1,12 +1,16 @@
|
|||||||
#ifndef WIRES_HPP
|
#ifndef WIRES_HPP
|
||||||
#define 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_NUM I2C_NUM_1
|
||||||
#define WIRES_I2C_ADDR 125
|
#define WIRES_I2C_ADDR 125
|
||||||
|
|
||||||
|
#define DELTA_BIT_WIRES 0
|
||||||
|
#define DELTA_BIT_BUTTON 1
|
||||||
|
|
||||||
static const char *WIRES_TAG = "wires";
|
static const char *WIRES_TAG = "wires";
|
||||||
|
|
||||||
|
uint8_t button_state;
|
||||||
uint8_t wires_states;
|
uint8_t wires_states;
|
||||||
uint8_t wires_cut;
|
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_param_config(WIRES_I2C_NUM, &wires_conf));
|
||||||
ESP_ERROR_CHECK(i2c_driver_install(WIRES_I2C_NUM, wires_conf.mode, 0, 0, 0));
|
ESP_ERROR_CHECK(i2c_driver_install(WIRES_I2C_NUM, wires_conf.mode, 0, 0, 0));
|
||||||
|
|
||||||
gpio_config_t int_pin_conf = {};
|
gpio_config_t int_pin_conf = {};
|
||||||
// delta_pin_conf.intr_type = GPIO_INTR_LOW_LEVEL;
|
// delta_pin_conf.intr_type = GPIO_INTR_LOW_LEVEL;
|
||||||
int_pin_conf.mode = GPIO_MODE_INPUT;
|
int_pin_conf.mode = GPIO_MODE_INPUT;
|
||||||
// GPIO 0
|
int_pin_conf.pin_bit_mask = (1ULL<<WIRES_PIN_DELTA);
|
||||||
int_pin_conf.pin_bit_mask = (1ULL<<WIRES_PIN_INTERUPT);
|
|
||||||
int_pin_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
int_pin_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||||
gpio_config(&int_pin_conf);
|
gpio_config(&int_pin_conf);
|
||||||
|
|
||||||
|
xTaskCreate(poll_wires_task, "poll_wires", 4096, NULL, 10, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void strike(char* reason) {
|
void strike(char* reason) {
|
||||||
@ -48,39 +55,34 @@ static uint8_t read_buf[8];
|
|||||||
static uint8_t receive_delta(void) {
|
static uint8_t receive_delta(void) {
|
||||||
uint8_t reg = 1;
|
uint8_t reg = 1;
|
||||||
read_buf[0] = 0;
|
read_buf[0] = 0;
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, read_buf, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, read_buf, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
return read_buf[0];
|
return read_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void receive_wires(void) {
|
static void receive_wires(void) {
|
||||||
uint8_t reg = 1;
|
uint8_t reg = 1;
|
||||||
read_buf[0] = 0;
|
read_buf[0] = 0;
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, read_buf, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, read_buf, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
return read_buf[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void receive_button(void) {
|
static void receive_button(void) {
|
||||||
uint8_t reg = 2;
|
uint8_t reg = 2;
|
||||||
read_buf[0] = 0;
|
read_buf[0] = 0;
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, read_buf, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, read_buf, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
uint8_t new_button = read_buf[0];
|
uint8_t new_button = read_buf[0];
|
||||||
|
button_state = new_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void poll_wires_task(void *arg) {
|
static void poll_wires_task(void *arg) {
|
||||||
while (1) {
|
while (1) {
|
||||||
bool new_data = gpio_get_level(WIRES_PIN_INTERUPT) == 0;
|
bool new_data = gpio_get_level(WIRES_PIN_DELTA) == 0;
|
||||||
if (new_data) {
|
if (new_data) {
|
||||||
if (delta == 0) ESP_LOGW(WIRES_TAG, "int pin was low, but int register returned 0");
|
uint8_t delta = receive_delta();
|
||||||
|
|
||||||
if (delta & (1 << DELTA_BIT_KP)) {
|
if (delta == 0) ESP_LOGW(WIRES_TAG, "delta pin was low, but delta register returned 0");
|
||||||
receive_keypad();
|
|
||||||
// ESP_LOGI(_TAG, "keypad: %d", keypad_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delta & (1 << DELTA_BIT_BUTTON)) {
|
if (delta & (1 << DELTA_BIT_WIRES)) receive_wires();
|
||||||
receive_button();
|
if (delta & (1 << DELTA_BIT_BUTTON)) receive_button();
|
||||||
// ESP_LOGI(_TAG, "button: %d", button_state);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include "driver/i2c.h"
|
#include "driver/i2c.h"
|
||||||
#include "drivers/tft.hpp"
|
#include "drivers/tft.hpp"
|
||||||
#include "drivers/wires.hpp"
|
#include "drivers/wires.hpp"
|
||||||
#include "drivers/bottom_half.hpp"
|
#include "drivers/bottom_half.h"
|
||||||
#include "drivers/sd.hpp"
|
#include "drivers/sd.hpp"
|
||||||
#include "drivers/game_timer.hpp"
|
#include "drivers/game_timer.hpp"
|
||||||
#include "drivers/speaker.hpp"
|
#include "drivers/speaker.hpp"
|
||||||
@ -14,6 +14,7 @@
|
|||||||
#include "esp_rom_gpio.h"
|
#include "esp_rom_gpio.h"
|
||||||
|
|
||||||
#include "steps/step0.hpp"
|
#include "steps/step0.hpp"
|
||||||
|
#include "steps/step1.hpp"
|
||||||
|
|
||||||
#define WIRES_ADDR 125
|
#define WIRES_ADDR 125
|
||||||
#define WIRES_REG_WIRES
|
#define WIRES_REG_WIRES
|
||||||
@ -34,7 +35,6 @@ extern "C" void app_main(void) {
|
|||||||
|
|
||||||
init_bottom_half();
|
init_bottom_half();
|
||||||
init_char_lcd();
|
init_char_lcd();
|
||||||
init_wires();
|
|
||||||
|
|
||||||
step0();
|
step0();
|
||||||
step1();
|
step1();
|
||||||
@ -47,100 +47,5 @@ extern "C" void app_main(void) {
|
|||||||
|
|
||||||
// set_game_timer(1234, 1);
|
// set_game_timer(1234, 1);
|
||||||
// set_module_timer(5678, 2);
|
// set_module_timer(5678, 2);
|
||||||
|
|
||||||
// while (1) {
|
|
||||||
// vTaskDelay(pdMS_TO_TICKS(10));
|
|
||||||
// lv_timer_handler();
|
|
||||||
// }
|
|
||||||
|
|
||||||
gpio_reset_pin(GPIO_NUM_41);
|
|
||||||
gpio_reset_pin(GPIO_NUM_42);
|
|
||||||
|
|
||||||
i2c_config_t wires_conf = {
|
|
||||||
.mode = I2C_MODE_MASTER,
|
|
||||||
.sda_io_num = GPIO_NUM_41,
|
|
||||||
.scl_io_num = GPIO_NUM_42,
|
|
||||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
|
||||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
|
||||||
.master = {
|
|
||||||
.clk_speed = 100000,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_1, &wires_conf));
|
|
||||||
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_1, wires_conf.mode, 0, 0, 0));
|
|
||||||
|
|
||||||
|
|
||||||
// uint8_t write[8] = {1, 2, 4, 8, 16, 32, 64, 128};
|
|
||||||
return;
|
|
||||||
while (1) {
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
|
||||||
uint8_t read[8] = {0};
|
|
||||||
uint8_t reg;
|
|
||||||
|
|
||||||
// reg = 1;
|
|
||||||
// ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(I2C_NUM_0, 126, ®, 1, read, 1, (100 / portTICK_PERIOD_MS)));
|
|
||||||
// ESP_LOGI("main", "delta: %d", read[0]);
|
|
||||||
|
|
||||||
// read[0] = 0;
|
|
||||||
// reg = 2;
|
|
||||||
// ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(I2C_NUM_0, 126, ®, 1, read, 2, (100 / portTICK_PERIOD_MS)));
|
|
||||||
// ESP_LOGI("main", "keypad: %d %d", read[0], read[1]);
|
|
||||||
|
|
||||||
|
|
||||||
// WIRES
|
|
||||||
reg = 1;
|
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(I2C_NUM_1, 125, ®, 1, read, 1, (1000 / portTICK_PERIOD_MS)));
|
|
||||||
ESP_LOGI("main", "wires: %d", read[0]);
|
|
||||||
|
|
||||||
// Issue strike
|
|
||||||
|
|
||||||
|
|
||||||
// vTaskDelay(pdMS_TO_TICKS(10));
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(20000));
|
|
||||||
// vTaskDelay(pdMS_TO_TICKS(5000));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define BUF_SIZE (1024)
|
|
||||||
#define TX_PIN GPIO_NUM_
|
|
||||||
|
|
||||||
static void relay_task(void *arg)
|
|
||||||
{
|
|
||||||
/* Configure parameters of an UART driver,
|
|
||||||
* communication pins and install the driver */
|
|
||||||
uart_config_t uart_config = {
|
|
||||||
.baud_rate = 115200,
|
|
||||||
.data_bits = UART_DATA_8_BITS,
|
|
||||||
.parity = UART_PARITY_DISABLE,
|
|
||||||
.stop_bits = UART_STOP_BITS_1,
|
|
||||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
|
||||||
.source_clk = UART_SCLK_DEFAULT,
|
|
||||||
};
|
|
||||||
int intr_alloc_flags = 0;
|
|
||||||
|
|
||||||
#if CONFIG_UART_ISR_IN_IRAM
|
|
||||||
intr_alloc_flags = ESP_INTR_FLAG_IRAM;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(uart_driver_install(UART_NUM_0, BUF_SIZE * 2, 0, 0, NULL, intr_alloc_flags));
|
|
||||||
ESP_ERROR_CHECK(uart_param_config(UART_NUM_0, &uart_config));
|
|
||||||
ESP_ERROR_CHECK(uart_set_pin(UART_NUM_0, GPIO_NUM_1, GPIO_NUM_2, GPIO_NUM_NC, GPIO_NUM_NC));
|
|
||||||
|
|
||||||
// Configure a temporary buffer for the incoming data
|
|
||||||
uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
// Read data from the UART
|
|
||||||
int len = uart_read_bytes(UART_NUM_0, data, (BUF_SIZE - 1), 20 / portTICK_PERIOD_MS);
|
|
||||||
// Write data back to the UART
|
|
||||||
// uart_write_bytes(ECHO_UART_PORT_NUM, (const char *) data, len);
|
|
||||||
if (len) {
|
|
||||||
data[len] = '\0';
|
|
||||||
// ESP_LOGI(TAG, "%s", (char *) data);
|
|
||||||
printf("%s", (char *) data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#ifndef STEP_0_HPP
|
#ifndef STEP_0_HPP
|
||||||
#define STEP_0_HPP
|
#define STEP_0_HPP
|
||||||
|
|
||||||
#include "../drivers/bottom_half.hpp"
|
#include "../drivers/bottom_half.h"
|
||||||
#include "../drivers/char_lcd.hpp"
|
#include "../drivers/char_lcd.hpp"
|
||||||
#include "i2c_lcd_pcf8574.h"
|
#include "../drivers/wires.hpp"
|
||||||
|
|
||||||
static const char *STEP0_TAG = "step0";
|
static const char *STEP0_TAG = "step0";
|
||||||
|
|
||||||
@ -35,6 +35,7 @@ void step0(void) {
|
|||||||
} else {
|
} else {
|
||||||
lcd_set_cursor(&lcd, 1, 2);
|
lcd_set_cursor(&lcd, 1, 2);
|
||||||
lcd_print(&lcd, "Invalid Star Code");
|
lcd_print(&lcd, "Invalid Star Code");
|
||||||
|
strike("Invalid Star Code");
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear
|
// clear
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user