BLE <-> UART only char[8]
Fork of nRF51822 by
nRF51822n.cpp@16:d8161e2af6c6, 2014-05-30 (annotated)
- Committer:
- Rohit Grover
- Date:
- Fri May 30 13:32:48 2014 +0100
- Revision:
- 16:d8161e2af6c6
- Parent:
- 4:534c2146e5ec
- Child:
- 22:c6ee8136847e
reset() should be called automatically by init()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:eff01767de02 | 1 | /* mbed Microcontroller Library |
bogdanm | 0:eff01767de02 | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 0:eff01767de02 | 3 | * |
bogdanm | 0:eff01767de02 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 0:eff01767de02 | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 0:eff01767de02 | 6 | * You may obtain a copy of the License at |
bogdanm | 0:eff01767de02 | 7 | * |
bogdanm | 0:eff01767de02 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 0:eff01767de02 | 9 | * |
bogdanm | 0:eff01767de02 | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 0:eff01767de02 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 0:eff01767de02 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 0:eff01767de02 | 13 | * See the License for the specific language governing permissions and |
bogdanm | 0:eff01767de02 | 14 | * limitations under the License. |
bogdanm | 0:eff01767de02 | 15 | */ |
Rohit Grover |
16:d8161e2af6c6 | 16 | |
bogdanm | 0:eff01767de02 | 17 | #include "mbed.h" |
bogdanm | 0:eff01767de02 | 18 | #include "nRF51822n.h" |
bogdanm | 0:eff01767de02 | 19 | |
bogdanm | 0:eff01767de02 | 20 | #include "btle/btle.h" |
bogdanm | 0:eff01767de02 | 21 | |
Rohit Grover |
4:534c2146e5ec | 22 | /** |
Rohit Grover |
4:534c2146e5ec | 23 | * The singleton which represents the nRF51822 transport for the BLEDevice. |
Rohit Grover |
4:534c2146e5ec | 24 | */ |
Rohit Grover |
4:534c2146e5ec | 25 | static nRF51822n deviceInstance; |
Rohit Grover |
4:534c2146e5ec | 26 | |
Rohit Grover |
4:534c2146e5ec | 27 | /** |
Rohit Grover |
4:534c2146e5ec | 28 | * BLE-API requires an implementation of the following function in order to |
Rohit Grover |
4:534c2146e5ec | 29 | * obtain its transport handle. |
Rohit Grover |
4:534c2146e5ec | 30 | */ |
Rohit Grover |
4:534c2146e5ec | 31 | BLEDeviceInstanceBase * |
Rohit Grover |
4:534c2146e5ec | 32 | createBLEDeviceInstance(void) { |
Rohit Grover |
4:534c2146e5ec | 33 | return (&deviceInstance); |
Rohit Grover |
4:534c2146e5ec | 34 | } |
Rohit Grover |
4:534c2146e5ec | 35 | |
bogdanm | 0:eff01767de02 | 36 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 37 | /*! |
bogdanm | 0:eff01767de02 | 38 | @brief Constructor |
bogdanm | 0:eff01767de02 | 39 | */ |
bogdanm | 0:eff01767de02 | 40 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 41 | nRF51822n::nRF51822n(void) |
bogdanm | 0:eff01767de02 | 42 | { |
bogdanm | 0:eff01767de02 | 43 | } |
bogdanm | 0:eff01767de02 | 44 | |
bogdanm | 0:eff01767de02 | 45 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 46 | /*! |
bogdanm | 0:eff01767de02 | 47 | @brief Destructor |
bogdanm | 0:eff01767de02 | 48 | */ |
bogdanm | 0:eff01767de02 | 49 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 50 | nRF51822n::~nRF51822n(void) |
bogdanm | 0:eff01767de02 | 51 | { |
bogdanm | 0:eff01767de02 | 52 | } |
bogdanm | 0:eff01767de02 | 53 | |
bogdanm | 0:eff01767de02 | 54 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 55 | /*! |
bogdanm | 0:eff01767de02 | 56 | @brief Initialises anything required to start using BLE |
Rohit Grover |
16:d8161e2af6c6 | 57 | |
bogdanm | 0:eff01767de02 | 58 | @returns ble_error_t |
Rohit Grover |
16:d8161e2af6c6 | 59 | |
bogdanm | 0:eff01767de02 | 60 | @retval BLE_ERROR_NONE |
bogdanm | 0:eff01767de02 | 61 | Everything executed properly |
Rohit Grover |
16:d8161e2af6c6 | 62 | |
bogdanm | 0:eff01767de02 | 63 | @section EXAMPLE |
bogdanm | 0:eff01767de02 | 64 | |
bogdanm | 0:eff01767de02 | 65 | @code |
bogdanm | 0:eff01767de02 | 66 | |
bogdanm | 0:eff01767de02 | 67 | @endcode |
bogdanm | 0:eff01767de02 | 68 | */ |
bogdanm | 0:eff01767de02 | 69 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 70 | ble_error_t nRF51822n::init(void) |
bogdanm | 0:eff01767de02 | 71 | { |
bogdanm | 0:eff01767de02 | 72 | /* ToDo: Clear memory contents, reset the SD, etc. */ |
bogdanm | 0:eff01767de02 | 73 | btle_init(); |
bogdanm | 0:eff01767de02 | 74 | |
Rohit Grover |
16:d8161e2af6c6 | 75 | reset(); |
Rohit Grover |
16:d8161e2af6c6 | 76 | |
bogdanm | 0:eff01767de02 | 77 | return BLE_ERROR_NONE; |
bogdanm | 0:eff01767de02 | 78 | } |
bogdanm | 0:eff01767de02 | 79 | |
bogdanm | 0:eff01767de02 | 80 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 81 | /*! |
bogdanm | 0:eff01767de02 | 82 | @brief Resets the BLE HW, removing any existing services and |
bogdanm | 0:eff01767de02 | 83 | characteristics |
Rohit Grover |
16:d8161e2af6c6 | 84 | |
bogdanm | 0:eff01767de02 | 85 | @returns ble_error_t |
Rohit Grover |
16:d8161e2af6c6 | 86 | |
bogdanm | 0:eff01767de02 | 87 | @retval BLE_ERROR_NONE |
bogdanm | 0:eff01767de02 | 88 | Everything executed properly |
Rohit Grover |
16:d8161e2af6c6 | 89 | |
bogdanm | 0:eff01767de02 | 90 | @section EXAMPLE |
bogdanm | 0:eff01767de02 | 91 | |
bogdanm | 0:eff01767de02 | 92 | @code |
bogdanm | 0:eff01767de02 | 93 | |
bogdanm | 0:eff01767de02 | 94 | @endcode |
bogdanm | 0:eff01767de02 | 95 | */ |
bogdanm | 0:eff01767de02 | 96 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 97 | ble_error_t nRF51822n::reset(void) |
bogdanm | 0:eff01767de02 | 98 | { |
bogdanm | 0:eff01767de02 | 99 | wait(0.5); |
Rohit Grover |
16:d8161e2af6c6 | 100 | |
bogdanm | 0:eff01767de02 | 101 | /* Wait for the radio to come back up */ |
bogdanm | 0:eff01767de02 | 102 | wait(1); |
Rohit Grover |
16:d8161e2af6c6 | 103 | |
bogdanm | 0:eff01767de02 | 104 | return BLE_ERROR_NONE; |
bogdanm | 0:eff01767de02 | 105 | } |