diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 24e4c3a..3f407d9 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -9,7 +9,6 @@ SRCS "system.c" "work_queue.c" "./NvsManager/src/nvs_device.c" - "lv_font_portfolio-6x8.c" "./http_server/http_server.c" "./http_server/handler_ota_github.c" "./self_test/self_test.c" @@ -68,9 +67,6 @@ EMBED_FILES "http_server/ap_page.html" ) -idf_build_set_property(COMPILE_OPTIONS "-DLV_CONF_INCLUDE_SIMPLE=1" APPEND) -idf_build_set_property(COMPILE_OPTIONS "-DLV_CONF_PATH=\"${CMAKE_SOURCE_DIR}/main/lv_conf.h\"" APPEND) - set(WEB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/http_server/forge-os") if("$ENV{GITHUB_ACTIONS}" STREQUAL "true") diff --git a/main/HMI/inc/display.h b/main/HMI/inc/display.h deleted file mode 100644 index 9cdc5e9..0000000 --- a/main/HMI/inc/display.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef DISPLAY_H_ -#define DISPLAY_H_ - -esp_err_t display_init(void * pvParameters); - -#endif /* DISPLAY_H_ */ diff --git a/main/HMI/inc/input.h b/main/HMI/inc/input.h index 6dc95ac..68626b0 100644 --- a/main/HMI/inc/input.h +++ b/main/HMI/inc/input.h @@ -1,6 +1,8 @@ #ifndef INPUT_H_ #define INPUT_H_ +#include "esp_err.h" + esp_err_t input_init(void (*button_short_clicked_cb)(void), void (*button_long_pressed_cb)(void)); #endif /* INPUT_H_ */ diff --git a/main/HMI/inc/screen.h b/main/HMI/inc/screen.h deleted file mode 100644 index d10f0e2..0000000 --- a/main/HMI/inc/screen.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef SCREEN_H_ -#define SCREEN_H_ - -typedef enum { - SCR_SELF_TEST, - SCR_OVERHEAT, - SCR_ASIC_STATUS, - SCR_CONFIGURE, - SCR_FIRMWARE_UPDATE, - SCR_CONNECTION, - SCR_LOGO, - SCR_URLS, - SCR_STATS, - MAX_SCREENS, -} screen_t; - -#define SCR_CAROUSEL_START SCR_URLS -#define SCR_CAROUSEL_END SCR_STATS - -esp_err_t screen_start(void * pvParameters); -void screen_next(void); - -#endif /* SCREEN_H_ */ diff --git a/main/HMI/src/display.c b/main/HMI/src/display.c deleted file mode 100644 index 11b2571..0000000 --- a/main/HMI/src/display.c +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_timer.h" -#include "esp_lcd_panel_io.h" -#include "esp_lcd_panel_ops.h" -#include "esp_err.h" -#include "esp_log.h" -#include "esp_check.h" -#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_bitforge.h" -#include "driver/i2c_master.h" -#include "driver/i2c_types.h" -#include "esp_lcd_panel_ssd1306.h" - -#define SSD1306_I2C_ADDRESS 0x3C - -#define LCD_H_RES 128 -#define LCD_V_RES 32 -#define LCD_CMD_BITS 8 -#define LCD_PARAM_BITS 8 - -static const char * TAG = "display"; - -static lv_theme_t theme; -static lv_style_t scr_style; - -extern const lv_font_t lv_font_portfolio_6x8; - -static void theme_apply(lv_theme_t *theme, lv_obj_t *obj) { - if (lv_obj_get_parent(obj) == NULL) { - lv_obj_add_style(obj, &scr_style, LV_PART_MAIN); - } -} - -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); - - i2c_master_bus_handle_t i2c_master_bus_handle; - ESP_RETURN_ON_ERROR(i2c_bitforge_get_master_bus_handle(&i2c_master_bus_handle), TAG, "Failed to get i2c master bus handle"); - - ESP_LOGI(TAG, "Install panel IO"); - esp_lcd_panel_io_handle_t io_handle = NULL; - esp_lcd_panel_io_i2c_config_t io_config = { - .scl_speed_hz = I2C_BUS_SPEED_HZ, - .dev_addr = SSD1306_I2C_ADDRESS, - .control_phase_bytes = 1, - .lcd_cmd_bits = LCD_CMD_BITS, - .lcd_param_bits = LCD_PARAM_BITS, - .dc_bit_offset = 6 - }; - - ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(i2c_master_bus_handle, &io_config, &io_handle), TAG, "Failed to initialise i2c panel bus"); - - ESP_LOGI(TAG, "Install SSD1306 panel driver"); - esp_lcd_panel_handle_t panel_handle = NULL; - esp_lcd_panel_dev_config_t panel_config = { - .bits_per_pixel = 1, - .reset_gpio_num = -1, - }; - - esp_lcd_panel_ssd1306_config_t ssd1306_config = { - .height = LCD_V_RES, - }; - panel_config.vendor_config = &ssd1306_config; - - ESP_RETURN_ON_ERROR(esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle), TAG, "No display found"); - ESP_RETURN_ON_ERROR(esp_lcd_panel_reset(panel_handle), TAG, "Panel reset failed"); - esp_err_t esp_lcd_panel_init_err = esp_lcd_panel_init(panel_handle); - if (esp_lcd_panel_init_err != ESP_OK) { - ESP_LOGE(TAG, "Panel init failed, no display connected?"); - } else { - ESP_RETURN_ON_ERROR(esp_lcd_panel_invert_color(panel_handle, invert_screen), TAG, "Panel invert failed"); - // ESP_RETURN_ON_ERROR(esp_lcd_panel_mirror(panel_handle, false, false), TAG, "Panel mirror failed"); - } - - ESP_LOGI(TAG, "Initialize LVGL"); - - const lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG(); - ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "LVGL init failed"); - - const lvgl_port_display_cfg_t disp_cfg = { - .io_handle = io_handle, - .panel_handle = panel_handle, - .buffer_size = LCD_H_RES * LCD_V_RES, - .double_buffer = true, - .hres = LCD_H_RES, - .vres = LCD_V_RES, - .monochrome = true, - .color_format = LV_COLOR_FORMAT_RGB565, - .rotation = { - .swap_xy = false, - .mirror_x = !flip_screen, // The screen is not flipped, this is for backwards compatibility - .mirror_y = !flip_screen, - }, - .flags = { - .swap_bytes = false, - .sw_rotate = false, - } - }; - - lv_disp_t * disp = lvgl_port_add_disp(&disp_cfg); - - if (esp_lcd_panel_init_err == ESP_OK) { - - if (lvgl_port_lock(0)) { - lv_style_init(&scr_style); - lv_style_set_text_font(&scr_style, &lv_font_portfolio_6x8); - lv_style_set_bg_opa(&scr_style, LV_OPA_COVER); - - lv_theme_set_apply_cb(&theme, theme_apply); - - lv_display_set_theme(disp, &theme); - lvgl_port_unlock(); - } - - // 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"); - - GLOBAL_STATE->SYSTEM_MODULE.is_screen_active = true; - } else { - ESP_LOGW(TAG, "No display found."); - } - - return ESP_OK; -} diff --git a/main/HMI/src/input.c b/main/HMI/src/input.c index e26e222..c0c91fd 100644 --- a/main/HMI/src/input.c +++ b/main/HMI/src/input.c @@ -1,49 +1,81 @@ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" #include "esp_log.h" #include "esp_err.h" #include "esp_check.h" -#include "lvgl.h" -#include "esp_lvgl_port.h" +#include "esp_timer.h" #include "driver/gpio.h" #define GPIO_BUTTON_BOOT CONFIG_GPIO_BUTTON_BOOT #define LONG_PRESS_DURATION_MS 2000 +#define DEBOUNCE_MS 30 +#define POLL_INTERVAL_MS 20 static const char * TAG = "input"; -static lv_indev_state_t button_state = LV_INDEV_STATE_RELEASED; +static TaskHandle_t button_task_handle = NULL; static void (*button_short_clicked_fn)(void) = NULL; static void (*button_long_pressed_fn)(void) = NULL; -static void button_read(lv_indev_t *indev, lv_indev_data_t *data) +static bool button_is_pressed(void) { - data->key = LV_KEY_ENTER; - data->state = button_state; + return gpio_get_level(GPIO_BUTTON_BOOT) == 0; // LOW when pressed } -static void IRAM_ATTR button_isr_handler(void *arg) +static void IRAM_ATTR button_isr_handler(void *arg) { - bool pressed = gpio_get_level(GPIO_BUTTON_BOOT) == 0; // LOW when pressed - button_state = pressed ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; + BaseType_t higher_prio_task_woken = pdFALSE; + vTaskNotifyGiveFromISR(button_task_handle, &higher_prio_task_woken); + portYIELD_FROM_ISR(higher_prio_task_woken); } -static void button_short_clicked_event_cb(lv_event_t *e) +static void button_task(void *pvParameters) { - ESP_LOGI(TAG, "Short button click detected"); - button_short_clicked_fn(); -} + while (1) { + // Sleep until an edge wakes us up + ulTaskNotifyTake(pdTRUE, portMAX_DELAY); -static void button_long_pressed_event_cb(lv_event_t *e) -{ - ESP_LOGI(TAG, "Long button press detected"); - button_long_pressed_fn(); + vTaskDelay(pdMS_TO_TICKS(DEBOUNCE_MS)); + if (!button_is_pressed()) { + continue; // bounce or a release we already handled + } + + // Held down: fire the long press as soon as the threshold passes, like the + // ISR-free equivalent of LV_EVENT_LONG_PRESSED did + bool long_press_fired = false; + int64_t press_start = esp_timer_get_time(); + + while (button_is_pressed()) { + if (!long_press_fired && (esp_timer_get_time() - press_start) >= LONG_PRESS_DURATION_MS * 1000LL) { + long_press_fired = true; + if (button_long_pressed_fn != NULL) { + ESP_LOGI(TAG, "Long button press detected"); + button_long_pressed_fn(); + } + } + vTaskDelay(pdMS_TO_TICKS(POLL_INTERVAL_MS)); + } + + if (!long_press_fired && button_short_clicked_fn != NULL) { + ESP_LOGI(TAG, "Short button click detected"); + button_short_clicked_fn(); + } + + // Drop the edges the release bounce queued up while we were polling + vTaskDelay(pdMS_TO_TICKS(DEBOUNCE_MS)); + ulTaskNotifyTake(pdTRUE, 0); + } } esp_err_t input_init(void (*button_short_clicked_cb)(void), void (*button_long_pressed_cb)(void)) { ESP_LOGI(TAG, "Install button driver"); + button_short_clicked_fn = button_short_clicked_cb; + button_long_pressed_fn = button_long_pressed_cb; + // Button handling gpio_config_t io_conf = { .pin_bit_mask = (1ULL << GPIO_BUTTON_BOOT), @@ -51,29 +83,20 @@ esp_err_t input_init(void (*button_short_clicked_cb)(void), void (*button_long_p .pull_up_en = GPIO_PULLUP_ENABLE, .intr_type = GPIO_INTR_ANYEDGE }; - gpio_config(&io_conf); - - // Install ISR service and hook the interrupt handler - ESP_RETURN_ON_ERROR(gpio_isr_handler_add(GPIO_BUTTON_BOOT, button_isr_handler, NULL), TAG, "Error adding ISR handler"); + ESP_RETURN_ON_ERROR(gpio_config(&io_conf), TAG, "Button GPIO config failed"); - lv_group_t * group = lv_group_create(); - lv_group_set_default(group); - lv_group_add_obj(group, lv_obj_create(NULL)); // dummy screen for event handling, in case no display is attached - - // Create input device - lv_indev_t * indev = lv_indev_create(); - lv_indev_set_type(indev, LV_INDEV_TYPE_KEYPAD); - lv_indev_set_long_press_time(indev, LONG_PRESS_DURATION_MS); - lv_indev_set_read_cb(indev, button_read); - lv_indev_set_group(indev, group); - if (button_short_clicked_cb != NULL) { - button_short_clicked_fn = button_short_clicked_cb; - lv_indev_add_event_cb(indev, button_short_clicked_event_cb, LV_EVENT_SHORT_CLICKED, NULL); - } - if (button_long_pressed_cb != NULL) { - button_long_pressed_fn = button_long_pressed_cb; - lv_indev_add_event_cb(indev, button_long_pressed_event_cb, LV_EVENT_LONG_PRESSED, NULL); + // The ISR service is installed during peripheral init, but self test and normal + // boot get there by different paths, so tolerate it already being up + esp_err_t isr_service_err = gpio_install_isr_service(0); + if (isr_service_err != ESP_OK && isr_service_err != ESP_ERR_INVALID_STATE) { + ESP_RETURN_ON_ERROR(isr_service_err, TAG, "Error installing ISR service"); } + // Task has to exist before the ISR can notify it + ESP_RETURN_ON_FALSE(xTaskCreate(button_task, "button", 3072, NULL, 5, &button_task_handle) == pdPASS, + ESP_ERR_NO_MEM, TAG, "Failed to create button task"); + + ESP_RETURN_ON_ERROR(gpio_isr_handler_add(GPIO_BUTTON_BOOT, button_isr_handler, NULL), TAG, "Error adding ISR handler"); + return ESP_OK; } diff --git a/main/HMI/src/screen.c b/main/HMI/src/screen.c deleted file mode 100644 index 2f358a8..0000000 --- a/main/HMI/src/screen.c +++ /dev/null @@ -1,410 +0,0 @@ -#include -#include "esp_log.h" -#include "esp_err.h" -#include "esp_check.h" -#include "lvgl.h" -#include "esp_lvgl_port.h" -#include "global_state.h" -#include "screen.h" - -// static const char * TAG = "screen"; - -extern const lv_img_dsc_t logo; - -static lv_obj_t * screens[MAX_SCREENS]; - -static screen_t current_screen = -1; -static TickType_t current_screen_counter; - -static GlobalState * GLOBAL_STATE; - -static lv_obj_t *asic_status_label; - -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 *firmware_update_scr_filename_label; -static lv_obj_t *firmware_update_scr_status_label; -static lv_obj_t *ip_addr_scr_overheat_label; -static lv_obj_t *ip_addr_scr_urls_label; -static lv_obj_t *mining_url_scr_urls_label; -static lv_obj_t *wifi_status_label; - -static lv_obj_t *self_test_message_label; -static lv_obj_t *self_test_result_label; -static lv_obj_t *self_test_finished_label_pass; -static lv_obj_t *self_test_finished_label_fail; - -static double current_hashrate; -static float current_power; -static uint64_t current_difficulty; -static float current_chip_temp; -static bool found_block; - -#define SCREEN_UPDATE_MS 500 -#define LOGO_DELAY_COUNT 5000 / SCREEN_UPDATE_MS -#define CAROUSEL_DELAY_COUNT 10000 / SCREEN_UPDATE_MS - -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, "NANO SELF TEST"); - - self_test_message_label = lv_label_create(scr); - self_test_result_label = lv_label_create(scr); - - self_test_finished_label_pass = lv_label_create(scr); - lv_obj_set_width(self_test_finished_label_pass, LV_HOR_RES); - lv_obj_add_flag(self_test_finished_label_pass, LV_OBJ_FLAG_HIDDEN); - lv_label_set_long_mode(self_test_finished_label_pass, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_label_set_text(self_test_finished_label_pass, "Press RESET button to start Nano."); - - self_test_finished_label_fail = lv_label_create(scr); - lv_obj_set_width(self_test_finished_label_fail, LV_HOR_RES); - lv_obj_add_flag(self_test_finished_label_fail, LV_OBJ_FLAG_HIDDEN); - lv_label_set_long_mode(self_test_finished_label_fail, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_label_set_text(self_test_finished_label_fail, "Hold BOOT button for 2 seconds to cancel self test, or press RESET to run again."); - - return scr; -} - -static lv_obj_t * create_scr_overheat(SystemModule * module) { - 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, "DEVICE OVERHEAT!"); - - 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, "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:"); - - ip_addr_scr_overheat_label = lv_label_create(scr); - lv_label_set_text(ip_addr_scr_overheat_label, module->ip_addr_str); - - return scr; -} - -static lv_obj_t * create_scr_asic_status(SystemModule * module) { - 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, "ASIC STATUS:"); - - asic_status_label = lv_label_create(scr); - lv_label_set_long_mode(asic_status_label, LV_LABEL_LONG_SCROLL_CIRCULAR); - - return scr; -} - -static lv_obj_t * create_scr_configure(SystemModule * module) { - 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_obj_set_width(label1, LV_HOR_RES); - lv_obj_set_style_anim_duration(label1, 15000, LV_PART_MAIN); - lv_label_set_long_mode(label1, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_label_set_text(label1, "Welcome to your new Nano! Connect to the configuration Wi-Fi and connect the Nano to your network."); - - // skip a line, it looks nicer this way - lv_label_create(scr); - - lv_obj_t *label2 = lv_label_create(scr); - lv_label_set_text(label2, "Wi-Fi (for setup):"); - - lv_obj_t *label3 = lv_label_create(scr); - lv_label_set_text(label3, module->ap_ssid); - - return scr; -} - -static lv_obj_t * create_scr_ota(SystemModule * module) { - 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_obj_set_width(label1, LV_HOR_RES); - lv_label_set_text(label1, "Firmware update"); - - firmware_update_scr_filename_label = lv_label_create(scr); - - firmware_update_scr_status_label = lv_label_create(scr); - - return scr; -} - -static lv_obj_t * create_scr_connection(SystemModule * module) { - 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_obj_set_width(label1, LV_HOR_RES); - lv_label_set_long_mode(label1, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_label_set_text_fmt(label1, "Wi-Fi: %s", module->ssid); - - wifi_status_label = lv_label_create(scr); - lv_label_set_text(wifi_status_label, module->wifi_status); - - lv_obj_t *label3 = lv_label_create(scr); - lv_label_set_text(label3, "Wi-Fi (for setup):"); - - lv_obj_t *label4 = lv_label_create(scr); - lv_label_set_text(label4, module->ap_ssid); - - return scr; -} - -static lv_obj_t * create_scr_logo() { - lv_obj_t * scr = lv_obj_create(NULL); - - lv_obj_t *img = lv_img_create(scr); - lv_img_set_src(img, &logo); - lv_obj_align(img, LV_ALIGN_CENTER, 0, 0); - - return scr; -} - -static lv_obj_t * create_scr_urls(SystemModule * module) { - 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, "Stratum Host:"); - - mining_url_scr_urls_label = lv_label_create(scr); - lv_obj_set_width(mining_url_scr_urls_label, LV_HOR_RES); - lv_label_set_long_mode(mining_url_scr_urls_label, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_label_set_text(mining_url_scr_urls_label, module->is_using_fallback ? module->fallback_pool_url : module->pool_url); - - lv_obj_t *label3 = lv_label_create(scr); - lv_label_set_text(label3, "Nano IP:"); - - ip_addr_scr_urls_label = lv_label_create(scr); - lv_label_set_text(ip_addr_scr_urls_label, module->ip_addr_str); - - return scr; -} - -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); - lv_obj_set_flex_align(scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); - - hashrate_label = lv_label_create(scr); - lv_label_set_text(hashrate_label, "Gh/s: --"); - - efficiency_label = lv_label_create(scr); - lv_label_set_text(efficiency_label, "J/Th: --"); - - difficulty_label = lv_label_create(scr); - lv_label_set_text(difficulty_label, "Best: --"); - - chip_temp_label = lv_label_create(scr); - lv_label_set_text(chip_temp_label, "Temp: --"); - - return scr; -} - -static void screen_show(screen_t screen) -{ - if (current_screen != screen) { - lv_obj_t * scr = screens[screen]; - - if (scr && lvgl_port_lock(0)) { - lv_screen_load_anim(scr, LV_SCR_LOAD_ANIM_MOVE_LEFT, LV_DEF_REFR_PERIOD * 128 / 8, 0, false); - lvgl_port_unlock(); - } - - current_screen = screen; - current_screen_counter = 0; - } -} - -static void screen_update_cb(lv_timer_t * timer) -{ - if (GLOBAL_STATE->SELF_TEST_MODULE.active) { - - screen_show(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) { - if (self_test->result) { - lv_label_set_text(self_test_result_label, "TESTS PASS!"); - lv_obj_remove_flag(self_test_finished_label_pass, LV_OBJ_FLAG_HIDDEN); - } else { - lv_label_set_text(self_test_result_label, "TESTS FAIL!"); - lv_obj_remove_flag(self_test_finished_label_fail, LV_OBJ_FLAG_HIDDEN); - } - } - - return; - } - - if (GLOBAL_STATE->SYSTEM_MODULE.is_firmware_update) { - if (strcmp(GLOBAL_STATE->SYSTEM_MODULE.firmware_update_filename, lv_label_get_text(firmware_update_scr_filename_label)) != 0) { - lv_label_set_text(firmware_update_scr_filename_label, GLOBAL_STATE->SYSTEM_MODULE.firmware_update_filename); - } - if (strcmp(GLOBAL_STATE->SYSTEM_MODULE.firmware_update_status, lv_label_get_text(firmware_update_scr_status_label)) != 0) { - lv_label_set_text(firmware_update_scr_status_label, GLOBAL_STATE->SYSTEM_MODULE.firmware_update_status); - } - screen_show(SCR_FIRMWARE_UPDATE); - return; - } - - SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - - if (module->asic_status) { - lv_label_set_text(asic_status_label, module->asic_status); - screen_show(SCR_ASIC_STATUS); - return; - } - - if (module->overheat_mode == 1) { - if (strcmp(module->ip_addr_str, lv_label_get_text(ip_addr_scr_overheat_label)) != 0) { - lv_label_set_text(ip_addr_scr_overheat_label, module->ip_addr_str); - } - screen_show(SCR_OVERHEAT); - return; - } - - if (module->ssid[0] == '\0') { - screen_show(SCR_CONFIGURE); - return; - } - - if (module->ap_enabled) { - if (strcmp(module->wifi_status, lv_label_get_text(wifi_status_label)) != 0) { - lv_label_set_text(wifi_status_label, module->wifi_status); - } - screen_show(SCR_CONNECTION); - return; - } - - current_screen_counter++; - - // Logo - - if (current_screen < SCR_LOGO) { - screen_show(SCR_LOGO); - return; - } - - if (current_screen == SCR_LOGO) { - if (LOGO_DELAY_COUNT > current_screen_counter) { - return; - } - screen_show(SCR_CAROUSEL_START); - return; - } - - // Carousel - - PowerManagementModule * power_management = &GLOBAL_STATE->POWER_MANAGEMENT_MODULE; - - char *pool_url = module->is_using_fallback ? module->fallback_pool_url : module->pool_url; - if (strcmp(lv_label_get_text(mining_url_scr_urls_label), pool_url) != 0) { - lv_label_set_text(mining_url_scr_urls_label, pool_url); - } - - if (strcmp(lv_label_get_text(ip_addr_scr_urls_label), module->ip_addr_str) != 0) { - lv_label_set_text(ip_addr_scr_urls_label, module->ip_addr_str); - } - - if (current_hashrate != module->current_hashrate) { - lv_label_set_text_fmt(hashrate_label, "Gh/s: %.2f", module->current_hashrate); - } - - if (current_power != power_management->power || current_hashrate != module->current_hashrate) { - if (power_management->power > 0 && module->current_hashrate > 0) { - float efficiency = power_management->power / (module->current_hashrate / 1000.0); - lv_label_set_text_fmt(efficiency_label, "J/Th: %.2f", efficiency); - } - } - - if (module->FOUND_BLOCK && !found_block) { - found_block = true; - - lv_obj_set_width(difficulty_label, LV_HOR_RES); - lv_label_set_long_mode(difficulty_label, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_label_set_text_fmt(difficulty_label, "Best: %s !!! BLOCK FOUND !!!", module->best_session_diff_string); - - screen_show(SCR_STATS); - } else { - if (current_difficulty != module->best_session_nonce_diff) { - lv_label_set_text_fmt(difficulty_label, "Best: %s/%s", module->best_session_diff_string, module->best_diff_string); - } - } - - if (current_chip_temp != power_management->chip_temp_avg && power_management->chip_temp_avg > 0) { - lv_label_set_text_fmt(chip_temp_label, "Temp: %.1f C", power_management->chip_temp_avg); - } - - current_hashrate = module->current_hashrate; - current_power = power_management->power; - current_difficulty = module->best_session_nonce_diff; - current_chip_temp = power_management->chip_temp_avg; - - if (CAROUSEL_DELAY_COUNT > current_screen_counter || found_block) { - return; - } - - screen_next(); -} - -void screen_next() -{ - if (current_screen >= SCR_CAROUSEL_START) { - screen_show(current_screen == SCR_CAROUSEL_END ? SCR_CAROUSEL_START : current_screen + 1); - } -} - -esp_err_t screen_start(void * pvParameters) -{ - GLOBAL_STATE = (GlobalState *) pvParameters; - - if (GLOBAL_STATE->SYSTEM_MODULE.is_screen_active) { - SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - - screens[SCR_SELF_TEST] = create_scr_self_test(); - screens[SCR_OVERHEAT] = create_scr_overheat(module); - screens[SCR_ASIC_STATUS] = create_scr_asic_status(module); - screens[SCR_CONFIGURE] = create_scr_configure(module); - screens[SCR_FIRMWARE_UPDATE] = create_scr_ota(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(); - - lv_timer_create(screen_update_cb, SCREEN_UPDATE_MS, NULL); - } - - return ESP_OK; -} diff --git a/main/global_state.h b/main/global_state.h index 95ad777..1aeebf5 100644 --- a/main/global_state.h +++ b/main/global_state.h @@ -69,7 +69,6 @@ typedef struct uint64_t shares_rejected; RejectedReasonStat rejected_reason_stats[10]; int rejected_reason_stats_count; - int screen_page; uint64_t best_nonce_diff; char best_diff_string[DIFF_STRING_SIZE]; uint64_t best_session_nonce_diff; @@ -99,21 +98,12 @@ typedef struct uint16_t overheat_mode; uint16_t power_fault; uint32_t lastClockSync; - bool is_screen_active; bool is_firmware_update; char firmware_update_filename[20]; char firmware_update_status[20]; char * asic_status; } SystemModule; -typedef struct -{ - bool active; - char *message; - bool result; - bool finished; -} SelfTestModule; - typedef struct { esp_transport_handle_t transport; @@ -156,7 +146,6 @@ typedef struct AsicTaskModule ASIC_TASK_MODULE; PowerManagementModule POWER_MANAGEMENT_MODULE; HashrateMonitorModule HASHRATE_MONITOR_MODULE; - SelfTestModule SELF_TEST_MODULE; char * extranonce_str; int extranonce_2_len; diff --git a/main/http_server/openapi.yaml b/main/http_server/openapi.yaml index 1ecb254..018f2df 100644 --- a/main/http_server/openapi.yaml +++ b/main/http_server/openapi.yaml @@ -88,14 +88,12 @@ components: - fallbackStratumUser - fanrpm - fanSpeed - - flipscreen - freeHeap - frequency - hashRate - hostname - idfVersion - invertfanpolarity - - invertscreen - isPSRAMAvailable - isUsingFallbackStratum - macAddr @@ -162,9 +160,6 @@ components: fanSpeed: type: number description: Current fan speed percentage - flipscreen: - type: number - description: Screen flip setting (0=normal, 1=flipped) freeHeap: type: number description: Available heap memory in bytes @@ -183,9 +178,6 @@ components: invertfanpolarity: type: number description: Fan polarity setting (0=normal, 1=inverted) - invertscreen: - type: number - description: Screen invert setting (0=normal, 1=inverted) isPSRAMAvailable: type: number description: Whether PSRAM is available (0=no, 1=yes) @@ -329,24 +321,12 @@ components: minimum: 1 examples: - 450 - flipscreen: - type: integer - description: Whether to flip the screen orientation (0=normal, 1=flipped) - enum: [0, 1] - examples: - - 0 overheat_mode: type: integer description: Overheat protection mode (0=disabled) enum: [0] examples: - 0 - invertscreen: - type: integer - description: Whether to invert screen colors (0=normal, 1=inverted) - enum: [0, 1] - examples: - - 0 invertfanpolarity: type: integer description: Whether to invert fan polarity (0=normal, 1=inverted) diff --git a/main/idf_component.yml b/main/idf_component.yml index 0f7aea8..17b2cec 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -1,7 +1,5 @@ ## IDF Component Manager Manifest File dependencies: - lvgl/lvgl: "^9.3.0" - espressif/esp_lvgl_port: "^2.4.3" ## Required IDF version idf: version: ">=5.4.0" diff --git a/main/lv_conf.h b/main/lv_conf.h deleted file mode 100644 index 979297a..0000000 --- a/main/lv_conf.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef LV_CONF_H -#define LV_CONF_H - -#define LV_COLOR_DEPTH 1 - -#define LV_USE_OS LV_OS_FREERTOS - -#define LV_DRAW_SW_SUPPORT_RGB565A8 0 -#define LV_DRAW_SW_SUPPORT_RGB888 0 -#define LV_DRAW_SW_SUPPORT_XRGB8888 0 -#define LV_DRAW_SW_SUPPORT_ARGB8888 0 -#define LV_DRAW_SW_SUPPORT_L8 0 -#define LV_DRAW_SW_SUPPORT_AL88 0 -#define LV_DRAW_SW_SUPPORT_A8 0 - -#define LV_DRAW_SW_COMPLEX 0 - -#define LV_USE_FLOAT 1 - -#define LV_FONT_MONTSERRAT_14 0 - -#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(lv_font_portfolio_6x8) -#define LV_FONT_DEFAULT &lv_font_portfolio_6x8 - -#define LV_WIDGETS_HAS_DEFAULT_VALUE 0 - -#define LV_USE_ANIMIMG 0 -#define LV_USE_ARC 0 -#define LV_USE_BAR 0 -#define LV_USE_BUTTON 0 -#define LV_USE_BUTTONMATRIX 0 -#define LV_USE_CALENDAR 0 -#define LV_USE_CANVAS 0 -#define LV_USE_CHART 0 -#define LV_USE_CHECKBOX 0 -#define LV_USE_DROPDOWN 0 -#define LV_USE_IMAGEBUTTON 0 -#define LV_USE_KEYBOARD 0 -#define LV_USE_LED 0 -#define LV_USE_LINE 0 -#define LV_USE_LIST 0 -#define LV_USE_MENU 0 -#define LV_USE_MSGBOX 0 -#define LV_USE_ROLLER 0 -#define LV_USE_SCALE 0 -#define LV_USE_SLIDER 0 -#define LV_USE_SPAN 0 -#define LV_USE_SPINBOX 0 -#define LV_USE_SPINNER 0 -#define LV_USE_SWITCH 0 -#define LV_USE_TEXTAREA 0 -#define LV_USE_TABLE 0 -#define LV_USE_TABVIEW 0 -#define LV_USE_TILEVIEW 0 -#define LV_USE_WIN 0 - -#define LV_USE_THEME_DEFAULT 0 -#define LV_USE_THEME_SIMPLE 0 -#define LV_USE_THEME_MONO 0 - -#define LV_BUILD_EXAMPLES 0 - -#endif /* LV_CONF_H */ diff --git a/main/lv_font_portfolio-6x8.c b/main/lv_font_portfolio-6x8.c deleted file mode 100644 index 0571835..0000000 --- a/main/lv_font_portfolio-6x8.c +++ /dev/null @@ -1,505 +0,0 @@ -/******************************************************************************* - * Size: 8 px - * Bpp: 1 - * Opts: --font oldschool_pc_font_pack_v2.2_linux/ttf - Mx (mixed outline+bitmap)/Mx437_Portfolio_6x8.ttf --bpp 1 --size 8 --format lvgl --range 0x20-0x7F -o portfolio_6x8 - ******************************************************************************/ - -#ifdef __has_include - #if __has_include("lvgl.h") - #ifndef LV_LVGL_H_INCLUDE_SIMPLE - #define LV_LVGL_H_INCLUDE_SIMPLE - #endif - #endif -#endif - -#ifdef LV_LVGL_H_INCLUDE_SIMPLE - #include "lvgl.h" -#else - #include "lvgl/lvgl.h" -#endif - -#ifndef PORTFOLIO_6X8 -#define PORTFOLIO_6X8 1 -#endif - -#if PORTFOLIO_6X8 - -/*----------------- - * BITMAPS - *----------------*/ - -/*Store the image of the glyphs*/ -static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = { - /* U+0020 " " */ - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - - /* U+0021 "!" */ - 0x20, 0x82, 0x8, 0x20, 0x2, 0x0, - - /* U+0022 "\"" */ - 0x51, 0x45, 0x0, 0x0, 0x0, 0x0, - - /* U+0023 "#" */ - 0x51, 0x4f, 0x94, 0xf9, 0x45, 0x0, - - /* U+0024 "$" */ - 0x21, 0xe8, 0x1c, 0xb, 0xc2, 0x0, - - /* U+0025 "%" */ - 0xc3, 0x21, 0x8, 0x42, 0x61, 0x80, - - /* U+0026 "&" */ - 0x62, 0x4a, 0x10, 0xaa, 0x46, 0x80, - - /* U+0027 "'" */ - 0x30, 0x42, 0x0, 0x0, 0x0, 0x0, - - /* U+0028 "(" */ - 0x10, 0x84, 0x10, 0x40, 0x81, 0x0, - - /* U+0029 ")" */ - 0x40, 0x81, 0x4, 0x10, 0x84, 0x0, - - /* U+002A "*" */ - 0x0, 0x8a, 0x9c, 0xa8, 0x80, 0x0, - - /* U+002B "+" */ - 0x0, 0x82, 0x3e, 0x20, 0x80, 0x0, - - /* U+002C "," */ - 0x0, 0x0, 0x0, 0x30, 0x42, 0x0, - - /* U+002D "-" */ - 0x0, 0x0, 0x3e, 0x0, 0x0, 0x0, - - /* U+002E "." */ - 0x0, 0x0, 0x0, 0x0, 0xc3, 0x0, - - /* U+002F "/" */ - 0x0, 0x21, 0x8, 0x42, 0x0, 0x0, - - /* U+0030 "0" */ - 0x72, 0x29, 0xaa, 0xca, 0x27, 0x0, - - /* U+0031 "1" */ - 0x21, 0x82, 0x8, 0x20, 0x87, 0x0, - - /* U+0032 "2" */ - 0x72, 0x20, 0x84, 0x21, 0xf, 0x80, - - /* U+0033 "3" */ - 0xf8, 0x42, 0x4, 0xa, 0x27, 0x0, - - /* U+0034 "4" */ - 0x10, 0xc5, 0x24, 0xf8, 0x41, 0x0, - - /* U+0035 "5" */ - 0xfa, 0xf, 0x2, 0xa, 0x27, 0x0, - - /* U+0036 "6" */ - 0x31, 0x8, 0x3c, 0x8a, 0x27, 0x0, - - /* U+0037 "7" */ - 0xf8, 0x21, 0x8, 0x20, 0x82, 0x0, - - /* U+0038 "8" */ - 0x72, 0x28, 0x9c, 0x8a, 0x27, 0x0, - - /* U+0039 "9" */ - 0x72, 0x28, 0x9e, 0x8, 0x46, 0x0, - - /* U+003A ":" */ - 0x0, 0xc3, 0x0, 0x30, 0xc0, 0x0, - - /* U+003B ";" */ - 0x0, 0xc3, 0x0, 0x30, 0x42, 0x0, - - /* U+003C "<" */ - 0x8, 0x42, 0x10, 0x20, 0x40, 0x80, - - /* U+003D "=" */ - 0x0, 0xf, 0x80, 0xf8, 0x0, 0x0, - - /* U+003E ">" */ - 0x81, 0x2, 0x4, 0x21, 0x8, 0x0, - - /* U+003F "?" */ - 0x72, 0x20, 0x84, 0x20, 0x2, 0x0, - - /* U+0040 "@" */ - 0x72, 0x29, 0xaa, 0x92, 0x7, 0x0, - - /* U+0041 "A" */ - 0x72, 0x28, 0xa2, 0xfa, 0x28, 0x80, - - /* U+0042 "B" */ - 0xf2, 0x28, 0xbc, 0x8a, 0x2f, 0x0, - - /* U+0043 "C" */ - 0x72, 0x28, 0x20, 0x82, 0x27, 0x0, - - /* U+0044 "D" */ - 0xe2, 0x48, 0xa2, 0x8a, 0x4e, 0x0, - - /* U+0045 "E" */ - 0xfa, 0x8, 0x3c, 0x82, 0xf, 0x80, - - /* U+0046 "F" */ - 0xfa, 0x8, 0x3c, 0x82, 0x8, 0x0, - - /* U+0047 "G" */ - 0x72, 0x28, 0x20, 0xba, 0x27, 0x80, - - /* U+0048 "H" */ - 0x8a, 0x28, 0xbe, 0x8a, 0x28, 0x80, - - /* U+0049 "I" */ - 0x70, 0x82, 0x8, 0x20, 0x87, 0x0, - - /* U+004A "J" */ - 0x38, 0x41, 0x4, 0x12, 0x46, 0x0, - - /* U+004B "K" */ - 0x8a, 0x4a, 0x30, 0xa2, 0x48, 0x80, - - /* U+004C "L" */ - 0x82, 0x8, 0x20, 0x82, 0xf, 0x80, - - /* U+004D "M" */ - 0x8b, 0x6a, 0xaa, 0x8a, 0x28, 0x80, - - /* U+004E "N" */ - 0x8a, 0x2c, 0xaa, 0x9a, 0x28, 0x80, - - /* U+004F "O" */ - 0x72, 0x28, 0xa2, 0x8a, 0x27, 0x0, - - /* U+0050 "P" */ - 0xf2, 0x28, 0xbc, 0x82, 0x8, 0x0, - - /* U+0051 "Q" */ - 0x72, 0x28, 0xa2, 0xaa, 0x46, 0x80, - - /* U+0052 "R" */ - 0xf2, 0x28, 0xbc, 0xa2, 0x48, 0x80, - - /* U+0053 "S" */ - 0x72, 0x28, 0x1c, 0xa, 0x27, 0x0, - - /* U+0054 "T" */ - 0xf8, 0x82, 0x8, 0x20, 0x82, 0x0, - - /* U+0055 "U" */ - 0x8a, 0x28, 0xa2, 0x8a, 0x27, 0x0, - - /* U+0056 "V" */ - 0x8a, 0x28, 0xa2, 0x89, 0x42, 0x0, - - /* U+0057 "W" */ - 0x8a, 0x28, 0xaa, 0xab, 0x68, 0x80, - - /* U+0058 "X" */ - 0x8a, 0x25, 0x8, 0x52, 0x28, 0x80, - - /* U+0059 "Y" */ - 0x8a, 0x28, 0x9c, 0x20, 0x82, 0x0, - - /* U+005A "Z" */ - 0xf8, 0x21, 0x8, 0x42, 0xf, 0x80, - - /* U+005B "[" */ - 0x71, 0x4, 0x10, 0x41, 0x7, 0x0, - - /* U+005C "\\" */ - 0x2, 0x4, 0x8, 0x10, 0x20, 0x0, - - /* U+005D "]" */ - 0x70, 0x41, 0x4, 0x10, 0x47, 0x0, - - /* U+005E "^" */ - 0x21, 0x48, 0x80, 0x0, 0x0, 0x0, - - /* U+005F "_" */ - 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f, - - /* U+0060 "`" */ - 0x61, 0x2, 0x0, 0x0, 0x0, 0x0, - - /* U+0061 "a" */ - 0x0, 0x7, 0x2, 0x7a, 0x27, 0x80, - - /* U+0062 "b" */ - 0x82, 0xb, 0x32, 0x8a, 0x2f, 0x0, - - /* U+0063 "c" */ - 0x0, 0x7, 0x20, 0x82, 0x27, 0x0, - - /* U+0064 "d" */ - 0x8, 0x26, 0xa6, 0x8a, 0x27, 0x80, - - /* U+0065 "e" */ - 0x0, 0x7, 0x22, 0xfa, 0x7, 0x80, - - /* U+0066 "f" */ - 0x31, 0x24, 0x3c, 0x41, 0x4, 0x0, - - /* U+0067 "g" */ - 0x0, 0x7, 0xa2, 0x78, 0x27, 0x0, - - /* U+0068 "h" */ - 0x82, 0xb, 0x32, 0x8a, 0x28, 0x80, - - /* U+0069 "i" */ - 0x20, 0x6, 0x8, 0x20, 0x87, 0x0, - - /* U+006A "j" */ - 0x10, 0x3, 0x4, 0x12, 0x46, 0x0, - - /* U+006B "k" */ - 0x82, 0x8, 0xa4, 0xa3, 0x48, 0x80, - - /* U+006C "l" */ - 0x60, 0x82, 0x8, 0x20, 0x87, 0x0, - - /* U+006D "m" */ - 0x0, 0xd, 0x2a, 0xaa, 0x28, 0x80, - - /* U+006E "n" */ - 0x0, 0xb, 0x32, 0x8a, 0x28, 0x80, - - /* U+006F "o" */ - 0x0, 0x7, 0x22, 0x8a, 0x27, 0x0, - - /* U+0070 "p" */ - 0x0, 0xf, 0x22, 0xf2, 0x8, 0x0, - - /* U+0071 "q" */ - 0x0, 0x7, 0xa2, 0x78, 0x20, 0x80, - - /* U+0072 "r" */ - 0x0, 0xb, 0x32, 0x82, 0x8, 0x0, - - /* U+0073 "s" */ - 0x0, 0x7, 0xa0, 0x70, 0x2f, 0x0, - - /* U+0074 "t" */ - 0x41, 0xf, 0x10, 0x41, 0x23, 0x0, - - /* U+0075 "u" */ - 0x0, 0x8, 0xa2, 0x8a, 0x66, 0x80, - - /* U+0076 "v" */ - 0x0, 0x8, 0xa2, 0x89, 0x42, 0x0, - - /* U+0077 "w" */ - 0x0, 0x8, 0xa2, 0xaa, 0xa5, 0x0, - - /* U+0078 "x" */ - 0x0, 0x8, 0x94, 0x21, 0x48, 0x80, - - /* U+0079 "y" */ - 0x0, 0x8, 0xa2, 0x78, 0x2f, 0x0, - - /* U+007A "z" */ - 0x0, 0xf, 0x84, 0x21, 0xf, 0x80, - - /* U+007B "{" */ - 0x18, 0x82, 0x18, 0x20, 0x81, 0x80, - - /* U+007C "|" */ - 0x20, 0x82, 0x0, 0x20, 0x82, 0x0, - - /* U+007D "}" */ - 0xc0, 0x82, 0xc, 0x20, 0x8c, 0x0, - - /* U+007E "~" */ - 0x6a, 0xc0, 0x0, 0x0, 0x0, 0x0, - - /* U+007F "" */ - 0x0, 0x2, 0x14, 0x8b, 0xe0, 0x0 -}; - - -/*--------------------- - * GLYPH DESCRIPTION - *--------------------*/ - -static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { - {.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */, - {.bitmap_index = 0, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 6, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 12, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 18, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 24, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 30, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 36, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 42, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 48, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 54, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 60, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 66, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 72, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 78, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 84, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 90, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 96, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 102, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 108, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 114, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 120, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 126, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 132, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 138, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 144, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 150, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 156, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 162, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 168, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 174, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 180, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 186, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 192, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 198, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 204, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 210, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 216, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 222, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 228, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 234, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 240, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 246, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 252, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 258, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 264, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 270, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 276, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 282, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 288, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 294, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 300, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 306, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 312, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 318, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 324, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 330, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 336, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 342, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 348, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 354, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 360, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 366, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 372, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 378, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 384, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 390, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 396, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 402, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 408, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 414, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 420, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 426, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 432, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 438, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 444, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 450, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 456, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 462, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 468, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 474, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 480, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 486, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 492, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 498, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 504, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 510, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 516, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 522, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 528, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 534, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 540, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 546, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 552, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 558, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 564, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 570, .adv_w = 96, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = -1} -}; - -/*--------------------- - * CHARACTER MAPPING - *--------------------*/ - - - -/*Collect the unicode lists and glyph_id offsets*/ -static const lv_font_fmt_txt_cmap_t cmaps[] = -{ - { - .range_start = 32, .range_length = 96, .glyph_id_start = 1, - .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY - } -}; - - - -/*-------------------- - * ALL CUSTOM DATA - *--------------------*/ - -#if LVGL_VERSION_MAJOR == 8 -/*Store all the custom data of the font*/ -static lv_font_fmt_txt_glyph_cache_t cache; -#endif - -#if LVGL_VERSION_MAJOR >= 8 -static const lv_font_fmt_txt_dsc_t font_dsc = { -#else -static lv_font_fmt_txt_dsc_t font_dsc = { -#endif - .glyph_bitmap = glyph_bitmap, - .glyph_dsc = glyph_dsc, - .cmaps = cmaps, - .kern_dsc = NULL, - .kern_scale = 0, - .cmap_num = 1, - .bpp = 1, - .kern_classes = 0, - .bitmap_format = 0, -#if LVGL_VERSION_MAJOR == 8 - .cache = &cache -#endif -}; - - - -/*----------------- - * PUBLIC FONT - *----------------*/ - -/*Initialize a public general font descriptor*/ -#if LVGL_VERSION_MAJOR >= 8 -const lv_font_t lv_font_portfolio_6x8 = { -#else -lv_font_t lv_font_portfolio_6x8 = { -#endif - .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/ - .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/ - .line_height = 8, /*The maximum line height required by the font*/ - .base_line = 1, /*Baseline measured from the bottom of the line*/ -#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0) - .subpx = LV_FONT_SUBPX_NONE, -#endif -#if LV_VERSION_CHECK(7, 4, 0) || LVGL_VERSION_MAJOR >= 8 - .underline_position = 0, - .underline_thickness = 1, -#endif - .dsc = &font_dsc, /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */ -#if LV_VERSION_CHECK(8, 2, 0) || LVGL_VERSION_MAJOR >= 9 - .fallback = NULL, -#endif - .user_data = NULL, -}; - - - -#endif /*#if PORTFOLIO_6X8*/ - diff --git a/main/self_test/self_test.c b/main/self_test/self_test.c index 05bbc00..1ed4215 100644 --- a/main/self_test/self_test.c +++ b/main/self_test/self_test.c @@ -12,7 +12,6 @@ #include "adc.h" #include "nvs_config.h" #include "nvs_flash.h" -#include "display.h" #include "input.h" #include "vcore.h" #include "utils.h" @@ -33,8 +32,8 @@ * LED Pattern | Status | Cause * -------------------------|-------------------|---------------------------------- * LED1,LED2: ON BLINKING | PASS | All tests passed successfully - * LED1: ON, LED2: OFF | PERIPHERAL_FAILURE| PSRAM, Display, Input, or - * | | Peripheral initialization failed + * LED1: ON, LED2: OFF | PERIPHERAL_FAILURE| PSRAM, Input, or Peripheral + * | | initialization failed * LED1: OFF, LED2: ON | ASIC_FAILURE | ASIC detection, hashrate, or * | | reference voltage test failed * LED1: ON, LED2: ON | POWER_FAILURE | Voltage regulator or power @@ -120,16 +119,11 @@ bool production_test(GlobalState * GLOBAL_STATE) { return false; } -static void reset_self_test() { +static void reset_self_test(void) { ESP_LOGI(TAG, "Long press detected..."); xSemaphoreGive(BootSemaphore); } -static void display_msg(char * msg, GlobalState * GLOBAL_STATE) -{ - GLOBAL_STATE->SELF_TEST_MODULE.message = msg; -} - static esp_err_t test_fan_sense(GlobalState * GLOBAL_STATE) { uint16_t fan_speed_1 = 0; @@ -281,7 +275,6 @@ esp_err_t test_init_peripherals(GlobalState * GLOBAL_STATE) { esp_err_t test_psram(GlobalState * GLOBAL_STATE){ if(!esp_psram_is_initialized()) { ESP_LOGE(TAG, "No PSRAM available on ESP32!"); - //display_msg("PSRAM:FAIL", GLOBAL_STATE); return ESP_FAIL; } return ESP_OK; @@ -301,23 +294,27 @@ void execute_production_test(void * pvParameters) ESP_LOGI(TAG, "Running Self Tests"); - if (configure_led() != ESP_OK) { - ESP_LOGE(TAG, "LED config failed!"); - tests_done(GLOBAL_STATE, TESTS_FAILED, PERIPHERAL_FAILURE); - } - - GLOBAL_STATE->SELF_TEST_MODULE.active = true; - - // Create a binary semaphore + // Create a binary semaphore. Has to exist before the first tests_done() call, + // which blocks on it forever when a test fails. BootSemaphore = xSemaphoreCreateBinary(); - gpio_install_isr_service(0); - if (BootSemaphore == NULL) { ESP_LOGE(TAG, "Failed to create semaphore"); return; } + gpio_install_isr_service(0); + + // A long press on the boot button is the only way out of a failed self test + if (input_init(NULL, reset_self_test) != ESP_OK) { + ESP_LOGE(TAG, "Input init failed!"); + } + + if (configure_led() != ESP_OK) { + ESP_LOGE(TAG, "LED config failed!"); + tests_done(GLOBAL_STATE, TESTS_FAILED, PERIPHERAL_FAILURE); + } + //Run PSRAM test if(test_psram(GLOBAL_STATE) != ESP_OK) { ESP_LOGE(TAG, "NO PSRAM on device!"); @@ -383,9 +380,6 @@ void execute_production_test(void * pvParameters) //test for voltage regulator faults if (test_vreg_faults(GLOBAL_STATE) != ESP_OK) { ESP_LOGE(TAG, "VCORE check fault failed!"); - char error_buf[20]; - snprintf(error_buf, 20, "VCORE:PWR FAULT"); - //display_msg(error_buf, GLOBAL_STATE); tests_done(GLOBAL_STATE, TESTS_FAILED, POWER_FAILURE); } @@ -499,7 +493,7 @@ void execute_production_test(void * pvParameters) ESP_LOGI(TAG, "Hashrate: %.2f, Expected: %.2f", hashrate, expected_hashrate_ghs); if (hashrate < expected_hashrate_ghs) { - display_msg("HASHRATE:FAIL", GLOBAL_STATE); + ESP_LOGE(TAG, "Hashrate test failed!"); tests_done(GLOBAL_STATE, TESTS_FAILED, ASIC_FAILURE); } @@ -527,8 +521,6 @@ void execute_production_test(void * pvParameters) static void tests_done(GlobalState * GLOBAL_STATE, bool test_result, TEST_FAILED_CAUSE cause) { - GLOBAL_STATE->SELF_TEST_MODULE.result = test_result; - GLOBAL_STATE->SELF_TEST_MODULE.finished = true; Power_disable(GLOBAL_STATE); if (test_result == TESTS_FAILED) { diff --git a/main/system.c b/main/system.c index 0fb2e02..aaa57ef 100644 --- a/main/system.c +++ b/main/system.c @@ -24,8 +24,6 @@ #include "adc.h" #include "connect.h" #include "nvs_config.h" -#include "display.h" -#include "input.h" #include "vcore.h" #include "ThermalMonitoring.h" diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 42345a4..d8c8a76 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -11,7 +11,6 @@ CONFIG_HTTPD_MAX_URI_LEN=2048 CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y CONFIG_ESP_WIFI_11KV_SUPPORT=y CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096 -CONFIG_LV_CONF_SKIP=n CONFIG_BT_ENABLED=y CONFIG_BT_NIMBLE_ENABLED=y # CONFIG_BT_BLUEDROID_ENABLED is not set