Skip to content

Commit 4d2bb9d

Browse files
committed
Merge remote-tracking branch 'origin/master' into staging
2 parents 0997a2e + 86081cb commit 4d2bb9d

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

libraries/I2S/keywords.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ I2S KEYWORD1
1111
#######################################
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
14-
begin KEYWORD2
15-
end KEYWORD2
14+
begin KEYWORD2
15+
end KEYWORD2
1616

17-
onReceive KEYWORD2
18-
onTransmit KEYWORD2
17+
onReceive KEYWORD2
18+
onTransmit KEYWORD2
19+
20+
setBufferSize KEYWORD2
1921

2022
#######################################
2123
# Constants (LITERAL1)
2224
#######################################
23-
I2S_PHILIPS_MODE LITERAL1
25+
I2S_PHILIPS_MODE LITERAL1
2426
I2S_RIGHT_JUSTIFIED_MODE LITERAL1
25-
I2S_LEFT_JUSTIFIED_MODE LITERAL1
27+
I2S_LEFT_JUSTIFIED_MODE LITERAL1

libraries/I2S/src/I2S.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ void I2SClass::onReceive(void(*function)(void))
396396
_onReceive = function;
397397
}
398398

399+
void I2SClass::setBufferSize(int bufferSize)
400+
{
401+
_doubleBuffer.setSize(bufferSize);
402+
}
403+
399404
void I2SClass::enableClock(int divider)
400405
{
401406
int div = SystemCoreClock / divider;

libraries/I2S/src/I2S.h

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "utility/I2SDoubleBuffer.h"
2525

26+
#define I2S_HAS_SET_BUFFER_SIZE 1
27+
2628
typedef enum {
2729
I2S_PHILIPS_MODE,
2830
I2S_RIGHT_JUSTIFIED_MODE,
@@ -62,6 +64,8 @@ class I2SClass : public Stream
6264
void onTransmit(void(*)(void));
6365
void onReceive(void(*)(void));
6466

67+
void setBufferSize(int bufferSize);
68+
6569
private:
6670
int begin(int mode, long sampleRate, int bitsPerSample, bool driveClock);
6771

libraries/I2S/src/utility/I2SDoubleBuffer.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19+
#include <stdlib.h>
1920
#include <string.h>
2021

2122
#include "I2SDoubleBuffer.h"
2223

23-
I2SDoubleBuffer::I2SDoubleBuffer()
24+
I2SDoubleBuffer::I2SDoubleBuffer() :
25+
_size(DEFAULT_I2S_BUFFER_SIZE)
2426
{
2527
reset();
2628
}
@@ -29,8 +31,16 @@ I2SDoubleBuffer::~I2SDoubleBuffer()
2931
{
3032
}
3133

34+
void I2SDoubleBuffer::setSize(int size)
35+
{
36+
_size = size;
37+
}
38+
3239
void I2SDoubleBuffer::reset()
3340
{
41+
_buffer[0] = (uint8_t*)realloc(_buffer[0], _size);
42+
_buffer[1] = (uint8_t*)realloc(_buffer[1], _size);
43+
3444
_index = 0;
3545
_length[0] = 0;
3646
_length[1] = 0;
@@ -40,7 +50,7 @@ void I2SDoubleBuffer::reset()
4050

4151
size_t I2SDoubleBuffer::availableForWrite()
4252
{
43-
return (I2S_BUFFER_SIZE - (_length[_index] - _readOffset[_index]));
53+
return (_size - (_length[_index] - _readOffset[_index]));
4454
}
4555

4656
size_t I2SDoubleBuffer::write(const void *buffer, size_t size)

libraries/I2S/src/utility/I2SDoubleBuffer.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222
#include <stddef.h>
2323
#include <stdint.h>
2424

25-
#define I2S_BUFFER_SIZE 512
25+
#define DEFAULT_I2S_BUFFER_SIZE 512
2626

2727
class I2SDoubleBuffer
2828
{
2929
public:
3030
I2SDoubleBuffer();
3131
virtual ~I2SDoubleBuffer();
3232

33+
void setSize(int size);
34+
3335
void reset();
3436

3537
size_t availableForWrite();
@@ -41,7 +43,8 @@ class I2SDoubleBuffer
4143
void swap(int length = 0);
4244

4345
private:
44-
uint8_t _buffer[2][I2S_BUFFER_SIZE];
46+
uint8_t* _buffer[2];
47+
int _size;
4548
volatile int _length[2];
4649
volatile int _readOffset[2];
4750
volatile int _index;

libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino

+2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ void loop() {
6363
void digitalPotWrite(int address, int value) {
6464
// take the SS pin low to select the chip:
6565
digitalWrite(slaveSelectPin, LOW);
66+
delay(100);
6667
// send in the address and value via SPI:
6768
SPI.transfer(address);
6869
SPI.transfer(value);
70+
delay(100);
6971
// take the SS pin high to de-select the chip:
7072
digitalWrite(slaveSelectPin, HIGH);
7173
}

0 commit comments

Comments
 (0)