Merge branch 'master' into develop
This commit is contained in:
commit
6aabe01674
36 files changed
+1139
-583
No files matched your search
@@ -168,6 +168,7 @@ void lfs_crc(uint32_t *crc, const void *buffer, size_t size);
|
||||
// Allocate memory, only used if buffers are not provided to littlefs
|
||||
static inline void *lfs_malloc(size_t size) {
|
||||
#ifndef LFS_NO_MALLOC
|
||||
extern void *pvPortMalloc( size_t xWantedSize );
|
||||
return pvPortMalloc(size);
|
||||
#else
|
||||
(void)size;
|
||||
@@ -178,6 +179,7 @@ static inline void *lfs_malloc(size_t size) {
|
||||
// Deallocate memory, only used if buffers are not provided to littlefs
|
||||
static inline void lfs_free(void *p) {
|
||||
#ifndef LFS_NO_MALLOC
|
||||
extern void vPortFree( void *pv );
|
||||
vPortFree(p);
|
||||
#else
|
||||
(void)p;
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
// Circuit Playground Birthday Candles
|
||||
//
|
||||
// All the NeoPixels will flicker like candles and the speaker will
|
||||
// play the tune to Happy Birthday continuously. Blow on the board
|
||||
// to slowly blow out all the candles and hear a victory song!
|
||||
// Controls:
|
||||
// - Slide switch: Move this to +/on to hear music or -/off to disable sound.
|
||||
// - Left button: Hold this down and press reset to use a rainbow flicker color.
|
||||
// - Right button: Hold this down and press reset to use a simple solid color (no flicker).
|
||||
// - If neither left or right button are pressed at startup then a flame-like
|
||||
// flickering animation will be used.
|
||||
// After all the candles are blown out press reset to reset and start over!
|
||||
//
|
||||
// Author: Tony DiCola
|
||||
// License: MIT (https://opensource.org/licenses/MIT)
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// PIN_BUZZER should be defined by the supported variant e.g CPlay Bluefruit or CLUE.
|
||||
// Otherwise please define the pin you would like to use for tone output
|
||||
#ifndef PIN_BUZZER
|
||||
#define PIN_BUZZER A0
|
||||
#endif
|
||||
|
||||
|
||||
// A few music note frequencies as defined in this tone example:
|
||||
// https://www.arduino.cc/en/Tutorial/toneMelody
|
||||
#define NOTE_C4 262
|
||||
#define NOTE_CS4 277
|
||||
#define NOTE_D4 294
|
||||
#define NOTE_DS4 311
|
||||
#define NOTE_E4 330
|
||||
#define NOTE_F4 349
|
||||
#define NOTE_FS4 370
|
||||
#define NOTE_G4 392
|
||||
#define NOTE_GS4 415
|
||||
#define NOTE_A4 440
|
||||
#define NOTE_AS4 466
|
||||
#define NOTE_B4 494
|
||||
#define NOTE_C5 523
|
||||
#define NOTE_CS5 554
|
||||
#define NOTE_D5 587
|
||||
#define NOTE_DS5 622
|
||||
#define NOTE_E5 659
|
||||
#define NOTE_F5 698
|
||||
#define NOTE_FS5 740
|
||||
#define NOTE_G5 784
|
||||
#define NOTE_GS5 831
|
||||
#define NOTE_A5 880
|
||||
#define NOTE_AS5 932
|
||||
#define NOTE_B5 988
|
||||
|
||||
// Define note durations. You only need to adjust the whole note
|
||||
// time and other notes will be subdivided from it directly.
|
||||
#define WHOLE 2200 // Length of time in milliseconds of a whole note (i.e. a full bar).
|
||||
#define HALF WHOLE/2
|
||||
#define QUARTER HALF/2
|
||||
#define EIGHTH QUARTER/2
|
||||
#define EIGHTH_TRIPLE QUARTER/3
|
||||
#define SIXTEENTH EIGHTH/2
|
||||
|
||||
// Play a note of the specified frequency and for the specified duration.
|
||||
// Hold is an optional bool that specifies if this note should be held a
|
||||
// little longer, i.e. for eigth notes that are tied together.
|
||||
// While waiting for a note to play the waitBreath delay function is used
|
||||
// so breath detection and pixel animation continues to run. No tones
|
||||
// will play if the slide switch is in the -/off position or all the
|
||||
// candles have been blown out.
|
||||
void playNote(int frequency, int duration, bool hold=false, bool measure=true) {
|
||||
(void) measure;
|
||||
|
||||
if (hold) {
|
||||
// For a note that's held play it a little longer than the specified duration
|
||||
// so it blends into the next tone (but there's still a small delay to
|
||||
// hear the next note).
|
||||
tone(PIN_BUZZER, frequency, duration + duration/32);
|
||||
}
|
||||
else {
|
||||
// For a note that isn't held just play it for the specified duration.
|
||||
tone(PIN_BUZZER, frequency, duration);
|
||||
}
|
||||
|
||||
delay(duration + duration/16);
|
||||
}
|
||||
|
||||
// Song to play when the candles are blown out.
|
||||
void celebrateSong() {
|
||||
// Play a little charge melody, from:
|
||||
// https://en.wikipedia.org/wiki/Charge_(fanfare)
|
||||
// Note the explicit boolean parameters in particular the measure=false
|
||||
// at the end. This means the notes will play without any breath measurement
|
||||
// logic. Without this false value playNote will try to keep waiting for candles
|
||||
// to blow out during the celebration song!
|
||||
playNote(NOTE_G4, EIGHTH_TRIPLE, true, false);
|
||||
playNote(NOTE_C5, EIGHTH_TRIPLE, true, false);
|
||||
playNote(NOTE_E5, EIGHTH_TRIPLE, false, false);
|
||||
playNote(NOTE_G5, EIGHTH, true, false);
|
||||
playNote(NOTE_E5, SIXTEENTH, false);
|
||||
playNote(NOTE_G5, HALF, false);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Initialize serial output and Circuit Playground library.
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(PIN_BUZZER, OUTPUT);
|
||||
digitalWrite(PIN_BUZZER, LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Play happy birthday tune, from:
|
||||
// http://www.irish-folk-songs.com/happy-birthday-tin-whistle-sheet-music.html#.WXFJMtPytBw
|
||||
// Inside each playNote call it will play a note and drive the NeoPixel animation
|
||||
// and check for a breath against the sound sensor. Once all the candles are blown out
|
||||
// the playNote calls will stop playing music.
|
||||
playNote(NOTE_D4, EIGHTH, true);
|
||||
playNote(NOTE_D4, EIGHTH);
|
||||
playNote(NOTE_E4, QUARTER); // Bar 1
|
||||
playNote(NOTE_D4, QUARTER);
|
||||
playNote(NOTE_G4, QUARTER);
|
||||
playNote(NOTE_FS4, HALF); // Bar 2
|
||||
playNote(NOTE_D4, EIGHTH, true);
|
||||
playNote(NOTE_D4, EIGHTH);
|
||||
playNote(NOTE_E4, QUARTER); // Bar 3
|
||||
playNote(NOTE_D4, QUARTER);
|
||||
playNote(NOTE_A4, QUARTER);
|
||||
playNote(NOTE_G4, HALF); // Bar 4
|
||||
playNote(NOTE_D4, EIGHTH, true);
|
||||
playNote(NOTE_D4, EIGHTH);
|
||||
playNote(NOTE_D5, QUARTER); // Bar 5
|
||||
playNote(NOTE_B4, QUARTER);
|
||||
playNote(NOTE_G4, QUARTER);
|
||||
playNote(NOTE_FS4, QUARTER); // Bar 6
|
||||
playNote(NOTE_E4, QUARTER);
|
||||
playNote(NOTE_C5, EIGHTH, true);
|
||||
playNote(NOTE_C5, EIGHTH);
|
||||
playNote(NOTE_B4, QUARTER); // Bar 7
|
||||
playNote(NOTE_G4, QUARTER);
|
||||
playNote(NOTE_A4, QUARTER);
|
||||
playNote(NOTE_G4, HALF); // Bar 8
|
||||
|
||||
celebrateSong();
|
||||
|
||||
// One second pause before repeating the loop and playing
|
||||
delay(1000);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
name=Adafruit Bluefruit nRF52 Libraries
|
||||
version=0.20.5
|
||||
version=0.21.0
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for nRF52-based Adafruit Bluefruit LE modules
|
||||
|
||||
@@ -78,6 +78,17 @@ void usb_softdevice_post_enable(void)
|
||||
sd_power_usbdetected_enable(true);
|
||||
sd_power_usbpwrrdy_enable(true);
|
||||
sd_power_usbremoved_enable(true);
|
||||
|
||||
uint32_t usb_reg;
|
||||
sd_power_usbregstatus_get(&usb_reg);
|
||||
|
||||
// Note: Detect event is possibly handled by usb_hardware_init() however depending on how fast
|
||||
// Bluefruit.begin() is called, Ready event may or may not be handled before we disable the nrfx_power.
|
||||
// USBPULLUP not enabled -> Ready event not yet handled
|
||||
if ( (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk) && (NRF_USBD->USBPULLUP == 0) )
|
||||
{
|
||||
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -165,7 +176,7 @@ AdafruitBluefruit::AdafruitBluefruit(void)
|
||||
_ble_event_sem = NULL;
|
||||
_soc_event_sem = NULL;
|
||||
#ifdef ANT_LICENSE_KEY
|
||||
_mprot_event_sem = NULL; //additiona semaphore for multiprotocol
|
||||
_mprot_event_sem = NULL;
|
||||
#endif
|
||||
|
||||
_led_blink_th = NULL;
|
||||
@@ -282,34 +293,31 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
|
||||
#if defined( USE_LFXO )
|
||||
nrf_clock_lf_cfg_t clock_cfg =
|
||||
{
|
||||
// LFXO
|
||||
.source = NRF_CLOCK_LF_SRC_XTAL,
|
||||
.rc_ctiv = 0,
|
||||
.rc_temp_ctiv = 0,
|
||||
.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
|
||||
// LFXO
|
||||
.source = NRF_CLOCK_LF_SRC_XTAL,
|
||||
.rc_ctiv = 0,
|
||||
.rc_temp_ctiv = 0,
|
||||
.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
|
||||
};
|
||||
#elif defined( USE_LFRC )
|
||||
nrf_clock_lf_cfg_t clock_cfg =
|
||||
{
|
||||
// LXRC
|
||||
.source = NRF_CLOCK_LF_SRC_RC,
|
||||
.rc_ctiv = 16,
|
||||
.rc_temp_ctiv = 2,
|
||||
.accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
|
||||
// LXRC
|
||||
.source = NRF_CLOCK_LF_SRC_RC,
|
||||
.rc_ctiv = 16,
|
||||
.rc_temp_ctiv = 2,
|
||||
.accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
|
||||
};
|
||||
#else
|
||||
#error Clock Source is not configured, define USE_LFXO or USE_LFRC according to your board in variant.h
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
** BLE only Softdevices have 2-args sd_softdevice_enable()
|
||||
** BLE & ANT+ Softdevices have 3-args sd_softdevice_enable()
|
||||
*/
|
||||
#ifdef ANT_LICENSE_KEY
|
||||
// Enable SoftDevice
|
||||
#ifdef ANT_LICENSE_KEY
|
||||
VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb, ANT_LICENSE_KEY), false );
|
||||
#else //#ifdef ANT_LICENSE_KEY
|
||||
#else
|
||||
VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, nrf_error_cb), false );
|
||||
#endif //#ifdef ANT_LICENSE_KEY
|
||||
#endif
|
||||
|
||||
#ifdef USE_TINYUSB
|
||||
usb_softdevice_post_enable();
|
||||
@@ -454,13 +462,6 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
|
||||
ble_gap_conn_sec_mode_t sec_mode = BLE_SECMODE_OPEN;
|
||||
VERIFY_STATUS(sd_ble_gap_device_name_set(&sec_mode, (uint8_t const *) CFG_DEFAULT_NAME, strlen(CFG_DEFAULT_NAME)), false);
|
||||
|
||||
//------------- USB -------------//
|
||||
#ifdef USE_TINYUSB
|
||||
sd_power_usbdetected_enable(true);
|
||||
sd_power_usbpwrrdy_enable(true);
|
||||
sd_power_usbremoved_enable(true);
|
||||
#endif
|
||||
|
||||
// Init Central role
|
||||
if (_central_count) Central.begin();
|
||||
|
||||
@@ -650,13 +651,21 @@ void AdafruitBluefruit::setRssiCallback(rssi_cb_t fp)
|
||||
*------------------------------------------------------------------*/
|
||||
extern "C" void SD_EVT_IRQHandler(void)
|
||||
{
|
||||
// Notify both BLE & SOC Task
|
||||
#if CFG_SYSVIEW
|
||||
SEGGER_SYSVIEW_RecordEnterISR();
|
||||
#endif
|
||||
|
||||
// Notify both BLE & SOC & MultiProtocol (if any) Task
|
||||
xSemaphoreGiveFromISR(Bluefruit._soc_event_sem, NULL);
|
||||
xSemaphoreGiveFromISR(Bluefruit._ble_event_sem, NULL);
|
||||
|
||||
#ifdef ANT_LICENSE_KEY
|
||||
// Notify parallel multiprotocol Task, if any
|
||||
if (Bluefruit._mprot_event_sem) xSemaphoreGiveFromISR(Bluefruit._mprot_event_sem, NULL);
|
||||
#endif
|
||||
|
||||
#if CFG_SYSVIEW
|
||||
SEGGER_SYSVIEW_RecordExitISR();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,7 +101,7 @@ class Servo
|
||||
{
|
||||
public:
|
||||
Servo();
|
||||
uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
|
||||
uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or INVALID_SERVO if failure (zero is a valid channel number)
|
||||
uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
|
||||
void detach();
|
||||
void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
|
||||
@@ -111,8 +111,8 @@ public:
|
||||
bool attached(); // return true if this servo is attached, otherwise false
|
||||
private:
|
||||
uint8_t servoIndex; // index into the channel data for this servo
|
||||
int16_t min; // minimum pulse in µs
|
||||
int16_t max; // maximum pulse in µs
|
||||
int16_t min; // minimum pulse in µs
|
||||
int16_t max; // maximum pulse in µs
|
||||
|
||||
HardwarePWM* pwm;
|
||||
};
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Modified by Ha Thach for Adafruit Industries
|
||||
Modified by Henry Gabryjelski to add ownershp support
|
||||
*/
|
||||
|
||||
#if defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_NRF52_ADAFRUIT)
|
||||
@@ -21,6 +24,10 @@
|
||||
#include <Arduino.h>
|
||||
#include <Servo.h>
|
||||
|
||||
enum
|
||||
{
|
||||
SERVO_TOKEN = 0x76726553 // 'S' 'e' 'r' 'v'
|
||||
};
|
||||
|
||||
static servo_t servos[MAX_SERVOS]; // static array of servo structures
|
||||
uint8_t ServoCount = 0; // the total number of attached servos
|
||||
@@ -32,7 +39,6 @@ Servo::Servo()
|
||||
} else {
|
||||
this->servoIndex = INVALID_SERVO; // too many servos
|
||||
}
|
||||
|
||||
this->pwm = NULL;
|
||||
}
|
||||
|
||||
@@ -43,55 +49,98 @@ uint8_t Servo::attach(int pin)
|
||||
|
||||
uint8_t Servo::attach(int pin, int min, int max)
|
||||
{
|
||||
if (this->servoIndex < MAX_SERVOS) {
|
||||
pinMode(pin, OUTPUT); // set servo pin to output
|
||||
servos[this->servoIndex].Pin.nbr = pin;
|
||||
if (this->servoIndex == INVALID_SERVO) {
|
||||
return INVALID_SERVO;
|
||||
}
|
||||
bool succeeded = false;
|
||||
|
||||
if (min < MIN_PULSE_WIDTH) min = MIN_PULSE_WIDTH;
|
||||
if (max > MAX_PULSE_WIDTH) max = MAX_PULSE_WIDTH;
|
||||
if (min < MIN_PULSE_WIDTH)
|
||||
{
|
||||
min = MIN_PULSE_WIDTH;
|
||||
}
|
||||
|
||||
//fix min if conversion to pulse cycle value is too low
|
||||
if((min/DUTY_CYCLE_RESOLUTION)*DUTY_CYCLE_RESOLUTION<min) min+=DUTY_CYCLE_RESOLUTION;
|
||||
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
if (max > MAX_PULSE_WIDTH)
|
||||
{
|
||||
max = MAX_PULSE_WIDTH;
|
||||
}
|
||||
|
||||
servos[this->servoIndex].Pin.isActive = true;
|
||||
//fix min if conversion to pulse cycle value is too low
|
||||
if ( (min / DUTY_CYCLE_RESOLUTION) * DUTY_CYCLE_RESOLUTION < min )
|
||||
{
|
||||
min += DUTY_CYCLE_RESOLUTION;
|
||||
}
|
||||
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
|
||||
// Adafruit, add pin to 1 of available Hw PWM
|
||||
for(int i=0; i<HWPWM_MODULE_NUM; i++)
|
||||
// Adafruit, add pin to 1 of available Hw PWM
|
||||
// first, use existing HWPWM modules (already owned by Servo)
|
||||
for ( int i = 0; i < HWPWM_MODULE_NUM; i++ )
|
||||
{
|
||||
if ( HwPWMx[i]->isOwner(SERVO_TOKEN) && HwPWMx[i]->addPin(pin) )
|
||||
{
|
||||
if ( HwPWMx[i]->addPin(pin) )
|
||||
this->pwm = HwPWMx[i];
|
||||
succeeded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if could not add to existing owned PWM modules, try to add to a new PWM module
|
||||
if ( !succeeded )
|
||||
{
|
||||
for ( int i = 0; i < HWPWM_MODULE_NUM; i++ )
|
||||
{
|
||||
if ( HwPWMx[i]->takeOwnership(SERVO_TOKEN) && HwPWMx[i]->addPin(pin) )
|
||||
{
|
||||
this->pwm = HwPWMx[i];
|
||||
succeeded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( succeeded )
|
||||
{
|
||||
pinMode(pin, OUTPUT);
|
||||
servos[this->servoIndex].Pin.nbr = pin;
|
||||
servos[this->servoIndex].Pin.isActive = true;
|
||||
|
||||
this->pwm->setMaxValue(MAXVALUE);
|
||||
this->pwm->setClockDiv(CLOCKDIV);
|
||||
|
||||
return this->servoIndex;
|
||||
}else
|
||||
{
|
||||
return INVALID_SERVO;
|
||||
}
|
||||
return this->servoIndex;
|
||||
}
|
||||
|
||||
void Servo::detach()
|
||||
{
|
||||
if (this->servoIndex == INVALID_SERVO) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t const pin = servos[this->servoIndex].Pin.nbr;
|
||||
servos[this->servoIndex].Pin.isActive = false;
|
||||
|
||||
servos[this->servoIndex].Pin.isActive = false;
|
||||
|
||||
// remove pin from HW PWM
|
||||
this->pwm->removePin(pin);
|
||||
// remove pin from HW PWM
|
||||
HardwarePWM * pwm = this->pwm;
|
||||
this->pwm = nullptr;
|
||||
pwm->removePin(pin);
|
||||
if (pwm->usedChannelCount() == 0) {
|
||||
pwm->stop(); // disables peripheral so can release ownership
|
||||
pwm->releaseOwnership(SERVO_TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Servo::write(int value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
else if (value > 180)
|
||||
} else if (value > 180) {
|
||||
value = 180;
|
||||
}
|
||||
value = map(value, 0, 180, this->min, this->max);
|
||||
|
||||
writeMicroseconds(value);
|
||||
@@ -100,9 +149,10 @@ void Servo::write(int value)
|
||||
|
||||
void Servo::writeMicroseconds(int value)
|
||||
{
|
||||
uint8_t pin = servos[this->servoIndex].Pin.nbr;
|
||||
|
||||
if ( this->pwm ) this->pwm->writePin(pin, value/DUTY_CYCLE_RESOLUTION);
|
||||
if (this->pwm) {
|
||||
uint8_t pin = servos[this->servoIndex].Pin.nbr;
|
||||
this->pwm->writePin(pin, value/DUTY_CYCLE_RESOLUTION);
|
||||
}
|
||||
}
|
||||
|
||||
int Servo::read() // return the value as degrees
|
||||
@@ -112,15 +162,18 @@ int Servo::read() // return the value as degrees
|
||||
|
||||
int Servo::readMicroseconds()
|
||||
{
|
||||
uint8_t pin = servos[this->servoIndex].Pin.nbr;
|
||||
|
||||
if ( this->pwm ) return this->pwm->readPin(pin)*DUTY_CYCLE_RESOLUTION;
|
||||
|
||||
if (this->pwm) {
|
||||
uint8_t pin = servos[this->servoIndex].Pin.nbr;
|
||||
return this->pwm->readPin(pin)*DUTY_CYCLE_RESOLUTION;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Servo::attached()
|
||||
{
|
||||
if (this->servoIndex == INVALID_SERVO) {
|
||||
return false;
|
||||
}
|
||||
return servos[this->servoIndex].Pin.isActive;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ class TwoWire : public Stream
|
||||
void begin(uint8_t);
|
||||
void end();
|
||||
void setClock(uint32_t);
|
||||
void setPins(uint8_t pinSDA, uint8_t pinSCL);
|
||||
|
||||
void beginTransmission(uint8_t);
|
||||
uint8_t endTransmission(bool stopBit);
|
||||
|
||||
@@ -46,7 +46,7 @@ TwoWire::TwoWire(NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn,
|
||||
}
|
||||
|
||||
void TwoWire::begin(void) {
|
||||
//Master Mode
|
||||
//Main Mode
|
||||
master = true;
|
||||
|
||||
*pincfg_reg(_uc_pinSCL) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
@@ -72,7 +72,7 @@ void TwoWire::begin(void) {
|
||||
}
|
||||
|
||||
void TwoWire::begin(uint8_t address) {
|
||||
//Slave mode
|
||||
//Secondary mode
|
||||
master = false;
|
||||
|
||||
*pincfg_reg(_uc_pinSCL) = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
|
||||
@@ -127,6 +127,12 @@ void TwoWire::setClock(uint32_t baudrate) {
|
||||
}
|
||||
}
|
||||
|
||||
void TwoWire::setPins(uint8_t pinSDA, uint8_t pinSCL)
|
||||
{
|
||||
this->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
|
||||
this->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
|
||||
}
|
||||
|
||||
void TwoWire::end() {
|
||||
if (master)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin(); // join i2c bus (address optional for master)
|
||||
Wire.begin(); // join i2c bus (address optional for main)
|
||||
Serial.begin(9600); // start serial communication at 9600bps
|
||||
while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
}
|
||||
@@ -42,7 +42,7 @@ void loop()
|
||||
Wire.endTransmission(); // stop transmitting
|
||||
|
||||
// step 4: request reading from sensor
|
||||
Wire.requestFrom(112, 2); // request 2 bytes from slave device #112
|
||||
Wire.requestFrom(112, 2); // request 2 bytes from secondary device #112
|
||||
|
||||
// step 5: receive reading from sensor
|
||||
if(2 <= Wire.available()) // if two bytes were received
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin(); // join i2c bus (address optional for master)
|
||||
Wire.begin(); // join i2c bus (address optional for main)
|
||||
}
|
||||
|
||||
byte val = 0;
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
// Wire Master Reader
|
||||
// Wire Main Reader
|
||||
// by Nicholas Zambetti <http://www.zambetti.com>
|
||||
|
||||
// Demonstrates use of the Wire library
|
||||
// Reads data from an I2C/TWI slave device
|
||||
// Refer to the "Wire Slave Sender" example for use with this
|
||||
// Reads data from an I2C/TWI secondary device
|
||||
// Refer to the "Wire Secondary Sender" example for use with this
|
||||
|
||||
// Created 29 March 2006
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin(); // join i2c bus (address optional for master)
|
||||
Wire.begin(); // join i2c bus (address optional for main)
|
||||
Serial.begin(9600); // start serial for output
|
||||
while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Wire.requestFrom(2, 6); // request 6 bytes from slave device #2
|
||||
Wire.requestFrom(2, 6); // request 6 bytes from secondary device #2
|
||||
|
||||
while(Wire.available()) // slave may send less than requested
|
||||
while(Wire.available()) // secondary may send less than requested
|
||||
{
|
||||
char c = Wire.read(); // receive a byte as character
|
||||
Serial.print(c); // print the character
|
||||
+1
-1
@@ -7,7 +7,7 @@ void setup()
|
||||
{
|
||||
Serial.begin(115200); // start serial for output
|
||||
while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
wi->begin(); // join i2c bus (address optional for master)
|
||||
wi->begin(); // join i2c bus (address optional for main)
|
||||
}
|
||||
|
||||
void loop()
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
// Wire Master Writer
|
||||
// Wire Main Writer
|
||||
// by Nicholas Zambetti <http://www.zambetti.com>
|
||||
|
||||
// Demonstrates use of the Wire library
|
||||
// Writes data to an I2C/TWI slave device
|
||||
// Refer to the "Wire Slave Receiver" example for use with this
|
||||
// Writes data to an I2C/TWI secondary device
|
||||
// Refer to the "Wire Secondary Receiver" example for use with this
|
||||
|
||||
// Created 29 March 2006
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin(); // join i2c bus (address optional for master)
|
||||
Wire.begin(); // join i2c bus (address optional for main)
|
||||
}
|
||||
|
||||
byte x = 0;
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
// Wire Slave Receiver
|
||||
// Wire Secondary Receiver
|
||||
// by Nicholas Zambetti <http://www.zambetti.com>
|
||||
|
||||
// Demonstrates use of the Wire library
|
||||
// Receives data as an I2C/TWI slave device
|
||||
// Refer to the "Wire Master Writer" example for use with this
|
||||
// Receives data as an I2C/TWI secondary device
|
||||
// Refer to the "Wire Main Writer" example for use with this
|
||||
|
||||
// Created 29 March 2006
|
||||
|
||||
@@ -25,7 +25,7 @@ void loop()
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// function that executes whenever data is received from master
|
||||
// function that executes whenever data is received from main
|
||||
// this function is registered as an event, see setup()
|
||||
void receiveEvent(int howMany)
|
||||
{
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
// Wire Slave Sender
|
||||
// Wire Secondary Sender
|
||||
// by Nicholas Zambetti <http://www.zambetti.com>
|
||||
|
||||
// Demonstrates use of the Wire library
|
||||
// Sends data as an I2C/TWI slave device
|
||||
// Refer to the "Wire Master Reader" example for use with this
|
||||
// Sends data as an I2C/TWI secondary device
|
||||
// Refer to the "Wire Main Reader" example for use with this
|
||||
|
||||
// Created 29 March 2006
|
||||
|
||||
@@ -23,10 +23,10 @@ void loop()
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// function that executes whenever data is requested by master
|
||||
// function that executes whenever data is requested by main
|
||||
// this function is registered as an event, see setup()
|
||||
void requestEvent()
|
||||
{
|
||||
Wire.write("hello "); // respond with message of 6 bytes
|
||||
// as expected by master
|
||||
// as expected by main
|
||||
}
|
||||
Reference in new issue
Block a user