mirror of
https://github.com/pengwon/epd42.git
synced 2025-12-17 17:28:15 +08:00
add led and wakeup support
This commit is contained in:
@@ -13,7 +13,10 @@
|
||||
#include <string.h>
|
||||
#include "nordic_common.h"
|
||||
#include "ble_srv_common.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_nvmc.h"
|
||||
#include "nrf_soc.h"
|
||||
#include "nrf_log.h"
|
||||
#include "EPD_4in2.h"
|
||||
#include "EPD_4in2_V2.h"
|
||||
@@ -26,6 +29,7 @@
|
||||
#define BLE_UUID_EPD_CHARACTERISTIC 0x0002
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#define EPD_CONFIG_SIZE (sizeof(epd_config_t) / sizeof(uint8_t))
|
||||
|
||||
/** EPD drivers */
|
||||
static epd_driver_t epd_drivers[] = {
|
||||
@@ -60,7 +64,7 @@ static void epd_config_load(epd_config_t *cfg)
|
||||
static void epd_config_save(epd_config_t *cfg)
|
||||
{
|
||||
nrf_nvmc_page_erase(BLE_EPD_CONFIG_ADDR);
|
||||
nrf_nvmc_write_bytes(BLE_EPD_CONFIG_ADDR, (uint8_t*)cfg, sizeof(epd_config_t) / sizeof(uint8_t));
|
||||
nrf_nvmc_write_bytes(BLE_EPD_CONFIG_ADDR, (uint8_t*)cfg, EPD_CONFIG_SIZE);
|
||||
}
|
||||
|
||||
/**@brief Function for handling the @ref BLE_GAP_EVT_CONNECTED event from the S110 SoftDevice.
|
||||
@@ -155,6 +159,21 @@ static void epd_service_process(ble_epd_t * p_epd, uint8_t * p_data, uint16_t le
|
||||
DEV_Delay_ms(200);
|
||||
break;
|
||||
|
||||
case EPD_CMD_SET_CONFIG:
|
||||
if (length < 2) return;
|
||||
memcpy(&p_epd->config, &p_data[1], (length - 1 > EPD_CONFIG_SIZE) ? EPD_CONFIG_SIZE : length - 1);
|
||||
epd_config_save(&p_epd->config);
|
||||
break;
|
||||
|
||||
case EPD_CMD_SYS_RESET:
|
||||
NVIC_SystemReset();
|
||||
break;
|
||||
|
||||
case EPD_CMD_SYS_SLEEP:
|
||||
ble_epd_sleep_prepare(p_epd);
|
||||
sd_power_system_off();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -206,10 +225,12 @@ void ble_epd_on_ble_evt(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
|
||||
switch (p_ble_evt->header.evt_id)
|
||||
{
|
||||
case BLE_GAP_EVT_CONNECTED:
|
||||
nrf_gpio_pin_toggle(p_epd->config.led_pin);
|
||||
on_connect(p_epd, p_ble_evt);
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
nrf_gpio_pin_toggle(p_epd->config.led_pin);
|
||||
on_disconnect(p_epd, p_ble_evt);
|
||||
break;
|
||||
|
||||
@@ -285,19 +306,8 @@ static uint32_t epd_service_init(ble_epd_t * p_epd)
|
||||
return err_code;
|
||||
}
|
||||
|
||||
uint32_t ble_epd_init(ble_epd_t * p_epd)
|
||||
static void epd_config_init(ble_epd_t * p_epd)
|
||||
{
|
||||
if (p_epd == NULL)
|
||||
{
|
||||
return NRF_ERROR_NULL;
|
||||
}
|
||||
|
||||
// Initialize the service structure.
|
||||
p_epd->conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
p_epd->is_notification_enabled = false;
|
||||
|
||||
// Load epd config
|
||||
epd_config_load(&p_epd->config);
|
||||
bool save_config = false;
|
||||
if (p_epd->config.mosi_pin == 0xFF && p_epd->config.sclk_pin == 0xFF &&
|
||||
p_epd->config.cs_pin == 0xFF && p_epd->config.dc_pin == 0xFF &&
|
||||
@@ -330,9 +340,40 @@ uint32_t ble_epd_init(ble_epd_t * p_epd)
|
||||
p_epd->config.driver_id = p_epd->driver->id;
|
||||
save_config = true;
|
||||
}
|
||||
if (save_config) {
|
||||
if (save_config)
|
||||
{
|
||||
epd_config_save(&p_epd->config);
|
||||
}
|
||||
}
|
||||
|
||||
void ble_epd_sleep_prepare(ble_epd_t * p_epd)
|
||||
{
|
||||
// Turn off led
|
||||
nrf_gpio_pin_set(p_epd->config.led_pin);
|
||||
// Prepare wakeup pin
|
||||
nrf_gpio_cfg_sense_input(p_epd->config.wakeup_pin, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
|
||||
}
|
||||
|
||||
uint32_t ble_epd_init(ble_epd_t * p_epd)
|
||||
{
|
||||
if (p_epd == NULL)
|
||||
{
|
||||
return NRF_ERROR_NULL;
|
||||
}
|
||||
|
||||
// Initialize the service structure.
|
||||
p_epd->conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
p_epd->is_notification_enabled = false;
|
||||
|
||||
// Load epd config
|
||||
epd_config_load(&p_epd->config);
|
||||
epd_config_init(p_epd);
|
||||
|
||||
// Init led pin
|
||||
nrf_gpio_cfg_output(p_epd->config.led_pin);
|
||||
nrf_gpio_pin_clear(p_epd->config.led_pin);
|
||||
nrf_delay_ms(50);
|
||||
nrf_gpio_pin_set(p_epd->config.led_pin);
|
||||
|
||||
// Add the service.
|
||||
return epd_service_init(p_epd);
|
||||
|
||||
@@ -34,18 +34,24 @@ typedef struct
|
||||
uint8_t busy_pin;
|
||||
uint8_t bs_pin;
|
||||
uint8_t driver_id;
|
||||
uint8_t wakeup_pin;
|
||||
uint8_t led_pin;
|
||||
} epd_config_t;
|
||||
|
||||
/**< EPD Service command IDs. */
|
||||
enum EPD_CMDS
|
||||
{
|
||||
EPD_CMD_SET_PINS,
|
||||
EPD_CMD_INIT,
|
||||
EPD_CMD_CLEAR,
|
||||
EPD_CMD_SEND_COMMAND,
|
||||
EPD_CMD_SEND_DATA,
|
||||
EPD_CMD_DISPLAY,
|
||||
EPD_CMD_SLEEP,
|
||||
EPD_CMD_SET_PINS, /**< set EPD pin mapping. */
|
||||
EPD_CMD_INIT, /**< init EPD display driver */
|
||||
EPD_CMD_CLEAR, /**< clear EPD screen */
|
||||
EPD_CMD_SEND_COMMAND, /**< send command to EPD */
|
||||
EPD_CMD_SEND_DATA, /**< send data to EPD */
|
||||
EPD_CMD_DISPLAY, /**< diaplay EPD ram on screen */
|
||||
EPD_CMD_SLEEP, /**< EPD enter sleep mode */
|
||||
|
||||
EPD_CMD_SET_CONFIG = 0x90, /**< set full EPD config */
|
||||
EPD_CMD_SYS_RESET = 0x91, /**< MCU reset */
|
||||
EPD_CMD_SYS_SLEEP = 0x92, /**< MCU enter sleep mode */
|
||||
};
|
||||
|
||||
/**< EPD driver IDs. */
|
||||
@@ -86,6 +92,12 @@ typedef struct
|
||||
epd_config_t config; /**< EPD config */
|
||||
} ble_epd_t;
|
||||
|
||||
/**@brief Function for preparing sleep mode.
|
||||
*
|
||||
* @param[in] p_epd EPD Service structure.
|
||||
*/
|
||||
void ble_epd_sleep_prepare(ble_epd_t * p_epd);
|
||||
|
||||
/**@brief Function for initializing the EPD Service.
|
||||
*
|
||||
* @param[out] p_epd EPD Service structure. This structure must be supplied
|
||||
|
||||
Reference in New Issue
Block a user