Miscellaneous work

This commit is contained in:
Th3maz1ng 2023-01-15 20:37:46 +01:00
parent eb2c26d85f
commit 6f8ccb4f6a
9 changed files with 104 additions and 29 deletions

View File

@ -51,7 +51,7 @@
* @brief lcd touch panel
*
*/
#define LCD_TOUCH_PANEL_IRQ WM_IO_PB_00
#define LCD_TOUCH_PANEL_IRQ WM_IO_PB_01
/**
* @brief debug uart
@ -59,4 +59,22 @@
*/
// DEBUG_UART_TX WM_IO_PB_02
/**
* @brief battery voltage divider enable pin
*
*/
#define BATTERY_VOLTAGE_DIVIDER_ENABLE WM_IO_PB_05
/**
* @brief battery voltage adc input pin : WM_IO_PA_04 = channel 1
*
*/
#define BATTERY_VOLTAGE_ADC_CHANNEL (1)
/**
* @brief vibration motor control pin
*
*/
#define VIBRATION_MOTOR_ENABLE WM_IO_PB_03
#endif //APPCONFIG_H

View File

@ -5,7 +5,8 @@ ifndef PDIR
GEN_LIBS = libappdrivers$(LIB_EXT)
COMPONENTS_libappdrivers = lcd/libappdriverslcd$(LIB_EXT) \
mmc_sdio/libappdriversmmc_sdio$(LIB_EXT) \
i2c/libappdriversi2c$(LIB_EXT)
i2c/libappdriversi2c$(LIB_EXT) \
watch_peripherals/libappdriverswatch_peripherals$(LIB_EXT)
endif
#DEFINES +=

View File

