Skip to content

Commit

Permalink
many changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marchingband committed Jul 3, 2021
1 parent 9553968 commit a05bfc3
Show file tree
Hide file tree
Showing 21 changed files with 413 additions and 258 deletions.
7 changes: 3 additions & 4 deletions src/WVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

WVR::WVR()
{
// this->autoConfigPins = true;
this->wifiIsOn = get_wifi_is_on();
// this->mute = false;
// this->globalVolume = 127;
this->useFTDI = false;
this->useUsbMidi = false;
}

void WVR::begin()
{
wvr_init();
wvr_init(useFTDI, useUsbMidi);
}

void WVR::play(uint8_t voice, uint8_t note, uint8_t velocity)
Expand Down
3 changes: 2 additions & 1 deletion src/WVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class WVR {
// bool mute;
// bool autoConfigPins;
bool wifiIsOn;

bool useFTDI;
bool useUsbMidi;
};

#endif
2 changes: 1 addition & 1 deletion src/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void boot_into_recovery_mode(void)
new_metadata->current_firmware_index = index;
write_metadata(*new_metadata);
// sdmmc_host_deinit();
// feedLoopWDT();
feedLoopWDT();
// delay(1000);
ESP.restart();
} else {
Expand Down
55 changes: 36 additions & 19 deletions src/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
xQueueHandle gpio_queue_handle;
xTaskHandle gpio_task_handle;


static void gpioTask(void* x) {
button_event_t *event;
uint32_t touch_reg = 0;
for(;;) {
if(xQueueReceive(gpio_queue_handle, &event, portMAX_DELAY)) {
log_i("gpio task pin:%d val:%d",event->pin, event->val);
log_d("gpio task pin:%d val:%d",event->pin, event->val);
if(event->button->touch != 1)
{
// digital
Expand All @@ -46,15 +45,15 @@ static void gpioTask(void* x) {
void IRAM_ATTR isr(void *e){
button_event_t *event = (button_event_t*)e;
event->val = digitalRead(event->pin);
isr_log_d("read %d",event->val);
xQueueSendFromISR(gpio_queue_handle, &event, NULL);
}

void IRAM_ATTR touch_isr(void *e){
// isr_log_i("touch isr");
button_event_t *event = (button_event_t*)e;
uint32_t pad_intr = touch_pad_get_status();
touch_pad_clear_status();
// send the whole register to the queue so the other pad interrupts can read it even though its bee cleared
// send the whole register to the queue so the other pad interrupts can read it even though its been cleared
event->val = pad_intr;
xQueueSendFromISR(gpio_queue_handle, &event, NULL);
}
Expand All @@ -67,6 +66,7 @@ Button::Button(int pin, int mode, int dbnc){
this->touch = false;
this->handlePress = NULL;
this->handleRelease = NULL;
this->pressed = false;
event.pin = pin;
event.button = this;
// gpio_reset_pin(gpioNumToGpioNum_T(pin));
Expand All @@ -78,6 +78,7 @@ Button::Button(int pin, int mode, int dbnc, bool touch){
this->dbnc = dbnc;
this->last = 0;
this->touch = true;
this->pressed = false;
this->handlePress = NULL;
this->handleRelease = NULL;
event.pin = pin;
Expand All @@ -86,7 +87,7 @@ Button::Button(int pin, int mode, int dbnc, bool touch){
}

Button::~Button(){
log_i("destructor button on %u",pin);
log_d("destructor button on %u",pin);
detachInterrupt(pin);
}

Expand All @@ -105,51 +106,67 @@ void Button::onPress(void(*handlePress)()){
}

void Button::onRelease(void(*handleRelease)()){
this->handleRelease=handleRelease;
attachInterruptArg(pin, isr, (void*)&event, CHANGE);
if(this->touch != 1)
{
// digital read mode
this->handleRelease=handleRelease;
attachInterruptArg(pin, isr, (void*)&event, CHANGE);
}
else
{
// capacitive touch mode has no onRelease()
return;
}
}

void Button::handleChange(int val){
log_d("pin:%d val:%d",pin,val);
// if EDGE_NONE then ignore
log_i("pin:%d val:%d",pin,val);
if(mode != RISING && mode != FALLING) return;
int now = millis();
if((now - last) > dbnc){
last = now;
// last = now;
if(
(val==0 && mode == FALLING) ||
(val==1 && mode == RISING)
(val==0 && mode == FALLING && !pressed) ||
(val==1 && mode == RISING && !pressed)
){
if(handlePress != NULL)
{
handlePress();
}
last = now;
}
else
{
if(handleRelease != NULL)
else if(
(val==1 && mode == FALLING && pressed) ||
(val==0 && mode == RISING && pressed)
){
if(handleRelease != NULL && pressed)
{
handleRelease();
}
last = now;
}
}
// make sure the pressed state updates even when debounced (this isr logic is annoying)
// touch pins have no such concept
if(!touch)
{
pressed = (val==0 && mode==FALLING) || (val==1 && mode==RISING);
log_d("pressed %d", pressed);
}
}

static bool touch_initialized = false;

void init_touch(void)
{
log_i("*");
touch_pad_init();
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V5);
// touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD);
// touch_initialized = true;
}

void init_touch_pad(int pin, void *event)
{
log_i("*");
if(!touch_initialized)
{
init_touch();
Expand All @@ -161,7 +178,7 @@ void init_touch_pad(int pin, void *event)

touch_pad_read_filtered( gpioNumToTPNum(pin), &touch_value);
ESP_ERROR_CHECK(touch_pad_set_thresh( gpioNumToTPNum(pin), touch_value * 2 / 3));
log_i("touch setup TPNUM:%d touchValue:%d",gpioNumToTPNum(pin),touch_value);
log_d("touch setup TPNUM:%d touchValue:%d",gpioNumToTPNum(pin),touch_value);
touch_pad_isr_register(touch_isr, (void*)event);
touch_pad_intr_enable();
}
Expand Down
1 change: 1 addition & 0 deletions src/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Button {
int last;
int mode;
bool touch;
bool pressed;
void (*handlePress)();
void (*handleRelease)();
button_event_t event;
Expand Down
7 changes: 7 additions & 0 deletions src/defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef DEFINES_H
#define DEFINES_H

// #define CONFIG_ASYNC_TCP_RUNNING_CORE 0
// #define CONFIG_ASYNC_TCP_USE_WDT 0

#endif
14 changes: 1 addition & 13 deletions src/emmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,13 @@ esp_err_t emmc_read(void *dst, size_t start_sector, size_t sector_count)

void emmc_init(void)
{
wlog_i("********************");
wlog_i("hello from emmc");
wlog_i("*********************");
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
// slot_config.width = 4;
// slot_config.width = 1;
host.flags = SDMMC_HOST_FLAG_4BIT;
// host.flags = SDMMC_HOST_FLAG_1BIT;

host.max_freq_khz = SDMMC_FREQ_52M;
// host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
// host.max_freq_khz = 80000;
// host.max_freq_khz = SDMMC_FREQ_DEFAULT;
// host.max_freq_khz = SDMMC_FREQ_PROBING;

ret = sdmmc_host_set_bus_ddr_mode(SDMMC_HOST_SLOT_1, true);
if(ret != ESP_OK){
log_i( "sdmmc_host_init : %s", esp_err_to_name(ret));
log_e( "sdmmc_host_init : %s", esp_err_to_name(ret));
}
gpio_set_pull_mode(15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
gpio_set_pull_mode(2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
Expand Down
8 changes: 4 additions & 4 deletions src/file_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@


// char waver_tag[METADATA_TAG_LENGTH] = "wvr_magic_10";
char waver_tag[METADATA_TAG_LENGTH] = "wvr_magic_11";
char waver_tag[METADATA_TAG_LENGTH] = "wvr_magic_12";
static const char* TAG = "file_system";

// declare prototypes from emmc.c
Expand Down Expand Up @@ -286,7 +286,7 @@ void init_rack_lut(void){
rack_lut[j] = blank;
}
struct rack_file_t *buf = (struct rack_file_t*)ps_malloc(RACK_DIRECTORY_BLOCKS * SECTOR_SIZE);
if(buf == NULL){log_i("failed to alloc rack_file_t buf");};
if(buf == NULL){log_e("failed to alloc rack_file_t buf");};
for(int k=0; k < NUM_RACK_DIRECTORY_ENTRIES; k++){
buf[k] = blank_file;
}
Expand Down Expand Up @@ -318,7 +318,7 @@ void init_firmware_lut(void){
void write_firmware_lut_to_disk(void){
// log_i("writting firmware wav_lut to disk");
struct firmware_t *buf = (struct firmware_t*)ps_malloc(FIRMWARE_LUT_BLOCKS * SECTOR_SIZE);
if(buf == NULL){log_i("failed to alloc firmware_t buf");};
if(buf == NULL){log_e("failed to alloc firmware_t buf");};
// log_i("allocated buffer of %u blocks for %u firmwares to write to disk", FIRMWARE_LUT_BLOCKS, MAX_FIRMWARES);
for(int i=0; i< MAX_FIRMWARES; i++){
buf[i] = firmware_lut[i];
Expand Down Expand Up @@ -1147,7 +1147,7 @@ void log_pin_config(void)
{
for(int i=0;i<14;i++)
{
log_i("pin %d action:%d edge:%d gpio:%d note:%d touch:%d velocity:%d dbnc:%d",
log_d("pin %d action:%d edge:%d gpio:%d note:%d touch:%d velocity:%d dbnc:%d",
i,
pin_config_lut[i].action,
pin_config_lut[i].edge,
Expand Down
27 changes: 10 additions & 17 deletions src/file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,10 @@ struct rack_file_t {
uint8_t free;
};

// static struct metadata_t metadata;
// static struct wav_lu_t **wav_lut;
// static struct firmware_t *firmware_lut;
// static struct website_t *website_lut;
// static struct rack_lu_t *rack_lut;
// static struct pin_config_t *pin_config_lut;

static struct pin_config_t default_pin_config_array[14] = {
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D0,
.note = 40,
.touch = -1, //no touch on this pin
Expand All @@ -187,7 +180,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D1,
.note = 41,
.touch = -1, //no touch on this pin
Expand All @@ -196,7 +189,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D2,
.note = 42,
.touch = -1, //no touch on this pin
Expand All @@ -205,7 +198,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D3,
.note = 43,
.touch = -1, //no touch on this pin
Expand All @@ -214,7 +207,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D4,
.note = 44,
.touch = -1, //no touch on this pin
Expand All @@ -223,7 +216,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D5,
.note = 45,
.touch = -1, //no touch on this pin
Expand All @@ -232,7 +225,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D6,
.note = 46,
.touch = 0,
Expand Down Expand Up @@ -277,7 +270,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D11,
.note = 51,
.touch = 0,
Expand All @@ -286,7 +279,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D12,
.note = 52,
.touch = 0,
Expand All @@ -295,7 +288,7 @@ static struct pin_config_t default_pin_config_array[14] = {
},
{
.action = NOTE_ON,
.edge = EDGE_FALLING,
.edge = EDGE_NONE,
.gpio_num = D13,
.note = 53,
.touch = 0,
Expand Down
Loading

0 comments on commit a05bfc3

Please sign in to comment.