Skip to content

Commit

Permalink
Webusb: add control requests for reading mode and fw version
Browse files Browse the repository at this point in the history
  • Loading branch information
renzenicolai committed Jun 28, 2022
1 parent fc7d97a commit 2de774d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion i2c_peripheral.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "pico/unique_id.h"
#include "uart_task.h"

#include "version.h"

static bool interrupt_target = false;
static bool interrupt_state = false;
static bool interrupt_clear = false;
Expand Down Expand Up @@ -92,7 +94,7 @@ void setup_i2c_registers(int param_ir_statemachine) {
i2c_registers.modified[reg] = false;
}

i2c_registers.registers[I2C_REGISTER_FW_VER] = 0x07;
i2c_registers.registers[I2C_REGISTER_FW_VER] = FW_VERSION;

pico_unique_board_id_t id;
pico_get_unique_board_id((pico_unique_board_id_t*) &i2c_registers.registers[I2C_REGISTER_UID0]);
Expand Down
3 changes: 3 additions & 0 deletions version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#define FW_VERSION 0x08
12 changes: 12 additions & 0 deletions webusb_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "uart_task.h"
#include "usb_descriptors.h"

#include "version.h"

uint16_t webusb_status[CFG_TUD_VENDOR] = {0x0000};
bool webusb_status_changed[CFG_TUD_VENDOR] = {false};

Expand Down Expand Up @@ -144,6 +146,16 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
return tud_control_status(rhport, request);
}
}
if (request->bRequest == 0x26) { // Get mode
if (request->wIndex == ITF_NUM_VENDOR_0) {
return tud_control_xfer(rhport, request, (void*) &webusb_esp32_mode_change_target, 1);
}
}
if (request->bRequest == 0x27) { // Get firmware version
uint8_t version = FW_VERSION;
return tud_control_xfer(rhport, request, (void*) &version, 1);
}

break;
}
default:
Expand Down

0 comments on commit 2de774d

Please sign in to comment.