Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: microbit_rubber_ducky microbit_mouse_BLE microbit_mouse_BLE_daybreak_version microbit_presenter
Fork of nRF51822 by
Diff: nRF51822n.cpp
- Revision:
- 370:295f76db798e
- Parent:
- 362:6fa0d4d555f6
- Child:
- 371:8f7d2137727a
--- a/nRF51822n.cpp Thu Jul 02 09:08:45 2015 +0100
+++ b/nRF51822n.cpp Mon Jul 06 10:13:26 2015 +0100
@@ -24,7 +24,7 @@
#include "softdevice_handler.h"
/**
- * The singleton which represents the nRF51822 transport for the BLE.
+ * The singleton which represents the nRF51822 transport for the BLEDevice.
*/
static nRF51822n deviceInstance;
@@ -32,8 +32,8 @@
* BLE-API requires an implementation of the following function in order to
* obtain its transport handle.
*/
-BLEInstanceBase *
-createBLEInstance(void)
+BLEDeviceInstanceBase *
+createBLEDeviceInstance(void)
{
return (&deviceInstance);
}
@@ -71,11 +71,40 @@
return versionString;
}
+/* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */
+ble_error_t nRF51822n::setTxPower(int8_t txPower)
+{
+ unsigned rc;
+ if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) {
+ switch (rc) {
+ case NRF_ERROR_BUSY:
+ return BLE_STACK_BUSY;
+ case NRF_ERROR_INVALID_PARAM:
+ default:
+ return BLE_ERROR_PARAM_OUT_OF_RANGE;
+ }
+ }
+
+ return BLE_ERROR_NONE;
+}
+
+void nRF51822n::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
+{
+ static const int8_t permittedTxValues[] = {
+ -40, -30, -20, -16, -12, -8, -4, 0, 4
+ };
+
+ *valueArrayPP = permittedTxValues;
+ *countP = sizeof(permittedTxValues) / sizeof(int8_t);
+}
+
ble_error_t nRF51822n::init(void)
{
/* ToDo: Clear memory contents, reset the SD, etc. */
btle_init();
+ reset();
+
return BLE_ERROR_NONE;
}
@@ -84,6 +113,16 @@
return (softdevice_handler_sd_disable() == NRF_SUCCESS) ? BLE_ERROR_NONE : BLE_STACK_BUSY;
}
+ble_error_t nRF51822n::reset(void)
+{
+ nrf_delay_us(500000);
+
+ /* Wait for the radio to come back up */
+ nrf_delay_us(1000000);
+
+ return BLE_ERROR_NONE;
+}
+
void
nRF51822n::waitForEvent(void)
{
