From 0ec9b4246bd2663377168ed70c2e8ecf89af77ae Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Sun, 8 Jan 2023 22:16:37 +0100 Subject: [PATCH] Added lcd off and lcd power down functions to the API. This improves sleep current which is around 4.5mA instead of 12mA --- .../app/app_drivers/lcd/lcd.c | 28 +++++++++++++++++++ .../app/app_drivers/lcd/lcd.h | 21 ++++++++++++-- .../app/app_drivers/mmc_sdio/mmc_sdio.c | 6 ++++ src/W800 SDK v1.00.08/app/gfx/gfx_task.c | 8 ++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/W800 SDK v1.00.08/app/app_drivers/lcd/lcd.c b/src/W800 SDK v1.00.08/app/app_drivers/lcd/lcd.c index ba22325..b52f5f8 100644 --- a/src/W800 SDK v1.00.08/app/app_drivers/lcd/lcd.c +++ b/src/W800 SDK v1.00.08/app/app_drivers/lcd/lcd.c @@ -382,11 +382,39 @@ void lcd_set_backlight(LCDConfig_t * const LCDConfig, uint8_t brightness) void lcd_hardware_reset(LCDConfig_t * const LCDConfig) { + if(!LCDConfig) return; + tls_gpio_write(LCDConfig->LCDResetPin, 0); tls_os_time_delay(1); tls_gpio_write(LCDConfig->LCDResetPin, 1); } +void lcd_on(LCDConfig_t *const LCDConfig, bool state) +{ + if(!LCDConfig) return; + + lcd_set_data_command(LCDConfig, LCD_COMMAND); + lcd_set_cs(LCDConfig, LCD_SELECTED); + + mmc_sdio_driver_write_one(state ? 0x29 : 0x28); + + lcd_set_cs(LCDConfig, LCD_RELEASED); + lcd_set_data_command(LCDConfig, LCD_DATA); +} + +void lcd_sleep(LCDConfig_t *const LCDConfig, bool state) +{ + if(!LCDConfig) return; + + lcd_set_data_command(LCDConfig, LCD_COMMAND); + lcd_set_cs(LCDConfig, LCD_SELECTED); + + mmc_sdio_driver_write_one(state ? 0x10 : 0x11); + + lcd_set_cs(LCDConfig, LCD_RELEASED); + lcd_set_data_command(LCDConfig, LCD_DATA); +} + static void lcd_write_cmd_data_bytes(LCDConfig_t * const LCDConfig, const uint8_t *cmdAndData, uint32_t dataLengthInBytes) { // Select the slave CS line and tell him that he will receive a command ! diff --git a/src/W800 SDK v1.00.08/app/app_drivers/lcd/lcd.h b/src/W800 SDK v1.00.08/app/app_drivers/lcd/lcd.h index 64281f4..bd7180e 100644 --- a/src/W800 SDK v1.00.08/app/app_drivers/lcd/lcd.h +++ b/src/W800 SDK v1.00.08/app/app_drivers/lcd/lcd.h @@ -92,7 +92,7 @@ void lcd_draw_rect_frame(LCDConfig_t * const LCDConfig, uint16_t x, uint16_t y, /** * @brief Sets the backlight to the specified brightness value * - * @param LCDConfig a pointer a user allocated LCDConfig_t structure + * @param LCDConfig a pointer a user allocated LCDConfig_t structure * @param brightness a value from 0 (backlight off) to 255 backlight fully on. */ void lcd_set_backlight(LCDConfig_t * const LCDConfig, uint8_t brightness); @@ -100,8 +100,25 @@ void lcd_set_backlight(LCDConfig_t * const LCDConfig, uint8_t brightness); /** * @brief Issues a hardware reset of the lcd display * - * @param LCDConfig a pointer a user allocated LCDConfig_t structure + * @param LCDConfig a pointer a user allocated LCDConfig_t structure */ void lcd_hardware_reset(LCDConfig_t * const LCDConfig); +/** + * @brief Turns the LCD on or off, /!\ not the same as sleep mode ! + * + * @param LCDConfig a pointer a user allocated LCDConfig_t structure + * @param state true to turn the LCD on or false to turn it off + */ +void lcd_on(LCDConfig_t * const LCDConfig, bool state); + +/** + * @brief Puts the LCD in power down mode (sleep) or power up mode (active) + * Sleep mode puts the LCD in it's lowest power state + * + * @param LCDConfig a pointer a user allocated LCDConfig_t structure + * @param state true to put the LCD in sleep mode or false to put it in active mode + */ +void lcd_sleep(LCDConfig_t * const LCDConfig, bool state); + #endif //LCD_H \ No newline at end of file diff --git a/src/W800 SDK v1.00.08/app/app_drivers/mmc_sdio/mmc_sdio.c b/src/W800 SDK v1.00.08/app/app_drivers/mmc_sdio/mmc_sdio.c index 6f24609..0dbe660 100644 --- a/src/W800 SDK v1.00.08/app/app_drivers/mmc_sdio/mmc_sdio.c +++ b/src/W800 SDK v1.00.08/app/app_drivers/mmc_sdio/mmc_sdio.c @@ -98,6 +98,9 @@ void mmc_sdio_driver_write_dma_async(uint32_t *data, uint32_t dataLengthInBytes) void mmc_sdio_driver_write_one(uint8_t data) { + /* Wait for MMC device to be ready to send the data */ + while (SDIO_HOST->MMC_IO & 0x01); + SDIO_HOST->BUF_CTL = 0x4820; SDIO_HOST->DATA_BUF[0] = (uint32_t)data; SDIO_HOST->MMC_BYTECNTL = 1U; @@ -109,6 +112,9 @@ void mmc_sdio_driver_write_one(uint8_t data) void mmc_sdio_driver_write(const uint8_t *data, uint16_t dataLengthInBytes) { + /* Wait for MMC device to be ready to send the data */ + while (SDIO_HOST->MMC_IO & 0x01); + SDIO_HOST->BUF_CTL = 0x4820; memcpy((void *)SDIO_HOST->DATA_BUF, (void *)data, dataLengthInBytes); SDIO_HOST->MMC_BYTECNTL = dataLengthInBytes; diff --git a/src/W800 SDK v1.00.08/app/gfx/gfx_task.c b/src/W800 SDK v1.00.08/app/gfx/gfx_task.c index 5122683..ee492f2 100644 --- a/src/W800 SDK v1.00.08/app/gfx/gfx_task.c +++ b/src/W800 SDK v1.00.08/app/gfx/gfx_task.c @@ -237,6 +237,8 @@ void gfx_task(void *param) don't forget to turn the backlight on ! */ setBrightness(persistency_get_settings()->display.brightness); + extern LCDConfig_t LCDConfig; + for(;;) { lv_timer_handler(); @@ -275,12 +277,18 @@ void gfx_task(void *param) { // First, we disable the display backlight and we set all the peripherals in their low power mode setBrightness(0); + //lcd_on(&LCDConfig, false); + lcd_sleep(&LCDConfig, true); + QMC5883L_set_power_mode(Standby); // Let's sleep tls_pmu_sleep_start(); // On wake up, we force the watch face to sync up with the rtc /!\ RTC update delay WTF ? tls_os_time_delay(1); watch_face_force_sync(&watchFace); lv_disp_trig_activity(NULL); + QMC5883L_set_power_mode(Continuous); + //lcd_on(&LCDConfig, true); + lcd_sleep(&LCDConfig, false); setBrightness(persistency_get_settings()->display.brightness); } }