うおーるぼっとを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 /* mbed USBHost Library
jksoft 0:fccb789424fc 2 * Copyright (c) 2006-2013 ARM Limited
jksoft 0:fccb789424fc 3 *
jksoft 0:fccb789424fc 4 * Licensed under the Apache License, Version 2.0 (the "License");
jksoft 0:fccb789424fc 5 * you may not use this file except in compliance with the License.
jksoft 0:fccb789424fc 6 * You may obtain a copy of the License at
jksoft 0:fccb789424fc 7 *
jksoft 0:fccb789424fc 8 * http://www.apache.org/licenses/LICENSE-2.0
jksoft 0:fccb789424fc 9 *
jksoft 0:fccb789424fc 10 * Unless required by applicable law or agreed to in writing, software
jksoft 0:fccb789424fc 11 * distributed under the License is distributed on an "AS IS" BASIS,
jksoft 0:fccb789424fc 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jksoft 0:fccb789424fc 13 * See the License for the specific language governing permissions and
jksoft 0:fccb789424fc 14 * limitations under the License.
jksoft 0:fccb789424fc 15 */
jksoft 0:fccb789424fc 16
jksoft 0:fccb789424fc 17 #ifndef USBHOSTSERIAL_H
jksoft 0:fccb789424fc 18 #define USBHOSTSERIAL_H
jksoft 0:fccb789424fc 19
jksoft 0:fccb789424fc 20 #include "USBHostConf.h"
jksoft 0:fccb789424fc 21
jksoft 0:fccb789424fc 22 #if USBHOST_SERIAL
jksoft 0:fccb789424fc 23
jksoft 0:fccb789424fc 24 #include "USBHost.h"
jksoft 0:fccb789424fc 25 #include "Stream.h"
jksoft 0:fccb789424fc 26 #include "MtxCircBuffer.h"
jksoft 0:fccb789424fc 27
jksoft 0:fccb789424fc 28 /**
jksoft 0:fccb789424fc 29 * A class to communicate a USB virtual serial port
jksoft 0:fccb789424fc 30 */
jksoft 0:fccb789424fc 31 class USBHostSerial : public IUSBEnumerator, public Stream {
jksoft 0:fccb789424fc 32 public:
jksoft 0:fccb789424fc 33 /**
jksoft 0:fccb789424fc 34 * Constructor
jksoft 0:fccb789424fc 35 */
jksoft 0:fccb789424fc 36 USBHostSerial();
jksoft 0:fccb789424fc 37
jksoft 0:fccb789424fc 38 enum IrqType {
jksoft 0:fccb789424fc 39 RxIrq,
jksoft 0:fccb789424fc 40 TxIrq
jksoft 0:fccb789424fc 41 };
jksoft 0:fccb789424fc 42
jksoft 0:fccb789424fc 43 enum Parity {
jksoft 0:fccb789424fc 44 None = 0,
jksoft 0:fccb789424fc 45 Odd,
jksoft 0:fccb789424fc 46 Even,
jksoft 0:fccb789424fc 47 Mark,
jksoft 0:fccb789424fc 48 Space
jksoft 0:fccb789424fc 49 };
jksoft 0:fccb789424fc 50
jksoft 0:fccb789424fc 51 /**
jksoft 0:fccb789424fc 52 * Check if a virtual serial port is connected
jksoft 0:fccb789424fc 53 *
jksoft 0:fccb789424fc 54 * @returns true if a serial device is connected
jksoft 0:fccb789424fc 55 */
jksoft 0:fccb789424fc 56 bool connected();
jksoft 0:fccb789424fc 57
jksoft 0:fccb789424fc 58 /**
jksoft 0:fccb789424fc 59 * Try to connect a serial device
jksoft 0:fccb789424fc 60 *
jksoft 0:fccb789424fc 61 * @return true if connection was successful
jksoft 0:fccb789424fc 62 */
jksoft 0:fccb789424fc 63 bool connect();
jksoft 0:fccb789424fc 64
jksoft 0:fccb789424fc 65 /**
jksoft 0:fccb789424fc 66 * Check the number of bytes available.
jksoft 0:fccb789424fc 67 *
jksoft 0:fccb789424fc 68 * @returns the number of bytes available
jksoft 0:fccb789424fc 69 */
jksoft 0:fccb789424fc 70 uint8_t available();
jksoft 0:fccb789424fc 71
jksoft 0:fccb789424fc 72 /**
jksoft 0:fccb789424fc 73 * Attach a member function to call when a packet is received.
jksoft 0:fccb789424fc 74 *
jksoft 0:fccb789424fc 75 * @param tptr pointer to the object to call the member function on
jksoft 0:fccb789424fc 76 * @param mptr pointer to the member function to be called
jksoft 0:fccb789424fc 77 * @param irq irq type
jksoft 0:fccb789424fc 78 */
jksoft 0:fccb789424fc 79 template<typename T>
jksoft 0:fccb789424fc 80 inline void attach(T* tptr, void (T::*mptr)(void), IrqType irq = RxIrq) {
jksoft 0:fccb789424fc 81 if ((mptr != NULL) && (tptr != NULL)) {
jksoft 0:fccb789424fc 82 if (irq == RxIrq) {
jksoft 0:fccb789424fc 83 rx.attach(tptr, mptr);
jksoft 0:fccb789424fc 84 } else {
jksoft 0:fccb789424fc 85 tx.attach(tptr, mptr);
jksoft 0:fccb789424fc 86 }
jksoft 0:fccb789424fc 87 }
jksoft 0:fccb789424fc 88 }
jksoft 0:fccb789424fc 89
jksoft 0:fccb789424fc 90 /**
jksoft 0:fccb789424fc 91 * Attach a callback called when a packet is received
jksoft 0:fccb789424fc 92 *
jksoft 0:fccb789424fc 93 * @param ptr function pointer
jksoft 0:fccb789424fc 94 */
jksoft 0:fccb789424fc 95 inline void attach(void (*fn)(void), IrqType irq = RxIrq) {
jksoft 0:fccb789424fc 96 if (fn != NULL) {
jksoft 0:fccb789424fc 97 if (irq == RxIrq) {
jksoft 0:fccb789424fc 98 rx.attach(fn);
jksoft 0:fccb789424fc 99 } else {
jksoft 0:fccb789424fc 100 tx.attach(fn);
jksoft 0:fccb789424fc 101 }
jksoft 0:fccb789424fc 102 }
jksoft 0:fccb789424fc 103 }
jksoft 0:fccb789424fc 104
jksoft 0:fccb789424fc 105 /** Set the baud rate of the serial port
jksoft 0:fccb789424fc 106 *
jksoft 0:fccb789424fc 107 * @param baudrate The baudrate of the serial port (default = 9600).
jksoft 0:fccb789424fc 108 */
jksoft 0:fccb789424fc 109 void baud(int baudrate = 9600);
jksoft 0:fccb789424fc 110
jksoft 0:fccb789424fc 111 /** Set the transmission format used by the Serial port
jksoft 0:fccb789424fc 112 *
jksoft 0:fccb789424fc 113 * @param bits The number of bits in a word (default = 8)
jksoft 0:fccb789424fc 114 * @param parity The parity used (USBHostSerial::None, USBHostSerial::Odd, USBHostSerial::Even, USBHostSerial::Mark, USBHostSerial::Space; default = USBHostSerial::None)
jksoft 0:fccb789424fc 115 * @param stop The number of stop bits (1 or 2; default = 1)
jksoft 0:fccb789424fc 116 */
jksoft 0:fccb789424fc 117 void format(int bits = 8, Parity parity = USBHostSerial::None, int stop_bits = 1);
jksoft 0:fccb789424fc 118
jksoft 0:fccb789424fc 119
jksoft 0:fccb789424fc 120 protected:
jksoft 0:fccb789424fc 121 //From IUSBEnumerator
jksoft 0:fccb789424fc 122 virtual void setVidPid(uint16_t vid, uint16_t pid);
jksoft 0:fccb789424fc 123 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
jksoft 0:fccb789424fc 124 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
jksoft 0:fccb789424fc 125
jksoft 0:fccb789424fc 126 virtual int _getc();
jksoft 0:fccb789424fc 127 virtual int _putc(int c);
jksoft 0:fccb789424fc 128
jksoft 0:fccb789424fc 129 private:
jksoft 0:fccb789424fc 130 USBHost * host;
jksoft 0:fccb789424fc 131 USBDeviceConnected * dev;
jksoft 0:fccb789424fc 132 USBEndpoint * bulk_in;
jksoft 0:fccb789424fc 133 USBEndpoint * bulk_out;
jksoft 0:fccb789424fc 134 uint32_t size_bulk_in;
jksoft 0:fccb789424fc 135 uint32_t size_bulk_out;
jksoft 0:fccb789424fc 136
jksoft 0:fccb789424fc 137 bool dev_connected;
jksoft 0:fccb789424fc 138
jksoft 0:fccb789424fc 139 void init();
jksoft 0:fccb789424fc 140
jksoft 0:fccb789424fc 141 MtxCircBuffer<uint8_t, 64> circ_buf;
jksoft 0:fccb789424fc 142
jksoft 0:fccb789424fc 143 uint8_t buf[64];
jksoft 0:fccb789424fc 144
jksoft 0:fccb789424fc 145 typedef __packed struct {
jksoft 0:fccb789424fc 146 uint32_t baudrate;
jksoft 0:fccb789424fc 147 uint8_t stop_bits;
jksoft 0:fccb789424fc 148 uint8_t parity;
jksoft 0:fccb789424fc 149 uint8_t data_bits;
jksoft 0:fccb789424fc 150 } LINE_CODING;
jksoft 0:fccb789424fc 151
jksoft 0:fccb789424fc 152 LINE_CODING line_coding;
jksoft 0:fccb789424fc 153
jksoft 0:fccb789424fc 154 void rxHandler();
jksoft 0:fccb789424fc 155 void txHandler();
jksoft 0:fccb789424fc 156 FunctionPointer rx;
jksoft 0:fccb789424fc 157 FunctionPointer tx;
jksoft 0:fccb789424fc 158
jksoft 0:fccb789424fc 159 int serial_intf;
jksoft 0:fccb789424fc 160 bool serial_device_found;
jksoft 0:fccb789424fc 161
jksoft 0:fccb789424fc 162 };
jksoft 0:fccb789424fc 163
jksoft 0:fccb789424fc 164 #endif
jksoft 0:fccb789424fc 165
jksoft 0:fccb789424fc 166 #endif