BTstack for Nucleo F401RE/FRDM-KL46Z example program

Dependencies:   F401RE-USBHost mbed

The usage is the same as KL46Z-BTstack_example.
使い方はKL46Z-BTstack_exampleと同じです。
/media/uploads/va009039/f401re-btstack.jpg

Committer:
va009039
Date:
Mon Jun 09 09:03:25 2014 +0000
Revision:
0:a05a07cd6fdf
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:a05a07cd6fdf 1 #include "USBHostConf.h"
va009039 0:a05a07cd6fdf 2 #include "USBHost.h"
va009039 0:a05a07cd6fdf 3 #pragma once
va009039 0:a05a07cd6fdf 4
va009039 0:a05a07cd6fdf 5 #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
va009039 0:a05a07cd6fdf 6
va009039 0:a05a07cd6fdf 7 /**
va009039 0:a05a07cd6fdf 8 * A class to communicate a BTstack
va009039 0:a05a07cd6fdf 9 */
va009039 0:a05a07cd6fdf 10 class USBHostBTstack : public IUSBEnumerator {
va009039 0:a05a07cd6fdf 11 public:
va009039 0:a05a07cd6fdf 12 /**
va009039 0:a05a07cd6fdf 13 * Constructor
va009039 0:a05a07cd6fdf 14 *
va009039 0:a05a07cd6fdf 15 */
va009039 0:a05a07cd6fdf 16 USBHostBTstack();
va009039 0:a05a07cd6fdf 17
va009039 0:a05a07cd6fdf 18 /**
va009039 0:a05a07cd6fdf 19 * Check if a BTstack device is connected
va009039 0:a05a07cd6fdf 20 *
va009039 0:a05a07cd6fdf 21 * @return true if a BTstack device is connected
va009039 0:a05a07cd6fdf 22 */
va009039 0:a05a07cd6fdf 23 bool connected();
va009039 0:a05a07cd6fdf 24
va009039 0:a05a07cd6fdf 25 /**
va009039 0:a05a07cd6fdf 26 * Try to connect to a BTstack device
va009039 0:a05a07cd6fdf 27 *
va009039 0:a05a07cd6fdf 28 * @return true if connection was successful
va009039 0:a05a07cd6fdf 29 */
va009039 0:a05a07cd6fdf 30 bool connect();
va009039 0:a05a07cd6fdf 31
va009039 0:a05a07cd6fdf 32 int open();
va009039 0:a05a07cd6fdf 33 int send_packet(uint8_t packet_type, uint8_t* packet, int size);
va009039 0:a05a07cd6fdf 34 void register_packet_handler( void (*pMethod)(uint8_t, uint8_t*, uint16_t));
va009039 0:a05a07cd6fdf 35 void poll();
va009039 0:a05a07cd6fdf 36
va009039 0:a05a07cd6fdf 37 protected:
va009039 0:a05a07cd6fdf 38 //From IUSBEnumerator
va009039 0:a05a07cd6fdf 39 virtual void setVidPid(uint16_t vid, uint16_t pid);
va009039 0:a05a07cd6fdf 40 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 0:a05a07cd6fdf 41 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
va009039 0:a05a07cd6fdf 42
va009039 0:a05a07cd6fdf 43 private:
va009039 0:a05a07cd6fdf 44 USBHost * host;
va009039 0:a05a07cd6fdf 45 USBDeviceConnected * dev;
va009039 0:a05a07cd6fdf 46 bool dev_connected;
va009039 0:a05a07cd6fdf 47 uint8_t int_report[64];
va009039 0:a05a07cd6fdf 48 uint8_t bulk_report[64];
va009039 0:a05a07cd6fdf 49 USBEndpoint * int_in;
va009039 0:a05a07cd6fdf 50 USBEndpoint * bulk_in;
va009039 0:a05a07cd6fdf 51 USBEndpoint * bulk_out;
va009039 0:a05a07cd6fdf 52 bool ep_int_in;
va009039 0:a05a07cd6fdf 53 bool ep_bulk_in;
va009039 0:a05a07cd6fdf 54 bool ep_bulk_out;
va009039 0:a05a07cd6fdf 55
va009039 0:a05a07cd6fdf 56 bool btstack_device_found;
va009039 0:a05a07cd6fdf 57 int btstack_intf;
va009039 0:a05a07cd6fdf 58 void (*m_pCb)(uint8_t, uint8_t*, uint16_t);
va009039 0:a05a07cd6fdf 59 void init();
va009039 0:a05a07cd6fdf 60 };
va009039 0:a05a07cd6fdf 61
va009039 0:a05a07cd6fdf 62 void _debug_bytes(const char* pretty, int line, const char* s, uint8_t* buf, int len);