64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
#include <stdio.h>
|
|
#include "pico/stdlib.h"
|
|
#include "pico/bootrom.h"
|
|
#include "device.h"
|
|
|
|
extern "C" {
|
|
#include "wizchip_conf.h"
|
|
#include "wizchip_spi.h"
|
|
}
|
|
|
|
static void send_bytes(const std::vector<uint8_t> &data) {
|
|
for (auto b : data) {
|
|
putchar(b);
|
|
}
|
|
stdio_flush();
|
|
}
|
|
|
|
static bool w6300_init() {
|
|
wizchip_spi_initialize();
|
|
wizchip_cris_initialize();
|
|
wizchip_reset();
|
|
wizchip_initialize();
|
|
return getCIDR() == 0x6300;
|
|
}
|
|
|
|
int main() {
|
|
stdio_init_all();
|
|
|
|
if (!w6300_init()) {
|
|
printf("W6300 init failed\n");
|
|
}
|
|
|
|
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;
|
|
case RequestInfo::ext_id: {
|
|
ResponseInfo info;
|
|
getSHAR(info.mac.data());
|
|
send_bytes(encode_response(msg->message_id, info));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|