Skip to content

Commit

Permalink
Fix Arduino SAMD support, add Arduino NANO 33 IoT
Browse files Browse the repository at this point in the history
  • Loading branch information
PaintYourDragon committed Mar 1, 2022
1 parent 8cb23b6 commit fb5b33a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Adafruit_NeoPixel_ZeroDMA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool Adafruit_NeoPixel_ZeroDMA::begin(SERCOM *sercom, Sercom *sercomBase,
// conceivable that this could fail spectacularly on some unforseen
// future device, if the SERCOM pad assignment becomes hardwarily
// strict.)
spi = new SPIClass(sercom, mosi, mosi, mosi, padTX, SERCOM_RX_PAD_1);
spi = new SPIClassSAMD(sercom, mosi, mosi, mosi, padTX, SERCOM_RX_PAD_1);
}
if ((spi)) {
spi->begin();
Expand Down
9 changes: 8 additions & 1 deletion Adafruit_NeoPixel_ZeroDMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#include <Adafruit_ZeroDMA.h>
#include <SPI.h>

// For Adafruit SAMD boards, alias SPIClassSAMD to SPIClass so the
// same code works on Arduino or Adafruit SAMD boards (hardware SPI
// is implemented a bit different on each now).
#ifdef ARDUINO_SAMD_ADAFRUIT
typedef SPIClass SPIClassSAMD;
#endif

/** @brief Create a NeoPixel class that uses SPI DMA to write strands in
a non-blocking manner */
class Adafruit_NeoPixel_ZeroDMA : public Adafruit_NeoPixel {
Expand All @@ -31,7 +38,7 @@ class Adafruit_NeoPixel_ZeroDMA : public Adafruit_NeoPixel {

protected:
Adafruit_ZeroDMA dma; ///< The DMA manager for the SPI class
SPIClass *spi; ///< Underlying SPI hardware interface we use to DMA
SPIClassSAMD *spi; ///< Underlying SPI hardware interface we use to DMA
uint8_t *dmaBuf; ///< The raw buffer we write to SPI to mimic NeoPixel
uint16_t brightness; ///< 1 (off) to 256 (brightest)
#ifdef __SAMD51__
Expand Down
1 change: 1 addition & 0 deletions examples/strandtest/strandtest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Trinket M0: pin 4 (can't use with I2C, SPI or Serial1 active).
Gemma M0: pin D0 (can't use with I2C, SPI or Serial1 active).
QT Py: MOSI* and pin 16 (underside pad, can't use w/optional SPI flash).
Arduino NANO 33 IoT: pins 4, 6, 7, A2, A3, MOSI*.
* If using the MOSI pin on these boards, the corresponding SPI
peripheral is not usable.
*/
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit DMA neopixel library
version=1.2.3
version=1.3.0
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Arduino library for NeoPixel DMA on SAMD21 and SAMD51 microcontrollers
Expand Down
11 changes: 11 additions & 0 deletions pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ struct {
&sercom4, SERCOM4, SERCOM4_DMAC_ID_TX, MOSI, SPI_PAD_2_SCK_3, PIO_SERCOM_ALT,
#endif // end Arduino Zero

#if defined(USB_PID) && (USB_PID == 0x8057) // ARDUINO NANO 33 IOT
// SERCOM0 is the only one 100% in the clear; others overlap serial1/2,
// WiFi, Wire, etc.
&sercom0, SERCOM0, SERCOM0_DMAC_ID_TX, 4, SPI_PAD_3_SCK_1, PIO_SERCOM_ALT,
&sercom0, SERCOM0, SERCOM0_DMAC_ID_TX, 6, SPI_PAD_0_SCK_1, PIO_SERCOM_ALT,
&sercom0, SERCOM0, SERCOM0_DMAC_ID_TX, 7, SPI_PAD_2_SCK_3, PIO_SERCOM_ALT,
&sercom0, SERCOM0, SERCOM0_DMAC_ID_TX, A2, SPI_PAD_3_SCK_1, PIO_SERCOM,
&sercom0, SERCOM0, SERCOM0_DMAC_ID_TX, A3, SPI_PAD_2_SCK_3, PIO_SERCOM,
&sercom1, SERCOM1, SERCOM1_DMAC_ID_TX, MOSI, SPI_PAD_0_SCK_1, PIO_SERCOM,
#endif // end Arduino NANO 33 IoT

}; // end sercomTable[]

#define N_SERCOMS (sizeof sercomTable / sizeof sercomTable[0])
Expand Down

0 comments on commit fb5b33a

Please sign in to comment.