Sleep with __wfi() between USB interrupts instead of busy-polling
This commit is contained in:
56
picomap.cpp
56
picomap.cpp
@@ -57,37 +57,39 @@ int main() {
|
|||||||
while (true) {
|
while (true) {
|
||||||
tud_task();
|
tud_task();
|
||||||
|
|
||||||
if (!tud_cdc_available()) continue;
|
while (tud_cdc_available()) {
|
||||||
|
uint8_t byte;
|
||||||
|
if (tud_cdc_read(&byte, 1) != 1) break;
|
||||||
|
|
||||||
uint8_t byte;
|
rx_buf.push_back(byte);
|
||||||
if (tud_cdc_read(&byte, 1) != 1) continue;
|
|
||||||
|
|
||||||
rx_buf.push_back(byte);
|
auto msg = try_decode(rx_buf);
|
||||||
|
if (!msg) {
|
||||||
|
if (rx_buf.full()) rx_buf.clear();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto msg = try_decode(rx_buf);
|
rx_buf.clear();
|
||||||
if (!msg) {
|
|
||||||
if (rx_buf.full()) rx_buf.clear();
|
switch (msg->type_id) {
|
||||||
continue;
|
case RequestPICOBOOT::ext_id:
|
||||||
|
send_bytes(encode_response(msg->message_id, ResponsePICOBOOT{}));
|
||||||
|
sleep_ms(100);
|
||||||
|
reset_usb_boot(0, 1);
|
||||||
|
break;
|
||||||
|
case RequestInfo::ext_id: {
|
||||||
|
ResponseInfo resp;
|
||||||
|
pico_unique_board_id_t uid;
|
||||||
|
pico_get_unique_board_id(&uid);
|
||||||
|
std::copy(uid.id, uid.id + 8, resp.board_id.begin());
|
||||||
|
auto ninfo = w6300::get_net_info();
|
||||||
|
resp.mac = ninfo.mac;
|
||||||
|
send_bytes(encode_response(msg->message_id, resp));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rx_buf.clear();
|
__wfi();
|
||||||
|
|
||||||
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;
|
|
||||||
case RequestInfo::ext_id: {
|
|
||||||
ResponseInfo resp;
|
|
||||||
pico_unique_board_id_t uid;
|
|
||||||
pico_get_unique_board_id(&uid);
|
|
||||||
std::copy(uid.id, uid.id + 8, resp.board_id.begin());
|
|
||||||
auto ninfo = w6300::get_net_info();
|
|
||||||
resp.mac = ninfo.mac;
|
|
||||||
send_bytes(encode_response(msg->message_id, resp));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user