-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathI2S.h
58 lines (48 loc) · 1.75 KB
/
I2S.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
This file is part of the Arduino_AdvancedAnalog library.
Copyright (c) 2024 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __I2S_H__
#define __I2S_H__
#include "r_i2s_api.h"
#include "r_ssi.h"
#include "pwm.h"
#include "api/DMAPool.h"
typedef uint16_t Sample;
typedef DMABuffer<Sample> &SampleBuffer;
enum {
I2S_MODE_IN = (1U << 0U),
I2S_MODE_OUT = (1U << 1U),
I2S_MODE_INOUT = (I2S_MODE_IN | I2S_MODE_OUT),
};
class I2SClass {
private:
uint32_t i2s_mode;
int start_transfer();
public:
DMABuffer<Sample> *tx_buf;
DMABuffer<Sample> *rx_buf;
DMAPool<Sample> *tx_pool;
DMAPool<Sample> *rx_pool;
I2SClass(): tx_buf(nullptr), rx_buf(nullptr), tx_pool(nullptr), rx_pool(nullptr) {
}
bool available();
SampleBuffer read();
SampleBuffer dequeue();
void write(SampleBuffer buf);
int begin(uint32_t i2s_mode, uint32_t sample_rate, size_t n_samples, size_t n_buffers);
int stop();
};
extern I2SClass I2S;
#endif // __I2S_H__