diff --git a/openrtx/include/interfaces/display.h b/openrtx/include/interfaces/display.h index cf69f1d9..4e1ce25b 100644 --- a/openrtx/include/interfaces/display.h +++ b/openrtx/include/interfaces/display.h @@ -109,6 +109,14 @@ bool display_renderingInProgress(); */ void display_setContrast(uint8_t contrast); +/** + * Set level of display backlight. + * NOTE: not all the display controllers support backlight control, thus on some + * targets this function has no effect. + * @param level: display backlight level, normalised value with range 0 - 100. + */ +void display_setBacklightLevel(uint8_t level); + #ifdef __cplusplus } #endif diff --git a/openrtx/include/interfaces/platform.h b/openrtx/include/interfaces/platform.h index 157853cf..64274f3f 100644 --- a/openrtx/include/interfaces/platform.h +++ b/openrtx/include/interfaces/platform.h @@ -142,13 +142,6 @@ void platform_beepStart(uint16_t freq); */ void platform_beepStop(); -/** - * This function sets the screen backlight to the specified level. - * @param level: backlight level, from 0 (backlight off) to 100 (backlight at - * full brightness). - */ -void platform_setBacklightLevel(uint8_t level); - /** * This function returns a pointer to a data structure containing all the * hardware information. diff --git a/openrtx/src/core/openrtx.c b/openrtx/src/core/openrtx.c index dd347c6a..39bff732 100644 --- a/openrtx/src/core/openrtx.c +++ b/openrtx/src/core/openrtx.c @@ -72,7 +72,7 @@ void openrtx_init() ui_drawSplashScreen(true); gfx_render(); sleepFor(0u, 30u); - platform_setBacklightLevel(state.settings.brightness); + display_setBacklightLevel(state.settings.brightness); #if defined(GPS_PRESENT) // Detect and initialise GPS diff --git a/openrtx/src/ui/default/ui.c b/openrtx/src/ui/default/ui.c index 77ccfb1d..604b4835 100644 --- a/openrtx/src/ui/default/ui.c +++ b/openrtx/src/ui/default/ui.c @@ -728,7 +728,7 @@ static void _ui_changeBrightness(int variation) if(state.settings.brightness > 100) state.settings.brightness = 100; if(state.settings.brightness < 5) state.settings.brightness = 5; - platform_setBacklightLevel(state.settings.brightness); + display_setBacklightLevel(state.settings.brightness); } #ifdef SCREEN_CONTRAST @@ -839,7 +839,7 @@ static void _ui_enterStandby() standby = true; redraw_needed = false; - platform_setBacklightLevel(0); + display_setBacklightLevel(0); } static bool _ui_exitStandby(long long now) @@ -851,7 +851,7 @@ static bool _ui_exitStandby(long long now) standby = false; redraw_needed = true; - platform_setBacklightLevel(state.settings.brightness); + display_setBacklightLevel(state.settings.brightness); return true; } diff --git a/openrtx/src/ui/module17/ui.c b/openrtx/src/ui/module17/ui.c index e3b34491..9a184aae 100644 --- a/openrtx/src/ui/module17/ui.c +++ b/openrtx/src/ui/module17/ui.c @@ -564,7 +564,7 @@ void _ui_enterStandby() standby = true; redraw_needed = false; - platform_setBacklightLevel(0); + display_setBacklightLevel(0); } bool _ui_exitStandby(long long now) @@ -576,7 +576,7 @@ bool _ui_exitStandby(long long now) standby = false; redraw_needed = true; - platform_setBacklightLevel(state.settings.brightness); + display_setBacklightLevel(state.settings.brightness); return true; } diff --git a/platform/drivers/backlight/backlight.h b/platform/drivers/backlight/backlight.h index 0412f8ca..24fc69a8 100644 --- a/platform/drivers/backlight/backlight.h +++ b/platform/drivers/backlight/backlight.h @@ -21,11 +21,15 @@ #ifndef BACKLIGHT_H #define BACKLIGHT_H +#ifdef __cplusplus +extern "C" { +#endif + /** * Low-level driver for backlight dimming control. * This header file only provides the API for driver initialisation and shutdown, * while effective setting of backlight level is provided by target-specific - * sources by implementating platform_setBacklightLevel(). + * sources by implementating display_setBacklightLevel(). */ /** @@ -38,4 +42,9 @@ void backlight_init(); */ void backlight_terminate(); + +#ifdef __cplusplus +} +#endif + #endif /* BACKLIGHT_H */ diff --git a/platform/drivers/backlight/backlight_GDx.c b/platform/drivers/backlight/backlight_GDx.c index 67cf8a0f..2963aff8 100644 --- a/platform/drivers/backlight/backlight_GDx.c +++ b/platform/drivers/backlight/backlight_GDx.c @@ -49,9 +49,9 @@ void backlight_terminate() } /* - * This function is defined in platform.h + * This function is defined in display.h */ -void platform_setBacklightLevel(uint8_t level) +void display_setBacklightLevel(uint8_t level) { if(level > 100) level = 100; diff --git a/platform/drivers/backlight/backlight_MDx.c b/platform/drivers/backlight/backlight_MDx.c index 83284831..43cf7b0e 100644 --- a/platform/drivers/backlight/backlight_MDx.c +++ b/platform/drivers/backlight/backlight_MDx.c @@ -128,9 +128,9 @@ void backlight_terminate() } /* - * This function is defined in platform.h + * This function is defined in display.h */ -void platform_setBacklightLevel(uint8_t level) +void display_setBacklightLevel(uint8_t level) { if(level > 100) level = 100; @@ -144,7 +144,7 @@ void platform_setBacklightLevel(uint8_t level) * If CCR1 value is zero, a waveform with 99% duty cycle is generated: to * avoid this the PWM is cut off when backlight level is 1. */ - if(level > 1) + if(pwmLevel > 1) { #ifdef ENABLE_BKLIGHT_DIMMING TIM11->CCR1 = pwmLevel; diff --git a/platform/drivers/display/HX8353_MD3x.cpp b/platform/drivers/display/HX8353_MD3x.cpp index 7eb82aa6..13484a48 100644 --- a/platform/drivers/display/HX8353_MD3x.cpp +++ b/platform/drivers/display/HX8353_MD3x.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -127,6 +128,9 @@ static inline __attribute__((__always_inline__)) void writeData(uint8_t val) void display_init() { + /* Initialise backlight driver */ + backlight_init(); + /* Clear framebuffer, setting all pixels to 0x00 makes the screen white */ memset(frameBuffer, 0x00, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(uint16_t)); @@ -430,6 +434,9 @@ void display_init() void display_terminate() { + /* Shut down backlight */ + backlight_terminate(); + /* Shut off FSMC and deallocate framebuffer */ RCC->AHB3ENR &= ~RCC_AHB3ENR_FSMCEN; __DSB(); @@ -537,3 +544,9 @@ void display_setContrast(uint8_t contrast) /* This controller does not support contrast regulation */ (void) contrast; } + +/* + * Function implemented in backlight_MDx driver + * + * void display_setBacklightLevel(uint8_t level) + */ diff --git a/platform/drivers/display/SH110x_Mod17.c b/platform/drivers/display/SH110x_Mod17.c index a2d3fb2b..3f38bfd8 100644 --- a/platform/drivers/display/SH110x_Mod17.c +++ b/platform/drivers/display/SH110x_Mod17.c @@ -150,3 +150,8 @@ void display_setContrast(uint8_t contrast) gpio_setPin(LCD_CS); } + +void display_setBacklightLevel(uint8_t level) +{ + (void) level; +} diff --git a/platform/drivers/display/SSD1306_Mod17.c b/platform/drivers/display/SSD1306_Mod17.c index 16faf289..31c92188 100644 --- a/platform/drivers/display/SSD1306_Mod17.c +++ b/platform/drivers/display/SSD1306_Mod17.c @@ -170,3 +170,8 @@ void display_setContrast(uint8_t contrast) gpio_setPin(LCD_CS); } + +void display_setBacklightLevel(uint8_t level) +{ + (void) level; +} diff --git a/platform/drivers/display/ST7567_MD9600.c b/platform/drivers/display/ST7567_MD9600.c index c47975cb..59c31491 100644 --- a/platform/drivers/display/ST7567_MD9600.c +++ b/platform/drivers/display/ST7567_MD9600.c @@ -157,3 +157,8 @@ void display_setContrast(uint8_t contrast) gpio_setPin(LCD_CS); spi2_releaseDevice(); } + +void display_setBacklightLevel(uint8_t level) +{ + (void) level; +} diff --git a/platform/drivers/display/UC1701_GDx.c b/platform/drivers/display/UC1701_GDx.c index 718552a5..85138838 100644 --- a/platform/drivers/display/UC1701_GDx.c +++ b/platform/drivers/display/UC1701_GDx.c @@ -22,10 +22,11 @@ #include #include #include +#include #include #include #include -#include "hwconfig.h" +#include /* * LCD framebuffer, statically allocated. @@ -98,6 +99,8 @@ static void display_renderRow(uint8_t row) void display_init() { + backlight_init(); /* Initialise backlight driver */ + gpio_setMode(LCD_CS, OUTPUT); gpio_setMode(LCD_RST, OUTPUT); gpio_setMode(LCD_RS, OUTPUT); @@ -129,6 +132,8 @@ void display_init() void display_terminate() { + backlight_terminate(); + gpio_setMode(LCD_CS, INPUT); gpio_setMode(LCD_RST, INPUT); gpio_setMode(LCD_RS, INPUT); @@ -171,3 +176,9 @@ void display_setContrast(uint8_t contrast) sendByteToController(0x81); /* Set Electronic Volume */ sendByteToController(contrast >> 2); /* Controller contrast range is 0 - 63 */ } + +/* + * Function implemented in backlight_GDx driver + * + * void display_setBacklightLevel(uint8_t level) + */ diff --git a/platform/drivers/display/display_libSDL.c b/platform/drivers/display/display_libSDL.c index a2a12aee..3335c782 100644 --- a/platform/drivers/display/display_libSDL.c +++ b/platform/drivers/display/display_libSDL.c @@ -41,12 +41,15 @@ bool inProgress; /* Flag to signal when rendering is in progress */ bool sdl_ready = false; /* Flag to signal the sdl main loop is running */ extern chan_t fb_sync; /* Shared channel to send a frame buffer update */ +/* Custom SDL Event to adjust backlight */ +extern Uint32 SDL_Backlight_Event; + /** * @internal * Internal helper function which fetches pixel at position (x, y) from framebuffer * and returns it in SDL-compatible format, which is ARGB8888. */ -uint32_t fetchPixelFromFb(unsigned int x, unsigned int y) +static uint32_t fetchPixelFromFb(unsigned int x, unsigned int y) { (void) x; (void) y; @@ -176,3 +179,19 @@ void display_setContrast(uint8_t contrast) { printf("Setting display contrast to %d\n", contrast); } + +void display_setBacklightLevel(uint8_t level) +{ + // Saturate level to 100 and convert value to 0 - 255 + if(level > 100) level = 100; + uint16_t value = (2 * level) + (level * 55)/100; + + SDL_Event e; + SDL_zero(e); + e.type = SDL_Backlight_Event; + e.user.data1 = malloc(sizeof(uint8_t)); + uint8_t *data = (uint8_t *)e.user.data1; + *data = ((uint8_t) value); + + SDL_PushEvent(&e); +} diff --git a/platform/targets/DM-1801/platform.c b/platform/targets/DM-1801/platform.c index d1b72262..7faa19d2 100644 --- a/platform/targets/DM-1801/platform.c +++ b/platform/targets/DM-1801/platform.c @@ -195,10 +195,3 @@ const hwInfo_t *platform_getHwInfo() { return &hwInfo; } - - -/* - * NOTE: implementation of this API function is provided in - * platform/drivers/backlight/backlight_GDx.c - */ -// void platform_setBacklightLevel(uint8_t level) diff --git a/platform/targets/GD-77/platform.c b/platform/targets/GD-77/platform.c index 7a12cdc9..972f591f 100644 --- a/platform/targets/GD-77/platform.c +++ b/platform/targets/GD-77/platform.c @@ -195,10 +195,3 @@ const hwInfo_t *platform_getHwInfo() { return &hwInfo; } - - -/* - * NOTE: implementation of this API function is provided in - * platform/drivers/backlight/backlight_GDx.c - */ -// void platform_setBacklightLevel(uint8_t level) diff --git a/platform/targets/MD-3x0/platform.c b/platform/targets/MD-3x0/platform.c index a00ca6c9..2aa85655 100644 --- a/platform/targets/MD-3x0/platform.c +++ b/platform/targets/MD-3x0/platform.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -63,15 +62,11 @@ void platform_init() nvm_readHwInfo(&hwInfo); /* Load hardware information data */ toneGen_init(); /* Initialise tone generator */ rtc_init(); /* Initialise RTC */ - backlight_init(); /* Initialise backlight driver */ audio_init(); /* Initialise audio management module */ } void platform_terminate() { - /* Shut down backlight */ - backlight_terminate(); - /* Shut down LEDs */ gpio_clearPin(GREEN_LED); gpio_clearPin(RED_LED); @@ -202,9 +197,3 @@ const hwInfo_t *platform_getHwInfo() { return &hwInfo; } - -/* - * NOTE: implementation of this API function is provided in - * platform/drivers/backlight/backlight_MDx.c - */ -// void platform_setBacklightLevel(uint8_t level) diff --git a/platform/targets/MD-9600/platform.c b/platform/targets/MD-9600/platform.c index 962d4a58..fa1255d4 100644 --- a/platform/targets/MD-9600/platform.c +++ b/platform/targets/MD-9600/platform.c @@ -230,10 +230,3 @@ const hwInfo_t *platform_getHwInfo() * platform/drivers/chSelector/chSelector_MD9600.c */ // int8_t platform_getChSelector() - -/* - * NOTE: implementation of this API function is provided in - * platform/drivers/backlight/backlight_MDx.c - */ -// void platform_setBacklightLevel(uint8_t level) - diff --git a/platform/targets/MD-UV3x0/platform.c b/platform/targets/MD-UV3x0/platform.c index ebb95495..f581202f 100644 --- a/platform/targets/MD-UV3x0/platform.c +++ b/platform/targets/MD-UV3x0/platform.c @@ -66,14 +66,10 @@ void platform_init() rtc_init(); /* Initialise RTC */ chSelector_init(); /* Initialise channel selector handler */ audio_init(); /* Initialise audio management module */ - backlight_init(); /* Initialise backlight driver */ } void platform_terminate() { - /* Shut down backlight */ - backlight_terminate(); - /* Shut down LEDs */ gpio_clearPin(GREEN_LED); gpio_clearPin(RED_LED); @@ -200,9 +196,3 @@ const hwInfo_t *platform_getHwInfo() * platform/drivers/chSelector/chSelector_MDUV3x0.c */ // int8_t platform_getChSelector() - -/* - * NOTE: implementation of this API function is provided in - * platform/drivers/backlight/backlight_MDx.c - */ -// void platform_setBacklightLevel(uint8_t level) diff --git a/platform/targets/Module17/platform.c b/platform/targets/Module17/platform.c index 1537afff..f027c17a 100644 --- a/platform/targets/Module17/platform.c +++ b/platform/targets/Module17/platform.c @@ -19,17 +19,14 @@ * along with this program; if not, see * ***************************************************************************/ -#include -#include #include -#include -#include -#include -#include -#include -#include #include +#include +#include #include +#include +#include +#include #include extern mod17Calib_t mod17CalData; @@ -192,8 +189,3 @@ const hwInfo_t *platform_getHwInfo() { return &hwInfo; } - -void platform_setBacklightLevel(uint8_t level) -{ - (void) level; -} diff --git a/platform/targets/linux/platform.c b/platform/targets/linux/platform.c index 2353e68d..85258315 100644 --- a/platform/targets/linux/platform.c +++ b/platform/targets/linux/platform.c @@ -20,10 +20,7 @@ #include #include #include "emulator.h" -#include -/* Custom SDL Event to adjust backlight */ -extern Uint32 SDL_Backlight_Event; static const hwInfo_t hwInfo = { @@ -49,22 +46,6 @@ void platform_terminate() exit(0); } -void platform_setBacklightLevel(uint8_t level) -{ - // Saturate level to 100 and convert value to 0 - 255 - if(level > 100) level = 100; - uint16_t value = (2 * level) + (level * 55)/100; - - SDL_Event e; - SDL_zero(e); - e.type = SDL_Backlight_Event; - e.user.data1 = malloc(sizeof(uint8_t)); - uint8_t *data = (uint8_t *)e.user.data1; - *data = ((uint8_t) value); - - SDL_PushEvent(&e); -} - // Simulate a fully charged lithium battery uint16_t platform_getVbat() {