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