From c7b62aa051bd942bf5148a386dc852de1943c0cc Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Wed, 28 Mar 2012 17:35:46 +0200 Subject: Added I2C_READ control request. --- main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/main.cpp b/main.cpp index 54bc4a6..ce799d9 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,7 @@ #include "pin.h" #include "usb.h" +#include "i2c.h" static Pin& led_status = PA4; static Pin& led_error = PC4; @@ -20,6 +21,9 @@ static Pin& jtag_tms = PC13; static Pin& jtag_tck = PC14; static Pin& jtag_tdi = PC15; +static Pin& i2c_scl = PB10; +static Pin& i2c_sda = PB11; + bool jtag_tick(bool tdi, bool tms) { bool tdo = jtag_tdo.get(); jtag_tdi.set(tdi); @@ -87,6 +91,14 @@ bool jtag_shift(uint16_t wValue, uint16_t wIndex, uint16_t wLength) { return true; } +bool i2c_read(uint16_t wValue, uint16_t wIndex, uint16_t wLength) { + uint8_t buf[wLength]; + I2C2.read_reg(wValue, wIndex, wLength, buf); + + usb_write((uint32_t*)buf, wLength); + return true; +} + void handle_setup(const uint32_t* bufp) { led_error.toggle(); @@ -110,6 +122,13 @@ void handle_setup(const uint32_t* bufp) { } } + // I2C_READ + if(bmRequestType == 0xc0 && bRequest == 0xf0) { + if(i2c_read(wValue, wIndex, wLength)) { + return; + } + } + // JTAG_SHIFT if(bmRequestType == 0xc0 && bRequest == 0xff) { if(jtag_shift(wValue, wIndex, wLength)) { @@ -242,6 +261,9 @@ int main() { OTG_HS.reg.GCCFG = (1 << 19) | (1 << 16); // VBUSBSEN PWRDWN + RCC.enable(RCC.I2C2); + I2C2.enable(i2c_scl, i2c_sda); + usb_thread.start(); while(1) { -- cgit v1.2.3