PHS module SMA-01 library. see: https://developer.mbed.org/users/phsfan/notebook/abitusbmodem/
Dependencies: Socket lwip-sys lwip
Dependents: AbitUSBModem_HTTPTest AbitUSBModem_MQTTTest AbitUSBModem_WebsocketTest AbitUSBModem_SMSTest
Fork of VodafoneUSBModem by
USBHostPhs.h
00001 /* USBHostPhs.h */ 00002 /* Modified by 2015 phsfan 00003 * for ABIT SMA-01 00004 */ 00005 /* mbed USBHost Library 00006 * Copyright (c) 2006-2013 ARM Limited 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 */ 00020 00021 /* WANDongle.h, WANDongleSerialPort.h */ 00022 /* Copyright (c) 2010-2012 mbed.org, MIT License 00023 * 00024 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00025 * and associated documentation files (the "Software"), to deal in the Software without 00026 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00027 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00028 * Software is furnished to do so, subject to the following conditions: 00029 * 00030 * The above copyright notice and this permission notice shall be included in all copies or 00031 * substantial portions of the Software. 00032 * 00033 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00034 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00035 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00036 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00037 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00038 */ 00039 00040 #ifndef _USBHostPhs_H_ 00041 #define _USBHostPhs_H_ 00042 00043 #include "USBHost.h" 00044 #include "IUSBHostSerial.h" 00045 00046 #include "rtos.h" 00047 00048 #define PHS_VID 0x075E 00049 #define PHS_PID 0x0028 00050 00051 #define WANDONGLE_MAX_OUTEP_SIZE 64 00052 #define WANDONGLE_MAX_INEP_SIZE 64 00053 00054 /** 00055 * A class to communicate a USB virtual serial port 00056 */ 00057 class USBHostPhsPort : public IUSBHostSerial { 00058 public: 00059 /** 00060 * Constructor 00061 */ 00062 USBHostPhsPort(); 00063 00064 enum IrqType { 00065 RxIrq, 00066 TxIrq 00067 }; 00068 00069 enum Parity { 00070 None = 0, 00071 Odd, 00072 Even, 00073 Mark, 00074 Space 00075 }; 00076 00077 void connect(USBHost* _host, USBDeviceConnected * _dev, 00078 uint8_t _serial_intf, USBEndpoint* _bulk_in, USBEndpoint* _bulk_out); 00079 00080 /** Set the baud rate of the serial port 00081 * 00082 * @param baudrate The baudrate of the serial port (default = 9600). 00083 */ 00084 void baud(int baudrate = 921600); 00085 00086 /** Set the transmission format used by the Serial port 00087 * 00088 * @param bits The number of bits in a word (default = 8) 00089 * @param parity The parity used (USBHostSerialPort::None, USBHostSerialPort::Odd, USBHostSerialPort::Even, USBHostSerialPort::Mark, USBHostSerialPort::Space; default = USBHostSerialPort::None) 00090 * @param stop The number of stop bits (1 or 2; default = 1) 00091 */ 00092 void format(int bits = 8, Parity parity = USBHostPhsPort::None, int stop_bits = 1); 00093 00094 virtual int getc(); 00095 virtual int putc(int c); 00096 virtual int readPacket(); 00097 virtual int writePacket(); 00098 virtual int readable(); 00099 virtual int writeable(); 00100 virtual void attach(IUSBHostSerialListener* pListener); 00101 virtual void setupIrq(bool en, IUSBHostSerial::IrqType irq = IUSBHostSerial::RxIrq); 00102 00103 protected: 00104 void reset(); 00105 00106 private: 00107 USBHost * host; 00108 USBDeviceConnected * dev; 00109 00110 USBEndpoint * bulk_in; 00111 USBEndpoint * bulk_out; 00112 uint32_t size_bulk_in; 00113 uint32_t size_bulk_out; 00114 00115 void init(); 00116 00117 uint8_t buf[64]; 00118 00119 typedef struct { 00120 uint32_t baudrate; 00121 uint8_t stop_bits; 00122 uint8_t parity; 00123 uint8_t data_bits; 00124 } PACKED LINE_CODING; 00125 00126 LINE_CODING line_coding; 00127 00128 void rxHandler(); 00129 void txHandler(); 00130 00131 uint8_t serial_intf; 00132 00133 00134 uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE]; 00135 volatile uint32_t buf_out_len; 00136 uint32_t max_out_size; 00137 volatile bool lock_tx; 00138 volatile bool cb_tx_en; 00139 volatile bool cb_tx_pending; 00140 Mutex tx_mtx; 00141 00142 uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE]; 00143 volatile uint32_t buf_in_len; 00144 volatile uint32_t buf_in_read_pos; 00145 volatile bool lock_rx; 00146 volatile bool cb_rx_en; 00147 volatile bool cb_rx_pending; 00148 Mutex rx_mtx; 00149 00150 IUSBHostSerialListener* listener; 00151 00152 }; 00153 00154 00155 class USBHostPhs : public IUSBEnumerator, public USBHostPhsPort 00156 { 00157 public: 00158 USBHostPhs(); 00159 00160 /** 00161 * Try to connect a serial device 00162 * 00163 * @return true if connection was successful 00164 */ 00165 bool connect(); 00166 00167 void disconnect(); 00168 00169 /** 00170 * Check if a any serial port is connected 00171 * 00172 * @returns true if a serial device is connected 00173 */ 00174 bool connected(); 00175 00176 protected: 00177 USBHost* host; 00178 USBDeviceConnected* dev; 00179 uint8_t port_intf; 00180 int ports_found; 00181 00182 //From IUSBEnumerator 00183 virtual void setVidPid(uint16_t vid, uint16_t pid); 00184 virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed 00185 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used 00186 00187 private: 00188 bool dev_connected; 00189 }; 00190 00191 #endif
Generated on Wed Jul 13 2022 01:40:22 by 1.7.2