upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Libraries | Files | Functions

NRF8001 Bluetooth Low Energy library. More...

Libraries

 aci-library
 ACI library.
 

Files

file  boards.h
 Defines for the different Bluetooth low energy boards.
 
file  hal_aci_tl.h
 Interface for hal_aci_tl.
 
file  hal_platform.h
 HAL specific macros.
 
file  uart_over_ble.h
 BLE specific macros.
 

Functions

void init_local_interfaces (aci_state_t *aci, uint8_t reqn, uint8_t rdyn, uint8_t rst)
 NRF8001 Bluetooth Low Energy library. More...
 

Detailed Description

Function Documentation

void init_local_interfaces ( aci_state_t *  aci,
uint8_t  reqn,
uint8_t  rdyn,
uint8_t  rst 
)

These files define the NRF8001 interface for lib-nrf8001. Interaction with this device is done through the ACI routines included with the library. You can use the nRF UART app in Apple* App Store and Google* Play* on Samsung* Galaxy S*4 running Android* 4.3 to interact with a microcontroller running the 'hello world' example.

nrf8001.jpg
init_aci_setup ();
init_local_interfaces (&aci_state, 10, 8, 4);
while (1) {
static bool setup_required = false;
// We enter the if statement only when there is a ACI event available to be processed
if (lib_aci_event_get(&aci_state, &aci_data)) {
aci_evt_t * aci_evt;
aci_evt = &aci_data.evt;
switch(aci_evt->evt_opcode) {
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
switch(aci_evt->params.device_started.device_mode) {
case ACI_DEVICE_SETUP:
printf ("Evt Device Started: Setup \n");
setup_required = true;
break;
case ACI_DEVICE_STANDBY:
printf ("Evt Device Started: Standby \n");
// Looking for an iPhone by sending radio advertisements
// When an iPhone connects to us we will get an ACI_EVT_CONNECTED event from the nRF8001
if (aci_evt->params.device_started.hw_error) {
usleep (20000); //Handle the HW error event correctly.
} else {
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
printf ("Advertising started \n");
}
break;
}
}
break; // ACI Device Started Event
//If an ACI command response event comes with an error -> stop
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
//ACI ReadDynamicData and ACI WriteDynamicData will have status codes of
//TRANSACTION_CONTINUE and TRANSACTION_COMPLETE
//all other ACI commands will have status code of ACI_STATUS_SCUCCESS for a successful command
printf ("ACI_EVT_CMD_RSP \n");
}
if (ACI_CMD_GET_DEVICE_VERSION == aci_evt->params.cmd_rsp.cmd_opcode) {
//Store the version and configuration information of the nRF8001 in the Hardware Revision String Characteristic
lib_aci_set_local_data(&aci_state, PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET,
(uint8_t *)&(aci_evt->params.cmd_rsp.params.get_device_version), sizeof(aci_evt_cmd_rsp_params_get_device_version_t));
}
break;
printf ("ACI_EVT_CONNECTED");
uart_over_ble_init ();
timing_change_done = false;
aci_state.data_credit_available = aci_state.data_credit_total;
/*
Get the device version of the nRF8001 and store it in the Hardware Revision String
*/
break;
printf ("ACI_EVT_PIPE_STATUS \n");
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) && (false == timing_change_done)) {
lib_aci_change_timing_GAP_PPCP(); // change the timing on the link as specified in the nRFgo studio -> nRF8001 conf. -> GAP.
// Used to increase or decrease bandwidth
timing_change_done = true;
char hello[]="Hello World, works";
uart_tx((uint8_t *)&hello[0], strlen(hello));
}
break;
printf ("Evt link connection interval changed \n");
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET,
(uint8_t *)&(aci_evt->params.timing.conn_rf_interval), /* Byte aligned */
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE);
break;
printf ("ACI_EVT_DISCONNECTED \n");
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
printf ("Advertising started \n");
break;
if (PIPE_UART_OVER_BTLE_UART_RX_RX == aci_evt->params.data_received.rx_data.pipe_number) {
for(int i=0; i<aci_evt->len - 2; i++) {
uart_buffer[i] = aci_evt->params.data_received.rx_data.aci_data[i];
}
uart_buffer_len = aci_evt->len - 2;
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX)) {
}
}
if (PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX == aci_evt->params.data_received.rx_data.pipe_number) {
//Subtract for Opcode and Pipe number
uart_process_control_point_rx(&aci_evt->params.data_received.rx_data.aci_data[0], aci_evt->len - 2);
}
printf ("Incomming data - %s\n", uart_buffer);
break;
printf ("ACI_EVT_DATA_CREDIT \n");
aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit;
break;
printf ("ACI_EVT_PIPE_ERROR \n");
//Increment the credit available as the data packet was not sent.
//The pipe error also represents the Attribute protocol Error Response sent from the peer and that should not be counted
//for the credit.
if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code) {
aci_state.data_credit_available++;
}
break;
printf ("ACI_EVT_HW_ERROR \n");
lib_aci_connect(0/* in seconds, 0 means forever */, 0x0050 /* advertising interval 50ms*/);
printf ("Advertising started \n");
break;
}
}
/* setup_required is set to true when the device starts up and enters setup mode.
* It indicates that do_aci_setup() should be called. The flag should be cleared if
* do_aci_setup() returns ACI_STATUS_TRANSACTION_COMPLETE.
*/
if(setup_required) {
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
setup_required = false;
}
}
usleep (100);
}
close_local_interfaces (&aci_state);
init_aci_setup ();
init_local_interfaces (&aci_state, 10, 8, 4);
while (1) {
static bool setup_required = false;
if (lib_aci_event_get (&aci_state, &aci_data)) {
aci_evt_t * aci_evt;
aci_evt = &aci_data.evt;
switch(aci_evt->evt_opcode) {
aci_state.data_credit_available = aci_evt->params.device_started.credit_available;
switch(aci_evt->params.device_started.device_mode) {
case ACI_DEVICE_SETUP:
printf ("Evt Device Started: Setup\n");
setup_required = true;
break;
case ACI_DEVICE_STANDBY:
printf ("Evt Device Started: Standby\n");
lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */);
printf ("Broadcasting started\n");
break;
}
}
break; //ACI Device Started Event
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
printf ("ACI_EVT_CMD_RSP\n");
while (1);
}
break;
printf ("ACI_EVT_CONNECTED\n");
break;
printf ("ACI_EVT_PIPE_STATUS\n");
break;
if (ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status) {
printf ("Broadcasting timed out\n");
} else {
printf ("Evt Disconnected. Link Loss\n");
}
break;
printf ("ACI_EVT_DATA_RECEIVED\n");
break;
printf ("ACI_EVT_HW_ERROR\n");
break;
}
}
if (setup_required) {
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
setup_required = false;
}
}
usleep (100);
}
close_local_interfaces (&aci_state);

Include the services_lock.h to put the setup in the OTP memory of the nRF8001. This would mean that the setup cannot be changed once put in. However this removes the need to do the setup of the nRF8001 on every reset.

Tell the ACI library, the MCU to nRF8001 pin connections. The Active pin is optional and can be marked UNUSED

Here is the call graph for this function:

Collaboration diagram for libupm-nrf8001: