aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorajmeyer@mit.edu <ajmeyer@mit.edu@749a229e-a60e-11de-b98f-4500b42dc123>2010-01-07 03:31:35 +0000
committerajmeyer@mit.edu <ajmeyer@mit.edu@749a229e-a60e-11de-b98f-4500b42dc123>2010-01-07 03:31:35 +0000
commit2addfe8c42c6bcdc0a15c751e2436447b73d03fe (patch)
tree07e569cd0fe7fd4a06cb5f71e12ba76dda3d5e2c /src/lib
parent5f423270cde82f9dfffb52bdd617e5eb439921c5 (diff)
downloadlibrambutan-2addfe8c42c6bcdc0a15c751e2436447b73d03fe.tar.gz
librambutan-2addfe8c42c6bcdc0a15c751e2436447b73d03fe.zip
Added a print class for USB, works identically to the Serial object. Bugs out if you try and pump more than 64 bytes through it in a single packet (which is really the OS's decision). This can be fixed
git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@93 749a229e-a60e-11de-b98f-4500b42dc123
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/bootVect.h52
-rw-r--r--src/lib/usb.c24
-rw-r--r--src/lib/usb.h28
3 files changed, 78 insertions, 26 deletions
diff --git a/src/lib/bootVect.h b/src/lib/bootVect.h
new file mode 100644
index 0000000..5bcb42b
--- /dev/null
+++ b/src/lib/bootVect.h
@@ -0,0 +1,52 @@
+/* *****************************************************************************
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ****************************************************************************/
+
+/**
+ * @file HardwareUsb.h
+ *
+ * @brief Defines the maple boot vector structure
+ */
+
+#ifndef _BOOTVECT_H_
+#define _BOOTVECT_H_
+
+#define BOOTLOADER_VECT_TABLE ((uint32_t*)0x20000000)
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+typedef void (*FuncPtr)(void);
+
+typedef struct {
+ FuncPtr serial_tx_cb;
+ FuncPtr serial_rx_cb;
+ FuncPtr serial_linecoding_cb;
+ uint32_t* serial_count_in;
+ uint32_t* serial_count_out;
+ uint8_t* serial_buffer_out;
+ void* linecoding;
+ uint8_t major_rev;
+ uint8_t minor_rev;
+ void* usb_device_ptr;
+ void* usb_local_obj_ptr;
+} BootVectTable;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _BOOTVECT_H_
diff --git a/src/lib/usb.c b/src/lib/usb.c
index 17c8c8d..8c312f8 100644
--- a/src/lib/usb.c
+++ b/src/lib/usb.c
@@ -1,8 +1,6 @@
#include <inttypes.h>
#include "usb.h"
-BootVectTable* bootVect = ((BootVectTable*) BOOTLOADER_VECT_TABLE);
-
void usb_lpIRQHandler(void)
{
typedef void (*funcPtr)(void);
@@ -60,8 +58,26 @@ void usb_serialWriteStr(const char* outStr) {
}
+void usb_serialWriteChar(unsigned char ch) {
+ BootVectTable *bootVector = ((BootVectTable*)BOOTLOADER_VECT_TABLE);
+
+ delay(1);
+
+ *(bootVector->serial_count_in) = 1;
+ usb_userToPMABufferCopy((u8*)(&ch),USB_SERIAL_ENDP_TXADDR,1);
+ _SetEPTxCount(USB_SERIAL_ENDP_TX,1);
+ _SetEPTxValid(USB_SERIAL_ENDP_TX);
+
+}
+
uint8_t usb_serialGetRecvLen() {
- uint8_t count_out = _GetEPRxCount(USB_SERIAL_ENDP_RX);
- _SetEPRxValid(USB_SERIAL_ENDP_RX);
+ uint8_t count_out =_GetEPRxCount(USB_SERIAL_ENDP_RX);
return count_out;
}
+
+void usb_copyRecvBuffer(unsigned char* dest, uint8_t len) {
+ ASSERT(len < USB_SERIAL_BUF_SIZE);
+ usb_PMAToUserBufferCopy((u8*)(dest),USB_SERIAL_ENDP_RXADDR,len);
+ _SetEPRxValid(USB_SERIAL_ENDP_RX);
+}
+
diff --git a/src/lib/usb.h b/src/lib/usb.h
index 3a7e92b..3b7a971 100644
--- a/src/lib/usb.h
+++ b/src/lib/usb.h
@@ -5,10 +5,7 @@
#include "util.h"
#include "cortexm3_macro.h"
#include "usb_regs.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "bootVect.h"
#define USB_ISR_ADDR (0x08000090)
#define USB_SERIAL_ENDP_TXADDR ((uint32_t) 0xC0)
@@ -17,30 +14,17 @@ extern "C" {
#define USB_SERIAL_ENDP_RX ((uint16_t) 0x3)
#define USB_SERIAL_BUF_SIZE (0x40)
-#define BOOTLOADER_VECT_TABLE ((uint32_t*)0x20000000)
-
-typedef void (*FuncPtr)(void);
-
-typedef struct {
- FuncPtr serial_tx_cb;
- FuncPtr serial_rx_cb;
- FuncPtr serial_linecoding_cb;
- uint32_t* serial_count_in;
- uint32_t* serial_count_out;
- uint8_t* serial_buffer_out;
- void* linecoding;
- uint8_t major_rev;
- uint8_t minor_rev;
- void* usb_device_ptr;
-} BootVectTable;
-
-extern BootVectTable* bootVect;
+#ifdef __cplusplus
+extern "C" {
+#endif
void usb_lpIRQHandler(void);
void usb_userToPMABufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr,u16 wNBytes);
void usb_PMAToUserBufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr,u16 wNBytes);
void usb_serialWriteStr(const char *outStr);
+void usb_serialWriteChar(unsigned char ch);
uint8_t usb_serialGetRecvLen();
+void usb_copyRecvBuffer(unsigned char* dest, uint8_t len);
#ifdef __cplusplus
} // extern "C"