mirror of
https://github.com/whowechina/iidx_pico.git
synced 2025-02-07 07:01:17 +01:00
Just begin the "Setup" feature
This commit is contained in:
parent
ebe2a2a268
commit
0a150d5b1b
@ -1,6 +1,6 @@
|
||||
function(make_firmware board board_def)
|
||||
add_executable(${board}
|
||||
main.c buttons.c rgb.c config.c turntable.c
|
||||
main.c buttons.c rgb.c config.c setup.c turntable.c
|
||||
tt_rainbow.c tt_blade.c
|
||||
usb_descriptors.c)
|
||||
target_compile_definitions(${board} PUBLIC ${board_def})
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Controller Config
|
||||
* Controller Config Save and Load
|
||||
* WHowe <github.com/whowechina>
|
||||
*
|
||||
* Config is stored in last sector of flash
|
||||
@ -42,7 +42,7 @@ static int cfg_page = -1;
|
||||
static bool requesting_save = false;
|
||||
static uint64_t requesting_time = 0;
|
||||
|
||||
static core2_locker core2_lock;
|
||||
static io_locker_func io_lock;
|
||||
|
||||
static void config_save()
|
||||
{
|
||||
@ -50,7 +50,7 @@ static void config_save()
|
||||
|
||||
cfg_page = (cfg_page + 1) % (FLASH_SECTOR_SIZE / FLASH_PAGE_SIZE);
|
||||
printf("Program Flash %d %8lx\n", cfg_page, old_cfg.magic);
|
||||
core2_lock(true);
|
||||
io_lock(true);
|
||||
uint32_t ints = save_and_disable_interrupts();
|
||||
if (cfg_page == 0) {
|
||||
flash_range_erase(CONFIG_SECTOR_OFFSET, FLASH_SECTOR_SIZE);
|
||||
@ -58,7 +58,7 @@ static void config_save()
|
||||
flash_range_program(CONFIG_SECTOR_OFFSET + cfg_page * FLASH_PAGE_SIZE,
|
||||
(uint8_t *)&old_cfg, FLASH_PAGE_SIZE);
|
||||
restore_interrupts(ints);
|
||||
core2_lock(false);
|
||||
io_lock(false);
|
||||
}
|
||||
|
||||
static void load_default()
|
||||
@ -101,9 +101,9 @@ static void config_loaded()
|
||||
}
|
||||
}
|
||||
|
||||
void config_init(core2_locker locker)
|
||||
void config_init(io_locker_func locker)
|
||||
{
|
||||
core2_lock = locker;
|
||||
io_lock = locker;
|
||||
config_load();
|
||||
config_loop();
|
||||
config_loaded();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Controller Config
|
||||
* Controller Config Save and Load
|
||||
* WHowe <github.com/whowechina>
|
||||
*/
|
||||
|
||||
@ -9,9 +9,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void (*core2_locker)(bool pause);
|
||||
/* It's safer to lock other I/O ops during saving, so we need a locker */
|
||||
typedef void (*io_locker_func)(bool pause);
|
||||
void config_init(io_locker_func locker);
|
||||
|
||||
void config_init(core2_locker locker);
|
||||
void config_loop();
|
||||
|
||||
void *config_alloc(size_t size, void *def, void (*after_load)());
|
||||
|
@ -56,9 +56,17 @@ void boot_check()
|
||||
}
|
||||
}
|
||||
|
||||
static bool core2_pause = false;
|
||||
static bool request_core1_pause = false;
|
||||
|
||||
static void core2_loop()
|
||||
static void pause_core1(bool pause)
|
||||
{
|
||||
request_core1_pause = pause;
|
||||
if (pause) {
|
||||
sleep_ms(5); /* wait for any IO ops to finish */
|
||||
}
|
||||
}
|
||||
|
||||
static void core1_loop()
|
||||
{
|
||||
#define RUN_EVERY_N_MS(a, ms) { if (frame % ms == 0) a; }
|
||||
uint32_t frame = 0;
|
||||
@ -71,20 +79,20 @@ static void core2_loop()
|
||||
frame++;
|
||||
do {
|
||||
sleep_ms(1);
|
||||
} while (core2_pause);
|
||||
} while (request_core1_pause);
|
||||
}
|
||||
}
|
||||
|
||||
static void core2_init()
|
||||
static void core0_loop()
|
||||
{
|
||||
multicore_launch_core1(core2_loop);
|
||||
}
|
||||
|
||||
static void core2_pause_loop(bool pause)
|
||||
{
|
||||
core2_pause = pause;
|
||||
if (pause) {
|
||||
sleep_ms(5); /* wait for any IO ops to finish */
|
||||
while (true)
|
||||
{
|
||||
tud_task();
|
||||
report.buttons = button_read();
|
||||
hid_report();
|
||||
rgb_set_button_light(report.buttons);
|
||||
button_update();
|
||||
config_loop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,23 +109,15 @@ void init()
|
||||
turntable_init();
|
||||
boot_check();
|
||||
stdio_init_all();
|
||||
config_init(core2_pause_loop);
|
||||
core2_init();
|
||||
config_init(pause_core1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init();
|
||||
multicore_launch_core1(core1_loop);
|
||||
|
||||
while (1)
|
||||
{
|
||||
tud_task();
|
||||
report.buttons = button_read();
|
||||
hid_report();
|
||||
rgb_set_button_light(report.buttons);
|
||||
button_update();
|
||||
config_loop();
|
||||
}
|
||||
core0_loop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
8
firmware/src/setup.c
Normal file
8
firmware/src/setup.c
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Controller Setup Menu
|
||||
* WHowe <github.com/whowechina>
|
||||
*
|
||||
* Setup is a mode, so one can change settings live
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
10
firmware/src/setup.h
Normal file
10
firmware/src/setup.h
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Controller Setup
|
||||
* WHowe <github.com/whowechina>
|
||||
*/
|
||||
|
||||
#ifndef SETUP_H
|
||||
#define SETUP_H
|
||||
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user