diff --git a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c index 337e324..0a2c264 100644 --- a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c +++ b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c @@ -7,8 +7,9 @@ #include "wm_pwm.h" #include "i2c.h" #include "BMP280.h" -#include "FreeRTOS.h" // <---- Only needed for the pdMS_TO_TICKS macro, to be removed #include "bma456w.h" +#include "CST816D.h" +#include "app_utils.h" #define INTERRUPT_POLICY (0) #define POLL_POLICY (1) @@ -25,6 +26,10 @@ static uint8_t _vibration_motor_timer_id = WM_TIMER_ID_INVALID; static battery_controller_status_e _battery_fsm = BATTERY_CONTROLLER_STATUS_DISCHARGING; static BatteryControllerStatusChangeCb_t _BatteryControllerStatusChangeCb = NULL; +/* Wakeup source boolean */ +static bool _wakeup_is_io = false; +static bool _wakeup_is_timer = false; + /* BMA456 strcture */ struct { @@ -128,6 +133,23 @@ static void battery_controller_irq_cb(void *p) } #endif +typedef enum wakeup_source +{ + WAKEUP_SOURCE_IO = 0, + WAKEUP_SOURCE_TIMER, +} wakeup_source_e; + +static void pmu_wakeup_source_irq_cb(void *arg) +{ + wakeup_source_e wakeup_source = (wakeup_source_e)arg; + + if(wakeup_source == WAKEUP_SOURCE_IO) + _wakeup_is_io = true; + + if(wakeup_source == WAKEUP_SOURCE_TIMER) + _wakeup_is_timer = true; +} + static void watch_peripherals_io_init(void) { /* We initialize the ADC input as well as the gpio used to enabled the voltage divider bridge */ @@ -150,6 +172,10 @@ static void watch_peripherals_io_init(void) tls_gpio_isr_register(BATTERY_CONTROLLER_CHARGING_STATUS, &(battery_controller_irq_cb), (int*) BATTERY_CONTROLLER_CHARGING_STATUS); tls_gpio_irq_enable(BATTERY_CONTROLLER_CHARGING_STATUS, WM_GPIO_IRQ_TRIG_DOUBLE_EDGE); // Enabled when level is changing edge #endif + + /* We register the IRQs needed to determine the watch wake up source/reason */ + tls_pmu_gpio_isr_register(&(pmu_wakeup_source_irq_cb), (void *)WAKEUP_SOURCE_IO); + tls_pmu_timer0_isr_register(&(pmu_wakeup_source_irq_cb), (void *)WAKEUP_SOURCE_TIMER); } #ifndef CASE_RETURN_STR @@ -289,6 +315,26 @@ void watch_peripherals_set_orientation(LCDOrientation_e orientation) lcd_orientation(&LCDConfig, orientation); } +bool watch_peripherals_wakeup_source_is_user(void) +{ + if(_wakeup_is_io) + { + _wakeup_is_io = false; + return true; + } + return false; +} + +bool watch_peripherals_wakeup_source_is_timer(void) +{ + if(_wakeup_is_timer) + { + _wakeup_is_timer = false; + return true; + } + return false; +} + bool watch_peripherals_magnetometer_init(void) { /* Init the magnetometer */ @@ -405,11 +451,7 @@ static BMA4_INTF_RET_TYPE _bma4_i2c_write(uint8_t reg_addr, const uint8_t *read_ static void _bma4_delay_us(uint32_t period, void *intf_ptr) { (void) intf_ptr; - - if(period < 1000) - tls_os_time_delay(1); - else - tls_os_time_delay(pdMS_TO_TICKS(period / 1000)); + us_delay(period); } bool watch_peripherals_accelerometer_init(void) @@ -594,3 +636,17 @@ bool watch_peripherals_accelerometer_step_count_reset(void) return true; } + +void watch_peripherals_watch_sleep(void) +{ + extern LCDConfig_t LCDConfig; + // First, we disable the display backlight and we set all the peripherals in their low power mode + lcd_set_backlight(&LCDConfig, 0); + //lcd_on(&LCDConfig, false); + lcd_sleep(&LCDConfig, true); + watch_peripherals_magnetometer_power_mode_set(QMC5883L_Mode_Control_Standby); + if(CST816D_sleep()) + APP_LOG_DEBUG("CST816D Sleep cmd ok"); + else + APP_LOG_ERROR("CST816D Sleep cmd fail"); +} diff --git a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.h b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.h index 1a3402c..0ff1646 100644 --- a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.h +++ b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.h @@ -101,6 +101,22 @@ void watch_peripherals_set_brightness(uint8_t brightness); */ void watch_peripherals_set_orientation(LCDOrientation_e orientation); +/** + * @brief Check if the watch woke up because of the user(trigger on the wakeup pin : wrist tilt or touch screen). + * + * @return true if the source of the wakeup is the user + * @return false otherwise + */ +bool watch_peripherals_wakeup_source_is_user(void); + +/** + * @brief Check if the watch woke up because of a timed event (timer 0 of the PMU module). + * + * @return true if the source of the wake up is the timer 0 + * @return false otherwise + */ +bool watch_peripherals_wakeup_source_is_timer(void); + bool watch_peripherals_magnetometer_init(void); void watch_peripherals_magnetometer_calibration_data_set( @@ -131,4 +147,6 @@ bool watch_peripherals_accelerometer_step_count_read(uint32_t *step_count); bool watch_peripherals_accelerometer_step_count_reset(void); +void watch_peripherals_watch_sleep(void); + #endif //WATCH_PERIPHERALS_H \ No newline at end of file