summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2012-04-22 23:07:52 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2012-04-22 23:07:52 +0200
commita75f2ed11d49f6db8da08fd01d66bcb2ca2f7fcf (patch)
treecd207cf6f51de7220c6a913055f25314787823ff
parent2529ce991e6eda9f8235084ed1b7a7e408c86866 (diff)
Added support for multiple FIFOs.
-rw-r--r--hal/usb.h9
-rw-r--r--main.cpp22
2 files changed, 18 insertions, 13 deletions
diff --git a/hal/usb.h b/hal/usb.h
index 8376727..c8c550f 100644
--- a/hal/usb.h
+++ b/hal/usb.h
@@ -62,20 +62,25 @@ struct USB_dev_oep_reg_t {
uint32_t _reserved2[3];
};
+union USB_fifo_reg_t {
+ volatile uint32_t reg;
+ volatile uint32_t buf[1024];
+};
+
class USB_t {
public:
USB_reg_t& reg;
USB_dev_reg_t& dev_reg;
USB_dev_iep_reg_t* const dev_iep_reg;
USB_dev_oep_reg_t* const dev_oep_reg;
- volatile uint32_t& fifo;
+ USB_fifo_reg_t* const fifo;
USB_t(uint32_t reg_addr) :
reg(*(USB_reg_t*)reg_addr),
dev_reg(*(USB_dev_reg_t*)(reg_addr + 0x800)),
dev_iep_reg((USB_dev_iep_reg_t*)(reg_addr + 0x900)),
dev_oep_reg((USB_dev_oep_reg_t*)(reg_addr + 0xb00)),
- fifo(*(volatile uint32_t*)(reg_addr + 0x1000)) {}
+ fifo((USB_fifo_reg_t*)(reg_addr + 0x1000)) {}
};
#if defined(STM32F1)
diff --git a/main.cpp b/main.cpp
index 9337c20..ca9237f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -39,16 +39,16 @@ bool jtag_tick(bool tdi, bool tms) {
return tdo;
}
-void usb_write(uint32_t* bufp, uint32_t len) {
- OTG_HS.dev_iep_reg[0].DIEPTSIZ = (1 << 19) | len;
+void usb_write(uint32_t ep, uint32_t* bufp, uint32_t len) {
+ OTG_HS.dev_iep_reg[ep].DIEPTSIZ = (1 << 19) | len;
// PKTCNT
- OTG_HS.dev_iep_reg[0].DIEPCTL |= (1 << 31) | (1 << 26);
+ OTG_HS.dev_iep_reg[ep].DIEPCTL |= (1 << 31) | (1 << 26);
// EPENA CNAK
len = (len + 3) >> 2;
while(len--) {
- OTG_HS.fifo = *bufp++;
+ OTG_HS.fifo[ep].reg = *bufp++;
}
}
@@ -65,10 +65,10 @@ uint8_t conf_desc[] = {
bool get_descriptor(uint16_t wValue, uint16_t wIndex, uint16_t wLength) {
switch(wValue) {
case 0x100:
- usb_write((uint32_t*)dev_desc, wLength > sizeof(dev_desc) ? sizeof(dev_desc) : wLength);
+ usb_write(0, (uint32_t*)dev_desc, wLength > sizeof(dev_desc) ? sizeof(dev_desc) : wLength);
return true;
case 0x200:
- usb_write((uint32_t*)conf_desc, wLength > sizeof(conf_desc) ? sizeof(conf_desc) : wLength);
+ usb_write(0, (uint32_t*)conf_desc, wLength > sizeof(conf_desc) ? sizeof(conf_desc) : wLength);
return true;
default:
return false;
@@ -77,7 +77,7 @@ bool get_descriptor(uint16_t wValue, uint16_t wIndex, uint16_t wLength) {
bool set_address(uint16_t wValue, uint16_t wIndex, uint16_t wLength) {
OTG_HS.dev_reg.DCFG |= wValue << 4;
- usb_write(0, 0);
+ usb_write(0, 0, 0);
return true;
}
@@ -86,7 +86,7 @@ bool set_configuration(uint16_t wValue, uint16_t wIndex, uint16_t wLength) {
return false;
}
- usb_write(0, 0);
+ usb_write(0, 0, 0);
return true;
}
@@ -103,7 +103,7 @@ bool jtag_shift(uint16_t wValue, uint16_t wIndex, uint16_t wLength) {
wIndex >>= 1;
}
- usb_write(&tdo, (wLength + 7) >> 3);
+ usb_write(0, &tdo, (wLength + 7) >> 3);
return true;
}
@@ -111,7 +111,7 @@ 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);
+ usb_write(0, (uint32_t*)buf, wLength);
return true;
}
@@ -172,7 +172,7 @@ void handle_rxfifo() {
uint32_t len = (status & 0x7ff0) >> 6;
for(uint32_t i = 0; i < len; i++) {
- buf[i] = OTG_HS.fifo;
+ buf[i] = OTG_HS.fifo[0].reg;
}
//if(status == 0x000c0080) {