mbed base bard check program for BlueTooth USB dongle module (3 switches, 6 leds, I2C LCD, A/D)
Fork of BTstack by
USBHostBTstack/USBHostBTstack.h@3:7b7d1273e2d5, 2016-10-17 (annotated)
- Committer:
- tamaki
- Date:
- Mon Oct 17 00:25:18 2016 +0000
- Revision:
- 3:7b7d1273e2d5
- Parent:
- 2:871b41f4789e
mbed base bard check program
; for BlueTooth USB dongle module
; (3 switches, 6 leds, I2C LCD, A/D)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 1:b657594559be | 1 | #include "USBHostConf.h" |
va009039 | 1:b657594559be | 2 | #include "USBHost.h" |
va009039 | 1:b657594559be | 3 | #pragma once |
va009039 | 1:b657594559be | 4 | |
va009039 | 1:b657594559be | 5 | #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; |
va009039 | 1:b657594559be | 6 | |
va009039 | 2:871b41f4789e | 7 | struct Packet { |
va009039 | 2:871b41f4789e | 8 | uint8_t type; |
va009039 | 2:871b41f4789e | 9 | uint8_t* buf; |
va009039 | 2:871b41f4789e | 10 | uint16_t len; |
va009039 | 2:871b41f4789e | 11 | }; |
va009039 | 2:871b41f4789e | 12 | |
va009039 | 1:b657594559be | 13 | /** |
va009039 | 1:b657594559be | 14 | * A class to communicate a BTstack |
va009039 | 1:b657594559be | 15 | */ |
va009039 | 1:b657594559be | 16 | class USBHostBTstack : public IUSBEnumerator { |
va009039 | 1:b657594559be | 17 | public: |
va009039 | 1:b657594559be | 18 | /** |
va009039 | 1:b657594559be | 19 | * Constructor |
va009039 | 1:b657594559be | 20 | * |
va009039 | 1:b657594559be | 21 | */ |
va009039 | 1:b657594559be | 22 | USBHostBTstack(); |
va009039 | 1:b657594559be | 23 | |
va009039 | 1:b657594559be | 24 | /** |
va009039 | 1:b657594559be | 25 | * Check if a BTstack device is connected |
va009039 | 1:b657594559be | 26 | * |
va009039 | 2:871b41f4789e | 27 | * @return true if a BTstack device is connected |
va009039 | 1:b657594559be | 28 | */ |
va009039 | 1:b657594559be | 29 | bool connected(); |
va009039 | 1:b657594559be | 30 | |
va009039 | 1:b657594559be | 31 | /** |
va009039 | 1:b657594559be | 32 | * Try to connect to a BTstack device |
va009039 | 1:b657594559be | 33 | * |
va009039 | 1:b657594559be | 34 | * @return true if connection was successful |
va009039 | 1:b657594559be | 35 | */ |
va009039 | 1:b657594559be | 36 | bool connect(); |
va009039 | 1:b657594559be | 37 | |
va009039 | 1:b657594559be | 38 | int open(); |
va009039 | 1:b657594559be | 39 | int send_packet(uint8_t packet_type, uint8_t* packet, int size); |
va009039 | 1:b657594559be | 40 | void register_packet_handler( void (*pMethod)(uint8_t, uint8_t*, uint16_t)); |
va009039 | 2:871b41f4789e | 41 | void poll(); |
va009039 | 2:871b41f4789e | 42 | |
va009039 | 1:b657594559be | 43 | protected: |
va009039 | 1:b657594559be | 44 | //From IUSBEnumerator |
va009039 | 1:b657594559be | 45 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
va009039 | 1:b657594559be | 46 | 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 | 1:b657594559be | 47 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
va009039 | 1:b657594559be | 48 | |
va009039 | 1:b657594559be | 49 | private: |
va009039 | 1:b657594559be | 50 | USBHost * host; |
va009039 | 1:b657594559be | 51 | USBDeviceConnected * dev; |
va009039 | 1:b657594559be | 52 | bool dev_connected; |
va009039 | 1:b657594559be | 53 | uint8_t int_report[64]; |
va009039 | 1:b657594559be | 54 | uint8_t bulk_report[64]; |
va009039 | 1:b657594559be | 55 | USBEndpoint * int_in; |
va009039 | 1:b657594559be | 56 | USBEndpoint * bulk_in; |
va009039 | 1:b657594559be | 57 | USBEndpoint * bulk_out; |
va009039 | 1:b657594559be | 58 | bool ep_int_in; |
va009039 | 1:b657594559be | 59 | bool ep_bulk_in; |
va009039 | 1:b657594559be | 60 | bool ep_bulk_out; |
va009039 | 1:b657594559be | 61 | |
va009039 | 1:b657594559be | 62 | bool btstack_device_found; |
va009039 | 1:b657594559be | 63 | int btstack_intf; |
va009039 | 1:b657594559be | 64 | void (*m_pCb)(uint8_t, uint8_t*, uint16_t); |
va009039 | 2:871b41f4789e | 65 | Mail<Packet, 2> mail_box; |
va009039 | 1:b657594559be | 66 | void int_rxHandler(); |
va009039 | 1:b657594559be | 67 | void bulk_rxHandler(); |
va009039 | 1:b657594559be | 68 | void init(); |
va009039 | 1:b657594559be | 69 | }; |
va009039 | 2:871b41f4789e | 70 | |
va009039 | 2:871b41f4789e | 71 | void _debug_bytes(const char* pretty, int line, const char* s, uint8_t* buf, int len); |