USB Host Driver with Socket Modem support. Works with revision 323 of mbed-src but broken with any later version.
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
USBHostGPS/USBHostGPS.h@13:8774c07f12a5, 2014-06-10 (annotated)
- Committer:
- va009039
- Date:
- Tue Jun 10 13:38:41 2014 +0900
- Revision:
- 13:8774c07f12a5
add USBHostC270
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 |
13:8774c07f12a5 | 1 | // Simple USBHost GPS Dongle for FRDM-KL46Z |
va009039 |
13:8774c07f12a5 | 2 | #include "USBHost.h" |
va009039 |
13:8774c07f12a5 | 3 | #include "decodeNMEA.h" |
va009039 |
13:8774c07f12a5 | 4 | |
va009039 |
13:8774c07f12a5 | 5 | #define PL2303_SET_LINE_CODING 0x20 |
va009039 |
13:8774c07f12a5 | 6 | |
va009039 |
13:8774c07f12a5 | 7 | class USBHostGPS : public IUSBEnumerator { |
va009039 |
13:8774c07f12a5 | 8 | public: |
va009039 |
13:8774c07f12a5 | 9 | |
va009039 |
13:8774c07f12a5 | 10 | /** |
va009039 |
13:8774c07f12a5 | 11 | * Constructor |
va009039 |
13:8774c07f12a5 | 12 | */ |
va009039 |
13:8774c07f12a5 | 13 | USBHostGPS(int baud = 38400); |
va009039 |
13:8774c07f12a5 | 14 | |
va009039 |
13:8774c07f12a5 | 15 | /** |
va009039 |
13:8774c07f12a5 | 16 | * Try to connect a USB GPS device |
va009039 |
13:8774c07f12a5 | 17 | * |
va009039 |
13:8774c07f12a5 | 18 | * @return true if connection was successful |
va009039 |
13:8774c07f12a5 | 19 | */ |
va009039 |
13:8774c07f12a5 | 20 | bool connect(); |
va009039 |
13:8774c07f12a5 | 21 | |
va009039 |
13:8774c07f12a5 | 22 | /** |
va009039 |
13:8774c07f12a5 | 23 | * Check if a USB GPS is connected |
va009039 |
13:8774c07f12a5 | 24 | * |
va009039 |
13:8774c07f12a5 | 25 | * @returns true if a mouse is connected |
va009039 |
13:8774c07f12a5 | 26 | */ |
va009039 |
13:8774c07f12a5 | 27 | bool connected(); |
va009039 |
13:8774c07f12a5 | 28 | |
va009039 |
13:8774c07f12a5 | 29 | int readNMEA(char* data, int size, int timeout_ms) { |
va009039 |
13:8774c07f12a5 | 30 | host->bulkRead(dev, bulk_in, (uint8_t*)data, size); |
va009039 |
13:8774c07f12a5 | 31 | return bulk_in->getLengthTransferred(); |
va009039 |
13:8774c07f12a5 | 32 | } |
va009039 |
13:8774c07f12a5 | 33 | void attachEventRaw(void (*ptr)(char* data, int size)) { |
va009039 |
13:8774c07f12a5 | 34 | if (ptr != NULL) { |
va009039 |
13:8774c07f12a5 | 35 | onUpdateRaw = ptr; |
va009039 |
13:8774c07f12a5 | 36 | } |
va009039 |
13:8774c07f12a5 | 37 | } |
va009039 |
13:8774c07f12a5 | 38 | |
va009039 |
13:8774c07f12a5 | 39 | decodeNMEA nmea; |
va009039 |
13:8774c07f12a5 | 40 | |
va009039 |
13:8774c07f12a5 | 41 | protected: |
va009039 |
13:8774c07f12a5 | 42 | //From IUSBEnumerator |
va009039 |
13:8774c07f12a5 | 43 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
va009039 |
13:8774c07f12a5 | 44 | 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 |
va009039 |
13:8774c07f12a5 | 45 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
va009039 |
13:8774c07f12a5 | 46 | |
va009039 |
13:8774c07f12a5 | 47 | private: |
va009039 |
13:8774c07f12a5 | 48 | USBHost * host; |
va009039 |
13:8774c07f12a5 | 49 | USBDeviceConnected* dev; |
va009039 |
13:8774c07f12a5 | 50 | USBEndpoint* bulk_in; |
va009039 |
13:8774c07f12a5 | 51 | bool dev_connected; |
va009039 |
13:8774c07f12a5 | 52 | bool gps_device_found; |
va009039 |
13:8774c07f12a5 | 53 | int gps_intf; |
va009039 |
13:8774c07f12a5 | 54 | |
va009039 |
13:8774c07f12a5 | 55 | void rxHandler(); |
va009039 |
13:8774c07f12a5 | 56 | void (*onUpdateRaw)(char* data, int size); |
va009039 |
13:8774c07f12a5 | 57 | uint8_t bulk_buf[64]; |
va009039 |
13:8774c07f12a5 | 58 | int baud; |
va009039 |
13:8774c07f12a5 | 59 | void init(); |
va009039 |
13:8774c07f12a5 | 60 | }; |