Add dispatch loop, copy_to_ram, retry picotool load without sleep
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user