From 0a1737591d2070b17b137fd9eb24e718907e8aa7 Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Sun, 22 Jan 2023 21:20:03 +0100 Subject: [PATCH] Added a simple implementation of adaptive MCU core clock to save power, displayed the current core clock in the main task, minor changes to the app_config file --- src/W800 SDK v1.00.08/app/app_config.h | 5 +-- .../watch_peripherals/watch_peripherals.c | 9 +++-- src/W800 SDK v1.00.08/app/gfx/gfx_task.c | 33 +++++++++++++++++++ src/W800 SDK v1.00.08/app/main.c | 5 ++- .../lvgl/lvgl_port/lv_port_indev.c | 25 ++++++++++++-- 5 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/W800 SDK v1.00.08/app/app_config.h b/src/W800 SDK v1.00.08/app/app_config.h index 3d98391..4202a0e 100644 --- a/src/W800 SDK v1.00.08/app/app_config.h +++ b/src/W800 SDK v1.00.08/app/app_config.h @@ -45,7 +45,7 @@ #define LCD_DATA_COMMAND WM_IO_PB_08 #define LCD_RESET WM_IO_PB_09 #define LCD_PWM_BACKLIGHT WM_IO_PA_07 -#define LCD_PWM_CHANNEL 4 +#define LCD_PWM_CHANNEL (4) /** * @brief lcd touch panel @@ -75,6 +75,7 @@ * @brief vibration motor control pin * */ -#define VIBRATION_MOTOR_ENABLE WM_IO_PB_03 +#define VIBRATION_MOTOR_ENABLE WM_IO_PB_00 +#define VIBRATION_MOTOR_PWM_CHANNEL (0) #endif //APPCONFIG_H \ No newline at end of file diff --git a/src/W800 SDK v1.00.08/app/app_drivers/watch_peripherals/watch_peripherals.c b/src/W800 SDK v1.00.08/app/app_drivers/watch_peripherals/watch_peripherals.c index faa784e..23407e8 100644 --- a/src/W800 SDK v1.00.08/app/app_drivers/watch_peripherals/watch_peripherals.c +++ b/src/W800 SDK v1.00.08/app/app_drivers/watch_peripherals/watch_peripherals.c @@ -14,7 +14,7 @@ static void vibration_motor_timer_irq_cb(void *p) { (void)p; //tls_gpio_write(VIBRATION_MOTOR_ENABLE, 0); - tls_pwm_stop(3); + tls_pwm_stop(VIBRATION_MOTOR_PWM_CHANNEL); tls_gpio_cfg(VIBRATION_MOTOR_ENABLE, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING); tls_gpio_write(VIBRATION_MOTOR_ENABLE, 0); APP_LOG_DEBUG("Vibration stopped"); @@ -69,9 +69,8 @@ void watch_peripherals_vibrate(uint8_t strength, uint32_t durationMs) APP_LOG_DEBUG("Vibration started"); /* We start the timer which will stop the vibration after durationMs time */ tls_timer_change(_vibration_motor_timer_id, durationMs); - //tls_gpio_write(VIBRATION_MOTOR_ENABLE, 1); - wm_pwm3_config(VIBRATION_MOTOR_ENABLE); - tls_pwm_init(3, 10000, 0, 0); - tls_pwm_duty_set(3, strength); + wm_pwm0_config(VIBRATION_MOTOR_ENABLE); + tls_pwm_init(VIBRATION_MOTOR_PWM_CHANNEL, 10000, 0, 0); + tls_pwm_duty_set(VIBRATION_MOTOR_PWM_CHANNEL, strength); tls_timer_start(_vibration_motor_timer_id); } 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 4514dd5..50c53b5 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 @@ -80,11 +80,21 @@ static void setTimeoutCb(uint8_t timeout) persistency_get_settings()->display.sleep_timeout = timeout; } +static void setOrientationCb(uint8_t orientation) +{ + extern LCDConfig_t LCDConfig; + lcd_orientation(&LCDConfig, orientation); + persistency_get_settings()->display.orientation = orientation; + // Forces to redraw the full screen to avoid strange artifact + lv_obj_invalidate(lv_scr_act()); +} + SettingsScreenAPIInterface_t settingsScreenAPIInterface = { .setBrightnessSettingsCb = setBrightnessCb, .setTimeSettingsCb = setTimeCb, .setTimeoutSettingsCb = setTimeoutCb, + .setOrientationSettingsCb = setOrientationCb, }; static uint16_t angle_with_offset(uint16_t angle, uint16_t offset) @@ -302,6 +312,7 @@ void gfx_task(void *param) //lcd_on(&LCDConfig, false); lcd_sleep(&LCDConfig, true); QMC5883L_set_power_mode(Standby); + CST816D_set_power_mode(); // 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 ? @@ -313,5 +324,27 @@ void gfx_task(void *param) lcd_sleep(&LCDConfig, false); setBrightness(persistency_get_settings()->display.brightness); } + + /* Throttle CPU freq down when inactive to save power or to increase responsiveness */ + tls_sys_clk clk; + tls_sys_clk_get(&clk); + if(lv_disp_get_inactive_time(NULL) > 5000) + { + if(clk.cpuclk != 40) + { + tls_sys_clk_set(CPU_CLK_40M); + APP_LOG_DEBUG("CPU 40Mhz"); + } + + } + else + { + if(clk.cpuclk != 160) + { + tls_sys_clk_set(CPU_CLK_160M); + APP_LOG_DEBUG("CPU 160Mhz"); + } + + } } } \ No newline at end of file diff --git a/src/W800 SDK v1.00.08/app/main.c b/src/W800 SDK v1.00.08/app/main.c index bb2a9de..05ef144 100644 --- a/src/W800 SDK v1.00.08/app/main.c +++ b/src/W800 SDK v1.00.08/app/main.c @@ -32,14 +32,17 @@ void user_task_main(void *param) TickType_t time_ref = tls_os_get_time(); for(;;) { + tls_sys_clk clk; + tls_sys_clk_get(&clk); char *buf = tls_mem_alloc(800); if(buf) { UBaseType_t writtenSize = vTaskList((char *)buf, 800); - APP_LOG_INFO("Available RAM (bytes)/Total RAM (bytes) : %u/%u"NEW_LINE"Reset reason : %d"NEW_LINE"Tasks (%lu) :"NEW_LINE, + APP_LOG_INFO("Available RAM (bytes)/Total RAM (bytes) : %u/%u"NEW_LINE"Reset reason : %d"NEW_LINE"Clk : apb(%u), cpu(%u), wlan(%u)"NEW_LINE"Tasks (%lu) :"NEW_LINE, tls_mem_get_avail_heapsize(), total_mem_size, tls_sys_get_reboot_reason(), + clk.apbclk, clk.cpuclk, clk.wlanclk, writtenSize); printf("\n%s", buf); tls_mem_free(buf); diff --git a/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c b/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c index 35f9d35..e9d2c9c 100644 --- a/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c +++ b/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c @@ -12,6 +12,7 @@ #include "lv_port_indev.h" #include "wm_gpio.h" #include "app_config.h" +#include "lcd.h" #include "CST816D.h" #include "watch_peripherals.h" @@ -115,6 +116,7 @@ void lv_port_indev_init(void) static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { + extern LCDConfig_t LCDConfig; static lv_coord_t last_x = 0; static lv_coord_t last_y = 0; @@ -130,9 +132,26 @@ static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) data->state = LV_INDEV_STATE_REL; } - // Set the last pressed coordinates - data->point.x = 239-last_x; - data->point.y = 239-last_y; + // Set the last pressed coordinates taking into account the current display orientation + switch(LCDConfig.LCDOrientation) + { + case LCD_ORIENTATION_90: + data->point.x = 239-last_y; + data->point.y = last_x; + break; + case LCD_ORIENTATION_180: + data->point.x = last_x; + data->point.y = last_y; + break; + case LCD_ORIENTATION_270: + data->point.x = last_y; + data->point.y = 239-last_x; + break; + default: + data->point.x = 239-last_x; + data->point.y = 239-last_y; + break; + } } #else /*Enable this file at the top*/