icE1usb fw: Add device request to read/write I2C device registers

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I55a72762d535827a51e5ea1775e9abbd116bc8a8
changes/66/30066/2
Sylvain Munaut 4 months ago
parent 652c732ec4
commit 0036b1fa9f
  1. 4
      firmware/ice40-riscv/icE1usb/ice1usb_proto.h
  2. 10
      firmware/ice40-riscv/icE1usb/usb_dev.c

@ -20,6 +20,10 @@
/*! returns a string describing the firmware version */
#define ICE1USB_DEV_GET_FW_BUILD 0x02
/*! performs an I2C register access (read/write depends on direction) */
#define ICE1USB_DEV_I2C_REG_ACCESS 0x10
enum e1usb_dev_capability {
/*! Does this board have a GPS-DO */
ICE1USB_DEV_CAP_GPSDO,

@ -12,6 +12,7 @@
#include <no2usb/usb_proto.h>
#include "console.h"
#include "i2c.h"
#include "misc.h"
#include "ice1usb_proto.h"
@ -24,6 +25,10 @@ static enum usb_fnd_resp
_usb_dev_ctrl_req_write(struct usb_ctrl_req *req, struct usb_xfer *xfer)
{
switch (req->bRequest) {
case ICE1USB_DEV_I2C_REG_ACCESS:
if (!i2c_write_reg((req->wIndex >> 8), req->wIndex & 0xff, req->wValue & 0xff))
return USB_FND_ERROR;
break;
default:
return USB_FND_ERROR;
}
@ -43,6 +48,11 @@ _usb_dev_ctrl_req_read(struct usb_ctrl_req *req, struct usb_xfer *xfer)
xfer->data = (void*) fw_build_str;
xfer->len = strlen(fw_build_str);
break;
case ICE1USB_DEV_I2C_REG_ACCESS:
if (!i2c_read_reg((req->wIndex >> 8), req->wIndex & 0xff, &xfer->data[0]))
return USB_FND_ERROR;
xfer->len = 1;
break;
default:
return USB_FND_ERROR;
}

Loading…
Cancel
Save