forked from W4D/soundcube-firmware
trying out both cores - 1 for ui and 0 for sound - sound not working yet
This commit is contained in:
@ -13,6 +13,8 @@
|
|||||||
#include "codec.h"
|
#include "codec.h"
|
||||||
#include "wavestream.h"
|
#include "wavestream.h"
|
||||||
|
|
||||||
|
bool core1_separate_stack = true;
|
||||||
|
|
||||||
#define HAPTIC 1
|
#define HAPTIC 1
|
||||||
#define AURAL 1
|
#define AURAL 1
|
||||||
#define UI_SAMPLERATE 22050
|
#define UI_SAMPLERATE 22050
|
||||||
@ -65,10 +67,13 @@ volatile bool buttonChanged = false;
|
|||||||
bool ui_click = false;
|
bool ui_click = false;
|
||||||
bool ui_beep = false;
|
bool ui_beep = false;
|
||||||
bool amp = false;
|
bool amp = false;
|
||||||
bool streams_loaded = false;
|
volatile bool streams_loaded = false;
|
||||||
bool speakerToggle = false;
|
bool speakerToggle = false;
|
||||||
bool sd_card_detected = false;
|
bool sd_card_detected = false;
|
||||||
|
|
||||||
|
volatile bool codec_ready = false;
|
||||||
|
volatile bool config_loaded = false;
|
||||||
|
|
||||||
bool buttons[16] = {false};
|
bool buttons[16] = {false};
|
||||||
int buttonsDir[16] = {0};
|
int buttonsDir[16] = {0};
|
||||||
|
|
||||||
@ -155,7 +160,6 @@ size_t tape_write = 0;
|
|||||||
|
|
||||||
void codec_transmit() {
|
void codec_transmit() {
|
||||||
for(int i = 0; i < count; i++){
|
for(int i = 0; i < count; i++){
|
||||||
int j = active % NSTREAMS;
|
|
||||||
for(int k = 0; k < NSTREAMS; k++){
|
for(int k = 0; k < NSTREAMS; k++){
|
||||||
int16_t sample = 0;
|
int16_t sample = 0;
|
||||||
sample = stream[k].get();
|
sample = stream[k].get();
|
||||||
@ -320,14 +324,11 @@ void setup() {
|
|||||||
|
|
||||||
i2s.setFrequency(48000);
|
i2s.setFrequency(48000);
|
||||||
|
|
||||||
SPI1.setSCK(10);
|
pinMode(19, OUTPUT); // MCLK enable
|
||||||
SPI1.setTX(11);
|
digitalWrite(19, HIGH); // enable MCLK
|
||||||
SPI1.begin();
|
|
||||||
|
|
||||||
dac.begin();
|
pinMode(20, OUTPUT); // CODEC reset (enable)
|
||||||
|
digitalWrite(20, HIGH);
|
||||||
FastLED.addLeds<NEOPIXEL, 4>(edge_leds, 11);
|
|
||||||
FastLED.addLeds<NEOPIXEL, 5>(ui_leds, 74);
|
|
||||||
|
|
||||||
pinMode(12, OUTPUT);
|
pinMode(12, OUTPUT);
|
||||||
pinMode(13, OUTPUT);
|
pinMode(13, OUTPUT);
|
||||||
@ -348,6 +349,72 @@ void setup() {
|
|||||||
load_ui_sounds("/ui/click.wav", ui_click_snd, click_length);
|
load_ui_sounds("/ui/click.wav", ui_click_snd, click_length);
|
||||||
load_ui_sounds("/ui/beep.wav", ui_beep_snd, beep_length);
|
load_ui_sounds("/ui/beep.wav", ui_beep_snd, beep_length);
|
||||||
}
|
}
|
||||||
|
config_loaded = true;
|
||||||
|
|
||||||
|
pinMode(6, OUTPUT); // Vibration Motor
|
||||||
|
pinMode(7, OUTPUT); // UI Amp Enable
|
||||||
|
|
||||||
|
ui_snd.onTransmit(pwm_audio_callback);
|
||||||
|
ui_snd.begin(UI_SAMPLERATE);
|
||||||
|
|
||||||
|
digitalWrite(7, LOW); // UI amp off
|
||||||
|
|
||||||
|
while(!codec_ready){
|
||||||
|
delay(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
//i2s.onTransmit(codec_transmit);
|
||||||
|
//i2s.onReceive(codec_receive);
|
||||||
|
|
||||||
|
i2s.setDOUT(15);
|
||||||
|
i2s.setDIN(14);
|
||||||
|
i2s.setBCLK(16); // Note: LRCLK = BCLK + 1
|
||||||
|
i2s.setMCLK(18);
|
||||||
|
i2s.setMCLKmult(512); // 256 = 12.288.000Hz 512 = 25Mhz
|
||||||
|
|
||||||
|
i2s.swapClocks();
|
||||||
|
i2s.setBitsPerSample(16);
|
||||||
|
|
||||||
|
//i2s.setBuffers(6, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
|
||||||
|
|
||||||
|
if(sdInitialized) {
|
||||||
|
streams_loaded = load_samples();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(streams_loaded) {
|
||||||
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
|
samples[i].file = &stream[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!i2s.begin(48000)){
|
||||||
|
Serial.println("I2S error!");
|
||||||
|
while(100);
|
||||||
|
}
|
||||||
|
Serial.println("I2S OK");
|
||||||
|
|
||||||
|
digitalWrite(6, HIGH);
|
||||||
|
delay(25);
|
||||||
|
digitalWrite(6, LOW);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(6, HIGH);
|
||||||
|
delay(25);
|
||||||
|
digitalWrite(6, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup1(){
|
||||||
|
while(!config_loaded){
|
||||||
|
delay(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPI1.setSCK(10);
|
||||||
|
SPI1.setTX(11);
|
||||||
|
SPI1.begin();
|
||||||
|
|
||||||
|
dac.begin();
|
||||||
|
|
||||||
|
FastLED.addLeds<NEOPIXEL, 4>(edge_leds, 11);
|
||||||
|
FastLED.addLeds<NEOPIXEL, 5>(ui_leds, 74);
|
||||||
|
|
||||||
Serial.println("INIT WIRE");
|
Serial.println("INIT WIRE");
|
||||||
Wire1.setSDA(2);
|
Wire1.setSDA(2);
|
||||||
@ -370,59 +437,10 @@ void setup() {
|
|||||||
ENC.begin(); // set direction pin.
|
ENC.begin(); // set direction pin.
|
||||||
ENC.setDirection(AS5600_CLOCK_WISE);
|
ENC.setDirection(AS5600_CLOCK_WISE);
|
||||||
ENC.resetCumulativePosition();
|
ENC.resetCumulativePosition();
|
||||||
|
|
||||||
pinMode(6, OUTPUT); // Vibration Motor
|
|
||||||
pinMode(7, OUTPUT); // UI Amp Enable
|
|
||||||
|
|
||||||
ui_snd.onTransmit(pwm_audio_callback);
|
|
||||||
ui_snd.begin(UI_SAMPLERATE);
|
|
||||||
|
|
||||||
digitalWrite(7, LOW); // UI amp off
|
|
||||||
|
|
||||||
pinMode(19, OUTPUT); // MCLK enable
|
|
||||||
digitalWrite(19, HIGH); // enable MCLK
|
|
||||||
|
|
||||||
pinMode(20, OUTPUT); // CODEC reset
|
|
||||||
digitalWrite(20, HIGH);
|
|
||||||
|
|
||||||
codec.begin(&Wire1);
|
codec.begin(&Wire1);
|
||||||
|
delay(100);
|
||||||
i2s.onTransmit(codec_transmit);
|
codec_ready = true;
|
||||||
i2s.onReceive(codec_receive);
|
|
||||||
|
|
||||||
i2s.setDOUT(15);
|
|
||||||
i2s.setDIN(14);
|
|
||||||
i2s.setBCLK(16); // Note: LRCLK = BCLK + 1
|
|
||||||
i2s.setMCLK(18);
|
|
||||||
i2s.setMCLKmult(512); // 256 = 12.288.000Hz 512 = 25Mhz
|
|
||||||
|
|
||||||
i2s.swapClocks();
|
|
||||||
i2s.setBitsPerSample(16);
|
|
||||||
|
|
||||||
i2s.setBuffers(6, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
|
|
||||||
|
|
||||||
if(!i2s.begin(48000)){
|
|
||||||
Serial.println("I2S error!");
|
|
||||||
while(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sdInitialized) {
|
|
||||||
streams_loaded = load_samples();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(streams_loaded) {
|
|
||||||
for(int i = 0; i < NSTREAMS; i++){
|
|
||||||
samples[i].file = &stream[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
digitalWrite(6, HIGH);
|
|
||||||
delay(25);
|
|
||||||
digitalWrite(6, LOW);
|
|
||||||
delay(50);
|
|
||||||
digitalWrite(6, HIGH);
|
|
||||||
delay(25);
|
|
||||||
digitalWrite(6, LOW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t last = 0;
|
uint32_t last = 0;
|
||||||
@ -435,7 +453,7 @@ int32_t position_last = 0;
|
|||||||
int16_t encdelta_raw = 0;
|
int16_t encdelta_raw = 0;
|
||||||
int16_t encdeltadiv = 512;
|
int16_t encdeltadiv = 512;
|
||||||
|
|
||||||
void loop() {
|
void loop1() {
|
||||||
position = ENC.getCumulativePosition();
|
position = ENC.getCumulativePosition();
|
||||||
angle = ENC.readAngle();
|
angle = ENC.readAngle();
|
||||||
encdelta_raw += (position - position_last);
|
encdelta_raw += (position - position_last);
|
||||||
@ -669,11 +687,6 @@ void loop() {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
if(streams_loaded) {
|
|
||||||
for(int i = 0; i < NSTREAMS; i++){
|
|
||||||
stream[i].stream();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(buttonChanged){
|
if(buttonChanged){
|
||||||
for(int i = 0; i < 16; i++){
|
for(int i = 0; i < 16; i++){
|
||||||
@ -681,13 +694,33 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i2s.getOverflow()) Serial.println("overflow");
|
|
||||||
if(i2s.getUnderflow()) Serial.println("underflow");
|
|
||||||
|
|
||||||
//delay(20); // wait 1ms
|
//delay(20); // wait 1ms
|
||||||
bar_old = bar;
|
bar_old = bar;
|
||||||
vibration.update();
|
vibration.update();
|
||||||
position_last = position;
|
position_last = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
int16_t l, r;
|
||||||
|
i2s.read16(&l, &r);
|
||||||
|
|
||||||
|
for(int k = 0; k < NSTREAMS; k++){
|
||||||
|
int16_t sample_l = 0;
|
||||||
|
int16_t sample_r = 0;
|
||||||
|
sample_l = stream[k].get();
|
||||||
|
sample_r = stream[k].get();
|
||||||
|
l += sample_l >> 2;
|
||||||
|
r += sample_r >> 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2s.write16(l, r);
|
||||||
|
|
||||||
|
if(streams_loaded) {
|
||||||
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
|
stream[i].stream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user