mirror of https://github.com/ARMmbed/mbed-os.git
Merge remote-tracking branch 'upstream/master'
commit
35602c21be
11
README.md
11
README.md
|
|
@ -38,17 +38,24 @@ NXP:
|
|||
* [LPC1549](https://mbed.org/platforms/LPCXpresso1549/) (Cortex-M3)
|
||||
|
||||
Freescale:
|
||||
* FRDM-K20D50M
|
||||
* FRDM-K20D50M (Cortex-M4)
|
||||
* [FRDM-KL05Z](https://mbed.org/platforms/FRDM-KL05Z/) (Cortex-M0+)
|
||||
* [FRDM-KL25Z](http://mbed.org/platforms/KL25Z/) (Cortex-M0+)
|
||||
* [FRDM-KL46Z](https://mbed.org/platforms/FRDM-KL46Z/) (Cortex-M0+)
|
||||
* FRDM-K64F (Cortex-M4)
|
||||
|
||||
STMicroelectronics:
|
||||
* [Nucleo-F103RB](https://mbed.org/platforms/ST-Nucleo-F103RB/) (Cortex-M3)
|
||||
* [Nucleo-L152RE](https://mbed.org/platforms/ST-Nucleo-L152RE/) (Cortex-M3)
|
||||
* [Nucleo-F030R8](https://mbed.org/platforms/ST-Nucleo-F030R8/) (Cortex-M0)
|
||||
* [Nucleo-F401RE](https://mbed.org/platforms/ST-Nucleo-F401RE/) (Cortex-M4)
|
||||
* STM32F407 (Cortex-M4)
|
||||
* STM32F4XX (Cortex-M4F)
|
||||
* STM32F3XX (Cortex-M4F)
|
||||
* STM32F0-Discovery (Cortex-M0)
|
||||
* STM32VL-Discovery (Cortex-M3)
|
||||
* STM32F3-Discovery (Cortex-M4F)
|
||||
* STM32F4-Discovery (Cortex-M4F)
|
||||
|
||||
|
||||
Nordic:
|
||||
* [nRF51822-mKIT](https://mbed.org/platforms/Nordic-nRF51822/) (Cortex-M0)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ typedef enum {
|
|||
#include "USBEndpoints_LPC17_LPC23.h"
|
||||
#elif defined(TARGET_LPC11UXX) || defined(TARGET_LPC1347)
|
||||
#include "USBEndpoints_LPC11U.h"
|
||||
#elif defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M)
|
||||
#elif defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M) | defined(TARGET_K64F)
|
||||
#include "USBEndpoints_KL25Z.h"
|
||||
#elif defined (TARGET_STM32F4XX)
|
||||
#include "USBEndpoints_STM32F4.h"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#if defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M)
|
||||
#if defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M) | defined(TARGET_K64F)
|
||||
|
||||
#include "USBHAL.h"
|
||||
|
||||
|
|
@ -86,6 +86,9 @@ USBHAL::USBHAL(void) {
|
|||
// Disable IRQ
|
||||
NVIC_DisableIRQ(USB0_IRQn);
|
||||
|
||||
#if defined(TARGET_K64F)
|
||||
MPU->CESR=0;
|
||||
#endif
|
||||
// fill in callback array
|
||||
epCallback[0] = &USBHAL::EP1_OUT_callback;
|
||||
epCallback[1] = &USBHAL::EP1_IN_callback;
|
||||
|
|
@ -136,9 +139,9 @@ USBHAL::USBHAL(void) {
|
|||
while(USB0->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
|
||||
|
||||
// Set BDT Base Register
|
||||
USB0->BDTPAGE1=(uint8_t)((uint32_t)bdt>>8);
|
||||
USB0->BDTPAGE2=(uint8_t)((uint32_t)bdt>>16);
|
||||
USB0->BDTPAGE3=(uint8_t)((uint32_t)bdt>>24);
|
||||
USB0->BDTPAGE1 = (uint8_t)((uint32_t)bdt>>8);
|
||||
USB0->BDTPAGE2 = (uint8_t)((uint32_t)bdt>>16);
|
||||
USB0->BDTPAGE3 = (uint8_t)((uint32_t)bdt>>24);
|
||||
|
||||
// Clear interrupt flag
|
||||
USB0->ISTAT = 0xff;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@ bool USBHID::readNB(HID_REPORT *report)
|
|||
uint32_t bytesRead = 0;
|
||||
bool result;
|
||||
result = USBDevice::readEP_NB(EPINT_OUT, report->data, &bytesRead, MAX_HID_REPORT_SIZE);
|
||||
// if readEP_NB did not succeed, does not issue a readStart
|
||||
if (!result)
|
||||
return false;
|
||||
report->length = bytesRead;
|
||||
if(!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,15 @@ class Gap
|
|||
GapEvents *m_pEventHandler;
|
||||
|
||||
public:
|
||||
typedef enum addr_type_e{
|
||||
ADDR_TYPE_PUBLIC = 0,
|
||||
ADDR_TYPE_RANDOM_STATIC,
|
||||
ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE,
|
||||
ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE
|
||||
} addr_type_t;
|
||||
|
||||
/* These functions must be defined in the sub-class */
|
||||
virtual ble_error_t setAddress(addr_type_t type, uint8_t address[6]) = 0;
|
||||
virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &) = 0;
|
||||
virtual ble_error_t startAdvertising(GapAdvertisingParams &) = 0;
|
||||
virtual ble_error_t stopAdvertising(void) = 0;
|
||||
|
|
@ -38,7 +38,7 @@ class GattServer
|
|||
/* These functions must be defined in the sub-class */
|
||||
virtual ble_error_t addService(GattService &) = 0;
|
||||
virtual ble_error_t readValue(uint16_t, uint8_t[], uint16_t) = 0;
|
||||
virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t) = 0;
|
||||
virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false) = 0;
|
||||
|
||||
// ToDo: For updateValue, check the CCCD to see if the value we are
|
||||
// updating has the notify or indicate bits sent, and if BOTH are set
|
||||
|
|
@ -33,8 +33,8 @@
|
|||
#include "pstorage.h"
|
||||
|
||||
#include "hw/GapEvents.h"
|
||||
#include "hw/nRF51822n/nRF51Gap.h"
|
||||
#include "hw/nRF51822n/nRF51GattServer.h"
|
||||
#include "nRF51Gap.h"
|
||||
#include "nRF51GattServer.h"
|
||||
|
||||
static void service_error_callback(uint32_t nrf_error);
|
||||
void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name);
|
||||
|
|
@ -94,13 +94,13 @@ static void btle_handler(ble_evt_t * p_ble_evt)
|
|||
switch (p_ble_evt->header.evt_id)
|
||||
{
|
||||
case BLE_GAP_EVT_CONNECTED:
|
||||
nRF51GattServer::getInstance().m_connectionHandle = p_ble_evt->evt.gap_evt.conn_handle;
|
||||
nRF51Gap::getInstance().setConnectionHandle( p_ble_evt->evt.gap_evt.conn_handle );
|
||||
nRF51Gap::getInstance().handleEvent(GapEvents::GAP_EVENT_CONNECTED);
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
// Since we are not in a connection and have not started advertising, store bonds
|
||||
nRF51GattServer::getInstance().m_connectionHandle = BLE_CONN_HANDLE_INVALID;
|
||||
nRF51Gap::getInstance().setConnectionHandle (BLE_CONN_HANDLE_INVALID);
|
||||
ASSERT_STATUS_RET_VOID ( ble_bondmngr_bonded_centrals_store() );
|
||||
nRF51Gap::getInstance().handleEvent(GapEvents::GAP_EVENT_DISCONNECTED);
|
||||
break;
|
||||
|
|
@ -117,7 +117,7 @@ static void btle_handler(ble_evt_t * p_ble_evt)
|
|||
sec_params.min_key_size = CFG_BLE_SEC_PARAM_MIN_KEY_SIZE ;
|
||||
sec_params.max_key_size = CFG_BLE_SEC_PARAM_MAX_KEY_SIZE ;
|
||||
|
||||
ASSERT_STATUS_RET_VOID ( sd_ble_gap_sec_params_reply(nRF51GattServer::getInstance().m_connectionHandle, BLE_GAP_SEC_STATUS_SUCCESS, &sec_params) );
|
||||
ASSERT_STATUS_RET_VOID ( sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().getConnectionHandle(), BLE_GAP_SEC_STATUS_SUCCESS, &sec_params) );
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -25,8 +25,8 @@
|
|||
#include "mbed.h"
|
||||
#include "blecommon.h"
|
||||
#include "hw/BLEDevice.h"
|
||||
#include "hw/nRF51822n/nRF51Gap.h"
|
||||
#include "hw/nRF51822n/nRF51GattServer.h"
|
||||
#include "nRF51Gap.h"
|
||||
#include "nRF51GattServer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "common/common.h"
|
||||
#include "ble_advdata.h"
|
||||
#include "ble_hci.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
|
|
@ -162,7 +163,7 @@ ble_error_t nRF51Gap::startAdvertising(GapAdvertisingParams & params)
|
|||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
/* ToDo: Start Advertising */
|
||||
/* Start Advertising */
|
||||
ble_gap_adv_params_t adv_para = { 0 };
|
||||
|
||||
adv_para.type = params.getAdvertisingType() ;
|
||||
|
|
@ -174,7 +175,7 @@ ble_error_t nRF51Gap::startAdvertising(GapAdvertisingParams & params)
|
|||
|
||||
ASSERT( ERROR_NONE == sd_ble_gap_adv_start(&adv_para), BLE_ERROR_PARAM_OUT_OF_RANGE);
|
||||
|
||||
state.advertising = 1;
|
||||
state.advertising = 1;
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
|
@ -197,14 +198,12 @@ ble_error_t nRF51Gap::startAdvertising(GapAdvertisingParams & params)
|
|||
/**************************************************************************/
|
||||
ble_error_t nRF51Gap::stopAdvertising(void)
|
||||
{
|
||||
/* ToDo: Stop Advertising */
|
||||
/* Stop Advertising */
|
||||
ASSERT( ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
|
||||
|
||||
/* ToDo: Check response */
|
||||
wait(0.1);
|
||||
state.advertising = 0;
|
||||
|
||||
state.advertising = 0;
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
|
@ -225,10 +224,61 @@ ble_error_t nRF51Gap::stopAdvertising(void)
|
|||
/**************************************************************************/
|
||||
ble_error_t nRF51Gap::disconnect(void)
|
||||
{
|
||||
/* ToDo: Disconnect if we are connected to a central device */
|
||||
state.advertising = 0;
|
||||
state.connected = 0;
|
||||
|
||||
state.advertising = 0;
|
||||
state.connected = 0;
|
||||
/* Disconnect if we are connected to a central device */
|
||||
ASSERT_INT(ERROR_NONE, sd_ble_gap_disconnect(m_connectionHandle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION),
|
||||
BLE_ERROR_PARAM_OUT_OF_RANGE);
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets the 16-bit connection handle
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void nRF51Gap::setConnectionHandle(uint16_t con_handle)
|
||||
{
|
||||
m_connectionHandle = con_handle;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets the 16-bit connection handle
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint16_t nRF51Gap::getConnectionHandle(void)
|
||||
{
|
||||
return m_connectionHandle;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets the BLE device address
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
uint8_t device_address[6] = { 0xca, 0xfe, 0xf0, 0xf0, 0xf0, 0xf0 };
|
||||
nrf.getGap().setAddress(Gap::ADDR_TYPE_RANDOM_STATIC, device_address);
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51Gap::setAddress(addr_type_t type, uint8_t address[6])
|
||||
{
|
||||
if ( type > ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
|
||||
ble_gap_addr_t dev_addr;
|
||||
dev_addr.addr_type = type;
|
||||
memcpy(dev_addr.addr, address, 6);
|
||||
|
||||
ASSERT_INT(ERROR_NONE, sd_ble_gap_address_set(&dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE);
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "mbed.h"
|
||||
#include "blecommon.h"
|
||||
#include "ble.h"
|
||||
#include "GapAdvertisingParams.h"
|
||||
#include "GapAdvertisingData.h"
|
||||
#include "hw/Gap.h"
|
||||
|
|
@ -39,13 +40,18 @@ class nRF51Gap : public Gap
|
|||
}
|
||||
|
||||
/* Functions that must be implemented from Gap */
|
||||
virtual ble_error_t setAddress(addr_type_t type, uint8_t address[6]);
|
||||
virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &);
|
||||
virtual ble_error_t startAdvertising(GapAdvertisingParams &);
|
||||
virtual ble_error_t stopAdvertising(void);
|
||||
virtual ble_error_t disconnect(void);
|
||||
|
||||
void setConnectionHandle(uint16_t con_handle);
|
||||
uint16_t getConnectionHandle(void);
|
||||
|
||||
private:
|
||||
nRF51Gap() { };
|
||||
uint16_t m_connectionHandle;
|
||||
nRF51Gap() { m_connectionHandle = BLE_CONN_HANDLE_INVALID; };
|
||||
nRF51Gap(nRF51Gap const&);
|
||||
void operator=(nRF51Gap const&);
|
||||
};
|
||||
|
|
@ -20,6 +20,8 @@
|
|||
#include "common/common.h"
|
||||
#include "btle/custom/custom_helper.h"
|
||||
|
||||
#include "nRF51Gap.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Adds a new service to the GATT table on the peripheral
|
||||
|
|
@ -136,10 +138,18 @@ ble_error_t nRF51GattServer::readValue(uint16_t charHandle, uint8_t buffer[], ui
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len)
|
||||
ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len, bool localOnly)
|
||||
{
|
||||
uint16_t gapConnectionHandle = nRF51Gap::getInstance().getConnectionHandle();
|
||||
|
||||
if (localOnly)
|
||||
{
|
||||
/* Only update locally regardless of notify/indicate */
|
||||
ASSERT_INT( ERROR_NONE, sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer), BLE_ERROR_PARAM_OUT_OF_RANGE );
|
||||
}
|
||||
|
||||
if ((p_characteristics[charHandle]->properties & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) &&
|
||||
(m_connectionHandle != BLE_CONN_HANDLE_INVALID) )
|
||||
(gapConnectionHandle != BLE_CONN_HANDLE_INVALID) )
|
||||
{
|
||||
/* HVX update for the characteristic value */
|
||||
ble_gatts_hvx_params_t hvx_params;
|
||||
|
|
@ -150,7 +160,7 @@ ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[],
|
|||
hvx_params.p_data = buffer;
|
||||
hvx_params.p_len = &len;
|
||||
|
||||
error_t error = (error_t) sd_ble_gatts_hvx(m_connectionHandle, &hvx_params);
|
||||
error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &hvx_params);
|
||||
|
||||
/* ERROR_INVALID_STATE, ERROR_BUSY, ERROR_GATTS_SYS_ATTR_MISSING and ERROR_NO_TX_BUFFERS the ATT table has been updated. */
|
||||
if ( (error != ERROR_NONE ) && (error != ERROR_INVALID_STATE) &&
|
||||
|
|
@ -43,19 +43,17 @@ class nRF51GattServer : public GattServer
|
|||
/* Functions that must be implemented from GattServer */
|
||||
virtual ble_error_t addService(GattService &);
|
||||
virtual ble_error_t readValue(uint16_t, uint8_t[], uint16_t);
|
||||
virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t);
|
||||
virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false);
|
||||
|
||||
/* nRF51 Functions */
|
||||
void eventCallback(void);
|
||||
void hwCallback(ble_evt_t * p_ble_evt);
|
||||
|
||||
uint16_t m_connectionHandle; // TODO move to private
|
||||
|
||||
private:
|
||||
GattCharacteristic* p_characteristics[BLE_TOTAL_CHARACTERISTICS];
|
||||
ble_gatts_char_handles_t nrfCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS];
|
||||
|
||||
nRF51GattServer() { serviceCount = 0; characteristicCount = 0; m_connectionHandle = BLE_CONN_HANDLE_INVALID; };
|
||||
nRF51GattServer() { serviceCount = 0; characteristicCount = 0; };
|
||||
|
||||
nRF51GattServer(nRF51GattServer const&);
|
||||
void operator=(nRF51GattServer const&);
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _NORDIC_GLOBAL_H_
|
||||
#define _NORDIC_GLOBAL_H_
|
||||
|
||||
/* There are no global defines in mbed, so we need to define */
|
||||
/* mandatory conditional compilation flags here */
|
||||
#define NRF51
|
||||
#define DEBUG_NRF_USER
|
||||
#define BLE_STACK_SUPPORT_REQD
|
||||
#define BOARD_PCA10001
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue