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

cap touch in python

parent 5ff305e4
No related branches found
No related tags found
No related merge requests found
...@@ -3,9 +3,9 @@ micropython repl hooked up, hw functionality partly broken ...@@ -3,9 +3,9 @@ micropython repl hooked up, hw functionality partly broken
some fun commands to try: some fun commands to try:
``` ```
import badge_audio import hardware
#turn on sound #turn on sound
badge_audio.set_global_volume_dB(-10) hardware.set_global_volume_dB(-10)
from synth import tinysynth from synth import tinysynth
a=tinysynth(440,1); # enters decay phase without stop signal a=tinysynth(440,1); # enters decay phase without stop signal
...@@ -15,20 +15,20 @@ b.start(); ...@@ -15,20 +15,20 @@ b.start();
b.stop(); b.stop();
#tiny issue with garbage collect: #tiny issue with garbage collect:
badge_audio.count_sources(); hardware.count_sources();
a.__del__(); a.__del__();
badge_audio.count_sources(); hardware.count_sources();
import gc import gc
del b del b
gc.collect() gc.collect()
badge_audio.count_sources(); hardware.count_sources();
#...don't know how to hook up gc to __del__, maybe wrong approach #...don't know how to hook up gc to __del__, maybe wrong approach
``` ```
files can be transferred with mpremote, such as: files can be transferred with mpremote, such as:
``` ```
mpremote fs cp python_payload/boot.py :boot.py mpremote fs cp python_payload/boot.py :boot.py
mpremote fs cp python_payload/boot_button_demo.py :boot_button_demo.py mpremote fs cp python_payload/cap_touch_demo.py :cap_touch_demo.py
``` ```
## how to build ## how to build
...@@ -66,7 +66,7 @@ flash + build: (put badge into bootloader mode*) ...@@ -66,7 +66,7 @@ flash + build: (put badge into bootloader mode*)
``` ```
$ make deploy PORT=/dev/ttyACM0 $ make deploy PORT=/dev/ttyACM0
``` ```
__*press right shoulder button down during boot (on modified "last gen" prototypes)__ _*press right shoulder button down during boot (on modified "last gen" prototypes)_
empty build cache (useful when moving files around): empty build cache (useful when moving files around):
``` ```
......
...@@ -157,7 +157,7 @@ static void IRAM_ATTR gpio_isr_handler(void* arg) ...@@ -157,7 +157,7 @@ static void IRAM_ATTR gpio_isr_handler(void* arg)
void manual_captouch_readout(uint8_t top) void manual_captouch_readout(uint8_t top)
{ {
struct ad714x_chip* chip = top ? (&chip_top) : (&chip_bot); struct ad714x_chip* chip = top ? (&chip_top) : (&chip_bot);
xQueueSendFromISR(gpio_evt_queue, &chip, NULL); xQueueSend(gpio_evt_queue, &chip, NULL);
} }
void espan_handle_captouch(uint16_t pressed_top, uint16_t pressed_bot); void espan_handle_captouch(uint16_t pressed_top, uint16_t pressed_bot);
...@@ -182,6 +182,27 @@ void gpio_event_handler(void* arg) ...@@ -182,6 +182,27 @@ void gpio_event_handler(void* arg)
} }
} }
static uint8_t top_map[] = {2, 2, 2, 0, 0, 8, 8, 8, 6, 6, 4, 4};
static uint8_t bot_map[] = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9};
uint16_t read_captouch(){
uint16_t petals = 0;
for(int i=0; i<12; i++) {
if(pressed_top & (1 << i)) {
petals |= (1<<top_map[i]);
}
}
for(int i=0; i<10; i++) {
if(pressed_bot & (1 << i)) {
petals |= (1<<bot_map[i]);
}
}
return petals;
}
static void captouch_init_chip(const struct ad714x_chip* chip, const struct ad7147_device_config device_config) static void captouch_init_chip(const struct ad714x_chip* chip, const struct ad7147_device_config device_config)
{ {
uint16_t data; uint16_t data;
......
...@@ -6,3 +6,4 @@ void captouch_print_debug_info(void); ...@@ -6,3 +6,4 @@ void captouch_print_debug_info(void);
void gpio_event_handler(void * arg); void gpio_event_handler(void * arg);
void manual_captouch_readout(uint8_t top); void manual_captouch_readout(uint8_t top);
void captouch_get_cross(int paddle, int * x, int * y); void captouch_get_cross(int paddle, int * x, int * y);
uint16_t read_captouch();
...@@ -116,9 +116,9 @@ void os_app_main(void) ...@@ -116,9 +116,9 @@ void os_app_main(void)
void * asdasd = &i; void * asdasd = &i;
while(1) { while(1) {
manual_captouch_readout(1); manual_captouch_readout(1);
vTaskDelay(10 / portTICK_PERIOD_MS); vTaskDelay(3 / portTICK_PERIOD_MS);
manual_captouch_readout(0); manual_captouch_readout(0);
vTaskDelay(10 / portTICK_PERIOD_MS); vTaskDelay(3 / portTICK_PERIOD_MS);
continue; continue;
i = (i + 1) % 10; i = (i + 1) % 10;
......
...@@ -11,6 +11,16 @@ ...@@ -11,6 +11,16 @@
#include "py/builtin.h" #include "py/builtin.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "../badge23/audio.h" #include "../badge23/audio.h"
#include "../badge23/captouch.h"
STATIC mp_obj_t mp_get_captouch(size_t n_args, const mp_obj_t *args) {
uint16_t captouch = read_captouch();
uint8_t pad = mp_obj_get_int(args[0]);
uint8_t output = (captouch >> pad) & 1;
return mp_obj_new_int(output);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_get_captouch_obj, 1, 2, mp_get_captouch);
STATIC mp_obj_t mp_set_global_volume_dB(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mp_set_global_volume_dB(size_t n_args, const mp_obj_t *args) {
mp_float_t x = mp_obj_get_float(args[0]); mp_float_t x = mp_obj_get_float(args[0]);
...@@ -36,19 +46,20 @@ STATIC mp_obj_t mp_dump_all_sources(size_t n_args, const mp_obj_t *args) { ...@@ -36,19 +46,20 @@ STATIC mp_obj_t mp_dump_all_sources(size_t n_args, const mp_obj_t *args) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_dump_all_sources_obj, 0, 2, mp_dump_all_sources); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_dump_all_sources_obj, 0, 2, mp_dump_all_sources);
STATIC const mp_rom_map_elem_t mp_module_badge_audio_globals_table[] = { STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_badge_audio) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_badge_audio) },
{ MP_ROM_QSTR(MP_QSTR_get_captouch), MP_ROM_PTR(&mp_get_captouch_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_global_volume_dB), MP_ROM_PTR(&mp_set_global_volume_dB_obj) }, { MP_ROM_QSTR(MP_QSTR_set_global_volume_dB), MP_ROM_PTR(&mp_set_global_volume_dB_obj) },
{ MP_ROM_QSTR(MP_QSTR_count_sources), MP_ROM_PTR(&mp_count_sources_obj) }, { MP_ROM_QSTR(MP_QSTR_count_sources), MP_ROM_PTR(&mp_count_sources_obj) },
{ MP_ROM_QSTR(MP_QSTR_dump_all_sources), MP_ROM_PTR(&mp_dump_all_sources_obj) }, { MP_ROM_QSTR(MP_QSTR_dump_all_sources), MP_ROM_PTR(&mp_dump_all_sources_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(mp_module_badge_audio_globals, mp_module_badge_audio_globals_table); STATIC MP_DEFINE_CONST_DICT(mp_module_hardware_globals, mp_module_hardware_globals_table);
const mp_obj_module_t mp_module_badge_audio = { const mp_obj_module_t mp_module_hardware = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_badge_audio_globals, .globals = (mp_obj_dict_t *)&mp_module_hardware_globals,
}; };
MP_REGISTER_MODULE(MP_QSTR_badge_audio, mp_module_badge_audio); MP_REGISTER_MODULE(MP_QSTR_hardware, mp_module_hardware);
...@@ -60,8 +60,8 @@ set(MICROPY_SOURCE_DRIVERS ...@@ -60,8 +60,8 @@ set(MICROPY_SOURCE_DRIVERS
) )
set(MICROPY_SOURCE_PORT set(MICROPY_SOURCE_PORT
${PROJECT_DIR}/badge23_mp_audio.c ${PROJECT_DIR}/badge23_mp_hardware.c
${PROJECT_DIR}/badge23_mp_tinysynth.c ${PROJECT_DIR}/badge23_mp_synth.c
${PROJECT_DIR}/main.c ${PROJECT_DIR}/main.c
${PROJECT_DIR}/uart.c ${PROJECT_DIR}/uart.c
${PROJECT_DIR}/usb.c ${PROJECT_DIR}/usb.c
......
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
#esp.osdebug(None) #esp.osdebug(None)
#import webrepl #import webrepl
#webrepl.start() #webrepl.start()
import boot_button_demo import cap_touch_demo
from synth import tinysynth
from hardware import *
set_global_volume_dB(0)
synths = []
for i in range(10):
synths += [tinysynth(440+50*i,1)]
chords = [[0,3,7,10,12],[-2,2,5,8,10],[i-2,3,7,10,14],[-4,0,3,8,12],[-1,2,5,7,11]]
def tune_guitar_to_chord(chord):
for j in range(5):
frq = 440 * (2**(chord[j]/12))
synths[j].freq(int(frq))
tune_guitar_to_chord(chords[2])
while True:
for i in range(10):
if(get_captouch(i)):
if(i%2):
tune_guitar_to_chord(chords[int((i-1)/2)])
else:
synths[int(i/2)].start()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment