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/USBHostPhs.h@97:7d9cc95e2ea7, 2015-02-18 (annotated)
- Committer:
- phsfan
- Date:
- Wed Feb 18 14:11:24 2015 +0000
- Revision:
- 97:7d9cc95e2ea7
- Parent:
- 96:b50f5f795684
support sms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phsfan | 97:7d9cc95e2ea7 | 1 | /* USBHostPhs.h */ |
phsfan | 97:7d9cc95e2ea7 | 2 | /* Modified by 2015 phsfan |
phsfan | 97:7d9cc95e2ea7 | 3 | * for ABIT SMA-01 |
phsfan | 97:7d9cc95e2ea7 | 4 | */ |
phsfan | 96:b50f5f795684 | 5 | /* mbed USBHost Library |
phsfan | 96:b50f5f795684 | 6 | * Copyright (c) 2006-2013 ARM Limited |
phsfan | 96:b50f5f795684 | 7 | * |
phsfan | 96:b50f5f795684 | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
phsfan | 96:b50f5f795684 | 9 | * you may not use this file except in compliance with the License. |
phsfan | 96:b50f5f795684 | 10 | * You may obtain a copy of the License at |
phsfan | 96:b50f5f795684 | 11 | * |
phsfan | 96:b50f5f795684 | 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
phsfan | 96:b50f5f795684 | 13 | * |
phsfan | 96:b50f5f795684 | 14 | * Unless required by applicable law or agreed to in writing, software |
phsfan | 96:b50f5f795684 | 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
phsfan | 96:b50f5f795684 | 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
phsfan | 96:b50f5f795684 | 17 | * See the License for the specific language governing permissions and |
phsfan | 96:b50f5f795684 | 18 | * limitations under the License. |
phsfan | 96:b50f5f795684 | 19 | */ |
phsfan | 96:b50f5f795684 | 20 | |
phsfan | 97:7d9cc95e2ea7 | 21 | /* WANDongle.h, WANDongleSerialPort.h */ |
phsfan | 97:7d9cc95e2ea7 | 22 | /* Copyright (c) 2010-2012 mbed.org, MIT License |
phsfan | 97:7d9cc95e2ea7 | 23 | * |
phsfan | 97:7d9cc95e2ea7 | 24 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
phsfan | 97:7d9cc95e2ea7 | 25 | * and associated documentation files (the "Software"), to deal in the Software without |
phsfan | 97:7d9cc95e2ea7 | 26 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
phsfan | 97:7d9cc95e2ea7 | 27 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
phsfan | 97:7d9cc95e2ea7 | 28 | * Software is furnished to do so, subject to the following conditions: |
phsfan | 97:7d9cc95e2ea7 | 29 | * |
phsfan | 97:7d9cc95e2ea7 | 30 | * The above copyright notice and this permission notice shall be included in all copies or |
phsfan | 97:7d9cc95e2ea7 | 31 | * substantial portions of the Software. |
phsfan | 97:7d9cc95e2ea7 | 32 | * |
phsfan | 97:7d9cc95e2ea7 | 33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
phsfan | 97:7d9cc95e2ea7 | 34 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
phsfan | 97:7d9cc95e2ea7 | 35 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
phsfan | 97:7d9cc95e2ea7 | 36 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
phsfan | 97:7d9cc95e2ea7 | 37 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
phsfan | 97:7d9cc95e2ea7 | 38 | */ |
phsfan | 97:7d9cc95e2ea7 | 39 | |
phsfan | 96:b50f5f795684 | 40 | #ifndef _USBHostPhs_H_ |
phsfan | 96:b50f5f795684 | 41 | #define _USBHostPhs_H_ |
phsfan | 96:b50f5f795684 | 42 | |
phsfan | 96:b50f5f795684 | 43 | #include "USBHost.h" |
phsfan | 96:b50f5f795684 | 44 | #include "IUSBHostSerial.h" |
phsfan | 96:b50f5f795684 | 45 | |
phsfan | 96:b50f5f795684 | 46 | #include "rtos.h" |
phsfan | 96:b50f5f795684 | 47 | |
phsfan | 96:b50f5f795684 | 48 | #define PHS_VID 0x075E |
phsfan | 96:b50f5f795684 | 49 | #define PHS_PID 0x0028 |
phsfan | 96:b50f5f795684 | 50 | |
phsfan | 96:b50f5f795684 | 51 | #define WANDONGLE_MAX_OUTEP_SIZE 64 |
phsfan | 96:b50f5f795684 | 52 | #define WANDONGLE_MAX_INEP_SIZE 64 |
phsfan | 96:b50f5f795684 | 53 | |
phsfan | 96:b50f5f795684 | 54 | /** |
phsfan | 96:b50f5f795684 | 55 | * A class to communicate a USB virtual serial port |
phsfan | 96:b50f5f795684 | 56 | */ |
phsfan | 96:b50f5f795684 | 57 | class USBHostPhsPort : public IUSBHostSerial { |
phsfan | 96:b50f5f795684 | 58 | public: |
phsfan | 96:b50f5f795684 | 59 | /** |
phsfan | 96:b50f5f795684 | 60 | * Constructor |
phsfan | 96:b50f5f795684 | 61 | */ |
phsfan | 96:b50f5f795684 | 62 | USBHostPhsPort(); |
phsfan | 96:b50f5f795684 | 63 | |
phsfan | 96:b50f5f795684 | 64 | enum IrqType { |
phsfan | 96:b50f5f795684 | 65 | RxIrq, |
phsfan | 96:b50f5f795684 | 66 | TxIrq |
phsfan | 96:b50f5f795684 | 67 | }; |
phsfan | 96:b50f5f795684 | 68 | |
phsfan | 96:b50f5f795684 | 69 | enum Parity { |
phsfan | 96:b50f5f795684 | 70 | None = 0, |
phsfan | 96:b50f5f795684 | 71 | Odd, |
phsfan | 96:b50f5f795684 | 72 | Even, |
phsfan | 96:b50f5f795684 | 73 | Mark, |
phsfan | 96:b50f5f795684 | 74 | Space |
phsfan | 96:b50f5f795684 | 75 | }; |
phsfan | 96:b50f5f795684 | 76 | |
phsfan | 96:b50f5f795684 | 77 | void connect(USBHost* _host, USBDeviceConnected * _dev, |
phsfan | 96:b50f5f795684 | 78 | uint8_t _serial_intf, USBEndpoint* _bulk_in, USBEndpoint* _bulk_out); |
phsfan | 96:b50f5f795684 | 79 | |
phsfan | 96:b50f5f795684 | 80 | /** Set the baud rate of the serial port |
phsfan | 96:b50f5f795684 | 81 | * |
phsfan | 96:b50f5f795684 | 82 | * @param baudrate The baudrate of the serial port (default = 9600). |
phsfan | 96:b50f5f795684 | 83 | */ |
phsfan | 96:b50f5f795684 | 84 | void baud(int baudrate = 921600); |
phsfan | 96:b50f5f795684 | 85 | |
phsfan | 96:b50f5f795684 | 86 | /** Set the transmission format used by the Serial port |
phsfan | 96:b50f5f795684 | 87 | * |
phsfan | 96:b50f5f795684 | 88 | * @param bits The number of bits in a word (default = 8) |
phsfan | 96:b50f5f795684 | 89 | * @param parity The parity used (USBHostSerialPort::None, USBHostSerialPort::Odd, USBHostSerialPort::Even, USBHostSerialPort::Mark, USBHostSerialPort::Space; default = USBHostSerialPort::None) |
phsfan | 96:b50f5f795684 | 90 | * @param stop The number of stop bits (1 or 2; default = 1) |
phsfan | 96:b50f5f795684 | 91 | */ |
phsfan | 96:b50f5f795684 | 92 | void format(int bits = 8, Parity parity = USBHostPhsPort::None, int stop_bits = 1); |
phsfan | 96:b50f5f795684 | 93 | |
phsfan | 96:b50f5f795684 | 94 | virtual int getc(); |
phsfan | 96:b50f5f795684 | 95 | virtual int putc(int c); |
phsfan | 96:b50f5f795684 | 96 | virtual int readPacket(); |
phsfan | 96:b50f5f795684 | 97 | virtual int writePacket(); |
phsfan | 96:b50f5f795684 | 98 | virtual int readable(); |
phsfan | 96:b50f5f795684 | 99 | virtual int writeable(); |
phsfan | 96:b50f5f795684 | 100 | virtual void attach(IUSBHostSerialListener* pListener); |
phsfan | 96:b50f5f795684 | 101 | virtual void setupIrq(bool en, IUSBHostSerial::IrqType irq = IUSBHostSerial::RxIrq); |
phsfan | 96:b50f5f795684 | 102 | |
phsfan | 96:b50f5f795684 | 103 | protected: |
phsfan | 96:b50f5f795684 | 104 | void reset(); |
phsfan | 96:b50f5f795684 | 105 | |
phsfan | 96:b50f5f795684 | 106 | private: |
phsfan | 96:b50f5f795684 | 107 | USBHost * host; |
phsfan | 96:b50f5f795684 | 108 | USBDeviceConnected * dev; |
phsfan | 96:b50f5f795684 | 109 | |
phsfan | 96:b50f5f795684 | 110 | USBEndpoint * bulk_in; |
phsfan | 96:b50f5f795684 | 111 | USBEndpoint * bulk_out; |
phsfan | 96:b50f5f795684 | 112 | uint32_t size_bulk_in; |
phsfan | 96:b50f5f795684 | 113 | uint32_t size_bulk_out; |
phsfan | 96:b50f5f795684 | 114 | |
phsfan | 96:b50f5f795684 | 115 | void init(); |
phsfan | 96:b50f5f795684 | 116 | |
phsfan | 96:b50f5f795684 | 117 | uint8_t buf[64]; |
phsfan | 96:b50f5f795684 | 118 | |
phsfan | 96:b50f5f795684 | 119 | typedef struct { |
phsfan | 96:b50f5f795684 | 120 | uint32_t baudrate; |
phsfan | 96:b50f5f795684 | 121 | uint8_t stop_bits; |
phsfan | 96:b50f5f795684 | 122 | uint8_t parity; |
phsfan | 96:b50f5f795684 | 123 | uint8_t data_bits; |
phsfan | 96:b50f5f795684 | 124 | } PACKED LINE_CODING; |
phsfan | 96:b50f5f795684 | 125 | |
phsfan | 96:b50f5f795684 | 126 | LINE_CODING line_coding; |
phsfan | 96:b50f5f795684 | 127 | |
phsfan | 96:b50f5f795684 | 128 | void rxHandler(); |
phsfan | 96:b50f5f795684 | 129 | void txHandler(); |
phsfan | 96:b50f5f795684 | 130 | |
phsfan | 96:b50f5f795684 | 131 | uint8_t serial_intf; |
phsfan | 96:b50f5f795684 | 132 | |
phsfan | 96:b50f5f795684 | 133 | |
phsfan | 96:b50f5f795684 | 134 | uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE]; |
phsfan | 96:b50f5f795684 | 135 | volatile uint32_t buf_out_len; |
phsfan | 96:b50f5f795684 | 136 | uint32_t max_out_size; |
phsfan | 96:b50f5f795684 | 137 | volatile bool lock_tx; |
phsfan | 96:b50f5f795684 | 138 | volatile bool cb_tx_en; |
phsfan | 96:b50f5f795684 | 139 | volatile bool cb_tx_pending; |
phsfan | 96:b50f5f795684 | 140 | Mutex tx_mtx; |
phsfan | 96:b50f5f795684 | 141 | |
phsfan | 96:b50f5f795684 | 142 | uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE]; |
phsfan | 96:b50f5f795684 | 143 | volatile uint32_t buf_in_len; |
phsfan | 96:b50f5f795684 | 144 | volatile uint32_t buf_in_read_pos; |
phsfan | 96:b50f5f795684 | 145 | volatile bool lock_rx; |
phsfan | 96:b50f5f795684 | 146 | volatile bool cb_rx_en; |
phsfan | 96:b50f5f795684 | 147 | volatile bool cb_rx_pending; |
phsfan | 96:b50f5f795684 | 148 | Mutex rx_mtx; |
phsfan | 96:b50f5f795684 | 149 | |
phsfan | 96:b50f5f795684 | 150 | IUSBHostSerialListener* listener; |
phsfan | 96:b50f5f795684 | 151 | |
phsfan | 96:b50f5f795684 | 152 | }; |
phsfan | 96:b50f5f795684 | 153 | |
phsfan | 96:b50f5f795684 | 154 | |
phsfan | 96:b50f5f795684 | 155 | class USBHostPhs : public IUSBEnumerator, public USBHostPhsPort |
phsfan | 96:b50f5f795684 | 156 | { |
phsfan | 96:b50f5f795684 | 157 | public: |
phsfan | 96:b50f5f795684 | 158 | USBHostPhs(); |
phsfan | 96:b50f5f795684 | 159 | |
phsfan | 96:b50f5f795684 | 160 | /** |
phsfan | 96:b50f5f795684 | 161 | * Try to connect a serial device |
phsfan | 96:b50f5f795684 | 162 | * |
phsfan | 96:b50f5f795684 | 163 | * @return true if connection was successful |
phsfan | 96:b50f5f795684 | 164 | */ |
phsfan | 96:b50f5f795684 | 165 | bool connect(); |
phsfan | 96:b50f5f795684 | 166 | |
phsfan | 96:b50f5f795684 | 167 | void disconnect(); |
phsfan | 96:b50f5f795684 | 168 | |
phsfan | 96:b50f5f795684 | 169 | /** |
phsfan | 96:b50f5f795684 | 170 | * Check if a any serial port is connected |
phsfan | 96:b50f5f795684 | 171 | * |
phsfan | 96:b50f5f795684 | 172 | * @returns true if a serial device is connected |
phsfan | 96:b50f5f795684 | 173 | */ |
phsfan | 96:b50f5f795684 | 174 | bool connected(); |
phsfan | 96:b50f5f795684 | 175 | |
phsfan | 96:b50f5f795684 | 176 | protected: |
phsfan | 96:b50f5f795684 | 177 | USBHost* host; |
phsfan | 96:b50f5f795684 | 178 | USBDeviceConnected* dev; |
phsfan | 96:b50f5f795684 | 179 | uint8_t port_intf; |
phsfan | 96:b50f5f795684 | 180 | int ports_found; |
phsfan | 96:b50f5f795684 | 181 | |
phsfan | 96:b50f5f795684 | 182 | //From IUSBEnumerator |
phsfan | 96:b50f5f795684 | 183 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
phsfan | 96:b50f5f795684 | 184 | 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 |
phsfan | 96:b50f5f795684 | 185 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
phsfan | 96:b50f5f795684 | 186 | |
phsfan | 96:b50f5f795684 | 187 | private: |
phsfan | 96:b50f5f795684 | 188 | bool dev_connected; |
phsfan | 96:b50f5f795684 | 189 | }; |
phsfan | 96:b50f5f795684 | 190 | |
phsfan | 96:b50f5f795684 | 191 | #endif |