Added new folder/module containing the API to interract with some of the watch feature like measuring the battery voltage or activating the vibration motor
This commit is contained in:
parent
42553f737b
commit
eb2c26d85f
@ -0,0 +1,15 @@
|
|||||||
|
TOP_DIR = ../../..
|
||||||
|
sinclude $(TOP_DIR)/tools/w800/conf.mk
|
||||||
|
|
||||||
|
ifndef PDIR
|
||||||
|
GEN_LIBS = libappdriverswatch_peripherals$(LIB_EXT)
|
||||||
|
endif
|
||||||
|
|
||||||
|
#DEFINES +=
|
||||||
|
|
||||||
|
sinclude $(TOP_DIR)/tools/w800/rules.mk
|
||||||
|
|
||||||
|
INCLUDES := $(INCLUDES) -I $(PDIR)include
|
||||||
|
|
||||||
|
PDIR := ../$(PDIR)
|
||||||
|
sinclude $(PDIR)Makefile
|
@ -0,0 +1,77 @@
|
|||||||
|
#include "watch_peripherals.h"
|
||||||
|
#include "app_config.h"
|
||||||
|
#include "app_log.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
#include "wm_adc.h"
|
||||||
|
#include "wm_timer.h"
|
||||||
|
#include "wm_pwm.h"
|
||||||
|
|
||||||
|
|
||||||
|
static uint8_t _adc_offset = 0;
|
||||||
|
static uint8_t _vibration_motor_timer_id = WM_TIMER_ID_INVALID;
|
||||||
|
|
||||||
|
static void vibration_motor_timer_irq_cb(void *p)
|
||||||
|
{
|
||||||
|
(void)p;
|
||||||
|
//tls_gpio_write(VIBRATION_MOTOR_ENABLE, 0);
|
||||||
|
tls_pwm_stop(3);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
void watch_peripherals_io_init(void)
|
||||||
|
{
|
||||||
|
/* We initialize the ADC input as well as the gpio used to enabled the voltage divider bridge */
|
||||||
|
wm_adc_config(BATTERY_VOLTAGE_ADC_CHANNEL);
|
||||||
|
tls_gpio_cfg(BATTERY_VOLTAGE_DIVIDER_ENABLE, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
|
||||||
|
tls_gpio_write(BATTERY_VOLTAGE_DIVIDER_ENABLE, 0);
|
||||||
|
|
||||||
|
/* We initialize the output pin for the vibration motor enable pin */
|
||||||
|
/*tls_gpio_cfg(VIBRATION_MOTOR_ENABLE, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
|
||||||
|
tls_gpio_write(VIBRATION_MOTOR_ENABLE, 0);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void watch_peripherals_init(uint8_t adcOffset)
|
||||||
|
{
|
||||||
|
watch_peripherals_io_init();
|
||||||
|
_adc_offset = adcOffset;
|
||||||
|
|
||||||
|
/* Prevent multiple init call !*/
|
||||||
|
if(WM_TIMER_ID_INVALID == _vibration_motor_timer_id)
|
||||||
|
{
|
||||||
|
/* Let's initialize the timer w'll use to stop the vibration motor */
|
||||||
|
struct tls_timer_cfg vibration_motor_timer_cfg =
|
||||||
|
{
|
||||||
|
.arg = NULL,
|
||||||
|
.callback = &(vibration_motor_timer_irq_cb),
|
||||||
|
.unit = TLS_TIMER_UNIT_MS,
|
||||||
|
.is_repeat = false,
|
||||||
|
.timeout = 0
|
||||||
|
};
|
||||||
|
_vibration_motor_timer_id = tls_timer_create(&vibration_motor_timer_cfg);
|
||||||
|
|
||||||
|
if(WM_TIMER_ID_INVALID == _vibration_motor_timer_id)
|
||||||
|
APP_LOG_ERROR("Failed to create timer");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t watch_peripherals_get_battery_voltage(void)
|
||||||
|
{
|
||||||
|
tls_gpio_write(BATTERY_VOLTAGE_DIVIDER_ENABLE, 1);
|
||||||
|
int batteryVoltage = adc_get_inputVolt(BATTERY_VOLTAGE_ADC_CHANNEL, 1, 1) * 2 + _adc_offset;
|
||||||
|
tls_gpio_write(BATTERY_VOLTAGE_DIVIDER_ENABLE, 0);
|
||||||
|
return batteryVoltage < 0 ? 0 : batteryVoltage;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
tls_timer_start(_vibration_motor_timer_id);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Declares various functions to interract with some of the watch's
|
||||||
|
* peripherals like : reading the battery voltage, using the vibration motor etc.
|
||||||
|
*/
|
||||||
|
#ifndef WATCH_PERIPHERALS_H
|
||||||
|
#define WATCH_PERIPHERALS_H
|
||||||
|
#include "wm_type_def.h"
|
||||||
|
|
||||||
|
void watch_peripherals_io_init(void);
|
||||||
|
|
||||||
|
void watch_peripherals_init(uint8_t adcOffset);
|
||||||
|
|
||||||
|
uint16_t watch_peripherals_get_battery_voltage(void);
|
||||||
|
|
||||||
|
uint8_t watch_peripherals_battery_voltage_to_level(uint16_t voltage);
|
||||||
|
|
||||||
|
void watch_peripherals_vibrate(uint8_t strength, uint32_t durationMs);
|
||||||
|
|
||||||
|
#endif //WATCH_PERIPHERALS_H
|
Loading…
Reference in New Issue
Block a user