Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: USBHostC270_example_GR-PEACH USBHostDac_example USBHostDac_Audio_in_out
Fork of USBHost_custom by
Diff: USBHostSerial/USBHostSerial.cpp
- Revision:
- 38:dd168a3e4194
- Parent:
- 36:f8c0979c2814
- Child:
- 40:cdc0d2ab4678
diff -r 22e8f744bbad -r dd168a3e4194 USBHostSerial/USBHostSerial.cpp
--- a/USBHostSerial/USBHostSerial.cpp Tue Feb 28 02:51:39 2017 +0000
+++ b/USBHostSerial/USBHostSerial.cpp Tue Mar 14 05:38:25 2017 +0000
@@ -194,11 +194,16 @@
#define SET_LINE_CODING 0x20
-USBHostSerialPort::USBHostSerialPort(): circ_buf()
+USBHostSerialPort::USBHostSerialPort()
{
+ p_circ_buf = new CircBufferHostSerial<uint8_t, (1024 * 32)>;
init();
}
+USBHostSerialPort::~USBHostSerialPort() {
+ delete p_circ_buf;
+}
+
void USBHostSerialPort::init(void)
{
dev_connected = false;
@@ -213,7 +218,7 @@
line_coding.data_bits = 8;
line_coding.parity = None;
line_coding.stop_bits = 1;
- circ_buf.flush();
+ p_circ_buf->flush();
}
void USBHostSerialPort::connect(USBHost* _host, USBDeviceConnected * _dev,
@@ -246,10 +251,10 @@
int len = bulk_in->getLengthTransferred();
if (bulk_in->getState() == USB_TYPE_IDLE) {
for (int i = 0; i < len; i++) {
- while (circ_buf.isFull()) {
+ while (p_circ_buf->isFull()) {
Thread::wait(1);
}
- circ_buf.queue(buf[i]);
+ p_circ_buf->queue(buf[i]);
}
rx.call();
host->bulkRead(dev, bulk_in, buf, size_bulk_in, false);
@@ -297,13 +302,13 @@
init();
return -1;
}
- while (circ_buf.isEmpty()) {
+ while (p_circ_buf->isEmpty()) {
if (dev_connected == false) {
return -1;
}
Thread::wait(1);
}
- circ_buf.dequeue(&c);
+ p_circ_buf->dequeue(&c);
return c;
}
@@ -327,9 +332,9 @@
int USBHostSerialPort::readBuf(char* b, int s, int timeout) {
int i = 0;
- if (bulk_out) {
+ if (bulk_in) {
for (i = 0; i < s; i++) {
- while ((circ_buf.isEmpty()) && (dev_connected)) {
+ while ((p_circ_buf->isEmpty()) && (dev_connected)) {
if (timeout == 0) {
break;
} else {
@@ -339,7 +344,7 @@
Thread::wait(1);
}
}
- if (!circ_buf.dequeue((uint8_t *)&b[i])) {
+ if (!p_circ_buf->dequeue((uint8_t *)&b[i])) {
break;
}
}
@@ -348,8 +353,9 @@
}
uint32_t USBHostSerialPort::available() {
- return circ_buf.available();
+ return p_circ_buf->available();
}
#endif
+
