Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions cores/nRF5/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions libraries/Adafruit_LittleFS/src/Adafruit_LittleFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <string.h>
#include "Adafruit_LittleFS.h"

#include <Adafruit_TinyUSB.h> // for Serial

using namespace Adafruit_LittleFS_Namespace;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
#include <Adafruit_TinyUSB.h>

Adafruit_Arcada arcada;
Adafruit_SPITFT* tft;
// Use built-in buttons if available, else use A0, A1
#ifdef PIN_BUTTON1
#define BUTTON_YES PIN_BUTTON1
#else
#define BUTTON_YES A0
#endif

#ifdef PIN_BUTTON2
#define BUTTON_NO PIN_BUTTON2
#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

#ifdef PIN_BUTTON2
#define BUTTON_NO PIN_BUTTON2
#else
#define BUTTON_NO A1
#endif
#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
Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand All @@ -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 )
{
// Peer is disconnected while waiting for input
if ( !Bluefruit.connected(conn_handle) ) break;
// 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;
}

// 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 ( 0 == digitalRead(BUTTON_NO) ) return false;
#endif
if (accept_pairing)
{
Serial.println("Accepted");
}else
{
Serial.println("Declined");
}

return false;
return accept_pairing;
}

return true;
Expand All @@ -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
}

/**
Expand All @@ -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
}
Loading