Skip to content

Commit 6e64469

Browse files
committed
Clean up BLE LED example
1 parent f109062 commit 6e64469

File tree

5 files changed

+151
-144
lines changed

5 files changed

+151
-144
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef _BLE_EXAMPLE_H_
2+
#define _BLE_EXAMPLE_H_
3+
4+
#include "Arduino.h"
5+
6+
#define DEBUG
7+
#define SERIAL_PORT Serial
8+
9+
#include <stdint.h>
10+
#include <stdbool.h>
11+
12+
#ifdef __cplusplus
13+
extern "C"
14+
{
15+
#endif
16+
17+
#include "wsf_types.h"
18+
#include "wsf_trace.h"
19+
#include "wsf_buf.h"
20+
21+
#include "hci_handler.h"
22+
#include "dm_handler.h"
23+
#include "l2c_handler.h"
24+
#include "att_handler.h"
25+
#include "smp_handler.h"
26+
#include "l2c_api.h"
27+
#include "att_api.h"
28+
#include "smp_api.h"
29+
#include "app_api.h"
30+
#include "hci_core.h"
31+
#include "hci_drv.h"
32+
#include "hci_drv_apollo.h"
33+
#include "hci_drv_apollo3.h"
34+
35+
#include "am_mcu_apollo.h"
36+
#include "am_util.h"
37+
38+
#include "nus_api.h"
39+
#include "app_ui.h"
40+
41+
#include "wsf_msg.h"
42+
43+
#ifdef __cplusplus
44+
}
45+
#endif
46+
47+
48+
//*****************************************************************************
49+
//
50+
// Forward declarations.
51+
//
52+
//*****************************************************************************
53+
void exactle_stack_init(void);
54+
void scheduler_timer_init(void);
55+
void update_scheduler_timers(void);
56+
void set_next_wakeup(void);
57+
void button_handler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
58+
extern void AppUiBtnTest(uint8_t btn);
59+
60+
61+
#endif // _BLE_EXAMPLE_H_

libraries/Examples/examples/z_BLE_LED_temporary/z_BLE_LED_temporary.ino renamed to libraries/Examples/examples/Example8_BLE_LED/BLE_example_funcs.cpp

+36-144
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,4 @@
1-
#include <stdint.h>
2-
#include <stdbool.h>
3-
4-
#ifdef __cplusplus
5-
extern "C"
6-
{
7-
#endif
8-
9-
#include "wsf_types.h"
10-
#include "wsf_trace.h"
11-
#include "wsf_buf.h"
12-
13-
#include "hci_handler.h"
14-
#include "dm_handler.h"
15-
#include "l2c_handler.h"
16-
#include "att_handler.h"
17-
#include "smp_handler.h"
18-
#include "l2c_api.h"
19-
#include "att_api.h"
20-
#include "smp_api.h"
21-
#include "app_api.h"
22-
#include "hci_core.h"
23-
#include "hci_drv.h"
24-
#include "hci_drv_apollo.h"
25-
#include "hci_drv_apollo3.h"
26-
27-
#include "am_mcu_apollo.h"
28-
#include "am_util.h"
29-
30-
#include "nus_api.h"
31-
#include "app_ui.h"
32-
33-
#include "wsf_msg.h"
34-
35-
#ifdef __cplusplus
36-
}
37-
#endif
38-
39-
#define DEBUG
40-
#define SERIAL_PORT Serial
41-
#define DEBUG_UART_BUF_LEN 256
42-
43-
// ****************************************
44-
//
45-
// Debug print functions
46-
//
47-
// ****************************************
48-
extern "C" void debug_print(const char* f, const char* F, uint16_t L){
49-
SERIAL_PORT.printf("fm: %s, file: %s, line: %d\n", f, F, L);
50-
}
51-
52-
extern "C" void debug_printf(char* fmt, ...){
53-
#ifdef DEBUG
54-
char debug_buffer [DEBUG_UART_BUF_LEN];
55-
va_list args;
56-
va_start (args, fmt);
57-
vsnprintf(debug_buffer, DEBUG_UART_BUF_LEN, (const char*)fmt, args);
58-
va_end (args);
59-
60-
SERIAL_PORT.print(debug_buffer);
61-
#endif //DEBUG
62-
}
63-
64-
65-
// ****************************************
66-
//
67-
// C-callable led functions
68-
//
69-
// ****************************************
70-
extern void set_led_high( void ){
71-
digitalWrite(LED_BUILTIN, HIGH);
72-
}
73-
74-
extern void set_led_low( void ){
75-
digitalWrite(LED_BUILTIN, LOW);
76-
}
77-
78-
//*****************************************************************************
79-
//
80-
// Forward declarations.
81-
//
82-
//*****************************************************************************
83-
void exactle_stack_init(void);
84-
void scheduler_timer_init(void);
85-
void update_scheduler_timers(void);
86-
void set_next_wakeup(void);
87-
void button_handler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
88-
extern void AppUiBtnTest(uint8_t btn);
1+
#include "BLE_example.h"
892

