-
Notifications
You must be signed in to change notification settings - Fork 5
/
Alislahish_PCM1808.cpp
154 lines (135 loc) · 4.02 KB
/
Alislahish_PCM1808.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**********************************************************************
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
**********************************************************************/
#include "Alislahish_PCM1808.h"
Alislahish_PCM1808::Alislahish_PCM1808(){}
/**
* constructor using pins
*/
Alislahish_PCM1808::Alislahish_PCM1808(uint8_t FMTpin, uint8_t MD1pin, uint8_t MD0pin, uint8_t SCKIMASKpin,
uint8_t LRCKpin, uint8_t BCKpin, uint8_t DINpin)
: _FMTpin(FMTpin),
_MD1pin(MD1pin),
_MD0pin(MD0pin),
_SCKIMASKpin(SCKIMASKpin),
_LRCKpin(LRCKpin),
_BCKpin(BCKpin),
_DINpin(DINpin)
{
}
/**
* use appropriate hardware pins to choose a sampling frequency
*/
// Alislahish_PCM1808::selectSamplingFrequency(PCMSamplingFrequencies freq){}
/**
* use to select the interface mode...
* when adding slave PCM1808s with an existing master,
* conserve pins by hardwiring MD1 and MD2, or connecting multiple
* PCM1808s to the same bus
*/
void Alislahish_PCM1808::selectMode(InterfaceModes mode){
_mode = mode;
setPins();
}
/**
* use to choose the audio data output format
*/
void Alislahish_PCM1808::selectFormat(AudioInterfaceFormats format){
_format = format;
setPins();
}
/**
* getters
*/
InterfaceModes Alislahish_PCM1808::getMode(){ return _mode; }
AudioInterfaceFormats Alislahish_PCM1808::getFormat(){ return _format; }
/**
* begin sampling at a default (Master 256) interface mode and default I2S data format
*/
void Alislahish_PCM1808::begin(){
begin(InterfaceModes::MASTER_384, AudioInterfaceFormats::I2S);
}
/**
* begin sampling at given interface mode
*/
void Alislahish_PCM1808::begin(InterfaceModes mode, AudioInterfaceFormats format){
setPinModes();
//selectSamplingFrequency(freq);
selectMode(mode);
selectFormat(format);
resume();
}
/**
* halt the SCKI signal to initiate power down and reset
*/
void Alislahish_PCM1808::powerDownAndReset(){
ICUsingMCP23017::digitalWrite(_SCKIMASKpin, LOW);
_isConverting=false;
}
/**
* is the PCM1808 currently making ADC conversions?
*/
bool Alislahish_PCM1808::isConverting(){
return _isConverting;
}
/**
* resume the SCKI signal
*/
void Alislahish_PCM1808::resume(){
ICUsingMCP23017::digitalWrite(_SCKIMASKpin, HIGH);
_isConverting=true;
}
/**
* set hardware pin modes
*/
void Alislahish_PCM1808::setPinModes(){
ICUsingMCP23017::pinMode(_FMTpin, OUTPUT);
ICUsingMCP23017::pinMode(_MD1pin, OUTPUT);
ICUsingMCP23017::pinMode(_MD0pin, OUTPUT);
ICUsingMCP23017::pinMode(_SCKIMASKpin, OUTPUT);
}
/**
* set hardware pins to current operating mode
*/
void Alislahish_PCM1808::setPins(){
//interface mode
switch(_mode){
case InterfaceModes::SLAVE:
ICUsingMCP23017::digitalWrite(_MD1pin, LOW);
ICUsingMCP23017::digitalWrite(_MD0pin, LOW);
break;
case InterfaceModes::MASTER_512:
ICUsingMCP23017::digitalWrite(_MD1pin, LOW);
ICUsingMCP23017::digitalWrite(_MD0pin, HIGH);
break;
case InterfaceModes::MASTER_384:
ICUsingMCP23017::digitalWrite(_MD1pin, HIGH);
ICUsingMCP23017::digitalWrite(_MD0pin, LOW);
break;
case InterfaceModes::MASTER_256:
ICUsingMCP23017::digitalWrite(_MD1pin, HIGH);
ICUsingMCP23017::digitalWrite(_MD0pin, HIGH);
break;
}
//audio data format
switch(_format){
case AudioInterfaceFormats::I2S:
ICUsingMCP23017::digitalWrite(_FMTpin, LOW);
break;
case AudioInterfaceFormats::LEFT:
ICUsingMCP23017::digitalWrite(_FMTpin, HIGH);
break;
}
}