From 8c8d64315c253175993b162fe09161e9ca90f30e Mon Sep 17 00:00:00 2001 From: Ureloc Date: Wed, 25 Oct 2017 13:57:56 +0200 Subject: [PATCH 1/6] Added analog oversampling Implemented analog oversampling which allows any analog pin to be automatically sampled muliple times (upto 256) when analogRead() is used. An average of the samples is then returned. --- cores/nRF5/wiring_analog.h | 7 +++++ cores/nRF5/wiring_analog_nRF52.c | 47 +++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/cores/nRF5/wiring_analog.h b/cores/nRF5/wiring_analog.h index 17a20744..e20e8c01 100644 --- a/cores/nRF5/wiring_analog.h +++ b/cores/nRF5/wiring_analog.h @@ -61,6 +61,13 @@ typedef enum _eAnalogReference */ extern void analogReference( eAnalogReference ulMode ) ; +/* +* \brief Configures the oversampling amount used to sample analog input. +* +* \param ulOversampling Should be set to 1, 2, 4, 8, 16, 32, 64, 128 or 256. +*/ +extern void analogOversampling( uint32_t ulOversampling ); + /* * \brief Writes an analog value (PWM wave) to a pin. * diff --git a/cores/nRF5/wiring_analog_nRF52.c b/cores/nRF5/wiring_analog_nRF52.c index 28afc210..f34f47a5 100644 --- a/cores/nRF5/wiring_analog_nRF52.c +++ b/cores/nRF5/wiring_analog_nRF52.c @@ -31,6 +31,9 @@ extern "C" { static uint32_t saadcReference = SAADC_CH_CONFIG_REFSEL_Internal; static uint32_t saadcGain = SAADC_CH_CONFIG_GAIN_Gain1_6; +static uint32_t saadcOversampling = SAADC_OVERSAMPLE_OVERSAMPLE_Bypass; +static bool saadcBurst = SAADC_CH_CONFIG_BURST_Disabled; + #if 0 // Note: Adafruit use seperated HardwarePWM class #define PWM_COUNT 3 @@ -124,6 +127,47 @@ void analogReference( eAnalogReference ulMode ) } } +void analogOversampling( uint32_t ulOversampling ) +{ + if(ulOversampling > 0) saadcBurst = SAADC_CH_CONFIG_BURST_Enabled; // burst mode has to be enable to use oversampling + else saadcBurst = SAADC_CH_CONFIG_BURST_Disabled; + + switch (ulOversampling) { + case 0: + case 1: + saadcBurst = SAADC_CH_CONFIG_BURST_Disabled; + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Bypass; + return; + break; + case 2: + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over2x; + break; + case 4: + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over4x; + break; + case 8: + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over8x; + break; + case 16: + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over16x; + break; + case 32: + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over32x; + break; + case 64: + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over64x; + break; + case 128: + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over128x; + break; + case 256: + NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over256x; + break; + } + + saadcBurst = SAADC_CH_CONFIG_BURST_Enabled; +} + uint32_t analogRead( uint32_t ulPin ) { uint32_t pin = SAADC_CH_PSELP_PSELP_NC; @@ -200,7 +244,8 @@ uint32_t analogRead( uint32_t ulPin ) | ((saadcGain << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk) | ((saadcReference << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk) | ((SAADC_CH_CONFIG_TACQ_3us << SAADC_CH_CONFIG_TACQ_Pos) & SAADC_CH_CONFIG_TACQ_Msk) - | ((SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk); + | ((SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk) + | ((saadcBurst << SAADC_CH_CONFIG_BURST_Pos) & SAADC_CH_CONFIG_BURST_Msk); NRF_SAADC->CH[0].PSELN = pin; NRF_SAADC->CH[0].PSELP = pin; From 92b638100c2198186b7503d581df1e6f79c55161 Mon Sep 17 00:00:00 2001 From: Ureloc Date: Wed, 25 Oct 2017 14:35:08 +0200 Subject: [PATCH 2/6] Implemented Uart::flush() --- cores/nRF5/Uart.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index c079e17f..f478f21a 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -186,6 +186,7 @@ void Uart::end() void Uart::flush() { + rxBuffer.clear(); } void Uart::IrqHandler() From 52752f378b5c0fa39099657d0a89e1f5012d3c2d Mon Sep 17 00:00:00 2001 From: Ureloc Date: Wed, 25 Oct 2017 15:46:50 +0200 Subject: [PATCH 3/6] Cleaned up analogOversampling() Removed unneeded code --- cores/nRF5/wiring_analog_nRF52.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cores/nRF5/wiring_analog_nRF52.c b/cores/nRF5/wiring_analog_nRF52.c index f34f47a5..8f4c3e79 100644 --- a/cores/nRF5/wiring_analog_nRF52.c +++ b/cores/nRF5/wiring_analog_nRF52.c @@ -31,7 +31,6 @@ extern "C" { static uint32_t saadcReference = SAADC_CH_CONFIG_REFSEL_Internal; static uint32_t saadcGain = SAADC_CH_CONFIG_GAIN_Gain1_6; -static uint32_t saadcOversampling = SAADC_OVERSAMPLE_OVERSAMPLE_Bypass; static bool saadcBurst = SAADC_CH_CONFIG_BURST_Disabled; #if 0 // Note: Adafruit use seperated HardwarePWM class @@ -129,8 +128,7 @@ void analogReference( eAnalogReference ulMode ) void analogOversampling( uint32_t ulOversampling ) { - if(ulOversampling > 0) saadcBurst = SAADC_CH_CONFIG_BURST_Enabled; // burst mode has to be enable to use oversampling - else saadcBurst = SAADC_CH_CONFIG_BURST_Disabled; + saadcBurst = SAADC_CH_CONFIG_BURST_Enabled; switch (ulOversampling) { case 0: @@ -164,8 +162,6 @@ void analogOversampling( uint32_t ulOversampling ) NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over256x; break; } - - saadcBurst = SAADC_CH_CONFIG_BURST_Enabled; } uint32_t analogRead( uint32_t ulPin ) From e61fbe9a68de2ace7ba8b69554c56c5b1381300a Mon Sep 17 00:00:00 2001 From: Brandyn Burbank Date: Sun, 5 Nov 2017 18:58:41 -0700 Subject: [PATCH 4/6] Allow HardwarePWM::addPin method to return true if _count == MAX_CHANNELS, but pin passed was already configured. Return false if trying to add a new pin more than MAX_CHANNELS. --- cores/nRF5/HardwarePWM.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cores/nRF5/HardwarePWM.cpp b/cores/nRF5/HardwarePWM.cpp index 89d05887..5cf601ce 100644 --- a/cores/nRF5/HardwarePWM.cpp +++ b/cores/nRF5/HardwarePWM.cpp @@ -78,7 +78,7 @@ void HardwarePWM::setClockDiv(uint8_t div) */ bool HardwarePWM::addPin(uint8_t pin) { - VERIFY( isPinValid(pin) && (_count < MAX_CHANNELS) ); + VERIFY( isPinValid(pin) && (_count <= MAX_CHANNELS) ); // Check if pin is already configured for(uint8_t i=0; i<_count; i++) @@ -86,6 +86,12 @@ bool HardwarePWM::addPin(uint8_t pin) if (_pwm->PSEL.OUT[i] == pin) return true; } + if ((_count >= MAX_CHANNELS)) + { + //Pin not already configured, but this HardwarePWM is full + return false; + } + pinMode(pin, OUTPUT); digitalWrite(pin, LOW); From 174ffb2df6d614207f375da9b5419a1454a7f476 Mon Sep 17 00:00:00 2001 From: ogatatsu Date: Tue, 12 Dec 2017 21:09:02 +0900 Subject: [PATCH 5/6] enable BLEHidAdafruit to send key codes larger than 101. --- libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp b/libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp index eb82a162..fe38635f 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp @@ -70,9 +70,9 @@ uint8_t const hid_report_descriptor[] = // 6-byte Keycodes HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD), HID_USAGE_MIN ( 0 ), - HID_USAGE_MAX ( 101 ), + HID_USAGE_MAX ( 255 ), HID_LOGICAL_MIN ( 0 ), - HID_LOGICAL_MAX ( 101 ), + HID_LOGICAL_MAX ( 255 ), HID_REPORT_COUNT ( 6 ), HID_REPORT_SIZE ( 8 ), From 6478ca17bef998dd6c3d0e61d384f60649d1a463 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 18 Dec 2017 22:57:05 +0700 Subject: [PATCH 6/6] fix #108 make sure all bits in OUTSET is set HIGH when reset --- cores/nRF5/wiring.c | 3 +++ libraries/SPI/SPI.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index 02d84afd..a972fa47 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -56,6 +56,9 @@ void init( void ) NRF_RTC1->INTENCLR = RTC_INTENSET_COMPARE0_Msk; NRF_RTC1->TASKS_STOP = 1; NRF_RTC1->TASKS_CLEAR = 1; + + // Make sure all pin is set HIGH when pinmode() is called + NRF_GPIO->OUTSET = UINT32_MAX; } void enterSerialDfu(void) diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index fc82d73e..e0c4a2a5 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -118,6 +118,7 @@ void SPIClass::beginTransaction(SPISettings settings) void SPIClass::endTransaction(void) { + _p_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos); } void SPIClass::setBitOrder(BitOrder order)