@ -13,6 +13,7 @@
#include "QMC5883L.h"
#include "BMP280.h"
#include "bma456w.h"
#include "watch_peripherals.h"
#include "watch_settings.h"
static void date_time_cb(struct tm * const dateTime)
@ -74,10 +75,16 @@ static void setTimeCb(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day,
tls_set_rtc(&timeToSet);
}
static void setTimeoutCb(uint8_t timeout)
{
persistency_get_settings()->display.sleep_timeout = timeout;
}
SettingsScreenAPIInterface_t settingsScreenAPIInterface =
{
.setBrightnessSettingsCb = setBrightnessCb,
.setTimeSettingsCb = setTimeCb
.setTimeSettingsCb = setTimeCb,
.setTimeoutSettingsCb = setTimeoutCb,
};
static uint16_t angle_with_offset(uint16_t angle, uint16_t offset)
@ -113,12 +120,13 @@ void gfx_task(void *param)
{
APP_LOG_TRACE("starting");
/* Initialize the lvgl library*/
/* Initialize the lvgl library and peripherals (display and input device)*/
lv_init();
lv_port_disp_init();
lv_port_indev_init();
/* Initialize lvgl screens */
watch_face_init(&watchFace);
menu_screen_init(&menuScreen);
compass_screen_init(&compassScreen);
@ -233,28 +241,38 @@ void gfx_task(void *param)
else
APP_LOG_INFO("BMA456 set pin conf failed");
watch_peripherals_init(27);
/* Once we are done with the initializing steps we
don't forget to turn the backlight on ! */
setBrightness(persistency_get_settings()->display.brightness);
extern LCDConfig_t LCDConfig;
float temperature = 0;
float pressure = 0;
for(;;)
{
lv_timer_handler();
tls_os_time_delay(5);
if(compass_screen_is_in_use(&compassScreen) && QMC5883L_is_data_available())
if(compass_screen_is_in_use(&compassScreen))
{
/*
QMC5883L_MData_t MDataRaw = QMC5883L_get_MFields_raw();
APP_LOG_TRACE("X %d Y %d Z %d", MDataRaw.MFieldX, MDataRaw.MFieldY, MDataRaw.MFieldZ);
*/
if(QMC5883L_is_data_available())
{
/*
QMC5883L_MData_t MDataRaw = QMC5883L_get_MFields_raw();
APP_LOG_TRACE("X %d Y %d Z %d", MDataRaw.MFieldX, MDataRaw.MFieldY, MDataRaw.MFieldZ);
*/
QMC5883L_MData_calibrated_t MData = QMC5883L_get_MFields_calibrated();
compass_screen_set_azimuth(&compassScreen, angle_with_offset(QMC5883L_get_azimuth(MData), 180));
QMC5883L_MData_calibrated_t MData = QMC5883L_get_MFields_calibrated();
compass_screen_set_azimuth(&compassScreen, angle_with_offset(QMC5883L_get_azimuth(MData), 180));
}
compass_screen_set_temperature(&compassScreen, temperature);
}
uint8_t rslt = bma456w_read_int_status(&int_status, &bma);
if(rslt != BMA4_OK)
APP_LOG_DEBUG("Failed to read int status");
@ -266,14 +284,18 @@ void gfx_task(void *param)
if(++aliveCounter % 200 == 0)
{
float temp = BMP280_get_temperature();
pressure = BMP280_get_pressure(&temperature);
BMP280_trigger_measurement();
APP_LOG_DEBUG("GFX thread, temp : %0.2f", temp);
APP_LOG_DEBUG("GFX thread, temp : %0.2f °C, press : %0.2f hPa, bat : %u mV",
temperature,
pressure/100,
watch_peripherals_get_battery_voltage());
aliveCounter = 0;
}
/* Handle inactivity periods : */
if(lv_disp_get_inactive_time(NULL) > 10000)
if( persistency_get_settings()->display.sleep_timeout != 0 &&
lv_disp_get_inactive_time(NULL) > (persistency_get_settings()->display.sleep_timeout * 1000))
{
// First, we disable the display backlight and we set all the peripherals in their low power mode
setBrightness(0);

View File

@ -8,8 +8,9 @@ static const char *month_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n
static const char *year_options = "22\n23\n24\n25\n26\n27\n28\n29\n30";
static const char *hour_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23";
static const char *minute_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59";
static const char *second_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59";
static const char *second_minute_options = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59";
static const char *timeout_options = "0\n5\n10\n15\n20\n25\n30\n35\n40\n45\n50\n55\n60";
const char *date_format = "dd/mm/yyyy\ndd/mm/yy\nyyyy/mm/dd\nyy/mm/dd";
@ -87,13 +88,24 @@ static void brightness_slider_cb(lv_event_t * e)
SettingsScreen_t *settingsScreen = e->user_data;
if(!settingsScreen->settingsScreenAPIInterface.setBrightnessSettingsCb) return;
lv_obj_t * slider = lv_event_get_target(e);
lv_obj_t *slider = lv_event_get_target(e);
uint8_t brightness = (float)lv_slider_get_value(slider) * 2.55;
if(brightness > 0)
settingsScreen->settingsScreenAPIInterface.setBrightnessSettingsCb(brightness);
}
static void timeout_roller_cb(lv_event_t * e)
{
SettingsScreen_t *settingsScreen = e->user_data;
if(!settingsScreen->settingsScreenAPIInterface.setTimeoutSettingsCb) return;
lv_obj_t *roller = lv_event_get_target(e);
uint8_t timeout = lv_roller_get_selected(roller) * 5;
settingsScreen->settingsScreenAPIInterface.setTimeoutSettingsCb(timeout);
}
static lv_obj_t* add_sidebar_entry_to_menu(lv_obj_t *parent, const char *title, lv_obj_t *menu, lv_obj_t *pageToShow)
{
lv_obj_t *container = lv_menu_cont_create(parent);
@ -230,11 +242,11 @@ void settings_screen_create(SettingsScreen_t * const settingsScreen)
lv_roller_set_visible_row_count(settingsScreen->hour_roller, 2);
lv_obj_add_event_cb(settingsScreen->hour_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen);
lv_roller_set_options(settingsScreen->minute_roller, minute_options, LV_ROLLER_MODE_NORMAL);
lv_roller_set_options(settingsScreen->minute_roller, second_minute_options, LV_ROLLER_MODE_NORMAL);
lv_roller_set_visible_row_count(settingsScreen->minute_roller, 2);
lv_obj_add_event_cb(settingsScreen->minute_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen);
lv_roller_set_options(settingsScreen->second_roller, second_options, LV_ROLLER_MODE_NORMAL);
lv_roller_set_options(settingsScreen->second_roller, second_minute_options, LV_ROLLER_MODE_NORMAL);
lv_roller_set_visible_row_count(settingsScreen->second_roller, 2);
lv_obj_add_event_cb(settingsScreen->second_roller, &(time_roller_cb), LV_EVENT_RELEASED, settingsScreen);
@ -297,8 +309,10 @@ void settings_screen_create(SettingsScreen_t * const settingsScreen)
container = create_section_container(section);
lv_obj_t *timeout = lv_roller_create(container);
lv_roller_set_options(timeout, second_options, LV_ROLLER_MODE_NORMAL);
lv_roller_set_options(timeout, timeout_options, LV_ROLLER_MODE_NORMAL);
lv_roller_set_visible_row_count(timeout, 2);
lv_obj_add_event_cb(timeout, &(timeout_roller_cb), LV_EVENT_RELEASED, settingsScreen);
lv_obj_t *timeout_label = lv_label_create(container);
lv_label_set_text_static(timeout_label, "Second(s)");
lv_obj_set_style_pad_top(timeout_label, 25, LV_PART_MAIN);

View File

@ -7,6 +7,7 @@ typedef struct SettingsScreenAPIInterface
{
void (*setBrightnessSettingsCb)(uint8_t brightness);
void (*setTimeSettingsCb)(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8_t month, uint8_t year);
void (*setTimeoutSettingsCb)(uint8_t timeout);
} SettingsScreenAPIInterface_t;
typedef struct SettingsScreen

View File

@ -4,7 +4,7 @@
static WatchSettings_t watchSettings =
{
.timeAndDate = {.config = 0},
.display = {.brightness = 255, .sleep_timeout = 10,},
.display = {.brightness = 255, .sleep_timeout = 0,},
};
WatchSettings_t *persistency_get_settings(void)

View File

@ -17,7 +17,7 @@
#include "wm_type_def.h"
#define ADC_DEST_BUFFER_SIZE 16383//以字为单位
#define ADC_DEST_BUFFER_SIZE 16383//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>λ
/*ADC Result*/
@ -111,15 +111,15 @@
#define ADC_INT_TYPE_DMA 1
#define ADC_INT_TYPE_ADC_COMP 2
#define ADC_REFERENCE_EXTERNAL 0 //外部参考
#define ADC_REFERENCE_INTERNAL 1 //内部参考
#define ADC_REFERENCE_EXTERNAL 0 //<EFBFBD>ⲿ<EFBFBD>ο<EFBFBD>
#define ADC_REFERENCE_INTERNAL 1 //<EFBFBD>ڲ<EFBFBD><EFBFBD>ο<EFBFBD>
typedef struct adc_st{
u8 dmachannel;
void (*adc_cb)(int *buf, u16 len);
void (*adc_bigger_cb)(int *buf, u16 len);
void (*adc_dma_cb)(int *buf,u16 len);
u16 valuelen; /*dma 采样数据长度*/
u16 valuelen; /*dma <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>*/
u16 offset;
}ST_ADC;
@ -270,7 +270,7 @@ int adc_get_interTemp(void);
*
* @note None
*/
int adc_get_inputVolt(u8 channel);
int adc_get_inputVolt(u8 channel, u8 gain1, u8 gain2);
/**
* @brief This function is used to read internal voltage.

View File

@ -13,6 +13,9 @@
#include "wm_gpio.h"
#include "app_config.h"
#include "CST816D.h"
#include "watch_peripherals.h"
#include "app_log.h"
/*********************
* DEFINES
@ -45,6 +48,21 @@ static void touch_panel_isr(void *arg)
tls_clr_gpio_irq_status(LCD_TOUCH_PANEL_IRQ);
CST816D_read_touch_event(p);
}
void touch_panel_feedback_cb(struct _lv_indev_drv_t *lv_indev_drv, uint8_t lv_event_code)
{
(void)lv_indev_drv;
switch(lv_event_code)
{
case LV_EVENT_LONG_PRESSED:
watch_peripherals_vibrate(255, 200);
break;
case LV_EVENT_PRESSED:
watch_peripherals_vibrate(200, 200);
break;
}
}
/**********************
* GLOBAL FUNCTIONS
**********************/
@ -83,6 +101,7 @@ void lv_port_indev_init(void)
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = touchpad_read;
indev_drv.user_data = &CST816D_Touch_Data;
indev_drv.feedback_cb = &(touch_panel_feedback_cb);
indev_touchpad = lv_indev_drv_register(&indev_drv);
}

View File

@ -526,7 +526,7 @@ int adc_get_interTemp(void)
return adc_temp();
}
int adc_get_inputVolt(u8 channel)
int adc_get_inputVolt(u8 channel, u8 gain1, u8 gain2)
{
int average = 0;
double voltage = 0.0;
@ -538,7 +538,7 @@ int adc_get_inputVolt(u8 channel)
tls_adc_init(0, 0);
tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
tls_adc_set_pga(1,1);
tls_adc_set_pga(gain1, gain2);
tls_adc_set_clk(0x28);
tls_adc_start_with_cpu(channel);