BLE demo for mbed Ported RunningElectronics's SBDBT firmware for BLE. It can communicate with iOS
Dependencies: FatFileSystem mbed
Fork of BTstack by
hci_transport_usb.cpp
00001 /* 00002 * Copyright (C) 2009-2012 by Matthias Ringwald 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the copyright holders nor the names of 00014 * contributors may be used to endorse or promote products derived 00015 * from this software without specific prior written permission. 00016 * 4. Any redistribution, use, or modification is done solely for 00017 * personal benefit and not for any commercial purpose or for 00018 * monetary gain. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS 00021 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 00024 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00026 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00027 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00028 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00030 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 * 00033 * Please inquire about commercial licensing options at btstack@ringwald.ch 00034 * 00035 */ 00036 00037 /* 00038 * hci_transport_usb.cpp 00039 * 00040 * HCI Transport API implementation for USB 00041 * 00042 * Created by Matthias Ringwald on 7/5/09. 00043 */ 00044 00045 // delock bt class 2 - csr 00046 // 0a12:0001 (bus 27, device 2) 00047 00048 // Interface Number - Alternate Setting - suggested Endpoint Address - Endpoint Type - Suggested Max Packet Size 00049 // HCI Commands 0 0 0x00 Control 8/16/32/64 00050 // HCI Events 0 0 0x81 Interrupt (IN) 16 00051 // ACL Data 0 0 0x82 Bulk (IN) 32/64 00052 // ACL Data 0 0 0x02 Bulk (OUT) 32/64 00053 00054 #include <stdio.h> 00055 #include <string.h> 00056 #include "config.h" 00057 #include "debug.h" 00058 #include "hci.h" 00059 #include "hci_transport.h" 00060 #include "hci_dump.h" 00061 #include "usbbt.h" 00062 // prototypes 00063 static int usb_close(void *transport_config); 00064 00065 enum { 00066 LIB_USB_CLOSED = 0, 00067 LIB_USB_OPENED, 00068 LIB_USB_DEVICE_OPENDED, 00069 LIB_USB_KERNEL_DETACHED, 00070 LIB_USB_INTERFACE_CLAIMED, 00071 LIB_USB_TRANSFERS_ALLOCATED 00072 } libusb_state = LIB_USB_CLOSED; 00073 00074 // single instance 00075 static hci_transport_t * hci_transport_usb = NULL; 00076 static usbbt* bt = NULL; 00077 static int usb_process_ds(struct data_source *ds) { 00078 if (bt) { 00079 bt->poll(); 00080 } 00081 return 0; 00082 } 00083 00084 static int usb_open(void *transport_config){ 00085 log_info("usb_open\n"); 00086 data_source_t *ds = (data_source_t*)malloc(sizeof(data_source_t)); 00087 ds->process = usb_process_ds; 00088 run_loop_add_data_source(ds); 00089 return 0; 00090 } 00091 static int usb_close(void *transport_config){ 00092 00093 return 0; 00094 } 00095 00096 static int usb_send_packet(uint8_t packet_type, uint8_t * packet, int size){ 00097 //log_info("usb_send_packet\n"); 00098 if (bt) { 00099 bt->send_packet(packet_type, packet, size); 00100 } 00101 return 0; 00102 } 00103 00104 static void usb_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){ 00105 log_info("registering packet handler\n"); 00106 if (bt) { 00107 bt->setOnPacket(handler); 00108 } 00109 } 00110 00111 static const char * usb_get_transport_name(void){ 00112 return "USB"; 00113 } 00114 00115 // get usb singleton 00116 hci_transport_t * hci_transport_usb_instance() { 00117 if (!bt) { 00118 bt = new usbbt; 00119 bt->setup(); 00120 } 00121 if (!hci_transport_usb) { 00122 hci_transport_usb = (hci_transport_t*)malloc( sizeof(hci_transport_t)); 00123 hci_transport_usb->open = usb_open; 00124 hci_transport_usb->close = usb_close; 00125 hci_transport_usb->send_packet = usb_send_packet; 00126 hci_transport_usb->register_packet_handler = usb_register_packet_handler; 00127 hci_transport_usb->get_transport_name = usb_get_transport_name; 00128 hci_transport_usb->set_baudrate = NULL; 00129 hci_transport_usb->can_send_packet_now = NULL; 00130 } 00131 return hci_transport_usb; 00132 }
Generated on Thu Jul 14 2022 15:03:48 by 1.7.2