v2
Dependencies: BLE_API mbed DOOR
Fork of DOOR by
main.cpp@5:97ce285ff00a, 2014-05-20 (annotated)
- Committer:
- rohit.grover
- Date:
- Tue May 20 17:56:47 2014 +0100
- Revision:
- 5:97ce285ff00a
- Parent:
- 4:0ce8d2dd62f9
- Child:
- 6:26eab6ee6df4
white space diffs.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ktownsend | 0:7613d21e5974 | 1 | /* mbed Microcontroller Library |
ktownsend | 0:7613d21e5974 | 2 | * Copyright (c) 2006-2013 ARM Limited |
ktownsend | 0:7613d21e5974 | 3 | * |
ktownsend | 0:7613d21e5974 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ktownsend | 0:7613d21e5974 | 5 | * you may not use this file except in compliance with the License. |
ktownsend | 0:7613d21e5974 | 6 | * You may obtain a copy of the License at |
ktownsend | 0:7613d21e5974 | 7 | * |
ktownsend | 0:7613d21e5974 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ktownsend | 0:7613d21e5974 | 9 | * |
ktownsend | 0:7613d21e5974 | 10 | * Unless required by applicable law or agreed to in writing, software |
ktownsend | 0:7613d21e5974 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
ktownsend | 0:7613d21e5974 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ktownsend | 0:7613d21e5974 | 13 | * See the License for the specific language governing permissions and |
ktownsend | 0:7613d21e5974 | 14 | * limitations under the License. |
ktownsend | 0:7613d21e5974 | 15 | */ |
ktownsend | 0:7613d21e5974 | 16 | |
ktownsend | 0:7613d21e5974 | 17 | #include "mbed.h" |
ktownsend | 0:7613d21e5974 | 18 | #include "nRF51822n.h" |
ktownsend | 0:7613d21e5974 | 19 | |
ktownsend | 0:7613d21e5974 | 20 | nRF51822n nrf; /* BLE radio driver */ |
ktownsend | 0:7613d21e5974 | 21 | |
ktownsend | 0:7613d21e5974 | 22 | DigitalOut led1(LED1); |
ktownsend | 0:7613d21e5974 | 23 | DigitalOut led2(LED2); |
ktownsend | 0:7613d21e5974 | 24 | Ticker flipper; |
ktownsend | 0:7613d21e5974 | 25 | Serial pc(USBTX,USBRX); |
ktownsend | 0:7613d21e5974 | 26 | |
ktownsend | 0:7613d21e5974 | 27 | void tickerCallback(void); |
ktownsend | 0:7613d21e5974 | 28 | |
ktownsend | 0:7613d21e5974 | 29 | /**************************************************************************/ |
ktownsend | 0:7613d21e5974 | 30 | /*! |
ktownsend | 0:7613d21e5974 | 31 | @brief Program entry point |
ktownsend | 0:7613d21e5974 | 32 | */ |
ktownsend | 0:7613d21e5974 | 33 | /**************************************************************************/ |
ktownsend | 0:7613d21e5974 | 34 | int main(void) |
ktownsend | 0:7613d21e5974 | 35 | { |
ktownsend | 0:7613d21e5974 | 36 | *(uint32_t *)0x40000504 = 0xC007FFDF; |
ktownsend | 0:7613d21e5974 | 37 | *(uint32_t *)0x40006C18 = 0x00008000; |
ktownsend | 0:7613d21e5974 | 38 | |
ktownsend | 0:7613d21e5974 | 39 | /* Setup blinky: led1 is toggled in main, led2 is toggled via Ticker */ |
ktownsend | 0:7613d21e5974 | 40 | led1=1; |
ktownsend | 0:7613d21e5974 | 41 | led2=1; |
ktownsend | 0:7613d21e5974 | 42 | flipper.attach(&tickerCallback, 1.0); |
ktownsend | 0:7613d21e5974 | 43 | |
ktownsend | 0:7613d21e5974 | 44 | /* Initialise the nRF51822 */ |
ktownsend | 0:7613d21e5974 | 45 | pc.printf("Initialising the nRF51822\n\r"); |
ktownsend | 0:7613d21e5974 | 46 | nrf.init(); |
ktownsend | 0:7613d21e5974 | 47 | |
rohit.grover |
5:97ce285ff00a | 48 | GapAdvertisingParams advParams ( |
rohit.grover |
5:97ce285ff00a | 49 | GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED ); |
ktownsend | 0:7613d21e5974 | 50 | GapAdvertisingData advData; |
ktownsend | 0:7613d21e5974 | 51 | GapAdvertisingData scanResponse; |
ktownsend | 0:7613d21e5974 | 52 | |
ktownsend | 2:90b493cdcb1f | 53 | /* Define an Beacon payload |
ktownsend | 0:7613d21e5974 | 54 | -------------------------------------------------------------- |
ktownsend | 0:7613d21e5974 | 55 | 128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 |
ktownsend | 0:7613d21e5974 | 56 | Major/Minor = 0000 / 0000 |
ktownsend | 0:7613d21e5974 | 57 | Tx Power = C8 |
ktownsend | 0:7613d21e5974 | 58 | */ |
ktownsend | 4:0ce8d2dd62f9 | 59 | uint8_t beaconPayload[25] = { 0x4C, 0x00, 0x02, 0x15, 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61, 0x00, 0x00, 0x00, 0x00, 0xC8 }; |
ktownsend | 0:7613d21e5974 | 60 | |
ktownsend | 0:7613d21e5974 | 61 | /* Make sure we get a clean start */ |
ktownsend | 0:7613d21e5974 | 62 | nrf.reset(); |
ktownsend | 0:7613d21e5974 | 63 | |
ktownsend | 2:90b493cdcb1f | 64 | /* Beacon includes the FLAG and MSD fields */ |
ktownsend | 0:7613d21e5974 | 65 | advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
rohit.grover |
5:97ce285ff00a | 66 | advData.addData(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, |
rohit.grover |
5:97ce285ff00a | 67 | beaconPayload, |
rohit.grover |
5:97ce285ff00a | 68 | sizeof(beaconPayload)); |
ktownsend | 0:7613d21e5974 | 69 | |
ktownsend | 0:7613d21e5974 | 70 | /* Start advertising! */ |
ktownsend | 0:7613d21e5974 | 71 | nrf.getGap().setAdvertisingData(advData, scanResponse); |
ktownsend | 0:7613d21e5974 | 72 | nrf.getGap().startAdvertising(advParams); |
ktownsend | 0:7613d21e5974 | 73 | |
ktownsend | 0:7613d21e5974 | 74 | /* Do blinky on LED1 while we're waiting for BLE events */ |
rohit.grover |
5:97ce285ff00a | 75 | for (;; ) { |
ktownsend | 0:7613d21e5974 | 76 | led1 = !led1; |
ktownsend | 0:7613d21e5974 | 77 | wait(1); |
ktownsend | 0:7613d21e5974 | 78 | } |
ktownsend | 0:7613d21e5974 | 79 | } |
ktownsend | 0:7613d21e5974 | 80 | |
ktownsend | 0:7613d21e5974 | 81 | /**************************************************************************/ |
ktownsend | 0:7613d21e5974 | 82 | /*! |
ktownsend | 0:7613d21e5974 | 83 | @brief Ticker callback to switch led2 state |
ktownsend | 0:7613d21e5974 | 84 | */ |
ktownsend | 0:7613d21e5974 | 85 | /**************************************************************************/ |
ktownsend | 0:7613d21e5974 | 86 | void tickerCallback(void) |
ktownsend | 0:7613d21e5974 | 87 | { |
ktownsend | 0:7613d21e5974 | 88 | led2 = !led2; |
ktownsend | 0:7613d21e5974 | 89 | } |