initial nrf52 port

This commit is contained in:
Shuanglei Tao
2025-03-04 21:46:34 +08:00
parent 69a3daa051
commit a284195c64
18 changed files with 2362 additions and 275 deletions

View File

@@ -5,7 +5,7 @@ on:
workflow_dispatch:
jobs:
build:
nrf51:
runs-on: ubuntu-latest
steps:
- name: Checkout
@@ -19,10 +19,33 @@ jobs:
run: |
gcc_path=${{ steps.arm-none-eabi-gcc-action.outputs.path }}
sudo ln -s `dirname ${gcc_path}` /usr/local/gcc-arm-none-eabi-4_9-2015q3
cp Makefile.nRF51 Makefile
make
- uses: actions/upload-artifact@v4
with:
name: nrf51822_xxaa
path: |
_build/nrf51822_xxaa.hex
components/softdevice/s130/hex/s130_nrf51_2.0.1_softdevice.hex
SDK/12.3.0_d7731ad/components/softdevice/s130/hex/s130_nrf51_2.0.1_softdevice.hex
nrf52:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install ARM GCC
uses: carlosperate/arm-none-eabi-gcc-action@v1
id: arm-none-eabi-gcc-action
with:
release: '9-2020-q2'
- name: Build
run: |
gcc_path=${{ steps.arm-none-eabi-gcc-action.outputs.path }}
sudo ln -s `dirname ${gcc_path}` /usr/local/gcc-arm-none-eabi-9-2020-q2-update
cp Makefile.nRF52 Makefile
make
- uses: actions/upload-artifact@v4
with:
name: nrf52811_xxaa
path: |
_build/nrf52811_xxaa.hex
SDK/17.1.0_ddde560/components/softdevice/s112/hex/s112_nrf52_7.2.0_softdevice.hex

101
EPD/EPD_config.c Normal file
View File

@@ -0,0 +1,101 @@
#include <string.h>
#include "nordic_common.h"
#include "fds.h"
#include "EPD_config.h"
#include "nrf_log.h"
#define CONFIG_FILE_ID 0x0000
#define CONFIG_REC_KEY 0x0001
static void fds_evt_handler(fds_evt_t const * const p_fds_evt)
{
NRF_LOG_DEBUG("fds evt: id=%d result=%d\n", p_fds_evt->id, p_fds_evt->result);
}
void epd_config_init(epd_config_t *cfg)
{
ret_code_t ret;
ret = fds_register(fds_evt_handler);
if (ret != NRF_SUCCESS) {
NRF_LOG_ERROR("fds_register failed!\n");
return;
}
ret = fds_init();
if (ret != NRF_SUCCESS) {
NRF_LOG_ERROR("fds init failed!\n");
}
}
void epd_config_load(epd_config_t *cfg)
{
fds_flash_record_t flash_record;
fds_record_desc_t record_desc;
fds_find_token_t ftok;
memset(cfg, 0xFF, sizeof(epd_config_t));
memset(&ftok, 0x00, sizeof(fds_find_token_t));
if (fds_record_find(CONFIG_FILE_ID, CONFIG_REC_KEY, &record_desc, &ftok) != NRF_SUCCESS) {
NRF_LOG_DEBUG("epd_config_load: record not found\n");
return;
}
if (fds_record_open(&record_desc, &flash_record) != NRF_SUCCESS) {
NRF_LOG_ERROR("epd_config_load: record open failed!");
return;
}
#ifdef S112
uint32_t record_len = flash_record.p_header->length_words * sizeof(uint32_t);
#else
uint32_t record_len = flash_record.p_header->tl.length_words * sizeof(uint32_t);
#endif
memcpy(cfg, flash_record.p_data, MIN(sizeof(epd_config_t), record_len));
fds_record_close(&record_desc);
}
void epd_config_clear(epd_config_t *cfg)
{
fds_record_desc_t record_desc;
fds_find_token_t ftok;
memset(&ftok, 0x00, sizeof(fds_find_token_t));
if (fds_record_find(CONFIG_FILE_ID, CONFIG_REC_KEY, &record_desc, &ftok) != NRF_SUCCESS) {
NRF_LOG_DEBUG("epd_config_clear: record not found\n");
return;
}
fds_record_delete(&record_desc);
}
void epd_config_save(epd_config_t *cfg)
{
ret_code_t ret;
fds_record_t record;
fds_record_desc_t record_desc;
fds_find_token_t ftok;
record.file_id = CONFIG_FILE_ID;
record.key = CONFIG_REC_KEY;
#ifdef S112
record.data.p_data = (void*)cfg;
record.data.length_words = BYTES_TO_WORDS(sizeof(epd_config_t));
#else
fds_record_chunk_t record_chunk;
record_chunk.p_data = cfg;
record_chunk.length_words = BYTES_TO_WORDS(sizeof(epd_config_t));
record.data.p_chunks = &record_chunk;
record.data.num_chunks = 1;
#endif
memset(&ftok, 0x00, sizeof(fds_find_token_t));
ret = fds_record_find(CONFIG_FILE_ID, CONFIG_REC_KEY, &record_desc, &ftok);
if (ret == NRF_SUCCESS)
ret = fds_record_update(&record_desc, &record);
else
ret = fds_record_write(&record_desc, &record);
if (ret != NRF_SUCCESS) {
NRF_LOG_ERROR("epd_config_save: record write/update failed!\n");
}
}

21
EPD/EPD_config.h Normal file
View File

@@ -0,0 +1,21 @@
#include <stdint.h>
typedef struct
{
uint8_t mosi_pin;
uint8_t sclk_pin;
uint8_t cs_pin;
uint8_t dc_pin;
uint8_t rst_pin;
uint8_t busy_pin;
uint8_t bs_pin;
uint8_t driver_id;
uint8_t wakeup_pin;
uint8_t led_pin;
uint8_t en_pin;
} epd_config_t;
void epd_config_init(epd_config_t *cfg);
void epd_config_load(epd_config_t *cfg);
void epd_config_clear(epd_config_t *cfg);
void epd_config_save(epd_config_t *cfg);

View File

