Add persistent OLED UI settings and recovery
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "board_pins.h"
|
||||
#include "driver/i2c_master.h"
|
||||
#include "esp_timer.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
@@ -21,6 +22,7 @@
|
||||
#define LOCAL_DISPLAY_DEFAULT_CONTRAST 127U
|
||||
#define LOCAL_DISPLAY_COMMAND_CAPACITY 32U
|
||||
#define LOCAL_DISPLAY_DATA_CHUNK_SIZE 128U
|
||||
#define LOCAL_DISPLAY_FLUSH_BUDGET_US (500LL * 1000LL)
|
||||
|
||||
static const uint8_t s_expected_addresses[] = {0x3cU, 0x3dU};
|
||||
|
||||
@@ -172,6 +174,7 @@ static esp_err_t flush_dirty_locked(void)
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
int64_t started = esp_timer_get_time();
|
||||
uint8_t transfer[LOCAL_DISPLAY_DATA_CHUNK_SIZE + 1U];
|
||||
transfer[0] = 0x40U;
|
||||
for (uint8_t page = 0U; page < LOCAL_DISPLAY_PAGE_COUNT; ++page) {
|
||||
@@ -179,6 +182,9 @@ static esp_err_t flush_dirty_locked(void)
|
||||
if ((s_dirty_pages & page_mask) == 0U) {
|
||||
continue;
|
||||
}
|
||||
if ((esp_timer_get_time() - started) >= LOCAL_DISPLAY_FLUSH_BUDGET_US) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
const uint8_t commands[] = {
|
||||
0x21U, 0x00U, (uint8_t)(LOCAL_DISPLAY_WIDTH - 1U),
|
||||
@@ -188,6 +194,9 @@ static esp_err_t flush_dirty_locked(void)
|
||||
if (error != ESP_OK) {
|
||||
return error;
|
||||
}
|
||||
if ((esp_timer_get_time() - started) >= LOCAL_DISPLAY_FLUSH_BUDGET_US) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
memcpy(&transfer[1], &s_framebuffer[(size_t)page * LOCAL_DISPLAY_WIDTH],
|
||||
LOCAL_DISPLAY_WIDTH);
|
||||
error = i2c_master_transmit(s_device, transfer, sizeof(transfer),
|
||||
|
||||
Reference in New Issue
Block a user