Skip to content

Commit 369450c

Browse files
committed
add support for left and right justified modes
1 parent cb94719 commit 369450c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

libraries/I2S/src/I2S.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ int I2SClass::begin(int mode, long sampleRate, int bitsPerSample, bool driveCloc
6363

6464
switch (mode) {
6565
case I2S_PHILIPS_MODE:
66+
case I2S_RIGHT_JUSTIFIED_MODE:
67+
case I2S_LEFT_JUSTIFIED_MODE:
6668
break;
6769

6870
default:
@@ -109,18 +111,26 @@ int I2SClass::begin(int mode, long sampleRate, int bitsPerSample, bool driveCloc
109111
}
110112

111113
i2sd.disable();
112-
i2sd.set1BitDelay(_deviceIndex);
114+
115+
if (mode == I2S_PHILIPS_MODE) {
116+
i2sd.set1BitDelay(_deviceIndex);
117+
} else {
118+
i2sd.set0BitDelay(_deviceIndex);
119+
}
113120
i2sd.setNumberOfSlots(_deviceIndex, 1);
114121
i2sd.setSlotSize(_deviceIndex, bitsPerSample);
115122

116123
pinPeripheral(_sckPin, PIO_COM);
117124
pinPeripheral(_fsPin, PIO_COM);
118125

119-
i2sd.setSlotAdjustedLeft(_deviceIndex);
120-
if (driveClock) {
121-
i2sd.setClockUnit(_deviceIndex);
126+
if (mode == I2S_RIGHT_JUSTIFIED_MODE) {
127+
i2sd.setSlotAdjustedRight(_deviceIndex);
128+
} else {
129+
i2sd.setSlotAdjustedLeft(_deviceIndex);
122130
}
123131

132+
i2sd.setClockUnit(_deviceIndex);
133+
124134
pinPeripheral(_sdPin, PIO_COM);
125135

126136
i2sd.enable();

libraries/I2S/src/I2S.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include "utility/I2SDoubleBuffer.h"
2525

2626
typedef enum {
27-
I2S_PHILIPS_MODE
27+
I2S_PHILIPS_MODE,
28+
I2S_RIGHT_JUSTIFIED_MODE,
29+
I2S_LEFT_JUSTIFIED_MODE
2830
} i2s_mode_t;
2931

3032
class I2SClass : public Stream

libraries/I2S/src/utility/SAMD21_I2SDevice.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class I2SDevice_SAMD21G18x {
6363
i2s.CLKCTRL[index].bit.FSSEL = I2S_CLKCTRL_FSSEL_FSPIN_Val;
6464
}
6565

66+
inline void set0BitDelay(int index) {
67+
i2s.CLKCTRL[index].bit.BITDELAY = I2S_CLKCTRL_BITDELAY_LJ_Val;
68+
}
69+
6670
inline void set1BitDelay(int index) {
6771
i2s.CLKCTRL[index].bit.BITDELAY = I2S_CLKCTRL_BITDELAY_I2S_Val;
6872
}
@@ -95,6 +99,10 @@ class I2SDevice_SAMD21G18x {
9599
}
96100
}
97101

102+
inline void setSlotAdjustedRight(int index) {
103+
i2s.SERCTRL[index].bit.SLOTADJ = I2S_SERCTRL_SLOTADJ_RIGHT_Val;
104+
}
105+
98106
inline void setSlotAdjustedLeft(int index) {
99107
i2s.SERCTRL[index].bit.SLOTADJ = I2S_SERCTRL_SLOTADJ_LEFT_Val;
100108
}

0 commit comments

Comments
 (0)