@@ -12,6 +12,7 @@
*
******************************************************************************/
#include "app_error.h"
#include "nrf_drv_spi.h"
#include "EPD_driver.h"
@@ -24,8 +25,10 @@ uint32_t EPD_DC_PIN = 10;
uint32_t EPD_RST_PIN = 11;
uint32_t EPD_BUSY_PIN = 12;
uint32_t EPD_BS_PIN = 13;
uint32_t EPD_EN_PIN = 0xFF;
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(0);
#define SPI_INSTANCE 0 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */
extern epd_driver_t epd_driver_4in2;
extern epd_driver_t epd_driver_4in2bv2;
@@ -69,86 +72,69 @@ bool epd_driver_set(uint8_t id)
return false;
}
/******************************************************************************
function: Initialize Arduino, Initialize Pins, and SPI
parameter:
Info:
******************************************************************************/
uint8_t DEV_Module_Init(void)
void DEV_Module_Init(void)
{
nrf_gpio_cfg_output(EPD_CS_PIN);
nrf_gpio_cfg_output(EPD_DC_PIN);
nrf_gpio_cfg_output(EPD_RST_PIN);
nrf_gpio_cfg_input(EPD_BUSY_PIN, NRF_GPIO_PIN_NOPULL);
if (EPD_EN_PIN != 0xFF) {
nrf_gpio_cfg_output(EPD_EN_PIN);
DEV_Digital_Write(EPD_EN_PIN, 1);
}
nrf_gpio_cfg_output(EPD_BS_PIN);
DEV_Digital_Write(EPD_BS_PIN, 0);
nrf_drv_spi_config_t spi_config =
{
.sck_pin = EPD_SCLK_PIN,
.mosi_pin = EPD_MOSI_PIN,
.miso_pin = NRF_DRV_SPI_PIN_NOT_USED,
.ss_pin = NRF_DRV_SPI_PIN_NOT_USED,
.frequency = NRF_DRV_SPI_FREQ_4M,
.mode = NRF_DRV_SPI_MODE_0,
};
nrf_drv_spi_init(&spi, &spi_config, NULL);
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.sck_pin = EPD_SCLK_PIN;
spi_config.mosi_pin = EPD_MOSI_PIN;
spi_config.ss_pin = EPD_CS_PIN;
#if defined(S112)
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL));
#else
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL));
#endif
DEV_Digital_Write(EPD_DC_PIN, 0);
DEV_Digital_Write(EPD_CS_PIN, 0);
DEV_Digital_Write(EPD_RST_PIN, 1);
return 0;
}
void DEV_Module_Exit(void)
{
DEV_Digital_Write(EPD_DC_PIN, 0);
DEV_Digital_Write(EPD_CS_PIN, 0);
//close 5V
DEV_Digital_Write(EPD_RST_PIN, 0);
nrf_drv_spi_uninit(&spi);
}
/*********************************************
function: Hardware interface
note:
SPI4W_Write_Byte(value) :
Register hardware SPI
*********************************************/
void DEV_SPI_WriteByte(uint8_t value)
{
nrf_drv_spi_transfer(&spi, &value, 1, NULL, 0);
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, &value, 1, NULL, 0));
}
void DEV_SPI_WriteBytes(uint8_t *value, uint8_t len)
{
nrf_drv_spi_transfer(&spi, value, len, NULL, 0);
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, value, len, NULL, 0));
}
void EPD_WriteCommand(uint8_t Reg)
{
DEV_Digital_Write(EPD_DC_PIN, 0);
DEV_Digital_Write(EPD_CS_PIN, 0);
DEV_SPI_WriteByte(Reg);
DEV_Digital_Write(EPD_CS_PIN, 1);
}
void EPD_WriteByte(uint8_t Data)
{
DEV_Digital_Write(EPD_DC_PIN, 1);
DEV_Digital_Write(EPD_CS_PIN, 0);
DEV_SPI_WriteByte(Data);
DEV_Digital_Write(EPD_CS_PIN, 1);
}
void EPD_WriteData(uint8_t *Data, uint8_t Len)
{
DEV_Digital_Write(EPD_DC_PIN, 1);
DEV_Digital_Write(EPD_CS_PIN, 0);
DEV_SPI_WriteBytes(Data, Len);
DEV_Digital_Write(EPD_CS_PIN, 1);
}

View File

