mbed base bard check program for BlueTooth USB dongle module (3 switches, 6 leds, I2C LCD, A/D)

Dependencies:   USBHost mbed

Fork of BTstack by Norimasa Okamoto

Committer:
va009039
Date:
Thu Mar 21 13:53:05 2013 +0000
Revision:
1:b657594559be
Parent:
0:1ed23ab1345f
Child:
2:871b41f4789e
replaced USBHost

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:1ed23ab1345f 1 /*
va009039 0:1ed23ab1345f 2 * Copyright (C) 2009-2012 by Matthias Ringwald
va009039 0:1ed23ab1345f 3 *
va009039 0:1ed23ab1345f 4 * Redistribution and use in source and binary forms, with or without
va009039 0:1ed23ab1345f 5 * modification, are permitted provided that the following conditions
va009039 0:1ed23ab1345f 6 * are met:
va009039 0:1ed23ab1345f 7 *
va009039 0:1ed23ab1345f 8 * 1. Redistributions of source code must retain the above copyright
va009039 0:1ed23ab1345f 9 * notice, this list of conditions and the following disclaimer.
va009039 0:1ed23ab1345f 10 * 2. Redistributions in binary form must reproduce the above copyright
va009039 0:1ed23ab1345f 11 * notice, this list of conditions and the following disclaimer in the
va009039 0:1ed23ab1345f 12 * documentation and/or other materials provided with the distribution.
va009039 0:1ed23ab1345f 13 * 3. Neither the name of the copyright holders nor the names of
va009039 0:1ed23ab1345f 14 * contributors may be used to endorse or promote products derived
va009039 0:1ed23ab1345f 15 * from this software without specific prior written permission.
va009039 0:1ed23ab1345f 16 * 4. Any redistribution, use, or modification is done solely for
va009039 0:1ed23ab1345f 17 * personal benefit and not for any commercial purpose or for
va009039 0:1ed23ab1345f 18 * monetary gain.
va009039 0:1ed23ab1345f 19 *
va009039 0:1ed23ab1345f 20 * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
va009039 0:1ed23ab1345f 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
va009039 0:1ed23ab1345f 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
va009039 0:1ed23ab1345f 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
va009039 0:1ed23ab1345f 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
va009039 0:1ed23ab1345f 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
va009039 0:1ed23ab1345f 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
va009039 0:1ed23ab1345f 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
va009039 0:1ed23ab1345f 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
va009039 0:1ed23ab1345f 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
va009039 0:1ed23ab1345f 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
va009039 0:1ed23ab1345f 31 * SUCH DAMAGE.
va009039 0:1ed23ab1345f 32 *
va009039 0:1ed23ab1345f 33 * Please inquire about commercial licensing options at btstack@ringwald.ch
va009039 0:1ed23ab1345f 34 *
va009039 0:1ed23ab1345f 35 */
va009039 0:1ed23ab1345f 36
va009039 0:1ed23ab1345f 37 /*
va009039 0:1ed23ab1345f 38 * hci_transport_usb.cpp
va009039 0:1ed23ab1345f 39 *
va009039 0:1ed23ab1345f 40 * HCI Transport API implementation for USB
va009039 0:1ed23ab1345f 41 *
va009039 0:1ed23ab1345f 42 * Created by Matthias Ringwald on 7/5/09.
va009039 0:1ed23ab1345f 43 */
va009039 0:1ed23ab1345f 44
va009039 0:1ed23ab1345f 45 // delock bt class 2 - csr
va009039 0:1ed23ab1345f 46 // 0a12:0001 (bus 27, device 2)
va009039 0:1ed23ab1345f 47
va009039 0:1ed23ab1345f 48 // Interface Number - Alternate Setting - suggested Endpoint Address - Endpoint Type - Suggested Max Packet Size
va009039 0:1ed23ab1345f 49 // HCI Commands 0 0 0x00 Control 8/16/32/64
va009039 0:1ed23ab1345f 50 // HCI Events 0 0 0x81 Interrupt (IN) 16
va009039 0:1ed23ab1345f 51 // ACL Data 0 0 0x82 Bulk (IN) 32/64
va009039 0:1ed23ab1345f 52 // ACL Data 0 0 0x02 Bulk (OUT) 32/64
va009039 0:1ed23ab1345f 53
va009039 0:1ed23ab1345f 54 #include <stdio.h>
va009039 0:1ed23ab1345f 55 #include <string.h>
va009039 0:1ed23ab1345f 56 #include "config.h"
va009039 0:1ed23ab1345f 57 #include "debug.h"
va009039 0:1ed23ab1345f 58 #include "hci.h"
va009039 0:1ed23ab1345f 59 #include "hci_transport.h"
va009039 0:1ed23ab1345f 60 #include "hci_dump.h"
va009039 1:b657594559be 61 #include "USBHostBTstack.h"
va009039 1:b657594559be 62
va009039 0:1ed23ab1345f 63 enum {
va009039 0:1ed23ab1345f 64 LIB_USB_CLOSED = 0,
va009039 0:1ed23ab1345f 65 LIB_USB_OPENED,
va009039 0:1ed23ab1345f 66 LIB_USB_DEVICE_OPENDED,
va009039 0:1ed23ab1345f 67 LIB_USB_KERNEL_DETACHED,
va009039 0:1ed23ab1345f 68 LIB_USB_INTERFACE_CLAIMED,
va009039 0:1ed23ab1345f 69 LIB_USB_TRANSFERS_ALLOCATED
va009039 0:1ed23ab1345f 70 } libusb_state = LIB_USB_CLOSED;
va009039 0:1ed23ab1345f 71
va009039 0:1ed23ab1345f 72 // single instance
va009039 0:1ed23ab1345f 73 static hci_transport_t * hci_transport_usb = NULL;
va009039 1:b657594559be 74 static USBHostBTstack* bt = NULL;
va009039 0:1ed23ab1345f 75
va009039 0:1ed23ab1345f 76 static int usb_open(void *transport_config){
va009039 0:1ed23ab1345f 77 log_info("usb_open\n");
va009039 1:b657594559be 78 if (bt) {
va009039 1:b657594559be 79 return bt->open();
va009039 1:b657594559be 80 }
va009039 0:1ed23ab1345f 81 return 0;
va009039 0:1ed23ab1345f 82 }
va009039 0:1ed23ab1345f 83 static int usb_close(void *transport_config){
va009039 0:1ed23ab1345f 84
va009039 0:1ed23ab1345f 85 return 0;
va009039 0:1ed23ab1345f 86 }
va009039 0:1ed23ab1345f 87
va009039 0:1ed23ab1345f 88 static int usb_send_packet(uint8_t packet_type, uint8_t * packet, int size){
va009039 0:1ed23ab1345f 89 //log_info("usb_send_packet\n");
va009039 0:1ed23ab1345f 90 if (bt) {
va009039 0:1ed23ab1345f 91 bt->send_packet(packet_type, packet, size);
va009039 0:1ed23ab1345f 92 }
va009039 0:1ed23ab1345f 93 return 0;
va009039 0:1ed23ab1345f 94 }
va009039 0:1ed23ab1345f 95
va009039 0:1ed23ab1345f 96 static void usb_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
va009039 0:1ed23ab1345f 97 log_info("registering packet handler\n");
va009039 0:1ed23ab1345f 98 if (bt) {
va009039 1:b657594559be 99 bt->register_packet_handler(handler);
va009039 0:1ed23ab1345f 100 }
va009039 0:1ed23ab1345f 101 }
va009039 0:1ed23ab1345f 102
va009039 0:1ed23ab1345f 103 static const char * usb_get_transport_name(void){
va009039 0:1ed23ab1345f 104 return "USB";
va009039 0:1ed23ab1345f 105 }
va009039 0:1ed23ab1345f 106
va009039 0:1ed23ab1345f 107 // get usb singleton
va009039 0:1ed23ab1345f 108 hci_transport_t * hci_transport_usb_instance() {
va009039 0:1ed23ab1345f 109 if (!bt) {
va009039 1:b657594559be 110 bt = new USBHostBTstack;
va009039 0:1ed23ab1345f 111 }
va009039 0:1ed23ab1345f 112 if (!hci_transport_usb) {
va009039 0:1ed23ab1345f 113 hci_transport_usb = (hci_transport_t*)malloc( sizeof(hci_transport_t));
va009039 0:1ed23ab1345f 114 hci_transport_usb->open = usb_open;
va009039 0:1ed23ab1345f 115 hci_transport_usb->close = usb_close;
va009039 0:1ed23ab1345f 116 hci_transport_usb->send_packet = usb_send_packet;
va009039 0:1ed23ab1345f 117 hci_transport_usb->register_packet_handler = usb_register_packet_handler;
va009039 0:1ed23ab1345f 118 hci_transport_usb->get_transport_name = usb_get_transport_name;
va009039 0:1ed23ab1345f 119 hci_transport_usb->set_baudrate = NULL;
va009039 0:1ed23ab1345f 120 hci_transport_usb->can_send_packet_now = NULL;
va009039 0:1ed23ab1345f 121 }
va009039 0:1ed23ab1345f 122 return hci_transport_usb;
va009039 0:1ed23ab1345f 123 }