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.
Dependencies: mbed USBMSD_SD USBDevice
USBDevice/USBSERIAL/USBSerial.cpp@6:126c4d980196, 2011-11-14 (annotated)
- Committer:
- samux
- Date:
- Mon Nov 14 10:00:07 2011 +0000
- Revision:
- 6:126c4d980196
- Parent:
- 2:27a7e7f8d399
now we have a connect inside USBMSD to get all capacities from storage chip
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| samux |
2:27a7e7f8d399 | 1 | // USBSerial.c |
| samux |
2:27a7e7f8d399 | 2 | // USB device example: virtual serial port |
| samux |
2:27a7e7f8d399 | 3 | // Copyright (c) 2011 ARM Limited. All rights reserved |
| samux |
2:27a7e7f8d399 | 4 | |
| samux |
2:27a7e7f8d399 | 5 | #include "stdint.h" |
| samux |
2:27a7e7f8d399 | 6 | #include "USBSerial.h" |
| samux |
2:27a7e7f8d399 | 7 | #include "USBBusInterface.h" |
| samux |
2:27a7e7f8d399 | 8 | |
| samux |
2:27a7e7f8d399 | 9 | |
| samux |
2:27a7e7f8d399 | 10 | int USBSerial::_putc(int c) { |
| samux |
2:27a7e7f8d399 | 11 | send(EPBULK_IN, (uint8_t *)&c, 1); |
| samux |
2:27a7e7f8d399 | 12 | return 1; |
| samux |
2:27a7e7f8d399 | 13 | } |
| samux |
2:27a7e7f8d399 | 14 | |
| samux |
2:27a7e7f8d399 | 15 | int USBSerial::_getc() { |
| samux |
2:27a7e7f8d399 | 16 | uint8_t c; |
| samux |
2:27a7e7f8d399 | 17 | while (buf.isEmpty()); |
| samux |
2:27a7e7f8d399 | 18 | buf.dequeue(&c); |
| samux |
2:27a7e7f8d399 | 19 | return c; |
| samux |
2:27a7e7f8d399 | 20 | } |
| samux |
2:27a7e7f8d399 | 21 | |
| samux |
2:27a7e7f8d399 | 22 | void USBSerial::attach(void (*ptr)(void)) { |
| samux |
2:27a7e7f8d399 | 23 | handler = true; |
| samux |
2:27a7e7f8d399 | 24 | proc = true; |
| samux |
2:27a7e7f8d399 | 25 | fn = ptr; |
| samux |
2:27a7e7f8d399 | 26 | } |
| samux |
2:27a7e7f8d399 | 27 | |
| samux |
2:27a7e7f8d399 | 28 | |
| samux |
2:27a7e7f8d399 | 29 | bool USBSerial::EP2_OUT_callback() { |
| samux |
2:27a7e7f8d399 | 30 | uint8_t c[65]; |
| samux |
2:27a7e7f8d399 | 31 | uint16_t size = 0; |
| samux |
2:27a7e7f8d399 | 32 | |
| samux |
2:27a7e7f8d399 | 33 | //we read the packet received and put it on the circular buffer |
| samux |
2:27a7e7f8d399 | 34 | USBCDC::read(EPBULK_OUT, c, &size, MAX_PACKET_SIZE_EPBULK); |
| samux |
2:27a7e7f8d399 | 35 | for (int i = 0; i < size; i++) { |
| samux |
2:27a7e7f8d399 | 36 | buf.queue(c[i]); |
| samux |
2:27a7e7f8d399 | 37 | } |
| samux |
2:27a7e7f8d399 | 38 | |
| samux |
2:27a7e7f8d399 | 39 | //call a potential handler |
| samux |
2:27a7e7f8d399 | 40 | if (handler) { |
| samux |
2:27a7e7f8d399 | 41 | if (proc) { |
| samux |
2:27a7e7f8d399 | 42 | (*fn)(); |
| samux |
2:27a7e7f8d399 | 43 | } else { |
| samux |
2:27a7e7f8d399 | 44 | rx.call(); |
| samux |
2:27a7e7f8d399 | 45 | } |
| samux |
2:27a7e7f8d399 | 46 | } |
| samux |
2:27a7e7f8d399 | 47 | |
| samux |
2:27a7e7f8d399 | 48 | // We reactivate the endpoint to receive next characters |
| samux |
2:27a7e7f8d399 | 49 | readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
| samux |
2:27a7e7f8d399 | 50 | return true; |
| samux |
2:27a7e7f8d399 | 51 | } |
| samux |
2:27a7e7f8d399 | 52 | |
| samux |
2:27a7e7f8d399 | 53 | uint8_t USBSerial::available() { |
| samux |
2:27a7e7f8d399 | 54 | return buf.available(); |
| samux |
2:27a7e7f8d399 | 55 | } |