2026-04-02 22:15:10 +09:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
|
#include "pico/bootrom.h"
|
2026-04-04 15:09:16 +09:00
|
|
|
#include "pico/unique_id.h"
|
2026-04-04 23:16:25 +09:00
|
|
|
#include "wire.h"
|
2026-04-03 16:59:11 +09:00
|
|
|
|
2026-04-04 20:36:22 +09:00
|
|
|
#include "w6300.h"
|
2026-04-03 21:47:48 +09:00
|
|
|
|
2026-04-03 16:59:11 +09:00
|
|
|
static void send_bytes(const std::vector<uint8_t> &data) {
|
|
|
|
|
for (auto b : data) {
|
|
|
|
|
putchar(b);
|
|
|
|
|
}
|
|
|
|
|
stdio_flush();
|
|
|
|
|
}
|
2026-04-02 22:15:10 +09:00
|
|
|
|
2026-04-03 21:47:48 +09:00
|
|
|
static bool w6300_init() {
|
2026-04-05 07:01:43 +09:00
|
|
|
w6300::init_spi();
|
|
|
|
|
w6300::init_critical_section();
|
|
|
|
|
w6300::reset();
|
|
|
|
|
w6300::init();
|
|
|
|
|
if (!w6300::check()) return false;
|
2026-04-04 15:12:15 +09:00
|
|
|
|
|
|
|
|
pico_unique_board_id_t uid;
|
|
|
|
|
pico_get_unique_board_id(&uid);
|
2026-04-05 07:01:43 +09:00
|
|
|
w6300::net_info info = {};
|
|
|
|
|
info.mac[0] = (uid.id[0] & 0xFC) | 0x02;
|
|
|
|
|
info.mac[1] = uid.id[1];
|
|
|
|
|
info.mac[2] = uid.id[2];
|
|
|
|
|
info.mac[3] = uid.id[3];
|
|
|
|
|
info.mac[4] = uid.id[4];
|
|
|
|
|
info.mac[5] = uid.id[5];
|
|
|
|
|
w6300::init_net(info);
|
2026-04-04 15:12:15 +09:00
|
|
|
|
|
|
|
|
return true;
|
2026-04-03 21:47:48 +09:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 22:15:10 +09:00
|
|
|
int main() {
|
|
|
|
|
stdio_init_all();
|
2026-04-04 15:09:16 +09:00
|
|
|
stdio_set_translate_crlf(&stdio_usb, false);
|
2026-04-02 22:15:10 +09:00
|
|
|
|
2026-04-03 21:47:48 +09:00
|
|
|
if (!w6300_init()) {
|
|
|
|
|
printf("W6300 init failed\n");
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 17:32:14 +09:00
|
|
|
static static_vector<uint8_t, 256> rx_buf;
|
|
|
|
|
|
2026-04-02 22:15:10 +09:00
|
|
|
while (true) {
|
|
|
|
|
int c = getchar_timeout_us(100000);
|
2026-04-03 17:32:14 +09:00
|
|
|
if (c == PICO_ERROR_TIMEOUT) continue;
|
|
|
|
|
|
|
|
|
|
rx_buf.push_back(static_cast<uint8_t>(c));
|
|
|
|
|
|
2026-04-03 17:41:44 +09:00
|
|
|
auto msg = try_decode(rx_buf);
|
|
|
|
|
if (!msg) {
|
2026-04-03 17:32:14 +09:00
|
|
|
if (rx_buf.full()) rx_buf.clear();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rx_buf.clear();
|
|
|
|
|
|
2026-04-03 17:41:44 +09:00
|
|
|
switch (msg->type_id) {
|
2026-04-03 17:44:32 +09:00
|
|
|
case RequestPICOBOOT::ext_id:
|
|
|
|
|
send_bytes(encode_response(msg->message_id, ResponsePICOBOOT{}));
|
2026-04-03 16:59:11 +09:00
|
|
|
sleep_ms(100);
|
2026-04-03 17:44:32 +09:00
|
|
|
reset_usb_boot(0, 1);
|
2026-04-03 17:32:14 +09:00
|
|
|
break;
|
2026-04-04 15:00:16 +09:00
|
|
|
case RequestInfo::ext_id: {
|
2026-04-05 07:01:43 +09:00
|
|
|
ResponseInfo resp;
|
2026-04-04 15:09:16 +09:00
|
|
|
pico_unique_board_id_t uid;
|
|
|
|
|
pico_get_unique_board_id(&uid);
|
2026-04-05 07:01:43 +09:00
|
|
|
std::copy(uid.id, uid.id + 8, resp.board_id.begin());
|
2026-04-05 15:32:20 +09:00
|
|
|
auto ninfo = w6300::get_net_info();
|
|
|
|
|
resp.mac = ninfo.mac;
|
2026-04-05 07:01:43 +09:00
|
|
|
send_bytes(encode_response(msg->message_id, resp));
|
2026-04-04 15:00:16 +09:00
|
|
|
break;
|
|
|
|
|
}
|
2026-04-02 22:15:10 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|