forked from W4D/soundcube-firmware
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 686f76b0fd | |||
| 499d5f2c63 | |||
| c9b6220449 | |||
| 235603d47a | |||
| a16ac73d9b | |||
| ad9c71363b | |||
| 8691bc05eb | |||
| 6ceefa6705 | |||
| ab0dbe98a1 | |||
| 202b862280 | |||
| 4b728fffd0 | |||
| 559d92e526 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
build
|
||||||
45
README.md
Normal file
45
README.md
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Soundcube Firmware
|
||||||
|
|
||||||
|
## Install new firmware
|
||||||
|
|
||||||
|
1. Go to [Releases](https://code.w4d.dev/W4D/soundcube-firmware/releases)
|
||||||
|
2. Download latest `soundcube-firmware.ino.uf2` file
|
||||||
|
3. On your Soundcube Board: Press and hold the outer most white button as seen from the USB-C socket
|
||||||
|
4. While holding the button press the inner most white button once
|
||||||
|
- the board will go into bootloader mode and appear as USB thumb drive
|
||||||
|
6. Copy the `soundcube-firmware.ino.uf2` file to the thumb drive and wait for the board to restart
|
||||||
|
|
||||||
|
## config.txt
|
||||||
|
|
||||||
|
Json formatted config file. For now only edge led color working.
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"edge": {
|
||||||
|
"color":{
|
||||||
|
"r":50,
|
||||||
|
"g":0,
|
||||||
|
"b":0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## click.wav (not played correctly)
|
||||||
|
|
||||||
|
Put a file called `click.wav` (not longer than a few seconds) in the root of the SD card and it will play when you press a button.
|
||||||
|
|
||||||
|
|
||||||
|
## Code something yourself
|
||||||
|
|
||||||
|
1. Download [Arduino IDE](https://www.arduino.cc/en/software/)
|
||||||
|
2. Install and open "Preferences"
|
||||||
|
3. Follow these [instructions](https://github.com/earlephilhower/arduino-pico?tab=readme-ov-file#installation)
|
||||||
|
- No need to change checkboxes, only paste the URL and hit OK.
|
||||||
|
4. Install **Raspberry Pi Pico** boards ([HowTo install boards](https://support.arduino.cc/hc/en-us/articles/360016119519-Add-boards-to-Arduino-IDE))
|
||||||
|
5. Install libraries ([HowTo install libraries](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-installing-a-library/)): Adafruit Neopixel, AS5600 (Rob Tillaart), TCA9555 (Rob Tillaart)
|
||||||
|
6. Choose **Generic RP2350** as board and the correct port (Mac: /dev/cu.usbmodemXXXX, PC: COMXX Serial Port)
|
||||||
|
7. Go to **Tools -> Flash Size** and choose **16MB (no FS)**
|
||||||
|
8. Make your changes in the code
|
||||||
|
9. Hit Upload Button (Arduino IDE compiles and uploads it automatically)
|
||||||
|
|
||||||
@ -1,186 +1,259 @@
|
|||||||
#include <TCA9555.h>
|
#include <ArduinoJson.h>
|
||||||
#include <AS5600.h>
|
#include <ArduinoJson.hpp>
|
||||||
#include <Adafruit_NeoPixel.h>
|
|
||||||
#include <PWMAudio.h>
|
#include <TCA9555.h>
|
||||||
#include <I2S.h>
|
#include <AS5600.h>
|
||||||
|
#include <FastLED.h>
|
||||||
#define HAPTIC 0
|
#include <PWMAudio.h>
|
||||||
#define AURAL 0
|
#include <I2S.h>
|
||||||
#define UI_SAMPLERATE 22050
|
#include <SPI.h>
|
||||||
|
#include <SD.h>
|
||||||
I2S i2s(INPUT_PULLUP);
|
|
||||||
|
#define HAPTIC 1
|
||||||
TCA9555 TCA(0x20, &Wire1);
|
#define AURAL 1
|
||||||
AS5600 ENC(&Wire1);
|
#define UI_SAMPLERATE 22050
|
||||||
|
|
||||||
PWMAudio ui_snd(8);
|
I2S i2s(INPUT_PULLUP);
|
||||||
|
|
||||||
enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
TCA9555 TCA(0x20, &Wire1);
|
||||||
|
AS5600 ENC(&Wire1);
|
||||||
Adafruit_NeoPixel edge_pixels(8, 4, NEO_GRB + NEO_KHZ800);
|
|
||||||
Adafruit_NeoPixel ui_pixels(72, 5, NEO_GRB + NEO_KHZ800);
|
PWMAudio ui_snd(8);
|
||||||
|
|
||||||
volatile bool flag = false;
|
enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
||||||
volatile bool click = false;
|
|
||||||
volatile bool amp = false;
|
CRGB ui_leds[74];
|
||||||
|
CRGB edge_leds[11];
|
||||||
int counter = 0;
|
|
||||||
|
volatile bool flag = false;
|
||||||
bool buttons[16] = {false};
|
volatile bool click = false;
|
||||||
|
volatile bool amp = false;
|
||||||
int16_t beep[UI_SAMPLERATE];
|
|
||||||
|
int counter = 0;
|
||||||
void pwm_audio_callback() {
|
|
||||||
while (ui_snd.availableForWrite()) {
|
bool buttons[16] = {false};
|
||||||
if(click) {
|
|
||||||
ui_snd.write(beep[counter]);
|
int16_t beep[UI_SAMPLERATE];
|
||||||
} else {
|
uint16_t beep_length = 0;
|
||||||
ui_snd.write(0);
|
|
||||||
}
|
bool sd_card_detected = false;
|
||||||
counter++;
|
|
||||||
if(counter == UI_SAMPLERATE) counter = 0;
|
struct Config {
|
||||||
}
|
int edge_color_r = 0;
|
||||||
}
|
int edge_color_g = 0;
|
||||||
|
int edge_color_b = 50;
|
||||||
void tca_irq() {
|
};
|
||||||
flag = true;
|
|
||||||
}
|
Config config;
|
||||||
|
|
||||||
void setup() {
|
void loadConfiguration(Config& config) {
|
||||||
|
File file = SD.open("/config.txt");
|
||||||
for(int i = 0; i < UI_SAMPLERATE; i++){
|
JsonDocument doc;
|
||||||
float sine_pos = (2.0f * M_PI * 8000.0f * (float)i) / (float)UI_SAMPLERATE;
|
|
||||||
beep[i] = (int16_t)(sin(sine_pos) * 8000.0f);
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
}
|
if(error) Serial.println(F("Failed to read file, using default configuration"));
|
||||||
|
|
||||||
Serial.begin();
|
config.edge_color_r = doc["edge"]["color"]["r"] | 0;
|
||||||
delay(2000);
|
config.edge_color_g = doc["edge"]["color"]["g"] | 0;
|
||||||
|
config.edge_color_b = doc["edge"]["color"]["b"] | 50;
|
||||||
Serial.println("INIT WIRE");
|
|
||||||
Wire1.setSDA(2);
|
//strlcpy(config.hostname, doc["hostname"] | "example.com", sizeof(config.hostname));
|
||||||
Wire1.setSCL(3);
|
|
||||||
Wire1.begin();
|
file.close();
|
||||||
Serial.println("SUCCESS");
|
}
|
||||||
|
|
||||||
Serial.println("INIT TCA");
|
void pwm_audio_callback() {
|
||||||
TCA.begin();
|
while (ui_snd.availableForWrite()) {
|
||||||
TCA.pinMode16(0xFFFF);
|
if(click) {
|
||||||
TCA.setPolarity16(0x0000);
|
ui_snd.write(beep[counter]);
|
||||||
Serial.println("SUCCESS");
|
counter++;
|
||||||
|
if(counter == beep_length) {
|
||||||
Serial.println("INIT INTERRUPT");
|
counter = 0;
|
||||||
pinMode(1, INPUT_PULLUP);
|
click = false;
|
||||||
attachInterrupt(digitalPinToInterrupt(1), tca_irq, FALLING);
|
}
|
||||||
Serial.println("SUCCESS");
|
} else {
|
||||||
|
digitalWrite(7, LOW);
|
||||||
// Rotary Encoder
|
ui_snd.write(0);
|
||||||
ENC.begin(4); // set direction pin.
|
counter = 0;
|
||||||
|
}
|
||||||
pinMode(6, OUTPUT); // Vibration Motor
|
}
|
||||||
pinMode(7, OUTPUT); // UI Amp Enable
|
}
|
||||||
|
|
||||||
ui_snd.onTransmit(pwm_audio_callback);
|
void tca_irq() {
|
||||||
ui_snd.begin(UI_SAMPLERATE);
|
flag = true;
|
||||||
|
}
|
||||||
digitalWrite(7, LOW);
|
|
||||||
|
void setup() {
|
||||||
edge_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
Serial.begin();
|
||||||
ui_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
delay(2000);
|
||||||
|
|
||||||
// i2s.setDOUT(14);
|
FastLED.addLeds<NEOPIXEL, 4>(edge_leds, 11);
|
||||||
// i2s.setDIN(15);
|
FastLED.addLeds<NEOPIXEL, 5>(ui_leds, 74);
|
||||||
// i2s.setBCLK(16); //
|
|
||||||
// i2s.swapClocks();
|
pinMode(21, INPUT_PULLUP);
|
||||||
// i2s.setMCLK(18);
|
sd_card_detected = !digitalRead(21);
|
||||||
// i2s.setBitsPerSample(16);
|
delay(500);
|
||||||
// i2s.setFrequency(48000);
|
|
||||||
// i2s.setSysClk(48000);
|
bool sdInitialized = SD.begin(22, 23, 24);
|
||||||
// i2s.begin();
|
delay(100);
|
||||||
|
if(!sdInitialized) sdInitialized = SD.begin(22, 23, 24); // hack to prevent SD card from not initializing after soft reset
|
||||||
// while (1) {
|
|
||||||
// int16_t l, r;
|
if(sdInitialized) loadConfiguration(config);
|
||||||
// i2s.read16(&l, &r);
|
|
||||||
// i2s.write16(l, r);
|
if(sdInitialized && SD.exists("/click.wav")) {
|
||||||
// }
|
File click = SD.open("/click.wav");
|
||||||
}
|
int click_bytes = 0;
|
||||||
int active = 0;
|
int16_t maxv = 0;
|
||||||
uint32_t lastTime = 0;
|
while (click.available() || click_bytes == UI_SAMPLERATE-1) {
|
||||||
int32_t position = 0;
|
int16_t sample = click.read() * 32;
|
||||||
|
if(abs(sample) > maxv) maxv = sample;
|
||||||
void loop() {
|
beep[click_bytes] = sample;
|
||||||
edge_pixels.clear(); // Set all pixel colors to 'off'
|
click_bytes++;
|
||||||
ui_pixels.clear(); // Set all pixel colors to 'off'
|
}
|
||||||
|
click.close();
|
||||||
position = ENC.getCumulativePosition();
|
|
||||||
|
beep_length = click_bytes;
|
||||||
// if (millis() - lastTime >= 100)
|
Serial.print("Read ");
|
||||||
// {
|
Serial.print(beep_length);
|
||||||
// lastTime = millis();
|
Serial.print(" bytes from click.wav into beep array. maxV was ");
|
||||||
// Serial.print(ENC.getCumulativePosition());
|
Serial.println(maxv);
|
||||||
// Serial.print("\t");
|
} else {
|
||||||
// Serial.println(ENC.getRevolutions());
|
for(int i = 0; i < UI_SAMPLERATE; i++){
|
||||||
// }
|
float sine_pos = (2.0f * M_PI * 8000.0f * (float)i) / (float)UI_SAMPLERATE;
|
||||||
|
beep[i] = (int16_t)(sin(sine_pos) * 8000.0f);
|
||||||
for (int i = 0; i < 48; i++) {
|
}
|
||||||
ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 0, 0));
|
Serial.println("Synthesized 8kHz sine into beep array.");
|
||||||
}
|
beep_length = UI_SAMPLERATE;
|
||||||
|
}
|
||||||
if (flag) {
|
|
||||||
int val = TCA.read16();
|
Serial.println("INIT WIRE");
|
||||||
Serial.println(val, BIN);
|
Wire1.setSDA(2);
|
||||||
|
Wire1.setSCL(3);
|
||||||
for(int i = 0; i < 16; i++){
|
Wire1.begin();
|
||||||
buttons[i] = ~(val >> i) & 0x01;
|
Serial.println("SUCCESS");
|
||||||
Serial.print(buttons[i]);
|
|
||||||
Serial.print(" ");
|
Serial.println("INIT TCA");
|
||||||
}
|
TCA.begin();
|
||||||
Serial.println();
|
TCA.pinMode16(0xFFFF);
|
||||||
|
TCA.setPolarity16(0x0000);
|
||||||
flag = false;
|
Serial.println("SUCCESS");
|
||||||
if (HAPTIC) {
|
|
||||||
digitalWrite(6, HIGH);
|
Serial.println("INIT INTERRUPT");
|
||||||
}
|
pinMode(1, INPUT_PULLUP);
|
||||||
if (AURAL) {
|
attachInterrupt(digitalPinToInterrupt(1), tca_irq, FALLING);
|
||||||
digitalWrite(7, HIGH);
|
Serial.println("SUCCESS");
|
||||||
click = true;
|
|
||||||
delay(50);
|
// Rotary Encoder
|
||||||
click = false;
|
ENC.begin(); // set direction pin.
|
||||||
digitalWrite(7, LOW);
|
ENC.setDirection(AS5600_COUNTERCLOCK_WISE);
|
||||||
}
|
|
||||||
if(HAPTIC){
|
pinMode(6, OUTPUT); // Vibration Motor
|
||||||
if(!AURAL) delay(50);
|
pinMode(7, OUTPUT); // UI Amp Enable
|
||||||
digitalWrite(6, LOW);
|
|
||||||
}
|
ui_snd.onTransmit(pwm_audio_callback);
|
||||||
for (int i = 0; i < 48; i++) {
|
ui_snd.begin(UI_SAMPLERATE);
|
||||||
ui_pixels.setPixelColor(i + 3, edge_pixels.Color(0, 15, 0));
|
|
||||||
}
|
digitalWrite(7, LOW);
|
||||||
if(buttons[RIGHT]) active++;
|
|
||||||
if(buttons[LEFT]) active--;
|
digitalWrite(6, HIGH);
|
||||||
if(active == 13) active = 0;
|
delay(50);
|
||||||
if(active == -1) active = 12;
|
digitalWrite(6, LOW);
|
||||||
}
|
|
||||||
// 11111110 11111111 button right
|
// i2s.setDOUT(14);
|
||||||
|
// i2s.setDIN(15);
|
||||||
// EDGE LEDs
|
// i2s.setBCLK(16); //
|
||||||
for (int i = 0; i < 8; i++) {
|
// i2s.swapClocks();
|
||||||
edge_pixels.setPixelColor(i, edge_pixels.Color(15, 15, 15));
|
// i2s.setMCLK(18);
|
||||||
}
|
// i2s.setBitsPerSample(16);
|
||||||
|
// i2s.setFrequency(48000);
|
||||||
// Rotary button LEDs
|
// i2s.setSysClk(48000);
|
||||||
ui_pixels.setPixelColor(0, edge_pixels.Color(0, 0, 15));
|
// i2s.begin();
|
||||||
ui_pixels.setPixelColor(1, edge_pixels.Color(0, 0, 15));
|
|
||||||
ui_pixels.setPixelColor(2, edge_pixels.Color(0, 0, 15));
|
// while (1) {
|
||||||
|
// int16_t l, r;
|
||||||
for (int i = 0; i < 13; i++) {
|
// i2s.read16(&l, &r);
|
||||||
ui_pixels.setPixelColor(i + 3 + 48 + 4, edge_pixels.Color(0, 0, 0));
|
// i2s.write16(l, r);
|
||||||
}
|
// }
|
||||||
|
}
|
||||||
ui_pixels.setPixelColor(active + 3 + 48 + 4, edge_pixels.Color(255, 255, 255));
|
|
||||||
|
int active = 0;
|
||||||
// put your main code here, to run repeatedly:
|
int active_led_ring = 0;
|
||||||
|
|
||||||
edge_pixels.show(); // Set all pixel colors to 'off'
|
uint32_t lastTime = 0;
|
||||||
ui_pixels.show(); // Set all pixel colors to 'off'
|
int32_t position = 0;
|
||||||
|
|
||||||
delay(1);
|
void loop() {
|
||||||
|
position = ENC.getCumulativePosition();
|
||||||
|
|
||||||
|
sd_card_detected = !digitalRead(21);
|
||||||
|
if(sd_card_detected) edge_leds[8] = CRGB(0,25,0);
|
||||||
|
if(!sd_card_detected) edge_leds[8] = CRGB(25,0,0);
|
||||||
|
|
||||||
|
// EDGE LEDs
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
edge_leds[i] = CRGB(config.edge_color_r, config.edge_color_g, config.edge_color_b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// LED Ring leeren
|
||||||
|
for (int i = 0; i < 48; i++) {
|
||||||
|
ui_leds[i + 3] = CRGB(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// flag = true when a button is pushed
|
||||||
|
if (flag) {
|
||||||
|
int val = TCA.read16();
|
||||||
|
|
||||||
|
for(int i = 0; i < 16; i++){
|
||||||
|
buttons[i] = ~(val >> i) & 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make vibration
|
||||||
|
if (HAPTIC) {
|
||||||
|
digitalWrite(6, HIGH);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(6, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make beep
|
||||||
|
if (AURAL) {
|
||||||
|
digitalWrite(7, HIGH);
|
||||||
|
click = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flash led ring
|
||||||
|
for (int i = 0; i < 48; i++) {
|
||||||
|
ui_leds[i + 3] = CRGB(0, 15, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch through LED matrix
|
||||||
|
if(buttons[RIGHT]) active++;
|
||||||
|
if(buttons[LEFT]) active--;
|
||||||
|
if(active == 13) active = 0;
|
||||||
|
if(active == -1) active = 12;
|
||||||
|
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotary button LEDs
|
||||||
|
ui_leds[0] = CRGB(0, 0, 15);
|
||||||
|
ui_leds[1] = CRGB(0, 0, 15);
|
||||||
|
ui_leds[2] = CRGB(0, 0, 15);
|
||||||
|
|
||||||
|
// empty LED matrix
|
||||||
|
for (int i = 0; i < 13; i++) {
|
||||||
|
ui_leds[i + 3 + 48 + 4] = CRGB(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set active LED matrix LED
|
||||||
|
ui_leds[active + 3 + 48 + 4] = CRGB(255, 255, 255);
|
||||||
|
|
||||||
|
if(position < 0) position += 4096;
|
||||||
|
active_led_ring = (position / 32) % 48;
|
||||||
|
|
||||||
|
// set active LED ring LED
|
||||||
|
ui_leds[active_led_ring + 3] = CRGB(255, 255, 255);
|
||||||
|
|
||||||
|
FastLED.show();
|
||||||
|
|
||||||
|
delay(1); // wait 1ms
|
||||||
}
|
}
|
||||||
@ -1,125 +1,125 @@
|
|||||||
/*
|
/*
|
||||||
I2S bi-directional input and output buffered loopback example
|
I2S bi-directional input and output buffered loopback example
|
||||||
Released to the Public Domain by Cooper Dalrymple
|
Released to the Public Domain by Cooper Dalrymple
|
||||||
*/
|
*/
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <I2S.h>
|
#include <I2S.h>
|
||||||
|
|
||||||
I2S i2s(INPUT_PULLUP);
|
I2S i2s(INPUT_PULLUP);
|
||||||
|
|
||||||
#define SIZE 256
|
#define SIZE 256
|
||||||
int16_t buffer[SIZE];
|
int16_t buffer[SIZE];
|
||||||
|
|
||||||
void cw(char first, char second){
|
void cw(char first, char second){
|
||||||
Wire1.beginTransmission(0x18);
|
Wire1.beginTransmission(0x18);
|
||||||
Wire1.write(first);
|
Wire1.write(first);
|
||||||
Wire1.write(second);
|
Wire1.write(second);
|
||||||
Wire1.endTransmission();
|
Wire1.endTransmission();
|
||||||
delay(5);
|
delay(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
Wire1.setSDA(2);
|
Wire1.setSDA(2);
|
||||||
Wire1.setSCL(3);
|
Wire1.setSCL(3);
|
||||||
Wire1.begin();
|
Wire1.begin();
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
// GENERAL
|
// GENERAL
|
||||||
cw(0x00, 0x00);
|
cw(0x00, 0x00);
|
||||||
cw(0x01, 0x01);
|
cw(0x01, 0x01);
|
||||||
cw(0x1b, 0x10); // select I2S
|
cw(0x1b, 0x10); // select I2S
|
||||||
|
|
||||||
// ADC
|
// ADC
|
||||||
cw(0x00, 0x00); // select page 0
|
cw(0x00, 0x00); // select page 0
|
||||||
//cw(0x01, 0x01); // soft reset
|
//cw(0x01, 0x01); // soft reset
|
||||||
cw(0x12, 0x87); // NADC 7
|
cw(0x12, 0x87); // NADC 7
|
||||||
cw(0x13, 0x82); // MADC 2
|
cw(0x13, 0x82); // MADC 2
|
||||||
cw(0x14, 0x80); // OSR ADC 128
|
cw(0x14, 0x80); // OSR ADC 128
|
||||||
cw(0x3d, 0x01); // ADC PRB_R1
|
cw(0x3d, 0x01); // ADC PRB_R1
|
||||||
|
|
||||||
cw(0x00, 0x01); // select page 1
|
cw(0x00, 0x01); // select page 1
|
||||||
cw(0x01, 0x08); // disable crude AVdd
|
cw(0x01, 0x08); // disable crude AVdd
|
||||||
cw(0x02, 0x01); // enable internal AVdd LDO
|
cw(0x02, 0x01); // enable internal AVdd LDO
|
||||||
cw(0x0a, 0x0B); // set input CM to 0.9V and LO to 1.65V
|
cw(0x0a, 0x0B); // set input CM to 0.9V and LO to 1.65V
|
||||||
cw(0x3d, 0x00); // ADC PTM_R4
|
cw(0x3d, 0x00); // ADC PTM_R4
|
||||||
cw(0x34, 0x80); // route IN1L to LEFT_P with 20k input impedance
|
cw(0x34, 0x80); // route IN1L to LEFT_P with 20k input impedance
|
||||||
cw(0x36, 0x80); // route CM to LEFT_M with 20k input impedance
|
cw(0x36, 0x80); // route CM to LEFT_M with 20k input impedance
|
||||||
cw(0x37, 0x80); // route IN1R to RIGHT_P with 20k input impedance
|
cw(0x37, 0x80); // route IN1R to RIGHT_P with 20k input impedance
|
||||||
cw(0x39, 0x80); // route CM to RIGHT_M with 20k input impedance
|
cw(0x39, 0x80); // route CM to RIGHT_M with 20k input impedance
|
||||||
cw(0x3b, 0x0c); // unmute left MICPGA
|
cw(0x3b, 0x0c); // unmute left MICPGA
|
||||||
cw(0x3c, 0x0c); // unmute right MICPGA
|
cw(0x3c, 0x0c); // unmute right MICPGA
|
||||||
|
|
||||||
cw(0x00, 0x00); // select page 0
|
cw(0x00, 0x00); // select page 0
|
||||||
cw(0x51, 0xc0); // power up ADC
|
cw(0x51, 0xc0); // power up ADC
|
||||||
cw(0x51, 0x00); // unmute ADC digital volume control
|
cw(0x51, 0x00); // unmute ADC digital volume control
|
||||||
|
|
||||||
// DAC
|
// DAC
|
||||||
cw(0x00, 0x00); // select page 0
|
cw(0x00, 0x00); // select page 0
|
||||||
//cw(0x01, 0x01); // software reset
|
//cw(0x01, 0x01); // software reset
|
||||||
cw(0x0b, 0x82); // NDAC 2
|
cw(0x0b, 0x82); // NDAC 2
|
||||||
cw(0x0c, 0x87); // MDAC 7
|
cw(0x0c, 0x87); // MDAC 7
|
||||||
cw(0x0d, 0x00); // OSR DAC 128
|
cw(0x0d, 0x00); // OSR DAC 128
|
||||||
cw(0x0e, 0x80); // OSR DAC 128
|
cw(0x0e, 0x80); // OSR DAC 128
|
||||||
cw(0x1b, 0x10); // world length 20bits PTM_P4 (highest performance)
|
cw(0x1b, 0x10); // world length 20bits PTM_P4 (highest performance)
|
||||||
cw(0x3c, 0x08); // PRB_P8
|
cw(0x3c, 0x08); // PRB_P8
|
||||||
|
|
||||||
cw(0x00, 0x01); // select page 1
|
cw(0x00, 0x01); // select page 1
|
||||||
//cw(0x01, 0x08); // disable internal crude avdd
|
//cw(0x01, 0x08); // disable internal crude avdd
|
||||||
//cw(0x02, 0x01); // enable AVdd LDO
|
//cw(0x02, 0x01); // enable AVdd LDO
|
||||||
cw(0x7b, 0x01); // set REF charging time to 40ms
|
cw(0x7b, 0x01); // set REF charging time to 40ms
|
||||||
//cw(0x14, 0x25); // set HP soft stepping for anti pop
|
//cw(0x14, 0x25); // set HP soft stepping for anti pop
|
||||||
//cw(0x0a, 0x0B); // set input CM to 0.9V and LO to 1.65V
|
//cw(0x0a, 0x0B); // set input CM to 0.9V and LO to 1.65V
|
||||||
cw(0x0e, 0x08); // left DAC reconstruction filter routed to LOL
|
cw(0x0e, 0x08); // left DAC reconstruction filter routed to LOL
|
||||||
cw(0x0f, 0x08); // right DAC reconstruction filter routed to LOR
|
cw(0x0f, 0x08); // right DAC reconstruction filter routed to LOR
|
||||||
cw(0x03, 0x00); // DAC PTM_P3/4
|
cw(0x03, 0x00); // DAC PTM_P3/4
|
||||||
cw(0x04, 0x00); // DAC PTM_P3/4
|
cw(0x04, 0x00); // DAC PTM_P3/4
|
||||||
cw(0x12, 0x00); // LOL gain 0dB
|
cw(0x12, 0x00); // LOL gain 0dB
|
||||||
cw(0x13, 0x00); // LOR gain 0dB
|
cw(0x13, 0x00); // LOR gain 0dB
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
cw(0x00, 0x00); // select page 0
|
cw(0x00, 0x00); // select page 0
|
||||||
cw(0x3f, 0xd6); // power up and route left digital audio to left dac channel and right to right
|
cw(0x3f, 0xd6); // power up and route left digital audio to left dac channel and right to right
|
||||||
cw(0x40, 0x00); // unmute DAC digital volume
|
cw(0x40, 0x00); // unmute DAC digital volume
|
||||||
|
|
||||||
|
|
||||||
pinMode(19, OUTPUT); // MCLK enable
|
pinMode(19, OUTPUT); // MCLK enable
|
||||||
pinMode(20, OUTPUT); // CODEC reset
|
pinMode(20, OUTPUT); // CODEC reset
|
||||||
|
|
||||||
i2s.setSysClk(48000);
|
i2s.setSysClk(48000);
|
||||||
|
|
||||||
i2s.setDOUT(14);
|
i2s.setDOUT(14);
|
||||||
i2s.setDIN(15);
|
i2s.setDIN(15);
|
||||||
i2s.setBCLK(16); // Note: LRCLK = BCLK + 1
|
i2s.setBCLK(16); // Note: LRCLK = BCLK + 1
|
||||||
i2s.setMCLK(18);
|
i2s.setMCLK(18);
|
||||||
i2s.swapClocks();
|
i2s.swapClocks();
|
||||||
i2s.setBitsPerSample(16);
|
i2s.setBitsPerSample(16);
|
||||||
i2s.setFrequency(48000);
|
i2s.setFrequency(48000);
|
||||||
i2s.setMCLKmult(128); // 6144000Hz 6.144MHz
|
i2s.setMCLKmult(128); // 6144000Hz 6.144MHz
|
||||||
|
|
||||||
i2s.setBuffers(6, SIZE * sizeof(int16_t) / sizeof(uint32_t));
|
i2s.setBuffers(6, SIZE * sizeof(int16_t) / sizeof(uint32_t));
|
||||||
|
|
||||||
digitalWrite(19, HIGH); // enable MCLK
|
digitalWrite(19, HIGH); // enable MCLK
|
||||||
digitalWrite(20, HIGH);
|
digitalWrite(20, HIGH);
|
||||||
i2s.begin();
|
i2s.begin();
|
||||||
|
|
||||||
size_t count, index;
|
size_t count, index;
|
||||||
while (1) {
|
while (1) {
|
||||||
count = i2s.read((uint8_t *)&buffer, SIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t);
|
count = i2s.read((uint8_t *)&buffer, SIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t);
|
||||||
index = 0;
|
index = 0;
|
||||||
while (index < count) {
|
while (index < count) {
|
||||||
// Reduce volume by half
|
// Reduce volume by half
|
||||||
buffer[index++] >>= 1; // right
|
buffer[index++] >>= 1; // right
|
||||||
buffer[index++] >>= 1; // left
|
buffer[index++] >>= 1; // left
|
||||||
}
|
}
|
||||||
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
/* Nothing here */
|
/* Nothing here */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user