-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (64 loc) · 1.76 KB
/
Copy pathmain.cpp
File metadata and controls
76 lines (64 loc) · 1.76 KB
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
#include <Audio.h>
#include <SPI.h>
const unsigned char CS1 = 31;
const unsigned char SCK1 = 32;
const unsigned char MOSI1 = 0;
// GUItool: begin automatically generated code
AudioInputUSB usb1; //xy=105,92
AudioOutputI2S i2s1; //xy=270,87
AudioConnection patchCord1(usb1, 0, i2s1, 0);
AudioConnection patchCord2(usb1, 1, i2s1, 1);
// GUItool: end automatically generated code
void setup()
{
// put your setup code here, to run once:
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(24);
}
void writeReg(unsigned char address, unsigned char value)
{
SPI1.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
// take the SS pin low to select the chip:
digitalWrite(CS1, LOW);
delay(1);
// send in the address and value via SPI:
SPI1.transfer(address);
SPI1.transfer(value);
// take the SS pin high to de-select the chip:
digitalWrite(CS1, HIGH);
// release control of the SPI port
SPI1.endTransaction();
delay(1);
}
void loop()
{
// put your main code here, to run repeatedly:
pinMode(CS1, OUTPUT);
SPI1.begin();
delay(100);
writeReg(0b01100000, 0b10001110); //Reset
writeReg(0b01100000, 0b10001111); //Enable I2S data format on AK4381
//delay(1);
//writeReg(0b11100000, 0b10010110); //Enable I2S data format on AK4355
//writeReg(0b11100000, 0b10010111); //Enable I2S data format on AK4355
writeReg(0b01100011, 40);
writeReg(0b01100100, 40);
while (1)
{
if (AudioInputUSB::features.change)
{
AudioInputUSB::features.change = 0;
unsigned char vol = AudioInputUSB::features.volume / 32;
if (AudioInputUSB::features.mute) vol = 0;
writeReg(0b01100011, vol);
writeReg(0b01100100, vol);
//delay(1);
}
}
}
void abort()
{
while (1)
;
}