うおーるぼっとをWiiリモコンでコントロールする新しいプログラムです。 以前のものより、Wiiリモコンが早く繋がる様になりました。 It is a program which controls A with the Wii remote. ※ A Bluetooth dongle and a Wii remote control are needed.

Dependencies:   USBHost mbed FATFileSystem mbed-rtos

Committer:
jksoft
Date:
Mon Jun 10 16:01:50 2013 +0000
Revision:
0:fccb789424fc
1.0

Who changed what in which revision?

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