Compare commits

...

46 Commits

Author SHA1 Message Date
Roy_01 10e1b32bc1 wheel capacitive touch sensor driver 2024-01-23 14:16:46 +08:00
Roy_01 50ef6af023 fix: i2c support multi-task & isr callback. 2024-01-16 10:03:51 +08:00
Roy_01 d3114ed49f fix: 修正 rtt 顯示異常的問題 2024-01-03 17:44:14 +08:00
Roy_01 0e90206dda fix: spim2 support multi-task & isr callback. 2024-01-03 17:36:37 +08:00
Roy_01 443f38e90c fix: clear_bus_init 設為 true
1. 確保不會有某個 i2c slave device 把 sda pin pull
2024-01-03 14:44:21 +08:00
Roy_01 7eb82ae895 style: updated code style 2024-01-03 14:40:04 +08:00
Roy_01 385b5ad471 new develop tool: change_led、gpio_output、gpio_input、spi2、i2c0 2023-12-27 15:10:01 +08:00
Roy_01 2bf247c103 new twi0 (i2c0) 2023-12-27 14:50:14 +08:00
Roy_01 c4bb2fec1f new spim2 2023-12-27 14:43:07 +08:00
Roy_01 0e9a2baa56 new spim1 for LED use 2023-12-27 13:42:32 +08:00
Roy_01 9faf9f8692 updated many pin configuration and enable RT6994 after one second 2023-12-27 11:56:38 +08:00
Roy_01 4cecf11510 modify the LED pin configuration, enable 5V and 12V power 2023-12-27 10:08:32 +08:00
chain40 d6f62f8b22 add led driver 2023-10-24 20:59:27 +08:00
chain40 fb60d3c254 create dfu service 2023-09-27 07:27:44 +08:00
chain40 c45c81e0ac use nrfutil create OTA file 2023-09-26 22:47:35 +08:00
Roy 3cf2a1453d update IDE setting 2023-08-02 10:27:09 +08:00
Roy 5e8cab7512 clear regular data queue when connected 2023-08-01 16:31:11 +08:00
Roy ca2c177949 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-08-01 16:30:00 +08:00
Roy ad35d558e4 reset edc char notify enable status 2023-08-01 16:27:33 +08:00
Roy d585a711ac bugfix: fix BLE_UUID_EDC_EVENT_CHAR error 2023-08-01 16:24:36 +08:00
Roy afcd31c12f 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-08-01 16:23:07 +08:00
Roy 92ec0d79a1 bugfix: increase hvn_tx_queue_size for high freq notify 2023-08-01 16:15:13 +08:00
Roy 82f8018af1 upgrade toolchain and add syscalls.c file 2023-07-31 16:20:01 +08:00
Roy afa267e0be bugfix: fix wrong offset for checksum
bugfix: fix channel_len (group_length) field miss
2023-07-27 16:49:24 +08:00
Roy e3c1a5a579 implement edc_regular_data feature
1. create 2 pseudo task, update freq = 1KHz
2. add regular_data_notify_demo.py for validation
2023-07-27 16:43:53 +08:00
Roy e27421d2bf update gap/gatt configurtion 2023-07-27 15:55:48 +08:00
Roy 41759ddfaf 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-07-27 15:55:00 +08:00
Roy 059305ecbf 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-07-26 14:49:51 +08:00
Roy 06184562e8 update freertos configuration
1. remove unused functions
2. increase freertos heap size to 32KB
3. increase max of priorities
2023-07-26 13:49:39 +08:00
Roy 28d1d31402 [note] 2023-07-26 13:45:14 +08:00
Roy 2c4e6a921f 1.create battery task
2.define le_edc_bat_volt_update(). sending notification with the battery volt characteristic , if notification is enable,

