BTstack for Nucleo F401RE/FRDM-KL46Z example program

Dependencies:   F401RE-USBHost mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHostBTstack.h Source File

USBHostBTstack.h

00001 #include "USBHostConf.h"
00002 #include "USBHost.h"
00003 #pragma once
00004 
00005 #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
00006 
00007 /** 
00008  * A class to communicate a BTstack
00009  */
00010 class USBHostBTstack : public IUSBEnumerator {
00011 public:
00012     /**
00013     * Constructor
00014     *
00015     */
00016     USBHostBTstack();
00017 
00018     /**
00019     * Check if a BTstack device is connected
00020     *
00021     * @return true if a BTstack device is connected
00022     */
00023     bool connected();
00024 
00025     /**
00026      * Try to connect to a BTstack device
00027      *
00028      * @return true if connection was successful
00029      */
00030     bool connect();
00031     
00032     int open();
00033     int send_packet(uint8_t packet_type, uint8_t* packet, int size);
00034     void register_packet_handler( void (*pMethod)(uint8_t, uint8_t*, uint16_t));
00035     void poll();
00036 
00037 protected:
00038     //From IUSBEnumerator
00039     virtual void setVidPid(uint16_t vid, uint16_t pid);
00040     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
00041     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
00042 
00043 private:
00044     USBHost * host;
00045     USBDeviceConnected * dev;
00046     bool dev_connected;
00047     uint8_t int_report[64];
00048     uint8_t bulk_report[64];
00049     USBEndpoint * int_in;
00050     USBEndpoint * bulk_in;
00051     USBEndpoint * bulk_out;
00052     bool ep_int_in;
00053     bool ep_bulk_in;
00054     bool ep_bulk_out;
00055 
00056     bool btstack_device_found;
00057     int btstack_intf;
00058     void (*m_pCb)(uint8_t, uint8_t*, uint16_t);
00059     void init();
00060 };
00061 
00062 void _debug_bytes(const char* pretty, int line, const char* s, uint8_t* buf, int len);