forked from W4D/soundcube-firmware
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a16ac73d9b | |||
| ad9c71363b |
@ -1,5 +1,14 @@
|
|||||||
# Soundcube Firmware
|
# 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
|
||||||
|
|
||||||
## Code something yourself
|
## Code something yourself
|
||||||
|
|
||||||
1. Download [Arduino IDE](https://www.arduino.cc/en/software/)
|
1. Download [Arduino IDE](https://www.arduino.cc/en/software/)
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <ArduinoJson.hpp>
|
||||||
|
|
||||||
#include <TCA9555.h>
|
#include <TCA9555.h>
|
||||||
#include <AS5600.h>
|
#include <AS5600.h>
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#include <PWMAudio.h>
|
#include <PWMAudio.h>
|
||||||
#include <I2S.h>
|
#include <I2S.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <SD.h>
|
||||||
|
|
||||||
#define HAPTIC 1
|
#define HAPTIC 1
|
||||||
#define AURAL 1
|
#define AURAL 1
|
||||||
@ -17,8 +22,8 @@ PWMAudio ui_snd(8);
|
|||||||
|
|
||||||
enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
||||||
|
|
||||||
Adafruit_NeoPixel edge_pixels(8, 4, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel edge_pixels(11, 4, NEO_GRB + NEO_KHZ800);
|
||||||
Adafruit_NeoPixel ui_pixels(72, 5, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel ui_pixels(74, 5, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
volatile bool flag = false;
|
volatile bool flag = false;
|
||||||
volatile bool click = false;
|
volatile bool click = false;
|
||||||
@ -29,16 +34,48 @@ int counter = 0;
|
|||||||
bool buttons[16] = {false};
|
bool buttons[16] = {false};
|
||||||
|
|
||||||
int16_t beep[UI_SAMPLERATE];
|
int16_t beep[UI_SAMPLERATE];
|
||||||
|
uint16_t beep_length = 0;
|
||||||
|
|
||||||
|
bool sd_card_detected = false;
|
||||||
|
|
||||||
|
struct Config {
|
||||||
|
int edge_color_r = 0;
|
||||||
|
int edge_color_g = 0;
|
||||||
|
int edge_color_b = 50;
|
||||||
|
};
|
||||||
|
|
||||||
|
Config config;
|
||||||
|
|
||||||
|
void loadConfiguration(Config& config) {
|
||||||
|
File file = SD.open("/config.txt");
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
|
if(error) Serial.println(F("Failed to read file, using default configuration"));
|
||||||
|
|
||||||
|
config.edge_color_r = doc["edge"]["color"]["r"] | 0;
|
||||||
|
config.edge_color_g = doc["edge"]["color"]["g"] | 0;
|
||||||
|
config.edge_color_b = doc["edge"]["color"]["b"] | 50;
|
||||||
|
|
||||||
|
//strlcpy(config.hostname, doc["hostname"] | "example.com", sizeof(config.hostname));
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
void pwm_audio_callback() {
|
void pwm_audio_callback() {
|
||||||
while (ui_snd.availableForWrite()) {
|
while (ui_snd.availableForWrite()) {
|
||||||
if(click) {
|
if(click) {
|
||||||
ui_snd.write(beep[counter]);
|
ui_snd.write(beep[counter]);
|
||||||
|
counter++;
|
||||||
|
if(counter == beep_length) {
|
||||||
|
counter = 0;
|
||||||
|
click = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
digitalWriteFast(7, LOW);
|
||||||
ui_snd.write(0);
|
ui_snd.write(0);
|
||||||
|
counter = 0;
|
||||||
}
|
}
|
||||||
counter++;
|
|
||||||
if(counter == UI_SAMPLERATE) counter = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,14 +84,45 @@ void tca_irq() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
Serial.begin();
|
||||||
for(int i = 0; i < UI_SAMPLERATE; i++){
|
while (!Serial) {
|
||||||
float sine_pos = (2.0f * M_PI * 8000.0f * (float)i) / (float)UI_SAMPLERATE;
|
;
|
||||||
beep[i] = (int16_t)(sin(sine_pos) * 8000.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.begin();
|
pinMode(21, INPUT_PULLUP);
|
||||||
delay(2000);
|
sd_card_detected = !digitalRead(21);
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
bool sdInitialized = SD.begin(22, 23, 24);
|
||||||
|
delay(100);
|
||||||
|
if(!sdInitialized) sdInitialized = SD.begin(22, 23, 24); // hack to prevent SD card from not initializing after soft reset
|
||||||
|
|
||||||
|
if(sdInitialized) loadConfiguration(config);
|
||||||
|
|
||||||
|
if(sdInitialized && SD.exists("/click.wav")) {
|
||||||
|
File click = SD.open("/click.wav");
|
||||||
|
int click_bytes = 0;
|
||||||
|
int32_t maxv = 0;
|
||||||
|
while (click.available() || click_bytes == UI_SAMPLERATE-1) {
|
||||||
|
int32_t sample = click.read() * 64;
|
||||||
|
if(abs(sample) > maxv) maxv = sample;
|
||||||
|
beep[click_bytes] = sample;
|
||||||
|
click_bytes++;
|
||||||
|
}
|
||||||
|
|
||||||
|
beep_length = click_bytes;
|
||||||
|
Serial.print("Read ");
|
||||||
|
Serial.print(beep_length);
|
||||||
|
Serial.print(" bytes from click.wav into beep array. maxV was ");
|
||||||
|
Serial.println(maxv);
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
Serial.println("Synthesized 8kHz sine into beep array.");
|
||||||
|
beep_length = UI_SAMPLERATE;
|
||||||
|
}
|
||||||
|
|
||||||
Serial.println("INIT WIRE");
|
Serial.println("INIT WIRE");
|
||||||
Wire1.setSDA(2);
|
Wire1.setSDA(2);
|
||||||
@ -114,6 +182,10 @@ void loop() {
|
|||||||
edge_pixels.clear(); // Set all pixel colors to 'off'
|
edge_pixels.clear(); // Set all pixel colors to 'off'
|
||||||
ui_pixels.clear(); // Set all pixel colors to 'off'
|
ui_pixels.clear(); // Set all pixel colors to 'off'
|
||||||
|
|
||||||
|
sd_card_detected = !digitalRead(21);
|
||||||
|
if(sd_card_detected) edge_pixels.setPixelColor(8, edge_pixels.Color(0,25,0));
|
||||||
|
if(!sd_card_detected) edge_pixels.setPixelColor(8, edge_pixels.Color(25,0,0));
|
||||||
|
|
||||||
position = ENC.getCumulativePosition();
|
position = ENC.getCumulativePosition();
|
||||||
|
|
||||||
// if (millis() - lastTime >= 100)
|
// if (millis() - lastTime >= 100)
|
||||||
@ -147,11 +219,8 @@ void loop() {
|
|||||||
}
|
}
|
||||||
// Make beep
|
// Make beep
|
||||||
if (AURAL) {
|
if (AURAL) {
|
||||||
digitalWrite(7, HIGH);
|
digitalWriteFast(7, HIGH);
|
||||||
click = true;
|
click = true;
|
||||||
delay(50);
|
|
||||||
click = false;
|
|
||||||
digitalWrite(7, LOW);
|
|
||||||
}
|
}
|
||||||
// Make vibration
|
// Make vibration
|
||||||
if(HAPTIC){
|
if(HAPTIC){
|
||||||
@ -171,7 +240,7 @@ void loop() {
|
|||||||
|
|
||||||
// EDGE LEDs
|
// EDGE LEDs
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
edge_pixels.setPixelColor(i, edge_pixels.Color(15, 15, 15));
|
edge_pixels.setPixelColor(i, edge_pixels.Color(config.edge_color_r, config.edge_color_g, config.edge_color_b));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotary button LEDs
|
// Rotary button LEDs
|
||||||
|
|||||||
Reference in New Issue
Block a user