Remove USB/serial support: network-only protocol, drop tinyusb and PICOBOOT
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
#include "dispatch.h"
|
||||
#include <unordered_map>
|
||||
#include "pico/stdlib.h"
|
||||
#include "tusb.h"
|
||||
#include "wire.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "timer_queue.h"
|
||||
#include "net.h"
|
||||
#include "igmp.h"
|
||||
@@ -19,7 +17,6 @@ static void igmp_reannounce() {
|
||||
}
|
||||
|
||||
void dispatch_init() {
|
||||
tusb_init();
|
||||
net_init();
|
||||
dispatch_schedule_ms(60000, igmp_reannounce);
|
||||
dlog("dispatch_init complete");
|
||||
@@ -41,8 +38,6 @@ bool dispatch_cancel_timer(timer_handle h) {
|
||||
handler_map[entry.type_id] = entry.handle;
|
||||
}
|
||||
|
||||
static usb_cdc usb;
|
||||
static static_vector<uint8_t, 4096> usb_rx_buf;
|
||||
static std::array<uint8_t, 4096> tx_buf;
|
||||
|
||||
auto dispatch_msg = [&](const DecodedMessage& msg, send_fn send) {
|
||||
@@ -65,48 +60,9 @@ bool dispatch_cancel_timer(timer_handle h) {
|
||||
while (true) {
|
||||
uint32_t save = save_and_disable_interrupts();
|
||||
|
||||
dlog_if_slow("tud_task", 1000, [&]{ tud_task(); });
|
||||
dlog_if_slow("drain", 1000, [&]{ usb.drain(); });
|
||||
dlog_if_slow("timers", 1000, [&]{ timers.run(); });
|
||||
dlog_if_slow("net_poll", 1000, [&]{ net_poll(std::span{tx_buf}); });
|
||||
|
||||
while (tud_cdc_available()) {
|
||||
uint8_t byte;
|
||||
if (tud_cdc_read(&byte, 1) != 1) break;
|
||||
|
||||
usb_rx_buf.push_back(byte);
|
||||
|
||||
auto msg = try_decode(usb_rx_buf);
|
||||
if (!msg) {
|
||||
if (usb_rx_buf.full()) usb_rx_buf.clear();
|
||||
continue;
|
||||
}
|
||||
|
||||
dispatch_msg(*msg, [&](encode_fn encode) {
|
||||
uint8_t buf[4096];
|
||||
span_writer out(buf, sizeof(buf));
|
||||
auto r = encode(out);
|
||||
if (!r) return;
|
||||
std::span<const uint8_t> data{buf, *r};
|
||||
if (data.size() <= usb.tx.free()) {
|
||||
if (!usb.send(data))
|
||||
dlogf("usb send failed: %zu bytes, %u free", data.size(), usb.tx.free());
|
||||
} else {
|
||||
dlogf("usb response too large: %zu bytes, %u free", data.size(), usb.tx.free());
|
||||
uint8_t err_buf[256];
|
||||
span_writer err_out(err_buf, sizeof(err_buf));
|
||||
auto err = encode_response_into(err_out, msg->message_id,
|
||||
[&]{
|
||||
char m[48];
|
||||
snprintf(m, sizeof(m), "response too large: %zu", data.size());
|
||||
return DeviceError{2, m};
|
||||
}());
|
||||
if (err) usb.send(std::span<const uint8_t>{err_buf, *err});
|
||||
}
|
||||
});
|
||||
usb_rx_buf.clear();
|
||||
}
|
||||
|
||||
__wfi();
|
||||
restore_interrupts(save);
|
||||
}
|
||||
|
||||
@@ -29,11 +29,6 @@ void handlers_start() {
|
||||
poke_watchdog();
|
||||
}
|
||||
|
||||
std::optional<ResponsePICOBOOT> handle_picoboot(const responder&, const RequestPICOBOOT&) {
|
||||
dispatch_schedule_ms(100, []{ reset_usb_boot(0, 1); });
|
||||
return ResponsePICOBOOT{};
|
||||
}
|
||||
|
||||
std::optional<ResponseInfo> handle_info(const responder&, const RequestInfo&) {
|
||||
ResponseInfo resp;
|
||||
pico_unique_board_id_t uid;
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
#include <cstring>
|
||||
#include "pico/unique_id.h"
|
||||
#include "tusb.h"
|
||||
|
||||
constexpr uint16_t USB_VID = 0x2E8A;
|
||||
constexpr uint16_t USB_PID = 0x000A;
|
||||
|
||||
static constexpr tusb_desc_device_t desc_device = {
|
||||
sizeof(tusb_desc_device_t),
|
||||
TUSB_DESC_DEVICE,
|
||||
0x0200,
|
||||
TUSB_CLASS_MISC,
|
||||
MISC_SUBCLASS_COMMON,
|
||||
MISC_PROTOCOL_IAD,
|
||||
CFG_TUD_ENDPOINT0_SIZE,
|
||||
USB_VID,
|
||||
USB_PID,
|
||||
0x0100,
|
||||
1, 2, 3,
|
||||
1,
|
||||
};
|
||||
|
||||
enum { ITF_NUM_CDC, ITF_NUM_CDC_DATA, ITF_NUM_TOTAL };
|
||||
|
||||
constexpr uint8_t EPNUM_CDC_NOTIF = 0x81;
|
||||
constexpr uint8_t EPNUM_CDC_OUT = 0x02;
|
||||
constexpr uint8_t EPNUM_CDC_IN = 0x82;
|
||||
constexpr uint16_t CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN;
|
||||
|
||||
static uint8_t const desc_configuration[] = {
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 0, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
|
||||
};
|
||||
|
||||
static constexpr const char* string_desc[] = {
|
||||
"\x09\x04",
|
||||
"picomap",
|
||||
"picomap",
|
||||
nullptr,
|
||||
};
|
||||
|
||||
static uint16_t desc_str_buf[33];
|
||||
|
||||
extern "C" {
|
||||
|
||||
uint8_t const* tud_descriptor_device_cb(void) {
|
||||
return reinterpret_cast<uint8_t const*>(&desc_device);
|
||||
}
|
||||
|
||||
uint8_t const* tud_descriptor_configuration_cb(uint8_t index) {
|
||||
return desc_configuration;
|
||||
}
|
||||
|
||||
uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
uint8_t chr_count;
|
||||
|
||||
if (index == 0) {
|
||||
memcpy(&desc_str_buf[1], string_desc[0], 2);
|
||||
chr_count = 1;
|
||||
} else if (index == 3) {
|
||||
pico_unique_board_id_t uid;
|
||||
pico_get_unique_board_id(&uid);
|
||||
chr_count = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
desc_str_buf[1 + chr_count++] = "0123456789ABCDEF"[uid.id[i] >> 4];
|
||||
desc_str_buf[1 + chr_count++] = "0123456789ABCDEF"[uid.id[i] & 0xF];
|
||||
}
|
||||
} else {
|
||||
if (index >= sizeof(string_desc) / sizeof(string_desc[0])) return nullptr;
|
||||
const char* str = string_desc[index];
|
||||
if (!str) return nullptr;
|
||||
chr_count = strlen(str);
|
||||
if (chr_count > 31) chr_count = 31;
|
||||
for (uint8_t i = 0; i < chr_count; i++)
|
||||
desc_str_buf[1 + i] = str[i];
|
||||
}
|
||||
|
||||
desc_str_buf[0] = static_cast<uint16_t>((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
|
||||
return desc_str_buf;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
Reference in New Issue
Block a user