aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/usb.c
diff options
context:
space:
mode:
authorajmeyer@mit.edu <ajmeyer@mit.edu@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-19 08:03:54 +0000
committerajmeyer@mit.edu <ajmeyer@mit.edu@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-19 08:03:54 +0000
commit7021adc50a041bfb69bc4432b712aa07ef710ca3 (patch)
tree4dcc3be7576e0ad5dd52039d3d99f3c6f99ea448 /src/lib/usb.c
parenta8aaabae4c1cc64a01d740a436336ca31c1f79ba (diff)
downloadlibrambutan-7021adc50a041bfb69bc4432b712aa07ef710ca3.tar.gz
librambutan-7021adc50a041bfb69bc4432b712aa07ef710ca3.zip
added USB support (TX over virtual com port), the linker modifications to work with the bootloader, a modified libcs-lanchon-stm32.a, and the arduino-required main.cxx and WProgram.h
git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@72 749a229e-a60e-11de-b98f-4500b42dc123
Diffstat (limited to 'src/lib/usb.c')
-rw-r--r--src/lib/usb.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lib/usb.c b/src/lib/usb.c
new file mode 100644
index 0000000..e0d7d42
--- /dev/null
+++ b/src/lib/usb.c
@@ -0,0 +1,56 @@
+#include "usb.h"
+#include <inttypes.h>
+
+void usb_lpIRQHandler(void)
+{
+ typedef void (*funcPtr)(void);
+
+ const uint32_t usbIsrAddr = *(uint32_t*)(USB_ISR_ADDR);
+ void (*ptrToUsbISR)(void) = (funcPtr) usbIsrAddr;
+ ptrToUsbISR();
+}
+
+void UserToPMABufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
+{
+ u32 n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
+ u32 i, temp1, temp2;
+ u16 *pdwVal;
+ pdwVal = (u16 *)(wPMABufAddr * 2 + PMAAddr);
+ for (i = n; i != 0; i--)
+ {
+ temp1 = (u16) * pbUsrBuf;
+ pbUsrBuf++;
+ temp2 = temp1 | (u16) * pbUsrBuf << 8;
+ *pdwVal++ = temp2;
+ pdwVal++;
+ pbUsrBuf++;
+ }
+}
+
+void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
+{
+ u32 n = (wNBytes + 1) >> 1;/* /2*/
+ u32 i;
+ u32 *pdwVal;
+ pdwVal = (u32 *)(wPMABufAddr * 2 + PMAAddr);
+ for (i = n; i != 0; i--)
+ {
+ *(u16*)pbUsrBuf++ = *pdwVal++;
+ pbUsrBuf++;
+ }
+}
+
+void serialWriteStr(char* outStr) {
+ u8 offset=0;
+ while ((outStr[offset] != 0)
+ && (offset < USB_SERIAL_BUF_SIZE)) {
+ offset++;
+ }
+
+ while (_GetEPTxCount(USB_SERIAL_ENDP_TX) > 0) {}
+
+ UserToPMABufferCopy(outStr,USB_SERIAL_ENDP_TXADDR,offset);
+ _SetEPTxCount(USB_SERIAL_ENDP_TX,offset);
+ _SetEPTxValid(USB_SERIAL_ENDP_TX);
+}
+