From fdd08d4bcbce8869bb9f147ef074c602cca8eaae Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Tue, 30 Jan 2024 22:37:48 +0100 Subject: [PATCH] Module17: removed screen contrast setting, added screen brightness setting Module17 uses an OLED display, which does not have contrast regulation. The contrast control register, however, allows to change the brightness of the display. --- openrtx/include/ui/ui_mod17.h | 9 ++----- openrtx/src/ui/module17/ui.c | 35 +++++++++++-------------- openrtx/src/ui/module17/ui_menu.c | 6 ++--- platform/drivers/display/SH110x_Mod17.c | 24 +++++++++++------ platform/targets/Module17/hwconfig.h | 4 --- 5 files changed, 36 insertions(+), 42 deletions(-) diff --git a/openrtx/include/ui/ui_mod17.h b/openrtx/include/ui/ui_mod17.h index 98fb1422..67d0f7cd 100644 --- a/openrtx/include/ui/ui_mod17.h +++ b/openrtx/include/ui/ui_mod17.h @@ -108,13 +108,8 @@ enum backupRestoreItems enum displayItems { -#ifdef CONFIG_SCREEN_CONTRAST - D_CONTRAST = 0 - ,D_TIMER -#endif -#ifndef CONFIG_SCREEN_CONTRAST - D_TIMER = 0 -#endif + D_BRIGHTNESS = 0, + D_TIMER }; #ifdef CONFIG_GPS diff --git a/openrtx/src/ui/module17/ui.c b/openrtx/src/ui/module17/ui.c index aef5845b..66bd7948 100644 --- a/openrtx/src/ui/module17/ui.c +++ b/openrtx/src/ui/module17/ui.c @@ -88,9 +88,7 @@ const char *settings_items[] = const char *display_items[] = { -#ifdef CONFIG_SCREEN_CONTRAST - "Contrast", -#endif + "Brightness", "Timer" }; @@ -502,15 +500,18 @@ void _ui_fsm_insertVFONumber(kbd_msg_t msg, bool *sync_rtx) } } -void _ui_changeContrast(int variation) +static void _ui_changeBrightness(int variation) { - if(variation >= 0) - state.settings.contrast = - (255 - state.settings.contrast < variation) ? 255 : state.settings.contrast + variation; - else - state.settings.contrast = - (state.settings.contrast < -variation) ? 0 : state.settings.contrast + variation; - display_setContrast(state.settings.contrast); + // Avoid rollover if current value is zero. + if((state.settings.brightness == 0) && (variation < 0)) + return; + + // Cap max brightness to 100 + if((state.settings.brightness == 100) && (variation > 0)) + return; + + state.settings.brightness += variation; + display_setBacklightLevel(state.settings.brightness); } void _ui_changeTimer(int variation) @@ -929,11 +930,9 @@ void ui_updateFSM(bool *sync_rtx) { switch(ui_state.menu_selected) { -#ifdef CONFIG_SCREEN_CONTRAST - case D_CONTRAST: - _ui_changeContrast(-4); + case D_BRIGHTNESS: + _ui_changeBrightness(-5); break; -#endif case D_TIMER: _ui_changeTimer(-1); break; @@ -945,11 +944,9 @@ void ui_updateFSM(bool *sync_rtx) { switch(ui_state.menu_selected) { -#ifdef CONFIG_SCREEN_CONTRAST - case D_CONTRAST: - _ui_changeContrast(+4); + case D_BRIGHTNESS: + _ui_changeBrightness(+5); break; -#endif case D_TIMER: _ui_changeTimer(+1); break; diff --git a/openrtx/src/ui/module17/ui_menu.c b/openrtx/src/ui/module17/ui_menu.c index 36569b8c..e821b738 100644 --- a/openrtx/src/ui/module17/ui_menu.c +++ b/openrtx/src/ui/module17/ui_menu.c @@ -177,11 +177,9 @@ int _ui_getDisplayValueName(char *buf, uint8_t max_len, uint8_t index) uint8_t value = 0; switch(index) { -#ifdef CONFIG_SCREEN_CONTRAST - case D_CONTRAST: - value = last_state.settings.contrast; + case D_BRIGHTNESS: + value = last_state.settings.brightness; break; -#endif case D_TIMER: snprintf(buf, max_len, "%s", display_timer_values[last_state.settings.display_timer]); diff --git a/platform/drivers/display/SH110x_Mod17.c b/platform/drivers/display/SH110x_Mod17.c index 3310210b..cbe53730 100644 --- a/platform/drivers/display/SH110x_Mod17.c +++ b/platform/drivers/display/SH110x_Mod17.c @@ -122,16 +122,24 @@ void display_render(void *fb) void display_setContrast(uint8_t contrast) { - gpio_clearPin(LCD_CS); - - gpio_clearPin(LCD_RS); /* RS low -> command mode */ - (void) spi2_sendRecv(0x81); /* Set Electronic Volume */ - (void) spi2_sendRecv(contrast); /* Controller contrast range is 0 - 63 */ - - gpio_setPin(LCD_CS); + /* OLED display do not have contrast regulation */ + (void) contrast; } void display_setBacklightLevel(uint8_t level) { - (void) level; + /* + * Module17 uses an OLED display, so contrast channel is actually controlling + * the brightness. The usable range is 0 - 128, above which there is no + * noticeable change in the brightness level (already at maximum). + */ + uint16_t bl = (level * 128) / 100; + + gpio_clearPin(LCD_CS); + + gpio_clearPin(LCD_RS); /* RS low -> command mode */ + (void) spi2_sendRecv(0x81); /* Contrast control register */ + (void) spi2_sendRecv(bl); + + gpio_setPin(LCD_CS); } diff --git a/platform/targets/Module17/hwconfig.h b/platform/targets/Module17/hwconfig.h index e0df4d4b..2c8a69a0 100644 --- a/platform/targets/Module17/hwconfig.h +++ b/platform/targets/Module17/hwconfig.h @@ -29,10 +29,6 @@ #define CONFIG_SCREEN_WIDTH 128 #define CONFIG_SCREEN_HEIGHT 64 -/* Screen has adjustable contrast */ -#define CONFIG_SCREEN_CONTRAST -#define CONFIG_DEFAULT_CONTRAST 91 - /* Screen pixel format */ #define CONFIG_PIX_FMT_BW