diff options
-rw-r--r-- | hal/usb.h | 9 | ||||
-rw-r--r-- | main.cpp | 22 |
2 files changed, 18 insertions, 13 deletions
@@ -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) @@ -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) { |