Bizan Nishimura / BLE_API

Dependents:   MiniSteer_BLE

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Thu Jan 16 22:29:53 2014 +0000
Revision:
29:011e95ce78b8
Added better radio abstraction layer, moved Gatt enums from blecommon.h to GattCharacteristic.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 29:011e95ce78b8 1 /* mbed Microcontroller Library
ktownsend 29:011e95ce78b8 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 29:011e95ce78b8 3 *
ktownsend 29:011e95ce78b8 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 29:011e95ce78b8 5 * you may not use this file except in compliance with the License.
ktownsend 29:011e95ce78b8 6 * You may obtain a copy of the License at
ktownsend 29:011e95ce78b8 7 *
ktownsend 29:011e95ce78b8 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 29:011e95ce78b8 9 *
ktownsend 29:011e95ce78b8 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 29:011e95ce78b8 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 29:011e95ce78b8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 29:011e95ce78b8 13 * See the License for the specific language governing permissions and
ktownsend 29:011e95ce78b8 14 * limitations under the License.
ktownsend 29:011e95ce78b8 15 */
ktownsend 29:011e95ce78b8 16
ktownsend 29:011e95ce78b8 17 #include "mbed.h"
ktownsend 29:011e95ce78b8 18 #include "nRF51822s.h"
ktownsend 29:011e95ce78b8 19
ktownsend 29:011e95ce78b8 20 /**************************************************************************/
ktownsend 29:011e95ce78b8 21 /*!
ktownsend 29:011e95ce78b8 22 @brief UART callback function
ktownsend 29:011e95ce78b8 23 */
ktownsend 29:011e95ce78b8 24 /**************************************************************************/
ktownsend 29:011e95ce78b8 25 void nRF51822s::uartCallback(void)
ktownsend 29:011e95ce78b8 26 {
ktownsend 29:011e95ce78b8 27 /* ToDo: Check responses and set a flag for success/error/etc. */
ktownsend 29:011e95ce78b8 28
ktownsend 29:011e95ce78b8 29 /* Read serial to clear the RX interrupt */
ktownsend 29:011e95ce78b8 30 uart.getc();
ktownsend 29:011e95ce78b8 31 }
ktownsend 29:011e95ce78b8 32
ktownsend 29:011e95ce78b8 33 /**************************************************************************/
ktownsend 29:011e95ce78b8 34 /*!
ktownsend 29:011e95ce78b8 35 @brief Constructor
ktownsend 29:011e95ce78b8 36 */
ktownsend 29:011e95ce78b8 37 /**************************************************************************/
ktownsend 29:011e95ce78b8 38 nRF51822s::nRF51822s(PinName tx, PinName rx, PinName rts, PinName cts) : uart(tx, rx), gap(uart), gattServer(uart)
ktownsend 29:011e95ce78b8 39 {
ktownsend 29:011e95ce78b8 40 /* Setup the nRF UART interface */
ktownsend 29:011e95ce78b8 41 uart.baud(9600);
ktownsend 29:011e95ce78b8 42
ktownsend 29:011e95ce78b8 43 /* Echo data on the debug CDC port */
ktownsend 29:011e95ce78b8 44 uart.attach(this, &nRF51822s::uartCallback);
ktownsend 29:011e95ce78b8 45
ktownsend 29:011e95ce78b8 46 /* Add flow control for UART (required by the nRF51822) */
ktownsend 29:011e95ce78b8 47 uart.set_flow_control(RawSerial::RTSCTS, rts, cts);
ktownsend 29:011e95ce78b8 48 }
ktownsend 29:011e95ce78b8 49
ktownsend 29:011e95ce78b8 50 /**************************************************************************/
ktownsend 29:011e95ce78b8 51 /*!
ktownsend 29:011e95ce78b8 52 @brief Destructor
ktownsend 29:011e95ce78b8 53 */
ktownsend 29:011e95ce78b8 54 /**************************************************************************/
ktownsend 29:011e95ce78b8 55 nRF51822s::~nRF51822s(void)
ktownsend 29:011e95ce78b8 56 {
ktownsend 29:011e95ce78b8 57 }
ktownsend 29:011e95ce78b8 58
ktownsend 29:011e95ce78b8 59 /**************************************************************************/
ktownsend 29:011e95ce78b8 60 /*!
ktownsend 29:011e95ce78b8 61 @brief Resets the BLE HW, removing any existing services and
ktownsend 29:011e95ce78b8 62 characteristics
ktownsend 29:011e95ce78b8 63
ktownsend 29:011e95ce78b8 64 @returns ble_error_t
ktownsend 29:011e95ce78b8 65
ktownsend 29:011e95ce78b8 66 @retval BLE_ERROR_NONE
ktownsend 29:011e95ce78b8 67 Everything executed properly
ktownsend 29:011e95ce78b8 68
ktownsend 29:011e95ce78b8 69 @section EXAMPLE
ktownsend 29:011e95ce78b8 70
ktownsend 29:011e95ce78b8 71 @code
ktownsend 29:011e95ce78b8 72
ktownsend 29:011e95ce78b8 73 @endcode
ktownsend 29:011e95ce78b8 74 */
ktownsend 29:011e95ce78b8 75 /**************************************************************************/
ktownsend 29:011e95ce78b8 76 ble_error_t nRF51822s::reset(void)
ktownsend 29:011e95ce78b8 77 {
ktownsend 29:011e95ce78b8 78 wait(0.5);
ktownsend 29:011e95ce78b8 79
ktownsend 29:011e95ce78b8 80 /* Command ID = 0x0005, No payload */
ktownsend 29:011e95ce78b8 81 uart.printf("10 05 00 00\r\n");
ktownsend 29:011e95ce78b8 82
ktownsend 29:011e95ce78b8 83 /* Reset the service and characteristic counters */
ktownsend 29:011e95ce78b8 84 //serviceCount = 0;
ktownsend 29:011e95ce78b8 85 //characteristicCount = 0;
ktownsend 29:011e95ce78b8 86
ktownsend 29:011e95ce78b8 87 /* Wait for the radio to come back up */
ktownsend 29:011e95ce78b8 88 wait(1);
ktownsend 29:011e95ce78b8 89
ktownsend 29:011e95ce78b8 90 return BLE_ERROR_NONE;
ktownsend 29:011e95ce78b8 91 }