41 lines
881 B
C++
41 lines
881 B
C++
#include <stdio.h>
|
|
#include "pico/stdlib.h"
|
|
#include "pico/bootrom.h"
|
|
#include "device.h"
|
|
|
|
static void send_bytes(const std::vector<uint8_t> &data) {
|
|
for (auto b : data) {
|
|
putchar(b);
|
|
}
|
|
stdio_flush();
|
|
}
|
|
|
|
int main() {
|
|
stdio_init_all();
|
|
|
|
static static_vector<uint8_t, 256> rx_buf;
|
|
|
|
while (true) {
|
|
int c = getchar_timeout_us(100000);
|
|
if (c == PICO_ERROR_TIMEOUT) continue;
|
|
|
|
rx_buf.push_back(static_cast<uint8_t>(c));
|
|
|
|
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:
|
|
send_bytes(encode_response(msg->message_id, ResponsePICOBOOT{}));
|
|
sleep_ms(100);
|
|
reset_usb_boot(0, 1);
|
|
break;
|
|
}
|
|
}
|
|
}
|