summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2012-03-28 17:35:46 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2012-03-28 17:35:46 +0200
commitc7b62aa051bd942bf5148a386dc852de1943c0cc (patch)
tree466f2427a0f95a9c4adad3ace6f666c35e33bea0
parent5ba138138c818f3faa4c78f86ae4f7d4507ff2b6 (diff)
Added I2C_READ control request.
-rw-r--r--main.cpp22
1 files changed, 22 insertions, 0 deletions
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) {