SD card interface
USBDevice/USBSERIAL/USBSerial.cpp@0:22612ae617a0, 2012-10-08 (annotated)
- Committer:
- lharoon
- Date:
- Mon Oct 08 11:14:07 2012 +0000
- Revision:
- 0:22612ae617a0
1st edition
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lharoon | 0:22612ae617a0 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
lharoon | 0:22612ae617a0 | 2 | * |
lharoon | 0:22612ae617a0 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
lharoon | 0:22612ae617a0 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
lharoon | 0:22612ae617a0 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
lharoon | 0:22612ae617a0 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
lharoon | 0:22612ae617a0 | 7 | * Software is furnished to do so, subject to the following conditions: |
lharoon | 0:22612ae617a0 | 8 | * |
lharoon | 0:22612ae617a0 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
lharoon | 0:22612ae617a0 | 10 | * substantial portions of the Software. |
lharoon | 0:22612ae617a0 | 11 | * |
lharoon | 0:22612ae617a0 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
lharoon | 0:22612ae617a0 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
lharoon | 0:22612ae617a0 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
lharoon | 0:22612ae617a0 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
lharoon | 0:22612ae617a0 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
lharoon | 0:22612ae617a0 | 17 | */ |
lharoon | 0:22612ae617a0 | 18 | |
lharoon | 0:22612ae617a0 | 19 | #include "stdint.h" |
lharoon | 0:22612ae617a0 | 20 | #include "USBSerial.h" |
lharoon | 0:22612ae617a0 | 21 | #include "USBBusInterface.h" |
lharoon | 0:22612ae617a0 | 22 | |
lharoon | 0:22612ae617a0 | 23 | |
lharoon | 0:22612ae617a0 | 24 | int USBSerial::_putc(int c) { |
lharoon | 0:22612ae617a0 | 25 | send((uint8_t *)&c, 1); |
lharoon | 0:22612ae617a0 | 26 | return 1; |
lharoon | 0:22612ae617a0 | 27 | } |
lharoon | 0:22612ae617a0 | 28 | |
lharoon | 0:22612ae617a0 | 29 | int USBSerial::_getc() { |
lharoon | 0:22612ae617a0 | 30 | uint8_t c; |
lharoon | 0:22612ae617a0 | 31 | while (buf.isEmpty()); |
lharoon | 0:22612ae617a0 | 32 | buf.dequeue(&c); |
lharoon | 0:22612ae617a0 | 33 | return c; |
lharoon | 0:22612ae617a0 | 34 | } |
lharoon | 0:22612ae617a0 | 35 | |
lharoon | 0:22612ae617a0 | 36 | |
lharoon | 0:22612ae617a0 | 37 | bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) { |
lharoon | 0:22612ae617a0 | 38 | if(size > MAX_PACKET_SIZE_EPBULK) { |
lharoon | 0:22612ae617a0 | 39 | return false; |
lharoon | 0:22612ae617a0 | 40 | } |
lharoon | 0:22612ae617a0 | 41 | if(!send(buf, size)) { |
lharoon | 0:22612ae617a0 | 42 | return false; |
lharoon | 0:22612ae617a0 | 43 | } |
lharoon | 0:22612ae617a0 | 44 | return true; |
lharoon | 0:22612ae617a0 | 45 | } |
lharoon | 0:22612ae617a0 | 46 | |
lharoon | 0:22612ae617a0 | 47 | |
lharoon | 0:22612ae617a0 | 48 | |
lharoon | 0:22612ae617a0 | 49 | bool USBSerial::EP2_OUT_callback() { |
lharoon | 0:22612ae617a0 | 50 | uint8_t c[65]; |
lharoon | 0:22612ae617a0 | 51 | uint16_t size = 0; |
lharoon | 0:22612ae617a0 | 52 | |
lharoon | 0:22612ae617a0 | 53 | //we read the packet received and put it on the circular buffer |
lharoon | 0:22612ae617a0 | 54 | readEP(c, &size); |
lharoon | 0:22612ae617a0 | 55 | for (int i = 0; i < size; i++) { |
lharoon | 0:22612ae617a0 | 56 | buf.queue(c[i]); |
lharoon | 0:22612ae617a0 | 57 | } |
lharoon | 0:22612ae617a0 | 58 | |
lharoon | 0:22612ae617a0 | 59 | //call a potential handler |
lharoon | 0:22612ae617a0 | 60 | rx.call(); |
lharoon | 0:22612ae617a0 | 61 | |
lharoon | 0:22612ae617a0 | 62 | // We reactivate the endpoint to receive next characters |
lharoon | 0:22612ae617a0 | 63 | readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
lharoon | 0:22612ae617a0 | 64 | return true; |
lharoon | 0:22612ae617a0 | 65 | } |
lharoon | 0:22612ae617a0 | 66 | |
lharoon | 0:22612ae617a0 | 67 | uint8_t USBSerial::available() { |
lharoon | 0:22612ae617a0 | 68 | return buf.available(); |
lharoon | 0:22612ae617a0 | 69 | } |
lharoon | 0:22612ae617a0 | 70 |