1. define on_connect()
2. define on_disconnect()
2023-07-25 17:27:10 +08:00
Roy d0706fa05c set the battery voltage characteristic as a notification characteristic Part 1.
1. register handler for ble events
2. add edc_ccc_update() for CCCD (client characteristic configuration descriptor)
2023-07-25 17:19:06 +08:00
Roy 399fdf6a45 create EDC battery volt characteristic, and support read only 2023-07-25 14:33:35 +08:00
Roy 8f45c844cd create EDC service 2023-07-25 13:24:43 +08:00
Roy c1d841239d [note] Merge branch 'device_info_srv' 2023-07-25 09:37:41 +08:00
Roy 216c9c40f8 add device info service 2023-07-24 16:50:04 +08:00
Roy d563e23105 [note] Merge branch 'gatt' 2023-07-24 16:37:49 +08:00
Roy c42b96a6eb handle BLE_GAP_EVT_PHY_UPDATE_REQUEST for phy update request 2023-07-24 16:22:43 +08:00
Roy d9c1bf6a49 add gatt initialization 2023-07-24 16:04:25 +08:00
Roy 6b30832545 [note] Merge branch 'advertising' 2023-07-24 15:26:45 +08:00
Roy 55db0df3d9 add manuf_specific_data(custom data) in advertising packet 2023-07-24 14:18:54 +08:00
Roy dd7a8eb33e remove "appearance" from advertising packet and housekeeping 2023-07-24 13:49:24 +08:00
Roy 06171ec3ae [note] Merge branch 'ble' into develop 2023-07-24 11:56:18 +08:00
Roy 52f75b1969 add le_gap.c / le_adv.c
[roy: could scan device]
2023-07-20 16:57:32 +08:00
Roy e23abeb2d8 add nrf_sdh_freertos_init() 2023-07-20 16:48:41 +08:00
Roy c42094626a enable ble stack 2023-07-20 16:24:56 +08:00
24 changed files with 2624 additions and 63 deletions
+19 -19
View File
@@ -56,25 +56,25 @@
#define configTICK_SOURCE FREERTOS_USE_RTC
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 0
#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 1 /* See into vPortSuppressTicksAndSleep source code for explanation */
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ 1024
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( 160 )
#define configTOTAL_HEAP_SIZE ( 8192 )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configMAX_PRIORITIES ( 6 )
#define configMINIMAL_STACK_SIZE ( 192 )
#define configTOTAL_HEAP_SIZE ( 32 * 1024 )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_COUNTING_SEMAPHORES 0
#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
#define configQUEUE_REGISTRY_SIZE 2
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configUSE_NEWLIB_REENTRANT 1
#define configENABLE_BACKWARD_COMPATIBILITY 1
/* Hook function related definitions. */
@@ -113,22 +113,22 @@
#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 1
/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskPrioritySet 0
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_xResumeFromISR 0
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_pcTaskGetTaskName 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 0
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 0
#define INCLUDE_pcTaskGetTaskName 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTimerPendFunctionCall 0
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
+118 -3
View File
@@ -7,9 +7,6 @@ extern "C"
{
#endif
// DEVICE INFO
#define DEVICE_NAME "xyz"
// LOG
#define NRF_LOG_ENABLED 1
#define NRF_LOG_DEFAULT_LEVEL 3
@@ -83,6 +80,124 @@ extern "C"
#define POWER_CONFIG_IRQ_PRIORITY 6
#define CLOCK_CONFIG_IRQ_PRIORITY 6
// SoftDevice BLE event handler
#define NRF_SDH_BLE_ENABLED 1
// The number of vendor-specific UUIDs.
#define NRF_SDH_BLE_VS_UUID_COUNT 2
// Attribute Table size in bytes. The size must be a multiple of 4.
#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408
// BLE Observers - Observers and priority levels
#define NRF_SDH_BLE_OBSERVER_PRIO_LEVELS 4
// Include the Service Changed characteristic in the Attribute Table.
#define NRF_SDH_BLE_SERVICE_CHANGED 1
// This setting configures how Stack events are dispatched to the application.
#define NRF_SDH_DISPATCH_MODEL 2 /* SoftDevice events are to be fetched manually. */
// BLE Observers priorities - Invididual priorities
#define BLE_ADV_BLE_OBSERVER_PRIO 1
#define BLE_CONN_PARAMS_BLE_OBSERVER_PRIO 1
#define BLE_CONN_STATE_BLE_OBSERVER_PRIO 0
// Enable Advertising module
#define BLE_ADVERTISING_ENABLED 1
// BLE device name
#define DEF_ELITE_EDC_15RE 0x00020107
#define DEF_ELITE_EDC_15R2 0x00020108
#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
#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
#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
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_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 0
#define BLE_EIS_ENABLED 1
#define EDC_BLE_OBSERVER_PRIO 3
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#define ELITE_DEVICE_NAME "EIS"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 4
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 1
#define BLE_EIS_ENABLED 1
#define EDC_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
#endif
#define ELITE_COMPANY_CODE "Elite"
#define ELITE_HW_VER \
{ \
MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER \
}
// Maximum number of peripheral links.
#define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 1
// Maximum number of central links.
#define NRF_SDH_BLE_CENTRAL_LINK_COUNT 0
// Total link count.
#define NRF_SDH_BLE_TOTAL_LINK_COUNT 1
// Enable GATT module.
#define NRF_BLE_GATT_ENABLED 1
// Priority with which BLE events are dispatched to the GATT module.
#define NRF_BLE_GATT_BLE_OBSERVER_PRIO 1
// Requested BLE GAP data length to be negotiated.
#define NRF_SDH_BLE_GAP_DATA_LENGTH 251
// GAP event length. The time set aside for this connection on every connection interval in 1.25 ms units.
#define NRF_SDH_BLE_GAP_EVENT_LENGTH (0xFFFF)
// Static maximum MTU size.
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247
// Enable ble device info module
#define BLE_DIS_ENABLED 1
// DFU
#define NRF_DFU_TRANSPORT_BLE 1
#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
+14 -1
View File
@@ -25,6 +25,7 @@
<ProjectFile>bmd380_peripheral.vcxproj</ProjectFile>
<RemoteBuildEnvironment>
<Records />
<EnvironmentSetupFiles />
</RemoteBuildEnvironment>
<ParallelJobCount>1</ParallelJobCount>
<SuppressDirectoryChangeMessages>true</SuppressDirectoryChangeMessages>
@@ -33,7 +34,19 @@
<CustomBuild>
<PreSyncActions />
<PreBuildActions />
<PostBuildActions />
<PostBuildActions>
<CustomActionBase xsi:type="CommandLineAction">
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
<RemoteHost>
<HostName>BuildMachine</HostName>
<Transport>BuiltinShortcut</Transport>
</RemoteHost>
<Command>nrfutil</Command>
<Arguments>pkg generate --hw-version 52 --sd-req 0x100 --application-version 0 --application $(TargetPath).hex --key-file $(BuildDir)\private.pem $(BuildDir)\OTA_$(TargetFileName).zip"</Arguments>
<WorkingDirectory>$(BuildDir)</WorkingDirectory>
<BackgroundMode>false</BackgroundMode>
</CustomActionBase>
</PostBuildActions>
<PreCleanActions />
<PostCleanActions />
</CustomBuild>
+81 -9
View File
@@ -32,36 +32,44 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
<GNUConfigurationType>Debug</GNUConfigurationType>
<ToolchainID>com.visualgdb.arm-eabi</ToolchainID>
<ToolchainVersion>10.3.1/10.2.90/r1</ToolchainVersion>
<ToolchainVersion>12.3.1/13.2/r1</ToolchainVersion>
<GenerateHexFile>true</GenerateHexFile>
<MCUPropertyListFile>$(ProjectDir)nrf5x.props</MCUPropertyListFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">
<ToolchainID>com.visualgdb.arm-eabi</ToolchainID>
<ToolchainVersion>10.3.1/10.2.90/r1</ToolchainVersion>
<ToolchainVersion>12.3.1/13.2/r1</ToolchainVersion>
<GenerateHexFile>true</GenerateHexFile>
<MCUPropertyListFile>$(ProjectDir)nrf5x.props</MCUPropertyListFile>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
<ClCompile>
<CLanguageStandard>GNU99</CLanguageStandard>
<AdditionalIncludeDirectories>.;../bmd380_sdk/components/softdevice/s140/headers;../bmd380_sdk/components/softdevice/s140/headers/nrf52;../bmd380_sdk/external/segger_rtt;../bmd380_sdk/components/libraries/log;../bmd380_sdk/components/libraries/log/src;../bmd380_sdk/components/libraries/memobj;../bmd380_sdk/components/libraries/ringbuf;../bmd380_sdk/components/libraries/atomic;../bmd380_sdk/components/libraries/balloc;../bmd380_sdk/external/freertos/portable/CMSIS/nrf52;../bmd380_sdk/external/freertos/portable/GCC/nrf52;../bmd380_sdk/integration/nrfx;../bmd380_sdk/integration/nrfx/legacy;../bmd380_sdk/components/libraries/experimental_section_vars;../bmd380_sdk/components/libraries/strerror;../bmd380_sdk/external/freertos/source/include;%(ClCompile.AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;../bmd380_sdk/components/softdevice/s140/headers;../bmd380_sdk/components/softdevice/s140/headers/nrf52;../bmd380_sdk/external/segger_rtt;../bmd380_sdk/components/libraries/log;../bmd380_sdk/components/libraries/log/src;../bmd380_sdk/components/libraries/memobj;../bmd380_sdk/components/libraries/ringbuf;../bmd380_sdk/components/libraries/atomic;../bmd380_sdk/components/libraries/balloc;../bmd380_sdk/external/freertos/portable/CMSIS/nrf52;../bmd380_sdk/external/freertos/portable/GCC/nrf52;../bmd380_sdk/integration/nrfx;../bmd380_sdk/integration/nrfx/legacy;../bmd380_sdk/components/libraries/experimental_section_vars;../bmd380_sdk/components/libraries/strerror;../bmd380_sdk/external/freertos/source/include;../bmd380_sdk/components/softdevice/common;../bmd380_sdk/components/ble/common;../bmd380_sdk/components/ble/ble_advertising;../bmd380_sdk/components/libraries/atomic_flags;../bmd380_sdk/components/ble/ble_db_discovery;../bmd380_sdk/components/ble/ble_dtm;../bmd380_sdk/components/ble/ble_link_ctx_manager;../bmd380_sdk/components/ble/ble_racp;../bmd380_sdk/components/ble/ble_radio_notification;../bmd380_sdk/components/ble/ble_services/ble_ancs_c;../bmd380_sdk/components/ble/ble_services/ble_ans_c;../bmd380_sdk/components/ble/ble_services/ble_bas;../bmd380_sdk/components/ble/ble_services/ble_bas_c;../bmd380_sdk/components/ble/ble_services/ble_bps;../bmd380_sdk/components/ble/ble_services/ble_cscs;../bmd380_sdk/components/ble/ble_services/ble_cts_c;../bmd380_sdk/components/ble/ble_services/ble_dfu;../bmd380_sdk/components/ble/ble_services/ble_dis;../bmd380_sdk/components/ble/ble_services/ble_dis_c;../bmd380_sdk/components/ble/ble_services/ble_escs;../bmd380_sdk/components/ble/ble_services/ble_gls;../bmd380_sdk/components/ble/ble_services/ble_hids;../bmd380_sdk/components/ble/ble_services/ble_hrs;../bmd380_sdk/components/ble/ble_services/ble_hrs_c;../bmd380_sdk/components/ble/ble_services/ble_hts;../bmd380_sdk/components/ble/ble_services/ble_ias;../bmd380_sdk/components/ble/ble_services/ble_ias_c;../bmd380_sdk/components/ble/ble_services/ble_ipsp;../bmd380_sdk/components/ble/ble_services/ble_lbs;../bmd380_sdk/components/ble/ble_services/ble_lbs_c;../bmd380_sdk/components/ble/ble_services/ble_lls;../bmd380_sdk/components/ble/ble_services/ble_nus;../bmd380_sdk/components/ble/ble_services/ble_nus_c;../bmd380_sdk/components/ble/ble_services/ble_rscs;../bmd380_sdk/components/ble/ble_services/ble_rscs_c;../bmd380_sdk/components/ble/ble_services/ble_tps;../bmd380_sdk/components/ble/ble_services/eddystone;../bmd380_sdk/components/ble/ble_services/experimental_ble_lns;../bmd380_sdk/components/ble/ble_services/experimental_ble_ots;../bmd380_sdk/components/ble/ble_services/experimental_gatts_c;../bmd380_sdk/components/ble/ble_services/experimental_nrf_ble_cgms;../bmd380_sdk/components/ble/ble_services/experimental_nrf_ble_ots_c;../bmd380_sdk/components/ble/ble_services/nrf_ble_bms;../bmd380_sdk/components/ble/nrf_ble_gatt;../bmd380_sdk/components/ble/nrf_ble_gq;../bmd380_sdk/components/ble/nrf_ble_qwr;../bmd380_sdk/components/ble/nrf_ble_scan;../bmd380_sdk/components/ble/peer_manager;../bmd380_sdk/components/libraries/pwr_mgmt;%(ClCompile.AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>DEBUG=1;USE_APP_CONFIG=1;%(ClCompile.PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions />
<CPPLanguageStandard />
</ClCompile>
<Link>
<AdditionalLinkerInputs>;%(Link.AdditionalLinkerInputs)</AdditionalLinkerInputs>
<LibrarySearchDirectories>;%(Link.LibrarySearchDirectories)</LibrarySearchDirectories>
<AdditionalLibraryNames>;%(Link.AdditionalLibraryNames)</AdditionalLibraryNames>
<LinkerScript>nRF52811_XXAA_s140.lds</LinkerScript>
<AdditionalLinkerInputs>%(Link.AdditionalLinkerInputs)</AdditionalLinkerInputs>
<LibrarySearchDirectories>%(Link.LibrarySearchDirectories)</LibrarySearchDirectories>
<AdditionalLibraryNames>%(Link.AdditionalLibraryNames)</AdditionalLibraryNames>
<LinkerScript>nRF52840_XXAA_S140_reserve.lds</LinkerScript>
<AdditionalOptions />
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">
<ClCompile>
<CLanguageStandard>GNU99</CLanguageStandard>
<AdditionalIncludeDirectories>.;../bmd380_sdk/components/softdevice/s140/headers;../bmd380_sdk/components/softdevice/s140/headers/nrf52;../bmd380_sdk/external/segger_rtt;../bmd380_sdk/components/libraries/log;../bmd380_sdk/components/libraries/log/src;../bmd380_sdk/components/libraries/memobj;../bmd380_sdk/components/libraries/ringbuf;../bmd380_sdk/components/libraries/atomic;../bmd380_sdk/components/libraries/balloc;../bmd380_sdk/external/freertos/portable/CMSIS/nrf52;../bmd380_sdk/external/freertos/portable/GCC/nrf52;../bmd380_sdk/integration/nrfx;../bmd380_sdk/integration/nrfx/legacy;../bmd380_sdk/components/libraries/experimental_section_vars;../bmd380_sdk/components/libraries/strerror;../bmd380_sdk/external/freertos/source/include;../bmd380_sdk/components/softdevice/common;../bmd380_sdk/components/ble/common;../bmd380_sdk/components/ble/ble_advertising;../bmd380_sdk/components/libraries/atomic_flags;../bmd380_sdk/components/ble/ble_db_discovery;../bmd380_sdk/components/ble/ble_dtm;../bmd380_sdk/components/ble/ble_link_ctx_manager;../bmd380_sdk/components/ble/ble_racp;../bmd380_sdk/components/ble/ble_radio_notification;../bmd380_sdk/components/ble/ble_services/ble_ancs_c;../bmd380_sdk/components/ble/ble_services/ble_ans_c;../bmd380_sdk/components/ble/ble_services/ble_bas;../bmd380_sdk/components/ble/ble_services/ble_bas_c;../bmd380_sdk/components/ble/ble_services/ble_bps;../bmd380_sdk/components/ble/ble_services/ble_cscs;../bmd380_sdk/components/ble/ble_services/ble_cts_c;../bmd380_sdk/components/ble/ble_services/ble_dfu;../bmd380_sdk/components/ble/ble_services/ble_dis;../bmd380_sdk/components/ble/ble_services/ble_dis_c;../bmd380_sdk/components/ble/ble_services/ble_escs;../bmd380_sdk/components/ble/ble_services/ble_gls;../bmd380_sdk/components/ble/ble_services/ble_hids;../bmd380_sdk/components/ble/ble_services/ble_hrs;../bmd380_sdk/components/ble/ble_services/ble_hrs_c;../bmd380_sdk/components/ble/ble_services/ble_hts;../bmd380_sdk/components/ble/ble_services/ble_ias;../bmd380_sdk/components/ble/ble_services/ble_ias_c;../bmd380_sdk/components/ble/ble_services/ble_ipsp;../bmd380_sdk/components/ble/ble_services/ble_lbs;../bmd380_sdk/components/ble/ble_services/ble_lbs_c;../bmd380_sdk/components/ble/ble_services/ble_lls;../bmd380_sdk/components/ble/ble_services/ble_nus;../bmd380_sdk/components/ble/ble_services/ble_nus_c;../bmd380_sdk/components/ble/ble_services/ble_rscs;../bmd380_sdk/components/ble/ble_services/ble_rscs_c;../bmd380_sdk/components/ble/ble_services/ble_tps;../bmd380_sdk/components/ble/ble_services/eddystone;../bmd380_sdk/components/ble/ble_services/experimental_ble_lns;../bmd380_sdk/components/ble/ble_services/experimental_ble_ots;../bmd380_sdk/components/ble/ble_services/experimental_gatts_c;../bmd380_sdk/components/ble/ble_services/experimental_nrf_ble_cgms;../bmd380_sdk/components/ble/ble_services/experimental_nrf_ble_ots_c;../bmd380_sdk/components/ble/ble_services/nrf_ble_bms;../bmd380_sdk/components/ble/nrf_ble_gatt;../bmd380_sdk/components/ble/nrf_ble_gq;../bmd380_sdk/components/ble/nrf_ble_qwr;../bmd380_sdk/components/ble/nrf_ble_scan;../bmd380_sdk/components/ble/peer_manager;%(ClCompile.AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG=1;RELEASE=1;USE_APP_CONFIG=1;%(ClCompile.PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalLinkerInputs>;%(Link.AdditionalLinkerInputs)</AdditionalLinkerInputs>
<LibrarySearchDirectories>;%(Link.LibrarySearchDirectories)</LibrarySearchDirectories>
<AdditionalLibraryNames>;%(Link.AdditionalLibraryNames)</AdditionalLibraryNames>
<LinkerScript>nRF52840_XXAA_S140_reserve.lds</LinkerScript>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="..\bmd380_sdk\external\freertos\license\license.txt" />
@@ -74,7 +82,12 @@
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ItemGroup>
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu.c" />
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu_unbonded.c" />
<ClCompile Include="..\bmd380_sdk\components\ble\ble_services\ble_dis\ble_dis.c" />
<ClCompile Include="..\bmd380_sdk\components\ble\nrf_ble_gatt\nrf_ble_gatt.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\atomic\nrf_atomic.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\balloc\nrf_balloc.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\experimental_section_vars\nrf_section_iter.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\log\src\nrf_log_backend_flash.c" />
@@ -85,8 +98,24 @@
<ClCompile Include="..\bmd380_sdk\components\libraries\log\src\nrf_log_frontend.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\log\src\nrf_log_str_formatter.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\memobj\nrf_memobj.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\pwr_mgmt\nrf_pwr_mgmt.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\ringbuf\nrf_ringbuf.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\strerror\nrf_strerror.c" />
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_ant.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_ble.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_freertos.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_soc.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\external\freertos\portable\CMSIS\nrf52\port_cmsis.c" />
<ClCompile Include="..\bmd380_sdk\external\freertos\portable\CMSIS\nrf52\port_cmsis_systick.c" />
<ClCompile Include="..\bmd380_sdk\external\freertos\portable\GCC\nrf52\port.c" />
@@ -95,21 +124,27 @@
<ClCompile Include="..\bmd380_sdk\external\freertos\source\list.c" />
<ClCompile Include="..\bmd380_sdk\external\freertos\source\portable\Common\mpu_wrappers.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\external\freertos\source\portable\MemMang\heap_1.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\external\freertos\source\portable\MemMang\heap_2.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\external\freertos\source\portable\MemMang\heap_3.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\external\freertos\source\portable\MemMang\heap_4.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\external\freertos\source\portable\MemMang\heap_5.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\external\freertos\source\queue.c" />
<ClCompile Include="..\bmd380_sdk\external\freertos\source\stream_buffer.c" />
@@ -129,7 +164,8 @@
<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'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_spis.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
@@ -138,12 +174,24 @@
<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'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
</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="le_adv.c" />
<ClCompile Include="le_dfu.c" />
<ClCompile Include="le_edc_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" />
@@ -203,9 +251,13 @@
<ClCompile Include="$(BSP_ROOT)\nRF5x\modules\nrfx\hal\nrf_ecb.c" />
<ClCompile Include="$(BSP_ROOT)\nRF5x\modules\nrfx\hal\nrf_nvmc.c" />
<ClCompile Include="$(BSP_ROOT)\nRF5x\modules\nrfx\soc\nrfx_atomic.c" />
<ClInclude Include="..\bmd380_sdk\components\ble\ble_services\ble_dfu\ble_dfu.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\ble_services\ble_dis\ble_dis.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\nrf_ble_gatt\nrf_ble_gatt.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic\nrf_atomic.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic\nrf_atomic_internal.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic\nrf_atomic_sanity_check.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\balloc\nrf_balloc.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\experimental_section_vars\nrf_section.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\experimental_section_vars\nrf_section_iter.h" />
@@ -223,8 +275,14 @@
<ClInclude Include="..\bmd380_sdk\components\libraries\log\src\nrf_log_ctrl_internal.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\log\src\nrf_log_internal.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\memobj\nrf_memobj.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\pwr_mgmt\nrf_pwr_mgmt.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\ringbuf\nrf_ringbuf.h" />
<ClInclude Include="..\bmd380_sdk\components\libraries\strerror\nrf_strerror.h" />
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh.h" />
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_ant.h" />
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_ble.h" />
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_freertos.h" />
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_soc.h" />
<ClInclude Include="..\bmd380_sdk\external\freertos\portable\CMSIS\nrf52\portmacro_cmsis.h" />
<ClInclude Include="..\bmd380_sdk\external\freertos\portable\GCC\nrf52\portmacro.h" />
<ClInclude Include="..\bmd380_sdk\external\freertos\source\include\croutine.h" />
@@ -278,6 +336,7 @@
<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" />
@@ -521,5 +580,18 @@
<None Include="bmd380_peripheral-Debug.vgdbsettings" />
<None Include="bmd380_peripheral-Release.vgdbsettings" />
<None Include="nrf5x.xml" />
<ClCompile Include="..\bmd380_sdk\components\ble\ble_advertising\ble_advertising.c" />
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_advdata.c" />
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_conn_params.c" />
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_conn_state.c" />
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_srv_common.c" />
<ClInclude Include="..\bmd380_sdk\components\ble\ble_advertising\ble_advertising.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_advdata.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_conn_params.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_conn_state.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_date_time.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_gatt_db.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_sensor_location.h" />
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_srv_common.h" />
</ItemGroup>
</Project>
+165
View File
@@ -202,6 +202,36 @@
<Filter Include="Header files\integration\nrfx\legacy">
<UniqueIdentifier>{3eb77b43-f265-4923-86c6-d9e123cdf282}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\softdevice">
<UniqueIdentifier>{3d372dea-1fd2-4fa6-9de8-8f8e3e36d4cd}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\softdevice">
<UniqueIdentifier>{9d0c0dc5-0836-4799-8e1e-863bb92fa31b}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\softdevice\common">
<UniqueIdentifier>{e08c3a0a-44b9-484a-a2d6-753845cfc53f}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\softdevice\common">
<UniqueIdentifier>{c7ac68a2-299c-474c-885e-d429e8e5a452}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\ble">
<UniqueIdentifier>{bc9e84c6-e1eb-4f92-a953-156157313736}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\ble\ble_advertising">
<UniqueIdentifier>{e343d3fa-a2ab-4468-a86f-85ab5bf8691f}</UniqueIdentifier>
</Filter>
<Filter Include="Source files\ble\common">
<UniqueIdentifier>{6796de8c-d113-49ae-b410-1ba146602aaa}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\ble">
<UniqueIdentifier>{e35e5681-0697-4cac-a093-e56c06a1b735}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\ble\ble_advertising">
<UniqueIdentifier>{7f288a24-1e47-49e6-9a8a-907e9c84ca1d}</UniqueIdentifier>
</Filter>
<Filter Include="Header files\ble\common">
<UniqueIdentifier>{defffc43-551c-4791-967b-7d0aee507516}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
@@ -1230,6 +1260,108 @@
<ClCompile Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_uart.c">
<Filter>Source files\integration\nrfx\legacy</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh.c">
<Filter>Source files\softdevice\common</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_ant.c">
<Filter>Source files\softdevice\common</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_ble.c">
<Filter>Source files\softdevice\common</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_freertos.c">
<Filter>Source files\softdevice\common</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_soc.c">
<Filter>Source files\softdevice\common</Filter>
</ClCompile>
<ClCompile Include="le_adv.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="le_gap.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\ble_advertising\ble_advertising.c">
<Filter>Source files\ble\ble_advertising</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_advdata.c">
<Filter>Source files\ble\common</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_conn_params.c">
<Filter>Source files\ble\common</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_conn_state.c">
<Filter>Source files\ble\common</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_srv_common.c">
<Filter>Source files\ble\common</Filter>
</ClCompile>
<ClInclude Include="..\bmd380_sdk\components\ble\ble_advertising\ble_advertising.h">
<Filter>Header files\ble\ble_advertising</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_advdata.h">
<Filter>Header files\ble\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_conn_params.h">
<Filter>Header files\ble\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_conn_state.h">
<Filter>Header files\ble\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_date_time.h">
<Filter>Header files\ble\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_gatt_db.h">
<Filter>Header files\ble\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_sensor_location.h">
<Filter>Header files\ble\common</Filter>
</ClInclude>
<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">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\ble\nrf_ble_gatt\nrf_ble_gatt.c">
<Filter>Source files</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>
<ClCompile Include="le_srv.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="syscalls.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="..\bmd380_sdk\components\libraries\pwr_mgmt\nrf_pwr_mgmt.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="led.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="spi.c">
<Filter>Source files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="nRF52840_XXAA_S140_reserve.lds">
@@ -1465,6 +1597,39 @@
<ClInclude Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_wdt.h">
<Filter>Header files\integration\nrfx\legacy</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh.h">
<Filter>Header files\softdevice\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_ant.h">
<Filter>Header files\softdevice\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_ble.h">
<Filter>Header files\softdevice\common</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_freertos.h">
<Filter>Header files\softdevice\common</Filter>
</ClInclude>
<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>
<ClInclude Include="..\bmd380_sdk\components\ble\ble_services\ble_dis\ble_dis.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\bmd380_sdk\components\ble\nrf_ble_gatt\nrf_ble_gatt.h">
<Filter>Header files</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>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\bmd380_sdk\external\segger_rtt\license\license.txt">
+261
View File
@@ -0,0 +1,261 @@
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "ble_srv_common.h"
#include "FreeRTOS.h"
#include "queue.h"
#include "semphr.h"
#include "task.h"
#ifdef __cplusplus
}
#endif
static QueueHandle_t regular_data_q = NULL;
static SemaphoreHandle_t regular_data_sem = NULL;
typedef struct __PACKED
{
uint32_t timestamp;
uint8_t id;
uint8_t type : 4;
uint8_t : 4;
union
{
double double_val;
float flaot_val;
uint64_t u64_val;
uint32_t u32_val;
uint16_t u16_val;
uint8_t u8_val;
int64_t i64_val;
int32_t i32_val;
int16_t i16_val;
int8_t i8_val;
} content;
uint8_t padding[2];
} channel_data_t;
#define REGULAR_I8_TYPE 0
#define REGULAR_I16_TYPE 1
#define REGULAR_I32_TYPE 2
#define REGULAR_I64_TYPE 3
#define REGULAR_U8_TYPE 4
#define REGULAR_U16_TYPE 5
#define REGULAR_U32_TYPE 6
#define REGULAR_U64_TYPE 7
#define REGULAR_FLOAT_TYPE 8
#define REGULAR_DOUBLE_TYPE 9
#define REGULAR_MAX_TYPE 10
const uint32_t channel_size_table[REGULAR_MAX_TYPE] = {
[REGULAR_I8_TYPE] = offsetof(channel_data_t, content) + sizeof(int8_t),
[REGULAR_I16_TYPE] = offsetof(channel_data_t, content) + sizeof(int16_t),
[REGULAR_I32_TYPE] = offsetof(channel_data_t, content) + sizeof(int32_t),
[REGULAR_I64_TYPE] = offsetof(channel_data_t, content) + sizeof(int64_t),
[REGULAR_U8_TYPE] = offsetof(channel_data_t, content) + sizeof(uint8_t),
[REGULAR_U16_TYPE] = offsetof(channel_data_t, content) + sizeof(uint16_t),
[REGULAR_U32_TYPE] = offsetof(channel_data_t, content) + sizeof(uint32_t),
[REGULAR_U64_TYPE] = offsetof(channel_data_t, content) + sizeof(uint64_t),
[REGULAR_FLOAT_TYPE] = offsetof(channel_data_t, content) + sizeof(float),
[REGULAR_DOUBLE_TYPE] = offsetof(channel_data_t, content) + sizeof(double),
};
void pseudo_sensorAA_read(channel_data_t *p_channel_data)
{
static uint32_t val = 0;
p_channel_data->timestamp = xTaskGetTickCount();
p_channel_data->id = 0xAA;
p_channel_data->type = REGULAR_U32_TYPE;
p_channel_data->content.u32_val = val++;
}
void pseudo_sensorBB_read(channel_data_t *p_channel_data)
{
static uint32_t val = 0;
p_channel_data->timestamp = xTaskGetTickCount();
p_channel_data->id = 0xBB;
p_channel_data->type = REGULAR_U32_TYPE;
p_channel_data->content.u32_val = val--;
}
static void pseudo_data_task(void *pArg)
{
void (*pfCallback)(channel_data_t *p_channel_data) = pArg;
for (;;)
{
channel_data_t ch_data;
memset(&ch_data, 0x00, sizeof(ch_data));
pfCallback(&ch_data);
if (xQueueSend(regular_data_q, &ch_data, pdMS_TO_TICKS(50)) == pdFAIL)
{
__BKPT(255);
}
else
{
portYIELD();
}
}
}
static union
{
uint8_t raw[256];
struct __PACKED
{
uint8_t len;
uint8_t seq;
uint16_t : 16;
uint32_t time;
uint8_t channel_len; /* channel len => group length */
} header;
} payload;
static void regular_data_msg_task(void *pArg)
{
for (;;)
{
channel_data_t ch_data;
uint32_t offset = sizeof(payload.header);
/*
Receive a message on the regular_data_q queue.
Block for forever if a message is not immediately available.
*/
if (xQueueReceive(regular_data_q, &ch_data, portMAX_DELAY) == pdTRUE)
{
uint32_t channel_size = channel_size_table[ch_data.type % REGULAR_MAX_TYPE];
memcpy(&payload.raw[offset], &ch_data, channel_size);
offset += channel_size;
/* set channel len = 1 */
payload.header.channel_len = 1;
}
else
{
continue;
}
extern uint16_t le_gatt_mtu(void);
uint16_t att_mtu = le_gatt_mtu() - 3;
for (;;)
{
/*
Receive a message on the regular_data_q queue.
Block for 50ms if a message is not immediately available.
if there is no new message after 50ms, breaks out of the loop.
*/
if (xQueueReceive(regular_data_q, &ch_data, pdMS_TO_TICKS(50)) == pdTRUE)
{
/* set channel data total length. */
uint32_t channel_size = channel_size_table[ch_data.type % REGULAR_MAX_TYPE];
/* copy channel data to payload buffer. */
memcpy(&payload.raw[offset], &ch_data, channel_size);
offset += channel_size;
/* increase channel len */
payload.header.channel_len++;
/* if payload length is almost full, breaks out of the loop. */
if (offset > (att_mtu - (sizeof(ch_data) - 2) - 1))
{
break;
}
}
else
{
break;
}
}
extern bool le_regular_data_notify_is_enable(void);
if (le_regular_data_notify_is_enable())
{
extern ret_code_t le_regular_data_notify(uint8_t * p_value, uint16_t len);
/* update payload length & sequence number */
payload.header.len = offset + 1;
payload.header.seq++;
for (int i = 0; i < 3; i++)
{
/* update payload notify time */
payload.header.time = xTaskGetTickCount();
/* calculate checksum */
uint8_t chksum = 0;
for (uint32_t i = 0; i < offset; i++)
{
chksum += payload.raw[i];
}
/* append checksum */
payload.raw[offset] = chksum;
/* try to send notify */
ret_code_t err_code = le_regular_data_notify(payload.raw, offset + 1);
/* if notify success, breaks out of the loop. */
if (err_code == NRF_SUCCESS)
{
break;
}
/* if timeout, breaks out of the loop. */
if (xSemaphoreTake(regular_data_sem, pdMS_TO_TICKS(50)) == false)
{
NRF_LOG_INFO("regulat data underrun.");
break;
}
}
}
}
}
static void edc_regular_data_handler(ble_evt_t const *p_ble_evt, void *p_context)
{
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
payload.header.seq = 0xFF;
xQueueReset(regular_data_q);
break;
case BLE_GAP_EVT_DISCONNECTED:
break;
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
xSemaphoreGive(regular_data_sem);
break;
default:
break;
}
}
void edc_regular_data_init(void)
{
regular_data_q = xQueueCreate(64, sizeof(channel_data_t));
if (regular_data_q == NULL)
{
// Will not get here unless there is insufficient RAM.
__BKPT(255);
}
regular_data_sem = xSemaphoreCreateBinary();
if (regular_data_sem == NULL)
{
// Will not get here unless there is insufficient RAM.
__BKPT(255);
}
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);
}
+159
View File
@@ -0,0 +1,159 @@
#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);
}
+100
View File
@@ -0,0 +1,100 @@
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_srv_common.h"
#ifdef __cplusplus
}
#endif
BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */
static void le_adv_evt_handler(ble_adv_evt_t const adv_evt)
{
switch (adv_evt)
{
case BLE_ADV_EVT_IDLE:
case BLE_ADV_EVT_DIRECTED_HIGH_DUTY:
case BLE_ADV_EVT_DIRECTED:
case BLE_ADV_EVT_FAST:
case BLE_ADV_EVT_SLOW:
case BLE_ADV_EVT_FAST_WHITELIST:
case BLE_ADV_EVT_SLOW_WHITELIST:
case BLE_ADV_EVT_WHITELIST_REQUEST:
case BLE_ADV_EVT_PEER_ADDR_REQUEST:
default:
break;
}
}
static void le_adv_error_handler(uint32_t nrf_error)
{
// TODO...
__BKPT(255);
}
void le_adv_init(uint8_t ble_conn_cfg_tag)
{
uint32_t err_code;
ble_advertising_init_t init;
memset(&init, 0, sizeof(init));
struct
{
const uint8_t company_code[5];
const uint8_t hw_ver[4];
uint16_t bat_volt;
} __PACKED data = {
.company_code = ELITE_COMPANY_CODE,
.hw_ver = ELITE_HW_VER,
.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
manuf_specific_data.data.p_data = (uint8_t *)&data;
manuf_specific_data.data.size = sizeof(data);
manuf_specific_data.company_identifier = 0xFFFF;
init.advdata.p_manuf_specific_data = &manuf_specific_data;
init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
init.config.ble_adv_fast_enabled = true;
init.config.ble_adv_fast_interval = MSEC_TO_UNITS(25, UNIT_0_625_MS);
init.config.ble_adv_fast_timeout = MSEC_TO_UNITS(3000, UNIT_10_MS);
init.config.ble_adv_slow_enabled = true;
init.config.ble_adv_slow_interval = MSEC_TO_UNITS(250, UNIT_0_625_MS);
init.config.ble_adv_slow_timeout = MSEC_TO_UNITS(0, UNIT_10_MS);
init.evt_handler = le_adv_evt_handler;
init.error_handler = le_adv_error_handler;
err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(err_code);
ble_advertising_conn_cfg_tag_set(&m_advertising, ble_conn_cfg_tag);
ret_code_t ret = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(ret);
}
+80
View File
@@ -0,0 +1,80 @@
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "ble_conn_state.h"
#include "ble_dfu.h"
#include "ble_dis.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;
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_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;
}
}
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);
APP_ERROR_CHECK(err_code);
}
+728
View File
@@ -0,0 +1,728 @@
#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)
+67
View File
@@ -0,0 +1,67 @@
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_log.h"
#include "app_error.h"
#ifdef __cplusplus
}
#endif
void le_gap_init(const char *device_name, uint16_t usAppearance)
{
ret_code_t err_code;
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
if (device_name != NULL)
{
// Set GAP device name
err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)device_name, strlen(device_name));
APP_ERROR_CHECK(err_code);
}
// Set GAP Appearance value
err_code = sd_ble_gap_appearance_set(usAppearance);
APP_ERROR_CHECK(err_code);
// Set GAP Peripheral Preferred Connection Parameters.
ble_gap_conn_params_t gap_conn_params;
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
gap_conn_params.min_conn_interval = MSEC_TO_UNITS(8, UNIT_1_25_MS); /**< Minimum connection interval (7.5 ms) */
gap_conn_params.max_conn_interval = MSEC_TO_UNITS(20, UNIT_1_25_MS); /**< Maximum connection interval (20 ms). */
gap_conn_params.slave_latency = 8; /**< Slave latency. */
gap_conn_params.conn_sup_timeout = MSEC_TO_UNITS(10000, UNIT_10_MS); /**< Connection supervisory timeout (10s). */
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);
}
void le_gap_disconnect(uint16_t conn_handle, void *p_context)
{
UNUSED_PARAMETER(p_context);
ret_code_t err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_SUCCESS)
{
NRF_LOG_WARNING("Failed to disconnect connection. Connection handle: %d Error: %d", conn_handle, err_code);
}
else
{
NRF_LOG_DEBUG("Disconnected connection handle %d", conn_handle);
}
}
+41
View File
@@ -0,0 +1,41 @@
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "ble_gatt.h"
#include "nrf_ble_gatt.h"
#ifdef __cplusplus
}
#endif
NRF_BLE_GATT_DEF(m_gatt); /**< GATT module instance. */
void le_gatt_init(void)
{
ret_code_t err_code = nrf_ble_gatt_init(&m_gatt, NULL);
APP_ERROR_CHECK(err_code);
}
uint16_t le_gatt_mtu(void)
{
return nrf_ble_gatt_eff_mtu_get(&m_gatt, 0);
}
+65
View File
@@ -0,0 +1,65 @@
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "ble_conn_state.h"
#include "ble_dfu.h"
#include "ble_dis.h"
#include "nrf_ble_gatt.h"
#ifdef __cplusplus
}
#endif
#define MANUFACTURER_NAME "MEMCHIP" /**< Manufacturer. Will be passed to Device Information Service. */
#define HW_REV STRINGIFY(MAJOR_PRODUCT_NUMBER) "." STRINGIFY(MINOR_PRODUCT_NUMBER) "." STRINGIFY(MAJOR_VERSION_NUMBER) "." STRINGIFY(MINOR_VERSION_NUMBER)
#define FW_REV "0.1.0"
#define SER_NUM "0000-00-00-00001"
#define MODULE_NAME ELITE_DEVICE_NAME
static void le_dis_init(void)
{
ble_dis_init_t dis_init;
memset(&dis_init, 0, sizeof(dis_init));
ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, MANUFACTURER_NAME);
ble_srv_ascii_to_utf8(&dis_init.fw_rev_str, FW_REV);
ble_srv_ascii_to_utf8(&dis_init.hw_rev_str, HW_REV);
ble_srv_ascii_to_utf8(&dis_init.model_num_str, MODULE_NAME);
ble_srv_ascii_to_utf8(&dis_init.serial_num_str, SER_NUM);
dis_init.dis_char_rd_sec = SEC_OPEN;
ret_code_t err_code = ble_dis_init(&dis_init);
APP_ERROR_CHECK(err_code);
}
void le_srv_init(void)
{
le_dis_init();
extern void le_dfu_init(void);
le_dfu_init();
extern void le_edc_init(void);
le_edc_init(); // customer service
}
+100
View File
@@ -0,0 +1,100 @@
#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
@@ -0,0 +1,41 @@
#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__
+218 -22
View File
@@ -6,9 +6,9 @@ extern "C"
{
#endif
#include "sdk_config.h"
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
@@ -17,58 +17,254 @@ extern "C"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "led.h"
#ifdef __cplusplus
}
#endif
void led1_task(void *pArg)
#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. */
static void le_evt_handler(ble_evt_t const *p_ble_evt, void *p_context)
{
nrf_gpio_cfg_output(13);
ret_code_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_PHY_UPDATE:
NRF_LOG_INFO("PHY update procedure is complete.");
break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE:
NRF_LOG_INFO("Connection parameters updated.");
break;
case BLE_GAP_EVT_CONNECTED: {
NRF_LOG_INFO("Connect to peer.");
err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, p_ble_evt->evt.gap_evt.conn_handle, 8);
APP_ERROR_CHECK(err_code);
}
break;
case BLE_GAP_EVT_DISCONNECTED: {
NRF_LOG_INFO("Disconnect from peer.");
err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, p_ble_evt->evt.gap_evt.conn_handle, 0);
APP_ERROR_CHECK(err_code);
}
break;
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
.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;
case BLE_GATTS_EVT_SYS_ATTR_MISSING: {
ret_code_t err_code = sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0);
APP_ERROR_CHECK(err_code);
}
break;
default:
break;
}
}
static void le_stack_Init(void)
{
ret_code_t err_code;
uint32_t ram_start = 0;
ble_cfg_t ble_cfg;
memset(&ble_cfg, 0x00, sizeof(ble_cfg));
ble_cfg.conn_cfg.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;
ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 12;
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.
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
APP_ERROR_CHECK(err_code);
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, 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, 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 (;;)
{
NRF_LOG_INFO("led 1 off");
nrf_gpio_pin_set(13);
vTaskDelay(500);
NRF_LOG_INFO("led 1 on");
nrf_gpio_pin_clear(13);
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);
}
}
void led2_task(void *pArg)
static void nrf_sdh_freertos_task_hook(void *p_context)
{
nrf_gpio_cfg_output(14);
extern void twi0_init(void);
extern void spi_init(void);
for (;;)
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++)
{
NRF_LOG_INFO("led 2 off");
nrf_gpio_pin_set(14);
vTaskDelay(125);
NRF_LOG_INFO("led 2 on");
nrf_gpio_pin_clear(14);
vTaskDelay(125);
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", DEVICE_NAME, __TIME__, __DATE__);
NRF_LOG_INFO("%s Build: %s %s", ELITE_DEVICE_NAME, __TIME__, __DATE__);
xTaskCreate(led1_task, "led1_task", 160, NULL, 3, NULL);
xTaskCreate(led2_task, "led2_task", 160, NULL, 3, NULL);
nrf_sdh_freertos_init(nrf_sdh_freertos_task_hook, NULL); // create event: softdevice_task - wireless protocal stack
vTaskStartScheduler();
for (;;)
{
// Will not get here unless there is insufficient RAM.
__BKPT(255);
}
}
+2 -2
View File
@@ -5,8 +5,8 @@ MEMORY
{
FLASH_SOFTDEVICE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00027000
FLASH (rx) : ORIGIN = 0x00027000, LENGTH = 0x000d9000
RAM_SOFTDEVICE (rwx) : ORIGIN = 0x20000000, LENGTH = 0x000079e0
RAM (rwx) : ORIGIN = 0x200079e0, LENGTH = 0x00037620
RAM_SOFTDEVICE (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00018000
RAM (rwx) : ORIGIN = 0x20018000, LENGTH = 0x00027000
RTT (rwx) : ORIGIN = 0x2003F000, LENGTH = 0x00001000
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x6000
}
+11 -3
View File
@@ -2,10 +2,18 @@
MEMORY
{
FLASH (rx) : ORIGIN = 0x00027000, LENGTH = 0x000d9000
EXTFLASH (rx) : ORIGIN = 0x12000000, LENGTH = 0x8000000
RAM (rwx) : ORIGIN = 0x200079e0, LENGTH = 0x00038620
FLASH (rx) : ORIGIN = 0x00027000, LENGTH = 0x000B7000
RAM_SOFTDEVICE (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000
RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 0x0002F000
RTT (rwx) : ORIGIN = 0x2003F000, LENGTH = 0x00001000
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
+2 -2
View File
@@ -2,8 +2,8 @@
<EmbeddedProfile xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ToolchainID>com.visualgdb.arm-eabi</ToolchainID>
<ToolchainVersion>
<GCC>10.3.1</GCC>
<GDB>10.2.90</GDB>
<GCC>12.3.1</GCC>
<GDB>13.2</GDB>
<Revision>1</Revision>
</ToolchainVersion>
<BspID>com.sysprogs.arm.nordic.nrf5x</BspID>
+5
View File
@@ -0,0 +1,5 @@
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIEM6TVi/ofxCYEb2O9OYK4sNHlpwd0ZrW3yFOIeRJKqKoAoGCCqGSM49
AwEHoUQDQgAEYUIRVGOQwmOEfsuYSufu4hHxRsQSUzh9lMBkvc3ewrPkpbfiXfa/
vGyIM8HAY2Jemux9+FyFERXRjgj5RxOJAA==
-----END EC PRIVATE KEY-----
+73
View File
@@ -0,0 +1,73 @@
import asyncio
import os
import sys
import time
from io import BytesIO
from bleak import BleakClient
from bleak import _logger as logger
from bleak.uuids import uuid16_dict
os.chdir(os.path.dirname(os.path.realpath(__file__)))
REGULAR_UUID = "D89B0002-95C5-6F8D-1D44-8B1245563C4D"
target = 'raw1.bin'
f = open(target, 'wb')
f.truncate()
global IsFirstPacket
global TimeStart
global TimeStop
global TotalBytes
IsFirstPacket = True
TotalBytes = 0
def notification_handler(sender, data):
global IsFirstPacket
global TimeStart
global TimeStop
global TotalBytes
if IsFirstPacket :
TimeStart = time.time()
TimeStop = time.time()
IsFirstPacket = False
else :
TimeStop = time.time()
TotalBytes += len(data)
f.write(data)
if (TimeStop-TimeStart) > 0:
print("Throughput: {0} kbps ({1})".format(round((TotalBytes * 8 / 1024)/(TimeStop-TimeStart), 2),len(data)))
async def ble_notify_demo(mac_addr: str):
print("Connect to {0}".format(mac_addr))
client = BleakClient(mac_addr)
await client.connect()
IsConnected = await client.is_connected()
if IsConnected == False :
print("Connect fail.")
return False
print("Connect success.")
print("Wait 2 sec for PHY update procedure.")
await asyncio.sleep(2.0)
await client.start_notify(REGULAR_UUID, notification_handler)
# delay 10 sec
await asyncio.sleep(15)
await client.stop_notify(REGULAR_UUID)
await client.disconnect()
return True
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"
if asyncio.run(ble_notify_demo(mac_addr)) == True :
print("Recv total: {0} bytes".format(TotalBytes))
f.close()
# 資料讀取 n秒會自動存檔,並用 hex editor 開啟
os.system('010Editor.exe ' + target) # open file with hex editor
+117
View File
@@ -0,0 +1,117 @@
#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
@@ -0,0 +1,155 @@
/**
******************************************************************************
* @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;
}