Pierre Provent / USBHost

Dependents:   TEST_USB_Nucleo_F429ZI Essais_USB_Nucleo_F429ZI SID_V3_Nucleo_F429ZI SID_V4_Nucleo_F429ZI_copy

Committer:
pierreprovent
Date:
Fri Sep 25 10:17:49 2020 +0000
Revision:
0:77ca32e8e04e
Programme acquisition en enregistrement sur clef USB carte Nucleo F429ZI cours ELE118 Cnam

Who changed what in which revision?

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