@@ -53,6 +53,7 @@ extern uint32_t EPD_DC_PIN;
extern uint32_t EPD_RST_PIN;
extern uint32_t EPD_BUSY_PIN;
extern uint32_t EPD_BS_PIN;
extern uint32_t EPD_EN_PIN;
/**
* GPIO read and write
@@ -66,7 +67,7 @@ extern uint32_t EPD_BS_PIN;
#define DEV_Delay_ms(__xms) nrf_delay_ms(__xms);
#define DEV_Delay_us(__xus) nrf_delay_us(__xus);
uint8_t DEV_Module_Init(void);
void DEV_Module_Init(void);
void DEV_Module_Exit(void);
void DEV_SPI_WriteByte(uint8_t value);

View File

@@ -11,18 +11,20 @@
*/
#include <string.h>
#include "nordic_common.h"
#include "sdk_macros.h"
#include "ble_srv_common.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_soc.h"
#include "nrf_nvic.h"
#include "fstorage.h"
#include "EPD_ble.h"
#define NRF_LOG_MODULE_NAME "EPD_ble"
#include "EPD_service.h"
#include "nrf_log.h"
#define EPD_CFG_DEFAULT {0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x07}
#if defined(S112)
#define EPD_CFG_DEFAULT {0x14, 0x13, 0x06, 0x05, 0x04, 0x03, 0x02, 0x03, 0xFF, 0x12, 0x07}
#else
//#define EPD_CFG_DEFAULT {0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x01, 0x07}
#endif
#ifndef EPD_CFG_DEFAULT
#define EPD_CFG_DEFAULT {0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x03, 0x09, 0x03}
@@ -35,38 +37,16 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define EPD_CONFIG_SIZE (sizeof(epd_config_t) / sizeof(uint8_t))
static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result)
static void led_on(ble_epd_t * p_epd)
{
NRF_LOG_DEBUG("fs_evt_handler: %d\n", result);
if (p_epd->config.led_pin == 0xFF) return;
nrf_gpio_pin_clear(p_epd->config.led_pin);
}
// fstorage configuration
FS_REGISTER_CFG(fs_config_t fs_config) =
static void led_off(ble_epd_t * p_epd)
{
.callback = fs_evt_handler,
.num_pages = 1,
};
static uint32_t epd_config_load(epd_config_t *cfg)
{
memcpy(cfg, fs_config.p_start_addr, sizeof(epd_config_t));
return NRF_SUCCESS;
}
static uint32_t epd_config_clear(epd_config_t *cfg)
{
return fs_erase(&fs_config, fs_config.p_start_addr, 1, NULL);;
}
static uint32_t epd_config_save(epd_config_t *cfg)
{
uint32_t err_code;
if ((err_code = epd_config_clear(cfg)) != NRF_SUCCESS)
{
return err_code;
}
uint16_t const len = (sizeof(epd_config_t) + sizeof(uint32_t) - 1) / sizeof(uint32_t);
return fs_store(&fs_config, fs_config.p_start_addr, (uint32_t *) cfg, len, NULL);
if (p_epd->config.led_pin == 0xFF) return;
nrf_gpio_pin_set(p_epd->config.led_pin);
}
/**@brief Function for handling the @ref BLE_GAP_EVT_CONNECTED event from the S110 SoftDevice.
@@ -76,10 +56,7 @@ static uint32_t epd_config_save(epd_config_t *cfg)
*/
static void on_connect(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
{
if (p_epd->config.led_pin != 0xFF)
{
nrf_gpio_pin_toggle(p_epd->config.led_pin);
}
led_on(p_epd);
p_epd->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
}
@@ -92,10 +69,7 @@ static void on_connect(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
static void on_disconnect(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
{
UNUSED_PARAMETER(p_ble_evt);
if (p_epd->config.led_pin != 0xFF)
{
nrf_gpio_pin_toggle(p_epd->config.led_pin);
}
led_off(p_epd);
p_epd->conn_handle = BLE_CONN_HANDLE_INVALID;
}
@@ -123,6 +97,8 @@ static void epd_service_process(ble_epd_t * p_epd, uint8_t * p_data, uint16_t le
EPD_RST_PIN = p_epd->config.rst_pin = p_data[5];
EPD_BUSY_PIN = p_epd->config.busy_pin = p_data[6];
EPD_BS_PIN = p_epd->config.bs_pin = p_data[7];
if (length > 8)
EPD_EN_PIN = p_epd->config.en_pin = p_data[8];
epd_config_save(&p_epd->config);
DEV_Module_Init();
@@ -181,7 +157,7 @@ static void epd_service_process(ble_epd_t * p_epd, uint8_t * p_data, uint16_t le
case EPD_CMD_CFG_ERASE:
epd_config_clear(&p_epd->config);
nrf_delay_ms(10); // required
nrf_delay_ms(100); // required
sd_nvic_SystemReset();
break;
@@ -231,6 +207,15 @@ static void on_write(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
}
}
#if defined(S112)
void ble_epd_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
if (p_context == NULL || p_ble_evt == NULL) return;
ble_epd_t *p_epd = (ble_epd_t *)p_context;
ble_epd_on_ble_evt(p_epd, (ble_evt_t *)p_ble_evt);
}
#endif
void ble_epd_on_ble_evt(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
{
@@ -262,66 +247,39 @@ void ble_epd_on_ble_evt(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
static uint32_t epd_service_init(ble_epd_t * p_epd)
{
ble_uuid128_t base_uuid = BLE_EPD_BASE_UUID;
ble_uuid_t ble_uuid;
uint32_t err_code;
ble_uuid_t ble_uuid;
ble_uuid128_t base_uuid = BLE_EPD_BASE_UUID;
ble_add_char_params_t add_char_params;
err_code = sd_ble_uuid_vs_add(&base_uuid, &ble_uuid.type);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = sd_ble_uuid_vs_add(&base_uuid, &p_epd->uuid_type);
VERIFY_SUCCESS(err_code);
ble_uuid.type = p_epd->uuid_type;
ble_uuid.uuid = BLE_UUID_EPD_SERVICE;
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
&ble_uuid,
&p_epd->service_handle);
if (err_code != NRF_SUCCESS)
{
return err_code;
VERIFY_SUCCESS(err_code);
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = BLE_UUID_EPD_CHARACTERISTIC;
add_char_params.uuid_type = p_epd->uuid_type;
add_char_params.max_len = BLE_EPD_MAX_DATA_LEN;
add_char_params.init_len = sizeof(uint8_t);
add_char_params.is_var_len = true;
add_char_params.char_props.notify = 1;
add_char_params.char_props.write = 1;
add_char_params.char_props.write_wo_resp = 1;
add_char_params.read_access = SEC_OPEN;
add_char_params.write_access = SEC_OPEN;
add_char_params.cccd_write_access = SEC_OPEN;
return characteristic_add(p_epd->service_handle, &add_char_params, &p_epd->char_handles);
}
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t char_uuid;
ble_gatts_attr_md_t attr_md;
memset(&cccd_md, 0, sizeof(cccd_md));
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.notify = 1;
char_md.char_props.write = 1;
char_md.char_props.write_wo_resp = 1;
char_md.p_cccd_md = &cccd_md;
char_uuid.type = ble_uuid.type;
char_uuid.uuid = BLE_UUID_EPD_CHARACTERISTIC;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &char_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = BLE_EPD_MAX_DATA_LEN;
err_code = sd_ble_gatts_characteristic_add(p_epd->service_handle,
&char_md,
&attr_char_value,
&p_epd->char_handles);
return err_code;
}
static void epd_config_init(ble_epd_t * p_epd)
static void ble_epd_config_load(ble_epd_t * p_epd)
{
bool is_empty_config = true;
@@ -332,6 +290,7 @@ static void epd_config_init(ble_epd_t * p_epd)
is_empty_config = false;
}
}
NRF_LOG_DEBUG("is_empty_config: %d\n", is_empty_config);
// write default config
if (is_empty_config)
{
@@ -348,6 +307,7 @@ static void epd_config_init(ble_epd_t * p_epd)
EPD_RST_PIN = p_epd->config.rst_pin;
EPD_BUSY_PIN = p_epd->config.busy_pin;
EPD_BS_PIN = p_epd->config.bs_pin;
EPD_EN_PIN = p_epd->config.en_pin;
epd_driver_set(p_epd->config.driver_id);
p_epd->driver = epd_driver_get();
@@ -356,10 +316,7 @@ static void epd_config_init(ble_epd_t * p_epd)
void ble_epd_sleep_prepare(ble_epd_t * p_epd)
{
// Turn off led
if (p_epd->config.led_pin != 0xFF)
{
nrf_gpio_pin_set(p_epd->config.led_pin);
}
led_off(p_epd);
// Prepare wakeup pin
if (p_epd->config.wakeup_pin != 0xFF)
{
@@ -369,37 +326,30 @@ void ble_epd_sleep_prepare(ble_epd_t * p_epd)
uint32_t ble_epd_init(ble_epd_t * p_epd, epd_callback_t cmd_cb)
{
if (p_epd == NULL)
{
return NRF_ERROR_NULL;
}
if (p_epd == NULL) return NRF_ERROR_NULL;
p_epd->epd_cmd_cb = cmd_cb;
// Initialize the service structure.
p_epd->conn_handle = BLE_CONN_HANDLE_INVALID;
p_epd->is_notification_enabled = false;
uint32_t err_code;
err_code = epd_config_load(&p_epd->config);
if (err_code == NRF_SUCCESS)
{
epd_config_init(p_epd);
}
epd_config_init(&p_epd->config);
epd_config_load(&p_epd->config);
ble_epd_config_load(p_epd);
// Init led pin
if (p_epd->config.led_pin != 0xFF)
{
nrf_gpio_cfg_output(p_epd->config.led_pin);
nrf_gpio_pin_clear(p_epd->config.led_pin);
led_on(p_epd);
nrf_delay_ms(50);
nrf_gpio_pin_set(p_epd->config.led_pin);
led_off(p_epd);
}
// Add the service.
return epd_service_init(p_epd);
}
uint32_t ble_epd_string_send(ble_epd_t * p_epd, uint8_t * p_string, uint16_t length)
{
ble_gatts_hvx_params_t hvx_params;

View File

@@ -17,32 +17,42 @@
#include <stdbool.h>
#include "ble.h"
#include "ble_srv_common.h"
#if defined(S112)
#include "nrf_sdh_ble.h"
#endif
#include "sdk_config.h"
#include "EPD_driver.h"
#include "EPD_config.h"
/**@brief Macro for defining a ble_hts instance.
*
* @param _name Name of the instance.
* @hideinitializer
*/
#if defined(S112)
void ble_epd_evt_handler(ble_evt_t const * p_ble_evt, void * p_context);
#define BLE_EPD_BLE_OBSERVER_PRIO 2
#define BLE_EPD_DEF(_name) \
static ble_epd_t _name; \
NRF_SDH_BLE_OBSERVER(_name ## _obs, \
BLE_EPD_BLE_OBSERVER_PRIO, \
ble_epd_evt_handler, &_name)
#else
#define BLE_EPD_DEF(_name) static ble_epd_t _name;
#endif
#define BLE_UUID_EPD_SERVICE 0x0001
#define EPD_SERVICE_UUID_TYPE BLE_UUID_TYPE_VENDOR_BEGIN
#if defined(S112)
#define OPCODE_LENGTH 1
#define HANDLE_LENGTH 2
#define BLE_EPD_MAX_DATA_LEN (NRF_SDH_BLE_GATT_MAX_MTU_SIZE - OPCODE_LENGTH - HANDLE_LENGTH)
#else
#define BLE_EPD_MAX_DATA_LEN (GATT_MTU_SIZE_DEFAULT - 3) /**< Maximum length of data (in bytes) that can be transmitted to the peer. */
#endif
typedef bool (*epd_callback_t)(uint8_t cmd, uint8_t *data, uint16_t len);
/**< EPD Service Configs */
typedef struct
{
uint8_t mosi_pin;
uint8_t sclk_pin;
uint8_t cs_pin;
uint8_t dc_pin;
uint8_t rst_pin;
uint8_t busy_pin;
uint8_t bs_pin;
uint8_t driver_id;
uint8_t wakeup_pin;
uint8_t led_pin;
uint8_t reserved[6];
} epd_config_t;
/**< EPD Service command IDs. */
enum EPD_CMDS
{

View File

@@ -28,6 +28,7 @@
#
******************************************************************************/
#include "EPD_driver.h"
#include "nrf_log.h"
// Display resolution
#define EPD_4IN2_WIDTH 400
@@ -56,9 +57,11 @@ parameter:
******************************************************************************/
void EPD_4IN2_ReadBusy(void)
{
while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
do {
NRF_LOG_DEBUG("EPD_4IN2_ReadBusy\n");
EPD_WriteCommand(0x71);
DEV_Delay_ms(100);
}
} while (!DEV_Digital_Read(EPD_BUSY_PIN));
}
void EPD_4IN2_PowerOn(void)

View File

@@ -3,7 +3,6 @@
#include "EPD_driver.h"
#include "Lunar.h"
#include "Calendar.h"
#define NRF_LOG_MODULE_NAME "Calendar"
#include "nrf_log.h"
#define PAGE_HEIGHT 72

View File

@@ -340,7 +340,7 @@
<MiscControls></MiscControls>
<Define>BLE_STACK_SUPPORT_REQD NRF51822 NRF_SD_BLE_API_VERSION=2 S130 NRF51 SOFTDEVICE_PRESENT SWI_DISABLE0</Define>
<Undefine></Undefine>
<IncludePath>..\config;..\EPD;..\GUI;..\SDK\12.3.0_d7731ad;..\SDK\12.3.0_d7731ad\components\toolchain;..\SDK\12.3.0_d7731ad\components\toolchain\cmsis\include;..\SDK\12.3.0_d7731ad\components\drivers_nrf\clock;..\SDK\12.3.0_d7731ad\components\drivers_nrf\common;..\SDK\12.3.0_d7731ad\components\drivers_nrf\delay;..\SDK\12.3.0_d7731ad\components\drivers_nrf\gpiote;..\SDK\12.3.0_d7731ad\components\drivers_nrf\hal;..\SDK\12.3.0_d7731ad\components\drivers_nrf\spi_master;..\SDK\12.3.0_d7731ad\components\drivers_nrf\twi_master;..\SDK\12.3.0_d7731ad\external\segger_rtt;..\SDK\12.3.0_d7731ad\components\libraries\fstorage;..\SDK\12.3.0_d7731ad\components\libraries\experimental_section_vars;..\SDK\12.3.0_d7731ad\components\libraries\log;..\SDK\12.3.0_d7731ad\components\libraries\log\src;..\SDK\12.3.0_d7731ad\components\libraries\scheduler;..\SDK\12.3.0_d7731ad\components\libraries\trace;..\SDK\12.3.0_d7731ad\components\libraries\timer;..\SDK\12.3.0_d7731ad\components\libraries\util;..\SDK\12.3.0_d7731ad\components\ble\common;..\SDK\12.3.0_d7731ad\components\ble\ble_advertising;..\SDK\12.3.0_d7731ad\components\softdevice\common\softdevice_handler;..\SDK\12.3.0_d7731ad\components\softdevice\s130\headers;..\SDK\12.3.0_d7731ad\components\softdevice\s130\headers\nrf51</IncludePath>
<IncludePath>..\config;..\EPD;..\GUI;..\SDK\12.3.0_d7731ad;..\SDK\12.3.0_d7731ad\components\toolchain;..\SDK\12.3.0_d7731ad\components\toolchain\cmsis\include;..\SDK\12.3.0_d7731ad\components\drivers_nrf\clock;..\SDK\12.3.0_d7731ad\components\drivers_nrf\common;..\SDK\12.3.0_d7731ad\components\drivers_nrf\delay;..\SDK\12.3.0_d7731ad\components\drivers_nrf\gpiote;..\SDK\12.3.0_d7731ad\components\drivers_nrf\hal;..\SDK\12.3.0_d7731ad\components\drivers_nrf\spi_master;..\SDK\12.3.0_d7731ad\components\drivers_nrf\twi_master;..\SDK\12.3.0_d7731ad\external\segger_rtt;..\SDK\12.3.0_d7731ad\components\libraries\fds;..\SDK\12.3.0_d7731ad\components\libraries\fstorage;..\SDK\12.3.0_d7731ad\components\libraries\experimental_section_vars;..\SDK\12.3.0_d7731ad\components\libraries\log;..\SDK\12.3.0_d7731ad\components\libraries\log\src;..\SDK\12.3.0_d7731ad\components\libraries\scheduler;..\SDK\12.3.0_d7731ad\components\libraries\trace;..\SDK\12.3.0_d7731ad\components\libraries\timer;..\SDK\12.3.0_d7731ad\components\libraries\util;..\SDK\12.3.0_d7731ad\components\ble\common;..\SDK\12.3.0_d7731ad\components\ble\ble_advertising;..\SDK\12.3.0_d7731ad\components\softdevice\common\softdevice_handler;..\SDK\12.3.0_d7731ad\components\softdevice\s130\headers;..\SDK\12.3.0_d7731ad\components\softdevice\s130\headers\nrf51</IncludePath>
</VariousControls>
</Cads>
<Aads>
@@ -400,15 +400,20 @@
<GroupName>EPD</GroupName>
<Files>
<File>
<FileName>EPD_ble.c</FileName>
<FileName>EPD_config.c</FileName>
<FileType>1</FileType>
<FilePath>..\EPD\EPD_ble.c</FilePath>
<FilePath>..\EPD\EPD_config.c</FilePath>
</File>
<File>
<FileName>EPD_driver.c</FileName>
<FileType>1</FileType>
<FilePath>..\EPD\EPD_driver.c</FilePath>
</File>
<File>
<FileName>EPD_service.c</FileName>
<FileType>1</FileType>
<FilePath>..\EPD\EPD_service.c</FilePath>
</File>
<File>
<FileName>UC8176.c</FileName>
<FileType>1</FileType>
@@ -529,6 +534,11 @@
<FileType>1</FileType>
<FilePath>..\SDK\12.3.0_d7731ad\components\libraries\fstorage\fstorage.c</FilePath>
</File>
<File>
<FileName>fds.c</FileName>
<FileType>1</FileType>
<FilePath>..\SDK\12.3.0_d7731ad\components\libraries\fds\fds.c</FilePath>
</File>
</Files>
</Group>
<Group>
@@ -987,15 +997,20 @@
<GroupName>EPD</GroupName>
<Files>
<File>
<FileName>EPD_ble.c</FileName>
<FileName>EPD_config.c</FileName>
<FileType>1</FileType>
<FilePath>..\EPD\EPD_ble.c</FilePath>
<FilePath>..\EPD\EPD_config.c</FilePath>
</File>
<File>
<FileName>EPD_driver.c</FileName>
<FileType>1</FileType>
<FilePath>..\EPD\EPD_driver.c</FilePath>
</File>
<File>
<FileName>EPD_service.c</FileName>
<FileType>1</FileType>
<FilePath>..\EPD\EPD_service.c</FilePath>
</File>
<File>
<FileName>UC8176.c</FileName>
<FileType>1</FileType>
@@ -1116,6 +1131,11 @@
<FileType>1</FileType>
<FilePath>..\SDK\12.3.0_d7731ad\components\libraries\fstorage\fstorage.c</FilePath>
</File>
<File>
<FileName>fds.c</FileName>
<FileType>1</FileType>
<FilePath>..\SDK\12.3.0_d7731ad\components\libraries\fds\fds.c</FilePath>
</File>
</Files>
</Group>
<Group>
@@ -1196,32 +1216,7 @@
</packages>
<apis/>
<components/>
<files>
<file attr="config" category="source" condition="ARM Compiler" name="Device\Source\arm\arm_startup_nrf51.s" version="8.11.1">
<instance index="0" removed="1">RTE\Device\nRF51802_xxAA\arm_startup_nrf51.s</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="NordicSemiconductor" Cversion="8.11.1" condition="nRF51 Series and CMSIS"/>
<package name="nRF_DeviceFamilyPack" schemaVersion="1.3" url="http://developer.nordicsemi.com/nRF5_SDK/pieces/nRF_DeviceFamilyPack/" vendor="NordicSemiconductor" version="8.11.1"/>
<targetInfos/>
</file>
<file attr="config" category="source" name="Device\Source\system_nrf51.c" version="8.11.1">
<instance index="0" removed="1">RTE\Device\nRF51802_xxAA\system_nrf51.c</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="NordicSemiconductor" Cversion="8.11.1" condition="nRF51 Series and CMSIS"/>
<package name="nRF_DeviceFamilyPack" schemaVersion="1.3" url="http://developer.nordicsemi.com/nRF5_SDK/pieces/nRF_DeviceFamilyPack/" vendor="NordicSemiconductor" version="8.11.1"/>
<targetInfos/>
</file>
<file attr="config" category="source" condition="ARM Compiler" name="Device\Source\arm\arm_startup_nrf51.s" version="8.11.1">
<instance index="0" removed="1">RTE\Device\nRF51822_xxAB\arm_startup_nrf51.s</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="NordicSemiconductor" Cversion="8.11.1" condition="nRF51 Series and CMSIS"/>
<package name="nRF_DeviceFamilyPack" schemaVersion="1.3" url="http://developer.nordicsemi.com/nRF5_SDK/pieces/nRF_DeviceFamilyPack/" vendor="NordicSemiconductor" version="8.11.1"/>
<targetInfos/>
</file>
<file attr="config" category="source" name="Device\Source\system_nrf51.c" version="8.11.1">
<instance index="0" removed="1">RTE\Device\nRF51822_xxAB\system_nrf51.c</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="NordicSemiconductor" Cversion="8.11.1" condition="nRF51 Series and CMSIS"/>
<package name="nRF_DeviceFamilyPack" schemaVersion="1.3" url="http://developer.nordicsemi.com/nRF5_SDK/pieces/nRF_DeviceFamilyPack/" vendor="NordicSemiconductor" version="8.11.1"/>
<targetInfos/>
</file>
</files>
<files/>
</RTE>
<LayerInfo>

1481
Keil/EPD-nRF52.uvprojx Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -7,35 +7,37 @@ SDK_ROOT := $(PROJ_DIR)/SDK/12.3.0_d7731ad
SD_PATH := $(SDK_ROOT)/components/softdevice/s130
$(OUTPUT_DIRECTORY)/nrf51822_xxaa.out: \
LINKER_SCRIPT := $(SD_PATH)/toolchain/armgcc/armgcc_s130_nrf51822_xxaa.ld
LINKER_SCRIPT := $(SDK_ROOT)/gcc_nrf51.ld
# Source files common to all targets
SRC_FILES += \
$(SDK_ROOT)/external/segger_rtt/RTT_Syscalls_GCC.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/timer/app_timer.c \
$(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/fstorage/fstorage.c \
$(SDK_ROOT)/components/drivers_nrf/common/nrf_drv_common.c \
$(SDK_ROOT)/components/drivers_nrf/clock/nrf_drv_clock.c \
$(SDK_ROOT)/components/drivers_nrf/gpiote/nrf_drv_gpiote.c \
$(SDK_ROOT)/components/drivers_nrf/spi_master/nrf_drv_spi.c \
$(SDK_ROOT)/components/ble/common/ble_advdata.c \
$(SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c \
$(SDK_ROOT)/components/ble/common/ble_conn_params.c \
$(SDK_ROOT)/components/ble/common/ble_srv_common.c \
$(SDK_ROOT)/components/libraries/fds/fds.c \
$(SDK_ROOT)/components/libraries/fstorage/fstorage.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
$(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(SDK_ROOT)/components/libraries/timer/app_timer.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/drivers_nrf/common/nrf_drv_common.c \
$(SDK_ROOT)/components/drivers_nrf/clock/nrf_drv_clock.c \
$(SDK_ROOT)/components/drivers_nrf/gpiote/nrf_drv_gpiote.c \
$(SDK_ROOT)/components/drivers_nrf/spi_master/nrf_drv_spi.c \
$(SDK_ROOT)/components/toolchain/gcc/gcc_startup_nrf51.s \
$(SDK_ROOT)/components/toolchain/system_nrf51.c \
$(SDK_ROOT)/components/softdevice/common/softdevice_handler/softdevice_handler.c \
$(SDK_ROOT)/external/segger_rtt/RTT_Syscalls_GCC.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
$(PROJ_DIR)/main.c \
$(PROJ_DIR)/EPD/EPD_config.c \
$(PROJ_DIR)/EPD/EPD_driver.c \
$(PROJ_DIR)/EPD/EPD_ble.c \
$(PROJ_DIR)/EPD/EPD_service.c \
$(PROJ_DIR)/EPD/UC8176.c \
$(PROJ_DIR)/GUI/Calendar.c \
$(PROJ_DIR)/GUI/Lunar.c \
@@ -45,12 +47,10 @@ SRC_FILES += \
# Include folders common to all targets
INC_FOLDERS += \
$(PROJ_DIR)/config \
$(PROJ_DIR)/EPD \
$(PROJ_DIR)/GUI \
$(SDK_ROOT) \
$(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/components/toolchain/gcc \
$(SDK_ROOT)/components/toolchain \
$(SDK_ROOT)/components/device \
$(SDK_ROOT)/components/drivers_nrf/clock \
$(SDK_ROOT)/components/drivers_nrf/hal \
$(SDK_ROOT)/components/drivers_nrf/common \
@@ -59,20 +59,21 @@ INC_FOLDERS += \
$(SDK_ROOT)/components/drivers_nrf/spi_master \
$(SDK_ROOT)/components/libraries/fstorage \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/components/libraries/fds \
$(SDK_ROOT)/components/libraries/log \
$(SDK_ROOT)/components/libraries/log/src \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/components/libraries/scheduler \
$(SDK_ROOT)/components/libraries/util \
$(SDK_ROOT)/components/device \
$(SDK_ROOT)/components/toolchain \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/components/toolchain/gcc \
$(SDK_ROOT)/components/ble/common \
$(SDK_ROOT)/components/ble/ble_advertising \
$(SDK_ROOT)/components/softdevice/common/softdevice_handler \
$(SDK_ROOT)/components/softdevice/s130/headers \
$(SDK_ROOT)/components/softdevice/s130/headers/nrf51
$(SDK_ROOT)/components/softdevice/s130/headers/nrf51 \
$(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT) \
$(PROJ_DIR)/EPD \
$(PROJ_DIR)/GUI
# Libraries common to all targets
LIB_FILES += \

212
Makefile.nRF52 Normal file
View File

@@ -0,0 +1,212 @@
PROJECT_NAME := EPD-nRF52
TARGETS := nrf52811_xxaa
OUTPUT_DIRECTORY := _build
PROJ_DIR := $(CURDIR)
SDK_ROOT := $(PROJ_DIR)/SDK/17.1.0_ddde560
SD_PATH := $(SDK_ROOT)/components/softdevice/s112
$(OUTPUT_DIRECTORY)/nrf52811_xxaa.out: \
LINKER_SCRIPT := $(SDK_ROOT)/gcc_nrf52.ld
# Source files common to all targets
SRC_FILES += \
$(SDK_ROOT)/components/ble/common/ble_advdata.c \
$(SDK_ROOT)/components/ble/common/ble_conn_params.c \
$(SDK_ROOT)/components/ble/common/ble_srv_common.c \
$(SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c \
$(SDK_ROOT)/components/ble/nrf_ble_gatt/nrf_ble_gatt.c \
$(SDK_ROOT)/components/libraries/atomic_fifo/nrf_atfifo.c \
$(SDK_ROOT)/components/libraries/atomic_flags/nrf_atflags.c \
$(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \
$(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \
$(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c \
$(SDK_ROOT)/components/libraries/fds/fds.c \
$(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage.c \
$(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage_sd.c \
$(SDK_ROOT)/components/libraries/memobj/nrf_memobj.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_str_formatter.c \
$(SDK_ROOT)/components/libraries/ringbuf/nrf_ringbuf.c \
$(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
$(SDK_ROOT)/components/libraries/sortlist/nrf_sortlist.c \
$(SDK_ROOT)/components/libraries/timer/app_timer2.c \
$(SDK_ROOT)/components/libraries/timer/drv_rtc.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh_ble.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh_soc.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
$(SDK_ROOT)/modules/nrfx/soc/nrfx_atomic.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_spi.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_spim.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_spi.c \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52811.S \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \
$(PROJ_DIR)/main.c \
$(PROJ_DIR)/EPD/EPD_config.c \
$(PROJ_DIR)/EPD/EPD_driver.c \
$(PROJ_DIR)/EPD/EPD_service.c \
$(PROJ_DIR)/EPD/UC8176.c \
$(PROJ_DIR)/GUI/Calendar.c \
$(PROJ_DIR)/GUI/Lunar.c \
$(PROJ_DIR)/GUI/fonts.c \
$(PROJ_DIR)/GUI/Adafruit_GFX.c \
$(PROJ_DIR)/GUI/u8g2_font.c
# Include folders common to all targets
INC_FOLDERS += \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/components/softdevice/common \
$(SDK_ROOT)/components/softdevice/s112/headers \
$(SDK_ROOT)/components/softdevice/s112/headers/nrf52 \
$(SDK_ROOT)/components/libraries/atomic \
$(SDK_ROOT)/components/libraries/atomic_fifo \
$(SDK_ROOT)/components/libraries/atomic_flags \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/components/libraries/delay \
$(SDK_ROOT)/components/libraries/fstorage \
$(SDK_ROOT)/components/libraries/fds \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/components/libraries/log \
$(SDK_ROOT)/components/libraries/log/src \
$(SDK_ROOT)/components/libraries/memobj \
$(SDK_ROOT)/components/libraries/mutex \
$(SDK_ROOT)/components/libraries/ringbuf \
$(SDK_ROOT)/components/libraries/sortlist \
$(SDK_ROOT)/components/libraries/scheduler \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/components/libraries/util \
$(SDK_ROOT)/components/ble/common \
$(SDK_ROOT)/components/ble/ble_advertising \
$(SDK_ROOT)/components/ble/nrf_ble_gatt \
$(SDK_ROOT)/external/fprintf \
$(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/modules/nrfx/mdk \
$(SDK_ROOT)/modules/nrfx/drivers/include \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT) \
$(PROJ_DIR)/EPD \
$(PROJ_DIR)/GUI
# Libraries common to all targets
LIB_FILES += \
# Optimization flags
OPT = -Os -g3
# Uncomment the line below to enable link time optimization
#OPT += -flto
# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DAPP_TIMER_V2
CFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DDEVELOP_IN_NRF52840
CFLAGS += -DFLOAT_ABI_SOFT
CFLAGS += -DNRF52811_XXAA
CFLAGS += -DNRFX_COREDEP_DELAY_US_LOOP_CYCLES=3
CFLAGS += -DNRF_SD_BLE_API_VERSION=7
CFLAGS += -DS112
CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -Wall -Werror
CFLAGS += -mfloat-abi=soft
# keep every function in a separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin -fshort-enums
# C++ flags common to all targets
CXXFLAGS += $(OPT)
# Assembler flags common to all targets
ASMFLAGS += -g3
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=soft
ASMFLAGS += -DAPP_TIMER_V2
ASMFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DDEVELOP_IN_NRF52840
ASMFLAGS += -DFLOAT_ABI_SOFT
ASMFLAGS += -DNRF52811_XXAA
ASMFLAGS += -DNRFX_COREDEP_DELAY_US_LOOP_CYCLES=3
ASMFLAGS += -DNRF_SD_BLE_API_VERSION=7
ASMFLAGS += -DS112
ASMFLAGS += -DSOFTDEVICE_PRESENT
# Linker flags
LDFLAGS += $(OPT)
LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
# let linker dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs
nrf52811_xxaa: CFLAGS += -D__HEAP_SIZE=2048
nrf52811_xxaa: CFLAGS += -D__STACK_SIZE=2048
nrf52811_xxaa: ASMFLAGS += -D__HEAP_SIZE=2048
nrf52811_xxaa: ASMFLAGS += -D__STACK_SIZE=2048
# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm
.PHONY: default help
# Default target - first one defined
default: nrf52811_xxaa
# Print all targets that can be built
help:
@echo following targets are available:
@echo nrf52811_xxaa
@echo flash_softdevice
@echo sdk_config - starting external tool for editing sdk_config.h
@echo flash - flashing binary
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
include $(TEMPLATE_PATH)/Makefile.common
$(foreach target, $(TARGETS), $(call define_target, $(target)))
.PHONY: flash flash_softdevice erase
# Flash the program
flash: default
@echo Flashing: $(OUTPUT_DIRECTORY)/nrf52811_xxaa.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52811_xxaa.hex --sectorerase
nrfjprog -f nrf52 --reset
# Flash softdevice
flash_softdevice:
@echo Flashing: s112_nrf52_7.2.0_softdevice.hex
nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s112/hex/s112_nrf52_7.2.0_softdevice.hex --sectorerase
nrfjprog -f nrf52 --reset
erase:
nrfjprog -f nrf52 --eraseall

View File

@@ -0,0 +1,28 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x25000
RAM (rwx) : ORIGIN = 0x20001fe8, LENGTH = 0x6018
}
SECTIONS
{
.fs_data :
{
PROVIDE(__start_fs_data = .);
KEEP(*(.fs_data))
PROVIDE(__stop_fs_data = .);
} > RAM
.pwr_mgmt_data :
{
PROVIDE(__start_pwr_mgmt_data = .);
KEEP(*(.pwr_mgmt_data))
PROVIDE(__stop_pwr_mgmt_data = .);
} > RAM
} INSERT AFTER .data;
INCLUDE "nrf5x_common.ld"

View File

@@ -3085,7 +3085,7 @@
// <e> FDS_ENABLED - fds - Flash data storage module
//==========================================================
#ifndef FDS_ENABLED
#define FDS_ENABLED 0
#define FDS_ENABLED 1
#endif
#if FDS_ENABLED
// <o> FDS_OP_QUEUE_SIZE - Size of the internal queue.

View File

@@ -0,0 +1,130 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x19000, LENGTH = 0x17000
RAM (rwx) : ORIGIN = 0x200022c8, LENGTH = 0x3d38
}
SECTIONS
{
}
SECTIONS
{
. = ALIGN(4);
.mem_section_dummy_ram :
{
}
.cli_sorted_cmd_ptrs :
{
PROVIDE(__start_cli_sorted_cmd_ptrs = .);
KEEP(*(.cli_sorted_cmd_ptrs))
PROVIDE(__stop_cli_sorted_cmd_ptrs = .);
} > RAM
.fs_data :
{
PROVIDE(__start_fs_data = .);
KEEP(*(.fs_data))
PROVIDE(__stop_fs_data = .);
} > RAM
.log_dynamic_data :
{
PROVIDE(__start_log_dynamic_data = .);
KEEP(*(SORT(.log_dynamic_data*)))
PROVIDE(__stop_log_dynamic_data = .);
} > RAM
.log_filter_data :
{
PROVIDE(__start_log_filter_data = .);
KEEP(*(SORT(.log_filter_data*)))
PROVIDE(__stop_log_filter_data = .);
} > RAM
} INSERT AFTER .data;
SECTIONS
{
.mem_section_dummy_rom :
{
}
.sdh_soc_observers :
{
PROVIDE(__start_sdh_soc_observers = .);
KEEP(*(SORT(.sdh_soc_observers*)))
PROVIDE(__stop_sdh_soc_observers = .);
} > FLASH
.sdh_ble_observers :
{
PROVIDE(__start_sdh_ble_observers = .);
KEEP(*(SORT(.sdh_ble_observers*)))
PROVIDE(__stop_sdh_ble_observers = .);
} > FLASH
.pwr_mgmt_data :
{
PROVIDE(__start_pwr_mgmt_data = .);
KEEP(*(SORT(.pwr_mgmt_data*)))
PROVIDE(__stop_pwr_mgmt_data = .);
} > FLASH
.sdh_req_observers :
{
PROVIDE(__start_sdh_req_observers = .);
KEEP(*(SORT(.sdh_req_observers*)))
PROVIDE(__stop_sdh_req_observers = .);
} > FLASH
.sdh_state_observers :
{
PROVIDE(__start_sdh_state_observers = .);
KEEP(*(SORT(.sdh_state_observers*)))
PROVIDE(__stop_sdh_state_observers = .);
} > FLASH
.sdh_stack_observers :
{
PROVIDE(__start_sdh_stack_observers = .);
KEEP(*(SORT(.sdh_stack_observers*)))
PROVIDE(__stop_sdh_stack_observers = .);
} > FLASH
.nrf_queue :
{
PROVIDE(__start_nrf_queue = .);
KEEP(*(.nrf_queue))
PROVIDE(__stop_nrf_queue = .);
} > FLASH
.nrf_balloc :
{
PROVIDE(__start_nrf_balloc = .);
KEEP(*(.nrf_balloc))
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
.cli_command :
{
PROVIDE(__start_cli_command = .);
KEEP(*(.cli_command))
PROVIDE(__stop_cli_command = .);
} > FLASH
.crypto_data :
{
PROVIDE(__start_crypto_data = .);
KEEP(*(SORT(.crypto_data*)))
PROVIDE(__stop_crypto_data = .);
} > FLASH
.log_const_data :
{
PROVIDE(__start_log_const_data = .);
KEEP(*(SORT(.log_const_data*)))
PROVIDE(__stop_log_const_data = .);
} > FLASH
.log_backends :
{
PROVIDE(__start_log_backends = .);
KEEP(*(SORT(.log_backends*)))
PROVIDE(__stop_log_backends = .);
} > FLASH
} INSERT AFTER .text
INCLUDE "nrf_common.ld"

View File

@@ -190,7 +190,7 @@
// <e> NRF_BLE_QWR_ENABLED - nrf_ble_qwr - Queued writes support module (prepare/execute write)
//==========================================================
#ifndef NRF_BLE_QWR_ENABLED
#define NRF_BLE_QWR_ENABLED 1
#define NRF_BLE_QWR_ENABLED 0
#endif
// <o> NRF_BLE_QWR_MAX_ATTR - Maximum number of attribute handles that can be registered. This number must be adjusted according to the number of attributes for which Queued Writes will be enabled. If it is zero, the module will reject all Queued Write requests.
#ifndef NRF_BLE_QWR_MAX_ATTR
@@ -2015,7 +2015,7 @@
// <e> NRFX_GPIOTE_ENABLED - nrfx_gpiote - GPIOTE peripheral driver
//==========================================================
#ifndef NRFX_GPIOTE_ENABLED
#define NRFX_GPIOTE_ENABLED 0
#define NRFX_GPIOTE_ENABLED 1
#endif
// <o> NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins
#ifndef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
@@ -2292,7 +2292,7 @@
// <e> NRFX_PRS_ENABLED - nrfx_prs - Peripheral Resource Sharing module
//==========================================================
#ifndef NRFX_PRS_ENABLED
#define NRFX_PRS_ENABLED 0
#define NRFX_PRS_ENABLED 1
#endif
// <q> NRFX_PRS_BOX_0_ENABLED - Enables box 0 in the module.
@@ -2987,7 +2987,7 @@
// <e> NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver
//==========================================================
#ifndef NRFX_SPIM_ENABLED
#define NRFX_SPIM_ENABLED 0
#define NRFX_SPIM_ENABLED 1
#endif
// <q> NRFX_SPIM0_ENABLED - Enable SPIM0 instance
@@ -3185,7 +3185,7 @@
// <e> NRFX_SPI_ENABLED - nrfx_spi - SPI peripheral driver
//==========================================================
#ifndef NRFX_SPI_ENABLED
#define NRFX_SPI_ENABLED 0
#define NRFX_SPI_ENABLED 1
#endif
// <q> NRFX_SPI0_ENABLED - Enable SPI0 instance
@@ -3229,7 +3229,7 @@
// <e> NRFX_SPI_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef NRFX_SPI_CONFIG_LOG_ENABLED
#define NRFX_SPI_CONFIG_LOG_ENABLED 0
#define NRFX_SPI_CONFIG_LOG_ENABLED 1
#endif
// <o> NRFX_SPI_CONFIG_LOG_LEVEL - Default Severity level
@@ -3240,7 +3240,7 @@
// <4=> Debug
#ifndef NRFX_SPI_CONFIG_LOG_LEVEL
#define NRFX_SPI_CONFIG_LOG_LEVEL 3
#define NRFX_SPI_CONFIG_LOG_LEVEL 4
#endif
// <o> NRFX_SPI_CONFIG_INFO_COLOR - ANSI escape code prefix.
@@ -6006,7 +6006,7 @@
// <e> FDS_ENABLED - fds - Flash data storage module
//==========================================================
#ifndef FDS_ENABLED
#define FDS_ENABLED 0
#define FDS_ENABLED 1
#endif
// <h> Pages - Virtual page settings
@@ -6018,7 +6018,7 @@
// <i> The total amount of flash memory that is used by FDS amounts to @ref FDS_VIRTUAL_PAGES * @ref FDS_VIRTUAL_PAGE_SIZE * 4 bytes.
#ifndef FDS_VIRTUAL_PAGES
#define FDS_VIRTUAL_PAGES 3
#define FDS_VIRTUAL_PAGES 2
#endif
// <o> FDS_VIRTUAL_PAGE_SIZE - The size of a virtual flash page.
@@ -7025,7 +7025,7 @@
// <e> NRF_LOG_ENABLED - nrf_log - Logger
//==========================================================
#ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 1
#define NRF_LOG_ENABLED 0
#endif
// <h> Log message pool - Configuration of log message pool
@@ -7097,7 +7097,7 @@
// <4=> Debug
#ifndef NRF_LOG_DEFAULT_LEVEL
#define NRF_LOG_DEFAULT_LEVEL 3
#define NRF_LOG_DEFAULT_LEVEL 4
#endif
// <q> NRF_LOG_DEFERRED - Enable deffered logger.

220
main.c
View File

@@ -20,17 +20,27 @@
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_conn_params.h"
#include "softdevice_handler.h"
#if defined(S112)
#include "nrf_sdh.h"
#include "nrf_sdh_soc.h"
#include "nrf_sdh_ble.h"
#include "nrf_ble_gatt.h"
#else
#include "fstorage.h"
#include "softdevice_handler.h"
#endif
#include "nrf_soc.h"
#include "app_error.h"
#include "app_timer.h"
#include "app_scheduler.h"
#include "nrf_drv_gpiote.h"
#include "EPD_ble.h"
#include "EPD_service.h"
#include "Calendar.h"
#define NRF_LOG_MODULE_NAME "main"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#if defined(S112)
#include "nrf_log_default_backends.h"
#endif
#define CENTRAL_LINK_COUNT 0 /**< Number of central links used by the application. When changing this number remember to adjust the RAM settings*/
#define PERIPHERAL_LINK_COUNT 1 /**< Number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
@@ -41,27 +51,40 @@
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
#define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */
#if defined(S112)
#define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */
#define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */
#define TIMER_TICKS(MS) APP_TIMER_TICKS(MS)
#else
#define TIMER_TICKS(MS) APP_TIMER_TICKS(MS, APP_TIMER_PRESCALER)
#endif
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) /**< Minimum connection interval (7.5 ms) */
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(30, UNIT_1_25_MS) /**< Maximum connection interval (30 ms). */
#define SLAVE_LATENCY 6 /**< Slave latency. */
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(430, UNIT_10_MS) /**< Connection supervisory timeout (430 ms). */
#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER) /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000, APP_TIMER_PRESCALER) /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define FIRST_CONN_PARAMS_UPDATE_DELAY TIMER_TICKS(5000) /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY TIMER_TICKS(30000) /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT 3 /**< Number of attempts before giving up the connection parameter negotiation. */
#define SCHED_MAX_EVENT_DATA_SIZE 0 /**< Maximum size of scheduler events. */
#define SCHED_QUEUE_SIZE 10 /**< Maximum number of events in the scheduler queue. */
#define CLOCK_TIMER_INTERVAL APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) /**< Clock timer interval (ticks). */
#define CLOCK_TIMER_INTERVAL TIMER_TICKS(1000) /**< Clock timer interval (ticks). */
#define DEAD_BEEF 0xDEADBEEF /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */
#if defined(S112)
NRF_BLE_GATT_DEF(m_gatt); /**< GATT module instance. */
BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */
static uint16_t m_ble_max_data_len = BLE_GATT_ATT_MTU_DEFAULT - 3; /**< Maximum length of data (in bytes) that can be transmitted to the peer. */
#endif
static uint16_t m_driver_refs = 0;
static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; /**< Handle of the current connection. */
static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_EPD_SERVICE, \
EPD_SERVICE_UUID_TYPE}}; /**< Universally unique service identifier. */
static ble_epd_t m_epd; /**< Structure to identify the EPD Service. */
BLE_EPD_DEF(m_epd); /**< Structure to identify the EPD Service. */
static uint32_t m_timestamp = 1735689600; /**< Current timestamp. */
static bool m_calendar_mode = false; /**< Whether we are in calendar mode */
@@ -139,11 +162,17 @@ static void scheduler_init(void)
*/
static void timers_init(void)
{
// Initialize timer module.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
uint32_t err_code;
// Initialize timer module.
#if defined(S112)
err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
#else
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
#endif
// Create timers.
uint32_t err_code = app_timer_create(&m_clock_timer_id,
err_code = app_timer_create(&m_clock_timer_id,
APP_TIMER_MODE_REPEATED,
clock_timer_timeout_handler);
APP_ERROR_CHECK(err_code);
@@ -195,9 +224,6 @@ static void services_init(void)
{
uint32_t err_code;
err_code = fs_init();
APP_ERROR_CHECK(err_code);
memset(&m_epd, 0, sizeof(ble_epd_t));
err_code = ble_epd_init(&m_epd, epd_cmd_callback);
APP_ERROR_CHECK(err_code);
@@ -217,8 +243,11 @@ static void gap_params_init(void)
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
#if defined(S112)
err_code = sd_ble_gap_addr_get(&addr);
#else
err_code = sd_ble_gap_address_get(&addr);
#endif
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("Bluetooth MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\n",
@@ -301,7 +330,11 @@ static void conn_params_init(void)
static void advertising_start(void)
{
NRF_LOG_INFO("advertising start\n");
#if defined(S112)
uint32_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
#else
uint32_t err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
#endif
APP_ERROR_CHECK(err_code);
}
@@ -391,8 +424,23 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
NRF_LOG_INFO("DISCONNECTED\n");
m_conn_handle = BLE_CONN_HANDLE_INVALID;
epd_driver_exit();
#if !defined(S112)
advertising_start();
#endif
break;
#if defined(S112)
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
{
NRF_LOG_DEBUG("PHY update request.");
ble_gap_phys_t const phys =
{
.rx_phys = BLE_GAP_PHY_AUTO,
.tx_phys = BLE_GAP_PHY_AUTO,
};
err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
APP_ERROR_CHECK(err_code);
} break;
#endif
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
// Pairing not supported
@@ -407,15 +455,16 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
break;
case BLE_GATTC_EVT_TIMEOUT:
case BLE_GATTS_EVT_TIMEOUT:
// Disconnect on GATT Server and Client timeout events.
err_code = sd_ble_gap_disconnect(m_conn_handle,
// Disconnect on GATT Client timeout event.
err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break;
case BLE_EVT_USER_MEM_REQUEST:
err_code = sd_ble_user_mem_reply(m_conn_handle, NULL);
case BLE_GATTS_EVT_TIMEOUT:
// Disconnect on GATT Server timeout event.
err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
break;
@@ -426,6 +475,20 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
}
#if defined(S112)
/**@brief Function for handling BLE events.
*
* @param[in] p_ble_evt Bluetooth stack event.
* @param[in] p_context Unused.
*/
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
UNUSED_PARAMETER(p_context);
on_ble_evt((ble_evt_t *)p_ble_evt);
}
#else
/**@brief Function for dispatching a SoftDevice event to all modules with a SoftDevice
* event handler.
*
@@ -461,7 +524,7 @@ static void sys_evt_dispatch(uint32_t sys_evt)
// so that it can report correctly to the Advertising module.
ble_advertising_on_sys_evt(sys_evt);
}
#endif
/**@brief Function for the SoftDevice initialization.
*
@@ -470,6 +533,23 @@ static void sys_evt_dispatch(uint32_t sys_evt)
static void ble_stack_init(void)
{
uint32_t err_code;
#if defined(S112)
err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);
// Configure the BLE stack using the default settings.
// Fetch the start address of the application RAM.
uint32_t ram_start = 0;
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
APP_ERROR_CHECK(err_code);
// Enable BLE stack.
err_code = nrf_sdh_ble_enable(&ram_start);
APP_ERROR_CHECK(err_code);
// Register a handler for BLE events.
NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
#else
nrf_clock_lf_cfg_t clock_lf_cfg = {
.source = NRF_CLOCK_LF_SRC_SYNTH,
.rc_ctiv = 0,
@@ -500,8 +580,36 @@ static void ble_stack_init(void)
// Subscribe for System events.
err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);
#endif
}
#if defined(S112)
/**@brief Function for handling events from the GATT library. */
void gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
{
if ((m_conn_handle == p_evt->conn_handle) && (p_evt->evt_id == NRF_BLE_GATT_EVT_ATT_MTU_UPDATED))
{
m_ble_max_data_len = p_evt->params.att_mtu_effective - OPCODE_LENGTH - HANDLE_LENGTH;
NRF_LOG_INFO("Data len is set to 0x%X(%d)", m_ble_max_data_len, m_ble_max_data_len);
}
NRF_LOG_DEBUG("ATT MTU exchange completed. central 0x%x peripheral 0x%x",
p_gatt->att_mtu_desired_central,
p_gatt->att_mtu_desired_periph);
}
/**@brief Function for initializing the GATT library. */
void gatt_init(void)
{
ret_code_t err_code;
err_code = nrf_ble_gatt_init(&m_gatt, gatt_evt_handler);
APP_ERROR_CHECK(err_code);
err_code = nrf_ble_gatt_att_mtu_periph_set(&m_gatt, NRF_SDH_BLE_GATT_MAX_MTU_SIZE);
APP_ERROR_CHECK(err_code);
}
#else
// Set BW Config to HIGH.
static void ble_options_set(void)
{
@@ -516,12 +624,35 @@ static void ble_options_set(void)
err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_BW, &ble_opt);
APP_ERROR_CHECK(err_code);
}
#endif
/**@brief Function for initializing the Advertising functionality.
*/
static void advertising_init(void)
{
uint32_t err_code;
#if defined(S112)
ble_advertising_init_t init;
memset(&init, 0, sizeof(init));
init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
init.advdata.include_appearance = false;
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
init.srdata.uuids_complete.p_uuids = m_adv_uuids;
init.config.ble_adv_fast_enabled = true;
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
init.config.ble_adv_fast_timeout = APP_ADV_TIMEOUT_IN_SECONDS * 100;
init.evt_handler = on_adv_evt;
err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(err_code);
ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
#else
ble_advdata_t advdata;
ble_advdata_t scanrsp;
ble_adv_modes_config_t options;
@@ -543,14 +674,7 @@ static void advertising_init(void)
err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
APP_ERROR_CHECK(err_code);
}
/**@brief Function for the Power manager.
*/
static void power_manage(void)
{
uint32_t err_code = sd_app_evt_wait();
APP_ERROR_CHECK(err_code);
#endif
}
#if NRF_MODULE_ENABLED(NRF_LOG)
@@ -560,22 +684,46 @@ static uint32_t timestamp_func(void)
}
#endif
/**@brief Function for initializing the nrf log module.
*/
static void log_init(void)
{
ret_code_t err_code = NRF_LOG_INIT(timestamp_func);
APP_ERROR_CHECK(err_code);
#if defined(S112)
NRF_LOG_DEFAULT_BACKENDS_INIT();
#endif
}
/**@brief Function for handling the idle state (main loop).
*
* @details If there is no pending log operation, then sleep until next the next event occurs.
*/
static void idle_state_handle(void)
{
if (NRF_LOG_PROCESS() == false)
{
APP_ERROR_CHECK(sd_app_evt_wait());
}
}
/**@brief Function for application main entry.
*/
int main(void)
{
uint32_t err_code;
err_code = NRF_LOG_INIT(timestamp_func);
APP_ERROR_CHECK(err_code);
log_init();
NRF_LOG_DEBUG("init..\n");
timers_init();
ble_stack_init();
scheduler_init();
ble_options_set();
gap_params_init();
#if defined(S112)
gatt_init();
#else
ble_options_set();
#endif
services_init();
advertising_init();
conn_params_init();
@@ -592,8 +740,6 @@ int main(void)
for (;;)
{
app_sched_execute();
if (NRF_LOG_PROCESS() == false)
power_manage();
idle_state_handle();
}
}