A speedtest
Dependencies: aconno_SEGGER_RTT CustomService
Diff: main.cpp
- Branch:
- TestBranch
- Revision:
- 2:84d964276266
- Parent:
- 1:8fd903e4bcef
- Child:
- 4:de5cf6b1e96b
diff -r 8fd903e4bcef -r 84d964276266 main.cpp --- a/main.cpp Wed Oct 05 14:52:36 2016 +0000 +++ b/main.cpp Fri Aug 25 06:53:07 2017 +0000 @@ -4,24 +4,87 @@ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from * the file. * - * aconno simple example program - * blinky LED LD1 */ #include "mbed.h" #include "acd52832_bsp.h" +#include "ble/BLE.h" +#include "GapAdvertisingData.h" -#define pause 1 // Pause in seconds +#define USE_PWM (0) +#define USE_BLE (1) + +#if USE_BLE + BLE &ble = BLE::Instance(); +#endif + +Ticker WakeSleepT; +Ticker turnBuzzOffT; +Ticker sleepChanger; +#if USE_PWM + PwmOut buzzer(p31); +#endif -DigitalOut LD1(PIN_LED_RED); +#if USE_BLE +void bleInitComplete(BLE::InitializationCompleteCallbackContext *params){ + BLE& ble = params->ble; + /* Ensure that it is the default instance of BLE */ + if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { + return; + } + uint8_t MSD = 0x23; + /* setup advertising */ + ble.gap().setAdvertisingInterval(100); // --> Has to be at least 100ms! + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, &MSD, 1); + ble.gap().stopAdvertising(); +} +#endif + int main(){ + #if USE_BLE + ble.init(bleInitComplete); + /* SpinWait for initialization to complete. This is necessary because the BLE object is used in the main loop below. */ + while (ble.hasInitialized() == false){} + #endif + + #if USE_PWM + buzzer.period(0.0F); + buzzer.write(0.0F); + #endif + + /* + // Disconnect and stop PWM0 + NRF_PWM0->PSEL.OUT[0] = 0x80000000; + NRF_PWM0->PSEL.OUT[1] = 0x80000000; + NRF_PWM0->PSEL.OUT[2] = 0x80000000; + NRF_PWM0->PSEL.OUT[3] = 0x80000000; + NRF_PWM0->TASKS_STOP = 1; + */ + + // Disconnect and stop PWM1 + NRF_PWM1->PSEL.OUT[0] = 0x80000000; + NRF_PWM1->PSEL.OUT[1] = 0x80000000; + NRF_PWM1->PSEL.OUT[2] = 0x80000000; + NRF_PWM1->PSEL.OUT[3] = 0x80000000; + NRF_PWM1->TASKS_STOP = 1; + + // Disconnect and stop PWM2 + NRF_PWM2->PSEL.OUT[0] = 0x80000000; + NRF_PWM2->PSEL.OUT[1] = 0x80000000; + NRF_PWM2->PSEL.OUT[2] = 0x80000000; + NRF_PWM2->PSEL.OUT[3] = 0x80000000; + NRF_PWM2->TASKS_STOP = 1; + + NRF_CLOCK->TASKS_LFCLKSTART = 1; + while(!NRF_CLOCK->EVENTS_LFCLKSTARTED); + NRF_CLOCK->TASKS_HFCLKSTOP; + NRF_POWER->TASKS_LOWPWR = 0x00000001; + while(1){ - // Turn LED OFF - LD1 = 1; - wait(pause); - // Turn LED ON - LD1 = 0; - wait(pause); + #if USE_BLE + ble.waitForEvent(); + #endif + __WFI(); } } \ No newline at end of file