Skip to content

Commit

Permalink
Merge pull request #324 from adafruit/develop
Browse files Browse the repository at this point in the history
Maximize throughput
  • Loading branch information
ladyada authored Aug 16, 2019
2 parents 64b5555 + e23c63f commit 6c23375
Show file tree
Hide file tree
Showing 27 changed files with 719 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:
- BSP_VERSION=`eval ls $BSP_PATH`
- rm -r $BSP_PATH/*
- ln -s $TRAVIS_BUILD_DIR $BSP_PATH/$BSP_VERSION
- arduino --install-library "Adafruit NeoPixel","Adafruit NeoMatrix","Adafruit GFX Library","Adafruit SSD1306","MIDI Library",
- arduino --install-library "Adafruit NeoPixel","Adafruit NeoMatrix","Adafruit GFX Library","Adafruit SSD1306","MIDI Library","Adafruit ILI9341"

before_script:

Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void Adafruit_USBD_CDC::flush(void)

size_t Adafruit_USBD_CDC::write(uint8_t ch)
{
return tud_cdc_write_char((char) ch);
return write(&ch, 1);
}

size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) conn_handle;
(void) reason;

Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) conn_handle;
(void) reason;

Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) conn_handle;
(void) reason;

Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}

void loop()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/

/*
* This sketch demonstrate the central API(). A additional bluefruit
* that has bleuart as peripheral is required for the demo.
*/
#include <bluefruit.h>

BLEClientUart clientUart; // bleuart client

uint32_t rx_count = 0;

void setup()
{
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb

Serial.println("Bluefruit52 Central BLEUART Example");
Serial.println("-----------------------------------\n");

// Config the connection with maximum bandwidth
// more SRAM required by SoftDevice
// Note: All config***() function must be called before begin()
Bluefruit.configCentralBandwidth(BANDWIDTH_MAX);

// Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1
// SRAM usage required by SoftDevice will increase dramatically with number of connections
Bluefruit.begin(0, 1);

Bluefruit.setName("Bluefruit52 Central");

// Init BLE Central Uart Serivce
clientUart.begin();
clientUart.setRxCallback(bleuart_rx_callback);

// Increase Blink rate to different from PrPh advertising mode
Bluefruit.setConnLedInterval(250);

// Callbacks for Central
Bluefruit.Central.setConnectCallback(connect_callback);
Bluefruit.Central.setDisconnectCallback(disconnect_callback);

/* Start Central Scanning
* - Enable auto scan if disconnected
* - Interval = 100 ms, window = 80 ms
* - Don't use active scan
* - Start(timeout) with timeout = 0 will scan forever (until connected)
*/
Bluefruit.Scanner.setRxCallback(scan_callback);
Bluefruit.Scanner.restartOnDisconnect(true);
Bluefruit.Scanner.setInterval(160, 80); // in unit of 0.625 ms
Bluefruit.Scanner.useActiveScan(false);
Bluefruit.Scanner.start(0); // // 0 = Don't stop scanning after n seconds
}

/**
* Callback invoked when scanner pick up an advertising data
* @param report Structural advertising data
*/
void scan_callback(ble_gap_evt_adv_report_t* report)
{
// Check if advertising contain BleUart service
if ( Bluefruit.Scanner.checkReportForService(report, clientUart) )
{
Serial.print("BLE UART service detected. Connecting ... ");

// Connect to device with bleuart service in advertising
Bluefruit.Central.connect(report);
}else
{
// For Softdevice v6: after received a report, scanner will be paused
// We need to call Scanner resume() to continue scanning
Bluefruit.Scanner.resume();
}
}

/**
* Callback invoked when an connection is established
* @param conn_handle
*/
void connect_callback(uint16_t conn_handle)
{
Serial.println("Connected");

Serial.print("Discovering BLE Uart Service ... ");
if ( clientUart.discover(conn_handle) )
{
Serial.println("Found it");

Serial.println("Enable TXD's notify");
clientUart.enableTXD();

Serial.println("Ready to receive from peripheral");
}else
{
Serial.println("Found NONE");

// disconnect since we couldn't find bleuart service
Bluefruit.disconnect(conn_handle);
}
}

/**
* Callback invoked when a connection is dropped
* @param conn_handle
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
*/
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
(void) conn_handle;
(void) reason;

Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}

/**
* Callback invoked when uart received data
* @param uart_svc Reference object to the service where the data
* arrived. In this example it is clientUart
*/
void bleuart_rx_callback(BLEClientUart& uart_svc)
{
int count = uart_svc.available();
uart_svc.flush();
}

void loop()
{
if ( Bluefruit.Central.connected() )
{
// Not discovered yet
if ( clientUart.discovered() )
{
// Discovered means in working state
// Get Serial input and send to Peripheral
if ( Serial.available() )
{
delay(2); // delay a bit for all characters to arrive

char str[20+1] = { 0 };
Serial.readBytes(str, 20);

clientUart.print( str );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) conn_handle;
(void) reason;

Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}

/**
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion libraries/Bluefruit52Lib/examples/Peripheral/ancs/ancs.ino
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) reason;

Serial.println();
Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) reason;

Serial.println();
Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) reason;

Serial.println();
Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);

connection_count--;
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,5 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) reason;

Serial.println();
Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) conn_handle;
(void) reason;

Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
Serial.println("Advertising!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) conn_handle;
(void) reason;

Serial.println("Disconnected");
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
Serial.println("Advertising!");
}

Expand Down
Loading

0 comments on commit 6c23375

Please sign in to comment.