903

914
//*****************************************************************************
@@ -151,6 +64,8 @@ static wsfBufPoolDesc_t g_psPoolDescriptors[WSF_BUF_POOLS] =
15164
uint32_t g_ui32LastTime = 0;
15265
extern "C" void radio_timer_handler(void);
15366

67+
68+
15469
//*****************************************************************************
15570
//
15671
// Initialization for the ExactLE stack.
@@ -441,63 +356,40 @@ extern "C" void am_ble_isr(void){
441356
}
442357

443358

444-
void setup() {
445-
// put your setup code here, to run once:
446-
447-
#ifdef DEBUG
448-
SERIAL_PORT.begin(115200);
449-
delay(1000);
450-
SERIAL_PORT.printf("Apollo3 Arduino BLE Example. Compiled: %s\n", __TIME__);
451-
#endif
452-
453-
pinMode(LED_BUILTIN, OUTPUT);
454-
set_led_low();
455-
456-
//
457-
// Boot the radio.
458-
//
459-
HciDrvRadioBoot(0);
460-
461-
//
462-
// Initialize the main ExactLE stack.
463-
//
464-
exactle_stack_init();
465-
466-
//
467-
// Start the "Nus" profile.
468-
//
469-
NusStart();
470-
471-
while (TRUE)
472-
{
473-
// debug_print(__func__, __FILE__, __LINE__);
474-
475-
//
476-
// Calculate the elapsed time from our free-running timer, and update
477-
// the software timers in the WSF scheduler.
478-
//
479-
update_scheduler_timers();
480-
wsfOsDispatcher();
481-
482-
//
483-
// Enable an interrupt to wake us up next time we have a scheduled event.
484-
//
485-
set_next_wakeup();
486-
487-
am_hal_interrupt_master_disable();
488-
489-
//
490-
// Check to see if the WSF routines are ready to go to sleep.
491-
//
492-
if ( wsfOsReadyToSleep() )
493-
{
494-
am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP);
495-
}
496-
am_hal_interrupt_master_enable();
497-
}
359+
360+
361+
// ****************************************
362+
//
363+
// Debug print functions
364+
//
365+
// ****************************************
366+
#define DEBUG_UART_BUF_LEN 256
367+
368+
extern "C" void debug_print(const char* f, const char* F, uint16_t L){
369+
SERIAL_PORT.printf("fm: %s, file: %s, line: %d\n", f, F, L);
498370
}
499371

500-
void loop() {
501-
// put your main code here, to run repeatedly:
372+
extern "C" void debug_printf(char* fmt, ...){
373+
#ifdef DEBUG
374+
char debug_buffer [DEBUG_UART_BUF_LEN];
375+
va_list args;
376+
va_start (args, fmt);
377+
vsnprintf(debug_buffer, DEBUG_UART_BUF_LEN, (const char*)fmt, args);
378+
va_end (args);
502379

380+
SERIAL_PORT.print(debug_buffer);
381+
#endif //DEBUG
503382
}
383+
384+
// ****************************************
385+
//
386+
// C-callable led functions
387+
//
388+
// ****************************************
389+
extern void set_led_high( void ){
390+
digitalWrite(LED_BUILTIN, HIGH);
391+
}
392+
393+
extern void set_led_low( void ){
394+
digitalWrite(LED_BUILTIN, LOW);
395+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "BLE_example.h"
2+
3+
void setup() {
4+
5+
#ifdef DEBUG
6+
SERIAL_PORT.begin(115200);
7+
delay(1000);
8+
SERIAL_PORT.printf("Apollo3 Arduino BLE Example. Compiled: %s\n", __TIME__);
9+
#endif
10+
11+
pinMode(LED_BUILTIN, OUTPUT);
12+
set_led_low();
13+
14+
//
15+
// Boot the radio.
16+
//
17+
HciDrvRadioBoot(0);
18+
19+
//
20+
// Initialize the main ExactLE stack.
21+
//
22+
exactle_stack_init();
23+
24+
//
25+
// Start the "Nus" profile.
26+
//
27+
NusStart();
28+
}
29+
30+
void loop() {
31+
32+
//
33+
// Calculate the elapsed time from our free-running timer, and update
34+
// the software timers in the WSF scheduler.
35+
//
36+
update_scheduler_timers();
37+
wsfOsDispatcher();
38+
39+
//
40+
// Enable an interrupt to wake us up next time we have a scheduled event.
41+
//
42+
set_next_wakeup();
43+
44+
am_hal_interrupt_master_disable();
45+
46+
//
47+
// Check to see if the WSF routines are ready to go to sleep.
48+
//
49+
if ( wsfOsReadyToSleep() )
50+
{
51+
am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP);
52+
}
53+
am_hal_interrupt_master_enable();
54+
}

0 commit comments

Comments
 (0)