make vnd cfg interface index configurable (as it shouldve been)

This commit is contained in:
Triss 2021-07-14 03:12:37 +02:00
parent 16963bd39b
commit 595c768b88
4 changed files with 19 additions and 7 deletions

View File

@ -73,6 +73,7 @@ void stdio_usb_set_itf_num(int itf); // TODO: move to a header!
static void enter_cb(void) {
stdio_usb_set_itf_num(CDC_N_STDIO);
vnd_cfg_set_itf_num(VND_N_CFG);
// TODO: CMSISDAP?
#ifdef DBOARD_HAS_I2C

View File

@ -76,9 +76,9 @@ static uint8_t read_byte_cdc(void) {
}
static uint32_t nresp = 0;
static void handle_cmd(uint8_t cmd, int ud, uint8_t (*read_byte)(void),
void (*writepkt)(int ud, const uint8_t* buf, uint32_t len),
void (*flushpkt)(int ud),
static void handle_cmd(uint8_t cmd, uint8_t ud, uint8_t (*read_byte)(void),
uint32_t (*writepkt)(uint8_t ud, const void* buf, uint32_t len),
uint32_t (*flushpkt)(uint8_t ud),
void (*writehdr)(enum cfg_resp stat, uint32_t len, const void* data)) {
nresp = 0;
@ -304,15 +304,19 @@ void cdc_serprog_task(void) {
}
static void vnd_writepkt(int ud, const uint8_t* buf, uint32_t len) {
static uint32_t vnd_writepkt(uint8_t ud, const void* buf, uint32_t len) {
(void)ud;
for (size_t i = 0; i < len; ++i) vnd_cfg_write_byte(buf[i]);
for (size_t i = 0; i < len; ++i) vnd_cfg_write_byte(((const uint8_t*)buf)[i]);
return len;
}
static void vnd_flushpkt(int ud) {
static uint32_t vnd_flushpkt(uint8_t ud) {
(void)ud;
vnd_cfg_write_flush();
return 0;
}
void sp_spi_bulk_cmd(void) {
uint8_t cmd = read_byte_cdc();

View File

@ -16,12 +16,18 @@ static uint8_t tx_buf[CFG_TUD_VENDOR_TX_BUFSIZE];
static uint32_t rxavail, rxpos, txpos;
static const int VND_N_CFG;
static int VND_N_CFG = 0;
void vnd_cfg_init(void) {
rxavail = 0;
rxpos = 0;
txpos = 0;
VND_N_CFG = 0;
}
void vnd_cfg_set_itf_num(int itf) {
VND_N_CFG = itf;
}
uint8_t vnd_cfg_read_byte(void) {

View File

@ -51,6 +51,7 @@ enum cfg_resp {
cfg_resp_badarg = 0x04
};
void vnd_cfg_set_itf_num(int itf);
uint8_t vnd_cfg_read_byte (void);
void vnd_cfg_drop_incoming(void);
void vnd_cfg_write_flush(void);