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-03 17:41:44 +09:00
|
|
|
#include "device.h"
|
2026-04-03 16:59:11 +09:00
|
|
|
|
2026-04-03 21:47:48 +09:00
|
|
|
#include "wizchip_conf.h"
|
|
|
|
|
#include "wizchip_spi.h"
|
|
|
|
|
|
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() {
|
|
|
|
|
wizchip_spi_initialize();
|
|
|
|
|
wizchip_cris_initialize();
|
|
|
|
|
wizchip_reset();
|
|
|
|
|
wizchip_initialize();
|
2026-04-04 15:12:15 +09:00
|
|
|
if (getCIDR() != 0x6300) return false;
|
|
|
|
|
|
|
|
|
|
pico_unique_board_id_t uid;
|
|
|
|
|
pico_get_unique_board_id(&uid);
|
|
|
|
|
uint8_t mac[6] = {
|
|
|
|
|
static_cast<uint8_t>((uid.id[0] & 0xFC) | 0x02),
|
|
|
|
|
uid.id[1], uid.id[2], uid.id[3], uid.id[4], uid.id[5]
|
|
|
|
|
};
|
|
|
|
|
setSHAR(mac);
|
|
|
|
|
|
|
|
|
|
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: {
|
|
|
|
|
ResponseInfo info;
|
2026-04-04 15:09:16 +09:00
|
|
|
pico_unique_board_id_t uid;
|
|
|
|
|
pico_get_unique_board_id(&uid);
|
|
|
|
|
std::copy(uid.id, uid.id + 8, info.board_id.begin());
|
2026-04-04 15:00:16 +09:00
|
|
|
getSHAR(info.mac.data());
|
|
|
|
|
send_bytes(encode_response(msg->message_id, info));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-04-02 22:15:10 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|