summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/display.cpp15
-rw-r--r--src/drivers/display_init.cpp2
-rw-r--r--src/drivers/include/display_init.hpp3
-rw-r--r--src/drivers/include/nvs.hpp8
-rw-r--r--src/drivers/nvs.cpp21
5 files changed, 40 insertions, 9 deletions
diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp
index 026e1346..c16fc148 100644
--- a/src/drivers/display.cpp
+++ b/src/drivers/display.cpp
@@ -39,9 +39,6 @@
[[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 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
* 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];
namespace drivers {
@@ -154,10 +153,8 @@ auto Display::Create(IGpios& expander,
lv_disp_drv_init(&display->driver_);
display->driver_.draw_buf = &display->buffers_;
- display->driver_.hor_res = kDisplayWidth;
- display->driver_.ver_res = kDisplayHeight;
- // display->driver_.sw_rotate = 1;
- // display->driver_.rotated = LV_DISP_ROT_270;
+ display->driver_.hor_res = init_data.width;
+ display->driver_.ver_res = init_data.height;
display->driver_.sw_rotate = 0;
display->driver_.rotated = LV_DISP_ROT_NONE;
display->driver_.antialiasing = 0;
diff --git a/src/drivers/display_init.cpp b/src/drivers/display_init.cpp
index 833ea6a4..a69826fa 100644
--- a/src/drivers/display_init.cpp
+++ b/src/drivers/display_init.cpp
@@ -101,6 +101,8 @@ static const uint8_t kST7735RCommonFooter[]{
// clang-format on
const InitialisationData kST7735R = {
+ .width = 160,
+ .height = 128,
.num_sequences = 3,
.sequences = {kST7735RCommonHeader, kST7735RCommonGreen,
kST7735RCommonFooter}};
diff --git a/src/drivers/include/display_init.hpp b/src/drivers/include/display_init.hpp
index f6c28b54..9bf5b3f5 100644
--- a/src/drivers/include/display_init.hpp
+++ b/src/drivers/include/display_init.hpp
@@ -6,6 +6,7 @@
#pragma once
+#include <stdint.h>
#include <cstdint>
namespace drivers {
@@ -14,6 +15,8 @@ namespace displays {
extern const uint8_t kDelayBit;
struct InitialisationData {
+ uint16_t width;
+ uint16_t height;
uint8_t num_sequences;
const uint8_t* sequences[4];
};
diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp
index 5bd825e5..f288f8e2 100644
--- a/src/drivers/include/nvs.hpp
+++ b/src/drivers/include/nvs.hpp
@@ -71,6 +71,11 @@ class NvsStorage {
auto LockPolarity() -> bool;
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>) -> void;
@@ -120,6 +125,9 @@ class NvsStorage {
nvs_handle_t handle_;
Setting<uint8_t> lock_polarity_;
+ Setting<uint16_t> display_cols_;
+ Setting<uint16_t> display_rows_;
+
Setting<uint8_t> brightness_;
Setting<uint8_t> sensitivity_;
Setting<uint16_t> amp_max_vol_;
diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp
index 875059be..28cb542c 100644
--- a/src/drivers/nvs.cpp
+++ b/src/drivers/nvs.cpp
@@ -37,6 +37,8 @@ static constexpr char kKeyAmpLeftBias[] = "hp_bias";
static constexpr char kKeyPrimaryInput[] = "in_pri";
static constexpr char kKeyScrollSensitivity[] = "scroll";
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)
-> std::optional<std::string> {
@@ -161,6 +163,8 @@ auto NvsStorage::OpenSync() -> NvsStorage* {
NvsStorage::NvsStorage(nvs_handle_t handle)
: handle_(handle),
lock_polarity_(kKeyLockPolarity),
+ display_cols_(kKeyDisplayCols),
+ display_rows_(kKeyDisplayRows),
brightness_(kKeyBrightness),
sensitivity_(kKeyScrollSensitivity),
amp_max_vol_(kKeyAmpMaxVolume),
@@ -180,6 +184,8 @@ NvsStorage::~NvsStorage() {
auto NvsStorage::Read() -> void {
std::lock_guard<std::mutex> lock{mutex_};
lock_polarity_.read(handle_);
+ display_cols_.read(handle_);
+ display_rows_.read(handle_);
brightness_.read(handle_);
sensitivity_.read(handle_);
amp_max_vol_.read(handle_);
@@ -194,6 +200,8 @@ auto NvsStorage::Read() -> void {
auto NvsStorage::Write() -> bool {
std::lock_guard<std::mutex> lock{mutex_};
lock_polarity_.write(handle_);
+ display_cols_.write(handle_);
+ display_rows_.write(handle_);
brightness_.write(handle_);
sensitivity_.write(handle_);
amp_max_vol_.write(handle_);
@@ -231,6 +239,19 @@ auto NvsStorage::LockPolarity(bool p) -> void {
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()
-> std::optional<bluetooth::MacAndName> {
std::lock_guard<std::mutex> lock{mutex_};