USB BARCODE READER

Fork of USBHOST by ST

Committer:
shivanandgowdakr
Date:
Mon Jul 02 12:10:45 2018 +0000
Revision:
7:ccd0ac9ae1c9
Parent:
1:ab240722d7ef
USB BARCODE READER ;

Who changed what in which revision?

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