Compare commits

..

37 Commits

Author SHA1 Message Date
chain40 4c615f0b3b create dfu service 2023-09-27 07:17:40 +08:00
chain40 a8d9400624 use nrfutil create OTA file 2023-09-26 22:00:36 +08:00
chain40 6b4d87232a gcc compiler 12.3.1 2023-09-19 20:35:46 +08:00
chain40 06a1b0d036 clrea regular data queue when connected 2023-06-07 23:13:04 +08:00
chain40 c8a4a15b3d remove PHY request when connected event.
1. 2M PHY can be requested from either slave or master device.

2. In Elite device, the 2M PHY be requested from master device.
2023-06-07 23:12:29 +08:00
chain40 2f1a013dd4 reset eis char notify enable status 2023-06-07 23:05:00 +08:00
chain40 4f0a383880 bugfix: fix BLE_UUID_EIS_EVENT_CHAR error 2023-06-07 23:04:11 +08:00
charles a2653f7919 To achieve maximum throughput for the BLE dongle.
1. Set the maximum connection interval to 20ms.
2. Refactory pseudo_data_task()
3. Decrease size of regular_data_q
2023-05-25 15:24:22 +08:00
charles 066b436762 bugfix: increase hvn_tx_queue_size for high freq notify 2023-05-25 13:41:58 +08:00
charles fdab23e151 bugfix: fix channel_len (group_length) field miss 2023-05-25 13:08:51 +08:00
charles 386bc17007 bugfix: fix wrong offset for checksum 2023-05-25 11:29:34 +08:00
charles 8ed0921284 regular_data_notify_demo.py bugfix 2023-05-25 11:25:03 +08:00
chain40 3e1d8bfedc implenmet eis_regular_data feature
1. create 2 pseudo task, update freq = 1KHz
2. add regular_data_notify_demo.py for validation
2023-05-25 10:27:17 +08:00
chain40 bb5bf77aa1 update gap/gatt configurtion 2023-05-25 00:15:53 +08:00
chain40 99482ff463 update GAP/GATT configure for ATT MTU
1. set gap data length = 251
2. set gatt mtu = 247
3. increase gap event length (events per connection interval)
4. increase ram usage for softdevice
2023-05-25 00:15:35 +08:00
chain40 adc92b10ac main.c code refactoring
1. remove led1_task, led1_task.
2. send phy update request when conncted.
3. le_evt_handler() ouput more ble event information
2023-05-25 00:08:50 +08:00
chain40 d0d915d69e update freertos configuration
1. remove unused functions
2. increase freertos heap size to 32KB
3. increase max of priorities
2023-05-25 00:06:12 +08:00
chain40 4894838edf Revert "create EIS battery volt update interval characteristic (uint: ms)"
This reverts commit 811bcae588.
2023-05-11 20:34:06 +08:00
charles 811bcae588 create EIS battery volt update interval characteristic (uint: ms)
1.  if battery volt update interval < 100ms, set interval = 100ms
2023-05-11 17:05:28 +08:00
charles 6162d15791 define le_eis_bat_volt_update(). sending notification with the battery volt characteristic , if notification is enable,
1. define on_connect()
2. define on_disconnect()
2023-05-11 14:27:51 +08:00
charles c358f20a8a create battery task 2023-05-11 14:14:30 +08:00
chain40 60fb26518a fix BLE_GATTS_EVT_SYS_ATTR_MISSING issue 2023-05-11 08:12:20 +08:00
chain40 672ccaaa02 set the battery voltage characteristic as a notification characteristic Part 1.
1. register handler for ble events
2. add eis_ccc_update() for CCCD (client characteristic configuration descriptor)
2023-05-11 08:12:14 +08:00
chain40 2f708e0113 create EIS battery volt characteristic, and support read only 2023-05-10 23:19:31 +08:00
chain40 10aed00a1c create EIS service 2023-05-10 23:00:25 +08:00
chain40 d0f90da1fd Merge branch 'device_info_srv' 2023-05-09 21:00:15 +08:00
chain40 da65b6ab49 add device info service 2023-05-09 21:00:09 +08:00
chain40 d114bac8f0 Merge branch 'gatt' 2023-05-09 20:59:42 +08:00
chain40 f6ea58ce38 handle BLE_GAP_EVT_PHY_UPDATE_REQUEST for phy update request 2023-05-09 20:59:28 +08:00
chain40 905cdfee4d add gatt initialization 2023-05-09 19:26:20 +08:00
chain40 0f7c3e9803 Merge branch 'advertising' 2023-05-09 08:10:18 +08:00
chain40 5246b2f867 add manuf_specific_data(custom data) in advertising packet 2023-05-09 08:10:06 +08:00
chain40 a69b875884 remove "appearance" from advertising packet and housekeeping 2023-05-09 08:02:56 +08:00
chain40 414c88aea2 Merge branch 'ble' into develop 2023-05-06 16:13:23 +08:00
chain40 c8c8d6fe73 add le_gap.c / le_adv.c 2023-05-06 16:10:45 +08:00
chain40 88d3e6c7c3 add nrf_sdh_freertos_init() 2023-05-06 15:50:29 +08:00
chain40 d439f4d2ba enable ble stack 2023-05-06 13:28:31 +08:00
19 changed files with 439 additions and 1598 deletions
+18 -38
View File
@@ -108,24 +108,20 @@ extern "C"
#define DEF_ELITE_EIS_10 0x00040100
#define DEF_ELITE_EIS_11 0x00040101
#define DEF_ELITE_EIS_MINI_10 0x00040102
#define DEF_ELITE_MODEL DEF_ELITE_EDC_15RE
#define DEF_ELITE_MODEL DEF_ELITE_EIS_11
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
#define ELITE_DEVICE_NAME "EDC"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 2
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 7
#define BLE_EDC_ENABLED 1
#define EDC_BLE_OBSERVER_PRIO 3
#define ELITE_DEVICE_NAME "EDC"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 2
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 7
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
#define ELITE_DEVICE_NAME "EDC"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 2
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 8
#define BLE_EDC_ENABLED 1
#define EDC_BLE_OBSERVER_PRIO 3
#define ELITE_DEVICE_NAME "EDC"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 2
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 8
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
#define ELITE_DEVICE_NAME "EIS"
#define MAJOR_PRODUCT_NUMBER 0
@@ -133,7 +129,7 @@ extern "C"
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 0
#define BLE_EIS_ENABLED 1
#define EDC_BLE_OBSERVER_PRIO 3
#define EIS_BLE_OBSERVER_PRIO 3
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#define ELITE_DEVICE_NAME "EIS"
#define MAJOR_PRODUCT_NUMBER 0
@@ -141,15 +137,13 @@ extern "C"
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 1
#define BLE_EIS_ENABLED 1
#define EDC_BLE_OBSERVER_PRIO 3
#define EIS_BLE_OBSERVER_PRIO 3
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
#define ELITE_DEVICE_NAME "EIS"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 4
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 2
#define BLE_EIS_ENABLED 1
#define EDC_BLE_OBSERVER_PRIO 3
#define ELITE_DEVICE_NAME "EIS"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 4
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 2
#endif
#define ELITE_COMPANY_CODE "Elite"
@@ -184,20 +178,6 @@ extern "C"
#define BLE_DFU_BLE_OBSERVER_PRIO 2
#define NRF_PWR_MGMT_ENABLED 1
// Enable spim
#define SPI_ENABLED 1
#define SPI1_ENABLED 1
#define SPI1_USE_EASY_DMA 1
#define SPI2_ENABLED 1
#define SPI2_USE_EASY_DMA 1
#define SPI_DEFAULT_CONFIG_IRQ_PRIORITY 7
#define NRFX_SPIM_MISO_PULL_CFG 3
// Enable twi(i2c)
#define TWI_ENABLED 1
#define TWI0_ENABLED 1
#define TWI0_USE_EASY_DMA 1
#ifdef __cplusplus
}
#endif
+4 -11
View File
@@ -164,8 +164,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_spi.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_spis.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
@@ -174,24 +173,19 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_twi.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_uart.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="edc_regular_data.c" />
<ClCompile Include="i2c.c" />
<ClCompile Include="led.c" />
<ClCompile Include="eis_regular_data.c" />
<ClCompile Include="le_adv.c" />
<ClCompile Include="le_dfu.c" />
<ClCompile Include="le_edc_srv.c" />
<ClCompile Include="le_eis_srv.c" />
<ClCompile Include="le_gap.c" />
<ClCompile Include="le_gatt.c" />
<ClCompile Include="le_srv.c" />
<ClCompile Include="main.c" />
<ClCompile Include="spi.c" />
<ClCompile Include="syscalls.c" />
<None Include="nRF52811_XXAA_s140.lds" />
<None Include="nRF52840_XXAA_S140_reserve.lds" />
<None Include="nrf5x.props" />
@@ -336,7 +330,6 @@
<ClInclude Include="..\bmd380_sdk\integration\nrfx\nrfx_log.h" />
<ClInclude Include="app_config.h" />
<ClInclude Include="FreeRTOSConfig.h" />
<ClInclude Include="led.h" />
<ClInclude Include="sdk_config.h" />
<ClInclude Include="radio_config.h" />
<ClInclude Include="sdio_config.h" />
+64 -40
View File
@@ -232,6 +232,42 @@
<Filter Include="Header files\ble\common">
<UniqueIdentifier>{defffc43-551c-4791-967b-7d0aee507516}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\ble\nrf_ble_gatt">
<UniqueIdentifier>{345707cc-7a27-4c28-94b4-19df7d90e78d}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\ble\nrf_ble_gatt">
<UniqueIdentifier>{b6e27cec-5179-4ec4-8f4d-e7e9fbaabae8}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\ble\ble_services">
<UniqueIdentifier>{4153528a-d996-4c55-be9f-917ce26d6277}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\ble\ble_services">
<UniqueIdentifier>{7abc8adc-4234-4ec2-a927-53d29690cfc0}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\ble\ble_services\ble_dis">
<UniqueIdentifier>{2cf242dc-b5b5-4aa3-b56f-92c1afd295a1}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\ble\ble_services\ble_dis">
<UniqueIdentifier>{e8688895-c809-46b5-a2ab-2bd49da33d45}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\atomic_flags">
<UniqueIdentifier>{104f5151-8aba-4322-889f-18db11a159d5}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\atomic_flags">
<UniqueIdentifier>{8d9d4979-4f73-44d8-a1a3-2ffab500203f}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\ble\ble_services\ble_dfu">
<UniqueIdentifier>{66efbcba-2f2c-4f6b-88b7-373adf4cac3c}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\ble\ble_services\ble_dfu">
<UniqueIdentifier>{67ca4d15-7a65-482f-a7eb-a6f92d2e1bb4}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\pwr_mgmt">
<UniqueIdentifier>{0dee1448-4304-4fc9-ae41-f733003a27bf}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\pwr_mgmt">
<UniqueIdentifier>{9d008a9d-bd88-4a95-8bda-04ef32a7ce4b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
@@ -1320,46 +1356,37 @@
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_srv_common.h">
<Filter>Header files\ble\common</Filter>
</ClInclude>
<ClCompile Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu_unbonded.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dis\ble_dis.c">
<ClCompile Include="le_gatt.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\nrf_ble_gatt\nrf_ble_gatt.c">
<Filter>Source files</Filter>
<Filter>Source files\ble\nrf_ble_gatt</Filter>
</ClCompile>
<ClCompile Include="edc_regular_data.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="le_dfu.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="le_edc_srv.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="le_gatt.c">
<Filter>Source files</Filter>
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dis\ble_dis.c">
<Filter>Source files\ble\ble_services\ble_dis</Filter>
</ClCompile>
<ClCompile Include="le_srv.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="syscalls.c">
<ClCompile Include="le_eis_srv.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.c">
<Filter>Source files\atomic_flags</Filter>
</ClCompile>
<ClCompile Include="eis_regular_data.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu_unbonded.c">
<Filter>Source files\ble\ble_services\ble_dfu</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu.c">
<Filter>Source files\ble\ble_services\ble_dfu</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\libraries\pwr_mgmt\nrf_pwr_mgmt.c">
<Filter>Source files</Filter>
<Filter>Source files\pwr_mgmt</Filter>
</ClCompile>
<ClCompile Include="led.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="spi.c">
<ClCompile Include="le_dfu.c">
<Filter>Source files</Filter>
</ClCompile>
</ItemGroup>
@@ -1612,23 +1639,20 @@
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_soc.h">
<Filter>Header files\softdevice\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu.h">
<Filter>Header files</Filter>
<ClInclude Include="..\bmd380_sdk\components\ble\nrf_ble_gatt\nrf_ble_gatt.h">
<Filter>Header files\ble\nrf_ble_gatt</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\ble_services\ble_dis\ble_dis.h">
<Filter>Header files</Filter>
<Filter>Header files\ble\ble_services\ble_dis</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\nrf_ble_gatt\nrf_ble_gatt.h">
<Filter>Header files</Filter>
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.h">
<Filter>Header files\atomic_flags</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu.h">
<Filter>Header files\ble\ble_services\ble_dfu</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\libraries\pwr_mgmt\nrf_pwr_mgmt.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="led.h">
<Filter>Header files</Filter>
<Filter>Header files\pwr_mgmt</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
+3 -3
View File
@@ -220,7 +220,7 @@ static void regular_data_msg_task(void *pArg)
}
}
static void edc_regular_data_handler(ble_evt_t const *p_ble_evt, void *p_context)
static void eis_regular_data_handler(ble_evt_t const *p_ble_evt, void *p_context)
{
switch (p_ble_evt->header.evt_id)
{
@@ -238,7 +238,7 @@ static void edc_regular_data_handler(ble_evt_t const *p_ble_evt, void *p_context
}
}
void edc_regular_data_init(void)
void eis_regular_data_init(void)
{
regular_data_q = xQueueCreate(64, sizeof(channel_data_t));
if (regular_data_q == NULL)
@@ -257,5 +257,5 @@ void edc_regular_data_init(void)
xTaskCreate(regular_data_msg_task, "regular_msg", 192, NULL, 5, NULL);
xTaskCreate(pseudo_data_task, "pseudo_AA", 192, pseudo_sensorAA_read, 2, NULL);
xTaskCreate(pseudo_data_task, "pseudo_BB", 192, pseudo_sensorBB_read, 2, NULL);
NRF_SDH_BLE_OBSERVER(m_edc_regular_data_observer, 3, edc_regular_data_handler, NULL);
NRF_SDH_BLE_OBSERVER(m_eis_regular_data_observer, 3, eis_regular_data_handler, NULL);
}
-159
View File
@@ -1,159 +0,0 @@
#include "nrf_drv_twi.h"
#include "nrf_gpio.h"
#include "nrf_log.h"
#include "FreeRTOS.h"
#include "queue.h"
#include "semphr.h"
#include "task.h"
#define I2C_SDA NRF_GPIO_PIN_MAP(0, 11)
#define I2C_SCL NRF_GPIO_PIN_MAP(0, 2)
static const nrf_drv_twi_t twi0 = NRF_DRV_TWI_INSTANCE(0);
static SemaphoreHandle_t i2c_sem = NULL;
static SemaphoreHandle_t i2c_mutex = NULL;
static QueueHandle_t i2c_evt_queue = NULL;
void nrf_drv_twi_evt_handler(nrf_drv_twi_evt_t const *p_event, void *p_context)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(i2c_evt_queue, p_event, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
static void virtual_data(uint8_t *p_rx_buf, uint8_t rx_buffer_length)
{
uint8_t virtual_data_buff[20] = { 9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
if (rx_buffer_length == 0)
return;
memcpy(p_rx_buf, virtual_data_buff, rx_buffer_length);
}
void twi0_write_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data, uint8_t data_len);
void twi0_init(void)
{
ret_code_t err_code;
i2c_sem = xSemaphoreCreateBinary();
i2c_mutex = xSemaphoreCreateMutex();
i2c_evt_queue = xQueueCreate(2, sizeof(nrf_drv_twi_evt_t));
const nrf_drv_twi_config_t twi0_config = {
.scl = I2C_SCL,
.sda = I2C_SDA,
.frequency = NRF_DRV_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = true
};
err_code = nrf_drv_twi_init(&twi0, &twi0_config, nrf_drv_twi_evt_handler, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&twi0);
}
void twi0_write_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data, uint8_t data_len)
{
xSemaphoreTake(i2c_mutex, portMAX_DELAY);
static uint8_t i2c_buf[255];
static nrf_drv_twi_evt_t evt;
ret_code_t err_code;
memcpy(i2c_buf, &reg_addr, sizeof(reg_addr));
memcpy(i2c_buf + sizeof(reg_addr), data, data_len);
err_code = nrf_drv_twi_tx(&twi0, slave_addr, i2c_buf, data_len + 1, false);
APP_ERROR_CHECK(err_code);
xQueueReceive(i2c_evt_queue, &evt, portMAX_DELAY);
switch (evt.type)
{
/* Transfer completed event. */
case NRF_DRV_TWI_EVT_DONE:
// TODO...
break;
/* Error event: NACK received after sending the address. */
case NRF_DRV_TWI_EVT_ADDRESS_NACK:
// TODO...
__BKPT(255);
break;
/* Error event: NACK received after sending a data byte. */
case NRF_DRV_TWI_EVT_DATA_NACK:
// TODO...
__BKPT(255);
break;
default:
__BKPT(255);
break;
}
xSemaphoreGive(i2c_mutex);
NRF_LOG_INFO("i2c(W): slave_addr=0x%02x", slave_addr);
NRF_LOG_HEXDUMP_INFO(i2c_buf, sizeof(i2c_buf));
}
void twi0_read_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_rx_buf, uint8_t rx_buffer_length)
{
xSemaphoreTake(i2c_mutex, portMAX_DELAY);
nrf_drv_twi_evt_t evt;
ret_code_t err_code;
err_code = nrf_drv_twi_tx(&twi0, slave_addr, &reg_addr, sizeof(reg_addr), false);
APP_ERROR_CHECK(err_code);
xQueueReceive(i2c_evt_queue, &evt, portMAX_DELAY);
switch (evt.type)
{
/* Transfer completed event. */
case NRF_DRV_TWI_EVT_DONE:
// TODO...
break;
/* Error event: NACK received after sending the address. */
case NRF_DRV_TWI_EVT_ADDRESS_NACK:
// TODO...
__BKPT(255);
break;
/* Error event: NACK received after sending a data byte. */
case NRF_DRV_TWI_EVT_DATA_NACK:
// TODO...
__BKPT(255);
break;
default:
break;
}
err_code = nrf_drv_twi_rx(&twi0, slave_addr, p_rx_buf, rx_buffer_length);
APP_ERROR_CHECK(err_code);
xQueueReceive(i2c_evt_queue, &evt, portMAX_DELAY);
switch (evt.type)
{
/* Transfer completed event. */
case NRF_DRV_TWI_EVT_DONE:
// TODO...
break;
/* Error event: NACK received after sending the address. */
case NRF_DRV_TWI_EVT_ADDRESS_NACK:
// TODO...
__BKPT(255);
break;
/* Error event: NACK received after sending a data byte. */
case NRF_DRV_TWI_EVT_DATA_NACK:
// TODO...
__BKPT(255);
break;
default:
break;
}
xSemaphoreGive(i2c_mutex);
NRF_LOG_INFO("i2c(R): slave_addr=0x%02x reg_addr=0x%02x", slave_addr, reg_addr);
NRF_LOG_HEXDUMP_INFO(p_rx_buf, rx_buffer_length);
}
+1 -1
View File
@@ -72,7 +72,7 @@ void le_adv_init(uint8_t ble_conn_cfg_tag)
.bat_volt = 100,
};
ble_advdata_manuf_data_t manuf_specific_data; // Advertising Data: add manuf_specific_data = FF FF 45 6C 69 74 65 00 04 01 01 1C 0C
ble_advdata_manuf_data_t manuf_specific_data;
manuf_specific_data.data.p_data = (uint8_t *)&data;
manuf_specific_data.data.size = sizeof(data);
manuf_specific_data.company_identifier = 0xFFFF;
+36 -39
View File
@@ -23,58 +23,55 @@ extern "C"
#include "ble_conn_state.h"
#include "ble_dfu.h"
#include "ble_dis.h"
#include "ble_dfu.h"
#include "nrf_ble_gatt.h"
#ifdef __cplusplus
}
#endif
static void le_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
{
switch (event)
{
case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
NRF_LOG_INFO("Device is preparing to enter bootloader mode.");
// Disconnect all other bonded devices that currently are connected.
// This is required to receive a service changed indication
// on bootup after a successful (or aborted) Device Firmware Update.
extern void le_gap_disconnect(uint16_t conn_handle, void *p_context);
uint32_t conn_count = ble_conn_state_for_each_connected(le_gap_disconnect, NULL);
NRF_LOG_INFO("Disconnected %d links.", conn_count);
break;
static void le_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event) {
switch (event) {
case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
NRF_LOG_INFO("Device is preparing to enter bootloader mode.");
// Disconnect all other bonded devices that currently are connected.
// This is required to receive a service changed indication
// on bootup after a successful (or aborted) Device Firmware Update.
extern void le_gap_disconnect(uint16_t conn_handle, void * p_context);
uint32_t conn_count = ble_conn_state_for_each_connected(le_gap_disconnect, NULL);
NRF_LOG_INFO("Disconnected %d links.", conn_count);
break;
case BLE_DFU_EVT_BOOTLOADER_ENTER:
// YOUR_JOB: Write app-specific unwritten data to FLASH, control finalization of this
// by delaying reset by reporting false in app_shutdown_handler
NRF_LOG_INFO("Device will enter bootloader mode.");
break;
case BLE_DFU_EVT_BOOTLOADER_ENTER:
// YOUR_JOB: Write app-specific unwritten data to FLASH, control finalization of this
// by delaying reset by reporting false in app_shutdown_handler
NRF_LOG_INFO("Device will enter bootloader mode.");
break;
case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
NRF_LOG_ERROR("Request to enter bootloader mode failed asynchroneously.");
// YOUR_JOB: Take corrective measures to resolve the issue
// like calling APP_ERROR_CHECK to reset the device.
break;
case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
NRF_LOG_ERROR("Request to enter bootloader mode failed asynchroneously.");
// YOUR_JOB: Take corrective measures to resolve the issue
// like calling APP_ERROR_CHECK to reset the device.
break;
case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
NRF_LOG_ERROR("Request to send a response to client failed.");
// YOUR_JOB: Take corrective measures to resolve the issue
// like calling APP_ERROR_CHECK to reset the device.
APP_ERROR_CHECK(false);
break;
case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
NRF_LOG_ERROR("Request to send a response to client failed.");
// YOUR_JOB: Take corrective measures to resolve the issue
// like calling APP_ERROR_CHECK to reset the device.
APP_ERROR_CHECK(false);
break;
default:
NRF_LOG_ERROR("Unknown event from ble_dfu_buttonless.");
break;
default:
NRF_LOG_ERROR("Unknown event from ble_dfu_buttonless.");
break;
}
}
void le_dfu_init(void)
{
// ble dfu service
void le_dfu_init(void) {
// ble dfu service
ble_dfu_buttonless_init_t dfus_init = { 0 };
dfus_init.evt_handler = le_dfu_evt_handler;
ret_code_t err_code = ble_dfu_buttonless_init(&dfus_init);
dfus_init.evt_handler = le_dfu_evt_handler;
ret_code_t err_code = ble_dfu_buttonless_init(&dfus_init);
APP_ERROR_CHECK(err_code);
}
-728
View File
@@ -1,728 +0,0 @@
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(BLE_EDC)
#include "app_error.h"
#include "ble_conn_state.h"
#include "ble_gatts.h"
#include "ble_srv_common.h"
#include "nrf_sdh_ble.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include <stdlib.h>
#include <string.h>
/**< Used vendor specific UUID. */
#define BLE_EDC_BASE_UUID \
{ \
{ \
0x4D, 0x3C, 0x56, 0x45, 0x12, 0x8B, 0x44, 0x1D, 0x8D, 0x6F, 0xC5, 0x95, 0x00, 0x00, 0x9B, 0xD8 \
} \
}
#define BLE_UUID_EDC_SERVICE 0x0001
#define BLE_UUID_EDC_BAT_VOLT_CHAR 0x0002
#define BLE_UUID_EDC_LOW_FREQ_DATA_CHAR 0x0003
#define BLE_UUID_EDC_AUXILIARY_DATA_CHAR 0x0004
#define BLE_UUID_EDC_STATUS_CHAR 0x0005
#define BLE_UUID_EDC_EVENT_CHAR 0x0006
#define BLE_UUID_EDC_INSTRUCTION_CHAR 0x0007
typedef struct
{
uint16_t conn_handle;
uint16_t service_handle;
ble_gatts_char_handles_t regular_data_handles;
ble_gatts_char_handles_t low_freq_data_handles;
ble_gatts_char_handles_t auxiliary_data_handles;
ble_gatts_char_handles_t status_handles;
ble_gatts_char_handles_t event_handles;
ble_gatts_char_handles_t instruction_handles;
bool regular_data_notify_enable;
bool low_freq_data_notify_enable;
bool auxiliary_data_notify_enable;
bool status_notify_enable;
bool event_notify_enable;
uint8_t instruction[20];
} ble_edc_t;
typedef struct
{
uint16_t dummy;
} ble_edc_init_t;
static ble_edc_t ble_edc = {
.conn_handle = BLE_CONN_HANDLE_INVALID,
.regular_data_notify_enable = false,
.low_freq_data_notify_enable = false,
.auxiliary_data_notify_enable = false,
.status_notify_enable = false,
.event_notify_enable = false,
};
static void on_connect(ble_edc_t *p_edc, ble_evt_t const *p_ble_evt)
{
p_edc->conn_handle = p_ble_evt->evt.common_evt.conn_handle;
}
static void on_disconnect(ble_edc_t *p_edc, ble_evt_t const *p_ble_evt)
{
p_edc->conn_handle = BLE_CONN_HANDLE_INVALID;
p_edc->regular_data_notify_enable = false;
p_edc->low_freq_data_notify_enable = false;
p_edc->auxiliary_data_notify_enable = false;
p_edc->status_notify_enable = false;
p_edc->event_notify_enable = false;
}
static void edc_ccc_update(ble_edc_t *p_edc, ble_evt_t const *p_ble_evt)
{
ble_gatts_evt_write_t const *p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
if (p_evt_write->handle == p_edc->regular_data_handles.cccd_handle)
{
p_edc->regular_data_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("regular_data_notify:%s", p_edc->regular_data_notify_enable ? "enable" : "disable");
return;
}
else if (p_evt_write->handle == p_edc->low_freq_data_handles.cccd_handle)
{
p_edc->low_freq_data_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("low_freq_data_notify:%s", p_edc->low_freq_data_notify_enable ? "enable" : "disable");
return;
}
else if (p_evt_write->handle == p_edc->auxiliary_data_handles.cccd_handle)
{
p_edc->auxiliary_data_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("auxiliary_data_notify:%s", p_edc->auxiliary_data_notify_enable ? "enable" : "disable");
return;
}
else if (p_evt_write->handle == p_edc->status_handles.cccd_handle)
{
p_edc->status_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("status_notify:%s", p_edc->status_notify_enable ? "enable" : "disable");
return;
}
else if (p_evt_write->handle == p_edc->event_handles.cccd_handle)
{
p_edc->event_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("event_notify:%s", p_edc->event_notify_enable ? "enable" : "disable");
return;
}
}
void instruction_char_reply(uint8_t *reply, uint32_t reply_len)
{
// update database.
ble_gatts_value_t gatts_value = {
.p_value = reply,
.offset = 0,
.len = reply_len,
};
ret_code_t err_code = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, ble_edc.instruction_handles.value_handle, &gatts_value);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("reply[gatt]");
NRF_LOG_HEXDUMP_INFO(reply, reply_len);
}
#include "led.h"
static void tool_change_led(uint8_t *instru_received)
{
// instruction: 0x3xxxFF01ccll
// ps. ll = brightness
// ps. cc = 00 | 01 | 02 | 03 | 04 | 05 |
// LED_NONE | LED_RED | LED_GREEN | LED_CYAN | LED_BLUE | LED_PURPLE |
struct led_color color;
uint8_t brightness = *(instru_received + 5);
uint8_t reply[20] = { 0 };
switch (*(instru_received + 4))
{
case 0x00:
color = LED_NONE;
memcpy(reply, "LED_NONE", sizeof("LED_NONE"));
NRF_LOG_INFO("LED_NONE(%d)", brightness);
break;
case 0x01:
color = LED_RED;
memcpy(reply, "LED_RED", sizeof("LED_RED"));
NRF_LOG_INFO("LED_RED(%d)", brightness);
break;
case 0x02:
color = LED_GREEN;
memcpy(reply, "LED_GREEN", sizeof("LED_GREEN"));
NRF_LOG_INFO("LED_GREEN(%d)", brightness);
break;
case 0x03:
color = LED_CYAN;
memcpy(reply, "LED_CYAN", sizeof("LED_CYAN"));
NRF_LOG_INFO("LED_CYAN(%d)", brightness);
break;
case 0x04:
color = LED_BLUE;
memcpy(reply, "LED_BLUE", sizeof("LED_BLUE"));
NRF_LOG_INFO("LED_BLUE(%d)", brightness);
break;
case 0x05:
color = LED_PURPLE;
memcpy(reply, "LED_PURPLE", sizeof("LED_PURPLE"));
NRF_LOG_INFO("LED_PURPLE(%d)", brightness);
break;
default:
memcpy(reply, "Wrong...", sizeof("Wrong..."));
NRF_LOG_INFO("Wrong...");
break;
}
for (int i = 0; i < 12; i++)
{
led_set(i, color, brightness);
}
instruction_char_reply(reply, sizeof(reply));
}
#include "nrf_gpio.h"
static void tool_gpio_output(uint8_t *instru_received)
{
// tool_gpio_output()
// instruction: 0x3xxxFFA0ppnnss
// ps. pp = 00 | 01 |
// part0 | part1 |
// ps. nn = 0x00 ~ 0x31
// ps. ss = 00 | 01 |
// low | hihg |
uint16_t pin_number_user = *(instru_received + 4) << 8 | *(instru_received + 5);
uint8_t pin_signal = *(instru_received + 6);
uint8_t reply[20] = { 0 };
uint32_t pin;
switch (pin_number_user)
{
case 0x0015:
pin = NRF_GPIO_PIN_MAP(0, 15);
break;
case 0x0020: // special pin for BMD380 EVK
pin = NRF_GPIO_PIN_MAP(0, 20);
break;
case 0x0008:
pin = NRF_GPIO_PIN_MAP(0, 8);
break;
case 0x0006:
pin = NRF_GPIO_PIN_MAP(0, 6);
break;
case 0x0005:
pin = NRF_GPIO_PIN_MAP(0, 5);
break;
case 0x0025:
pin = NRF_GPIO_PIN_MAP(0, 25);
break;
case 0x0019: // special pin for BMD380 EVK
pin = NRF_GPIO_PIN_MAP(0, 19);
break;
case 0x0021: // special pin for BMD380 EVK
pin = NRF_GPIO_PIN_MAP(0, 21);
break;
case 0x0017: // special pin for BMD380 EVK
pin = NRF_GPIO_PIN_MAP(0, 17);
break;
case 0x0026:
pin = NRF_GPIO_PIN_MAP(0, 26);
break;
case 0x0004:
pin = NRF_GPIO_PIN_MAP(0, 4);
break;
case 0x0112:
pin = NRF_GPIO_PIN_MAP(1, 12);
break;
case 0x0114:
pin = NRF_GPIO_PIN_MAP(1, 14);
break;
case 0x0113:
pin = NRF_GPIO_PIN_MAP(1, 13);
break;
case 0x0103:
pin = NRF_GPIO_PIN_MAP(1, 3);
break;
case 0x0110:
pin = NRF_GPIO_PIN_MAP(1, 10);
break;
case 0x0106:
pin = NRF_GPIO_PIN_MAP(1, 6);
break;
case 0x0111:
pin = NRF_GPIO_PIN_MAP(1, 11);
break;
case 0x0016:
pin = NRF_GPIO_PIN_MAP(0, 16);
break;
default:
memcpy(reply, "Wrong...", sizeof("Wrong..."));
NRF_LOG_INFO("Wrong...");
instruction_char_reply(reply, sizeof(reply));
return;
break;
}
if (pin_signal == 0)
{
nrf_gpio_pin_clear(pin);
memset(reply, (pin_number_user & 0xFF00) >> 8, 1);
memset(reply + 1, (pin_number_user & 0x00FF), 1);
memset(reply + 2, pin_signal, 1);
NRF_LOG_INFO("tool_gpio_output(): P%X.%02X(%d)", (pin_number_user & 0xFF00) >> 8, pin_number_user & 0x00FF, pin_signal);
}
else if (pin_signal == 1)
{
nrf_gpio_pin_set(pin);
memset(reply, (pin_number_user & 0xFF00) >> 8, 1);
memset(reply + 1, (pin_number_user & 0x00FF), 1);
memset(reply + 2, pin_signal, 1);
NRF_LOG_INFO("tool_gpio_output(): P%X.%02X(%d)", (pin_number_user & 0xFF00) >> 8, pin_number_user & 0x00FF, pin_signal);
}
else
{
memcpy(reply, "Wrong...", sizeof("Wrong..."));
NRF_LOG_INFO("Wrong...");
}
instruction_char_reply(reply, sizeof(reply));
}
static void tool_gpio_input(uint8_t *instru_received)
{
// tool_gpio_input()
// instruction: 0x3xxxFFA1ppnn
// ps. pp = 00 | 01 |
// part0 | part1 |
// ps. nn = 0x00 ~ 0x31
uint16_t pin_number_user = *(instru_received + 4) << 8 | *(instru_received + 5);
uint8_t reply[20] = { 0 };
uint32_t pin;
uint32_t pin_signal;
switch (pin_number_user)
{
case 0x0003:
pin = NRF_GPIO_PIN_MAP(0, 3);
break;
case 0x0027:
pin = NRF_GPIO_PIN_MAP(0, 27);
break;
case 0x0108:
pin = NRF_GPIO_PIN_MAP(1, 8);
break;
default:
memcpy(reply, "Wrong...", sizeof("Wrong..."));
NRF_LOG_INFO("Wrong...");
instruction_char_reply(reply, sizeof(reply));
return;
break;
}
pin_signal = nrf_gpio_pin_read(pin);
memset(reply, (pin_number_user & 0xFF00) >> 8, 1);
memset(reply + 1, (pin_number_user & 0x00FF), 1);
memset(reply + 2, pin_signal, 1);
NRF_LOG_INFO("tool_gpio_input(): P%X.%02X(%d)", (pin_number_user & 0xFF00) >> 8, pin_number_user & 0x00FF, pin_signal);
instruction_char_reply(reply, sizeof(reply));
}
extern void spi2_write(uint32_t cs_pin, uint8_t *p_tx_buffer, uint8_t tx_buffer_length, uint8_t *p_rx_buf, uint8_t rx_buffer_length);
#define CS_SW_PIN NRF_GPIO_PIN_MAP(0, 20)
#define CS_MEM_PIN NRF_GPIO_PIN_MAP(0, 8)
#define CS_ADC_PIN NRF_GPIO_PIN_MAP(0, 6)
#define CS_DAC_PIN NRF_GPIO_PIN_MAP(0, 5)
static void tool_spi2(uint8_t *instru_received)
{
// tool_spi2()
// instruction: 0x3xxxFFA2ssttrrcccccc......
// ps. ss = selector
// | 00 | 01 | 02 | 03 |
// | SW | MEM | ADC | DAC |
// ps. tt = tx length
// ps. rr = rx length
// ps. cc = tx content
uint8_t chip_seletor = *(instru_received + 4);
uint8_t tx_buffer_len = *(instru_received + 5);
uint8_t rx_buffer_len = *(instru_received + 6);
uint8_t tx_buffer[tx_buffer_len];
uint8_t rx_buffer[rx_buffer_len];
uint8_t reply[20] = { 0 };
memcpy(tx_buffer, instru_received + 7, tx_buffer_len);
switch (chip_seletor)
{
case 0x00:
NRF_LOG_INFO("tool_spi2(): CS_SW");
spi2_write(CS_SW_PIN, tx_buffer, tx_buffer_len, rx_buffer, rx_buffer_len);
break;
case 0x01:
NRF_LOG_INFO("tool_spi2(): CS_MEM_PIN");
spi2_write(CS_MEM_PIN, tx_buffer, tx_buffer_len, rx_buffer, rx_buffer_len);
break;
case 0x02:
NRF_LOG_INFO("tool_spi2(): CS_ADC_PIN");
spi2_write(CS_ADC_PIN, tx_buffer, tx_buffer_len, rx_buffer, rx_buffer_len);
break;
case 0x03:
NRF_LOG_INFO("tool_spi2(): CS_DAC_PIN");
spi2_write(CS_DAC_PIN, tx_buffer, tx_buffer_len, rx_buffer, rx_buffer_len);
break;
default:
memcpy(reply, "Wrong...", sizeof("Wrong..."));
NRF_LOG_INFO("Wrong...");
instruction_char_reply(reply, sizeof(reply));
return;
break;
}
if (rx_buffer_len == 0)
{
instruction_char_reply(reply, sizeof(reply));
}
else
{
memcpy(reply, rx_buffer, rx_buffer_len);
instruction_char_reply(reply, sizeof(reply));
}
}
extern void twi0_write_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data, uint8_t data_len);
extern void twi0_read_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_rx_buf, uint8_t rx_buffer_length);
static void tool_i2c0(uint8_t *instru_received)
{
// tool_i2c0()
// instruction: 0x3xxxFFA3aaggttrrcccccc......
// ps. aa = slave address
// ps. gg = reg address
// ps. tt = tx length
// ps. rr = rx length
// ps. cc = tx content
NRF_LOG_INFO("tool_i2c0()");
uint8_t slave_addr = *(instru_received + 4);
uint8_t reg_addr = *(instru_received + 5);
uint8_t tx_buffer_len = *(instru_received + 6);
uint8_t rx_buffer_len = *(instru_received + 7);
uint8_t tx_buffer[tx_buffer_len];
uint8_t rx_buffer[rx_buffer_len];
uint8_t reply[20] = { 0 };
memcpy(tx_buffer, instru_received + 8, tx_buffer_len);
if (rx_buffer_len == 0)
{
twi0_write_reg(slave_addr, reg_addr, tx_buffer, tx_buffer_len);
instruction_char_reply(reply, sizeof(reply));
}
else
{
twi0_write_reg(slave_addr, reg_addr, tx_buffer, tx_buffer_len);
twi0_read_reg(slave_addr, reg_addr, rx_buffer, rx_buffer_len);
memcpy(reply, rx_buffer, rx_buffer_len);
instruction_char_reply(reply, sizeof(reply));
}
}
static void decode_instruction(uint8_t *instru_received)
{
uint32_t func = *(instru_received + 2);
switch (func)
{
case 0xFF: // tool 0x3xxxFF......
switch (*(instru_received + 3))
{
case 0x01: // instruction: 0x3xxxFF01ccll 3000FF010101
tool_change_led(instru_received);
break;
case 0xA0: // instruction: 0x3xxxFFA0ppnnss 3000FFA0011301
tool_gpio_output(instru_received);
break;
case 0xA1: // instruction: 0x3xxxFFA1ppnn 3000FFA10108
tool_gpio_input(instru_received);
break;
case 0xA2: // instruction: 0x3xxxFFA2ssttrrcccccc...... 3000FFA2010301112233
tool_spi2(instru_received);
break;
case 0xA3: // instruction: 0x3xxxFFA3aaggttrrcccccc...... 3000FFA3519902037788
tool_i2c0(instru_received);
break;
}
break;
}
}
static void on_write(ble_edc_t *p_edc, ble_evt_t const *p_ble_evt)
{
ble_uuid_t uuid = p_ble_evt->evt.gatts_evt.params.write.uuid;
uint16_t handle = p_ble_evt->evt.gatts_evt.params.write.handle;
NRF_LOG_INFO("@ble on_write[gatt]: ble uuid=0x%02x, handle=0x%02x", uuid.uuid, handle);
switch (uuid.uuid)
{
case BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG:
NRF_LOG_INFO("uuid.uuid=BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG");
edc_ccc_update(p_edc, p_ble_evt);
break;
case BLE_UUID_CHARACTERISTIC:
NRF_LOG_INFO("uuid.uuid=BLE_UUID_CHARACTERISTIC");
break;
case BLE_UUID_EDC_INSTRUCTION_CHAR: {
ble_gatts_evt_write_t const *p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
NRF_LOG_INFO("uuid.uuid=BLE_UUID_EDC_INSTRUCTION_CHAR");
if (p_evt_write->handle == p_edc->instruction_handles.value_handle)
{
memcpy(p_edc->instruction, p_evt_write->data, p_evt_write->len);
NRF_LOG_INFO("p_edc->instruction[0:%d]=", p_evt_write->len - 1);
NRF_LOG_HEXDUMP_INFO(p_edc->instruction, p_evt_write->len);
decode_instruction(p_edc->instruction);
}
}
break;
default:
break;
}
}
static void on_hvx_tx_complete(ble_edc_t *p_edc, ble_evt_t const *p_ble_evt)
{
}
static void ble_edc_evt_handler(ble_evt_t const *p_ble_evt, void *p_context)
{
ble_edc_t *p_edc = (ble_edc_t *)p_context;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
on_connect(p_edc, p_ble_evt);
break;
case BLE_GAP_EVT_DISCONNECTED:
on_disconnect(p_edc, p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
on_write(p_edc, p_ble_evt);
break;
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
on_hvx_tx_complete(p_edc, p_ble_evt);
break;
default:
// No implementation needed.
break;
}
}
static ret_code_t add_characteristic(uint16_t uuid, uint8_t uuid_type, uint32_t val_len, void *p_val, ble_gatts_char_handles_t *p_handles)
{
ble_add_char_params_t add_char_params;
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = uuid;
add_char_params.uuid_type = uuid_type;
add_char_params.max_len = val_len;
add_char_params.init_len = 0;
add_char_params.p_init_value = p_val;
add_char_params.is_value_user = false;
add_char_params.is_var_len = true;
add_char_params.char_props.read = 1;
add_char_params.char_props.notify = 1;
add_char_params.read_access = SEC_OPEN;
add_char_params.cccd_write_access = SEC_OPEN;
ret_code_t err_code = characteristic_add(ble_edc.service_handle, &add_char_params, p_handles);
return err_code;
}
static ret_code_t add_characteristic_read_write(uint16_t uuid, uint8_t uuid_type, uint32_t val_len, void *p_val, ble_gatts_char_handles_t *p_handles)
{
ble_add_char_params_t add_char_params;
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = uuid;
add_char_params.uuid_type = uuid_type;
add_char_params.max_len = val_len;
add_char_params.init_len = 0;
add_char_params.p_init_value = p_val;
add_char_params.is_value_user = false;
add_char_params.is_var_len = true;
add_char_params.char_props.write = 1;
add_char_params.write_access = SEC_OPEN;
add_char_params.char_props.read = 1;
add_char_params.read_access = SEC_OPEN;
ret_code_t err_code = characteristic_add(ble_edc.service_handle, &add_char_params, p_handles);
return err_code;
}
static uint32_t ble_edc_init(ble_edc_init_t const *p_edc_init)
{
ret_code_t err_code;
ble_uuid128_t base_uuid = BLE_EDC_BASE_UUID;
ble_uuid_t ble_uuid = {
.type = BLE_UUID_TYPE_UNKNOWN,
.uuid = BLE_UUID_EDC_SERVICE,
};
// Adding vendor specific UUID to the SoftDevice
err_code = sd_ble_uuid_vs_add(&base_uuid, &ble_uuid.type);
APP_ERROR_CHECK(err_code);
// Adding proprietary service to the SoftDevice
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &ble_edc.service_handle);
APP_ERROR_CHECK(err_code);
// Adding regular data characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EDC_BAT_VOLT_CHAR,
ble_uuid.type,
NRF_SDH_BLE_GATT_MAX_MTU_SIZE - 3,
NULL,
&ble_edc.regular_data_handles);
APP_ERROR_CHECK(err_code);
// Adding low freq data characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EDC_LOW_FREQ_DATA_CHAR,
ble_uuid.type,
32,
NULL,
&ble_edc.low_freq_data_handles);
APP_ERROR_CHECK(err_code);
// Adding auxiliary data characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EDC_AUXILIARY_DATA_CHAR,
ble_uuid.type,
32,
NULL,
&ble_edc.auxiliary_data_handles);
APP_ERROR_CHECK(err_code);
// Adding status characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EDC_STATUS_CHAR,
ble_uuid.type,
32,
NULL,
&ble_edc.status_handles);
APP_ERROR_CHECK(err_code);
// Adding event characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EDC_EVENT_CHAR,
ble_uuid.type,
32,
NULL,
&ble_edc.event_handles);
APP_ERROR_CHECK(err_code);
// Adding instruction characteristic to the SoftDevice
err_code = add_characteristic_read_write(BLE_UUID_EDC_INSTRUCTION_CHAR,
ble_uuid.type,
32,
NULL,
&ble_edc.instruction_handles);
APP_ERROR_CHECK(err_code);
// Register a handler for BLE events.
NRF_SDH_BLE_OBSERVER(m_edc_observer, EDC_BLE_OBSERVER_PRIO, ble_edc_evt_handler, &ble_edc);
NRF_LOG_INFO("+------------------------+------+");
NRF_LOG_INFO("| regular_data_handles | 0x%02x |", ble_edc.regular_data_handles.value_handle);
NRF_LOG_INFO("| low_freq_data_handles | 0x%02x |", ble_edc.low_freq_data_handles.value_handle);
NRF_LOG_INFO("| auxiliary_data_handles | 0x%02x |", ble_edc.auxiliary_data_handles.value_handle);
NRF_LOG_INFO("| status_handles | 0x%02x |", ble_edc.status_handles.value_handle);
NRF_LOG_INFO("| event_handles | 0x%02x |", ble_edc.event_handles.value_handle);
NRF_LOG_INFO("| instruction_handles | 0x%02x |", ble_edc.instruction_handles.value_handle);
NRF_LOG_INFO("+------------------------+------+");
return NRF_SUCCESS;
}
void le_edc_init(void)
{
ble_edc_init_t edc_init;
memset(&edc_init, 0x00, sizeof(edc_init));
ret_code_t err_code = ble_edc_init(&edc_init);
APP_ERROR_CHECK(err_code);
extern void edc_regular_data_init(void);
edc_regular_data_init();
}
ret_code_t le_regular_data_notify(uint8_t *p_value, uint16_t len)
{
ret_code_t err_code = NRF_SUCCESS;
// update database.
ble_gatts_value_t gatts_value = {
.offset = 0,
.len = len,
.p_value = p_value,
};
err_code = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, ble_edc.regular_data_handles.value_handle, &gatts_value);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// send notify
if (ble_edc.regular_data_notify_enable)
{
ble_gatts_hvx_params_t hvx_params = {
.handle = ble_edc.regular_data_handles.value_handle,
.type = BLE_GATT_HVX_NOTIFICATION,
.offset = gatts_value.offset,
.p_len = &gatts_value.len,
.p_data = gatts_value.p_value,
};
if (ble_conn_state_status(ble_edc.conn_handle) == BLE_CONN_STATUS_CONNECTED)
{
err_code = sd_ble_gatts_hvx(ble_edc.conn_handle, &hvx_params);
}
}
return err_code;
}
bool le_regular_data_notify_is_enable(void)
{
return ble_edc.regular_data_notify_enable;
}
#endif // NRF_MODULE_ENABLED(BLE_EDC)
+290
View File
@@ -0,0 +1,290 @@
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(BLE_EIS)
#include "app_error.h"
#include "ble_conn_state.h"
#include "ble_gatts.h"
#include "ble_srv_common.h"
#include "nrf_sdh_ble.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include <stdlib.h>
#include <string.h>
/**< Used vendor specific UUID. */
#define BLE_EIS_BASE_UUID \
{ \
{ \
0x4D, 0x3C, 0x56, 0x45, 0x12, 0x8B, 0x44, 0x1D, 0x8D, 0x6F, 0xC5, 0x95, 0x00, 0x00, 0x9B, 0xD8 \
} \
}
#define BLE_UUID_EIS_SERVICE 0x0001
#define BLE_UUID_EIS_REGULAR_DATA_CHAR 0x0002
#define BLE_UUID_EIS_LOW_FREQ_DATA_CHAR 0x0003
#define BLE_UUID_EIS_AUXILIARY_DATA_CHAR 0x0004
#define BLE_UUID_EIS_STATUS_CHAR 0x0005
#define BLE_UUID_EIS_EVENT_CHAR 0x0006
typedef struct
{
uint16_t conn_handle;
uint16_t service_handle;
ble_gatts_char_handles_t regular_data_handles;
ble_gatts_char_handles_t low_freq_data_handles;
ble_gatts_char_handles_t auxiliary_data_handles;
ble_gatts_char_handles_t status_handles;
ble_gatts_char_handles_t event_handles;
bool regular_data_notify_enable;
bool low_freq_data_notify_enable;
bool auxiliary_data_notify_enable;
bool status_notify_enable;
bool event_notify_enable;
} ble_eis_t;
typedef struct
{
uint16_t dummy;
} ble_eis_init_t;
static ble_eis_t ble_eis = {
.conn_handle = BLE_CONN_HANDLE_INVALID,
.regular_data_notify_enable = false,
.low_freq_data_notify_enable = false,
.auxiliary_data_notify_enable = false,
.status_notify_enable = false,
.event_notify_enable = false,
};
static void on_connect(ble_eis_t *p_eis, ble_evt_t const *p_ble_evt)
{
p_eis->conn_handle = p_ble_evt->evt.common_evt.conn_handle;
}
static void on_disconnect(ble_eis_t *p_eis, ble_evt_t const *p_ble_evt)
{
p_eis->conn_handle = BLE_CONN_HANDLE_INVALID;
p_eis->regular_data_notify_enable = false;
p_eis->low_freq_data_notify_enable = false;
p_eis->auxiliary_data_notify_enable = false;
p_eis->status_notify_enable = false;
p_eis->event_notify_enable = false;
}
static void eis_ccc_update(ble_eis_t *p_eis, ble_evt_t const *p_ble_evt)
{
ble_gatts_evt_write_t const *p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
if (p_evt_write->handle == p_eis->regular_data_handles.cccd_handle)
{
p_eis->regular_data_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("regular_data_notify:%s", p_eis->regular_data_notify_enable ? "enable" : "disable");
return;
}
else if (p_evt_write->handle == p_eis->low_freq_data_handles.cccd_handle)
{
p_eis->low_freq_data_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("low_freq_data_notify:%s", p_eis->low_freq_data_notify_enable ? "enable" : "disable");
return;
}
else if (p_evt_write->handle == p_eis->auxiliary_data_handles.cccd_handle)
{
p_eis->auxiliary_data_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("auxiliary_data_notify:%s", p_eis->auxiliary_data_notify_enable ? "enable" : "disable");
return;
}
else if (p_evt_write->handle == p_eis->status_handles.cccd_handle)
{
p_eis->status_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("status_notify:%s", p_eis->status_notify_enable ? "enable" : "disable");
return;
}
else if (p_evt_write->handle == p_eis->event_handles.cccd_handle)
{
p_eis->event_notify_enable = ble_srv_is_notification_enabled(p_evt_write->data);
NRF_LOG_INFO("event_notify:%s", p_eis->event_notify_enable ? "enable" : "disable");
return;
}
}
static void on_write(ble_eis_t *p_eis, ble_evt_t const *p_ble_evt)
{
ble_uuid_t uuid = p_ble_evt->evt.gatts_evt.params.write.uuid;
switch (uuid.uuid)
{
case BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG:
eis_ccc_update(p_eis, p_ble_evt);
break;
case BLE_UUID_CHARACTERISTIC:
break;
default:
break;
}
}
static void on_hvx_tx_complete(ble_eis_t *p_eis, ble_evt_t const *p_ble_evt)
{
}
static void ble_eis_evt_handler(ble_evt_t const *p_ble_evt, void *p_context)
{
ble_eis_t *p_eis = (ble_eis_t *)p_context;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
on_connect(p_eis, p_ble_evt);
break;
case BLE_GAP_EVT_DISCONNECTED:
on_disconnect(p_eis, p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
on_write(p_eis, p_ble_evt);
break;
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
on_hvx_tx_complete(p_eis, p_ble_evt);
break;
default:
// No implementation needed.
break;
}
}
static ret_code_t add_characteristic(uint16_t uuid, uint8_t uuid_type, uint32_t val_len, void *p_val, ble_gatts_char_handles_t *p_handles)
{
ble_add_char_params_t add_char_params;
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = uuid;
add_char_params.uuid_type = uuid_type;
add_char_params.max_len = val_len;
add_char_params.init_len = 0;
add_char_params.p_init_value = p_val;
add_char_params.is_value_user = false;
add_char_params.is_var_len = true;
add_char_params.char_props.read = 1;
add_char_params.char_props.notify = 1;
add_char_params.read_access = SEC_OPEN;
add_char_params.cccd_write_access = SEC_OPEN;
ret_code_t err_code = characteristic_add(ble_eis.service_handle, &add_char_params, p_handles);
return err_code;
}
static uint32_t ble_eis_init(ble_eis_init_t const *p_eis_init)
{
ret_code_t err_code;
ble_uuid128_t base_uuid = BLE_EIS_BASE_UUID;
ble_uuid_t ble_uuid = {
.type = BLE_UUID_TYPE_UNKNOWN,
.uuid = BLE_UUID_EIS_SERVICE,
};
// Adding vendor specific UUID to the SoftDevice
err_code = sd_ble_uuid_vs_add(&base_uuid, &ble_uuid.type);
APP_ERROR_CHECK(err_code);
// Adding proprietary service to the SoftDevice
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &ble_eis.service_handle);
APP_ERROR_CHECK(err_code);
// Adding regular data characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EIS_REGULAR_DATA_CHAR,
ble_uuid.type,
NRF_SDH_BLE_GATT_MAX_MTU_SIZE - 3,
NULL,
&ble_eis.regular_data_handles);
APP_ERROR_CHECK(err_code);
// Adding low freq data characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EIS_LOW_FREQ_DATA_CHAR,
ble_uuid.type,
32,
NULL,
&ble_eis.low_freq_data_handles);
APP_ERROR_CHECK(err_code);
// Adding auxiliary data characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EIS_AUXILIARY_DATA_CHAR,
ble_uuid.type,
32,
NULL,
&ble_eis.auxiliary_data_handles);
APP_ERROR_CHECK(err_code);
// Adding status characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EIS_STATUS_CHAR,
ble_uuid.type,
32,
NULL,
&ble_eis.status_handles);
APP_ERROR_CHECK(err_code);
// Adding event characteristic to the SoftDevice
err_code = add_characteristic(BLE_UUID_EIS_EVENT_CHAR,
ble_uuid.type,
32,
NULL,
&ble_eis.event_handles);
APP_ERROR_CHECK(err_code);
// Register a handler for BLE events.
NRF_SDH_BLE_OBSERVER(m_eis_observer, EIS_BLE_OBSERVER_PRIO, ble_eis_evt_handler, &ble_eis);
return NRF_SUCCESS;
}
void le_eis_init(void)
{
ble_eis_init_t eis_init;
memset(&eis_init, 0x00, sizeof(eis_init));
ret_code_t err_code = ble_eis_init(&eis_init);
APP_ERROR_CHECK(err_code);
extern void eis_regular_data_init(void);
eis_regular_data_init();
}
ret_code_t le_regular_data_notify(uint8_t *p_value, uint16_t len)
{
ret_code_t err_code = NRF_SUCCESS;
// update database.
ble_gatts_value_t gatts_value = {
.offset = 0,
.len = len,
.p_value = p_value,
};
err_code = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, ble_eis.regular_data_handles.value_handle, &gatts_value);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// send notify
if (ble_eis.regular_data_notify_enable)
{
ble_gatts_hvx_params_t hvx_params = {
.handle = ble_eis.regular_data_handles.value_handle,
.type = BLE_GATT_HVX_NOTIFICATION,
.offset = gatts_value.offset,
.p_len = &gatts_value.len,
.p_data = gatts_value.p_value,
};
if (ble_conn_state_status(ble_eis.conn_handle) == BLE_CONN_STATUS_CONNECTED)
{
err_code = sd_ble_gatts_hvx(ble_eis.conn_handle, &hvx_params);
}
}
return err_code;
}
bool le_regular_data_notify_is_enable(void)
{
return ble_eis.regular_data_notify_enable;
}
#endif // NRF_MODULE_ENABLED(BLE_EIS)
+1 -1
View File
@@ -51,7 +51,7 @@ void le_gap_init(const char *device_name, uint16_t usAppearance)
APP_ERROR_CHECK(err_code);
}
void le_gap_disconnect(uint16_t conn_handle, void *p_context)
void le_gap_disconnect(uint16_t conn_handle, void * p_context)
{
UNUSED_PARAMETER(p_context);
+3 -3
View File
@@ -23,8 +23,8 @@ extern "C"
#include "ble_conn_state.h"
#include "ble_dfu.h"
#include "ble_dis.h"
#include "ble_dfu.h"
#include "nrf_ble_gatt.h"
#ifdef __cplusplus
@@ -60,6 +60,6 @@ void le_srv_init(void)
extern void le_dfu_init(void);
le_dfu_init();
extern void le_edc_init(void);
le_edc_init(); // customer service
extern void le_eis_init(void);
le_eis_init();
}
-100
View File
@@ -1,100 +0,0 @@
#include "led.h"
#include "nrf_gpio.h"
#include "nrf_log.h"
#include "nrf_spim.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#define DISP_LED_COLOR 0
#define LED_COUNT 12
typedef struct
{
uint8_t brightness : 5;
uint8_t preamble : 3;
struct led_color color;
} led_t;
led_t led[LED_COUNT];
const led_t led_default = {
.brightness = 0b00000,
.preamble = 0b111,
.color = {
.B = 0,
.G = 0,
.R = 0},
};
static void led_write(uint8_t *pucData, uint32_t ulSize)
{
extern void spi1_write(uint8_t * p_tx_buffer, uint8_t tx_buffer_length);
spi1_write(pucData, ulSize);
// for (uint32_t i = 0; i < ulSize; i++)
// {
// for (uint32_t j = 0x80; j > 0; j >>= 1)
// {
// nrf_gpio_pin_clear(LED_CLK_PIN);
// if (pucData[i] & j)
// {
// nrf_gpio_pin_set(LED_SDI_PIN);
// }
// else
// {
// nrf_gpio_pin_clear(LED_SDI_PIN);
// }
// // portYIELD();
// nrf_gpio_pin_set(LED_CLK_PIN);
// // portYIELD();
// }
// }
// nrf_gpio_pin_clear(LED_CLK_PIN);
}
void led_set(uint32_t idx, struct led_color color, uint8_t brightness)
{
uint32_t start_frame = 0x00000000;
led_write((void *)&start_frame, sizeof(start_frame));
led[idx].color = color;
led[idx].brightness = brightness;
for (int i = 0; i < LED_COUNT; i++)
{
led_write((void *)&led[i], sizeof(led[i]));
}
uint32_t end_frame = 0xFFFFFFFF;
led_write((void *)&end_frame, sizeof(end_frame));
}
void led_off(void)
{
NRF_LOG_INFO("LED_NONE");
uint32_t start_frame = 0x00000000;
led_write((void *)&start_frame, sizeof(start_frame));
for (int i = 0; i < LED_COUNT; i++)
{
led[i] = led_default;
led_write((void *)&led[i], sizeof(led[i]));
}
uint32_t end_frame = 0xFFFFFFFF;
led_write((void *)&end_frame, sizeof(end_frame));
}
void led_init(void)
{
// // led gpio init
// nrf_gpio_pin_clear(LED_CLK_PIN);
// nrf_gpio_cfg_output(LED_CLK_PIN);
// nrf_gpio_pin_clear(LED_SDI_PIN);
// nrf_gpio_cfg_output(LED_SDI_PIN);
// turn off
led_off();
}
-41
View File
@@ -1,41 +0,0 @@
#pragma once
#ifndef __LED_H__
#define __LED_H__
#include <stdint.h>
struct led_color
{
uint8_t B;
uint8_t G;
uint8_t R;
};
#define LED_NONE \
(struct led_color) { .R = 0x00, .G = 0x00, .B = 0x00 }
#define LED_RED \
(struct led_color) { .R = 0xFF, .G = 0x00, .B = 0x00 }
#define LED_GREEN \
(struct led_color) { .R = 0x00, .G = 0xFF, .B = 0x00 }
#define LED_CYAN \
(struct led_color) { .R = 0x00, .G = 0xFF, .B = 0xFF } // connect to neulive
#define LED_BLUE \
(struct led_color) { .R = 0x00, .G = 0x00, .B = 0xFF } // neulive recording
#define LED_YELLOW \
(struct led_color) { .R = 0xEF, .G = 0x9F, .B = 0x00 } // neulive stimulate
#define LED_PURPLE \
(struct led_color) { .R = 0xFF, .G = 0x00, .B = 0xFF } // neulive rec + sti
#define LED_OFF LED_NONE
#define LED_ERROR LED_RED
#define LED_ON LED_GREEN
#define LED_CONNECTED LED_CYAN
#define LED_REC LED_BLUE
#define LED_STIMU LED_YELLOW
#define LED_STIMU_REC LED_PURPLE
void led_init(void);
void led_off(void);
void led_set(uint32_t idx, struct led_color color, uint8_t brightness);
#endif // !__LED_H__
+16 -152
View File
@@ -23,9 +23,6 @@ extern "C"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "led.h"
#ifdef __cplusplus
}
@@ -60,7 +57,7 @@ static void le_evt_handler(ble_evt_t const *p_ble_evt, void *p_context)
case BLE_GAP_EVT_PHY_UPDATE_REQUEST: {
NRF_LOG_INFO("PHY update response. (AUTO)");
ble_gap_phys_t const phys = {
.rx_phys = BLE_GAP_PHY_AUTO, // adv&connection: 1M PHY, After connection: mobile-2M, PC-1M
.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);
@@ -105,160 +102,27 @@ static void le_stack_Init(void)
NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, le_evt_handler, NULL);
}
/* edc2.0 pin */
#define ADCA2_PIN NRF_GPIO_PIN_MAP(0, 25)
#define ADCA1_PIN NRF_GPIO_PIN_MAP(0, 19)
#define ADCA0_PIN NRF_GPIO_PIN_MAP(0, 21)
#define RST_SW_PIN NRF_GPIO_PIN_MAP(0, 17)
#define CS_SW_PIN NRF_GPIO_PIN_MAP(0, 20)
#define OFF_PIN NRF_GPIO_PIN_MAP(0, 15)
#define SHUT_DOWN_PIN NRF_GPIO_PIN_MAP(1, 8)
#define CS_MEM_PIN NRF_GPIO_PIN_MAP(0, 8)
#define CS_ADC_PIN NRF_GPIO_PIN_MAP(0, 6)
#define CS_DAC_PIN NRF_GPIO_PIN_MAP(0, 5)
#define INT9466_PIN NRF_GPIO_PIN_MAP(0, 27)
#define Vout_FB_PIN NRF_GPIO_PIN_MAP(0, 26)
#define Vout_IN_PIN NRF_GPIO_PIN_MAP(0, 4)
#define LEDTH_PIN NRF_GPIO_PIN_MAP(0, 28)
#define Iin4_TEST_PIN NRF_GPIO_PIN_MAP(1, 12)
#define Iin3_SEL_PIN NRF_GPIO_PIN_MAP(1, 14)
#define VBAT_PIN NRF_GPIO_PIN_MAP(0, 3)
#define Iin3_PIN NRF_GPIO_PIN_MAP(1, 13)
#define Iin2_PIN NRF_GPIO_PIN_MAP(1, 3)
#define Iin1_PIN NRF_GPIO_PIN_MAP(1, 10)
#define Vin2_PIN NRF_GPIO_PIN_MAP(1, 6)
#define Vin1_PIN NRF_GPIO_PIN_MAP(1, 11)
#define POWER_5V_EN_PIN NRF_GPIO_PIN_MAP(0, 24)
#define POWER_12V_EN_PIN NRF_GPIO_PIN_MAP(0, 23)
#define CV_CTRL_PIN NRF_GPIO_PIN_MAP(0, 16)
void gpio_init(void)
{
nrf_gpio_cfg_output(POWER_5V_EN_PIN);
nrf_gpio_cfg_output(POWER_12V_EN_PIN);
nrf_gpio_cfg_output(OFF_PIN);
nrf_gpio_cfg_output(Vout_FB_PIN);
nrf_gpio_cfg_output(Vout_IN_PIN);
nrf_gpio_cfg_output(Iin4_TEST_PIN);
nrf_gpio_cfg_output(Iin3_SEL_PIN);
nrf_gpio_cfg_output(Iin3_PIN);
nrf_gpio_cfg_output(Iin2_PIN);
nrf_gpio_cfg_output(Iin1_PIN);
nrf_gpio_cfg_output(Vin2_PIN);
nrf_gpio_cfg_output(Vin1_PIN);
nrf_gpio_cfg_output(CV_CTRL_PIN);
nrf_gpio_cfg_output(ADCA2_PIN);
nrf_gpio_cfg_output(ADCA1_PIN);
nrf_gpio_cfg_output(ADCA0_PIN);
nrf_gpio_cfg_output(RST_SW_PIN);
nrf_gpio_cfg_output(CS_SW_PIN);
nrf_gpio_cfg_output(CS_MEM_PIN);
nrf_gpio_cfg_output(CS_ADC_PIN);
nrf_gpio_cfg_output(CS_DAC_PIN);
nrf_gpio_cfg_input(VBAT_PIN, NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_input(SHUT_DOWN_PIN, NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_input(INT9466_PIN, NRF_GPIO_PIN_NOPULL);
nrf_gpio_pin_set(POWER_5V_EN_PIN);
nrf_gpio_pin_set(POWER_12V_EN_PIN);
nrf_gpio_pin_set(OFF_PIN); // disable 6994
nrf_gpio_pin_set(CS_SW_PIN);
nrf_gpio_pin_set(CS_MEM_PIN);
nrf_gpio_pin_set(CS_ADC_PIN);
nrf_gpio_pin_set(CS_DAC_PIN);
nrf_gpio_pin_clear(Vout_FB_PIN);
nrf_gpio_pin_clear(Vout_IN_PIN);
nrf_gpio_pin_clear(Iin4_TEST_PIN);
nrf_gpio_pin_clear(Iin3_SEL_PIN);
nrf_gpio_pin_clear(Iin3_PIN);
nrf_gpio_pin_clear(Iin2_PIN);
nrf_gpio_pin_clear(Iin1_PIN);
nrf_gpio_pin_clear(Vin2_PIN);
nrf_gpio_pin_clear(Vin1_PIN);
nrf_gpio_pin_clear(CV_CTRL_PIN);
nrf_gpio_pin_clear(ADCA2_PIN);
nrf_gpio_pin_clear(ADCA1_PIN);
nrf_gpio_pin_clear(ADCA0_PIN);
nrf_gpio_pin_clear(RST_SW_PIN);
}
static void enable_6994_callback(void *pvParameter)
{
nrf_gpio_pin_clear(OFF_PIN); // enable 6994
NRF_LOG_INFO("enable 6994");
}
extern void twi0_write_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data, uint8_t data_len);
extern void twi0_read_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_rx_buf, uint8_t rx_buffer_length);
void touch_sensor_task(void *pArg)
{
/*
* pin assign:
* SDA SCL INT VDD GND
* p0.11 p0.02 p0.29 5V0 GND
*/
nrf_gpio_cfg_input(29, NRF_GPIO_PIN_NOPULL);//INT
for (;;)
{
bool button = nrf_gpio_pin_read(29);
NRF_LOG_INFO("button=%d", button);
uint8_t rx_buffer[1];
twi0_read_reg(0x50, 0x0D, rx_buffer, 1);
vTaskDelay(500);
}
}
static void nrf_sdh_freertos_task_hook(void *p_context)
{
extern void twi0_init(void);
extern void spi_init(void);
UNUSED_PARAMETER(p_context);
gpio_init();
spi_init();
twi0_init();
led_init();
xTaskCreate(touch_sensor_task, "touch_sensor_task", 256, NULL, 3, NULL);
NRF_LOG_INFO("LED_GREEN");
for (int i = 0; i < 12; i++)
{
led_set(i, LED_GREEN, 1);
}
le_stack_Init(); // enable ble stack, but unscannable!! register "le_evt_handler" handle(CB)
extern void le_gap_init(const char *device_name, uint16_t usAppearance);
le_gap_init(ELITE_DEVICE_NAME, BLE_APPEARANCE_UNKNOWN); // set BT name & connection interval
extern void le_gatt_init(void);
le_gatt_init();
extern void le_srv_init(void);
le_srv_init(); // service
extern void le_adv_init(uint8_t ble_conn_cfg_tag);
le_adv_init(APP_BLE_CONN_CFG_TAG); // could be scanned
/* Start timer to call enable_6994_callback() */
TimerHandle_t timer_handle; /**< Reference to counter FreeRTOS timer. */
timer_handle = xTimerCreate("enable 6994", 1000, pdFALSE, NULL, enable_6994_callback); // 1000ms no repeat
xTimerStart(timer_handle, 0);
}
int main(void)
{
NRF_LOG_INIT(NULL, 0);
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("%s Build: %s %s", ELITE_DEVICE_NAME, __TIME__, __DATE__);
nrf_sdh_freertos_init(nrf_sdh_freertos_task_hook, NULL); // create event: softdevice_task - wireless protocal stack
le_stack_Init();
extern void le_gap_init(const char *device_name, uint16_t usAppearance);
le_gap_init(ELITE_DEVICE_NAME, BLE_APPEARANCE_UNKNOWN);
extern void le_gatt_init(void);
le_gatt_init();
extern void le_srv_init(void);
le_srv_init();
extern void le_adv_init(uint8_t ble_conn_cfg_tag);
le_adv_init(APP_BLE_CONN_CFG_TAG);
nrf_sdh_freertos_init(NULL, NULL);
vTaskStartScheduler();
-7
View File
@@ -9,11 +9,4 @@ MEMORY
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x40000
}
SECTIONS
{
.segger_rtt (NOLOAD) :
{
} > RTT
}
INCLUDE "nrf_full.ld"
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -65,7 +65,7 @@ async def ble_notify_demo(mac_addr: str):
mac_addr = "DF:4C:23:1C:F5:59"
mac_addr = "EB:E6:E0:52:26:ED"
mac_addr = "D8:96:4A:0B:14:4A"
mac_addr = "DC:05:1F:1F:71:DA"
mac_addr = "DC:05:1F:1F:71:DA"
if asyncio.run(ble_notify_demo(mac_addr)) == True :
print("Recv total: {0} bytes".format(TotalBytes))
f.close()
-117
View File
@@ -1,117 +0,0 @@
#include "nrf_drv_spi.h"
#include "nrf_gpio.h"
#include "nrf_log.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#define SPI1_CLK_PIN NRF_GPIO_PIN_MAP(0, 13)
#define SPI1_MOSI_PIN NRF_GPIO_PIN_MAP(0, 14)
#define SPI2_CLK_PIN NRF_GPIO_PIN_MAP(0, 12)
#define SPI2_MOSI_PIN NRF_GPIO_PIN_MAP(0, 7)
#define SPI2_MISO_PIN NRF_GPIO_PIN_MAP(1, 9)
static const nrf_drv_spi_t spim1 = NRF_DRV_SPI_INSTANCE(1); /**< SPI instance. */
static const nrf_drv_spi_t spim2 = NRF_DRV_SPI_INSTANCE(2); /**< SPI instance. */
static SemaphoreHandle_t spim1_sem = NULL;
static SemaphoreHandle_t spim2_sem = NULL;
static SemaphoreHandle_t spim2_mutex = NULL;
void nrf_drv_spim1_evt_handler(nrf_drv_spi_evt_t const *p_event, void *p_context)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
switch (p_event->type)
{
case NRF_DRV_SPI_EVENT_DONE:
xSemaphoreGiveFromISR(spim1_sem, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
break;
default:
break;
}
}
void nrf_drv_spim2_evt_handler(nrf_drv_spi_evt_t const *p_event, void *p_context)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
switch (p_event->type)
{
case NRF_DRV_SPI_EVENT_DONE:
xSemaphoreGiveFromISR(spim2_sem, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
break;
default:
break;
}
}
void spi_init(void)
{
spim1_sem = xSemaphoreCreateBinary();
spim2_sem = xSemaphoreCreateBinary();
spim2_mutex = xSemaphoreCreateMutex();
nrf_drv_spi_config_t spi1_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi1_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi1_config.miso_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi1_config.mosi_pin = SPI1_MOSI_PIN;
spi1_config.sck_pin = SPI1_CLK_PIN;
spi1_config.mode = NRF_DRV_SPI_MODE_1;
spi1_config.frequency = NRF_DRV_SPI_FREQ_1M;
APP_ERROR_CHECK(nrf_drv_spi_init(&spim1, &spi1_config, nrf_drv_spim1_evt_handler, NULL));
nrf_drv_spi_config_t spi2_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi2_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi2_config.miso_pin = SPI2_MISO_PIN;
spi2_config.mosi_pin = SPI2_MOSI_PIN;
spi2_config.sck_pin = SPI2_CLK_PIN;
spi2_config.mode = NRF_DRV_SPI_MODE_1;
spi2_config.frequency = NRF_DRV_SPI_FREQ_1M;
APP_ERROR_CHECK(nrf_drv_spi_init(&spim2, &spi2_config, nrf_drv_spim2_evt_handler, NULL));
}
void spi1_write(uint8_t *p_tx_buffer, uint8_t tx_buffer_length)
{
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spim1, p_tx_buffer, tx_buffer_length, NULL, 0));
xSemaphoreTake(spim1_sem, portMAX_DELAY);
}
static void virtual_data(uint8_t *p_rx_buf, uint8_t rx_buffer_length)
{
uint8_t virtual_data_buff[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
if (rx_buffer_length == 0)
return;
memcpy(p_rx_buf, virtual_data_buff, rx_buffer_length);
}
void spi2_write(uint32_t cs_pin, uint8_t *p_tx_buffer, uint8_t tx_buffer_length, uint8_t *p_rx_buf, uint8_t rx_buffer_length)
{
xSemaphoreTake(spim2_mutex, portMAX_DELAY);
nrf_gpio_pin_clear(cs_pin);
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spim2, p_tx_buffer, tx_buffer_length, p_rx_buf, rx_buffer_length));
if (xSemaphoreTake(spim2_sem, pdMS_TO_TICKS(100)) == pdFALSE)
{
// TODO... spi treansfer timeout.
}
nrf_gpio_pin_set(cs_pin);
xSemaphoreGive(spim2_mutex);
NRF_LOG_INFO("spi(W)");
NRF_LOG_HEXDUMP_INFO(p_tx_buffer, tx_buffer_length);
// virtual_data(p_rx_buf, rx_buffer_length);
if (rx_buffer_length > 0)
{
NRF_LOG_INFO("spi(R)");
NRF_LOG_HEXDUMP_INFO(p_rx_buf, rx_buffer_length);
}
}
-155
View File
@@ -1,155 +0,0 @@
/**
******************************************************************************
* @file syscalls.c
* @author Auto-generated by STM32CubeIDE
* @brief STM32CubeIDE Minimal System calls file
*
* For more information about which c-functions
* need which of these lowlevel functions
* please consult the Newlib libc-manual
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes */
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
/* Variables */
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
char *__env[1] = { 0 };
char **environ = __env;
/* Functions */
void initialise_monitor_handles()
{
}
int _getpid(void)
{
return 1;
}
int _kill(int pid, int sig)
{
errno = EINVAL;
return -1;
}
void _exit (int status)
{
_kill(status, -1);
while (1) {} /* Make sure we hang here */
}
__attribute__((weak)) int _read(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}
return len;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}
int _close(int file)
{
return -1;
}
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int file)
{
return 1;
}
int _lseek(int file, int ptr, int dir)
{
return 0;
}
int _open(char *path, int flags, ...)
{
/* Pretend like we always fail */
return -1;
}
int _wait(int *status)
{
errno = ECHILD;
return -1;
}
int _unlink(char *name)
{
errno = ENOENT;
return -1;
}
int _times(struct tms *buf)
{
return -1;
}
int _stat(char *file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _link(char *old, char *new)
{
errno = EMLINK;
return -1;
}
int _fork(void)
{
errno = EAGAIN;
return -1;
}
int _execve(char *name, char **argv, char **env)
{
errno = ENOMEM;
return -1;
}