From e83bf4047acd2d3f8b77fe221b44ec0ab4d85873 Mon Sep 17 00:00:00 2001 From: ogatatsu Date: Sun, 12 Jan 2020 20:05:22 +0900 Subject: [PATCH 1/9] Changed to use the first cccd descriptor found. --- libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp b/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp index 78f8858f..68830b85 100644 --- a/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp +++ b/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp @@ -155,6 +155,8 @@ bool BLEClientCharacteristic::_discoverDescriptor(uint16_t conn_handle, ble_gatt { LOG_LV2("DISC", "Found CCDD: handle = %d", disc_rsp.descs[i].handle); _cccd_handle = disc_rsp.descs[i].handle; + + break; } } From 37e3b53bcff44e25c1595bb647a825bc05871e7f Mon Sep 17 00:00:00 2001 From: ogatatsu Date: Sun, 12 Jan 2020 20:10:40 +0900 Subject: [PATCH 2/9] Modified to work correctly when multiple characteristics of the same uuid are passed. --- libraries/Bluefruit52Lib/src/BLEDiscovery.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp index b5475994..a4b4d580 100644 --- a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp +++ b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp @@ -134,6 +134,9 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar { for (uint8_t i=0; idiscovered() ) + continue; + if ( chr[i]->uuid == disc_chr->chars[d].uuid ) { LOG_LV2("DISC", "[CHR] Found 0x%04X, handle = %d\n-----------------", disc_chr->chars[d].uuid.uuid, disc_chr->chars[d].handle_value); From 6f1acc4b3d888572eab629a4f0ef56da4e8cda59 Mon Sep 17 00:00:00 2001 From: ogatatsu Date: Sun, 12 Jan 2020 20:16:35 +0900 Subject: [PATCH 3/9] Fixed a bug that disconnect function of client characteristics was not called. --- libraries/Bluefruit52Lib/src/BLEGatt.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/BLEGatt.cpp b/libraries/Bluefruit52Lib/src/BLEGatt.cpp index 55101f3b..35d7bef3 100644 --- a/libraries/Bluefruit52Lib/src/BLEGatt.cpp +++ b/libraries/Bluefruit52Lib/src/BLEGatt.cpp @@ -184,15 +184,6 @@ void BLEGatt::_eventHandler(ble_evt_t* evt) if ( evt_id == BLE_GAP_EVT_DISCONNECTED ) { // Client - for(uint8_t i=0; i<_client.svc_count; i++) - { - if ( evt_conn_hdl == _client.svc_list[i]->_conn_hdl) - { - _client.svc_list[i]->disconnect(); - } - } - - // TODO merge to above loop for(uint8_t i=0; i<_client.chr_count; i++) { if ( evt_conn_hdl == _client.chr_list[i]->connHandle() ) @@ -200,6 +191,15 @@ void BLEGatt::_eventHandler(ble_evt_t* evt) _client.chr_list[i]->disconnect(); } } + + // TODO merge to above loop + for(uint8_t i=0; i<_client.svc_count; i++) + { + if ( evt_conn_hdl == _client.svc_list[i]->_conn_hdl) + { + _client.svc_list[i]->disconnect(); + } + } } // GATTC Read Characteristic by UUID procedure From 979a68dbd2b93582f81e737991d94c9c680e2622 Mon Sep 17 00:00:00 2001 From: bluera1n Date: Fri, 17 Jan 2020 00:02:35 +0900 Subject: [PATCH 4/9] Fix wrong expression of device ID in getMcuUniqueID() --- cores/nRF5/utility/utilities.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/nRF5/utility/utilities.c b/cores/nRF5/utility/utilities.c index a5b5f9e3..f1a4a4f3 100644 --- a/cores/nRF5/utility/utilities.c +++ b/cores/nRF5/utility/utilities.c @@ -93,7 +93,7 @@ const char* getMcuUniqueID(void) // Skip if already created if ( serial_str[0] == 0 ) { - sprintf(serial_str, "%08lu%08lu", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]); + sprintf(serial_str, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]); } return serial_str; From c9f824c8164f7ddad2500da3e5a30710995478aa Mon Sep 17 00:00:00 2001 From: ogatatsu Date: Sun, 19 Jan 2020 12:14:29 +0900 Subject: [PATCH 5/9] fix typo --- .../examples/Central/central_hid/central_hid.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Central/central_hid/central_hid.ino b/libraries/Bluefruit52Lib/examples/Central/central_hid/central_hid.ino index b56e2718..06a6d1e9 100644 --- a/libraries/Bluefruit52Lib/examples/Central/central_hid/central_hid.ino +++ b/libraries/Bluefruit52Lib/examples/Central/central_hid/central_hid.ino @@ -41,7 +41,7 @@ void setup() Bluefruit.setName("Bluefruit52 Central"); - // Init BLE Central Uart Serivce + // Init BLE Central Hid Serivce hid.begin(); #if POLLING == 0 @@ -126,7 +126,7 @@ void connect_callback(uint16_t conn_handle) { Serial.println("Found NONE"); - // disconnect since we couldn't find bleuart service + // disconnect since we couldn't find blehid service Bluefruit.disconnect(conn_handle); } } From 1358a1bc73cb3f99391cd20fbdc52eaf6bc5f5ff Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 19 Jan 2020 17:08:34 -0600 Subject: [PATCH 6/9] adding sense functions and sleep example --- cores/nRF5/wiring_constants.h | 2 + cores/nRF5/wiring_digital.c | 18 +++++++ .../Hardware/blink_sleep/blink_sleep.ino | 47 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino diff --git a/cores/nRF5/wiring_constants.h b/cores/nRF5/wiring_constants.h index 2cbda4ba..5bc30ba5 100644 --- a/cores/nRF5/wiring_constants.h +++ b/cores/nRF5/wiring_constants.h @@ -30,6 +30,8 @@ extern "C"{ #define OUTPUT (0x1) #define INPUT_PULLUP (0x2) #define INPUT_PULLDOWN (0x3) +#define INPUT_PULLUP_SENSE (0x4) +#define INPUT_PULLDOWN_SENSE (0x5) #define PI 3.1415926535897932384626433832795 #define HALF_PI 1.5707963267948966192313216916398 diff --git a/cores/nRF5/wiring_digital.c b/cores/nRF5/wiring_digital.c index ba435c40..d70b4a74 100644 --- a/cores/nRF5/wiring_digital.c +++ b/cores/nRF5/wiring_digital.c @@ -55,6 +55,15 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) | ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); break; + + case INPUT_PULLUP_SENSE: + // Set pin to input mode with pull-up resistor enabled and sense when Low + port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) + | ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) + | ((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) + | ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) + | ((uint32_t)GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos); + break; case INPUT_PULLDOWN: // Set pin to input mode with pull-down resistor enabled @@ -65,6 +74,15 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); break; + case INPUT_PULLDOWN_SENSE: + // Set pin to input mode with pull-down resistor enabled + port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) + | ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) + | ((uint32_t)GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos) + | ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) + | ((uint32_t)GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos); + break; + case OUTPUT: // Set pin to output mode port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos) diff --git a/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino b/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino new file mode 100644 index 00000000..27e22631 --- /dev/null +++ b/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino @@ -0,0 +1,47 @@ +/* + Blink_sleep + Turns on an LED on for one second, then off for one second, until the time to go to sleep runs out. + + Based on the blinky arduino example + + This example code is in the public domain. + + modified 19 Jan 2010 + by Pierre Constantineau + +*/ + +#define WAKE_LOW_PIN PIN_A0 +#define WAKE_HIGH_PIN PIN_A1 + +#define SLEEPING_DELAY 30000 // sleep after 30 seconds of blinking + +void gotoSleep(unsigned long time) +{ + // shutdown when time reaches SLEEPING_DELAY ms + if ((time>SLEEPING_DELAY)) + { + // to reduce power consumption when sleeping, turn off all your LEDs (and other power hungry devices) + digitalwrite(LED_BUILTIN, LOW); + + // setup your wake-up pins. + pinModeSense(WAKE_LOW_PIN, INPUT_PULLUP_SENSE); // this pin (WAKE_LOW_PIN) is pulled up and wakes up the feather when externally connected to ground. + pinModeSense(WAKE_HIGH_PIN, INPUT_PULLDOWN_SENSE); // this pin (WAKE_HIGH_PIN) is pulled down and wakes up the feather when externally connected to 3.3v. + + // power down nrf52. + sd_power_system_off(); // this function puts the whole nRF52 to deep sleep (no Bluetooth). If no sense pins are setup (or other hardware interrupts), the nrf52 will not wake up. + } +} + +// the setup function runs once when you press reset or power the board +void setup() { + // initialize digital pin LED_BUILTIN as an output. + pinMode(LED_BUILTIN, OUTPUT); +} + +// the loop function runs over and over again forever +void loop() { + digitalToggle(LED_BUILTIN); // turn the LED on (HIGH is the voltage level) + gotoSleep(millis()); // call millis() and pass it to the sleep function. On wake-up, millis will start at 0 again. + delay(1000); // wait for a second +} From 9a99c9cd5d7f15d52ce37b4361fa3237872a00b8 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 19 Jan 2020 17:12:26 -0600 Subject: [PATCH 7/9] adding sense functions and sleep example --- .../examples/Hardware/blink_sleep/blink_sleep.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino b/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino index 27e22631..c24261dc 100644 --- a/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino +++ b/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino @@ -6,7 +6,7 @@ This example code is in the public domain. - modified 19 Jan 2010 + created 19 Jan 2010 by Pierre Constantineau */ From e58aebb046c635c89d31ff45d6504b99f0f5b60f Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 19 Jan 2020 20:36:13 -0600 Subject: [PATCH 8/9] adding what's needed to enable the softdevice and the power off function --- .../examples/Hardware/blink_sleep/blink_sleep.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino b/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino index c24261dc..5b20d20c 100644 --- a/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino +++ b/libraries/Bluefruit52Lib/examples/Hardware/blink_sleep/blink_sleep.ino @@ -1,6 +1,7 @@ /* Blink_sleep Turns on an LED on for one second, then off for one second, until the time to go to sleep runs out. + You can wake up the feather by pressing a key/switch connecting the WAKE_LOW_PIN to GND and the WAKE_HIGH_PIN to 3.3V (VCC) Based on the blinky arduino example @@ -10,6 +11,7 @@ by Pierre Constantineau */ +#include #define WAKE_LOW_PIN PIN_A0 #define WAKE_HIGH_PIN PIN_A1 @@ -22,11 +24,11 @@ void gotoSleep(unsigned long time) if ((time>SLEEPING_DELAY)) { // to reduce power consumption when sleeping, turn off all your LEDs (and other power hungry devices) - digitalwrite(LED_BUILTIN, LOW); + digitalWrite(LED_BUILTIN, LOW); // setup your wake-up pins. - pinModeSense(WAKE_LOW_PIN, INPUT_PULLUP_SENSE); // this pin (WAKE_LOW_PIN) is pulled up and wakes up the feather when externally connected to ground. - pinModeSense(WAKE_HIGH_PIN, INPUT_PULLDOWN_SENSE); // this pin (WAKE_HIGH_PIN) is pulled down and wakes up the feather when externally connected to 3.3v. + pinMode(WAKE_LOW_PIN, INPUT_PULLUP_SENSE); // this pin (WAKE_LOW_PIN) is pulled up and wakes up the feather when externally connected to ground. + pinMode(WAKE_HIGH_PIN, INPUT_PULLDOWN_SENSE); // this pin (WAKE_HIGH_PIN) is pulled down and wakes up the feather when externally connected to 3.3v. // power down nrf52. sd_power_system_off(); // this function puts the whole nRF52 to deep sleep (no Bluetooth). If no sense pins are setup (or other hardware interrupts), the nrf52 will not wake up. @@ -35,6 +37,8 @@ void gotoSleep(unsigned long time) // the setup function runs once when you press reset or power the board void setup() { + Bluefruit.begin(); // Sleep functions need the softdevice to be active. + // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } From 3c3659ebb13dc6b5753fa0fdf52fca1de836e077 Mon Sep 17 00:00:00 2001 From: Lady Ada Date: Thu, 30 Jan 2020 14:43:10 -0500 Subject: [PATCH 9/9] added speaker, moved mic --- variants/clue_nrf52840/variant.cpp | 5 +++-- variants/clue_nrf52840/variant.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/variants/clue_nrf52840/variant.cpp b/variants/clue_nrf52840/variant.cpp index b2db14d8..71451e8e 100644 --- a/variants/clue_nrf52840/variant.cpp +++ b/variants/clue_nrf52840/variant.cpp @@ -67,8 +67,8 @@ const uint32_t g_ADigitalPinMap[] = 37, // P1.05 (TFT LITE) // 35 & 36 - PDM mic - 40, // D35 is P1.08 (PDM DAT) - 11, // D36 is P0.11 (PDM CLK) + 0, // D35 is P0.00 (PDM DAT) + 1, // D36 is P0.01 (PDM CLK) // QSPI pins (not exposed via any header / test point) 19, // D37 is P0.19 (QSPI CLK) @@ -81,6 +81,7 @@ const uint32_t g_ADigitalPinMap[] = 10, // D43 is P0.10 white LED control 9, // D44 is P0.09 APDS IRQ 38, // D45 is P1.06 LSM6DS33 IRQ + 32, // D46 is P1.00 Speaker/buzzer }; void initVariant() diff --git a/variants/clue_nrf52840/variant.h b/variants/clue_nrf52840/variant.h index e5cc58eb..a64710b6 100644 --- a/variants/clue_nrf52840/variant.h +++ b/variants/clue_nrf52840/variant.h @@ -35,8 +35,8 @@ extern "C" #endif // __cplusplus // Number of pins defined in PinDescription array -#define PINS_COUNT (46) -#define NUM_DIGITAL_PINS (46) +#define PINS_COUNT (47) +#define NUM_DIGITAL_PINS (47) #define NUM_ANALOG_INPUTS (8) #define NUM_ANALOG_OUTPUTS (0)