diff --git a/components/connect/connect.c b/components/connect/connect.c index 36be658ad..79808011a 100644 --- a/components/connect/connect.c +++ b/components/connect/connect.c @@ -53,6 +53,8 @@ static const char * TAG = "wifi_station"; static int s_retry_num = 0; +static char * _ip_addr_str; + static void event_handler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data) { if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { @@ -75,8 +77,11 @@ static void event_handler(void * arg, esp_event_base_t event_base, int32_t event MINER_set_wifi_status(WIFI_RETRYING, s_retry_num); } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { + ip_event_got_ip_t * event = (ip_event_got_ip_t *) event_data; - ESP_LOGI(TAG, "Bitaxe ip:" IPSTR, IP2STR(&event->ip_info.ip)); + snprintf(_ip_addr_str, IP4ADDR_STRLEN_MAX, IPSTR, IP2STR(&event->ip_info.ip)); + + ESP_LOGI(TAG, "Bitaxe ip: %s", _ip_addr_str); s_retry_num = 0; xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); MINER_set_wifi_status(WIFI_CONNECTED, 0); @@ -194,8 +199,10 @@ esp_netif_t * wifi_init_sta(const char * wifi_ssid, const char * wifi_pass) return esp_netif_sta; } -void wifi_init(const char * wifi_ssid, const char * wifi_pass, const char * hostname) +void wifi_init(const char * wifi_ssid, const char * wifi_pass, const char * hostname, char * ip_addr_str) { + _ip_addr_str = ip_addr_str; + s_wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_netif_init()); diff --git a/components/connect/include/connect.h b/components/connect/include/connect.h index bd0b97564..f23bc923e 100644 --- a/components/connect/include/connect.h +++ b/components/connect/include/connect.h @@ -32,6 +32,6 @@ typedef enum void toggle_wifi_softap(void); void wifi_softap_on(void); void wifi_softap_off(void); -void wifi_init(const char * wifi_ssid, const char * wifi_pass, const char * hostname); +void wifi_init(const char * wifi_ssid, const char * wifi_pass, const char * hostname, char * ip_addr_str); EventBits_t wifi_connect(void); void generate_ssid(char * ssid); diff --git a/main/display.c b/main/display.c index 05ddae1da..6fabd774e 100644 --- a/main/display.c +++ b/main/display.c @@ -10,6 +10,7 @@ #include "lvgl.h" #include "lvgl__lvgl/src/themes/lv_theme_private.h" #include "esp_lvgl_port.h" +#include "global_state.h" #include "nvs_config.h" #include "i2c_bitaxe.h" #include "driver/i2c_master.h" @@ -23,8 +24,6 @@ #define LCD_CMD_BITS 8 #define LCD_PARAM_BITS 8 -static bool is_display_active = false; - static const char * TAG = "display"; static lv_theme_t theme; @@ -38,8 +37,10 @@ static void theme_apply(lv_theme_t *theme, lv_obj_t *obj) { } } -esp_err_t display_init(void) +esp_err_t display_init(void * pvParameters) { + GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters; + uint8_t flip_screen = nvs_config_get_u16(NVS_CONFIG_FLIP_SCREEN, 1); uint8_t invert_screen = nvs_config_get_u16(NVS_CONFIG_INVERT_SCREEN, 0); @@ -116,12 +117,7 @@ esp_err_t display_init(void) // Only turn on the screen when it has been cleared ESP_RETURN_ON_ERROR(esp_lcd_panel_disp_on_off(panel_handle, true), TAG, "Panel display on failed"); - is_display_active = true; + GLOBAL_STATE->SYSTEM_MODULE.is_screen_active = true; return ESP_OK; } - -bool display_active(void) -{ - return is_display_active; -} diff --git a/main/display.h b/main/display.h index 035168ff1..456466195 100644 --- a/main/display.h +++ b/main/display.h @@ -1,7 +1,6 @@ #ifndef DISPLAY_H_ #define DISPLAY_H_ -esp_err_t display_init(void); -bool display_active(void); +esp_err_t display_init(void * pvParameters); #endif /* DISPLAY_H_ */ \ No newline at end of file diff --git a/main/global_state.h b/main/global_state.h index a154074e9..682e0c327 100644 --- a/main/global_state.h +++ b/main/global_state.h @@ -68,6 +68,7 @@ typedef struct bool startup_done; char ssid[32]; char wifi_status[20]; + char ip_addr_str[16]; // IP4ADDR_STRLEN_MAX char ap_ssid[32]; char * pool_url; char * fallback_pool_url; @@ -76,13 +77,15 @@ typedef struct bool is_using_fallback; uint16_t overheat_mode; uint32_t lastClockSync; + bool is_screen_active; } SystemModule; typedef struct { - bool running; + bool active; char *message; bool result; + bool finished; } SelfTestModule; typedef struct diff --git a/main/input.c b/main/input.c index 3c3d8b04b..74b43afbd 100644 --- a/main/input.c +++ b/main/input.c @@ -16,6 +16,8 @@ static const char * TAG = "input"; static lv_indev_state_t button_state = LV_INDEV_STATE_RELEASED; static lv_point_t points[] = { {0, 0} }; // must be static +static void (*button_long_pressed)(void) = NULL; + static void button_read(lv_indev_t *indev, lv_indev_data_t *data) { data->key = LV_KEY_ENTER; @@ -28,20 +30,24 @@ static void IRAM_ATTR button_isr_handler(void *arg) button_state = pressed ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; } -static void button_short_clicked(lv_event_t *e) +static void button_short_clicked_event_cb(lv_event_t *e) { ESP_LOGI(TAG, "Short button press detected, switching to next screen"); screen_next(); } -static void button_long_pressed(lv_event_t *e) +static void button_long_pressed_event_cb(lv_event_t *e) { - ESP_LOGI(TAG, "Long button press detected, toggling WiFi SoftAP"); - toggle_wifi_softap(); + if (button_long_pressed != NULL) { + ESP_LOGI(TAG, "Long button press detected"); + button_long_pressed(); + } } -esp_err_t input_init(void) +esp_err_t input_init(void (*button_long_pressed_cb)(void)) { + button_long_pressed = button_long_pressed_cb; + // Button handling gpio_config_t io_conf = { .pin_bit_mask = (1ULL << BUTTON_BOOT_GPIO), @@ -61,8 +67,8 @@ esp_err_t input_init(void) lv_indev_set_long_press_time(indev, LONG_PRESS_DURATION_MS); lv_indev_set_read_cb(indev, button_read); lv_indev_set_button_points(indev, points); - lv_indev_add_event_cb(indev, button_short_clicked, LV_EVENT_SHORT_CLICKED, NULL); - lv_indev_add_event_cb(indev, button_long_pressed, LV_EVENT_LONG_PRESSED, NULL); + lv_indev_add_event_cb(indev, button_short_clicked_event_cb, LV_EVENT_SHORT_CLICKED, NULL); + lv_indev_add_event_cb(indev, button_long_pressed_event_cb, LV_EVENT_LONG_PRESSED, NULL); return ESP_OK; } diff --git a/main/input.h b/main/input.h index cdc382b2b..afbd69592 100644 --- a/main/input.h +++ b/main/input.h @@ -1,6 +1,6 @@ #ifndef INPUT_H_ #define INPUT_H_ -esp_err_t input_init(void); +esp_err_t input_init(void (*button_long_pressed_cb)(void)); #endif /* INPUT_H_ */ \ No newline at end of file diff --git a/main/main.c b/main/main.c index 30f7905e6..ab790c191 100644 --- a/main/main.c +++ b/main/main.c @@ -59,7 +59,7 @@ void app_main(void) //should we run the self test? if (should_test(&GLOBAL_STATE)) { self_test((void *) &GLOBAL_STATE); - vTaskDelay(60 * 60 * 1000 / portTICK_PERIOD_MS); + return; } SYSTEM_init_system(&GLOBAL_STATE); @@ -74,7 +74,7 @@ void app_main(void) GLOBAL_STATE.SYSTEM_MODULE.ssid[sizeof(GLOBAL_STATE.SYSTEM_MODULE.ssid)-1] = 0; // init and connect to wifi - wifi_init(wifi_ssid, wifi_pass, hostname); + wifi_init(wifi_ssid, wifi_pass, hostname, GLOBAL_STATE.SYSTEM_MODULE.ip_addr_str); generate_ssid(GLOBAL_STATE.SYSTEM_MODULE.ap_ssid); diff --git a/main/screen.c b/main/screen.c index 6cfe6a964..839b2cafe 100644 --- a/main/screen.c +++ b/main/screen.c @@ -1,16 +1,12 @@ #include "esp_log.h" #include "esp_err.h" #include "esp_check.h" -#include "esp_event.h" -#include "esp_netif.h" #include "lvgl.h" #include "esp_lvgl_port.h" #include "global_state.h" -#include "display.h" #include "screen.h" -#include "lwip/lwip_napt.h" -static const char * TAG = "screen"; +// static const char * TAG = "screen"; extern const lv_img_dsc_t logo; @@ -21,14 +17,14 @@ static TickType_t current_screen_counter; static GlobalState * GLOBAL_STATE; -static char ip_address_str[IP4ADDR_STRLEN_MAX]; - static lv_obj_t *hashrate_label; static lv_obj_t *efficiency_label; static lv_obj_t *difficulty_label; static lv_obj_t *chip_temp_label; -static lv_obj_t *self_test_labels[2]; +static lv_obj_t *self_test_message_label; +static lv_obj_t *self_test_result_label; +static lv_obj_t *self_test_finished_label; static double current_hashrate; static float current_power; @@ -36,18 +32,27 @@ static uint64_t current_difficulty; static float curreny_chip_temp; #define SCREEN_UPDATE_MS 500 -#define LOGO_DELAY_COUNT 5000/SCREEN_UPDATE_MS +#define LOGO_DELAY_COUNT 5000 / SCREEN_UPDATE_MS #define CAROUSEL_DELAY_COUNT 10000 / SCREEN_UPDATE_MS -static lv_obj_t * create_scr_self_test(SystemModule * module) { +static lv_obj_t * create_scr_self_test() { lv_obj_t * scr = lv_obj_create(NULL); lv_obj_set_flex_flow(scr, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); + lv_obj_t *label1 = lv_label_create(scr); lv_label_set_text(label1, "BITAXE SELF TEST"); - self_test_labels[0] = lv_label_create(scr); - self_test_labels[1] = lv_label_create(scr); + + self_test_message_label = lv_label_create(scr); + + self_test_result_label = lv_label_create(scr); + + self_test_finished_label = lv_label_create(scr); + lv_obj_set_width(self_test_finished_label, LV_HOR_RES); + lv_obj_add_flag(self_test_finished_label, LV_OBJ_FLAG_HIDDEN); + lv_label_set_long_mode(self_test_finished_label, LV_LABEL_LONG_SCROLL_CIRCULAR); + lv_label_set_text(self_test_finished_label, "Self test finished. Press BOOT button for 2 seconds to reset self test status and reboot the device."); return scr; } @@ -57,15 +62,20 @@ static lv_obj_t * create_scr_overheat(SystemModule * module) { lv_obj_set_flex_flow(scr, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); + lv_obj_t *label1 = lv_label_create(scr); lv_label_set_text(label1, "DEVICE OVERHEAT!"); + lv_obj_t *label2 = lv_label_create(scr); - lv_label_set_text(label2, "Power, frequency and fan configurations have been reset. Go to AxeOS to reconfigure device."); + lv_obj_set_width(label2, LV_HOR_RES); lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR); + lv_label_set_text(label2, "Power, frequency and fan configurations have been reset. Go to AxeOS to reconfigure device."); + lv_obj_t *label3 = lv_label_create(scr); lv_label_set_text(label3, "Device IP:"); + lv_obj_t *label4 = lv_label_create(scr); - lv_label_set_text_static(label4, ip_address_str); + lv_label_set_text_static(label4, module->ip_addr_str); return scr; } @@ -75,11 +85,15 @@ static lv_obj_t * create_scr_configure(SystemModule * module) { lv_obj_set_flex_flow(scr, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); + lv_obj_t *label1 = lv_label_create(scr); - lv_label_set_text(label1, "Welcome to your new BitAxe! Connect to the configuration Wifi and connect the BitAxe to your network."); + lv_obj_set_width(label1, LV_HOR_RES); lv_label_set_long_mode(label1, LV_LABEL_LONG_SCROLL_CIRCULAR); + lv_label_set_text(label1, "Welcome to your new BitAxe! Connect to the configuration Wifi and connect the BitAxe to your network."); + lv_obj_t *label2 = lv_label_create(scr); lv_label_set_text(label2, "Configuration SSID:"); + lv_obj_t *label3 = lv_label_create(scr); lv_label_set_text(label3, module->ap_ssid); @@ -118,19 +132,25 @@ static lv_obj_t * create_scr_urls(SystemModule * module) { lv_obj_set_flex_flow(scr, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); + lv_obj_t *label1 = lv_label_create(scr); lv_label_set_text(label1, "Mining URL:"); + lv_obj_t *label2 = lv_label_create(scr); + lv_obj_set_width(label2, LV_HOR_RES); + lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR); lv_label_set_text(label2, module->is_using_fallback ? module->fallback_pool_url : module->pool_url); + lv_obj_t *label3 = lv_label_create(scr); lv_label_set_text(label3, "Bitaxe IP:"); + lv_obj_t *label4 = lv_label_create(scr); - lv_label_set_text_static(label4, ip_address_str); + lv_label_set_text_static(label4, module->ip_addr_str); return scr; } -static lv_obj_t * create_scr_stats(SystemModule * module, PowerManagementModule * power_management) { +static lv_obj_t * create_scr_stats() { lv_obj_t * scr = lv_obj_create(NULL); lv_obj_set_flex_flow(scr, LV_FLEX_FLOW_COLUMN); @@ -138,10 +158,13 @@ static lv_obj_t * create_scr_stats(SystemModule * module, PowerManagementModule hashrate_label = lv_label_create(scr); lv_label_set_text(hashrate_label, "Gh/s: n/a"); + efficiency_label = lv_label_create(scr); lv_label_set_text(efficiency_label, "J/Th: n/a"); + difficulty_label = lv_label_create(scr); lv_label_set_text(difficulty_label, "Best: n/a"); + chip_temp_label = lv_label_create(scr); lv_label_set_text(chip_temp_label, "Temp: n/a"); @@ -165,20 +188,19 @@ static void screen_show(screen_t screen) static void screen_update_cb(lv_timer_t * timer) { - SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - PowerManagementModule * power_management = &GLOBAL_STATE->POWER_MANAGEMENT_MODULE; + if (GLOBAL_STATE->SELF_TEST_MODULE.active) { - if (module->overheat_mode == 1) { - screen_show(SCR_OVERHEAT); - return; - } - - if (GLOBAL_STATE->SELF_TEST_MODULE.running) { screen_show(SCR_SELF_TEST); - return; - } - if (current_screen == SCR_SELF_TEST) { + SelfTestModule * self_test = &GLOBAL_STATE->SELF_TEST_MODULE; + + lv_label_set_text(self_test_message_label, self_test->message); + + if (self_test->finished) { + lv_label_set_text(self_test_result_label, self_test->result ? "TESTS PASS!" : "TESTS FAIL!"); + + lv_obj_remove_flag(self_test_finished_label, LV_OBJ_FLAG_HIDDEN); + } return; } @@ -189,6 +211,14 @@ static void screen_update_cb(lv_timer_t * timer) return; } + SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; + + if (module->overheat_mode == 1) { + screen_show(SCR_OVERHEAT); + + return; + } + if (module->ssid[0] == '\0') { screen_show(SCR_CONFIGURE); return; @@ -222,6 +252,8 @@ static void screen_update_cb(lv_timer_t * timer) // Carousel + PowerManagementModule * power_management = &GLOBAL_STATE->POWER_MANAGEMENT_MODULE; + if (current_hashrate != module->current_hashrate) { lv_label_set_text_fmt(hashrate_label, "Gh/s: %.2f", module->current_hashrate); } @@ -257,49 +289,24 @@ void screen_next() } } -static void ip_event_handler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data) -{ - if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { - ip_event_got_ip_t * event = (ip_event_got_ip_t *) event_data; - esp_ip4addr_ntoa(&event->ip_info.ip, ip_address_str, IP4ADDR_STRLEN_MAX); - } -} - esp_err_t screen_start(void * pvParameters) { GLOBAL_STATE = (GlobalState *) pvParameters; - if (display_active()) { + if (GLOBAL_STATE->SYSTEM_MODULE.is_screen_active) { SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - PowerManagementModule * power_management = &GLOBAL_STATE->POWER_MANAGEMENT_MODULE; - screens[SCR_SELF_TEST] = create_scr_self_test(module); + screens[SCR_SELF_TEST] = create_scr_self_test(); screens[SCR_OVERHEAT] = create_scr_overheat(module); screens[SCR_CONFIGURE] = create_scr_configure(module); screens[SCR_CONNECTION] = create_scr_connection(module); screens[SCR_LOGO] = create_scr_logo(); screens[SCR_URLS] = create_scr_urls(module); - screens[SCR_STATS] = create_scr_stats(module, power_management); + screens[SCR_STATS] = create_scr_stats(); lv_timer_create(screen_update_cb, SCREEN_UPDATE_MS, NULL); - - esp_event_handler_instance_t instance_got_ip; - ESP_RETURN_ON_ERROR(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL, &instance_got_ip), TAG, "Error registering IP event handler"); } return ESP_OK; } -// TODO: Transition code until self test code is revamped -void display_show_status(const char *messages[], size_t message_count) -{ - if (lvgl_port_lock(0)) { - - screen_show(SCR_SELF_TEST); - // messages[0] is ignored, it's already on the screen - lv_label_set_text(self_test_labels[0], messages[1]); - lv_label_set_text(self_test_labels[1], messages[2]); - lvgl_port_unlock(); - } -} - diff --git a/main/screen.h b/main/screen.h index 55214df84..1d585d267 100644 --- a/main/screen.h +++ b/main/screen.h @@ -17,6 +17,5 @@ typedef enum { esp_err_t screen_start(void * pvParameters); void screen_next(void); -void display_show_status(const char *messages[], size_t message_count); #endif /* SCREEN_H_ */ \ No newline at end of file diff --git a/main/self_test/self_test.c b/main/self_test/self_test.c index 816e1189d..52a676c5d 100644 --- a/main/self_test/self_test.c +++ b/main/self_test/self_test.c @@ -22,18 +22,9 @@ #include "utils.h" #include "TPS546.h" - -#define BUTTON_BOOT GPIO_NUM_0 -#define LONG_PRESS_DURATION_MS 2000 // Define what constitutes a long press -#define ESP_INTR_FLAG_DEFAULT 0 //wtf is this for esp-idf? - #define TESTS_FAILED 0 #define TESTS_PASSED 1 -// Define event bits -#define EVENT_SHORT_PRESS 1 -#define EVENT_LONG_PRESS 2 - /////Test Constants///// //Test Fan Speed #define FAN_SPEED_TARGET_MIN 1000 //RPM @@ -54,19 +45,10 @@ // #define HASHRATE_TARGET_ULTRA 1000 //GH/s // #define HASHRATE_TARGET_MAX 2000 //GH/s - static const char * TAG = "self_test"; -const char *messages[] = {"", "", "", ""}; - -// Create an event group -EventGroupHandle_t xTestsEventGroup; -TimerHandle_t xButtonTimer; -bool button_pressed = false; //local function prototypes static void tests_done(GlobalState * GLOBAL_STATE, bool test_result); -static void configure_button_boot_interrupt(void); -void vButtonTimerCallback(TimerHandle_t xTimer); bool should_test(GlobalState * GLOBAL_STATE) { bool is_max = GLOBAL_STATE->asic_model == ASIC_BM1397; @@ -78,20 +60,15 @@ bool should_test(GlobalState * GLOBAL_STATE) { return false; } +static void reset_self_test() { + ESP_LOGI(TAG, "Long press detected, resetting self test flag and rebooting..."); + nvs_config_set_u16(NVS_CONFIG_SELF_TEST, 0); + esp_restart(); +} + static void display_msg(char * msg, GlobalState * GLOBAL_STATE) { - switch (GLOBAL_STATE->device_model) { - case DEVICE_MAX: - case DEVICE_ULTRA: - case DEVICE_SUPRA: - case DEVICE_GAMMA: - if (display_active()) { - messages[1] = msg; - display_show_status(messages, 4); - } - break; - default: - } + GLOBAL_STATE->SELF_TEST_MODULE.message = msg; } static esp_err_t test_fan_sense(GlobalState * GLOBAL_STATE) @@ -160,19 +137,19 @@ esp_err_t test_display(GlobalState * GLOBAL_STATE) { case DEVICE_ULTRA: case DEVICE_SUPRA: case DEVICE_GAMMA: - ESP_RETURN_ON_ERROR(display_init(), TAG, "DISPLAY init failed!"); + if (display_init(GLOBAL_STATE) != ESP_OK) { + display_msg("DISPLAY:FAIL", GLOBAL_STATE); + return ESP_FAIL; + } ESP_LOGI(TAG, "DISPLAY init success!"); - - messages[0] = "BITAXE SELF TESTING"; - display_show_status(messages, 4); - break; default: } return ESP_OK; } + esp_err_t test_input(GlobalState * GLOBAL_STATE) { // Input testing switch (GLOBAL_STATE->device_model) { @@ -180,13 +157,33 @@ esp_err_t test_input(GlobalState * GLOBAL_STATE) { case DEVICE_ULTRA: case DEVICE_SUPRA: case DEVICE_GAMMA: - ESP_RETURN_ON_ERROR(input_init(), TAG, "INPUT init failed!"); + if (input_init(reset_self_test) != ESP_OK) { + display_msg("INPUT:FAIL", GLOBAL_STATE); + return ESP_FAIL; + } ESP_LOGI(TAG, "INPUT init success!"); + break; + default: + } - messages[0] = "BITAXE SELF TESTING"; - display_show_status(messages, 4); + return ESP_OK; +} +esp_err_t test_screen(GlobalState * GLOBAL_STATE) { + // Screen testing + switch (GLOBAL_STATE->device_model) { + case DEVICE_MAX: + case DEVICE_ULTRA: + case DEVICE_SUPRA: + case DEVICE_GAMMA: + if (screen_start(GLOBAL_STATE) != ESP_OK) { + display_msg("SCREEN:FAIL", GLOBAL_STATE); + return ESP_FAIL; + } + + ESP_LOGI(TAG, "SCREEN start success!"); + break; default: } @@ -284,8 +281,6 @@ esp_err_t test_init_peripherals(GlobalState * GLOBAL_STATE) { return ESP_OK; } - - /** * @brief Perform a self-test of the system. * @@ -300,10 +295,7 @@ void self_test(void * pvParameters) ESP_LOGI(TAG, "Running Self Tests"); - //create the button timer for long press detection - xButtonTimer = xTimerCreate("ButtonTimer", pdMS_TO_TICKS(LONG_PRESS_DURATION_MS), pdFALSE, (void*)0, vButtonTimerCallback); - - configure_button_boot_interrupt(); + GLOBAL_STATE->SELF_TEST_MODULE.active = true; //Run display tests if (test_display(GLOBAL_STATE) != ESP_OK) { @@ -311,12 +303,18 @@ void self_test(void * pvParameters) tests_done(GLOBAL_STATE, TESTS_FAILED); } - //Run display tests + //Run input tests if (test_input(GLOBAL_STATE) != ESP_OK) { ESP_LOGE(TAG, "Input test failed!"); tests_done(GLOBAL_STATE, TESTS_FAILED); } + //Run screen tests + if (test_screen(GLOBAL_STATE) != ESP_OK) { + ESP_LOGE(TAG, "Screen test failed!"); + tests_done(GLOBAL_STATE, TESTS_FAILED); + } + //Init peripherals EMC2101 and INA260 (if present) if (test_init_peripherals(GLOBAL_STATE) != ESP_OK) { ESP_LOGE(TAG, "Peripherals init failed!"); @@ -359,7 +357,6 @@ void self_test(void * pvParameters) GLOBAL_STATE->valid_jobs = malloc(sizeof(uint8_t) * 128); for (int i = 0; i < 128; i++) { - GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[i] = NULL; GLOBAL_STATE->valid_jobs[i] = 0; } @@ -494,15 +491,11 @@ void self_test(void * pvParameters) tests_done(GLOBAL_STATE, TESTS_PASSED); ESP_LOGI(TAG, "Self Tests Passed!!!"); - return; - + return; } -static void tests_done(GlobalState * GLOBAL_STATE, bool test_result) { - - // Create event group for the System task - xTestsEventGroup = xEventGroupCreate(); - +static void tests_done(GlobalState * GLOBAL_STATE, bool test_result) +{ if (test_result == TESTS_PASSED) { ESP_LOGI(TAG, "SELF TESTS PASS -- Press RESET to continue"); } else { @@ -514,80 +507,12 @@ static void tests_done(GlobalState * GLOBAL_STATE, bool test_result) { case DEVICE_ULTRA: case DEVICE_SUPRA: case DEVICE_GAMMA: - if (display_active()) { - if (test_result == TESTS_PASSED) { - messages[2] = "TESTS PASS!"; - } else { - messages[2] = "TESTS FAIL!"; - } - messages[3] = "LONG PRESS BOOT"; - display_show_status(messages, 4); - } + GLOBAL_STATE->SELF_TEST_MODULE.result = test_result; + GLOBAL_STATE->SELF_TEST_MODULE.finished = true; break; default: } //wait here for a long press to reboot - while (1) { - - EventBits_t uxBits = xEventGroupWaitBits( - xTestsEventGroup, - EVENT_LONG_PRESS, - pdTRUE, // Clear bits on exit - pdFALSE, // Wait for any bit - portMAX_DELAY //wait forever - ); - - if (uxBits & EVENT_LONG_PRESS) { - ESP_LOGI(TAG, "Long press detected, rebooting"); - nvs_config_set_u16(NVS_CONFIG_SELF_TEST, 0); - esp_restart(); - } - - } -} - -void vButtonTimerCallback(TimerHandle_t xTimer) { - // Timer callback, set the long press event bit - xEventGroupSetBits(xTestsEventGroup, EVENT_LONG_PRESS); + vTaskDelay(portMAX_DELAY); } - -// Interrupt handler for BUTTON_BOOT -void IRAM_ATTR button_boot_isr_handler(void* arg) { - if (gpio_get_level(BUTTON_BOOT) == 0) { - // Button pressed, start the timer - if (!button_pressed) { - button_pressed = true; - xTimerStartFromISR(xButtonTimer, NULL); - } - } else { - // Button released, stop the timer and check the duration - if (button_pressed) { - button_pressed = false; - if (xTimerIsTimerActive(xButtonTimer)) { - xTimerStopFromISR(xButtonTimer, NULL); - //xEventGroupSetBitsFromISR(xTestsEventGroup, EVENT_SHORT_PRESS, NULL); //we don't care about a short press - } - } - } -} - -static void configure_button_boot_interrupt(void) { - // Configure the GPIO pin as input - gpio_config_t io_conf = { - .intr_type = GPIO_INTR_ANYEDGE, // Interrupt on both edges - .mode = GPIO_MODE_INPUT, // Set as input mode - .pin_bit_mask = (1ULL << BUTTON_BOOT), // Bit mask of the pin to configure - .pull_down_en = GPIO_PULLDOWN_DISABLE, // Disable pull-down mode - .pull_up_en = GPIO_PULLUP_ENABLE, // Enable pull-up mode - }; - gpio_config(&io_conf); - - // Install the ISR service - gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT); - - // Attach the interrupt handler - gpio_isr_handler_add(BUTTON_BOOT, button_boot_isr_handler, NULL); - - ESP_LOGI(TAG, "BUTTON_BOOT interrupt configured"); -} \ No newline at end of file diff --git a/main/system.c b/main/system.c index 3b5c6f4c5..d5d1254a9 100644 --- a/main/system.c +++ b/main/system.c @@ -128,23 +128,25 @@ void SYSTEM_init_peripherals(GlobalState * GLOBAL_STATE) { ESP_LOGE(TAG, "Failed to ensure overheat_mode config"); } - //Init the OLED + //Init the DISPLAY switch (GLOBAL_STATE->device_model) { case DEVICE_MAX: case DEVICE_ULTRA: case DEVICE_SUPRA: case DEVICE_GAMMA: - // oled - if (display_init() != ESP_OK) { + // display + if (display_init(GLOBAL_STATE) != ESP_OK) { ESP_LOGW(TAG, "OLED init failed!"); } else { ESP_LOGI(TAG, "OLED init success!"); + + GLOBAL_STATE->SYSTEM_MODULE.is_screen_active = true; } break; default: } - if (input_init() != ESP_OK) { + if (input_init(toggle_wifi_softap) != ESP_OK) { ESP_LOGW(TAG, "Input init failed!"); }