Skip to content

Commit

Permalink
invert display option (#2232)
Browse files Browse the repository at this point in the history
* invert display option

* text fix, format code
  • Loading branch information
htotoo committed Sep 7, 2024
1 parent e6afd77 commit 87069f1
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 15 deletions.
14 changes: 10 additions & 4 deletions firmware/application/apps/ui_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,21 +774,27 @@ void SetConfigModeView::focus() {
button_save.focus();
}

/* SetFakeBrightnessView ************************************/
/* SetDisplayView ************************************/

SetFakeBrightnessView::SetFakeBrightnessView(NavigationView& nav) {
SetDisplayView::SetDisplayView(NavigationView& nav) {
add_children({&labels,
&field_fake_brightness,
&button_save,
&button_cancel,
&checkbox_invert_switch,
&checkbox_brightness_switch});

field_fake_brightness.set_by_value(pmem::fake_brightness_level());
checkbox_brightness_switch.set_value(pmem::apply_fake_brightness());
checkbox_invert_switch.set_value(pmem::config_lcd_inverted_mode());

button_save.on_select = [&nav, this](Button&) {
pmem::set_apply_fake_brightness(checkbox_brightness_switch.value());
pmem::set_fake_brightness_level(field_fake_brightness.selected_index_value());
if (checkbox_invert_switch.value() != pmem::config_lcd_inverted_mode()) {
display.set_inverted(checkbox_invert_switch.value());
pmem::set_lcd_inverted_mode(checkbox_invert_switch.value());
}
send_system_refresh();
nav.pop();
};
Expand All @@ -798,7 +804,7 @@ SetFakeBrightnessView::SetFakeBrightnessView(NavigationView& nav) {
};
}

void SetFakeBrightnessView::focus() {
void SetDisplayView::focus() {
button_save.focus();
}

Expand Down Expand Up @@ -999,7 +1005,7 @@ void SettingsMenuView::on_populate() {
{"SD Card", ui::Color::dark_cyan(), &bitmap_icon_sdcard, [this]() { nav_.push<SetSDCardView>(); }},
{"User Interface", ui::Color::dark_cyan(), &bitmap_icon_options_ui, [this]() { nav_.push<SetUIView>(); }},
//{"QR Code", ui::Color::dark_cyan(), &bitmap_icon_qr_code, [this]() { nav_.push<SetQRCodeView>(); }},
{"Brightness", ui::Color::dark_cyan(), &bitmap_icon_brightness, [this]() { nav_.push<SetFakeBrightnessView>(); }},
{"Display", ui::Color::dark_cyan(), &bitmap_icon_brightness, [this]() { nav_.push<SetDisplayView>(); }},
{"Menu Color", ui::Color::dark_cyan(), &bitmap_icon_brightness, [this]() { nav_.push<SetMenuColorView>(); }},
{"Theme", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetThemeView>(); }},
{"Autostart", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetAutostartView>(); }},
Expand Down
11 changes: 8 additions & 3 deletions firmware/application/apps/ui_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,13 @@ class SetConfigModeView : public View {

using portapack::persistent_memory::fake_brightness_level_options;

class SetFakeBrightnessView : public View {
class SetDisplayView : public View {
public:
SetFakeBrightnessView(NavigationView& nav);
SetDisplayView(NavigationView& nav);

void focus() override;

std::string title() const override { return "Brightness"; };
std::string title() const override { return "Display"; };

private:
Labels labels{
Expand All @@ -739,6 +739,11 @@ class SetFakeBrightnessView : public View {
16,
"Enable brightness adjust"};

Checkbox checkbox_invert_switch{
{1 * 8, 10 * 16},
23,
"Invert colors (For IPS)"};

Button button_save{
{2 * 8, 16 * 16, 12 * 8, 32},
"Save"};
Expand Down
2 changes: 2 additions & 0 deletions firmware/application/portapack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ init_status_t init() {

set_cpu_clock_speed();

if (persistent_memory::config_lcd_inverted_mode()) display.set_inverted(true);

if (lcd_fast_setup)
draw_splash_screen_icon(0, ui::bitmap_icon_memory);

Expand Down
8 changes: 8 additions & 0 deletions firmware/common/lcd_ili9341.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ void ILI9341::wake() {
lcd_wake();
}

void ILI9341::set_inverted(bool invert) {
if (invert) {
io.lcd_data_write_command_and_data(0x21, {});
} else {
io.lcd_data_write_command_and_data(0x20, {});
}
}

void ILI9341::fill_rectangle(ui::Rect r, const ui::Color c) {
const auto r_clipped = r.intersect(screen_rect());
if (!r_clipped.is_empty()) {
Expand Down
2 changes: 2 additions & 0 deletions firmware/common/lcd_ili9341.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class ILI9341 {
void sleep();
void wake();

void set_inverted(bool invert);

void fill_rectangle(ui::Rect r, const ui::Color c);
void fill_rectangle_unrolled8(ui::Rect r, const ui::Color c);
void draw_line(const ui::Point start, const ui::Point end, const ui::Color color);
Expand Down
4 changes: 4 additions & 0 deletions firmware/common/portapack_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ bool IO::get_dark_cover() {
return portapack::persistent_memory::apply_fake_brightness();
}

bool IO::get_is_inverted() {
return portapack::persistent_memory::config_lcd_inverted_mode();
}

uint8_t IO::get_brightness() {
return portapack::persistent_memory::fake_brightness_level();
}
Expand Down
22 changes: 17 additions & 5 deletions firmware/common/portapack_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ class IO {

void lcd_write_pixel(ui::Color pixel) {
if (get_dark_cover()) {
pixel.v = DARKENED_PIXEL(pixel.v, get_brightness());
if (!get_is_inverted())
pixel.v = DARKENED_PIXEL(pixel.v, get_brightness());
else
pixel.v = UNDARKENED_PIXEL(pixel.v, get_brightness());
}
lcd_write_data(pixel.v);
}
Expand All @@ -174,7 +177,10 @@ class IO {

void lcd_write_pixels(ui::Color pixel, size_t n) {
if (get_dark_cover()) {
pixel.v = DARKENED_PIXEL(pixel.v, get_brightness());
if (!get_is_inverted())
pixel.v = DARKENED_PIXEL(pixel.v, get_brightness());
else
pixel.v = UNDARKENED_PIXEL(pixel.v, get_brightness());
}
while (n--) {
lcd_write_data(pixel.v);
Expand All @@ -183,7 +189,10 @@ class IO {

void lcd_write_pixels_unrolled8(ui::Color pixel, size_t n) {
if (get_dark_cover()) {
pixel.v = DARKENED_PIXEL(pixel.v, get_brightness());
if (!get_is_inverted())
pixel.v = DARKENED_PIXEL(pixel.v, get_brightness());
else
pixel.v = UNDARKENED_PIXEL(pixel.v, get_brightness());
}
auto v = pixel.v;
n >>= 3;
Expand Down Expand Up @@ -231,7 +240,7 @@ class IO {

return switches_raw;
}

bool get_is_inverted();
bool get_dark_cover();
uint8_t get_brightness();
// TODO: cache the value ^^ & ^ to increaase performance, need a trigger cuz init doesn't work. And since the constructor is constexpr, we can't use with in class var to cache it. maybe cache from outside somewhere and pass it here as argument.
Expand Down Expand Up @@ -417,7 +426,10 @@ class IO {
uint32_t original_value = (value_high << 8) | value_low;

if (get_dark_cover()) {
original_value = UNDARKENED_PIXEL(original_value, get_brightness());
if (!get_is_inverted())
original_value = DARKENED_PIXEL(original_value, get_brightness());
else
original_value = UNDARKENED_PIXEL(original_value, get_brightness());
}
return original_value;
}
Expand Down
15 changes: 12 additions & 3 deletions firmware/common/portapack_persistent_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ struct data_t {
bool updown_converter;
bool updown_frequency_rx_correction;
bool updown_frequency_tx_correction;
bool UNUSED_4 : 1;
bool lcd_inverted_mode : 1;
bool UNUSED_5 : 1;
bool UNUSED_6 : 1;
bool UNUSED_7 : 1;
Expand Down Expand Up @@ -292,7 +292,7 @@ struct data_t {
updown_converter(false),
updown_frequency_rx_correction(false),
updown_frequency_tx_correction(false),
UNUSED_4(false),
lcd_inverted_mode(false),
UNUSED_5(false),
UNUSED_6(false),
UNUSED_7(false),
Expand Down Expand Up @@ -1062,6 +1062,14 @@ void set_config_freq_rx_correction(uint32_t v) {
data->frequency_rx_correction = v;
}

// LCD invert
bool config_lcd_inverted_mode() {
return data->lcd_inverted_mode;
}
void set_lcd_inverted_mode(bool v) {
data->lcd_inverted_mode = v;
}

// Rotary encoder dial settings
uint8_t encoder_dial_sensitivity() {
return data->encoder_dial_sensitivity;
Expand Down Expand Up @@ -1231,7 +1239,7 @@ bool debug_dump() {
pmem_dump_file.write_line("updown_converter: " + to_string_dec_int(data->updown_converter));
pmem_dump_file.write_line("updown_frequency_rx_correction: " + to_string_dec_int(data->updown_frequency_rx_correction));
pmem_dump_file.write_line("updown_frequency_tx_correction: " + to_string_dec_int(data->updown_frequency_tx_correction));
// pmem_dump_file.write_line("UNUSED_4: " + to_string_dec_int(data->UNUSED_4));
pmem_dump_file.write_line("lcd_inverted_mode: " + to_string_dec_uint(data->lcd_inverted_mode));
// pmem_dump_file.write_line("UNUSED_5: " + to_string_dec_int(data->UNUSED_5));
// pmem_dump_file.write_line("UNUSED_6: " + to_string_dec_int(data->UNUSED_6));
// pmem_dump_file.write_line("UNUSED_7: " + to_string_dec_int(data->UNUSED_7));
Expand Down Expand Up @@ -1278,6 +1286,7 @@ bool debug_dump() {
pmem_dump_file.write_line("ui_config2 hide_battery_icon: " + to_string_dec_uint(data->ui_config2.hide_battery_icon));
pmem_dump_file.write_line("ui_config2 hide_numeric_battery: " + to_string_dec_uint(data->ui_config2.hide_numeric_battery));
pmem_dump_file.write_line("ui_config2 theme_id: " + to_string_dec_uint(data->ui_config2.theme_id));
pmem_dump_file.write_line("ui_config2 override_batt_calc: " + to_string_dec_uint(data->ui_config2.override_batt_calc));

// misc_config bits
pmem_dump_file.write_line("misc_config config_audio_mute: " + to_string_dec_int(config_audio_mute()));
Expand Down
2 changes: 2 additions & 0 deletions firmware/common/portapack_persistent_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ void set_config_audio_mute(bool v);
void set_config_speaker_disable(bool v);
void set_config_backlight_timer(const backlight_config_t& new_value);
void set_disable_touchscreen(bool v);
bool config_lcd_inverted_mode();
void set_lcd_inverted_mode(bool v);

uint8_t encoder_dial_sensitivity();
void set_encoder_dial_sensitivity(uint8_t v);
Expand Down

0 comments on commit 87069f1

Please sign in to comment.