USBHost library with fixes

Dependencies:   mbed-rtos FATFileSystem

Dependents:   mbedica

Committer:
zrussell3
Date:
Thu Dec 13 19:24:21 2018 +0000
Revision:
0:b176d95bb38f
Modified USBHost library to fix modifier input

Who changed what in which revision?

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