Merge pull request #654 from adafruit/fix-cryptocell-high-power
Fix cryptocell high power
This commit is contained in:
23 files changed
+390
-162
No files matched your search
@@ -189,6 +189,12 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||
(void) __get_FPSCR();
|
||||
NVIC_ClearPendingIRQ(FPU_IRQn);
|
||||
#endif
|
||||
|
||||
#ifdef NRF_CRYPTOCELL
|
||||
// manually clear CryptoCell else it could prevent low power mode
|
||||
NVIC_ClearPendingIRQ(CRYPTOCELL_IRQn);
|
||||
#endif
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT // TODO
|
||||
uint8_t sd_en = 0;
|
||||
(void) sd_softdevice_is_enabled(&sd_en);
|
||||
|
||||
@@ -96,6 +96,11 @@ void waitForEvent(void)
|
||||
uint8_t sd_en = 0;
|
||||
(void) sd_softdevice_is_enabled(&sd_en);
|
||||
|
||||
#ifdef NRF_CRYPTOCELL
|
||||
// manually clear CryptoCell else it could prevent low power mode
|
||||
NVIC_ClearPendingIRQ(CRYPTOCELL_IRQn);
|
||||
#endif
|
||||
|
||||
if ( sd_en )
|
||||
{
|
||||
(void) sd_app_evt_wait();
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <string.h>
|
||||
#include "Adafruit_LittleFS.h"
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
|
||||
|
||||
Submodule libraries/Adafruit_nRFCrypto updated: 01de30c89b...3686f24136.
@@ -23,40 +23,37 @@
|
||||
* - https://www.bluetooth.com/blog/bluetooth-pairing-passkey-entry/
|
||||
* - https://www.bluetooth.com/blog/bluetooth-pairing-part-4/
|
||||
*
|
||||
* IF TFT enabled board such as CLUE is used, the passkey will also display on the
|
||||
* TFT. Following boards with TFT are supported
|
||||
* - Adafruit CLUE : https://www.adafruit.com/product/4500
|
||||
* - Circuit Playground Bluefruit: https://www.adafruit.com/product/4333
|
||||
* - TFT Gizmo : https://www.adafruit.com/product/4367
|
||||
* This example will "display" (print) passkey to Serial, and get digital input for yes/no
|
||||
* therefore the IO Capacities is set to Display = true, Yes/No = true, Keypad = false.
|
||||
*
|
||||
* Note For TFT enabled board such as CLUE, Circuit Play Bluefruit with Gizmo please use the `pairing_passkey_arcada` example.
|
||||
* Where the passkey is displayed on the TFT for better experience.
|
||||
*/
|
||||
|
||||
#if defined(ARDUINO_NRF52840_CIRCUITPLAY) || defined(ARDUINO_NRF52840_CLUE)
|
||||
#define USE_ARCADA
|
||||
#endif
|
||||
|
||||
#include <bluefruit.h>
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
#include <Adafruit_Arcada.h>
|
||||
|
||||
Adafruit_Arcada arcada;
|
||||
Adafruit_SPITFT* tft;
|
||||
#include <Adafruit_TinyUSB.h>
|
||||
|
||||
// Use built-in buttons if available, else use A0, A1
|
||||
#ifdef PIN_BUTTON1
|
||||
#define BUTTON_YES PIN_BUTTON1
|
||||
#else
|
||||
// Use built-in buttons if available, else use A0, A1
|
||||
#ifdef PIN_BUTTON1
|
||||
#define BUTTON_YES PIN_BUTTON1
|
||||
#else
|
||||
#define BUTTON_YES A0
|
||||
#endif
|
||||
#define BUTTON_YES A0
|
||||
#endif
|
||||
|
||||
#ifdef PIN_BUTTON2
|
||||
#define BUTTON_NO PIN_BUTTON2
|
||||
#else
|
||||
#define BUTTON_NO A1
|
||||
#endif
|
||||
#ifdef PIN_BUTTON2
|
||||
#define BUTTON_NO PIN_BUTTON2
|
||||
#else
|
||||
#define BUTTON_NO A1
|
||||
#endif
|
||||
|
||||
// Circuit Play Bluefruit has button active state = high
|
||||
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
|
||||
uint32_t const button_active_state = HIGH;
|
||||
#else
|
||||
uint32_t const button_active_state = LOW;
|
||||
#endif
|
||||
|
||||
// BLE Service
|
||||
@@ -69,19 +66,16 @@ void setup()
|
||||
Serial.println("Bluefruit52 Pairing Display Example");
|
||||
Serial.println("-----------------------------------\n");
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
arcada.arcadaBegin();
|
||||
arcada.displayBegin();
|
||||
arcada.setBacklight(255);
|
||||
|
||||
tft = arcada.display;
|
||||
tft->setCursor(0, 0);
|
||||
tft->setTextWrap(true);
|
||||
tft->setTextSize(2);
|
||||
#else
|
||||
pinMode(BUTTON_YES, INPUT_PULLUP);
|
||||
pinMode(BUTTON_NO, INPUT_PULLUP);
|
||||
#endif
|
||||
// pull high for active low, or pull low for active high
|
||||
if (button_active_state == HIGH)
|
||||
{
|
||||
pinMode(BUTTON_YES, INPUT_PULLDOWN);
|
||||
pinMode(BUTTON_NO, INPUT_PULLDOWN);
|
||||
}else
|
||||
{
|
||||
pinMode(BUTTON_YES, INPUT_PULLUP);
|
||||
pinMode(BUTTON_NO, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
// Setup the BLE LED to be enabled on CONNECT
|
||||
// Note: This is actually the default behavior, but provided
|
||||
@@ -125,14 +119,6 @@ void setup()
|
||||
bleuart.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM);
|
||||
bleuart.begin();
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
tft->fillScreen(ARCADA_BLACK);
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
tft->setTextSize(2);
|
||||
tft->setCursor(0, 0);
|
||||
tft->print("Advertising...");
|
||||
#endif
|
||||
|
||||
Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
|
||||
Serial.println("Your phone should pop-up PIN input");
|
||||
Serial.println("Once connected, enter character(s) that you wish to send");
|
||||
@@ -203,13 +189,6 @@ void connect_callback(uint16_t conn_handle)
|
||||
|
||||
Serial.print("Connected to ");
|
||||
Serial.println(central_name);
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
tft->fillScreen(ARCADA_BLACK);
|
||||
tft->setTextSize(2);
|
||||
tft->setCursor(0, 0);
|
||||
tft->println("Connected");
|
||||
#endif
|
||||
}
|
||||
|
||||
// callback invoked when pairing passkey is generated
|
||||
@@ -222,84 +201,48 @@ bool pairing_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bo
|
||||
Serial.println("Pairing Passkey");
|
||||
Serial.printf(" %.3s %.3s\n", passkey, passkey+3);
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
tft->fillScreen(ARCADA_BLACK);
|
||||
tft->println("Pairing Passkey\n");
|
||||
tft->setTextColor(ARCADA_YELLOW);
|
||||
tft->setTextSize(4);
|
||||
tft->printf(" %.3s %.3s\n", passkey, passkey+3);
|
||||
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
tft->setTextSize(2);
|
||||
#endif
|
||||
|
||||
// match_request means peer wait for our approval (return true)
|
||||
// match_request means peer wait for our approval
|
||||
// return true to accept, false to decline
|
||||
if (match_request)
|
||||
{
|
||||
bool accept_pairing = false;
|
||||
|
||||
Serial.println("Do you want to pair");
|
||||
Serial.println("Press Button Left to decline, Button Right to Accept");
|
||||
Serial.printf("Press button <%u> to Decline, button <%u> to Accept\n", BUTTON_YES, BUTTON_NO);
|
||||
|
||||
// timeout for pressing button
|
||||
uint32_t start_time = millis();
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
tft->println("\nDo you accept ?\n\n");
|
||||
tft->setTextSize(3);
|
||||
|
||||
// Yes <-> No on CPB is reversed since GIZMO TFT is on the back of CPB
|
||||
#if ARDUINO_NRF52840_CIRCUITPLAY
|
||||
tft->setTextColor(ARCADA_GREEN);
|
||||
tft->print("< Yes");
|
||||
tft->setTextColor(ARCADA_RED);
|
||||
tft->println(" No >");
|
||||
#else
|
||||
tft->setTextColor(ARCADA_RED);
|
||||
tft->print("< No");
|
||||
tft->setTextColor(ARCADA_GREEN);
|
||||
tft->println(" Yes >");
|
||||
#endif
|
||||
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
tft->setTextSize(2);
|
||||
tft->println();
|
||||
|
||||
// wait until either button is pressed (30 seconds timeout)
|
||||
uint32_t justReleased;
|
||||
do
|
||||
while( millis() < start_time + 30000 )
|
||||
{
|
||||
// user press YES
|
||||
if (digitalRead(BUTTON_YES) == button_active_state)
|
||||
{
|
||||
accept_pairing = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// user press NO
|
||||
if (digitalRead(BUTTON_NO) == button_active_state)
|
||||
{
|
||||
accept_pairing = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Peer is disconnected while waiting for input
|
||||
if ( !Bluefruit.connected(conn_handle) ) break;
|
||||
|
||||
// time out
|
||||
if ( millis() > start_time + 30000 ) break;
|
||||
|
||||
arcada.readButtons();
|
||||
justReleased = arcada.justReleasedButtons();
|
||||
} while ( !(justReleased & (ARCADA_BUTTONMASK_LEFT | ARCADA_BUTTONMASK_RIGHT) ) );
|
||||
|
||||
// Right = accept
|
||||
if (justReleased & ARCADA_BUTTONMASK_RIGHT) return true;
|
||||
|
||||
// Left = decline
|
||||
if (justReleased & ARCADA_BUTTONMASK_LEFT) return false;
|
||||
|
||||
#else
|
||||
// wait until either button is pressed (30 seconds timeout)
|
||||
while( digitalRead(BUTTON_YES) && digitalRead(BUTTON_NO) )
|
||||
{
|
||||
// Peer is disconnected while waiting for input
|
||||
if ( !Bluefruit.connected(conn_handle) ) break;
|
||||
|
||||
// time out
|
||||
if ( millis() > start_time + 30000 ) break;
|
||||
}
|
||||
|
||||
if ( 0 == digitalRead(BUTTON_YES) ) return true;
|
||||
if (accept_pairing)
|
||||
{
|
||||
Serial.println("Accepted");
|
||||
}else
|
||||
{
|
||||
Serial.println("Declined");
|
||||
}
|
||||
|
||||
if ( 0 == digitalRead(BUTTON_NO) ) return false;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
return accept_pairing;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -314,32 +257,11 @@ void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status)
|
||||
{
|
||||
Serial.println("Failed");
|
||||
}
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS)
|
||||
{
|
||||
tft->setTextColor(ARCADA_GREEN);
|
||||
tft->println("Succeeded");
|
||||
}else
|
||||
{
|
||||
tft->setTextColor(ARCADA_RED);
|
||||
tft->println("Failed");
|
||||
}
|
||||
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
tft->setTextSize(2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void connection_secured_callback(uint16_t conn_handle)
|
||||
{
|
||||
Serial.println("Secured");
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
tft->setTextColor(ARCADA_YELLOW);
|
||||
tft->println("secured");
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,11 +276,4 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
|
||||
|
||||
Serial.println();
|
||||
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
|
||||
|
||||
#ifdef USE_ARCADA
|
||||
tft->fillScreen(ARCADA_BLACK);
|
||||
tft->setTextSize(2);
|
||||
tft->setCursor(0, 0);
|
||||
tft->println("Advertising ...");
|
||||
#endif
|
||||
}
|
||||
Whitespace-only changes.
Whitespace-only changes.
+296
@@ -0,0 +1,296 @@
|
||||
/*********************************************************************
|
||||
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 demonstrates Pairing process using dynamic Passkey.
|
||||
* This sketch is essentially the same as bleuart.ino except the BLE Uart
|
||||
* service requires Security Mode with Man-In-The-Middle protection i.e
|
||||
*
|
||||
* BLE Pairing procedure is complicated, it is advisable for users to go through
|
||||
* these articles to get familiar with the procedure and terminology
|
||||
* - https://www.bluetooth.com/blog/bluetooth-pairing-part-1-pairing-feature-exchange/
|
||||
* - https://www.bluetooth.com/blog/bluetooth-pairing-part-2-key-generation-methods/
|
||||
* - https://www.bluetooth.com/blog/bluetooth-pairing-passkey-entry/
|
||||
* - https://www.bluetooth.com/blog/bluetooth-pairing-part-4/
|
||||
*
|
||||
* This example will display Passkey on the TFT and wait for user input to accept or decline
|
||||
* the pairing. Therefore the IO Capacities is set to Display = true, Yes/No = true, Keypad = false.
|
||||
*
|
||||
* Following boards with TFT are supported
|
||||
* - Adafruit CLUE : https://www.adafruit.com/product/4500
|
||||
* - Circuit Playground Bluefruit: https://www.adafruit.com/product/4333
|
||||
* - TFT Gizmo : https://www.adafruit.com/product/4367
|
||||
*
|
||||
* Note: If your board does not have TFT, please use the 'pairing_passkey' where it uses Serial
|
||||
* to display the passkey
|
||||
*/
|
||||
|
||||
#include <bluefruit.h>
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
|
||||
#include <Adafruit_TinyUSB.h>
|
||||
#include <Adafruit_Arcada.h>
|
||||
|
||||
Adafruit_Arcada arcada;
|
||||
Adafruit_SPITFT* tft;
|
||||
|
||||
// BLE Service
|
||||
BLEUart bleuart; // uart over ble
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Bluefruit52 Pairing Display Example");
|
||||
Serial.println("-----------------------------------\n");
|
||||
|
||||
arcada.arcadaBegin();
|
||||
arcada.displayBegin();
|
||||
arcada.setBacklight(255);
|
||||
|
||||
tft = arcada.display;
|
||||
tft->setCursor(0, 0);
|
||||
tft->setTextWrap(true);
|
||||
tft->setTextSize(2);
|
||||
|
||||
// Setup the BLE LED to be enabled on CONNECT
|
||||
// Note: This is actually the default behavior, but provided
|
||||
// here in case you want to control this LED manually via PIN 19
|
||||
Bluefruit.autoConnLed(true);
|
||||
|
||||
// Config the peripheral connection with maximum bandwidth
|
||||
// more SRAM required by SoftDevice
|
||||
// Note: All config***() function must be called before begin()
|
||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||
|
||||
Bluefruit.begin();
|
||||
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
|
||||
|
||||
/* To use dynamic PassKey for pairing, we need to have
|
||||
* - IO capacities at least DISPPLAY
|
||||
* - Display only: user have to enter 6-digit passkey on their phone
|
||||
* - DIsplay + Yes/No: user ony need to press Accept on both central and device
|
||||
* - Register callback to display/print dynamic passkey for central
|
||||
*
|
||||
* For complete mapping of the IO Capabilities to Key Generation Method, check out this article
|
||||
* https://www.bluetooth.com/blog/bluetooth-pairing-part-2-key-generation-methods/
|
||||
*/
|
||||
Bluefruit.Security.setIOCaps(true, true, false); // display = true, yes/no = true, keyboard = false
|
||||
Bluefruit.Security.setPairPasskeyCallback(pairing_passkey_callback);
|
||||
|
||||
// Set complete callback to print the pairing result
|
||||
Bluefruit.Security.setPairCompleteCallback(pairing_complete_callback);
|
||||
|
||||
// Set connection secured callback, invoked when connection is encrypted
|
||||
Bluefruit.Security.setSecuredCallback(connection_secured_callback);
|
||||
|
||||
Bluefruit.Periph.setConnectCallback(connect_callback);
|
||||
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
|
||||
|
||||
// Configure and Start BLE Uart Service
|
||||
// Set Permission to access BLE Uart is to require man-in-the-middle protection
|
||||
// This will cause central to perform pairing with a generated passkey, the passkey will
|
||||
// be printed on display or Serial and wait for our input
|
||||
Serial.println("Configure BLE Uart to require man-in-the-middle protection for PIN pairing");
|
||||
bleuart.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM);
|
||||
bleuart.begin();
|
||||
|
||||
tft->fillScreen(ARCADA_BLACK);
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
tft->setTextSize(2);
|
||||
tft->setCursor(0, 0);
|
||||
tft->print("Advertising...");
|
||||
|
||||
Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
|
||||
Serial.println("Your phone should pop-up PIN input");
|
||||
Serial.println("Once connected, enter character(s) that you wish to send");
|
||||
|
||||
// Set up and start advertising
|
||||
startAdv();
|
||||
}
|
||||
|
||||
void startAdv(void)
|
||||
{
|
||||
// Advertising packet
|
||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
Bluefruit.Advertising.addTxPower();
|
||||
|
||||
// Include bleuart 128-bit uuid
|
||||
Bluefruit.Advertising.addService(bleuart);
|
||||
|
||||
// Secondary Scan Response packet (optional)
|
||||
// Since there is no room for 'Name' in Advertising packet
|
||||
Bluefruit.ScanResponse.addName();
|
||||
|
||||
/* Start Advertising
|
||||
* - Enable auto advertising if disconnected
|
||||
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
|
||||
* - Timeout for fast mode is 30 seconds
|
||||
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
|
||||
*
|
||||
* For recommended advertising interval
|
||||
* https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||
*/
|
||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
||||
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
||||
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Forward data from HW Serial to BLEUART
|
||||
while (Serial.available())
|
||||
{
|
||||
// Delay to wait for enough input, since we have a limited transmission buffer
|
||||
delay(2);
|
||||
|
||||
uint8_t buf[64];
|
||||
int count = Serial.readBytes(buf, sizeof(buf));
|
||||
bleuart.write( buf, count );
|
||||
}
|
||||
|
||||
// Forward from BLEUART to HW Serial
|
||||
while ( bleuart.available() )
|
||||
{
|
||||
uint8_t ch;
|
||||
ch = (uint8_t) bleuart.read();
|
||||
Serial.write(ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// callback invoked when central connects
|
||||
void connect_callback(uint16_t conn_handle)
|
||||
{
|
||||
// Get the reference to current connection
|
||||
BLEConnection* connection = Bluefruit.Connection(conn_handle);
|
||||
|
||||
char central_name[32] = { 0 };
|
||||
connection->getPeerName(central_name, sizeof(central_name));
|
||||
|
||||
tft->fillScreen(ARCADA_BLACK);
|
||||
tft->setTextSize(2);
|
||||
tft->setCursor(0, 0);
|
||||
tft->println("Connected");
|
||||
}
|
||||
|
||||
// callback invoked when pairing passkey is generated
|
||||
// - passkey: 6 keys (without null terminator) for displaying
|
||||
// - match_request: true when authentication method is Numberic Comparison.
|
||||
// Then this callback's return value is used to accept (true) or
|
||||
// reject (false) the pairing process. Otherwise, return value has no effect
|
||||
bool pairing_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool match_request)
|
||||
{
|
||||
tft->fillScreen(ARCADA_BLACK);
|
||||
tft->println("Pairing Passkey\n");
|
||||
tft->setTextColor(ARCADA_YELLOW);
|
||||
tft->setTextSize(4);
|
||||
tft->printf(" %.3s %.3s\n", passkey, passkey+3);
|
||||
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
tft->setTextSize(2);
|
||||
|
||||
// match_request means peer wait for our approval (return true)
|
||||
if (match_request)
|
||||
{
|
||||
// timeout for pressing button
|
||||
uint32_t start_time = millis();
|
||||
|
||||
tft->println("\nDo you accept ?\n\n");
|
||||
tft->setTextSize(3);
|
||||
|
||||
// Yes <-> No on CPB is reversed since GIZMO TFT is on the back of CPB
|
||||
#if ARDUINO_NRF52840_CIRCUITPLAY
|
||||
tft->setTextColor(ARCADA_GREEN);
|
||||
tft->print("< Yes");
|
||||
tft->setTextColor(ARCADA_RED);
|
||||
tft->println(" No >");
|
||||
#else
|
||||
tft->setTextColor(ARCADA_RED);
|
||||
tft->print("< No");
|
||||
tft->setTextColor(ARCADA_GREEN);
|
||||
tft->println(" Yes >");
|
||||
#endif
|
||||
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
tft->setTextSize(2);
|
||||
tft->println();
|
||||
|
||||
// wait until either button is pressed (30 seconds timeout)
|
||||
uint32_t justReleased;
|
||||
while( millis() < start_time + 30000 )
|
||||
{
|
||||
// Peer is disconnected while waiting for input
|
||||
if ( !Bluefruit.connected(conn_handle) ) break;
|
||||
|
||||
arcada.readButtons();
|
||||
justReleased = arcada.justReleasedButtons();
|
||||
|
||||
// user press either button
|
||||
if (justReleased) break;
|
||||
}
|
||||
|
||||
// Right = accept
|
||||
if (justReleased & ARCADA_BUTTONMASK_RIGHT) return true;
|
||||
|
||||
// Left = decline
|
||||
if (justReleased & ARCADA_BUTTONMASK_LEFT) return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status)
|
||||
{
|
||||
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS)
|
||||
{
|
||||
tft->setTextColor(ARCADA_GREEN);
|
||||
tft->println("Succeeded");
|
||||
}else
|
||||
{
|
||||
tft->setTextColor(ARCADA_RED);
|
||||
tft->println("Failed");
|
||||
}
|
||||
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
tft->setTextSize(2);
|
||||
}
|
||||
|
||||
void connection_secured_callback(uint16_t conn_handle)
|
||||
{
|
||||
tft->setTextColor(ARCADA_YELLOW);
|
||||
tft->println("secured");
|
||||
tft->setTextColor(ARCADA_WHITE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback invoked when a connection is dropped
|
||||
* @param conn_handle connection where this event happens
|
||||
* @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;
|
||||
|
||||
Serial.println();
|
||||
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
|
||||
|
||||
tft->fillScreen(ARCADA_BLACK);
|
||||
tft->setTextSize(2);
|
||||
tft->setCursor(0, 0);
|
||||
tft->println("Advertising ...");
|
||||
}
|
||||
@@ -1051,7 +1051,7 @@ void AdafruitBluefruit::printInfo(void)
|
||||
|
||||
Periph.printInfo();
|
||||
|
||||
/*------------- List the paried device -------------*/
|
||||
/*------------- List the paired devices -------------*/
|
||||
if ( _prph_count )
|
||||
{
|
||||
logger.printf(title_fmt, "Peripheral Paired Devices");
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "bluefruit_common.h"
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
#define CFG_ADV_BLINKY_INTERVAL 500
|
||||
|
||||
@@ -180,7 +179,7 @@ class AdafruitBluefruit
|
||||
*------------------------------------------------------------------*/
|
||||
void setMultiprotocolSemaphore(SemaphoreHandle_t mprot_event_semaphore)
|
||||
{
|
||||
_mprot_event_sem= mprot_event_semaphore;
|
||||
_mprot_event_sem= mprot_event_semaphore;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ BLEHidAdafruit::BLEHidAdafruit(void)
|
||||
|
||||
err_t BLEHidAdafruit::begin(void)
|
||||
{
|
||||
uint16_t input_len [] = { sizeof(hid_keyboard_report_t), sizeof(hid_consumer_control_report_t), sizeof(hid_mouse_report_t) };
|
||||
// keyboard, consumer, mouse
|
||||
uint16_t input_len [] = { sizeof(hid_keyboard_report_t), 2, sizeof(hid_mouse_report_t) };
|
||||
uint16_t output_len[] = { 1 };
|
||||
|
||||
setReportLen(input_len, output_len, NULL);
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include "BLEHidGeneric.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
|
||||
class BLEHidAdafruit : public BLEHidGeneric
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -41,18 +41,13 @@
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
// include usb hid definitions
|
||||
// include for usb hid definitions
|
||||
#include <Adafruit_TinyUSB.h>
|
||||
#include "class/hid/hid.h"
|
||||
|
||||
extern const uint8_t hid_ascii_to_keycode[128][2];
|
||||
extern const uint8_t hid_keycode_to_ascii[128][2];
|
||||
|
||||
/// HID Consumer Control Report
|
||||
typedef struct ATTR_PACKED
|
||||
{
|
||||
uint16_t usage_value; ///< Usage value of the pressed control
|
||||
} hid_consumer_control_report_t;
|
||||
|
||||
class BLEHidGeneric : public BLEService
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "PDM.h"
|
||||
#include <hal/nrf_pdm.h>
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
#define DEFAULT_PDM_GAIN 20
|
||||
#define PDM_IRQ_PRIORITY 7
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "RotaryEncoder.h"
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
class HwRotaryEncoder RotaryEncoder;
|
||||
|
||||
extern "C"
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <wiring_private.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
SPIClass::SPIClass(NRF_SPIM_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI)
|
||||
{
|
||||
initialized = false;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define _SPI_H_INCLUDED
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
#include "nrfx_spim.h"
|
||||
|
||||
// SPI_HAS_TRANSACTION means SPI has
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <wiring_private.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
const SPISettings DEFAULT_SPI_SETTINGS = SPISettings();
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <Arduino.h>
|
||||
#include <Servo.h>
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
enum
|
||||
{
|
||||
SERVO_TOKEN = 0x76726553 // 'S' 'e' 'r' 'v'
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <variant.h>
|
||||
#include <WInterrupts.h>
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
SoftwareSerial *SoftwareSerial::active_object = 0;
|
||||
char SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
|
||||
volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0;
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#include "variant.h"
|
||||
#include "RingBuffer.h"
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
// WIRE_HAS_END means Wire has end()
|
||||
#define WIRE_HAS_END 1
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ extern "C" {
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
#include <Adafruit_TinyUSB.h> // for Serial
|
||||
|
||||
static volatile uint32_t* pincfg_reg(uint32_t pin)
|
||||
{
|
||||
NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&pin);
|
||||
|
||||
@@ -59,7 +59,7 @@ extern "C"
|
||||
/*
|
||||
* Buttons
|
||||
*/
|
||||
#define PIN_BUTTON1 (7)
|
||||
#define PIN_BUTTON1 (7)
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
|
||||
Reference in new issue
Block a user