Add exact display size to nvs, since it can vary

custom
jacqueline 1 year ago
parent edd5eecc14
commit 4cd3c187f9
  1. 15
      src/drivers/display.cpp
  2. 2
      src/drivers/display_init.cpp
  3. 3
      src/drivers/include/display_init.hpp
  4. 8
      src/drivers/include/nvs.hpp
  5. 21
      src/drivers/nvs.cpp
  6. 8
      src/system_fsm/booting.cpp
  7. 2
      src/ui/include/ui_fsm.hpp
  8. 16
      src/ui/ui_fsm.cpp

@ -39,9 +39,6 @@
[[maybe_unused]] static const char* kTag = "DISPLAY"; [[maybe_unused]] static const char* kTag = "DISPLAY";
// TODO(jacqueline): Encode width and height variations in the init data.
static const uint8_t kDisplayHeight = 128;
static const uint8_t kDisplayWidth = 160;
static const uint8_t kTransactionQueueSize = 2; static const uint8_t kTransactionQueueSize = 2;
static const gpio_num_t kDisplayDr = GPIO_NUM_33; static const gpio_num_t kDisplayDr = GPIO_NUM_33;
@ -51,9 +48,11 @@ static const gpio_num_t kDisplayCs = GPIO_NUM_22;
/* /*
* The size of each of our two display buffers. This is fundamentally a balance * The size of each of our two display buffers. This is fundamentally a balance
* between performance and memory usage. LVGL docs recommend a buffer 1/10th the * between performance and memory usage. LVGL docs recommend a buffer 1/10th the
* size of the screen is the best tradeoff * size of the screen is the best tradeoff.
8
* The 160x128 is the nominal size of our standard faceplate's display.
*/ */
static const int kDisplayBufferSize = kDisplayWidth * kDisplayHeight / 10; static const int kDisplayBufferSize = 160 * 128 / 10;
DMA_ATTR static lv_color_t kDisplayBuffer[kDisplayBufferSize]; DMA_ATTR static lv_color_t kDisplayBuffer[kDisplayBufferSize];
namespace drivers { namespace drivers {
@ -154,10 +153,8 @@ auto Display::Create(IGpios& expander,
lv_disp_drv_init(&display->driver_); lv_disp_drv_init(&display->driver_);
display->driver_.draw_buf = &display->buffers_; display->driver_.draw_buf = &display->buffers_;
display->driver_.hor_res = kDisplayWidth; display->driver_.hor_res = init_data.width;
display->driver_.ver_res = kDisplayHeight; display->driver_.ver_res = init_data.height;
// display->driver_.sw_rotate = 1;
// display->driver_.rotated = LV_DISP_ROT_270;
display->driver_.sw_rotate = 0; display->driver_.sw_rotate = 0;
display->driver_.rotated = LV_DISP_ROT_NONE; display->driver_.rotated = LV_DISP_ROT_NONE;
display->driver_.antialiasing = 0; display->driver_.antialiasing = 0;

@ -101,6 +101,8 @@ static const uint8_t kST7735RCommonFooter[]{
// clang-format on // clang-format on
const InitialisationData kST7735R = { const InitialisationData kST7735R = {
.width = 160,
.height = 128,
.num_sequences = 3, .num_sequences = 3,
.sequences = {kST7735RCommonHeader, kST7735RCommonGreen, .sequences = {kST7735RCommonHeader, kST7735RCommonGreen,
kST7735RCommonFooter}}; kST7735RCommonFooter}};

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <stdint.h>
#include <cstdint> #include <cstdint>
namespace drivers { namespace drivers {
@ -14,6 +15,8 @@ namespace displays {
extern const uint8_t kDelayBit; extern const uint8_t kDelayBit;
struct InitialisationData { struct InitialisationData {
uint16_t width;
uint16_t height;
uint8_t num_sequences; uint8_t num_sequences;
const uint8_t* sequences[4]; const uint8_t* sequences[4];
}; };

@ -71,6 +71,11 @@ class NvsStorage {
auto LockPolarity() -> bool; auto LockPolarity() -> bool;
auto LockPolarity(bool) -> void; auto LockPolarity(bool) -> void;
auto DisplaySize()
-> std::pair<std::optional<uint16_t>, std::optional<uint16_t>>;
auto DisplaySize(std::pair<std::optional<uint16_t>, std::optional<uint16_t>>)
-> void;
auto PreferredBluetoothDevice() -> std::optional<bluetooth::MacAndName>; auto PreferredBluetoothDevice() -> std::optional<bluetooth::MacAndName>;
auto PreferredBluetoothDevice(std::optional<bluetooth::MacAndName>) -> void; auto PreferredBluetoothDevice(std::optional<bluetooth::MacAndName>) -> void;
@ -120,6 +125,9 @@ class NvsStorage {
nvs_handle_t handle_; nvs_handle_t handle_;
Setting<uint8_t> lock_polarity_; Setting<uint8_t> lock_polarity_;
Setting<uint16_t> display_cols_;
Setting<uint16_t> display_rows_;
Setting<uint8_t> brightness_; Setting<uint8_t> brightness_;
Setting<uint8_t> sensitivity_; Setting<uint8_t> sensitivity_;
Setting<uint16_t> amp_max_vol_; Setting<uint16_t> amp_max_vol_;

@ -37,6 +37,8 @@ static constexpr char kKeyAmpLeftBias[] = "hp_bias";
static constexpr char kKeyPrimaryInput[] = "in_pri"; static constexpr char kKeyPrimaryInput[] = "in_pri";
static constexpr char kKeyScrollSensitivity[] = "scroll"; static constexpr char kKeyScrollSensitivity[] = "scroll";
static constexpr char kKeyLockPolarity[] = "lockpol"; static constexpr char kKeyLockPolarity[] = "lockpol";
static constexpr char kKeyDisplayCols[] = "dispcols";
static constexpr char kKeyDisplayRows[] = "disprows";
static auto nvs_get_string(nvs_handle_t nvs, const char* key) static auto nvs_get_string(nvs_handle_t nvs, const char* key)
-> std::optional<std::string> { -> std::optional<std::string> {
@ -161,6 +163,8 @@ auto NvsStorage::OpenSync() -> NvsStorage* {
NvsStorage::NvsStorage(nvs_handle_t handle) NvsStorage::NvsStorage(nvs_handle_t handle)
: handle_(handle), : handle_(handle),
lock_polarity_(kKeyLockPolarity), lock_polarity_(kKeyLockPolarity),
display_cols_(kKeyDisplayCols),
display_rows_(kKeyDisplayRows),
brightness_(kKeyBrightness), brightness_(kKeyBrightness),
sensitivity_(kKeyScrollSensitivity), sensitivity_(kKeyScrollSensitivity),
amp_max_vol_(kKeyAmpMaxVolume), amp_max_vol_(kKeyAmpMaxVolume),
@ -180,6 +184,8 @@ NvsStorage::~NvsStorage() {
auto NvsStorage::Read() -> void { auto NvsStorage::Read() -> void {
std::lock_guard<std::mutex> lock{mutex_}; std::lock_guard<std::mutex> lock{mutex_};
lock_polarity_.read(handle_); lock_polarity_.read(handle_);
display_cols_.read(handle_);
display_rows_.read(handle_);
brightness_.read(handle_); brightness_.read(handle_);
sensitivity_.read(handle_); sensitivity_.read(handle_);
amp_max_vol_.read(handle_); amp_max_vol_.read(handle_);
@ -194,6 +200,8 @@ auto NvsStorage::Read() -> void {
auto NvsStorage::Write() -> bool { auto NvsStorage::Write() -> bool {
std::lock_guard<std::mutex> lock{mutex_}; std::lock_guard<std::mutex> lock{mutex_};
lock_polarity_.write(handle_); lock_polarity_.write(handle_);
display_cols_.write(handle_);
display_rows_.write(handle_);
brightness_.write(handle_); brightness_.write(handle_);
sensitivity_.write(handle_); sensitivity_.write(handle_);
amp_max_vol_.write(handle_); amp_max_vol_.write(handle_);
@ -231,6 +239,19 @@ auto NvsStorage::LockPolarity(bool p) -> void {
lock_polarity_.set(p); lock_polarity_.set(p);
} }
auto NvsStorage::DisplaySize()
-> std::pair<std::optional<uint16_t>, std::optional<uint16_t>> {
std::lock_guard<std::mutex> lock{mutex_};
return std::make_pair(display_cols_.get(), display_rows_.get());
}
auto NvsStorage::DisplaySize(
std::pair<std::optional<uint16_t>, std::optional<uint16_t>> size) -> void {
std::lock_guard<std::mutex> lock{mutex_};
display_cols_.set(std::move(size.first));
display_rows_.set(std::move(size.second));
}
auto NvsStorage::PreferredBluetoothDevice() auto NvsStorage::PreferredBluetoothDevice()
-> std::optional<bluetooth::MacAndName> { -> std::optional<bluetooth::MacAndName> {
std::lock_guard<std::mutex> lock{mutex_}; std::lock_guard<std::mutex> lock{mutex_};

@ -62,8 +62,12 @@ auto Booting::entry() -> void {
ESP_ERROR_CHECK(drivers::init_spi()); ESP_ERROR_CHECK(drivers::init_spi());
sServices->gpios(std::unique_ptr<drivers::Gpios>(drivers::Gpios::Create())); sServices->gpios(std::unique_ptr<drivers::Gpios>(drivers::Gpios::Create()));
// NVS is needed early so that we can correctly initialise the display.
sServices->nvs(
std::unique_ptr<drivers::NvsStorage>(drivers::NvsStorage::OpenSync()));
ESP_LOGI(kTag, "starting ui"); ESP_LOGI(kTag, "starting ui");
if (!ui::UiState::InitBootSplash(sServices->gpios())) { if (!ui::UiState::InitBootSplash(sServices->gpios(), sServices->nvs())) {
events::System().Dispatch(FatalError{}); events::System().Dispatch(FatalError{});
return; return;
} }
@ -74,8 +78,6 @@ auto Booting::entry() -> void {
ESP_LOGI(kTag, "installing remaining drivers"); ESP_LOGI(kTag, "installing remaining drivers");
drivers::spiffs_mount(); drivers::spiffs_mount();
sServices->samd(std::unique_ptr<drivers::Samd>(drivers::Samd::Create())); sServices->samd(std::unique_ptr<drivers::Samd>(drivers::Samd::Create()));
sServices->nvs(
std::unique_ptr<drivers::NvsStorage>(drivers::NvsStorage::OpenSync()));
sServices->touchwheel( sServices->touchwheel(
std::unique_ptr<drivers::TouchWheel>{drivers::TouchWheel::Create()}); std::unique_ptr<drivers::TouchWheel>{drivers::TouchWheel::Create()});
sServices->haptics(std::make_unique<drivers::Haptics>()); sServices->haptics(std::make_unique<drivers::Haptics>());

@ -36,7 +36,7 @@ namespace ui {
class UiState : public tinyfsm::Fsm<UiState> { class UiState : public tinyfsm::Fsm<UiState> {
public: public:
static auto InitBootSplash(drivers::IGpios&) -> bool; static auto InitBootSplash(drivers::IGpios&, drivers::NvsStorage&) -> bool;
virtual ~UiState() {} virtual ~UiState() {}

@ -12,6 +12,7 @@
#include "bluetooth_types.hpp" #include "bluetooth_types.hpp"
#include "db_events.hpp" #include "db_events.hpp"
#include "display_init.hpp"
#include "freertos/portmacro.h" #include "freertos/portmacro.h"
#include "freertos/projdefs.h" #include "freertos/projdefs.h"
#include "lua.h" #include "lua.h"
@ -284,10 +285,21 @@ lua::Property UiState::sLockSwitch{false};
lua::Property UiState::sDatabaseUpdating{false}; lua::Property UiState::sDatabaseUpdating{false};
auto UiState::InitBootSplash(drivers::IGpios& gpios) -> bool { auto UiState::InitBootSplash(drivers::IGpios& gpios, drivers::NvsStorage& nvs)
-> bool {
// Init LVGL first, since the display driver registers itself with LVGL. // Init LVGL first, since the display driver registers itself with LVGL.
lv_init(); lv_init();
sDisplay.reset(drivers::Display::Create(gpios, drivers::displays::kST7735R));
drivers::displays::InitialisationData init_data = drivers::displays::kST7735R;
// HACK: correct the display size for our prototypes.
// nvs.DisplaySize({161, 130});
auto actual_size = nvs.DisplaySize();
init_data.width = actual_size.first.value_or(init_data.width);
init_data.height = actual_size.second.value_or(init_data.height);
sDisplay.reset(drivers::Display::Create(gpios, init_data));
if (sDisplay == nullptr) { if (sDisplay == nullptr) {
return false; return false;
} }

Loading…
Cancel
Save