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.
USBDevice/USBSERIAL/.svn/text-base/USBSerial.cpp.svn-base@0:505207de8566, 2011-11-29 (annotated)
- Committer:
- znuh
- Date:
- Tue Nov 29 21:26:20 2011 +0000
- Revision:
- 0:505207de8566
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| znuh | 0:505207de8566 | 1 | // USBSerial.c |
| znuh | 0:505207de8566 | 2 | // USB device example: virtual serial port |
| znuh | 0:505207de8566 | 3 | // Copyright (c) 2011 ARM Limited. All rights reserved |
| znuh | 0:505207de8566 | 4 | |
| znuh | 0:505207de8566 | 5 | #include "stdint.h" |
| znuh | 0:505207de8566 | 6 | #include "USBSerial.h" |
| znuh | 0:505207de8566 | 7 | #include "USBBusInterface.h" |
| znuh | 0:505207de8566 | 8 | |
| znuh | 0:505207de8566 | 9 | |
| znuh | 0:505207de8566 | 10 | int USBSerial::_putc(int c) { |
| znuh | 0:505207de8566 | 11 | send(EPBULK_IN, (uint8_t *)&c, 1); |
| znuh | 0:505207de8566 | 12 | return 1; |
| znuh | 0:505207de8566 | 13 | } |
| znuh | 0:505207de8566 | 14 | |
| znuh | 0:505207de8566 | 15 | int USBSerial::_getc() { |
| znuh | 0:505207de8566 | 16 | uint16_t size = 0; |
| znuh | 0:505207de8566 | 17 | uint8_t c[65]; |
| znuh | 0:505207de8566 | 18 | if (!USBCDC::read(EPBULK_OUT, c, &size, 1)) |
| znuh | 0:505207de8566 | 19 | return -1; |
| znuh | 0:505207de8566 | 20 | return c[0]; |
| znuh | 0:505207de8566 | 21 | } |
| znuh | 0:505207de8566 | 22 | |
| znuh | 0:505207de8566 | 23 | |
| znuh | 0:505207de8566 | 24 | void USBSerial::attach(void (*ptr)(void)) |
| znuh | 0:505207de8566 | 25 | { |
| znuh | 0:505207de8566 | 26 | handler = true; |
| znuh | 0:505207de8566 | 27 | proc = true; |
| znuh | 0:505207de8566 | 28 | fn = ptr; |
| znuh | 0:505207de8566 | 29 | } |
| znuh | 0:505207de8566 | 30 | |
| znuh | 0:505207de8566 | 31 | bool USBSerial::EPBULK_OUT_callback() |
| znuh | 0:505207de8566 | 32 | { |
| znuh | 0:505207de8566 | 33 | if(handler) |
| znuh | 0:505207de8566 | 34 | { |
| znuh | 0:505207de8566 | 35 | if(proc) |
| znuh | 0:505207de8566 | 36 | (*fn)(); |
| znuh | 0:505207de8566 | 37 | else |
| znuh | 0:505207de8566 | 38 | rx.call(); |
| znuh | 0:505207de8566 | 39 | |
| znuh | 0:505207de8566 | 40 | // We reactivate the endpoint to receive next characters |
| znuh | 0:505207de8566 | 41 | readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
| znuh | 0:505207de8566 | 42 | return true; |
| znuh | 0:505207de8566 | 43 | } |
| znuh | 0:505207de8566 | 44 | return false; |
| znuh | 0:505207de8566 | 45 | } |