added USB host

Dependencies:   FATFileSystem mbed-rtos

Dependents:   app-board-Speaker

Fork of USBHost by mbed official

Committer:
toyohara
Date:
Sun Dec 11 05:47:22 2016 +0000
Revision:
36:86650e205c6c
Parent:
24:868cbfe611a7
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 17:c7b1b8451598 1 /* Copyright (c) 2010-2012 mbed.org, MIT License
mbed_official 17:c7b1b8451598 2 *
mbed_official 17:c7b1b8451598 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mbed_official 17:c7b1b8451598 4 * and associated documentation files (the "Software"), to deal in the Software without
mbed_official 17:c7b1b8451598 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mbed_official 17:c7b1b8451598 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mbed_official 17:c7b1b8451598 7 * Software is furnished to do so, subject to the following conditions:
mbed_official 17:c7b1b8451598 8 *
mbed_official 17:c7b1b8451598 9 * The above copyright notice and this permission notice shall be included in all copies or
mbed_official 17:c7b1b8451598 10 * substantial portions of the Software.
mbed_official 17:c7b1b8451598 11 *
mbed_official 17:c7b1b8451598 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mbed_official 17:c7b1b8451598 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mbed_official 17:c7b1b8451598 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mbed_official 17:c7b1b8451598 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 17:c7b1b8451598 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mbed_official 17:c7b1b8451598 17 */
mbed_official 17:c7b1b8451598 18
mbed_official 17:c7b1b8451598 19 #ifndef WANDONGLESERIALPORT_H
mbed_official 17:c7b1b8451598 20 #define WANDONGLESERIALPORT_H
mbed_official 17:c7b1b8451598 21
mbed_official 17:c7b1b8451598 22 #include "USBHostConf.h"
mbed_official 17:c7b1b8451598 23
mbed_official 17:c7b1b8451598 24 #ifdef USBHOST_3GMODULE
mbed_official 17:c7b1b8451598 25
mbed_official 17:c7b1b8451598 26 #include "USBHost.h"
mbed_official 17:c7b1b8451598 27 #include "IUSBHostSerial.h"
mbed_official 17:c7b1b8451598 28
mbed_official 17:c7b1b8451598 29 #include "rtos.h"
mbed_official 17:c7b1b8451598 30
mbed_official 17:c7b1b8451598 31
mbed_official 17:c7b1b8451598 32 #define WANDONGLE_MAX_OUTEP_SIZE 64
mbed_official 17:c7b1b8451598 33 #define WANDONGLE_MAX_INEP_SIZE 64
mbed_official 17:c7b1b8451598 34
mbed_official 17:c7b1b8451598 35 /** A class to use a WAN (3G/LTE) access dongle
mbed_official 17:c7b1b8451598 36 *
mbed_official 17:c7b1b8451598 37 */
mbed_official 17:c7b1b8451598 38 class WANDongleSerialPort : public IUSBHostSerial {
mbed_official 17:c7b1b8451598 39 public:
mbed_official 17:c7b1b8451598 40 /*
mbed_official 17:c7b1b8451598 41 * Constructor
mbed_official 17:c7b1b8451598 42 *
mbed_official 17:c7b1b8451598 43 */
mbed_official 17:c7b1b8451598 44 WANDongleSerialPort();
mbed_official 24:868cbfe611a7 45
mbed_official 17:c7b1b8451598 46 void init( USBHost* pHost );
mbed_official 24:868cbfe611a7 47
mbed_official 17:c7b1b8451598 48 void connect( USBDeviceConnected* pDev, USBEndpoint* pInEp, USBEndpoint* pOutEp );
mbed_official 24:868cbfe611a7 49
mbed_official 17:c7b1b8451598 50 void disconnect( );
mbed_official 17:c7b1b8451598 51
mbed_official 17:c7b1b8451598 52 /*
mbed_official 17:c7b1b8451598 53 * Get a char from the dongle's serial interface
mbed_official 17:c7b1b8451598 54 */
mbed_official 17:c7b1b8451598 55 virtual int getc();
mbed_official 17:c7b1b8451598 56
mbed_official 17:c7b1b8451598 57 /*
mbed_official 17:c7b1b8451598 58 * Put a char to the dongle's serial interface
mbed_official 17:c7b1b8451598 59 */
mbed_official 17:c7b1b8451598 60 virtual int putc(int c);
mbed_official 17:c7b1b8451598 61
mbed_official 17:c7b1b8451598 62 /*
mbed_official 17:c7b1b8451598 63 * Read a packet from the dongle's serial interface, to be called after multiple getc() calls
mbed_official 17:c7b1b8451598 64 */
mbed_official 17:c7b1b8451598 65 virtual int readPacket();
mbed_official 17:c7b1b8451598 66
mbed_official 17:c7b1b8451598 67 /*
mbed_official 17:c7b1b8451598 68 * Write a packet to the dongle's serial interface, to be called after multiple putc() calls
mbed_official 17:c7b1b8451598 69 */
mbed_official 17:c7b1b8451598 70 virtual int writePacket();
mbed_official 17:c7b1b8451598 71
mbed_official 17:c7b1b8451598 72 /**
mbed_official 17:c7b1b8451598 73 * Check the number of bytes available.
mbed_official 17:c7b1b8451598 74 *
mbed_official 17:c7b1b8451598 75 * @returns the number of bytes available
mbed_official 17:c7b1b8451598 76 */
mbed_official 17:c7b1b8451598 77 virtual int readable();
mbed_official 17:c7b1b8451598 78
mbed_official 17:c7b1b8451598 79 /**
mbed_official 17:c7b1b8451598 80 * Check the free space in output.
mbed_official 17:c7b1b8451598 81 *
mbed_official 17:c7b1b8451598 82 * @returns the number of bytes available
mbed_official 17:c7b1b8451598 83 */
mbed_official 17:c7b1b8451598 84 virtual int writeable();
mbed_official 17:c7b1b8451598 85
mbed_official 17:c7b1b8451598 86 /**
mbed_official 17:c7b1b8451598 87 * Attach a handler to call when a packet is received / when a packet has been transmitted.
mbed_official 17:c7b1b8451598 88 *
mbed_official 17:c7b1b8451598 89 * @param pListener instance of the listener deriving from the IUSBHostSerialListener
mbed_official 17:c7b1b8451598 90 */
mbed_official 17:c7b1b8451598 91 virtual void attach(IUSBHostSerialListener* pListener);
mbed_official 24:868cbfe611a7 92
mbed_official 17:c7b1b8451598 93 /**
mbed_official 17:c7b1b8451598 94 * Enable or disable readable/writeable callbacks
mbed_official 17:c7b1b8451598 95 */
mbed_official 17:c7b1b8451598 96 virtual void setupIrq(bool en, IrqType irq = RxIrq);
mbed_official 17:c7b1b8451598 97
mbed_official 24:868cbfe611a7 98
mbed_official 17:c7b1b8451598 99 protected:
mbed_official 17:c7b1b8451598 100 USBEndpoint * bulk_in;
mbed_official 17:c7b1b8451598 101 USBEndpoint * bulk_out;
mbed_official 17:c7b1b8451598 102 USBHost * host;
mbed_official 17:c7b1b8451598 103 USBDeviceConnected * dev;
mbed_official 17:c7b1b8451598 104
mbed_official 17:c7b1b8451598 105 uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE];
mbed_official 17:c7b1b8451598 106 volatile uint32_t buf_out_len;
mbed_official 17:c7b1b8451598 107 uint32_t max_out_size;
mbed_official 17:c7b1b8451598 108 volatile bool lock_tx;
mbed_official 17:c7b1b8451598 109 volatile bool cb_tx_en;
mbed_official 17:c7b1b8451598 110 volatile bool cb_tx_pending;
mbed_official 17:c7b1b8451598 111 Mutex tx_mtx;
mbed_official 17:c7b1b8451598 112
mbed_official 17:c7b1b8451598 113 uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE];
mbed_official 17:c7b1b8451598 114 volatile uint32_t buf_in_len;
mbed_official 17:c7b1b8451598 115 volatile uint32_t buf_in_read_pos;
mbed_official 17:c7b1b8451598 116 volatile bool lock_rx;
mbed_official 17:c7b1b8451598 117 volatile bool cb_rx_en;
mbed_official 17:c7b1b8451598 118 volatile bool cb_rx_pending;
mbed_official 17:c7b1b8451598 119 Mutex rx_mtx;
mbed_official 24:868cbfe611a7 120
mbed_official 17:c7b1b8451598 121 IUSBHostSerialListener* listener;
mbed_official 24:868cbfe611a7 122
mbed_official 17:c7b1b8451598 123 void reset();
mbed_official 24:868cbfe611a7 124
mbed_official 17:c7b1b8451598 125 void rxHandler();
mbed_official 17:c7b1b8451598 126 void txHandler();
mbed_official 17:c7b1b8451598 127
mbed_official 17:c7b1b8451598 128 };
mbed_official 17:c7b1b8451598 129
mbed_official 17:c7b1b8451598 130 #endif /* USBHOST_3GMODULE */
mbed_official 17:c7b1b8451598 131
mbed_official 17:c7b1b8451598 132 #endif
mbed_official 17:c7b1b8451598 133