Skip to content
Snippets Groups Projects
Commit b7e0ec32 authored by moon2's avatar moon2 :speech_balloon: Committed by q3k
Browse files

disabled sequenced autoplay, more basic micropython stuff

parent ba78bc5e
No related branches found
No related tags found
No related merge requests found
## current hw functionality
plays an infinite scripted note sequence and provides a basic micropython repl
makes extra noise when Crtl+D'd in the repl (importing py libraries works too)
## current functionality
micropython repl hooked up, hw functionality partly broken
some fun commands to try:
'''
```
import badge_audio
#turn on sound
badge_audio.set_global_volume_dB(-10)
#turn off all demo oscillators
badge_audio.dump_all_sources()
import synth
a=synth.tinysynth(440,1);
from synth import tinysynth
a=tinysynth(440,1); # enters decay phase without stop signal
a.start();
b=synth.tinysynth(660,0);
b=tinysynth(660,0); # sustains until stop signal
b.start();
b.stop();
......@@ -26,8 +23,13 @@ del b
gc.collect()
badge_audio.count_sources();
#...don't know how to hook up gc to __del__, maybe wrong approach
```
'''
files can be transferred with mpremote, such as:
```
mpremote fs cp python_payload/boot.py :boot.py
mpremote fs cp python_payload/boot_button_demo.py :boot_button_demo.py
```
## how to build
......
......@@ -24,7 +24,7 @@ static void audio_player_task(void* arg);
#define DMA_BUFFER_COUNT 2
#define I2S_PORT 0
static void i2s_init_idk_lol(void){
static void i2s_init(void){
static const i2s_config_t i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX,
......@@ -90,6 +90,7 @@ typedef struct _audio_source_t{
static audio_source_t * _audio_sources = NULL;
uint16_t add_audio_source(void * render_data, void * render_function){
//construct audio source struct
audio_source_t * src = malloc(sizeof(audio_source_t));
if(src == NULL) return;
src->render_data = render_data;
......@@ -97,13 +98,29 @@ uint16_t add_audio_source(void * render_data, void * render_function){
src->next = NULL;
src->index = 0;
audio_source_t * audio_source = _audio_sources;
if(audio_source == NULL){
//handle empty list special case
if(_audio_sources == NULL){
_audio_sources = src;
return 0; //only nonempty lists from here on out!
}
//searching for lowest unused index
audio_source_t * index_source = _audio_sources;
while(1){
if(src->index == (index_source->index)){
src->index++; //someone else has index already, try next
index_source = _audio_sources; //start whole list for new index
} else {
index_source = index_source->next;
}
if(index_source == NULL){ //traversed the entire list
break;
}
}
audio_source_t * audio_source = _audio_sources;
//append new source to linked list
while(audio_source != NULL){
src->index++;
if(audio_source->next == NULL){
audio_source->next = src;
break;
......@@ -125,7 +142,8 @@ void remove_audio_source(uint16_t index){
} else {
start_gap->next = audio_source->next;
}
free(audio_source);
vTaskDelay(20 / portTICK_PERIOD_MS); //give other tasks time to stop using
free(audio_source); //terrible hack tbh
break;
}
start_gap = audio_source;
......@@ -145,10 +163,10 @@ uint16_t count_audio_sources(){
static void _audio_init(void) {
init_scope(241);
//i2s_init_std_duplex();
i2s_init_idk_lol();
i2s_init();
//ESP_ERROR_CHECK(i2s_channel_enable(tx_chan));
/*
for(int i = 0; i < NUM_SYNTH; i++){
if((i%2) || (!DRUMS_TOP) ){ //bottom leaves
synths[i].decay_steps = 50;
......@@ -193,6 +211,7 @@ static void _audio_init(void) {
}
add_audio_source(&(synths[i]), trad_osc);
}
*/
TaskHandle_t handle;
xTaskCreate(&audio_player_task, "Audio player", 20000, NULL, configMAX_PRIORITIES - 1, &handle);
}
......
......@@ -162,7 +162,6 @@ void gpio_event_handler(void* arg)
struct ad714x_chip* chip;
uint16_t pressed;
while(true) {
/*
if(xQueueReceive(gpio_evt_queue, &chip, portMAX_DELAY)) {
ad714x_i2c_read(chip, 9, &pressed, 1);
ESP_LOGI(TAG, "Addr %x, High interrupt %X", chip->addr, pressed);
......@@ -173,13 +172,6 @@ void gpio_event_handler(void* arg)
if(chip == &chip_bot) pressed_bot = pressed;
espan_handle_captouch(pressed_top, pressed_bot);
}
*/
vTaskDelay(1000/portTICK_PERIOD_MS);
counter++;
pressed = counter & ((1 << 5) - 1);
pressed_bot = pressed;
pressed_top = pressed;
espan_handle_captouch(pressed_top, pressed_bot);
}
}
......
......@@ -95,12 +95,12 @@ void os_app_main(void)
ESP_LOGI(TAG, "I2C initialized successfully");
vTaskDelay(1000 / portTICK_PERIOD_MS);
set_global_vol_dB(-90);
set_global_vol_dB(0);
audio_init();
leds_init();
//display_init();
captouch_init();
//captouch_init();
mp_hal_stdout_tx_str("task inits done\n\r");
//play_bootsound();
......@@ -115,8 +115,7 @@ void os_app_main(void)
int i = 0;
void * asdasd = &i;
while(1) {
gpio_event_handler(asdasd);
continue;
i = (i + 1) % 10;
if(!(i == 2 || i == 8)) continue;
if(VIB){
......
......@@ -57,6 +57,13 @@ STATIC mp_obj_t tinysynth_stop(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(tinysynth_stop_obj, tinysynth_stop);
STATIC mp_obj_t tinysynth_freq(mp_obj_t self_in, mp_obj_t freq) {
synth_tinysynth_obj_t *self = MP_OBJ_TO_PTR(self_in);
self->osc.freq = mp_obj_get_float(freq);
return mp_obj_new_float(self->osc.freq);
}
MP_DEFINE_CONST_FUN_OBJ_2(tinysynth_freq_obj, tinysynth_freq);
STATIC mp_obj_t tinysynth_deinit(mp_obj_t self_in) {
synth_tinysynth_obj_t *self = MP_OBJ_TO_PTR(self_in);
remove_audio_source(self->source_index);
......@@ -68,6 +75,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(tinysynth_deinit_obj, tinysynth_deinit);
STATIC const mp_rom_map_elem_t tinysynth_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&tinysynth_start_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&tinysynth_stop_obj) },
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&tinysynth_freq_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&tinysynth_deinit_obj) },
};
......
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()
import boot_button_demo
from machine import Pin
from synth import tinysynth
p = Pin(0, Pin.IN)
s = tinysynth(440,1)
while True:
if(p.value() == 0):
s.start()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment