tillitis-key/hw/application_fpga/fw/tk1/proto.h
Michael Cardell Widerkrantz 108120ffbf
Add alternative way of handling USB Mode Protocol
Make read()/write() hide all the details of handling the USB Mode
Protocol.

Unfortunately this also introduces 4 bytes to the .bss segment which
was removed because of lack of FW_RAM, originally just 1 kB. We add
back support in start.S and the linker script.
2025-02-11 09:32:05 +01:00

64 lines
1.1 KiB
C

/*
* Copyright (C) 2022, 2023 - Tillitis AB
* SPDX-License-Identifier: GPL-2.0-only
*/
#include "types.h"
#ifndef PROTO_H
#define PROTO_H
enum mode {
MODE_TKEYCTRL = 0x20,
MODE_CDC = 0x40,
MODE_HID = 0x80,
};
enum endpoints {
DST_HW_IFPGA,
DST_HW_AFPGA,
DST_FW,
DST_SW
};
enum cmdlen {
LEN_1,
LEN_4,
LEN_32,
LEN_128
};
#define CMDLEN_MAXBYTES 128
// clang-format off
enum fwcmd {
FW_CMD_NAME_VERSION = 0x01,
FW_RSP_NAME_VERSION = 0x02,
FW_CMD_LOAD_APP = 0x03,
FW_RSP_LOAD_APP = 0x04,
FW_CMD_LOAD_APP_DATA = 0x05,
FW_RSP_LOAD_APP_DATA = 0x06,
FW_RSP_LOAD_APP_DATA_READY = 0x07,
FW_CMD_GET_UDI = 0x08,
FW_RSP_GET_UDI = 0x09,
FW_CMD_MAX = 0x0a,
};
// clang-format on
enum status {
STATUS_OK,
STATUS_BAD
};
struct frame_header {
uint8_t id;
enum endpoints endpoint;
size_t len;
};
/*@ -exportlocal @*/
int read(uint8_t *buf, size_t bufsize, size_t nbytes, enum mode expect_mode);
void write(const uint8_t *buf, size_t nbytes, enum mode mode);
void fwreply(struct frame_header hdr, enum fwcmd rspcode, uint8_t *buf);
int readcommand(struct frame_header *hdr, uint8_t *cmd, int state);
#endif