initial clock mode impl

This commit is contained in:
Shuanglei Tao
2025-03-26 15:45:51 +08:00
parent f5cd6b431b
commit 3f9ec9de1b
19 changed files with 578 additions and 277 deletions

View File

@@ -1,5 +1,5 @@
#ifndef EPD_CONFIG_H__
#define EPD_CONFIG_H__
#ifndef __EPD_CONFIG_H
#define __EPD_CONFIG_H
#include <stdbool.h>
#include <stdint.h>

View File

@@ -336,6 +336,50 @@ void EPD_LED_BLINK(void)
}
}
float EPD_ReadVoltage(void)
{
#if defined(S112)
volatile int16_t value = 0;
NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_10bit;
NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos);
NRF_SAADC->CH[0].CONFIG = ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) & SAADC_CH_CONFIG_RESP_Msk)
| ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESN_Pos) & SAADC_CH_CONFIG_RESN_Msk)
| ((SAADC_CH_CONFIG_GAIN_Gain1_6 << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk)
| ((SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk)
| ((SAADC_CH_CONFIG_TACQ_3us << SAADC_CH_CONFIG_TACQ_Pos) & SAADC_CH_CONFIG_TACQ_Msk)
| ((SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk);
NRF_SAADC->CH[0].PSELN = SAADC_CH_PSELN_PSELN_NC;
NRF_SAADC->CH[0].PSELP = SAADC_CH_PSELP_PSELP_VDD;
NRF_SAADC->RESULT.PTR = (uint32_t)&value;
NRF_SAADC->RESULT.MAXCNT = 1;
NRF_SAADC->TASKS_START = 0x01UL;
while (!NRF_SAADC->EVENTS_STARTED);
NRF_SAADC->EVENTS_STARTED = 0x00UL;
NRF_SAADC->TASKS_SAMPLE = 0x01UL;
while (!NRF_SAADC->EVENTS_END);
NRF_SAADC->EVENTS_END = 0x00UL;
NRF_SAADC->TASKS_STOP = 0x01UL;
while (!NRF_SAADC->EVENTS_STOPPED);
NRF_SAADC->EVENTS_STOPPED = 0x00UL;
if (value < 0) value = 0;
NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos);
#else
NRF_ADC->ENABLE = 1;
NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) |
(ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) |
(ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
(ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos) |
(ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
NRF_ADC->TASKS_START = 1;
while(!NRF_ADC->EVENTS_END);
uint16_t value = NRF_ADC->RESULT;
NRF_ADC->TASKS_STOP = 1;
NRF_ADC->ENABLE = 0;
#endif
NRF_LOG_DEBUG("ADC value: %d\n", value);
return (value * 3.6) / (1 << 10);
}
// EPD models
extern epd_model_t epd_uc8176_420_bw;
extern epd_model_t epd_uc8176_420_bwr;

View File

@@ -93,12 +93,15 @@ void EPD_WriteData(uint8_t *Data, uint8_t Len);
void EPD_Reset(uint32_t value, uint16_t duration);
void EPD_WaitBusy(uint32_t value, uint16_t timeout);
// lED
// LED
void EPD_LED_ON(void);
void EPD_LED_OFF(void);
void EPD_LED_Toggle(void);
void EPD_LED_BLINK(void);
// VDD voltage
float EPD_ReadVoltage(void);
epd_model_t *epd_get(void);
epd_model_t *epd_init(epd_model_id_t id);

View File

@@ -17,14 +17,13 @@
#include "nrf_gpio.h"
#include "app_scheduler.h"
#include "EPD_service.h"
#include "Calendar.h"
#include "nrf_log.h"
#if defined(S112)
//#define EPD_CFG_DEFAULT {0x14, 0x13, 0x06, 0x05, 0x04, 0x03, 0x02, 0x03, 0xFF, 0x12, 0x07} // 52811
#define EPD_CFG_DEFAULT {0x14, 0x13, 0x12, 0x11, 0x10, 0x0F, 0x0E, 0x03, 0xFF, 0x0D, 0x02} // 52810
#else
#define EPD_CFG_DEFAULT {0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x07}
//#define EPD_CFG_DEFAULT {0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x07}
#endif
#ifndef EPD_CFG_DEFAULT
@@ -59,16 +58,14 @@ static void epd_gpio_uninit()
}
}
static void calendar_update(void * p_event_data, uint16_t event_size)
static void epd_gui_update(void * p_event_data, uint16_t event_size)
{
epd_calendar_update_event_t *event = (epd_calendar_update_event_t *)p_event_data;
epd_gui_update_event_t *event = (epd_gui_update_event_t *)p_event_data;
ble_epd_t *p_epd = event->p_epd;
p_epd->calendar_mode = true;
epd_gpio_init();
epd_model_t *epd = epd_init((epd_model_id_t)p_epd->config.model_id);
DrawCalendar(epd, event->timestamp);
DrawGUI(epd, event->timestamp, p_epd->display_mode);
epd_gpio_uninit();
}
@@ -138,7 +135,7 @@ static void epd_service_process(ble_epd_t * p_epd, uint8_t * p_data, uint16_t le
} break;
case EPD_CMD_CLEAR:
p_epd->calendar_mode = false;
p_epd->display_mode = MODE_NONE;
p_epd->epd->drv->clear();
break;
@@ -152,7 +149,7 @@ static void epd_service_process(ble_epd_t * p_epd, uint8_t * p_data, uint16_t le
break;
case EPD_CMD_DISPLAY:
p_epd->calendar_mode = false;
p_epd->display_mode = MODE_NONE;
p_epd->epd->drv->refresh();
break;
@@ -359,9 +356,11 @@ uint32_t ble_epd_string_send(ble_epd_t * p_epd, uint8_t * p_string, uint16_t len
void ble_epd_on_timer(ble_epd_t * p_epd, uint32_t timestamp, bool force_update)
{
// Update calendar on 00:00:00
if (force_update || (p_epd->calendar_mode && timestamp % 86400 == 0)) {
epd_calendar_update_event_t event = { p_epd, timestamp };
app_sched_event_put(&event, sizeof(epd_calendar_update_event_t), calendar_update);
// Update calendar on 00:00:00, clock on every minute
if (force_update ||
(p_epd->display_mode == MODE_CALENDAR && timestamp % 86400 == 0) ||
(p_epd->display_mode == MODE_CLOCK && timestamp % 60 == 0)) {
epd_gui_update_event_t event = { p_epd, timestamp };
app_sched_event_put(&event, sizeof(epd_gui_update_event_t), epd_gui_update);
}
}

View File

@@ -10,8 +10,8 @@
*
*/
#ifndef EPD_SERVICE_H__
#define EPD_SERVICE_H__
#ifndef __EPD_SERVICE_H
#define __EPD_SERVICE_H
#include <stdint.h>
#include <stdbool.h>
@@ -23,6 +23,7 @@
#include "sdk_config.h"
#include "EPD_driver.h"
#include "EPD_config.h"
#include "GUI.h"
/**@brief Macro for defining a ble_hts instance.
*
@@ -85,16 +86,16 @@ typedef struct
epd_model_t *epd; /**< current EPD model */
epd_config_t config; /**< EPD config */
epd_callback_t epd_cmd_cb; /**< EPD callback */
bool calendar_mode; /**< Calendar mode flag */
display_mode_t display_mode; /**< gui display mode */
} ble_epd_t;
typedef struct
{
ble_epd_t *p_epd;
uint32_t timestamp;
} epd_calendar_update_event_t;
} epd_gui_update_event_t;
#define EPD_CALENDAR_SCHD_EVENT_DATA_SIZE sizeof(epd_calendar_update_event_t)
#define EPD_GUI_SCHD_EVENT_DATA_SIZE sizeof(epd_gui_update_event_t)
/**@brief Function for preparing sleep mode.
*