Skip to content

Commit eaca4e6

Browse files
committed
allow variant to define I2S interfaces
1 parent 2680779 commit eaca4e6

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed

libraries/I2S/src/I2S.cpp

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,6 @@ void I2SClass::disableClock() {
264264
while (GCLK->STATUS.bit.SYNCBUSY);
265265
}
266266

267-
void I2SClass::onDmaTransferComplete(int channel)
268-
{
269-
if (I2S._dmaChannel == channel) {
270-
I2S.onTransferComplete();
271-
}
272-
}
273-
274267
void I2SClass::onTransferComplete(void)
275268
{
276269
if (_doubleBuffer.available()) {
@@ -286,24 +279,15 @@ void I2SClass::onTransferComplete(void)
286279
}
287280
}
288281

289-
/*
290-
291-
+--------+--------------+-----------+-----------------+
292-
| I2S | Pad | Zero | MKR1000 |
293-
+--------+--------------+-----------+-----------------+
294-
| SD[0] | PA07 or PA19 | 9 or 12 | A6 or 10 (MISO) |
295-
| MCK[0] | PA09 or PB17 | 3 or ? | 12 (SCL) or ? |
296-
| SCK[0] | PA10 or PA20 | 1 or 6 | 2 or 6 |
297-
| FS[0] | PA11 or PA21 | 0 or ? | 3 or 7 |
298-
+--------+--------------------------+-----------------+
299-
| SD[1] | PA08 or PB16 | 4 or ? | 11 (SDA) or ? |
300-
| MCK[1] | PB10 | 23 (MOSI) | 4 |
301-
| SCK[1] | PB11 | 24 (SCK) | 5 |
302-
| FS[1] | PB12 | ? | ? |
303-
+--------+--------------+-----------+-----------------+
304-
*/
305-
306-
307-
I2SClass I2S(0, GCLK_CLKCTRL_GEN_GCLK3_Val, 9, 1, 0);
282+
void I2SClass::onDmaTransferComplete(int channel)
283+
{
284+
#if I2S_INTERFACES_COUNT > 0
285+
if (I2S._dmaChannel == channel) {
286+
I2S.onTransferComplete();
287+
}
288+
#endif
289+
}
308290

309-
// I2SClass I2S(0, GCLK_CLKCTRL_GEN_GCLK3_Val, A6, 2, 3);
291+
#if I2S_INTERFACES_COUNT > 0
292+
I2SClass I2S(I2S_DEVICE, I2S_CLOCK_GENERATOR, PIN_I2S_SD, PIN_I2S_SCK, PIN_I2S_FS);
293+
#endif

libraries/I2S/src/I2S.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class I2SClass : public Stream
5858
void enableClock(int divider);
5959
void disableClock();
6060

61-
static void onDmaTransferComplete(int);
62-
6361
void onTransferComplete(void);
6462

63+
static void onDmaTransferComplete(int);
64+
6565
private:
6666
static int _beginCount;
6767

@@ -81,6 +81,8 @@ class I2SClass : public Stream
8181

8282
#undef I2S
8383

84+
#if I2S_INTERFACES_COUNT > 0
8485
extern I2SClass I2S;
86+
#endif
8587

8688
#endif

variants/arduino_zero/variant.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ static const uint8_t SCL = PIN_WIRE_SCL;
161161
#define PIN_USB_DM (28ul)
162162
#define PIN_USB_DP (29ul)
163163

164+
/*
165+
* I2S Interfaces
166+
*/
167+
#define I2S_INTERFACES_COUNT 1
168+
169+
#define I2S_DEVICE 0
170+
#define I2S_CLOCK_GENERATOR 3
171+
#define PIN_I2S_SD (9u)
172+
#define PIN_I2S_SCK (1u)
173+
#define PIN_I2S_FS (0u)
174+
164175
#ifdef __cplusplus
165176
}
166177
#endif

variants/mkr1000/variant.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ static const uint8_t SCL = PIN_WIRE_SCL;
135135
#define PIN_USB_DP (23ul)
136136
#define PIN_USB_HOST_ENABLE (24ul)
137137

138+
// I2S Interfaces
139+
// --------------
140+
#define I2S_INTERFACES_COUNT 1
141+
142+
#define I2S_DEVICE 0
143+
#define I2S_CLOCK_GENERATOR 3
144+
#define PIN_I2S_SD (PIN_A6)
145+
#define PIN_I2S_SCK (2u)
146+
#define PIN_I2S_FS (3u)
147+
138148
// Needed for WINC1501B (WiFi101) library
139149
// --------------------------------------
140150
#define WINC1501_RESET_PIN (30u)

0 commit comments

Comments
 (0)