Add dispatch loop, copy_to_ram, retry picotool load without sleep

This commit is contained in:
Ian Gulliver
2026-04-06 17:36:41 +09:00
parent b197f0bfa7
commit 00b960d81d
7 changed files with 87 additions and 116 deletions

View File

@@ -1,51 +1,11 @@
#include "pico/stdlib.h"
#include "tusb.h"
#include "wire.h"
#include "usb_cdc.h"
#include "timer_queue.h"
#include "dispatch.h"
#include "handlers.h"
#include "net.h"
static usb_cdc usb;
static timer_queue timers;
static constexpr handler_entry handlers[] = {
{RequestPICOBOOT::ext_id, handle_picoboot},
{RequestInfo::ext_id, handle_info},
};
int main() {
tusb_init();
net_init();
static static_vector<uint8_t, 256> rx_buf;
while (true) {
tud_task();
usb.drain();
timers.run();
while (tud_cdc_available()) {
uint8_t byte;
if (tud_cdc_read(&byte, 1) != 1) break;
rx_buf.push_back(byte);
auto msg = try_decode(rx_buf);
if (!msg) {
if (rx_buf.full()) rx_buf.clear();
continue;
}
rx_buf.clear();
switch (msg->type_id) {
case RequestPICOBOOT::ext_id:
handle_picoboot(usb, msg->message_id);
break;
case RequestInfo::ext_id:
handle_info(usb, msg->message_id);
break;
}
}
__wfi();
}
dispatch(handlers);
}