arduino-emulator
I2S.h
1 /*
2  Copyright (c) 2016 Arduino LLC. All right reserved.
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7  This library is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  See the GNU Lesser General Public License for more details.
11  You should have received a copy of the GNU Lesser General Public
12  License along with this library; if not, write to the Free Software
13  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14 */
15 
16 #ifndef _I2S_H_
17 #define _I2S_H_
18 
19 #include <Arduino.h>
20 
21 typedef enum {
22  I2S_PHILIPS_MODE,
23  I2S_RIGHT_JUSTIFIED_MODE,
24  I2S_LEFT_JUSTIFIED_MODE
25 } i2s_mode_t;
26 
27 class I2SClass : public Stream
28 {
29 public:
30  // the device index and pins must map to the "COM" pads in Table 6-1 of the datasheet
31  I2SClass(uint8_t deviceIndex, uint8_t clockGenerator, uint8_t sdPin, uint8_t sckPin, uint8_t fsPin){
32  create(deviceIndex,clockGenerator,sdPin,sckPin,fsPin );
33  }
34 
35  void create(uint8_t deviceIndex, uint8_t clockGenerator, uint8_t sdPin, uint8_t sckPin, uint8_t fsPin);
36 
37  // the SCK and FS pins are driven as outputs using the sample rate
38  int begin(int mode, long sampleRate, int bitsPerSample);
39  // the SCK and FS pins are inputs, other side controls sample rate
40  int begin(int mode, int bitsPerSample);
41  void end();
42 
43  // from Stream
44  virtual int available();
45  virtual int read();
46  virtual int peek();
47  virtual void flush();
48 
49  // from Print
50  virtual size_t write(uint8_t);
51  virtual size_t write(const uint8_t *buffer, size_t size);
52 
53  virtual int availableForWrite();
54 
55  int read(void* buffer, size_t size);
56 
57 // size_t write(int);
58  size_t write(int32_t);
59  size_t write(const void *buffer, size_t size);
60 
61 // void onTransmit(void(*)(void));
62 // void onReceive(void(*)(void));
63 
64  void setBufferSize(int bufferSize);
65 
66 
67 
68 
69 };
70 
71 extern I2SClass I2S;
72 
73 #endif
Definition: I2S.h:28