USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.
Dependencies: FATFileSystem mbed-rtos
Dependents: BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... more
WANDongleSerialPort.h
00001 /* Copyright (c) 2010-2012 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef WANDONGLESERIALPORT_H 00020 #define WANDONGLESERIALPORT_H 00021 00022 #include "USBHostConf.h" 00023 00024 #ifdef USBHOST_3GMODULE 00025 00026 #include "USBHost.h" 00027 #include "IUSBHostSerial.h" 00028 00029 #include "rtos.h" 00030 00031 00032 #define WANDONGLE_MAX_OUTEP_SIZE 64 00033 #define WANDONGLE_MAX_INEP_SIZE 64 00034 00035 /** A class to use a WAN (3G/LTE) access dongle 00036 * 00037 */ 00038 class WANDongleSerialPort : public IUSBHostSerial { 00039 public: 00040 /* 00041 * Constructor 00042 * 00043 */ 00044 WANDongleSerialPort(); 00045 00046 void init( USBHost* pHost ); 00047 00048 void connect( USBDeviceConnected* pDev, USBEndpoint* pInEp, USBEndpoint* pOutEp ); 00049 00050 void disconnect( ); 00051 00052 /* 00053 * Get a char from the dongle's serial interface 00054 */ 00055 virtual int getc(); 00056 00057 /* 00058 * Put a char to the dongle's serial interface 00059 */ 00060 virtual int putc(int c); 00061 00062 /* 00063 * Read a packet from the dongle's serial interface, to be called after multiple getc() calls 00064 */ 00065 virtual int readPacket(); 00066 00067 /* 00068 * Write a packet to the dongle's serial interface, to be called after multiple putc() calls 00069 */ 00070 virtual int writePacket(); 00071 00072 /** 00073 * Check the number of bytes available. 00074 * 00075 * @returns the number of bytes available 00076 */ 00077 virtual int readable(); 00078 00079 /** 00080 * Check the free space in output. 00081 * 00082 * @returns the number of bytes available 00083 */ 00084 virtual int writeable(); 00085 00086 /** 00087 * Attach a handler to call when a packet is received / when a packet has been transmitted. 00088 * 00089 * @param pListener instance of the listener deriving from the IUSBHostSerialListener 00090 */ 00091 virtual void attach(IUSBHostSerialListener* pListener); 00092 00093 /** 00094 * Enable or disable readable/writeable callbacks 00095 */ 00096 virtual void setupIrq(bool en, IrqType irq = RxIrq); 00097 00098 00099 protected: 00100 USBEndpoint * bulk_in; 00101 USBEndpoint * bulk_out; 00102 USBHost * host; 00103 USBDeviceConnected * dev; 00104 00105 uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE]; 00106 volatile uint32_t buf_out_len; 00107 uint32_t max_out_size; 00108 volatile bool lock_tx; 00109 volatile bool cb_tx_en; 00110 volatile bool cb_tx_pending; 00111 Mutex tx_mtx; 00112 00113 uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE]; 00114 volatile uint32_t buf_in_len; 00115 volatile uint32_t buf_in_read_pos; 00116 volatile bool lock_rx; 00117 volatile bool cb_rx_en; 00118 volatile bool cb_rx_pending; 00119 Mutex rx_mtx; 00120 00121 IUSBHostSerialListener* listener; 00122 00123 void reset(); 00124 00125 void rxHandler(); 00126 void txHandler(); 00127 00128 }; 00129 00130 #endif /* USBHOST_3GMODULE */ 00131 00132 #endif 00133
Generated on Tue Jul 12 2022 13:32:26 by 1.7.2