aboutsummaryrefslogtreecommitdiffstats
path: root/wirish
diff options
context:
space:
mode:
Diffstat (limited to 'wirish')
-rw-r--r--wirish/Print.cpp8
-rw-r--r--wirish/Print.h2
-rw-r--r--wirish/WProgram.h3
-rw-r--r--wirish/usb_serial.cpp (renamed from wirish/comm/HardwareUsb.cpp)50
-rw-r--r--wirish/usb_serial.h (renamed from wirish/comm/HardwareUsb.h)38
-rw-r--r--wirish/wirish.h6
6 files changed, 64 insertions, 43 deletions
diff --git a/wirish/Print.cpp b/wirish/Print.cpp
index 5a1bc93..9baa757 100644
--- a/wirish/Print.cpp
+++ b/wirish/Print.cpp
@@ -32,10 +32,12 @@ void Print::write(const char *str)
}
/* default implementation: may be overridden */
-void Print::write(const uint8 *buffer, uint32 size)
+void Print::write(void *buffer, uint32 size)
{
- while (size--)
- write(*buffer++);
+ uint8 *ch = (uint8*)buffer;
+ while (size--) {
+ write(*ch++);
+ }
}
void Print::print(uint8 b)
diff --git a/wirish/Print.h b/wirish/Print.h
index b2f8647..72208b4 100644
--- a/wirish/Print.h
+++ b/wirish/Print.h
@@ -36,7 +36,7 @@ class Print
public:
virtual void write(uint8) = 0;
virtual void write(const char *str);
- virtual void write(const uint8 *buffer, uint32 size);
+ virtual void write(void *, uint32);
void print(char);
void print(const char[]);
void print(uint8);
diff --git a/wirish/WProgram.h b/wirish/WProgram.h
index 889219e..9143991 100644
--- a/wirish/WProgram.h
+++ b/wirish/WProgram.h
@@ -23,9 +23,6 @@
* ****************************************************************************/
#include "wirish.h"
-#include "HardwareSerial.h"
-#include "HardwareUsb.h"
-#include "math.h"
void setup();
void loop();
diff --git a/wirish/comm/HardwareUsb.cpp b/wirish/usb_serial.cpp
index 064bcc8..9476e99 100644
--- a/wirish/comm/HardwareUsb.cpp
+++ b/wirish/usb_serial.cpp
@@ -1,7 +1,7 @@
/* *****************************************************************************
* The MIT License
*
- * Copyright (c) 2010 Andrew Meyer.
+ * Copyright (c) 2010 Perry Hung.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,38 +23,50 @@
* ****************************************************************************/
/**
- * @brief Wiring like serial api to USB virtual COM
+ * @brief wirish usb class for easy goin communication, uses libmaple's
+ * virtual com port implementation
*/
+#include <string.h>
+
#include "wirish.h"
-#include "HardwareUsb.h"
#include "usb.h"
-HardwareUsb::HardwareUsb(void) {
+USBSerial :: USBSerial(void) {
}
-uint8 HardwareUsb::read(void) {
- uint8 outVal;
- usbReceiveBytes(&outVal,1);
- return outVal;
+void USBSerial::write(uint8 ch) {
+ usbSendBytes(&ch, 1);
}
-uint8 HardwareUsb::available(void) {
- return usbBytesAvailable();
+void USBSerial::write(const char *str) {
+ uint32 len = strlen(str);
+ usbSendBytes((uint8*)str, len);
}
-void HardwareUsb::flush(void) {
- uint8 totalBytes = usbBytesAvailable();
- uint8 recvBuf[totalBytes];
- usbReceiveBytes(recvBuf,totalBytes);
+void USBSerial::write(void *buf, uint32 size) {
+ if (!buf) {
+ return;
+ }
+ usbSendBytes((uint8*)buf, size);
}
-void HardwareUsb::write(unsigned char ch) {
- while (usbSendBytes(&ch, 1) == 0);
+uint32 USBSerial::available(void) {
+ return usbBytesAvailable();
}
-void HardwareUsb::begin(void) {
- /* placeholder for usb<->uart linking */
+uint32 USBSerial::read(void *buf, uint32 len) {
+ if (!buf) {
+ return 0;
+ }
+
+ return usbReceiveBytes((uint8*)buf, len);
}
-HardwareUsb Usb;
+uint8 USBSerial::read(void) {
+ uint8 ch;
+ return usbReceiveBytes(&ch, 1);
+}
+
+USBSerial SerialUSB;
+
diff --git a/wirish/comm/HardwareUsb.h b/wirish/usb_serial.h
index e2af2e2..e1c61ff 100644
--- a/wirish/comm/HardwareUsb.h
+++ b/wirish/usb_serial.h
@@ -1,7 +1,7 @@
/* *****************************************************************************
* The MIT License
*
- * Copyright (c) 2010 Andrew Meyer.
+ * Copyright (c) 2010 Perry Hung.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,26 +23,30 @@
* ****************************************************************************/
/**
- * @brief Wiring like serial api to USB virtual COM. Dummy implmentation wrapping printChar() around usb.h for now. Todo: something better.
+ * @brief wirish usb class for easy goin communication, uses libmaple's
+ * virtual com port implementation
*/
-#ifndef _HARDWAREUSB_H_
-#define _HARDWAREUSB_H_
+#ifndef _USB_SERIAL_H_
+#define _USB_SERIAL_H_
#include "Print.h"
-#include "usb.h"
-
-class HardwareUsb : public Print {
- public:
- HardwareUsb(void);
- void begin();
- uint8 available(void);
- uint8 read(void);
- void flush(void);
- virtual void write(unsigned char);
- using Print::write;
+
+class USBSerial : public Print {
+ public:
+ USBSerial(void);
+
+ uint32 available(void);
+
+ uint32 read(void *buf, uint32 len);
+ uint8 read(void);
+
+ void write(uint8);
+ void write(const char *str);
+ void write(void *, uint32);
};
-extern HardwareUsb Usb;
+extern USBSerial SerialUSB;
+
+#endif
-#endif //_HARDWAREUSB_H/* *****************************************************************************
diff --git a/wirish/wirish.h b/wirish/wirish.h
index f54517a..2541e5e 100644
--- a/wirish/wirish.h
+++ b/wirish/wirish.h
@@ -41,6 +41,12 @@
#include "wirish_math.h"
#ifdef __cplusplus
+#include "HardwareSPI.h"
+#include "HardwareSerial.h"
+#include "usb_serial.h"
+#endif
+
+#ifdef __cplusplus
extern "C"{
#endif