7 Commits
Author SHA1 Message Date
mitchell 480445d31e update game results 2025-03-26 21:11:52 -05:00
mitchell 7d43f9957a rename purple to pink 2025-03-26 19:31:40 -05:00
mitchell ae1766b3b0 fix LVGL screen cleaning code 2025-03-26 19:28:33 -05:00
mitchell dc0efa74eb Clean Up calls to the leds driver 2025-03-26 18:39:35 -05:00
mitchell 7cdddb2c83 update LED driver 2025-03-26 17:13:30 -05:00
mitchell 51001d6bc4 move other drivers 2025-03-26 08:21:30 -05:00
mitchell d0d1a0bb0e Move tetris images to flash 2025-03-26 08:03:14 -05:00
84 changed files with 4310 additions and 2317 deletions
+1 -8
View File
@@ -4,24 +4,17 @@ set(SOURCES
"TM1640/TM1640.cpp" "TM1640/TM1640.cpp"
"SparkFunBQ27441/SparkFunBQ27441.cpp" "SparkFunBQ27441/SparkFunBQ27441.cpp"
"esp_lcd_ili9488/esp_lcd_ili9488.c" "esp_lcd_ili9488/esp_lcd_ili9488.c"
# "bottom_half.cpp" "bottom_half.cpp"
"char_lcd.cpp" "char_lcd.cpp"
"game_info.cpp"
"game_timer.cpp" "game_timer.cpp"
"i2c_lcd_pcf8574.c" "i2c_lcd_pcf8574.c"
"i2c.cpp"
"inputs.cpp"
"leds.cpp" "leds.cpp"
"perh.cpp"
"power.cpp" "power.cpp"
"sd.cpp" "sd.cpp"
"speaker.cpp" "speaker.cpp"
"sseg.cpp" "sseg.cpp"
"starcode.cpp"
"state_tracking.cpp"
"tft.cpp" "tft.cpp"
"wires.cpp" "wires.cpp"
"wlvgl.cpp"
) )
target_sources(${COMPONENT_LIB} PRIVATE ${SOURCES}) target_sources(${COMPONENT_LIB} PRIVATE ${SOURCES})
@@ -32,7 +32,6 @@ Arduino Uno (any 'duino should do)
******************************************************************************/ ******************************************************************************/
#include "SparkFunBQ27441.h" #include "SparkFunBQ27441.h"
#include "../i2c.h"
/***************************************************************************** /*****************************************************************************
************************** Initialization Functions ************************* ************************** Initialization Functions *************************
@@ -711,9 +710,7 @@ bool BQ27441::writeExtendedData(uint8_t classID, uint8_t offset, uint8_t * data,
int16_t BQ27441::i2cReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count) int16_t BQ27441::i2cReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count)
{ {
int16_t timeout = BQ72441_I2C_TIMEOUT; int16_t timeout = BQ72441_I2C_TIMEOUT;
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
i2c_master_write_read_device(BQ72441_I2C_NUM, _deviceAddress, &subAddress, 1, dest, count, timeout); i2c_master_write_read_device(BQ72441_I2C_NUM, _deviceAddress, &subAddress, 1, dest, count, timeout);
xSemaphoreGive(main_i2c_mutex);
return timeout; return timeout;
} }
+35 -3
View File
@@ -1,10 +1,12 @@
#include "all.h" #include "all.h"
static const char *TAG = "driver_all";
static void init_i2c();
void init_drivers() { void init_drivers() {
init_i2c(); init_i2c();
// init char_lcd so we can use it to report other initialization errors. // init char_lcd so we can use it to report other initialization errors.
init_lcd(); init_lcd();
init_star_code_system();
// init the bottom half so that we can get user input. // init the bottom half so that we can get user input.
init_bottom_half(); init_bottom_half();
init_sd(); init_sd();
@@ -14,6 +16,36 @@ void init_drivers() {
init_tft(); init_tft();
init_leds(); init_leds();
init_power_board(); init_power_board();
set_lcd_header_enabled(true);
} }
/// @brief Initializes I2C_NUM_0.
///
/// This is hooked up the to:
/// - The bottom half
/// - The char lcd
/// - The power board
/// - The MPU6050
/// - The PERH port
/// - The Capacitive Touch Panel
static void init_i2c() {
ESP_LOGI(TAG, "Initializing i2c...");
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = GPIO_NUM_5,
.scl_io_num = GPIO_NUM_6,
.sda_pullup_en = GPIO_PULLUP_DISABLE,
.scl_pullup_en = GPIO_PULLUP_DISABLE,
// .sda_pullup_en = GPIO_PULLUP_ENABLE,
// .scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = {
.clk_speed = 100*1000,
},
.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL
};
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &conf));
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, conf.mode, 0, 0, 0));
ESP_LOGI(TAG, "i2c initialized!");
}
+5 -10
View File
@@ -1,19 +1,14 @@
#ifndef ALL_H #ifndef ALL_H
#define ALL_H #define ALL_H
#include "bottom_half.h"
#include "char_lcd.h" #include "char_lcd.h"
#include "game_timer.h" #include "bottom_half.h"
#include "i2c.h"
#include "leds.h"
#include "power.h"
#include "sd.h" #include "sd.h"
#include "speaker.h" #include "speaker.h"
#include "sseg.h" #include "game_timer.h"
#include "starcode.h" #include "drivers/tft.h"
#include "state_tracking.h" #include "drivers/leds.h"
#include "tft.h" #include "drivers/power.h"
#include "wires.h"
void init_drivers(); void init_drivers();
+15 -89
View File
@@ -1,7 +1,5 @@
#include "bottom_half.h" #include "bottom_half.h"
#include <esp_log.h> #include <esp_log.h>
#include "state_tracking.h"
#include "starcode.h"
static const char *TAG = "bottom_half"; static const char *TAG = "bottom_half";
@@ -31,11 +29,6 @@ static void receive_keypad();
static void receive_button_switch(); static void receive_button_switch();
static void receive_touch(); static void receive_touch();
static bool replay_handler(const char* event, char* arg) {
// no reply neccesary
return false;
}
// TODO: add intrupt on bottom half delta pin // TODO: add intrupt on bottom half delta pin
// static void IRAM_ATTR gpio_isr_handler(void* arg) // static void IRAM_ATTR gpio_isr_handler(void* arg)
// { // {
@@ -46,14 +39,8 @@ static bool replay_handler(const char* event, char* arg) {
void init_bottom_half() { void init_bottom_half() {
ESP_LOGI(TAG, "Initializing bottom half..."); ESP_LOGI(TAG, "Initializing bottom half...");
gpio_config_t int_conf = { ESP_ERROR_CHECK(gpio_set_direction(BOTTOM_PIN_INTERUPT, GPIO_MODE_INPUT));
.pin_bit_mask = 1ULL << BOTTOM_PIN_INTERUPT, ESP_ERROR_CHECK(gpio_set_pull_mode(BOTTOM_PIN_INTERUPT, GPIO_PULLUP_ONLY));
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
ESP_ERROR_CHECK(gpio_config(&int_conf));
// TODO: do interupt stuff. // TODO: do interupt stuff.
// ESP_ERROR_CHECK(gpio_intr_enable(BOTTOM_PIN_INTERUPT)); // ESP_ERROR_CHECK(gpio_intr_enable(BOTTOM_PIN_INTERUPT));
@@ -69,60 +56,35 @@ void init_bottom_half() {
xTaskCreate(poll_bottom_task, "poll_bottom", 4096, NULL, 10, NULL); xTaskCreate(poll_bottom_task, "poll_bottom", 4096, NULL, 10, NULL);
register_replay_fn(replay_handler);
ESP_LOGI(TAG, "Bottom half initialized!"); ESP_LOGI(TAG, "Bottom half initialized!");
} }
static uint8_t receive_delta(void) { static uint8_t receive_delta(void) {
uint8_t reg = 1; uint8_t reg = 1;
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, &reg, 1, buf, 1, (100 / portTICK_PERIOD_MS)); buf[0] = 0;
ESP_ERROR_CHECK_WITHOUT_ABORT(result); ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, &reg, 1, buf, 1, (100 / portTICK_PERIOD_MS)));
if (result != ESP_OK) {
return 0;
}
return buf[0]; return buf[0];
} }
static void receive_keypad(void) { static void receive_keypad(void) {
// TODO: use mutex
// TODO: change the bottom half polling scheme from a state-based protocol to an event based protocol
uint8_t reg = 2; uint8_t reg = 2;
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, &reg, 1, buf, 2, (100 / portTICK_PERIOD_MS)); buf[0] = 0;
ESP_ERROR_CHECK_WITHOUT_ABORT(result); buf[1] = 0;
if (result != ESP_OK) { ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, &reg, 1, buf, 2, (100 / portTICK_PERIOD_MS)));
return;
}
uint16_t new_keypad_state = buf[0] | (buf[1] << 8); uint16_t new_keypad_state = buf[0] | (buf[1] << 8);
uint16_t just_pressed = new_keypad_state & ~keypad_state; uint16_t just_pressed = new_keypad_state & ~keypad_state;
if (is_state_tracking() && just_pressed) { keypad_pressed |= just_pressed;
char buf[6];
sprintf(buf, "%d", just_pressed);
event_occured("KP_PRESS", buf);
}
uint16_t just_released = ~new_keypad_state & keypad_state; uint16_t just_released = ~new_keypad_state & keypad_state;
if (is_state_tracking() && just_released) {
char buf[6];
sprintf(buf, "%d", just_released);
event_occured("KP_RELEASE", buf);
}
star_code_handle_keypad(&just_pressed, &just_released);
keypad_pressed |= just_pressed;
keypad_released |= just_released; keypad_released |= just_released;
keypad_state = new_keypad_state; keypad_state = new_keypad_state;
} }
static void receive_button_switch(void) { static void receive_button_switch(void) {
uint8_t reg = 3; uint8_t reg = 3;
esp_err_t result = i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, &reg, 1, buf, 2, (100 / portTICK_PERIOD_MS)); ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, &reg, 1, buf, 2, (100 / portTICK_PERIOD_MS)));
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
if (result != ESP_OK) {
return;
}
uint8_t new_button_state = buf[1] & 0xF; uint8_t new_button_state = buf[1] & 0xF;
uint8_t new_switch_state = (~buf[0]) & 0xF; uint8_t new_switch_state = (~buf[0]) & 0xF;
uint8_t new_switch_touch_state = (buf[1] >> 4) & 0xF; uint8_t new_switch_touch_state = (buf[1] >> 4) & 0xF;
@@ -130,57 +92,27 @@ static void receive_button_switch(void) {
// button // button
uint8_t just_pressed = new_button_state & ~button_state; uint8_t just_pressed = new_button_state & ~button_state;
button_pressed |= just_pressed; button_pressed |= just_pressed;
if (is_state_tracking() && just_pressed) {
char buf[4];
sprintf(buf, "%d", just_pressed);
event_occured("BTN_PRESS", buf);
}
uint8_t just_released = ~new_button_state & button_state; uint8_t just_released = ~new_button_state & button_state;
button_released |= just_released; button_released |= just_released;
if (is_state_tracking() && just_released) {
char buf[4];
sprintf(buf, "%d", just_released);
event_occured("BTN_RELEASE", buf);
}
button_state = new_button_state; button_state = new_button_state;
// switch // switch
uint8_t just_flipped_up = new_switch_state & ~switch_state; uint8_t just_flipped_up = new_switch_state & ~switch_state;
switch_flipped_up |= just_flipped_up; switch_flipped_up |= just_flipped_up;
if (is_state_tracking() && just_flipped_up) {
char buf[4];
sprintf(buf, "%d", just_flipped_up);
event_occured("SW_UP", buf);
}
uint8_t just_flipped_down = ~new_switch_state & switch_state; uint8_t just_flipped_down = ~new_switch_state & switch_state;
switch_flipped_down |= just_flipped_down; switch_flipped_down |= just_flipped_down;
if (is_state_tracking() && just_flipped_down) {
char buf[4];
sprintf(buf, "%d", just_flipped_down);
event_occured("SW_DOWN", buf);
}
switch_state = new_switch_state; switch_state = new_switch_state;
// switch touch // switch touch
uint8_t touch_just_pressed = new_switch_touch_state & ~switch_touch_state; uint8_t touch_just_pressed = new_switch_touch_state & ~switch_touch_state;
switch_touch_pressed |= touch_just_pressed; switch_touch_pressed |= touch_just_pressed;
if (is_state_tracking() && touch_just_pressed) {
char buf[4];
sprintf(buf, "%d", touch_just_pressed);
event_occured("SW_TOUCH", buf);
}
uint8_t touch_just_released = ~new_switch_touch_state & switch_touch_state; uint8_t touch_just_released = ~new_switch_touch_state & switch_touch_state;
switch_touch_released |= touch_just_released; switch_touch_released |= touch_just_released;
if (is_state_tracking() && touch_just_released) {
char buf[4];
sprintf(buf, "%d", touch_just_released);
event_occured("SW_UNTOUCH", buf);
}
switch_touch_state = new_switch_touch_state; switch_touch_state = new_switch_touch_state;
} }
@@ -193,15 +125,9 @@ static void receive_touch(void) {
bool just_pressed = new_touch_state & !touch_state; bool just_pressed = new_touch_state & !touch_state;
touch_pressed |= just_pressed; touch_pressed |= just_pressed;
if (is_state_tracking() && just_pressed) {
event_occured("FINGER_TOUCHED", NULL);
}
bool just_released = (!new_touch_state) & touch_state; bool just_released = (!new_touch_state) & touch_state;
touch_released |= just_released; touch_released |= just_released;
if (is_state_tracking() && just_released) {
event_occured("FINGER_UNTOUCHED", NULL);
}
touch_state = new_touch_state; touch_state = new_touch_state;
} }
@@ -237,8 +163,7 @@ void clear_all_pressed_released(void) {
touch_released = 0; touch_released = 0;
} }
// TODO: this is public, but it won't need to be after the event-based protocol refactor static bool _take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
bool take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
int bit_selector = (1 << i); int bit_selector = (1 << i);
if ((*keypad_bitfield) & bit_selector) { if ((*keypad_bitfield) & bit_selector) {
@@ -254,10 +179,10 @@ bool take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
} }
bool get_keypad_pressed(KeypadKey* kp) { bool get_keypad_pressed(KeypadKey* kp) {
return take_key(kp, &keypad_pressed); return _take_key(kp, &keypad_pressed);
} }
bool get_keypad_released(KeypadKey* kp) { bool get_keypad_released(KeypadKey* kp) {
return take_key(kp, &keypad_released); return _take_key(kp, &keypad_released);
} }
char char_of_keypad_key(KeypadKey kp) { char char_of_keypad_key(KeypadKey kp) {
@@ -382,6 +307,7 @@ uint8_t get_switch_touch_state(){
return switch_touch_state; return switch_touch_state;
} }
bool get_touch_state(void) { bool get_touch_state(void) {
return touch_state; return touch_state;
} }
+13 -21
View File
@@ -6,7 +6,7 @@
#define BOTTOM_I2C_NUM I2C_NUM_0 #define BOTTOM_I2C_NUM I2C_NUM_0
#define BOTTOM_I2C_ADDR 126 #define BOTTOM_I2C_ADDR 126
#define BOTTOM_PIN_INTERUPT GPIO_NUM_13 #define BOTTOM_PIN_INTERUPT GPIO_NUM_0
#define DELTA_BIT_KP 0 #define DELTA_BIT_KP 0
#define DELTA_BIT_BUTTON_SWITCH 1 #define DELTA_BIT_BUTTON_SWITCH 1
@@ -14,22 +14,22 @@
/// @brief An enum for the possible keypad buttons. /// @brief An enum for the possible keypad buttons.
typedef enum { typedef enum {
kd = 0, k1 = 0,
pound = 1, k4 = 1,
k0 = 2, k7 = 2,
star = 3, star = 3,
kc = 4, k2 = 4,
k9 = 5, k5 = 5,
k8 = 6, k8 = 6,
k7 = 7, k0 = 7,
kb = 8, k3 = 8,
k6 = 9, k6 = 9,
k5 = 10, k9 = 10,
k4 = 11, pound = 11,
ka = 12, ka = 12,
k3 = 13, kb = 13,
k2 = 14, kc = 14,
k1 = 15, kd = 15,
} KeypadKey; } KeypadKey;
/// @brief An enum for the possible buttons. /// @brief An enum for the possible buttons.
@@ -126,14 +126,6 @@ bool get_touch_pressed();
/// @return true if the touch sensor was just released /// @return true if the touch sensor was just released
bool get_touch_released(); bool get_touch_released();
/// @brief A helper function for internal use.
///
/// Takes one key from the bitfield and sets the `kp` variable accordingly if the bitfield is not 0.
/// @param kp Out. The keypad key to set.
/// @param keypad_bitfield A pointer to the keypad bitfield to take a key from
/// @return true if a key was taken from the bitfield
bool take_key(KeypadKey* kp, uint16_t* keypad_bitfield);
// TODO: add touch sensor for switch // TODO: add touch sensor for switch
#endif /* BOTTOM_HALF_HPP */ #endif /* BOTTOM_HALF_HPP */
+14 -211
View File
@@ -2,100 +2,10 @@
#include "./i2c_lcd_pcf8574.h" #include "./i2c_lcd_pcf8574.h"
#include <esp_log.h> #include <esp_log.h>
#include "state_tracking.h"
#include <cstring>
#include "power.h"
#include "starcode.h"
#include "game_info.h"
i2c_lcd_pcf8574_handle_t lcd; i2c_lcd_pcf8574_handle_t lcd;
static volatile bool header_enabled = false;
static const char *TAG = "char_lcd"; static const char *TAG = "char_lcd";
static const char* EMPTY_ROW = " ";
static char buf[65];
static void monitor_battery_task(void* _arg) {
(void) _arg;
while (true) {
vTaskDelay(pdMS_TO_TICKS(1'000));
lcd_print_header_bat();
}
}
static bool replay_handler(const char* event, char* arg) {
if (strcmp(event, "LCD_CLEAR") == 0) {
lcd_clear();
return true;
}
if (strcmp(event, "LCD_CURSOR") == 0) {
char* col_str = strtok(arg, ",");
char* row_str = strtok(NULL, ",");
uint32_t col = atoi(col_str);
uint32_t row = atoi(row_str);
lcd_set_cursor_pos(col, row);
return true;
}
if (strcmp(event, "LCD_SET_DISPLAY") == 0) {
lcd_set_display(strcmp(arg, "true") == 0);
return true;
}
if (strcmp(event, "LCD_CURSOR_VIS") == 0) {
lcd_set_cursor_vis(strcmp(arg, "true") == 0);
return true;
}
if (strcmp(event, "LCD_CURSOR_BLINK") == 0) {
lcd_set_cursor_blink(strcmp(arg, "true") == 0);
return true;
}
if (strcmp(event, "LCD_SCROLL_DISPLAY_LEFT") == 0) {
lcd_scroll_display_left();
return true;
}
if (strcmp(event, "LCD_SCROLL_DISPLAY_RIGHT") == 0) {
lcd_scroll_display_right();
return true;
}
if (strcmp(event, "LCD_LEFT_TO_RIGHT") == 0) {
lcd_left_to_right();
return true;
}
if (strcmp(event, "LCD_RIGHT_TO_LEFT") == 0) {
lcd_right_to_left();
return true;
}
if (strcmp(event, "LCD_AUTOSCROLL") == 0) {
lcd_set_autoscroll(strcmp(arg, "true") == 0);
return true;
}
if (strcmp(event, "LCD_BACKLIGHT") == 0) {
lcd_set_backlight(strcmp(arg, "true") == 0);
return true;
}
if (strcmp(event, "LCD_CREATE_CHAR") == 0) {
char* location_str = strtok(arg, ",");
uint8_t location = atoi(location_str);
uint8_t charmap[8];
for (int i = 0; i < 8; i++) {
char* str = strtok(NULL, ",");
charmap[i] = atoi(str);
}
lcd_create_char(location, charmap);
return true;
}
if (strcmp(event, "LCD_PRINT") == 0) {
// TODO: handle \r and \n
lcd_print(&lcd, arg);
return true;
}
return false;
}
void init_lcd() { void init_lcd() {
ESP_LOGI(TAG, "Initializing LCD..."); ESP_LOGI(TAG, "Initializing LCD...");
@@ -105,40 +15,20 @@ void init_lcd() {
lcd_set_backlight(&lcd, 255); lcd_set_backlight(&lcd, 255);
register_replay_fn(replay_handler);
xTaskCreate(monitor_battery_task, "bat_monitor", 1024*2, nullptr, 0, nullptr);
ESP_LOGI(TAG, "LCD initialized!"); ESP_LOGI(TAG, "LCD initialized!");
} }
void lcd_clear() { void lcd_clear() {
if (!header_enabled) { lcd_clear(&lcd);
lcd_clear(&lcd);
if (is_state_tracking()) {
event_occured("LCD_CLEAR", NULL);
}
} else {
lcd_print(0, 1, EMPTY_ROW);
lcd_print(0, 2, EMPTY_ROW);
lcd_print(0, 3, EMPTY_ROW);
}
} }
// TODO: rm
void lcd_cursor_home() { void lcd_cursor_home() {
lcd_set_cursor_pos(0, 0); lcd_home(&lcd);
} }
// TODO: with print requiring you to set a pos every time, this function is not helpful
void lcd_set_cursor_pos(uint8_t col, uint8_t row) { void lcd_set_cursor_pos(uint8_t col, uint8_t row) {
lcd_set_cursor(&lcd, col, row); lcd_set_cursor(&lcd, col, row);
if (is_state_tracking()) {
sprintf(buf, "%d,%d", col, row);
event_occured("LCD_CURSOR", buf);
}
} }
void lcd_set_display(bool display) { void lcd_set_display(bool display) {
@@ -147,10 +37,6 @@ void lcd_set_display(bool display) {
} else { } else {
lcd_no_display(&lcd); lcd_no_display(&lcd);
} }
if (is_state_tracking()) {
event_occured("LCD_SET_DISPLAY", display ? "true" : "false");
}
} }
void lcd_set_cursor_vis(bool cursor) { void lcd_set_cursor_vis(bool cursor) {
@@ -159,10 +45,6 @@ void lcd_set_cursor_vis(bool cursor) {
} else { } else {
lcd_no_cursor(&lcd); lcd_no_cursor(&lcd);
} }
if (is_state_tracking()) {
event_occured("LCD_CURSOR_VIS", cursor ? "true" : "false");
}
} }
void lcd_set_cursor_blink(bool blink) { void lcd_set_cursor_blink(bool blink) {
@@ -171,40 +53,20 @@ void lcd_set_cursor_blink(bool blink) {
} else { } else {
lcd_no_blink(&lcd); lcd_no_blink(&lcd);
} }
if (is_state_tracking()) {
event_occured("LCD_CURSOR_BLINK", blink ? "true" : "false");
}
} }
void lcd_scroll_display_left() { void lcd_scroll_display_left() {
lcd_scroll_display_left(&lcd); lcd_scroll_display_left(&lcd);
if (is_state_tracking()) {
event_occured("LCD_SCROLL_DISPLAY_LEFT", NULL);
}
} }
void lcd_scroll_display_right() { void lcd_scroll_display_right() {
lcd_scroll_display_right(&lcd); lcd_scroll_display_right(&lcd);
if (is_state_tracking()) {
event_occured("LCD_SCROLL_DISPLAY_RIGHT", NULL);
}
} }
void lcd_left_to_right() { void lcd_left_to_right() {
lcd_left_to_right(&lcd); lcd_left_to_right(&lcd);
if (is_state_tracking()) {
event_occured("LCD_LEFT_TO_RIGHT", NULL);
}
} }
void lcd_right_to_left() { void lcd_right_to_left() {
lcd_right_to_left(&lcd); lcd_right_to_left(&lcd);
if (is_state_tracking()) {
event_occured("LCD_RIGHT_TO_LEFT", NULL);
}
} }
void lcd_set_autoscroll(bool autoscroll) { void lcd_set_autoscroll(bool autoscroll) {
@@ -213,84 +75,25 @@ void lcd_set_autoscroll(bool autoscroll) {
} else { } else {
lcd_no_autoscroll(&lcd); lcd_no_autoscroll(&lcd);
} }
if (is_state_tracking()) {
event_occured("LCD_AUTOSCROLL", autoscroll ? "true" : "false");
}
} }
void lcd_set_backlight(bool backlight) { void lcd_set_backlight(uint8_t brightness) {
lcd_set_backlight(&lcd, backlight); lcd_set_backlight(&lcd, brightness);
if (is_state_tracking()) {
sprintf(buf, "%d", backlight);
event_occured("LCD_BACKLIGHT", backlight ? "true" : "false");
}
} }
void lcd_create_char(uint8_t location, const uint8_t charmap[]) { void lcd_create_char(uint8_t location, uint8_t charmap[]) {
lcd_create_char(&lcd, location, charmap); lcd_create_char(&lcd, location, charmap);
if (is_state_tracking()) {
snprintf(buf, 65,
"%d,%d,%d,%d,%d,%d,%d,%d,%d", location,
charmap[0], charmap[1], charmap[2], charmap[3], charmap[4], charmap[5], charmap[6], charmap[7]
);
event_occured("LCD_CREATE_CHAR", buf);
}
} }
// TODO: switch to row, col void lcd_write(uint8_t value) {
lcd_write(&lcd, value);
}
void lcd_print(const char* str) {
lcd_print(&lcd, str);
}
void lcd_print(uint8_t col, uint8_t row, const char* str) { void lcd_print(uint8_t col, uint8_t row, const char* str) {
lcd_set_cursor_pos(col, row); lcd_set_cursor_pos(col, row);
lcd_print(&lcd, str); lcd_print(&lcd, str);
if (is_state_tracking()) {
// TODO: handle \r and \n
event_occured("LCD_PRINT", str);
}
}
void set_lcd_header_enabled(bool enable) {
bool old_header_enabled = header_enabled;
header_enabled = enable;
// update header in response to enabling/disabling the header
if (enable && !old_header_enabled) {
lcd_print_header();
} else if (!enable && old_header_enabled) {
lcd_print(0, 0, EMPTY_ROW);
}
}
bool lcd_header_enabled() {
return header_enabled;
}
void lcd_print_header() {
lcd_print_header_star_code();
lcd_print_header_step();
lcd_print_header_bat();
}
void lcd_do_splash() {
const uint8_t custom_char[6][8] = {
{ 0x01, 0x01, 0x02, 0x02, 0x07, 0x07, 0x0F, 0x0D },
{ 0x10, 0x10, 0x18, 0x18, 0x1C, 0x0C, 0x0E, 0x06 },
{ 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x07 },
{ 0x19, 0x1B, 0x13, 0x17, 0x07, 0x0F, 0x0F, 0x1F },
{ 0x13, 0x1B, 0x1F, 0x1F, 0x00, 0x1F, 0x1F, 0x1F },
{ 0x00, 0x00, 0x10, 0x10, 0x00, 0x18, 0x1C, 0x1C },
};
// TODO: make the lcd_lib somehow support the custom character 0 which would otherwise be a null terminator
lcd_create_char(1, custom_char[0]);
lcd_create_char(2, custom_char[1]);
lcd_create_char(3, custom_char[2]);
lcd_create_char(4, custom_char[3]);
lcd_create_char(5, custom_char[4]);
lcd_create_char(6, custom_char[5]);
lcd_print(6, 1, "\x01\x02Marino");
lcd_print(5, 2, "\x03\x04\x05\x06""DEV");
} }
+9 -20
View File
@@ -44,29 +44,18 @@ void lcd_right_to_left();
void lcd_set_autoscroll(bool autoscroll); void lcd_set_autoscroll(bool autoscroll);
// Set backlight brightness // Set backlight brightness
void lcd_set_backlight(bool backlight); void lcd_set_backlight(uint8_t brightness);
// Create a custom character // Create a custom character
void lcd_create_char(uint8_t location, const uint8_t charmap[]); void lcd_create_char(uint8_t location, uint8_t charmap[]);
/// @brief Print a string to the LCD at a given pos. // Write a character to the LCD
/// @param col the column to print the string at. void lcd_write(uint8_t value);
/// @param row the row the print the string at.
/// @param str the string to print. // Print a string to the LCD
void lcd_print(const char* str);
// Print a string to the LCD at a given pos
void lcd_print(uint8_t col, uint8_t row, const char* str); void lcd_print(uint8_t col, uint8_t row, const char* str);
/// @brief Enables or disables the header on the LCD.
/// @param enable `true` to enable the header, `false` to disable.
void set_lcd_header_enabled(bool enable);
/// @brief Returns weather or not the lcd_header is enabled.
/// @return `true` if the header is enabled, `false` otherwise.
bool lcd_header_enabled();
/// @brief Prints the header in the LCD.
void lcd_print_header();
/// @brief Prints the splash screen for the BLK_BOX.
void lcd_do_splash();
#endif /* CHAR_LCD_H */ #endif /* CHAR_LCD_H */
-21
View File
@@ -1,21 +0,0 @@
#include "game_info.h"
#include "starcode.h"
#include <stdio.h>
#include "char_lcd.h"
static char game_state[GAME_STATE_MAX_LEN+2] = " MENU ";
void set_game_state(const char* new_state) {
snprintf(game_state, sizeof(game_state), " %-5s", new_state);
}
void reset_game_state() {
set_game_state("");
}
void lcd_print_header_step() {
if (!lcd_header_enabled()) return;
if (lcd_starcode_displaying_result()) return;
lcd_print(10, 0, game_state);
}
-17
View File
@@ -1,17 +0,0 @@
#ifndef GAME_INFO_H
#define GAME_INFO_H
#define GAME_STATE_MAX_LEN 5
/// @brief Sets the game state, used for the header.
///
/// Must be <= 5 characters
void set_game_state(const char* new_state);
/// @brief Resets the game state to be blank.
void reset_game_state();
/// @brief Prints the game state section of the header to the char_lcd. (row 0, columns 11-15)
void lcd_print_header_step();
#endif /* GAME_INFO_H */
-35
View File
@@ -1,35 +0,0 @@
#include "i2c.h"
#include "esp_log.h"
#include "esp_err.h"
#include "driver/i2c.h"
static const char *TAG = "i2c";
SemaphoreHandle_t main_i2c_mutex;
void init_i2c() {
ESP_LOGI(TAG, "Initializing i2c...");
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = PIN_I2C_SDA,
.scl_io_num = PIN_I2C_SCL,
.sda_pullup_en = GPIO_PULLUP_DISABLE,
.scl_pullup_en = GPIO_PULLUP_DISABLE,
// .sda_pullup_en = GPIO_PULLUP_ENABLE,
// .scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = {
// TODO: 400k?
.clk_speed = 100*1000,
},
.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL
};
ESP_ERROR_CHECK(i2c_param_config(MAIN_I2C_BUS_NUM, &conf));
ESP_ERROR_CHECK(i2c_driver_install(MAIN_I2C_BUS_NUM, conf.mode, 0, 0, 0));
main_i2c_mutex = xSemaphoreCreateMutex();
assert(main_i2c_mutex != NULL);
ESP_LOGI(TAG, "i2c initialized!");
}
-26
View File
@@ -1,26 +0,0 @@
#ifndef I2C_H
#define I2C_H
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#define MAIN_I2C_BUS_NUM I2C_NUM_0
#define PIN_I2C_SDA GPIO_NUM_7
#define PIN_I2C_SCL GPIO_NUM_15
/// The mutex for accessing `I2C_NUM_0`.
extern SemaphoreHandle_t main_i2c_mutex;
/// @brief Initializes `I2C_NUM_0`.
///
/// This is hooked up the to:
/// - The bottom half
/// - The char lcd
/// - The power board
/// - The MPU6050
/// - The PERH port
/// - The Capacitive Touch Panel
void init_i2c();
#endif /* I2C_H */
+3 -10
View File
@@ -12,7 +12,6 @@
#include "esp_check.h" #include "esp_check.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "i2c.h"
#define TAG "I2C_LCD_PCF8574" #define TAG "I2C_LCD_PCF8574"
@@ -59,7 +58,6 @@ void lcd_begin(i2c_lcd_pcf8574_handle_t* lcd, uint8_t cols, uint8_t rows) {
lcd->entrymode = 0x02; lcd->entrymode = 0x02;
// The following are the reset sequence: Please see "Initialization instruction in the PCF8574 datasheet." // The following are the reset sequence: Please see "Initialization instruction in the PCF8574 datasheet."
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd); i2c_master_start(cmd);
// We left-shift the device addres and add the read/write command // We left-shift the device addres and add the read/write command
@@ -97,7 +95,6 @@ void lcd_begin(i2c_lcd_pcf8574_handle_t* lcd, uint8_t cols, uint8_t rows) {
i2c_master_stop(cmd); i2c_master_stop(cmd);
i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS); i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd); i2c_cmd_link_delete(cmd);
xSemaphoreGive(main_i2c_mutex);
// Instruction: function set = 0x20 // Instruction: function set = 0x20
lcd_send(lcd, 0x20 | (rows > 1 ? 0x08 : 0x00), false); lcd_send(lcd, 0x20 | (rows > 1 ? 0x08 : 0x00), false);
@@ -113,7 +110,7 @@ void lcd_clear(i2c_lcd_pcf8574_handle_t* lcd) {
// Instruction: Clear display = 0x01 // Instruction: Clear display = 0x01
lcd_send(lcd, 0x01, false); lcd_send(lcd, 0x01, false);
// Clearing the display takes a while: takes approx. 1.5ms // Clearing the display takes a while: takes approx. 1.5ms
esp_rom_delay_us(2000); esp_rom_delay_us(1600);
} // lcd_clear() } // lcd_clear()
// Set the display to home // Set the display to home
@@ -121,7 +118,7 @@ void lcd_home(i2c_lcd_pcf8574_handle_t* lcd) {
// Instruction: Return home = 0x02 // Instruction: Return home = 0x02
lcd_send(lcd, 0x02, false); lcd_send(lcd, 0x02, false);
// Same as clearing the display: takes approx. 1.5ms // Same as clearing the display: takes approx. 1.5ms
esp_rom_delay_us(2000); esp_rom_delay_us(1600);
} // lcd_home() } // lcd_home()
// Set the cursor to a new position. // Set the cursor to a new position.
@@ -241,7 +238,7 @@ void lcd_set_backlight(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness) {
} // lcd_set_backlight() } // lcd_set_backlight()
// Custom character creation: allows us to create up to 8 custom characters in the CGRAM locations // Custom character creation: allows us to create up to 8 custom characters in the CGRAM locations
void lcd_create_char(i2c_lcd_pcf8574_handle_t* lcd, uint8_t location, const uint8_t charmap[]) { void lcd_create_char(i2c_lcd_pcf8574_handle_t* lcd, uint8_t location, uint8_t charmap[]) {
location &= 0x7; // Only 8 locations are available location &= 0x7; // Only 8 locations are available
// Set the CGRAM address // Set the CGRAM address
lcd_send(lcd, 0x40 | (location << 3), false); lcd_send(lcd, 0x40 | (location << 3), false);
@@ -298,7 +295,6 @@ void lcd_print_number(i2c_lcd_pcf8574_handle_t* lcd, uint8_t col, uint8_t row, u
static void lcd_send(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value, bool is_data) { static void lcd_send(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value, bool is_data) {
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd); i2c_master_start(cmd);
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true); i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
@@ -307,7 +303,6 @@ static void lcd_send(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value, bool is_data)
i2c_master_stop(cmd); i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS); esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd); i2c_cmd_link_delete(cmd);
xSemaphoreGive(main_i2c_mutex);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to send data to LCD: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "Failed to send data to LCD: %s", esp_err_to_name(ret));
@@ -346,7 +341,6 @@ static void lcd_write_i2c(i2c_lcd_pcf8574_handle_t* lcd, uint8_t data, bool is_d
data |= lcd->backlight_mask; data |= lcd->backlight_mask;
} }
xSemaphoreTake(main_i2c_mutex, portMAX_DELAY);
i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd); i2c_master_start(cmd);
i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true); i2c_master_write_byte(cmd, (lcd->i2c_addr << 1) | I2C_MASTER_WRITE, true);
@@ -354,7 +348,6 @@ static void lcd_write_i2c(i2c_lcd_pcf8574_handle_t* lcd, uint8_t data, bool is_d
i2c_master_stop(cmd); i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS); esp_err_t ret = i2c_master_cmd_begin(lcd->i2c_port, cmd, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd); i2c_cmd_link_delete(cmd);
xSemaphoreGive(main_i2c_mutex);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to write to LCD: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "Failed to write to LCD: %s", esp_err_to_name(ret));
+1 -1
View File
@@ -94,7 +94,7 @@ void lcd_no_autoscroll(i2c_lcd_pcf8574_handle_t* lcd);
void lcd_set_backlight(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness); void lcd_set_backlight(i2c_lcd_pcf8574_handle_t* lcd, uint8_t brightness);
// Create a custom character // Create a custom character
void lcd_create_char(i2c_lcd_pcf8574_handle_t* lcd, uint8_t location, const uint8_t charmap[]); void lcd_create_char(i2c_lcd_pcf8574_handle_t* lcd, uint8_t location, uint8_t charmap[]);
// Write a character to the LCD // Write a character to the LCD
void lcd_write(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value); void lcd_write(i2c_lcd_pcf8574_handle_t* lcd, uint8_t value);
-486
View File
@@ -1,486 +0,0 @@
#include "blk_box_drivers/inputs.hpp"
#include "bottom_half.h"
#include "pins.h"
#include "driver/i2c.h"
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_err.h"
static const char *TAG = "INPUTS";
static TaskHandle_t expander_task_handle = NULL;
static i2c_master_dev_handle_t expander_i2c_dev_handle;
const static uint8_t REG_WHOAMI = 0x01;
const static uint8_t REG_SW_VERSION = 0x02;
const static uint8_t REG_EVENT_QUEUE_POP = 0x10;
const static uint8_t REG_EVENT_QUEUE_LEN = 0x11;
const static uint8_t REG_STATE_BUTTONS = 0x20;
const static uint8_t REG_STATE_SWITCHES = 0x21;
const static uint8_t REG_STATE_KEYPAD = 0x22;
const static uint8_t REG_STATE_TOUCH = 0x23;
const static uint8_t REG_STATE_RFID = 0x24;
const static uint8_t REG_STATE_HALL = 0x25;
const static uint8_t REG_STATE_CLOSE = 0x26;
const static uint8_t REG_RESET = 0x30;
const static uint8_t REG_HALL_SENSITIVITY = 0x31;
const static uint8_t REG_CLOSE_SENSITIVITY = 0x32;
const static uint8_t REG_SWITCH_TOUCH_EVENT = 0x33;
/// The global data for the expander peripheral.
class ExpanderPeripheral {
// TODO: change these to private
// or even make this class hidden
public:
SemaphoreHandle_t state_mutex;
InputsState state;
// channels
QueueHandle_t button_press_events;
QueueHandle_t button_release_events;
QueueHandle_t switch_flip_events;
QueueHandle_t switch_touch_events;
QueueHandle_t touch_events;
QueueHandle_t keypad_press_events;
QueueHandle_t keypad_release_events;
};
ExpanderPeripheral expander_peripheral_singleton;
// forward declarations
static void get_events();
static void handle_event(uint8_t event);
static void handle_button_switch_event(uint8_t event);
static void handle_keypad_event(uint8_t event);
static void handle_touch_event(uint8_t event);
static void handle_rfid_event(uint8_t event);
static void handle_close_hal_event(uint8_t event);
static void expander_task(void *arg);
// ISR handler
static void IRAM_ATTR expander_isr_handler(void *arg) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (expander_task_handle != NULL) {
vTaskNotifyGiveFromISR(expander_task_handle, &xHigherPriorityTaskWoken);
}
if (xHigherPriorityTaskWoken == pdTRUE) {
portYIELD_FROM_ISR();
}
}
void init_expander() {
ESP_LOGI(TAG, "Initializing expander...");
i2c_device_config_t dev_config = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = EXPANDER_I2C_ADDR,
.scl_speed_hz = EXPANDER_I2C_SPEED,
.scl_wait_us = 0, // default
.flags = {
.disable_ack_check = 0,
}
};
// setup interrupt on BOTTOM_PIN_INTERUPT
gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << BOTTOM_PIN_INTERUPT),
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_NEGEDGE
};
ESP_ERROR_CHECK(gpio_config(&io_conf));
// Install ISR service (only call once in your program)
ESP_ERROR_CHECK(gpio_install_isr_service(0));
// Attach the ISR to the expander pin
ESP_ERROR_CHECK(gpio_isr_handler_add(BOTTOM_PIN_INTERUPT, expander_isr_handler, NULL));
// verify the expander connection status by reading the WHOAMI register
uint8_t read_buf[2] = {0};
i2c_master_write_read_device(I2C_NUM_0, BOTTOM_I2C_ADDR, &REG_WHOAMI, 1, read_buf, 1, 1000);
if (read_buf[0] != EXPANDER_WHOAMI_VALUE) {
ESP_LOGE(TAG, "WHOAMI mismatch, expected 0x%02X, got 0x%02X", EXPANDER_WHOAMI_VALUE, read_buf[0]);
return;
}
ESP_LOGD(TAG, "Expander WHOAMI check passed");
ESP_ERROR_CHECK(i2c_master_transmit_receive(expander_i2c_dev_handle, &REG_SW_VERSION, 1, read_buf, 2, EXPANDER_TIMEOUT_MS));
// init the peripheral struct
expander_peripheral_singleton.state_mutex = xSemaphoreCreateMutex();
expander_peripheral_singleton.button_press_events= xQueueCreate(EXPANDER_EVENT_QUEUE_SIZE, sizeof(Button));
expander_peripheral_singleton.button_release_events= xQueueCreate(EXPANDER_EVENT_QUEUE_SIZE, sizeof(Button));
expander_peripheral_singleton.switch_flip_events= xQueueCreate(EXPANDER_EVENT_QUEUE_SIZE, sizeof(SwitchFlip));
expander_peripheral_singleton.switch_touch_events= xQueueCreate(EXPANDER_EVENT_QUEUE_SIZE, sizeof(SwitchTouch));
expander_peripheral_singleton.touch_events= xQueueCreate(EXPANDER_EVENT_QUEUE_SIZE, sizeof(TouchedReleased));
expander_peripheral_singleton.keypad_press_events= xQueueCreate(EXPANDER_KEYPAD_QUEUE_SIZE, sizeof(KeypadKey));
expander_peripheral_singleton.keypad_release_events= xQueueCreate(EXPANDER_KEYPAD_QUEUE_SIZE, sizeof(KeypadKey));
ESP_LOGI(TAG, "Expander initialized! SW version: v%d.%d", read_buf[0], read_buf[1]);
// Create the expander background worker task
BaseType_t task_created = xTaskCreate(
expander_task,
"expander_task",
4096,
NULL,
tskIDLE_PRIORITY + 1,
&expander_task_handle
);
if (task_created != pdPASS) {
ESP_LOGE(TAG, "Failed to create expander task");
}
}
static void expander_task(void *arg) {
(void)arg;
while (true) {
get_events();
// Wait for interrupt notification (signal is sent when INT falls)
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
}
}
static void get_events() {
uint8_t recv;
while (gpio_get_level(PIN_EXPANDER_INT) == 0) {
ESP_ERROR_CHECK(i2c_master_transmit_receive(expander_i2c_dev_handle, &REG_EVENT_QUEUE_POP, 1, &recv, 1, EXPANDER_TIMEOUT_MS));
handle_event(recv);
}
}
static void handle_event(uint8_t event) {
const uint8_t BUTTON_SWITCH = 0b000;
const uint8_t KEYPAD = 0b001;
const uint8_t TOUCH = 0b010;
const uint8_t RFID = 0b011;
ESP_LOGD(TAG, "Expander event: 0b%08b (0x%02X)", event, event);
if (event == 0) {
ESP_LOGE(TAG, "We read from event queue while it was empty!");
return;
}
uint8_t type_bits = event >> 5;
switch (type_bits) {
case BUTTON_SWITCH:
handle_button_switch_event(event);
break;
case KEYPAD:
handle_keypad_event(event);
break;
case TOUCH:
handle_touch_event(event);
break;
case RFID:
handle_rfid_event(event);
break;
default:
handle_close_hal_event(event);
break;
}
}
static void handle_button_switch_event(uint8_t event) {
const uint8_t PRESSED_NOT_RELEASED_BIT = 0b10000;
const uint8_t SWITCH_NOT_BUTTON_BIT = 0b01000;
const uint8_t SWITCH_UP_NOT_DOWN_BIT = 0b00100;
const uint8_t NUMBER_MASK = 0b00011;
bool pressed = (event & PRESSED_NOT_RELEASED_BIT) != 0;
uint8_t number = event & NUMBER_MASK;
if ((event & SWITCH_NOT_BUTTON_BIT) != 0) {
// For now, we support two position switches by only looking at the switch up events
bool switch_up = (event & SWITCH_UP_NOT_DOWN_BIT) != 0;
if (!switch_up) {
return;
}
Switch sw = static_cast<Switch>(number);
SwitchFlip sw_flip = SwitchFlip(sw, pressed);
xQueueSendToBack(expander_peripheral_singleton.switch_flip_events, &sw_flip, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
if (pressed) {
// set
expander_peripheral_singleton.state.switch_state |= 1 << number;
} else {
// clear
expander_peripheral_singleton.state.switch_state &= ~(1 << number);
}
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
} else {
// button
Button button = static_cast<Button>(number);
if (pressed) {
xQueueSendToBack(expander_peripheral_singleton.button_press_events, &button, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
expander_peripheral_singleton.state.button_state |= 1 << number;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
} else {
xQueueSendToBack(expander_peripheral_singleton.button_release_events, &button, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
expander_peripheral_singleton.state.button_state &= ~(1 << number);
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
}
}
}
static void handle_keypad_event(uint8_t event) {
const uint8_t PRESSED_NOT_RELEASED_BIT = 0b10000;
const uint8_t KEY_MASK = 0b1111;
bool pressed = (event & PRESSED_NOT_RELEASED_BIT) != 0;
uint8_t number = event & KEY_MASK;
KeypadKey key = static_cast<KeypadKey>(number);
// starcode system gets first dibs
// TODO: do starcode inbetweener
// if starcode_handle_keypad(key, pressed).await {
// return;
// }
if (pressed) {
xQueueSendToBack(expander_peripheral_singleton.keypad_press_events, &key, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
expander_peripheral_singleton.state.keypad_state |= 1 << number;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
} else {
xQueueSendToBack(expander_peripheral_singleton.keypad_release_events, &key, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
expander_peripheral_singleton.state.keypad_state &= ~(1 << number);
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
}
}
static void handle_touch_event(uint8_t event) {
const uint8_t TOUCHED_NOT_UNTOUCHED_BIT = 0b10000;
const uint8_t SENSOR_MASK = 0b0111;
const uint8_t FINGERPRINT_BIT = 0b0100;
bool touched = (event & TOUCHED_NOT_UNTOUCHED_BIT) != 0;
uint8_t sensor = event & SENSOR_MASK;
if ((sensor & FINGERPRINT_BIT) != 0) {
TouchedReleased touch_state = static_cast<TouchedReleased>(touched);
xQueueSendToBack(expander_peripheral_singleton.touch_events, &touch_state, 0);
} else {
Switch sw = static_cast<Switch>(sensor);
SwitchTouch sw_touch = SwitchTouch(sw, touched);
xQueueSendToBack(expander_peripheral_singleton.switch_touch_events, &sw_touch, 0);
}
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
if (touched) {
expander_peripheral_singleton.state.touch_state |= 1 << sensor;
} else {
expander_peripheral_singleton.state.touch_state &= ~(1 << sensor);
}
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
}
static void handle_rfid_event(uint8_t event) {
// TODO: impl
(void)event;
}
static void handle_close_hal_event(uint8_t event) {
// TODO: impl
(void)event;
}
// InputsController implementations
/// Clears all events waiting in the queues.
void InputsController::clear_all_events() {
xQueueReset(expander_peripheral_singleton.button_press_events);
xQueueReset(expander_peripheral_singleton.button_release_events);
xQueueReset(expander_peripheral_singleton.switch_flip_events);
xQueueReset(expander_peripheral_singleton.switch_touch_events);
xQueueReset(expander_peripheral_singleton.touch_events);
xQueueReset(expander_peripheral_singleton.keypad_press_events);
xQueueReset(expander_peripheral_singleton.keypad_release_events);
}
InputsState InputsController::get_input_state() {
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
InputsState state_copy = expander_peripheral_singleton.state;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
return state_copy;
}
/// Returns `true` iff there is a button press event waiting.
bool InputsController::has_button_press() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.button_press_events) > 0;
}
/// Gets the next button press event (if any).
std::optional<Button> InputsController::get_button_press() {
Button b;
if (xQueueReceive(expander_peripheral_singleton.button_press_events, &b, 0) == pdTRUE) {
return b;
}
return std::nullopt;
}
/// Gets the next button press event, waiting if neccesary.
Button InputsController::wait_button_press() {
Button b;
xQueueReceive(expander_peripheral_singleton.button_press_events, &b, portMAX_DELAY);
return b;
}
/// Gets the current state of the buttons.
uint8_t InputsController::button_state() {
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
uint8_t value = expander_peripheral_singleton.state.button_state;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
return value;
}
/// Returns `true` iff there is a button release event waiting.
bool InputsController::has_button_release() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.button_release_events) > 0;
}
/// Gets the next button release event (if any).
std::optional<Button> InputsController::get_button_release() {
Button b;
if (xQueueReceive(expander_peripheral_singleton.button_release_events, &b, 0) == pdTRUE) {
return b;
}
return std::nullopt;
}
/// Gets the next button release event, waiting if neccesary.
Button InputsController::wait_button_release() {
Button b;
xQueueReceive(expander_peripheral_singleton.button_release_events, &b, portMAX_DELAY);
return b;
}
/// Returns `true` iff there is a switch flip event waiting.
bool InputsController::has_switch_flip() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.switch_flip_events) > 0;
}
/// Gets the next switch flip event (if any).
std::optional<SwitchFlip> InputsController::get_switch_flip() {
SwitchFlip s;
if (xQueueReceive(expander_peripheral_singleton.switch_flip_events, &s, 0) == pdTRUE) {
return s;
}
return std::nullopt;
}
/// Gets the next switch flip event, waiting if neccesary.
SwitchFlip InputsController::wait_switch_flip() {
SwitchFlip s;
xQueueReceive(expander_peripheral_singleton.switch_flip_events, &s, portMAX_DELAY);
return s;
}
/// Gets the current state of the switches.
uint8_t InputsController::switch_state() {
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
uint8_t value = expander_peripheral_singleton.state.switch_state;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
return value;
}
/// Returns `true` iff there is a switch touch event waiting.
bool InputsController::has_switch_touch() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.switch_touch_events) > 0;
}
/// Gets the next switch touch event (if any).
std::optional<SwitchTouch> InputsController::get_switch_touch() {
SwitchTouch s;
if (xQueueReceive(expander_peripheral_singleton.switch_touch_events, &s, 0) == pdTRUE) {
return s;
}
return std::nullopt;
}
/// Gets the next switch touch event, waiting if neccesary.
SwitchTouch InputsController::wait_switch_touch() {
SwitchTouch s;
xQueueReceive(expander_peripheral_singleton.switch_touch_events, &s, portMAX_DELAY);
return s;
}
/// Gets the current state of the touch sensors.
uint8_t InputsController::switch_touch_state() {
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
uint8_t value = expander_peripheral_singleton.state.touch_state;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
return value;
}
/// Returns `true` iff there is a keypad press event waiting.
bool InputsController::has_keypad_press() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.keypad_press_events) > 0;
}
/// Gets the next keypad press event (if any).
std::optional<KeypadKey> InputsController::get_keypad_press() {
KeypadKey k;
if (xQueueReceive(expander_peripheral_singleton.keypad_press_events, &k, 0) == pdTRUE) {
return k;
}
return std::nullopt;
}
/// Gets the next keypad press event, waiting if neccesary.
KeypadKey InputsController::wait_keypad_press() {
KeypadKey k;
xQueueReceive(expander_peripheral_singleton.keypad_press_events, &k, portMAX_DELAY);
return k;
}
/// Returns `true` iff there is a keypad release event waiting.
bool InputsController::has_keypad_release() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.keypad_release_events) > 0;
}
/// Gets the next keypad release event (if any).
std::optional<KeypadKey> InputsController::get_keypad_release() {
KeypadKey k;
if (xQueueReceive(expander_peripheral_singleton.keypad_release_events, &k, 0) == pdTRUE) {
return k;
}
return std::nullopt;
}
/// Gets the next keypad release event, waiting if neccesary.
KeypadKey InputsController::wait_keypad_release() {
KeypadKey k;
xQueueReceive(expander_peripheral_singleton.keypad_release_events, &k, portMAX_DELAY);
return k;
}
/// Gets the current state of the keypad.
uint16_t InputsController::keypad_state() {
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
uint16_t value = expander_peripheral_singleton.state.keypad_state;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
return value;
}
+2 -40
View File
@@ -1,33 +1,11 @@
#include "leds.h" #include "leds.h"
#include "led_strip.h" #include "led_strip.h"
#include <esp_log.h> #include <esp_log.h>
#include "state_tracking.h"
#include <cstring>
static const char* TAG = "leds"; static const char* TAG = "leds";
static led_strip_handle_t leds; static led_strip_handle_t leds;
// TODO: rename these to playback_handler
static bool replay_handler(const char* event, char* arg) {
if (strcmp(event, "LED_SET") == 0) {
uint32_t led = atoi(strtok(arg, ","));
uint32_t color = atoi(strtok(NULL, ","));
led_set(led, color);
return true;
}
if (strcmp(event, "LED_FLUSH") == 0) {
leds_flush();
return true;
}
if (strcmp(event, "LED_CLR") == 0) {
leds_clear();
return true;
}
return false;
}
void init_leds() { void init_leds() {
ESP_LOGI(TAG, "Initializing LEDs..."); ESP_LOGI(TAG, "Initializing LEDs...");
@@ -46,20 +24,11 @@ void init_leds() {
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &leds)); ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &leds));
register_replay_fn(replay_handler);
ESP_LOGI(TAG, "LEDs initialized!"); ESP_LOGI(TAG, "LEDs initialized!");
} }
void led_set(uint32_t led, uint8_t r, uint8_t g, uint8_t b) { void led_set(uint32_t led, uint8_t r, uint8_t g, uint8_t b) {
led_strip_set_pixel(leds, led, r, g, b); led_strip_set_pixel(leds, led, r, g, b);
if (is_state_tracking()) {
char buf[32];
uint32_t color = (r << 16) | (g << 8) | b;
sprintf(buf, "%ld,%ld", led, color);
event_occured("LED_SET", buf);
}
} }
void led_set(uint32_t led, uint32_t color) { void led_set(uint32_t led, uint32_t color) {
@@ -68,16 +37,9 @@ void led_set(uint32_t led, uint32_t color) {
void leds_flush() { void leds_flush() {
led_strip_refresh(leds); led_strip_refresh(leds);
if (is_state_tracking()) {
event_occured("LED_FLUSH", NULL);
}
} }
void leds_clear() { void leds_clear()
{
led_strip_clear(leds); led_strip_clear(leds);
if (is_state_tracking()) {
event_occured("LED_CLR", NULL);
}
} }
+1 -2
View File
@@ -4,7 +4,7 @@
#include <stdint.h> #include <stdint.h>
#define LED_COUNT 21 #define LED_COUNT 21
#define NEOPIXEL_PIN GPIO_NUM_0 #define NEOPIXEL_PIN GPIO_NUM_7
// 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution) // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000) #define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000)
@@ -26,7 +26,6 @@ enum LEDColor: uint32_t {
LED_COLOR_WHITE_STRONG = 0xFF'FF'FF, LED_COLOR_WHITE_STRONG = 0xFF'FF'FF,
}; };
// TODO: sepperate the indicator leds from the shape display.
enum IndicatorLED { enum IndicatorLED {
LED_SHAPE1 = 0u, LED_SHAPE1 = 0u,
LED_SHAPE2 = 1u, LED_SHAPE2 = 1u,
-2
View File
@@ -1,2 +0,0 @@
#include "perh.h"
-12
View File
@@ -1,12 +0,0 @@
#ifndef PERH_H
#define PERH_H
#include "driver/gpio.h"
#define PIN_PERH0 GPIO_NUM_6
#define PIN_PERH1 GPIO_NUM_5
#define PIN_PERH2 GPIO_NUM_4
#define PIN_PERH3 GPIO_NUM_2
#define PIN_PERH4 GPIO_NUM_1
#endif /* PERH_H */
-25
View File
@@ -1,6 +1,5 @@
#include "power.h" #include "power.h"
#include "char_lcd.h" #include "char_lcd.h"
#include "starcode.h"
#include <esp_log.h> #include <esp_log.h>
static const char* TAG = "power"; static const char* TAG = "power";
@@ -51,28 +50,4 @@ void init_power_board() {
ESP_LOGI(TAG, "Power board initialized!"); ESP_LOGI(TAG, "Power board initialized!");
} }
uint16_t get_bat_voltage() {
return lipo.voltage();
}
void lcd_print_header_bat() {
if (!lcd_header_enabled()) return;
if (lcd_starcode_displaying_result()) return;
uint8_t soc = lipo.soc();
uint8_t current = lipo.current();
char buf[6];
if (soc < 5 && current <= 0) {
snprintf(buf, sizeof(buf), " LOW");
} else if (soc == 100) {
snprintf(buf, sizeof(buf), " 100");
} else {
if (current > 0) {
snprintf(buf, sizeof(buf), " %2d+", soc);
} else {
snprintf(buf, sizeof(buf), " %2d%%", soc);
}
}
lcd_print(16, 0, buf);
}
+1 -6
View File
@@ -3,18 +3,13 @@
#include "SparkFunBQ27441/SparkFunBQ27441.h" #include "SparkFunBQ27441/SparkFunBQ27441.h"
extern volatile uint32_t battery_charge;
void bat_monitor_task(void* arg); void bat_monitor_task(void* arg);
/// Initializes the battery gas guage for getting battery stats. /// Initializes the battery gas guage for getting battery stats.
void init_power_board(); void init_power_board();
/// @brief Gets the battery voltage. /// @brief Gets the battery voltage
/// @return battery voltage in mV. /// @return battery voltage in mV.
uint16_t get_bat_voltage(); uint16_t get_bat_voltage();
/// @brief Prints the battery section of the header to the char_lcd. (row 0, columns 17-19)
void lcd_print_header_bat();
#endif /* POWER_H */ #endif /* POWER_H */
+6 -6
View File
@@ -12,12 +12,12 @@
extern sdmmc_card_t *card; extern sdmmc_card_t *card;
#define SD_PIN_CLK GPIO_NUM_39 #define SD_PIN_CLK GPIO_NUM_48
#define SD_PIN_CMD GPIO_NUM_40 #define SD_PIN_CMD GPIO_NUM_45
#define SD_PIN_D0 GPIO_NUM_38 #define SD_PIN_D0 GPIO_NUM_47
#define SD_PIN_D1 GPIO_NUM_45 #define SD_PIN_D1 GPIO_NUM_21
#define SD_PIN_D2 GPIO_NUM_42 #define SD_PIN_D2 GPIO_NUM_39
#define SD_PIN_D3 GPIO_NUM_41 #define SD_PIN_D3 GPIO_NUM_38
/// @brief Initializes the SD card /// @brief Initializes the SD card
/// ///
+3 -37
View File
@@ -1,5 +1,4 @@
#include "speaker.h" #include "speaker.h"
#include "state_tracking.h"
static const char *TAG = "speaker"; static const char *TAG = "speaker";
@@ -30,27 +29,6 @@ QueueHandle_t play_clip_queue;
/// The clips that are currently playing /// The clips that are currently playing
std::vector<playing_audio_clip_t> playing_clips; std::vector<playing_audio_clip_t> playing_clips;
static bool replay_handler(const char* event, char* arg) {
if (strcmp(event, "PLAY_WAV") == 0) {
char* file_name = strtok(arg, ":");
char* play_immediately_str = strtok(NULL, ":");
char* repeat_str = strtok(NULL, ":");
char* prescaler_str = strtok(NULL, ":");
bool play_immediately = strcmp(play_immediately_str, "true") == 0;
bool repeat = strcmp(repeat_str, "true") == 0;
uint8_t prescaler = atoi(prescaler_str);
play_clip_wav(file_name, play_immediately, repeat, prescaler, 0);
return true;
}
if (strcmp(event, "STOP_WAV") == 0) {
stop_clip(arg, 0);
return true;
}
return false;
}
static bool push_clip(audio_clip_t clip) { static bool push_clip(audio_clip_t clip) {
ESP_LOGD(TAG, "playing %s", clip.file_name); ESP_LOGD(TAG, "playing %s", clip.file_name);
FILE* fh = fopen(clip.file_name, "rb"); FILE* fh = fopen(clip.file_name, "rb");
@@ -178,7 +156,7 @@ static void speaker_task(void* arg) {
vTaskDelete(NULL); vTaskDelete(NULL);
} }
bool play_clip_wav(const char* file_name, bool play_immediately, bool repeat, uint8_t prescaler, TickType_t ticks_to_wait) { bool play_clip_wav(const char* file_name, bool play_immediatly, bool repeat, uint8_t prescaler, TickType_t ticks_to_wait) {
// clone the passed in string to the heap. // clone the passed in string to the heap.
size_t len = strlen(file_name); size_t len = strlen(file_name);
char* dynamic_file_name = (char*) malloc(len+1); char* dynamic_file_name = (char*) malloc(len+1);
@@ -188,16 +166,10 @@ bool play_clip_wav(const char* file_name, bool play_immediately, bool repeat, ui
.file_name = dynamic_file_name, .file_name = dynamic_file_name,
.prescaler = prescaler, .prescaler = prescaler,
.repeat = repeat, .repeat = repeat,
.play_immediatly = play_immediately, .play_immediatly = play_immediatly,
}; };
if (is_state_tracking()) { if (play_immediatly) {
char buf[64];
sprintf(buf, "%s:%d:%d:%d", file_name, play_immediately, repeat, prescaler);
event_occured("PLAY_WAV", buf);
}
if (play_immediately) {
return xQueueSendToFront(play_clip_queue, &clip, ticks_to_wait) == pdTRUE; return xQueueSendToFront(play_clip_queue, &clip, ticks_to_wait) == pdTRUE;
} }
return xQueueSend(play_clip_queue, &clip, ticks_to_wait) == pdTRUE; return xQueueSend(play_clip_queue, &clip, ticks_to_wait) == pdTRUE;
@@ -209,10 +181,6 @@ bool stop_clip(const char* file_name, TickType_t ticks_to_wait) {
char* dynamic_file_name = (char*) malloc(len+1); char* dynamic_file_name = (char*) malloc(len+1);
strcpy(dynamic_file_name, file_name); strcpy(dynamic_file_name, file_name);
if (is_state_tracking()) {
event_occured("STOP_WAV", file_name);
}
return xQueueSend(stop_clip_queue, &dynamic_file_name, ticks_to_wait) == pdTRUE; return xQueueSend(stop_clip_queue, &dynamic_file_name, ticks_to_wait) == pdTRUE;
} }
@@ -254,8 +222,6 @@ void init_speaker(void) {
xTaskCreate(speaker_task, "play_audio", 4096, NULL, 5, NULL); xTaskCreate(speaker_task, "play_audio", 4096, NULL, 5, NULL);
play_clip_wav(MOUNT_POINT "/startup.wav", true, false, 4, 0); play_clip_wav(MOUNT_POINT "/startup.wav", true, false, 4, 0);
register_replay_fn(replay_handler);
ESP_LOGI(TAG, "Speaker initialized!"); ESP_LOGI(TAG, "Speaker initialized!");
} }
+3 -3
View File
@@ -15,8 +15,8 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "sd.h" #include "sd.h"
#define SPEAKER_PIN_BCLK GPIO_NUM_11 #define SPEAKER_PIN_BCLK GPIO_NUM_46
#define SPEAKER_PIN_WS GPIO_NUM_12 #define SPEAKER_PIN_WS GPIO_NUM_9
#define SPEAKER_PIN_DOUT GPIO_NUM_3 #define SPEAKER_PIN_DOUT GPIO_NUM_3
#define SAMPLE_RATE 44100 #define SAMPLE_RATE 44100
// The maximum number of clips that can be queued at one time. // The maximum number of clips that can be queued at one time.
@@ -52,7 +52,7 @@ void init_speaker();
/// loud. Useful for loud audio files. /// loud. Useful for loud audio files.
/// @param ticks_to_wait The number of ticks to wait if the queue is full. /// @param ticks_to_wait The number of ticks to wait if the queue is full.
/// @return true if the clip was added to the queue. /// @return true if the clip was added to the queue.
bool play_clip_wav(const char* file_name, bool play_immediately, bool repeat, uint8_t prescaler, TickType_t ticks_to_wait); bool play_clip_wav(const char* file_name, bool play_immediatly, bool repeat, uint8_t prescaler, TickType_t ticks_to_wait);
/// @brief Stops an audio clip from playing. /// @brief Stops an audio clip from playing.
/// @param file_name The file name of the audio clip that was played. /// @param file_name The file name of the audio clip that was played.
+1 -82
View File
@@ -1,62 +1,15 @@
#include "sseg.h" #include "sseg.h"
#include <esp_log.h> #include "esp_log.h"
#include "state_tracking.h"
#include <cstring>
TM1640* sseg = nullptr; TM1640* sseg = nullptr;
static const char *TAG = "sseg"; static const char *TAG = "sseg";
static bool replay_handler(const char* event, char* arg) {
if (strcmp(event, "SSEG_G_RAW") == 0) {
uint8_t segments[4];
segments[0] = atoi(strtok(arg, ","));
for (int i = 1; i < 4; i++) {
segments[i] = atoi(strtok(NULL, ","));
}
set_game_sseg_raw(segments);
return true;
}
if (strcmp(event, "SSEG_G_CLR") == 0) {
clear_game_sseg();
return true;
}
if (strcmp(event, "SSEG_M_RAW") == 0) {
uint8_t segments[4];
segments[0] = atoi(strtok(arg, ","));
for (int i = 1; i < 4; i++) {
segments[i] = atoi(strtok(NULL, ","));
}
set_module_sseg_raw(segments);
return true;
}
if (strcmp(event, "SSEG_M_CLR") == 0) {
clear_module_sseg();
return true;
}
if (strcmp(event, "SSEG_G") == 0) {
uint32_t value = atoi(strtok(arg, ","));
uint8_t dot_pos = atoi(strtok(NULL, ","));
set_game_sseg_num(value, dot_pos);
return true;
}
if (strcmp(event, "SSEG_M") == 0) {
uint32_t value = atoi(strtok(arg, ","));
uint8_t dot_pos = atoi(strtok(NULL, ","));
set_module_sseg_num(value, dot_pos);
return true;
}
return false;
}
void init_sseg() { void init_sseg() {
ESP_LOGI(TAG, "Initializing sseg..."); ESP_LOGI(TAG, "Initializing sseg...");
sseg = new TM1640(SSEG_PIN_DATA, SSEG_PIN_CLK, 8); sseg = new TM1640(SSEG_PIN_DATA, SSEG_PIN_CLK, 8);
register_replay_fn(replay_handler);
ESP_LOGI(TAG, "Sseg initialized!"); ESP_LOGI(TAG, "Sseg initialized!");
} }
@@ -65,22 +18,12 @@ void set_game_sseg_raw(const uint8_t* segments) {
sseg->setSegments(segments[1], 1); sseg->setSegments(segments[1], 1);
sseg->setSegments(segments[2], 2); sseg->setSegments(segments[2], 2);
sseg->setSegments(segments[3], 3); sseg->setSegments(segments[3], 3);
if (is_state_tracking()) {
char buf[32];
sprintf(buf, "%d,%d,%d,%d", segments[0], segments[1], segments[2], segments[3]);
event_occured("SSEG_G_RAW", buf);
}
} }
void clear_game_sseg() { void clear_game_sseg() {
sseg->setSegments(0, 0); sseg->setSegments(0, 0);
sseg->setSegments(0, 1); sseg->setSegments(0, 1);
sseg->setSegments(0, 2); sseg->setSegments(0, 2);
sseg->setSegments(0, 3); sseg->setSegments(0, 3);
if (is_state_tracking()) {
event_occured("SSEG_G_CLR", NULL);
}
} }
void set_module_sseg_raw(const uint8_t* segments) { void set_module_sseg_raw(const uint8_t* segments) {
@@ -88,12 +31,6 @@ void set_module_sseg_raw(const uint8_t* segments) {
sseg->setSegments(segments[1], 5); sseg->setSegments(segments[1], 5);
sseg->setSegments(segments[2], 6); sseg->setSegments(segments[2], 6);
sseg->setSegments(segments[3], 7); sseg->setSegments(segments[3], 7);
if (is_state_tracking()) {
char buf[32];
sprintf(buf, "%d,%d,%d,%d", segments[0], segments[1], segments[2], segments[3]);
event_occured("SSEG_M_RAW", buf);
}
} }
void clear_module_sseg() { void clear_module_sseg() {
@@ -101,38 +38,20 @@ void clear_module_sseg() {
sseg->setSegments(0, 5); sseg->setSegments(0, 5);
sseg->setSegments(0, 6); sseg->setSegments(0, 6);
sseg->setSegments(0, 7); sseg->setSegments(0, 7);
if (is_state_tracking()) {
event_occured("SSEG_M_CLR", NULL);
}
} }
void set_game_sseg_num(uint32_t value, uint8_t dot_pos) { void set_game_sseg_num(uint32_t value, uint8_t dot_pos) {
uint32_t initial_value = value;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
auto idx = value % 10; auto idx = value % 10;
sseg->sendChar(3-i, TM16XX_NUMBER_FONT[idx], i == dot_pos); sseg->sendChar(3-i, TM16XX_NUMBER_FONT[idx], i == dot_pos);
value = value / 10; value = value / 10;
} }
if (is_state_tracking()) {
char buf[16];
sprintf(buf, "%ld,%d", initial_value, dot_pos);
event_occured("SSEG_G", buf);
}
} }
void set_module_sseg_num(uint32_t value, uint8_t dot_pos) { void set_module_sseg_num(uint32_t value, uint8_t dot_pos) {
uint32_t initial_value = value;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
auto idx = value % 10; auto idx = value % 10;
sseg->sendChar(7-i, TM16XX_NUMBER_FONT[idx], i == dot_pos); sseg->sendChar(7-i, TM16XX_NUMBER_FONT[idx], i == dot_pos);
value = value / 10; value = value / 10;
} }
if (is_state_tracking()) {
char buf[16];
sprintf(buf, "%ld,%d", initial_value, dot_pos);
event_occured("SSEG_M", buf);
}
} }
+2 -2
View File
@@ -4,8 +4,8 @@
#include "TM1640/TM1640.h" #include "TM1640/TM1640.h"
#include <esp_log.h> #include <esp_log.h>
#define SSEG_PIN_DATA GPIO_NUM_46 #define SSEG_PIN_DATA GPIO_NUM_10
#define SSEG_PIN_CLK GPIO_NUM_48 #define SSEG_PIN_CLK GPIO_NUM_11
extern TM1640* sseg; extern TM1640* sseg;
-256
View File
@@ -1,256 +0,0 @@
#include "starcode.h"
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdint.h>
#include <esp_log.h>
#include "drivers/bottom_half.h"
#include "char_lcd.h"
#include "esp_timer.h"
static const char* TAG = "star_code";
volatile bool handling_new_starcodes = false;
static volatile bool system_initialized = false;
// TODO: use the semaphore, convert to RWLock?
static volatile SemaphoreHandle_t star_codes_sem;
static std::vector<StarCodeEntry> star_codes;
static const char EMPTY_STAR_CODE_HEADER[] = " ";
esp_timer_handle_t starcode_delay_timer;
/// @brief `true` if we are delaying for a starcode
static volatile bool delaying_for_starcode;
static volatile StarCodeEntry* current_starcode = nullptr;
/// @brief `true` when we are handling user input for a starcode
static volatile bool doing_starcode = false;
static uint16_t starcode_waiting_on_release;
static char current[STARCODE_MAX_LEN + 1];
static size_t current_idx;
static void starcode_trigger_cb(void* arg) {
(void) arg;
delaying_for_starcode = false;
if (current_starcode != nullptr) {
if (current_starcode->triggered_sem != nullptr)
xSemaphoreGive(current_starcode->triggered_sem);
if (current_starcode->callback != nullptr)
(current_starcode->callback)();
current_starcode = nullptr;
}
// TODO: rename star code everywhere to starcode
lcd_print_header();
}
void star_code_handle_keypad(uint16_t* just_pressed, uint16_t* just_released) {
if ((!delaying_for_starcode) && handling_new_starcodes && (*just_pressed & (1 << KeypadKey::star))) {
current_idx = 0;
current[current_idx] = '\0';
doing_starcode = true;
}
if (doing_starcode) {
// If we get a press while handling a starcode, we also want to capture the release of that key.
starcode_waiting_on_release |= *just_pressed;
KeypadKey key;
while (take_key(&key, just_pressed)) {
if (key == KeypadKey::star) {
current_idx = 0;
current[current_idx] = '\0';
} else if (key == KeypadKey::pound) {
doing_starcode = false;
if (current_idx != 0) {
trigger_star_code(current);
}
} else {
// shift the digits left if neccesary
if (current_idx >= STARCODE_MAX_LEN) {
for (int i = 1; i < current_idx; i++) {
current[i-1] = current[i];
}
current_idx--;
}
// append the character
current[current_idx++] = char_of_keypad_key(key);
current[current_idx] = '\0';
}
lcd_print_header_star_code();
}
}
// capture any releases from starcodes
uint16_t new_just_released = (*just_released) & (~starcode_waiting_on_release);
starcode_waiting_on_release = starcode_waiting_on_release & (~*just_released);
*just_released = new_just_released;
}
void init_star_code_system() {
star_codes_sem = xSemaphoreCreateBinary();
xSemaphoreGive(star_codes_sem);
const esp_timer_create_args_t timer_args = {
.callback = &starcode_trigger_cb,
.arg = nullptr,
.dispatch_method = ESP_TIMER_TASK,
.name = "starcode_trigger",
.skip_unhandled_events = false,
};
ESP_ERROR_CHECK(esp_timer_create(&timer_args, &starcode_delay_timer));
handling_new_starcodes = true;
system_initialized = true;
}
/// Checks if a triggered code matches an expected code.
/// @return true iff the codes match, where '*'s in the expected code can match any character in the triggered code
static bool check_code_match(const char* triggered, const char* expected) {
size_t triggered_len = strlen(triggered);
size_t match_len = strlen(triggered);
if (triggered_len != match_len)
return false;
for (int i = 0; i < triggered_len; i++) {
if (!(expected[i] == '*' || expected[i] == triggered[i])) {
return false;
}
}
return true;
}
bool add_star_code(StarCodeEntry code) {
ESP_LOGI(TAG, "Adding starcode: %s", code.code);
if (code.code == nullptr || strlen(code.code) > STARCODE_MAX_LEN) {
ESP_LOGW(TAG, "invalid code");
return false;
}
if (code.display_text != nullptr && strlen(code.display_text) > STARCODE_DISPLAY_TEXT_MAX_LEN) {
ESP_LOGW(TAG, "invalid display_text");
return false;
}
// check for a existing entry
auto it = std::find_if(star_codes.begin(), star_codes.end(), [&](const StarCodeEntry& other) {
return check_code_match(code.code, other.code);
});
if (it != star_codes.end()) {
// existing star code found!
ESP_LOGW(TAG, "Duplicate starcode %s", code.code);
return false;
}
star_codes.push_back(code);
return true;
}
bool add_star_codes(const StarCodeEntry* codes, size_t len) {
bool success = true;
for (int i = 0; i < len; i++) {
if (!add_star_code(codes[i])) {
success = false;
}
}
return success;
}
bool rm_star_code(const char* code) {
ESP_LOGI(TAG, "Removing starcode: %s", code);
auto it = std::find_if(star_codes.begin(), star_codes.end(), [&](const StarCodeEntry& star_code) {
return strcmp(code, star_code.code) == 0;
});
if (it == star_codes.end()) {
ESP_LOGW(TAG, "Failed to remove star code %s", code);
return false;
}
star_codes.erase(it);
return true;
}
bool rm_star_codes(const StarCodeEntry* codes, size_t len) {
bool success = true;
for (int i = 0; i < len; i++) {
if (!rm_star_code(codes[i].code)) {
success = false;
}
}
return success;
}
bool rm_star_codes_str(const char** codes, size_t len) {
bool success = true;
for (int i = 0; i < len; i++) {
if (!rm_star_code(codes[i])) {
success = false;
}
}
return success;
}
void clear_star_codes() {
star_codes.clear();
}
bool trigger_star_code(const char* code) {
auto it = std::find_if(star_codes.begin(), star_codes.end(), [&](const StarCodeEntry& other) {
return check_code_match(code, other.code);
});
uint64_t delay_us = 2'000'000;
delaying_for_starcode = true;
if (it != star_codes.end()) {
current_starcode = &*it;
delay_us = current_starcode->delay_us;
}
ESP_ERROR_CHECK(esp_timer_start_once(starcode_delay_timer, delay_us));
return current_starcode != nullptr;
}
void pause_star_code_system() {
doing_starcode = false;
handling_new_starcodes = false;
}
void resume_star_code_system() {
handling_new_starcodes = system_initialized;
}
void lcd_print_header_star_code() {
if (!lcd_header_enabled()) return;
// TODO: consider upping the display text size to be able to overwrite the game_state area.
if (delaying_for_starcode) {
if (current_starcode == nullptr) {
lcd_print(0, 0, "Invalid starcode ");
} else if (current_starcode->display_text != nullptr) {
char buf[21];
snprintf(buf, sizeof(buf), "%-20s", current_starcode->display_text);
lcd_print(0, 0, buf);
} else {
lcd_print(0, 0, EMPTY_STAR_CODE_HEADER);
}
} else if (doing_starcode) {
char buf[STARCODE_MAX_LEN + 2];
snprintf(buf, sizeof(buf), "*%-9s", current);
lcd_print(0, 0, buf);
} else {
lcd_print(0, 0, EMPTY_STAR_CODE_HEADER);
}
}
bool lcd_starcode_displaying_result() {
return delaying_for_starcode;
}
-90
View File
@@ -1,90 +0,0 @@
#ifndef STAR_CODE_H
#define STAR_CODE_H
#include <stddef.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
/// The max length of a starcode (not counting the star)
#define STARCODE_MAX_LEN 9
#define STARCODE_DISPLAY_TEXT_MAX_LEN 20
/// @brief A handler for a specific star code
struct StarCodeEntry {
/// @brief The star code without the star
///
/// This must be <= 9 characters.
///
/// You may include a * in the code to match on any character
const char* code;
/// @brief The text to display when the star code is entered (or null).
///
/// This must be <= 20 characters.
const char* display_text;
/// @brief The number of microseconds to delay when the star code is entered before calling the handler.
uint64_t delay_us;
/// @brief The function to call when the star code is entered.
/// Can be null.
void (*callback)(void);
/// @brief The binary semaphore that will be given when this star code is triggered.
/// Can be null.
SemaphoreHandle_t triggered_sem;
};
/// @brief Initializes the star code system.
void init_star_code_system();
/// @brief Handles any keypad presses and releases before they bubble up to the rest of the BLK_BOX.
void star_code_handle_keypad(uint16_t* just_pressed, uint16_t* just_released);
/// @brief Adds a star code to be handled.
/// @param code the star code to add
/// @return true iff the star code was added
bool add_star_code(StarCodeEntry code);
/// @brief Adds a list of star codes to be handled.
/// @param codes the list of star codes to add
/// @param len the length of the list
/// @return true iff all the star codes were added
bool add_star_codes(const StarCodeEntry* codes, size_t len);
/// @brief removes a star code to stop handling it.
/// @param code the star code to remove
/// @return true iff the star code was removed
bool rm_star_code(const char* code);
/// @brief removes all given star codes to stop handling them.
/// @param codes the list of star codes to remove
/// @param len the length of the list
/// @return true iff all star codes were removed
bool rm_star_codes(const StarCodeEntry* codes, size_t len);
/// @brief removes all given star codes to stop handling them.
/// @param codes the list of star codes to remove
/// @param len the length of the list
/// @return true iff all star codes were removed
bool rm_star_codes_str(const char** codes, size_t len);
/// @brief clears all star codes.
void clear_star_codes();
/// @brief Triggers the given star code.
/// @param code the star code to trigger (without the *)
/// @return true iff a star code was triggered
bool trigger_star_code(const char* code);
/// @brief Starts/stops the star code system from handling new star codes.
/// If one is being handled currently, it is canceled.
void set_star_code_sys_enabled(bool enable);
/// @return `true` iff the star code system is handling star codes.
bool star_code_sys_enabled();
/// @brief Prints the star code section of the header to the char_lcd. (row 0, columns 0-9)
void lcd_print_header_star_code();
/// @return `true` iff the starcode system is using the full header.
bool lcd_starcode_displaying_result();
#endif /* STAR_CODE_H */
-225
View File
@@ -1,225 +0,0 @@
#include "state_tracking.h"
#include <unistd.h>
#include <vector>
#include "wlvgl.h"
static const char* PLAYBACK_TAG = "playback";
enum state_t {
STATE_IDLE = 0,
STATE_RECORDING = 1,
STATE_PLAYBACK = 2,
};
static std::vector<bool(*)(const char*, char*)> replay_fns;
static bool should_close_recording_stream;
static FILE* recording_stream;
static uint32_t recording_start_time;
TaskHandle_t flush_file_task_handle;
static bool should_close_playback_stream;
static FILE* playback_stream;
static uint32_t playback_start_time;
TaskHandle_t playback_task_handle;
static volatile state_t state = STATE_IDLE;
/// @brief Periodically flushes and syncs (if neccesary) the output stream.
/// @param arg unused.
static void flush_file_task(void* arg) {
while (state == STATE_RECORDING && recording_stream != nullptr) {
fflush(recording_stream);
int fd = fileno(recording_stream);
if (fd != -1) {
fsync(fd);
}
vTaskDelay(pdMS_TO_TICKS(5000));
}
flush_file_task_handle = NULL;
vTaskDelete(NULL);
}
static void playback_task(void* arg) {
const size_t size = 16*1024;
char* buf = (char*) malloc(size*sizeof(char));
if (buf == nullptr) {
ESP_LOGE(PLAYBACK_TAG, "buf alloc failure");
vTaskDelete(NULL);
}
while (state == STATE_PLAYBACK && playback_stream != nullptr) {
char* ret = fgets(buf, size, playback_stream);
if (ret == nullptr) {
break;
}
if (buf[0] == '\0') {
ESP_LOGI(PLAYBACK_TAG, "playback done");
break;
}
// get rid of the '\n' and possibly '\r' in the string
for (int i = 0; i < size; i++) {
if (buf[i] == '\0') break;
if (buf[i] == '\r' || buf[i] == '\n') {
buf[i] = '\0';
break;
}
}
ESP_LOGI(PLAYBACK_TAG, "handling: %s", buf);
// look for a comma, indicating the end of the "ticks" part
// TODO: replace with strtok
size_t comma_pos = 0;
for (int i = 0; i < 11; i++) {
if (buf[i] == ',') {
comma_pos = i;
break;
}
}
if (comma_pos == 0) {
ESP_LOGE(PLAYBACK_TAG, "Failed to find comma in playback line");
continue;
}
buf[comma_pos] = '\0';
uint32_t tick = atoi(buf);
// now look for the colon to indicate the end of the event name
size_t colon_pos = 0;
int i = comma_pos + 1; // start looking right after the comma
while (i < size) {
if (buf[i] == ':') {
colon_pos = i;
break;
}
i++;
}
if (colon_pos == 0) {
ESP_LOGE(PLAYBACK_TAG, "Failed to find colon in playback line");
continue;
}
buf[colon_pos] = '\0';
char* event_name = buf + (comma_pos + 1);
char* arg = buf + (colon_pos + 1);
int32_t ticks_to_wait = ((int32_t) tick) - (int32_t)(xTaskGetTickCount() - playback_start_time);
if (ticks_to_wait < 0) {
ESP_LOGW(PLAYBACK_TAG, "Playback is behind by %ld ticks!", ticks_to_wait);
}
if (ticks_to_wait > 0) {
vTaskDelay(ticks_to_wait);
}
bool matched = false;
for (const auto& fn : replay_fns) {
matched = (fn)(event_name, arg);
if (matched) break;
}
if (!matched) {
ESP_LOGW(PLAYBACK_TAG, "Failed to match event: %s!", event_name);
}
}
free(buf);
playback_task_handle = NULL;
stop_playback();
vTaskDelete(NULL);
}
void register_replay_fn(bool (*replay_fn)(const char*, char*)) {
replay_fns.push_back(replay_fn);
}
void event_occured(const char* name, const char* arg) {
if (state != STATE_RECORDING) return;
if (name == nullptr) return;
if (recording_stream == nullptr) {
ESP_LOGE("state_tracking", "We are in state recording, but recording stream is null");
return;
}
arg = (arg == nullptr) ? "" : arg;
uint32_t ticks = xTaskGetTickCount() - recording_start_time;
fprintf(recording_stream, "%ld,%s:%s\n", ticks, name, (arg == nullptr) ? "" : arg);
}
bool set_recording_source(FILE* stream, bool should_close) {
if (state == STATE_RECORDING) return false;
recording_stream = stream;
should_close_recording_stream = should_close;
return true;
}
bool set_playback_source(FILE* stream, bool should_close) {
if (state == STATE_PLAYBACK) return false;
playback_stream = stream;
should_close_playback_stream = should_close;
return true;
}
bool start_recording() {
if (state != STATE_IDLE) return false;
if (recording_stream == nullptr) return false;
state = STATE_RECORDING;
recording_start_time = xTaskGetTickCount();
xTaskCreate(flush_file_task, "flush_recording", 2048, NULL, 2, &flush_file_task_handle);
reset_wlv_tables(); // TODO: generify this
return true;
}
bool stop_recording() {
if (state != STATE_RECORDING) return false;
state = STATE_IDLE;
fflush(recording_stream);
if (should_close_recording_stream) {
fclose(recording_stream);
recording_stream = nullptr;
}
if (flush_file_task_handle != nullptr) {
vTaskDelete(flush_file_task_handle);
flush_file_task_handle = NULL;
}
return true;
}
bool start_playback() {
if (state != STATE_IDLE) return false;
if (playback_stream == nullptr) return false;
state = STATE_PLAYBACK;
playback_start_time = xTaskGetTickCount();
xTaskCreate(playback_task, "playback", 4096, NULL, 2, &playback_task_handle);
reset_wlv_tables(); // TODO: generify this
return true;
}
bool stop_playback() {
if (state != STATE_PLAYBACK) return false;
state = STATE_IDLE;
if (should_close_playback_stream) {
fclose(playback_stream);
playback_stream = nullptr;
}
if (playback_task_handle != nullptr) {
// TODO: NO!! This leaks the malloc. Instead, use a queue to request a graceful stop
vTaskDelete(playback_task_handle);
playback_task_handle = NULL;
}
return true;
}
bool is_state_tracking() {
return state == STATE_RECORDING;
}
-53
View File
@@ -1,53 +0,0 @@
#ifndef STATE_TRACKING_H
#define STATE_TRACKING_H
#include <stdint.h>
#include "esp_vfs_fat.h"
/// @brief Registers function to be called on replay.
/// @param replay_callback A function to call to playback the event.
void register_replay_fn(bool (*replay_fn)(const char*, char*));
// TODO: add one for generically responding to all events.
/// @brief Call this to indicate that the bomb state has transitioned.
/// @param name The name of the event that has occured.
/// @param arg The serialized data associated with the event.
/// This must not contain newline characters such as '\n' or '\r'
void event_occured(const char* name, const char* arg);
/// @brief Sets the recording source.
/// @param stream The stream to record to.
/// @param should_close whether or not the stream should be closed when finished.
/// @return true if the source was updated.
bool set_recording_source(FILE* stream, bool should_close);
/// @brief Sets the playback source.
/// @param stream The stream to playback from.
/// @param should_close whether or not the stream should be closed when finished.
/// @return true if the source was updated.
bool set_playback_source(FILE* stream, bool should_close);
/// @brief Starts recording to the stream specified by `set_recording_source()`.
/// @return true if starting recording is successful.
bool start_recording();
/// @brief Stops recording the state.
/// @return true if stopping the recording is successful.
bool stop_recording();
/// @brief Starts playing back the recording specified by `set_playback_source()`.
/// @return true if starting playback is successful.
bool start_playback();
/// @brief Stops playing back the recording.
/// @return true if stopping the playback is successful.
bool stop_playback();
/// @brief Gets weather or not we are tracking the state
/// This can be helpful to conditionally do extra computation only
/// when we are tracking the state.
/// @return
bool is_state_tracking();
#endif /* STATE_TRACKING_H */
+12 -56
View File
@@ -1,5 +1,4 @@
#include "tft.h" #include "tft.h"
#include "state_tracking.h"
static const char* TAG = "tft"; static const char* TAG = "tft";
@@ -17,28 +16,16 @@ static lv_style_t style_screen;
SemaphoreHandle_t xGuiSemaphore; SemaphoreHandle_t xGuiSemaphore;
static bool replay_handler(const char* event, char* arg) {
return false;
}
static bool notify_lvgl_flush_ready( static bool notify_lvgl_flush_ready(
esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_handle_t panel_io,
esp_lcd_panel_io_event_data_t *edata, esp_lcd_panel_io_event_data_t *edata,
void *user_ctx void *user_ctx
) { ) {
lv_disp_drv_t* disp_driver = (lv_disp_drv_t *)user_ctx; lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver); lv_disp_flush_ready(disp_driver);
return false; return false;
} }
const char base64_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/// Base 64 encodes a u16... sort of. This doesn't do any of the fancy padding stuff.
static void encode_base64(char* buf, size_t start_idx, uint16_t value) {
buf[start_idx+0] = base64_chars[(value >> 10) & 0x3F];
buf[start_idx+1] = base64_chars[(value >> 4) & 0x3F];
buf[start_idx+2] = base64_chars[(value << 2) & 0x3F];
}
static void lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) { static void lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) {
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t) drv->user_data; esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t) drv->user_data;
@@ -46,46 +33,7 @@ static void lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t
int offsetx2 = area->x2; int offsetx2 = area->x2;
int offsety1 = area->y1; int offsety1 = area->y1;
int offsety2 = area->y2; int offsety2 = area->y2;
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map); esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
// TODO: change this to be a kconfig value
#if false
if (is_state_tracking()) {
size_t size = (offsetx2 + 1 - offsetx1) * (offsety2 + 1 - offsety1) + 1;
// if (size > 1024) {
// ESP_LOGW("tft_track_state", "Write too big (%d)! truncating to 1024!", size);
// }
// size = MIN(1024, size);
// 24 bytes for the offsets
// 3 bytes per encoded color
// 1 byte for null terminator
size_t alloc_size = 24 + size * 3 + 1;
char* buf = (char*)malloc(alloc_size);
if (buf != nullptr) {
size_t initial_offset = sprintf(buf, "%d,%d,%d,%d:", offsetx1, offsety1, offsetx2 + 1, offsety2 + 1);
for (size_t i = 0; i < size; i++) {
size_t index = initial_offset + i * 3;
// we assume that the size of the color data is 16b
static_assert(sizeof(lv_color_t) == sizeof(uint16_t), "lv_color_t must be 16b wide");
encode_base64(buf, index, color_map[i].full);
}
buf[initial_offset + (size-1) * 3 + 1] = '\0';
event_occured("TFT_W", buf);
free(buf);
} else {
ESP_LOGE("tft_track_state", "buffer alloc failed!");
}
}
#endif
} }
static void IRAM_ATTR lv_tick_task(void *param) { static void IRAM_ATTR lv_tick_task(void *param) {
@@ -202,10 +150,10 @@ static void guiTask(void *pvParameter) {
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &periodic_timer)); ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &periodic_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LVGL_UPDATE_PERIOD_MS * 1000)); ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LVGL_UPDATE_PERIOD_MS * 1000));
screen = lv_scr_act(); screen = lv_disp_get_scr_act(NULL);
lv_style_init(&style_screen); lv_style_init(&style_screen);
lv_style_set_bg_color(&style_screen, lv_color_black()); lv_style_set_bg_color(&style_screen, lv_color_black());
lv_obj_add_style(screen, &style_screen, LV_STATE_DEFAULT); lv_obj_add_style(lv_scr_act(), &style_screen, LV_STATE_DEFAULT);
while (1) { while (1) {
/* Delay 1 tick (assumes FreeRTOS tick is 10ms */ /* Delay 1 tick (assumes FreeRTOS tick is 10ms */
@@ -221,6 +169,14 @@ static void guiTask(void *pvParameter) {
vTaskDelete(NULL); vTaskDelete(NULL);
} }
static void tick_timer_task(void* arg) {
while (1)
{
lv_task_handler();
vTaskDelay(pdMS_TO_TICKS(10));
}
}
void init_tft() { void init_tft() {
ESP_LOGI(TAG, "Initializing TFT..."); ESP_LOGI(TAG, "Initializing TFT...");
@@ -228,7 +184,7 @@ void init_tft() {
initialize_display(); initialize_display();
xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, NULL, 5, NULL, 1); xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, NULL, 5, NULL, 1);
register_replay_fn(replay_handler); // xTaskCreatePinnedToCore(tick_timer_task, "tick_lvgl", 4096, NULL, 5, NULL, 1);
ESP_LOGI(TAG, "TFT initialized!"); ESP_LOGI(TAG, "TFT initialized!");
} }
+4 -4
View File
@@ -44,11 +44,11 @@
#define SPI_MAX_TRANSFER_SIZE 32768 #define SPI_MAX_TRANSFER_SIZE 32768
#define TFT_PIN_MOSI GPIO_NUM_17 #define TFT_PIN_MOSI GPIO_NUM_17
#define TFT_PIN_MISO GPIO_NUM_16 #define TFT_PIN_MISO GPIO_NUM_18
#define TFT_PIN_CLK GPIO_NUM_18 #define TFT_PIN_CLK GPIO_NUM_16
#define TFT_PIN_CS GPIO_NUM_NC #define TFT_PIN_CS GPIO_NUM_NC
#define TFT_PIN_DC GPIO_NUM_8 #define TFT_PIN_DC GPIO_NUM_15
#define TFT_PIN_RESET GPIO_NUM_9 #define TFT_PIN_RESET GPIO_NUM_8
#define TFT_INVERT_COLOR false #define TFT_INVERT_COLOR false
+5 -5
View File
@@ -26,17 +26,17 @@ static void receive_button(void);
void init_wires(void) { void init_wires(void) {
i2c_config_t wires_conf = { i2c_config_t wires_conf = {
.mode = I2C_MODE_MASTER, .mode = I2C_MODE_MASTER,
.sda_io_num = PIN_WIRES_SDA, .sda_io_num = GPIO_NUM_41,
.scl_io_num = PIN_WIRES_SCL, .scl_io_num = GPIO_NUM_42,
.sda_pullup_en = GPIO_PULLUP_ENABLE, .sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE, .scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = { .master = {
.clk_speed = 100000, .clk_speed = 100000,
}, }
}; };
gpio_reset_pin(PIN_WIRES_SDA); gpio_reset_pin(GPIO_NUM_41);
gpio_reset_pin(PIN_WIRES_SCL); 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));
+1 -4
View File
@@ -8,11 +8,8 @@
#include "drivers/char_lcd.h" #include "drivers/char_lcd.h"
#include "drivers/game_timer.h" #include "drivers/game_timer.h"
#include "main.h" #include "main.h"
#include "perh.h"
#define WIRES_PIN_DELTA PIN_PERH3 #define WIRES_PIN_DELTA GPIO_NUM_2
#define PIN_WIRES_SDA PIN_PERH1
#define PIN_WIRES_SCL PIN_PERH2
#define WIRES_I2C_NUM I2C_NUM_1 #define WIRES_I2C_NUM I2C_NUM_1
#define WIRES_I2C_ADDR 125 #define WIRES_I2C_ADDR 125
-152
View File
@@ -1,152 +0,0 @@
#include "wlvgl.h"
#include <vector>
/// A table that maps an incrementing integer to a style reference
static std::vector<lv_style_t*> style_table;
/// A table that maps an incrementing integer to a style reference
static std::vector<lv_obj_t*> obj_table;
static int index_of_style(lv_style_t* style) {
for (size_t i = 0; i < style_table.size(); i++) {
if (style_table[i] == style) {
return i;
}
}
return -1;
}
static int index_of_obj(lv_obj_t* obj) {
for (size_t i = 0; i < obj_table.size(); i++) {
if (obj_table[i] == obj) {
return i;
}
}
return -1;
}
void reset_wlv_tables() {
style_table.clear();
obj_table.clear();
}
lv_obj_t * wlv_obj_create(lv_obj_t* parent) {
// initialize the obj
lv_obj_t* value = lv_obj_create(parent);
if (is_state_tracking()) {
// add the style to the table
obj_table.push_back(value);
size_t obj_index = obj_table.size();
char buf[8];
sprintf(buf, "%d", obj_index);
event_occured("lv_obj_create", buf);
}
return value;
}
void wlv_style_init(lv_style_t* style) {
// initialize the style
lv_style_init(style);
if (is_state_tracking()) {
// add the style to the table
style_table.push_back(style);
size_t style_index = style_table.size();
char buf[8];
sprintf(buf, "%d", style_index);
event_occured("lv_style_init", buf);
}
}
void wlv_obj_set_style_bg_color(lv_obj_t* obj, lv_color_t value, lv_style_selector_t selector) {
lv_obj_set_style_bg_color(obj, value, selector);
if (is_state_tracking()) {
int obj_index = index_of_obj(obj);
char buf[64];
sprintf(buf, "%d,%d,%ld", obj_index, value.full, selector);
event_occured("lv_obj_set_style_bg_color", buf);
}
}
void wlv_style_set_text_color() {
}
void wlv_style_set_text_align() {
}
void wlv_obj_align() {
}
void wlv_obj_set_size() {
}
void wlv_obj_add_style() {
}
void wlv_obj_set_style_text_align() {
}
void wlv_label_set_text() {
}
void wlv_scr_load() {
}
void wlv_scr_act() {
}
void wlv_style_set_bg_color() {
}
void wlv_style_set_bg_opa() {
}
void wlv_obj_set_width() {
}
void wlv_style_set_text_font() {
}
void wlv_label_create() {
}
void wlv_obj_del() {
}
void wlv_obj_center() {
}
void wlv_obj_remove_style() {
}
void wlv_obj_add_flag() {
}
void wlv_obj_clear_flag() {
}
-32
View File
@@ -1,32 +0,0 @@
#ifndef WLVGL_H
#define WLVGL_H
#include "lvgl.h"
#include "state_tracking.h"
void reset_wlv_tables();
lv_obj_t* wlv_obj_create(lv_obj_t* parent);
void wlv_style_init(lv_style_t* style);
void wlv_obj_set_style_bg_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector);
void wlv_style_set_text_color();
void wlv_style_set_text_align();
void wlv_obj_align();
void wlv_obj_set_size();
void wlv_obj_add_style();
void wlv_obj_set_style_text_align();
void wlv_label_set_text();
void wlv_scr_load();
void wlv_scr_act();
void wlv_style_set_bg_color();
void wlv_style_set_bg_opa();
void wlv_obj_set_width();
void wlv_style_set_text_font();
void wlv_label_create();
void wlv_obj_del();
void wlv_obj_center();
void wlv_obj_remove_style();
void wlv_obj_add_flag();
void wlv_obj_clear_flag();
#endif /* WLVGL_H */
+69 -2
View File
@@ -17,10 +17,76 @@ void clean_bomb(void) {
set_module_sseg_raw(clear); set_module_sseg_raw(clear);
// clear char lcd // clear char lcd
lcd_set_cursor_vis(false);
lcd_clear(); lcd_clear();
lcd_set_cursor_vis(false);
lcd_cursor_home();
}
// TODO: add stuff for starcode system static const int STRING_MAX_LEN = 8;
void do_star_codes(StarCodeHandler* star_codes, int star_codes_len) {
KeypadKey key;
int current_idx = 0;
char current[STRING_MAX_LEN+1] = {0};
while (1) {
while (get_keypad_pressed(&key)) {
if (key == KeypadKey::star) {
current[0] = '*';
for (int i = 1; i < STRING_MAX_LEN; i++) {
current[i] = 0;
}
current_idx = 1;
} else if (key == KeypadKey::pound) {
// submit
if (current[0] == '\0') {
continue;
}
bool hit = false;
for (int i = 0; i < star_codes_len; i++) {
StarCodeHandler sch = star_codes[i];
if (strcmp(current, sch.code) == 0) {
hit = true;
lcd_print(1, 2, sch.display_text);
vTaskDelay(pdMS_TO_TICKS(2000));
if (sch.callback != nullptr) {
(sch.callback)();
}
if (sch.should_exit) {
return;
}
break;
}
}
if (!hit) {
lcd_print(1, 2, "Invalid Star Code");
vTaskDelay(pdMS_TO_TICKS(2000));
}
// clear
for (int i = 0; i < STRING_MAX_LEN; i++) {
current[i] = 0;
}
current_idx = 0;
} else {
// out of room. skip
if (current_idx >= STRING_MAX_LEN) break;
// no code started.
if (current[0] != '*') continue;
char c = char_of_keypad_key(key);
current[current_idx++] = c;
}
// ESP_LOGI(STEP0_TAG, "Pressed: %c", c);
lcd_clear();
lcd_print(1, 1, current);
}
vTaskDelay(pdMS_TO_TICKS(10));
}
} }
static lv_obj_t* old_scr; static lv_obj_t* old_scr;
@@ -54,6 +120,7 @@ void display_game_results(void) {
lv_style_init(&game_results_style); lv_style_init(&game_results_style);
lv_style_set_text_color(&game_results_style, lv_color_white()); lv_style_set_text_color(&game_results_style, lv_color_white());
// lv_style_set_bg_color(&game_results_style, lv_color_black());
lv_style_set_text_align(&game_results_style, LV_TEXT_ALIGN_LEFT); lv_style_set_text_align(&game_results_style, LV_TEXT_ALIGN_LEFT);
overall_results_label = lv_label_create(scr); overall_results_label = lv_label_create(scr);
+9
View File
@@ -10,11 +10,20 @@
#include "drivers/speaker.h" #include "drivers/speaker.h"
#include "drivers/tft.h" #include "drivers/tft.h"
struct StarCodeHandler {
const char* code;
const char* display_text;
bool should_exit;
void (*callback)(void);
};
// TODO: add something for RNG. // TODO: add something for RNG.
// TODO: add something for colors, to make everything consistant.
/// Clears most persistant bomb state /// Clears most persistant bomb state
void clean_bomb(void); void clean_bomb(void);
void poster_child_task(void* arg); void poster_child_task(void* arg);
void do_star_codes(StarCodeHandler* star_codes, int star_codes_len);
void display_game_results(); void display_game_results();
#endif /* HELPER_H */ #endif /* HELPER_H */
-15
View File
@@ -5,10 +5,8 @@
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_rom_gpio.h" #include "esp_rom_gpio.h"
#include "esp_heap_caps.h"
#include "drivers/all.h" #include "drivers/all.h"
#include "drivers/state_tracking.h"
#include "helper.h" #include "helper.h"
@@ -34,20 +32,9 @@ extern "C" void app_main(void) {
// TODO: get wires out of the drivers // TODO: get wires out of the drivers
// TODO: generify the strike system out of wires // TODO: generify the strike system out of wires
init_wires(); init_wires();
vTaskDelay(pdMS_TO_TICKS(1000));
clean_bomb(); clean_bomb();
lcd_do_splash();
step0(); step0();
// set_recording_source(stdout, false);
FILE* record_file = fopen(MOUNT_POINT "/record.txt", "w");
if (record_file == nullptr) {
ESP_LOGE("main", "failed to open record.txt");
}
set_recording_source(record_file, true);
start_recording();
set_game_time(initial_game_time); set_game_time(initial_game_time);
start_game_timer(); start_game_timer();
total_strikes = 0; total_strikes = 0;
@@ -83,6 +70,4 @@ extern "C" void app_main(void) {
play_clip_wav(MOUNT_POINT "/diffuse.wav", true, false, 3, 0); play_clip_wav(MOUNT_POINT "/diffuse.wav", true, false, 3, 0);
display_game_results(); display_game_results();
stop_recording();
} }
+1 -1
View File
@@ -30,7 +30,7 @@ void setup_wires(void) {
clear_all_pressed_released(); clear_all_pressed_released();
get_cut_wires(); get_cut_wires();
lcd_clear(); lcd_clear();
lcd_set_cursor_vis(true); lcd_set_cursor_vis(false);
WireColor wires[NUM_WIRES]; WireColor wires[NUM_WIRES];
load_wires_from_sd_card(wires); load_wires_from_sd_card(wires);
+45 -91
View File
@@ -1,5 +1,4 @@
#include "step0.h" #include "step0.h"
#include "drivers/state_tracking.h"
static const char* TAG = "step0"; static const char* TAG = "step0";
@@ -35,177 +34,132 @@ static void battery_stats() {
} }
} }
// TODO: remove. This is temperary /// Wait for "*9819"
static void replay_last() {
FILE* record_file = fopen(MOUNT_POINT "/record.txt", "r");
if (record_file == nullptr) {
ESP_LOGE("main", "failed to open record.txt");
}
set_playback_source(record_file, true);
start_playback();
}
void step0() { void step0() {
led_set(IndicatorLED::LED_SPEAKER, LEDColor::LED_COLOR_BLUE); led_set(IndicatorLED::LED_SPEAKER, LEDColor::LED_COLOR_BLUE);
leds_flush(); leds_flush();
SemaphoreHandle_t continue_sem = xSemaphoreCreateBinary(); StarCodeHandler star_codes[] = {
if (continue_sem == nullptr) {
ESP_LOGE(TAG, "could not create semaphore");
return;
}
StarCodeEntry star_codes[] = {
{ {
.code = "9819", .code = "*9819",
.display_text = "Diffusal Initiated", .display_text = "Diffusal Initiated",
.delay_us = 2'000'000, .should_exit = true,
.callback = nullptr, .callback = nullptr,
.triggered_sem = continue_sem,
}, },
{ {
.code = "59861", .code = "*59861",
.display_text = "Setup Wires", .display_text = "Set Up Wires",
.delay_us = 10'000'000, .should_exit = false,
.callback = setup_wires, .callback = setup_wires,
.triggered_sem = nullptr,
}, },
{ {
.code = "59862", .code = "*59862",
.display_text = "Set Game Time", .display_text = "Set Game Time",
.delay_us = 2'000'000, .should_exit = false,
.callback = set_game_time, .callback = set_game_time,
.triggered_sem = nullptr,
}, },
{ {
.code = "59863", .code = "*59863",
.display_text = "Debug switches", .display_text = "Debug Switches",
.delay_us = 2'000'000, .should_exit = false,
.callback = debug_switches, .callback = debug_switches,
.triggered_sem = nullptr,
}, },
{ {
.code = "59864", .code = "*59864",
.display_text = "Battery Stats", .display_text = "Battery Stats",
.delay_us = 2'000'000, .should_exit = false,
.callback = battery_stats, .callback = battery_stats,
.triggered_sem = nullptr,
}, },
{ {
.code = "59871", .code = "*59871",
.display_text = "Try Step 1", .display_text = "Try Step 1",
.delay_us = 2'000'000, .should_exit = false,
.callback = try_step1, .callback = try_step1,
.triggered_sem = nullptr,
}, },
{ {
.code = "59872", .code = "*59872",
.display_text = "Try Step 2", .display_text = "Try Step 2",
.delay_us = 2'000'000, .should_exit = false,
.callback = try_step2, .callback = try_step2,
.triggered_sem = nullptr,
}, },
{ {
.code = "59873", .code = "*59873",
.display_text = "Try Step 3", .display_text = "Try Step 3",
.delay_us = 2'000'000, .should_exit = false,
.callback = try_step3, .callback = try_step3,
.triggered_sem = nullptr,
}, },
{ {
.code = "59874", .code = "*59874",
.display_text = "Try Step 4", .display_text = "Try Step 4",
.delay_us = 2'000'000, .should_exit = false,
.callback = try_step4, .callback = try_step4,
.triggered_sem = nullptr,
}, },
{ {
.code = "59875", .code = "*59875",
.display_text = "Try Step 5", .display_text = "Try Step 5",
.delay_us = 2'000'000, .should_exit = false,
.callback = try_step5, .callback = try_step5,
.triggered_sem = nullptr,
}, },
{ {
.code = "59876", .code = "*59876",
.display_text = "Try Step 6", .display_text = "Try Step 6",
.delay_us = 2'000'000, .should_exit = false,
.callback = try_step6, .callback = try_step6,
.triggered_sem = nullptr,
}, },
{ {
.code = "59881", .code = "*59881",
.display_text = "Skip To Step 1", .display_text = "Skip To Step 1",
.delay_us = 2'000'000, .should_exit = true,
.callback = skip_to_step1, .callback = skip_to_step1,
.triggered_sem = continue_sem,
}, },
{ {
.code = "59882", .code = "*59882",
.display_text = "Skip To Step 2", .display_text = "Skip To Step 2",
.delay_us = 2'000'000, .should_exit = true,
.callback = skip_to_step2, .callback = skip_to_step2,
.triggered_sem = continue_sem,
}, },
{ {
.code = "59883", .code = "*59883",
.display_text = "Skip To Step 3", .display_text = "Skip To Step 3",
.delay_us = 2'000'000, .should_exit = true,
.callback = skip_to_step3, .callback = skip_to_step3,
.triggered_sem = continue_sem,
}, },
{ {
.code = "59884", .code = "*59884",
.display_text = "Skip To Step 4", .display_text = "Skip To Step 4",
.delay_us = 2'000'000, .should_exit = true,
.callback = skip_to_step4, .callback = skip_to_step4,
.triggered_sem = continue_sem,
}, },
{ {
.code = "59885", .code = "*59885",
.display_text = "Skip To Step 5", .display_text = "Skip To Step 5",
.delay_us = 2'000'000, .should_exit = true,
.callback = skip_to_step5, .callback = skip_to_step5,
.triggered_sem = continue_sem,
}, },
{ {
.code = "59886", .code = "*59886",
.display_text = "Skip To Step 6", .display_text = "Skip To Step 6",
.delay_us = 2'000'000, .should_exit = true,
.callback = skip_to_step6, .callback = skip_to_step6,
.triggered_sem = continue_sem,
}, },
{ {
.code = "1111", .code = "*1111",
.display_text = "Issue Strike", .display_text = "Issue Strike",
.delay_us = 2'000'000, .should_exit = false,
.callback = issue_strike, .callback = issue_strike,
.triggered_sem = nullptr,
}, },
{ {
.code = "1112", .code = "*1112",
.display_text = "????", .display_text = "????",
.delay_us = 2'000'000, .should_exit = false,
.callback = flashbang, .callback = flashbang,
.triggered_sem = nullptr,
},
{
.code = "1113",
.display_text = "replay",
.delay_us = 2'000'000,
.callback = replay_last,
.triggered_sem = continue_sem,
}, },
}; };
size_t len = sizeof(star_codes)/sizeof(star_codes[0]); int len = sizeof(star_codes)/sizeof(StarCodeHandler);
do_star_codes(star_codes, len);
add_star_codes(star_codes, len);
xSemaphoreTake(continue_sem, portMAX_DELAY);
rm_star_codes(star_codes, len);
vSemaphoreDelete(continue_sem);
} }
static const int CURSOR_POS_MAP[5] = {1, 3, 4, 6, 7}; static const int CURSOR_POS_MAP[5] = {1, 3, 4, 6, 7};
static char str_buf[18] = {0}; static char str_buf[18] = {0};
static void _update_display(uint8_t* digits, uint8_t cursor_pos) { static void _update_display(uint8_t* digits, uint8_t cursor_pos) {
+6 -2
View File
@@ -1,9 +1,13 @@
#ifndef STEP_0_H #ifndef STEP_0_H
#define STEP_0_H #define STEP_0_H
#include "../drivers/all.h" #include "../drivers/bottom_half.h"
#include "../drivers/char_lcd.h"
#include "../drivers/wires.h"
#include "../drivers/power.h"
#include "setup_wires.h" #include "setup_wires.h"
#include "../helper.h"
#include "step1.h" #include "step1.h"
#include "step2.h" #include "step2.h"
#include "step3.h" #include "step3.h"
+4 -3
View File
@@ -206,17 +206,18 @@ static bool play_part(uint32_t time) {
set_module_time(time); set_module_time(time);
lcd_clear(); lcd_clear();
lcd_set_cursor_pos(1, 1);
switch (part) { switch (part) {
case 0: case 0:
lcd_print(1, 1, "COLOR"); lcd_print("COLOR");
led_set(IndicatorLED::LED_LCD, LEDColor::LED_COLOR_PINK); led_set(IndicatorLED::LED_LCD, LEDColor::LED_COLOR_PINK);
break; break;
case 1: case 1:
lcd_print(1, 1, "NUMBER"); lcd_print("NUMBER");
led_set(IndicatorLED::LED_LCD, LEDColor::LED_COLOR_BLUE); led_set(IndicatorLED::LED_LCD, LEDColor::LED_COLOR_BLUE);
break; break;
case 2: case 2:
lcd_print(1, 1, "SWITCH"); lcd_print("SWITCH");
led_set(IndicatorLED::LED_LCD, LEDColor::LED_COLOR_YELLOW); led_set(IndicatorLED::LED_LCD, LEDColor::LED_COLOR_YELLOW);
break; break;
} }
+7 -2
View File
@@ -2,8 +2,13 @@
#define STEP_1_H #define STEP_1_H
#include <random> #include <random>
#include "../drivers/all.h" #include "../drivers/bottom_half.h"
#include "../helper.h" #include "../drivers/tft.h"
#include "../drivers/leds.h"
#include "../drivers/wires.h"
#include "../drivers/speaker.h"
#include "../drivers/game_timer.h"
#include "../drivers/char_lcd.h"
void step1(void); void step1(void);
+1 -1
View File
@@ -88,7 +88,6 @@ static void new_puzzle(void) {
// ESP_LOGI(TAG, "Flipping bit %i on display %i", i, display); // ESP_LOGI(TAG, "Flipping bit %i on display %i", i, display);
} }
} }
set_module_sseg_raw(display_map);
} }
void step2(void) { void step2(void) {
@@ -99,6 +98,7 @@ void step2(void) {
int strike_time = 0; int strike_time = 0;
while(solved_times < NUM_SOLVES) { while(solved_times < NUM_SOLVES) {
// for every bit in the answer- // for every bit in the answer-
set_module_sseg_raw(display_map);
if (get_keypad_pressed(&key)) { if (get_keypad_pressed(&key)) {
lcd_clear(); lcd_clear();
char c = char_of_keypad_key(key); char c = char_of_keypad_key(key);
+5 -1
View File
@@ -1,7 +1,11 @@
#ifndef STEP_2_H #ifndef STEP_2_H
#define STEP_2_H #define STEP_2_H
#include "../drivers/all.h" #include "../drivers/bottom_half.h"
#include "../drivers/wires.h"
#include "../drivers/game_timer.h"
#include "../drivers/leds.h"
#include "../drivers/speaker.h"
#include "../helper.h" #include "../helper.h"
#include <iostream> #include <iostream>
#include <random> #include <random>
+21 -38
View File
@@ -21,8 +21,6 @@ static const char* TONE_FILES[] = {
MOUNT_POINT "/high-6.wav", MOUNT_POINT "/high-6.wav",
}; };
static const size_t LCD_STRING_SOMETHING = 0;
static const size_t LCD_STRING_NOTHING = 1;
static const char* LCD_STRINGS[] = { static const char* LCD_STRINGS[] = {
"something", "something",
"nothing", "nothing",
@@ -51,20 +49,13 @@ static std::uniform_int_distribution<> lcd_rand_char_dist(0, sizeof(lcd_random_c
static std::uniform_int_distribution<> has_coconut_dist(0, 2); static std::uniform_int_distribution<> has_coconut_dist(0, 2);
static std::uniform_int_distribution<> coconut_position_dist(0, 13); static std::uniform_int_distribution<> coconut_position_dist(0, 13);
const static uint32_t NEOPIXEL_COLOR_IDX_RED = 0;
const static uint32_t NEOPIXEL_COLOR_IDX_YELLOW = 1;
const static uint32_t NEOPIXEL_COLOR_IDX_GREEN = 2;
const static uint32_t NEOPIXEL_COLOR_IDX_BLUE = 3;
const static uint32_t NEOPIXEL_COLOR_IDX_PINK = 4;
const static uint32_t NEOPIXEL_COLOR_IDX_WHITE = 5;
const static uint32_t NEOPIXEL_COLOR_IDX_OFF = 6;
static uint32_t NEOPIXEL_COLORS[7] = { static uint32_t NEOPIXEL_COLORS[7] = {
LEDColor::LED_COLOR_RED, LEDColor::LED_COLOR_RED,
LEDColor::LED_COLOR_ORANGE,
LEDColor::LED_COLOR_YELLOW, LEDColor::LED_COLOR_YELLOW,
LEDColor::LED_COLOR_GREEN, LEDColor::LED_COLOR_GREEN,
LEDColor::LED_COLOR_BLUE, LEDColor::LED_COLOR_BLUE,
LEDColor::LED_COLOR_PINK, LEDColor::LED_COLOR_PINK,
LEDColor::LED_COLOR_WHITE,
LEDColor::LED_COLOR_OFF, LEDColor::LED_COLOR_OFF,
}; };
@@ -73,24 +64,16 @@ static bool three_second();
static bool six_second(); static bool six_second();
void step3(void) { void step3(void) {
SemaphoreHandle_t continue_sem = xSemaphoreCreateBinary(); StarCodeHandler star_codes[] = {
if (continue_sem == nullptr) { {
ESP_LOGE(TAG, "could not create semaphore"); .code = "*1642",
return; .display_text = "Starting...",
} .should_exit = true,
.callback = nullptr,
StarCodeEntry start_code = { },
.code = "1642",
.display_text = "Starting...",
.delay_us = 2'000'000,
.callback = nullptr,
.triggered_sem = continue_sem,
}; };
int len = sizeof(star_codes)/sizeof(StarCodeHandler);
add_star_code(start_code); do_star_codes(star_codes, len);
xSemaphoreTake(continue_sem, portMAX_DELAY);
rm_star_code(start_code.code);
vSemaphoreDelete(continue_sem);
while (times < TIMES_TO_COMPLETE) { while (times < TIMES_TO_COMPLETE) {
tone = tone_dist(gen); tone = tone_dist(gen);
@@ -99,7 +82,7 @@ void step3(void) {
play_clip_wav(MOUNT_POINT "/ready.wav", true, false, 3, 0); play_clip_wav(MOUNT_POINT "/ready.wav", true, false, 3, 0);
// The high pitched tones need to be scaled down by 3 more // The high pitched tones need to be scaled down by 3 more
play_clip_wav(TONE_FILES[tone], false, false, 1 + (tone/3) * 4, 0); play_clip_wav(TONE_FILES[tone], false, false, 2 + (tone/3) * 3, 0);
bool correct = false; bool correct = false;
switch (tone % 3) { switch (tone % 3) {
@@ -238,16 +221,16 @@ static bool one_second() {
int red_led_count = 0; int red_led_count = 0;
int blue_led_count = 0; int blue_led_count = 0;
for (int i = 0; i < LED_COUNT; i++) { for (int i = 0; i < LED_COUNT; i++) {
if (indicator_led_idxs[i] == NEOPIXEL_COLOR_IDX_RED) { if (indicator_led_idxs[i] == 0) {
red_led_count++; red_led_count++;
} else if (indicator_led_idxs[i] == NEOPIXEL_COLOR_IDX_BLUE) { } else if (indicator_led_idxs[i] == 4) {
blue_led_count++; blue_led_count++;
} }
} }
uint8_t correct_switches = four_bit_flag( uint8_t correct_switches = four_bit_flag(
speaker_color == NEOPIXEL_COLOR_IDX_RED || speaker_color == NEOPIXEL_COLOR_IDX_YELLOW || speaker_color == NEOPIXEL_COLOR_IDX_PINK, speaker_color == 0 || speaker_color == 1 || speaker_color == 2,
lcd_string_idx == LCD_STRING_SOMETHING || lcd_string_idx == LCD_STRING_NOTHING, lcd_string_idx == 0 || lcd_string_idx == 1,
was_high, was_high,
!was_high !was_high
); );
@@ -297,9 +280,9 @@ static bool three_second() {
int red_led_count = 0; int red_led_count = 0;
int blue_led_count = 0; int blue_led_count = 0;
for (int i = 0; i < LED_COUNT; i++) { for (int i = 0; i < LED_COUNT; i++) {
if (indicator_led_idxs[i] == NEOPIXEL_COLOR_IDX_RED) { if (indicator_led_idxs[i] == 0) {
red_led_count++; red_led_count++;
} else if (indicator_led_idxs[i] == NEOPIXEL_COLOR_IDX_BLUE) { } else if (indicator_led_idxs[i] == 4) {
blue_led_count++; blue_led_count++;
} }
} }
@@ -362,7 +345,7 @@ static bool six_second() {
bool was_high = (tone / 3) == 1; bool was_high = (tone / 3) == 1;
bool second_switch_correct_state = (indicator_led_idxs[IndicatorLED::LED_S2] == NEOPIXEL_COLOR_IDX_RED) || (indicator_led_idxs[IndicatorLED::LED_S2] == NEOPIXEL_COLOR_IDX_OFF); bool second_switch_correct_state = (indicator_led_idxs[IndicatorLED::LED_S2] == 0) || (indicator_led_idxs[IndicatorLED::LED_S2] == 6);
second_switch_correct_state = second_switch_correct_state || was_high; second_switch_correct_state = second_switch_correct_state || was_high;
rng_leds(); rng_leds();
@@ -371,16 +354,16 @@ static bool six_second() {
int green_led_count = 0; int green_led_count = 0;
int blue_led_count = 0; int blue_led_count = 0;
for (int i = 0; i < LED_COUNT; i++) { for (int i = 0; i < LED_COUNT; i++) {
if (indicator_led_idxs[i] == NEOPIXEL_COLOR_IDX_BLUE) { if (indicator_led_idxs[i] == 4) {
blue_led_count++; blue_led_count++;
} else if (indicator_led_idxs[i] == NEOPIXEL_COLOR_IDX_GREEN) { } else if (indicator_led_idxs[i] == 3) {
green_led_count++; green_led_count++;
} }
} }
int pink_led_on_bottom_count = 0; int pink_led_on_bottom_count = 0;
for (int i = IndicatorLED::LED_RFID; i < LED_COUNT; i++) { for (int i = IndicatorLED::LED_RFID; i < LED_COUNT; i++) {
if (indicator_led_idxs[i] == NEOPIXEL_COLOR_IDX_PINK) { if (indicator_led_idxs[i] == 5) {
pink_led_on_bottom_count++; pink_led_on_bottom_count++;
} }
} }
+6 -1
View File
@@ -2,7 +2,12 @@
#define STEP_3_H #define STEP_3_H
#include <random> #include <random>
#include "../drivers/all.h" #include "../drivers/bottom_half.h"
#include "../drivers/wires.h"
#include "../drivers/speaker.h"
#include "../drivers/leds.h"
#include "../drivers/char_lcd.h"
#include "../drivers/game_timer.h"
#include "../helper.h" #include "../helper.h"
void step3(void); void step3(void);
+4 -17
View File
@@ -380,29 +380,16 @@ static void fail() {
} }
void step4() { void step4() {
// TODO: extract to helper function StarCodeHandler star_code = {
SemaphoreHandle_t continue_sem = xSemaphoreCreateBinary(); .code = "*3850",
if (continue_sem == nullptr) {
ESP_LOGE(TAG, "could not create semaphore");
}
StarCodeEntry start_code = {
.code = "3850",
.display_text = "Starting...", .display_text = "Starting...",
.delay_us = 2'000'000, .should_exit = true,
.callback = nullptr, .callback = nullptr,
.triggered_sem = continue_sem,
}; };
do_star_codes(&star_code, 1);
add_star_code(start_code);
xSemaphoreTake(continue_sem, portMAX_DELAY);
rm_star_code(start_code.code);
vSemaphoreDelete(continue_sem);
init_screen(); init_screen();
while (!play_game(4*60*1000, 2)) fail(); while (!play_game(4*60*1000, 2)) fail();
// TODO: create constants for common assets, and put them in a folder.
play_clip_wav(MOUNT_POINT "/partdone.wav", true, false, 0, 0); play_clip_wav(MOUNT_POINT "/partdone.wav", true, false, 0, 0);
complete(); complete();
while (!play_game(4*60*1000, 4)) fail(); while (!play_game(4*60*1000, 4)) fail();
+6 -2
View File
@@ -2,9 +2,13 @@
#define STEP_4_H #define STEP_4_H
#include <random> #include <random>
#include "../drivers/all.h" #include "../drivers/tft.h"
#include "../drivers/speaker.h"
#include "../drivers/bottom_half.h"
#include "../drivers/game_timer.h"
#include "../drivers/wires.h"
#include "../drivers/char_lcd.h"
#include "../helper.h" #include "../helper.h"
#include "esp_log.h"
#define TETRIS_USE_FLASH_IMG #define TETRIS_USE_FLASH_IMG
#define TETRIS_USE_FLASH_BG_IMG #define TETRIS_USE_FLASH_BG_IMG
+21 -26
View File
@@ -179,23 +179,16 @@ bool submit_6(bool* buttons_cycling, bool button_turned_on, int led_off) {
} }
void step5(void) { void step5(void) {
SemaphoreHandle_t continue_sem = xSemaphoreCreateBinary(); StarCodeHandler star_codes[] = {
if (continue_sem == nullptr) { {
ESP_LOGE(TAG, "could not create semaphore"); .code = "*2648",
} .display_text = "Starting...",
.should_exit = true,
StarCodeEntry start_code = { .callback = nullptr,
.code = "2648", },
.display_text = "Starting...",
.delay_us = 2'000'000,
.callback = nullptr,
.triggered_sem = continue_sem,
}; };
int len = sizeof(star_codes)/sizeof(StarCodeHandler);
add_star_code(start_code); do_star_codes(star_codes, len);
xSemaphoreTake(continue_sem, portMAX_DELAY);
rm_star_code(start_code.code);
vSemaphoreDelete(continue_sem);
std::vector<int> all_leds; std::vector<int> all_leds;
@@ -229,13 +222,15 @@ void step5(void) {
clean_bomb(); clean_bomb();
int solved_puzzles = 0; int solved_puzzles = 0;
while (solved_puzzles < TIMES_TO_SOLVE) { while (solved_puzzles < TIMES_TO_SOLVE) {
lcd_set_cursor_pos(1, 1);
bool solved_correctly = false; bool solved_correctly = false;
int puzzle = puzzle_dist(gen); int puzzle = puzzle_dist(gen);
// int puzzle = 2;
switch (puzzle) { switch (puzzle) {
case 0: { case 0: {
lcd_print(1, 1, "Clear"); lcd_print("Clear");
set_module_time(TIME_CLEAR); set_module_time(TIME_CLEAR);
start_module_timer(); start_module_timer();
@@ -270,7 +265,7 @@ void step5(void) {
break; break;
} }
case 1: { case 1: {
lcd_print(1, 1, "Blank"); lcd_print("Blank");
set_module_time(TIME_BLANK); set_module_time(TIME_BLANK);
start_module_timer(); start_module_timer();
@@ -384,7 +379,7 @@ void step5(void) {
break; break;
} }
case 3: { case 3: {
lcd_print(1, 1, "Nothing"); lcd_print("Nothing");
set_module_time(TIME_NOTHING); set_module_time(TIME_NOTHING);
start_module_timer(); start_module_timer();
@@ -443,7 +438,7 @@ void step5(void) {
break; break;
} }
case 4: { case 4: {
lcd_print(1, 1, "Blink"); lcd_print("Blink");
set_module_time(TIME_BLINK); set_module_time(TIME_BLINK);
start_module_timer(); start_module_timer();
@@ -507,7 +502,7 @@ void step5(void) {
break; break;
} }
case 5: { case 5: {
lcd_print(1, 1, "Ummm"); lcd_print("Ummm");
set_module_time(TIME_UMMM); set_module_time(TIME_UMMM);
start_module_timer(); start_module_timer();
@@ -563,7 +558,7 @@ void step5(void) {
break; break;
} }
case 6: { case 6: {
lcd_print(1, 1, "Plank"); lcd_print("Plank");
set_module_time(TIME_PLANK); set_module_time(TIME_PLANK);
start_module_timer(); start_module_timer();
@@ -656,7 +651,7 @@ void step5(void) {
break; break;
} }
case 7: { case 7: {
lcd_print(1, 1, "What"); lcd_print("What");
set_module_time(TIME_WHAT); set_module_time(TIME_WHAT);
start_module_timer(); start_module_timer();
@@ -804,7 +799,7 @@ void step5(void) {
break; break;
} }
case 8: { case 8: {
lcd_print(1, 1, "Plink"); lcd_print("Plink");
set_module_time(TIME_PLINK); set_module_time(TIME_PLINK);
start_module_timer(); start_module_timer();
@@ -905,13 +900,13 @@ void step5(void) {
stop_module_timer(); stop_module_timer();
if (solved_correctly) { if (solved_correctly) {
solved_puzzles++; solved_puzzles++;
play_clip_wav(MOUNT_POINT "/partdone.wav", true, false, 0, 0); play_clip_wav(MOUNT_POINT "/correct.wav", true, false, 3, 0);
vTaskDelay(pdMS_TO_TICKS(500)); vTaskDelay(pdMS_TO_TICKS(500));
solved_correctly = false; solved_correctly = false;
} else { } else {
vTaskDelay(pdMS_TO_TICKS(3000)); vTaskDelay(pdMS_TO_TICKS(3000));
} }
play_clip_wav(MOUNT_POINT "/stepdone.wav", true, false, 1, 0); clear_all_pressed_released();
clean_bomb(); clean_bomb();
} }
} }
+5 -1
View File
@@ -1,7 +1,11 @@
#ifndef STEP_5_H #ifndef STEP_5_H
#define STEP_5_H #define STEP_5_H
#include "../drivers/all.h" #include "../drivers/bottom_half.h"
#include "../drivers/game_timer.h"
#include "../drivers/char_lcd.h"
#include "../drivers/leds.h"
#include "../drivers/wires.h"
#include "../helper.h" #include "../helper.h"
#include <random> #include <random>
#include <iostream> #include <iostream>
+4 -2
View File
@@ -2,8 +2,10 @@
#define STEP_6_H #define STEP_6_H
#include "wires_puzzle.h" #include "wires_puzzle.h"
#include "../drivers/all.h" #include "drivers/wires.h"
#include "../helper.h" #include "drivers/bottom_half.h"
#include "drivers/sd.h"
#include "drivers/speaker.h"
void step6(void); void step6(void);
-8
View File
@@ -1,8 +0,0 @@
# ESP-IDF Partition Table
# Name, Type, SubType, Offset, Size, Flags
nvs,data,nvs,0x9000,0x6000,,
phy_init,data,phy,0xf000,0x1000,,
ota,data,ota,0x10000,0x2000,,
factory,app,factory,0x20000,2M,,
ota0,app,ota_0,0x220000,2M,,
ota1,app,ota_1,0x420000,2M,,
1 # ESP-IDF Partition Table
2 # Name, Type, SubType, Offset, Size, Flags
3 nvs,data,nvs,0x9000,0x6000,,
4 phy_init,data,phy,0xf000,0x1000,,
5 ota,data,ota,0x10000,0x2000,,
6 factory,app,factory,0x20000,2M,,
7 ota0,app,ota_0,0x220000,2M,,
8 ota1,app,ota_1,0x420000,2M,,
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+550
View File
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
+3366
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
+10 -49
View File
@@ -527,11 +527,11 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
# Partition Table # Partition Table
# #
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set # CONFIG_PARTITION_TABLE_SINGLE_APP is not set
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
# CONFIG_PARTITION_TABLE_TWO_OTA is not set # CONFIG_PARTITION_TABLE_TWO_OTA is not set
CONFIG_PARTITION_TABLE_CUSTOM=y # CONFIG_PARTITION_TABLE_CUSTOM is not set
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp_large.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000 CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y CONFIG_PARTITION_TABLE_MD5=y
# end of Partition Table # end of Partition Table
@@ -539,7 +539,7 @@ CONFIG_PARTITION_TABLE_MD5=y
# #
# BLK_BOX Config # BLK_BOX Config
# #
# CONFIG_USE_NEW_DISPLAY is not set CONFIG_USE_NEW_DISPLAY=y
# end of BLK_BOX Config # end of BLK_BOX Config
# #
@@ -920,8 +920,8 @@ CONFIG_ESP32S3_UNIVERSAL_MAC_ADDRESSES=4
# #
# Sleep Config # Sleep Config
# #
# CONFIG_ESP_SLEEP_POWER_DOWN_FLASH is not set
CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND=y CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND=y
CONFIG_ESP_SLEEP_PSRAM_LEAKAGE_WORKAROUND=y
CONFIG_ESP_SLEEP_MSPI_NEED_ALL_IO_PU=y CONFIG_ESP_SLEEP_MSPI_NEED_ALL_IO_PU=y
CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y CONFIG_ESP_SLEEP_RTC_BUS_ISO_WORKAROUND=y
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
@@ -1030,39 +1030,7 @@ CONFIG_PM_RESTORE_CACHE_TAGMEM_AFTER_LIGHT_SLEEP=y
# #
# ESP PSRAM # ESP PSRAM
# #
CONFIG_SPIRAM=y # CONFIG_SPIRAM is not set
#
# SPI RAM config
#
CONFIG_SPIRAM_MODE_QUAD=y
# CONFIG_SPIRAM_MODE_OCT is not set
CONFIG_SPIRAM_TYPE_AUTO=y
# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_CLK_IO=30
CONFIG_SPIRAM_CS_IO=26
# CONFIG_SPIRAM_XIP_FROM_PSRAM is not set
# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
# CONFIG_SPIRAM_RODATA is not set
# CONFIG_SPIRAM_SPEED_120M is not set
# CONFIG_SPIRAM_SPEED_80M is not set
CONFIG_SPIRAM_SPEED_40M=y
CONFIG_SPIRAM_SPEED=40
CONFIG_SPIRAM_BOOT_INIT=y
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
# CONFIG_SPIRAM_USE_MEMMAP is not set
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
CONFIG_SPIRAM_USE_MALLOC=y
CONFIG_SPIRAM_MEMTEST=y
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
# CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is not set
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
# CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY is not set
# end of SPI RAM config
# end of ESP PSRAM # end of ESP PSRAM
# #
@@ -1216,9 +1184,9 @@ CONFIG_ESP_WIFI_ENABLED=y
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=10 CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=10
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=32 CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=32
CONFIG_ESP_WIFI_STATIC_TX_BUFFER=y CONFIG_ESP_WIFI_STATIC_TX_BUFFER=y
# CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER is not set
CONFIG_ESP_WIFI_TX_BUFFER_TYPE=0 CONFIG_ESP_WIFI_TX_BUFFER_TYPE=0
CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=16 CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=16
CONFIG_ESP_WIFI_CACHE_TX_BUFFER_NUM=32
CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y CONFIG_ESP_WIFI_STATIC_RX_MGMT_BUFFER=y
# CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set # CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER is not set
CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0 CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF=0
@@ -1228,7 +1196,6 @@ CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP_WIFI_TX_BA_WIN=6 CONFIG_ESP_WIFI_TX_BA_WIN=6
CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP_WIFI_RX_BA_WIN=6 CONFIG_ESP_WIFI_RX_BA_WIN=6
# CONFIG_ESP_WIFI_AMSDU_TX_ENABLED is not set
CONFIG_ESP_WIFI_NVS_ENABLED=y CONFIG_ESP_WIFI_NVS_ENABLED=y
CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0=y CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_1 is not set # CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_1 is not set
@@ -1318,7 +1285,6 @@ CONFIG_FATFS_CODEPAGE=437
CONFIG_FATFS_FS_LOCK=0 CONFIG_FATFS_FS_LOCK=0
CONFIG_FATFS_TIMEOUT_MS=10000 CONFIG_FATFS_TIMEOUT_MS=10000
CONFIG_FATFS_PER_FILE_CACHE=y CONFIG_FATFS_PER_FILE_CACHE=y
CONFIG_FATFS_ALLOC_PREFER_EXTRAM=y
# CONFIG_FATFS_USE_FASTSEEK is not set # CONFIG_FATFS_USE_FASTSEEK is not set
CONFIG_FATFS_VFS_FSTAT_BLKSIZE=0 CONFIG_FATFS_VFS_FSTAT_BLKSIZE=0
# CONFIG_FATFS_IMMEDIATE_FSYNC is not set # CONFIG_FATFS_IMMEDIATE_FSYNC is not set
@@ -1623,7 +1589,6 @@ CONFIG_LWIP_HOOK_IP6_INPUT_NONE=y
# mbedTLS # mbedTLS
# #
CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y
# CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC is not set
# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set # CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set # CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
@@ -1786,8 +1751,6 @@ CONFIG_NEWLIB_TIME_SYSCALL_USE_RTC_HRT=y
# CONFIG_NEWLIB_TIME_SYSCALL_USE_NONE is not set # CONFIG_NEWLIB_TIME_SYSCALL_USE_NONE is not set
# end of Newlib # end of Newlib
CONFIG_STDATOMIC_S32C1I_SPIRAM_WORKAROUND=y
# #
# NVS # NVS
# #
@@ -2414,6 +2377,7 @@ CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
CONFIG_GDBSTUB_SUPPORT_TASKS=y CONFIG_GDBSTUB_SUPPORT_TASKS=y
CONFIG_GDBSTUB_MAX_TASKS=32 CONFIG_GDBSTUB_MAX_TASKS=32
# CONFIG_OTA_ALLOW_HTTP is not set # CONFIG_OTA_ALLOW_HTTP is not set
# CONFIG_ESP_SYSTEM_PD_FLASH is not set
CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000 CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000
CONFIG_ESP_SLEEP_DEEP_SLEEP_WAKEUP_DELAY=2000 CONFIG_ESP_SLEEP_DEEP_SLEEP_WAKEUP_DELAY=2000
CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC=y CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC=y
@@ -2429,9 +2393,7 @@ CONFIG_ESP32_PHY_MAX_TX_POWER=20
# CONFIG_ESP32_REDUCE_PHY_TX_POWER is not set # CONFIG_ESP32_REDUCE_PHY_TX_POWER is not set
CONFIG_ESP_SYSTEM_PM_POWER_DOWN_CPU=y CONFIG_ESP_SYSTEM_PM_POWER_DOWN_CPU=y
CONFIG_PM_POWER_DOWN_TAGMEM_IN_LIGHT_SLEEP=y CONFIG_PM_POWER_DOWN_TAGMEM_IN_LIGHT_SLEEP=y
CONFIG_ESP32S3_SPIRAM_SUPPORT=y # CONFIG_ESP32S3_SPIRAM_SUPPORT is not set
CONFIG_DEFAULT_PSRAM_CLK_IO=30
CONFIG_DEFAULT_PSRAM_CS_IO=26
# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_80 is not set # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_80 is not set
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160=y CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160=y
# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240 is not set # CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240 is not set
@@ -2482,9 +2444,9 @@ CONFIG_ESP32_WIFI_ENABLED=y
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32 CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y
# CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER is not set
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0 CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16 CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=16
CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=32
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set # CONFIG_ESP32_WIFI_CSI_ENABLED is not set
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP32_WIFI_TX_BA_WIN=6 CONFIG_ESP32_WIFI_TX_BA_WIN=6
@@ -2492,7 +2454,6 @@ CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP32_WIFI_RX_BA_WIN=6 CONFIG_ESP32_WIFI_RX_BA_WIN=6
CONFIG_ESP32_WIFI_RX_BA_WIN=6 CONFIG_ESP32_WIFI_RX_BA_WIN=6
# CONFIG_ESP32_WIFI_AMSDU_TX_ENABLED is not set
CONFIG_ESP32_WIFI_NVS_ENABLED=y CONFIG_ESP32_WIFI_NVS_ENABLED=y
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set # CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set