dari pinpin usb langsung

Dependencies:   mbed

Fork of Nucleo_Ex04_USBPAD by woodstock .

Committer:
beaglescout007
Date:
Tue Mar 15 11:39:04 2016 +0000
Revision:
0:b5f79b4f741d
Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
beaglescout007 0:b5f79b4f741d 1 /* mbed USBHost Library
beaglescout007 0:b5f79b4f741d 2 * Copyright (c) 2006-2013 ARM Limited
beaglescout007 0:b5f79b4f741d 3 *
beaglescout007 0:b5f79b4f741d 4 * Licensed under the Apache License, Version 2.0 (the "License");
beaglescout007 0:b5f79b4f741d 5 * you may not use this file except in compliance with the License.
beaglescout007 0:b5f79b4f741d 6 * You may obtain a copy of the License at
beaglescout007 0:b5f79b4f741d 7 *
beaglescout007 0:b5f79b4f741d 8 * http://www.apache.org/licenses/LICENSE-2.0
beaglescout007 0:b5f79b4f741d 9 *
beaglescout007 0:b5f79b4f741d 10 * Unless required by applicable law or agreed to in writing, software
beaglescout007 0:b5f79b4f741d 11 * distributed under the License is distributed on an "AS IS" BASIS,
beaglescout007 0:b5f79b4f741d 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
beaglescout007 0:b5f79b4f741d 13 * See the License for the specific language governing permissions and
beaglescout007 0:b5f79b4f741d 14 * limitations under the License.
beaglescout007 0:b5f79b4f741d 15 */
beaglescout007 0:b5f79b4f741d 16
beaglescout007 0:b5f79b4f741d 17 #ifndef USB_INC_H
beaglescout007 0:b5f79b4f741d 18 #define USB_INC_H
beaglescout007 0:b5f79b4f741d 19
beaglescout007 0:b5f79b4f741d 20 #include "mbed.h"
beaglescout007 0:b5f79b4f741d 21 #include "toolchain.h"
beaglescout007 0:b5f79b4f741d 22
beaglescout007 0:b5f79b4f741d 23 enum USB_TYPE {
beaglescout007 0:b5f79b4f741d 24 USB_TYPE_OK = 0,
beaglescout007 0:b5f79b4f741d 25
beaglescout007 0:b5f79b4f741d 26 // completion code
beaglescout007 0:b5f79b4f741d 27 USB_TYPE_CRC_ERROR = 1,
beaglescout007 0:b5f79b4f741d 28 USB_TYPE_BIT_STUFFING_ERROR = 2,
beaglescout007 0:b5f79b4f741d 29 USB_TYPE_DATA_TOGGLE_MISMATCH_ERROR = 3,
beaglescout007 0:b5f79b4f741d 30 USB_TYPE_STALL_ERROR = 4,
beaglescout007 0:b5f79b4f741d 31 USB_TYPE_DEVICE_NOT_RESPONDING_ERROR = 5,
beaglescout007 0:b5f79b4f741d 32 USB_TYPE_PID_CHECK_FAILURE_ERROR = 6,
beaglescout007 0:b5f79b4f741d 33 USB_TYPE_UNEXPECTED_PID_ERROR = 7,
beaglescout007 0:b5f79b4f741d 34 USB_TYPE_DATA_OVERRUN_ERROR = 8,
beaglescout007 0:b5f79b4f741d 35 USB_TYPE_DATA_UNDERRUN_ERROR = 9,
beaglescout007 0:b5f79b4f741d 36 USB_TYPE_RESERVED = 9,
beaglescout007 0:b5f79b4f741d 37 USB_TYPE_RESERVED_ = 10,
beaglescout007 0:b5f79b4f741d 38 USB_TYPE_BUFFER_OVERRUN_ERROR = 12,
beaglescout007 0:b5f79b4f741d 39 USB_TYPE_BUFFER_UNDERRUN_ERROR = 13,
beaglescout007 0:b5f79b4f741d 40
beaglescout007 0:b5f79b4f741d 41 // general usb state
beaglescout007 0:b5f79b4f741d 42 USB_TYPE_DISCONNECTED = 14,
beaglescout007 0:b5f79b4f741d 43 USB_TYPE_FREE = 15,
beaglescout007 0:b5f79b4f741d 44 USB_TYPE_IDLE = 16,
beaglescout007 0:b5f79b4f741d 45 USB_TYPE_PROCESSING = 17,
beaglescout007 0:b5f79b4f741d 46
beaglescout007 0:b5f79b4f741d 47 USB_TYPE_ERROR = 18,
beaglescout007 0:b5f79b4f741d 48 };
beaglescout007 0:b5f79b4f741d 49
beaglescout007 0:b5f79b4f741d 50
beaglescout007 0:b5f79b4f741d 51 enum ENDPOINT_DIRECTION {
beaglescout007 0:b5f79b4f741d 52 OUT = 1,
beaglescout007 0:b5f79b4f741d 53 IN
beaglescout007 0:b5f79b4f741d 54 };
beaglescout007 0:b5f79b4f741d 55
beaglescout007 0:b5f79b4f741d 56 enum ENDPOINT_TYPE {
beaglescout007 0:b5f79b4f741d 57 CONTROL_ENDPOINT = 0,
beaglescout007 0:b5f79b4f741d 58 ISOCHRONOUS_ENDPOINT,
beaglescout007 0:b5f79b4f741d 59 BULK_ENDPOINT,
beaglescout007 0:b5f79b4f741d 60 INTERRUPT_ENDPOINT
beaglescout007 0:b5f79b4f741d 61 };
beaglescout007 0:b5f79b4f741d 62
beaglescout007 0:b5f79b4f741d 63 #define AUDIO_CLASS 0x01
beaglescout007 0:b5f79b4f741d 64 #define CDC_CLASS 0x02
beaglescout007 0:b5f79b4f741d 65 #define HID_CLASS 0x03
beaglescout007 0:b5f79b4f741d 66 #define MSD_CLASS 0x08
beaglescout007 0:b5f79b4f741d 67 #define HUB_CLASS 0x09
beaglescout007 0:b5f79b4f741d 68 #define SERIAL_CLASS 0x0A
beaglescout007 0:b5f79b4f741d 69
beaglescout007 0:b5f79b4f741d 70 #define DEVICE_DESCRIPTOR (1)
beaglescout007 0:b5f79b4f741d 71 #define CONFIGURATION_DESCRIPTOR (2)
beaglescout007 0:b5f79b4f741d 72 #define INTERFACE_DESCRIPTOR (4)
beaglescout007 0:b5f79b4f741d 73 #define ENDPOINT_DESCRIPTOR (5)
beaglescout007 0:b5f79b4f741d 74 #define HID_DESCRIPTOR (33)
beaglescout007 0:b5f79b4f741d 75
beaglescout007 0:b5f79b4f741d 76 // ----------- Control RequestType Fields -----------
beaglescout007 0:b5f79b4f741d 77 #define USB_DEVICE_TO_HOST 0x80
beaglescout007 0:b5f79b4f741d 78 #define USB_HOST_TO_DEVICE 0x00
beaglescout007 0:b5f79b4f741d 79 #define USB_REQUEST_TYPE_CLASS 0x20
beaglescout007 0:b5f79b4f741d 80 #define USB_REQUEST_TYPE_STANDARD 0x00
beaglescout007 0:b5f79b4f741d 81 #define USB_RECIPIENT_DEVICE 0x00
beaglescout007 0:b5f79b4f741d 82 #define USB_RECIPIENT_INTERFACE 0x01
beaglescout007 0:b5f79b4f741d 83 #define USB_RECIPIENT_ENDPOINT 0x02
beaglescout007 0:b5f79b4f741d 84
beaglescout007 0:b5f79b4f741d 85 // -------------- USB Standard Requests --------------
beaglescout007 0:b5f79b4f741d 86 #define GET_STATUS 0x00
beaglescout007 0:b5f79b4f741d 87 #define SET_FEATURE 0x03
beaglescout007 0:b5f79b4f741d 88 #define SET_ADDRESS 0x05
beaglescout007 0:b5f79b4f741d 89 #define GET_DESCRIPTOR 0x06
beaglescout007 0:b5f79b4f741d 90 #define SET_CONFIGURATION 0x09
beaglescout007 0:b5f79b4f741d 91 #define SET_INTERFACE 0x0b
beaglescout007 0:b5f79b4f741d 92 #define CLEAR_FEATURE 0x01
beaglescout007 0:b5f79b4f741d 93
beaglescout007 0:b5f79b4f741d 94 // -------------- USB Descriptor Length --------------
beaglescout007 0:b5f79b4f741d 95 #define DEVICE_DESCRIPTOR_LENGTH 0x12
beaglescout007 0:b5f79b4f741d 96 #define CONFIGURATION_DESCRIPTOR_LENGTH 0x09
beaglescout007 0:b5f79b4f741d 97
beaglescout007 0:b5f79b4f741d 98 // PID
beaglescout007 0:b5f79b4f741d 99 #define DATA0 0x03
beaglescout007 0:b5f79b4f741d 100 #define DATA1 0x0b
beaglescout007 0:b5f79b4f741d 101 #define ACK 0x02
beaglescout007 0:b5f79b4f741d 102 #define STALL 0x0e
beaglescout007 0:b5f79b4f741d 103 #define NAK 0x0a
beaglescout007 0:b5f79b4f741d 104
beaglescout007 0:b5f79b4f741d 105 #pragma pack(push,1)
beaglescout007 0:b5f79b4f741d 106 typedef struct {
beaglescout007 0:b5f79b4f741d 107 uint8_t bLength;
beaglescout007 0:b5f79b4f741d 108 uint8_t bDescriptorType;
beaglescout007 0:b5f79b4f741d 109 uint16_t bcdUSB;
beaglescout007 0:b5f79b4f741d 110 uint8_t bDeviceClass;
beaglescout007 0:b5f79b4f741d 111 uint8_t bDeviceSubClass;
beaglescout007 0:b5f79b4f741d 112 uint8_t bDeviceProtocol;
beaglescout007 0:b5f79b4f741d 113 uint8_t bMaxPacketSize;
beaglescout007 0:b5f79b4f741d 114 uint16_t idVendor;
beaglescout007 0:b5f79b4f741d 115 uint16_t idProduct;
beaglescout007 0:b5f79b4f741d 116 uint16_t bcdDevice;
beaglescout007 0:b5f79b4f741d 117 uint8_t iManufacturer;
beaglescout007 0:b5f79b4f741d 118 uint8_t iProduct;
beaglescout007 0:b5f79b4f741d 119 uint8_t iSerialNumber;
beaglescout007 0:b5f79b4f741d 120 uint8_t bNumConfigurations;
beaglescout007 0:b5f79b4f741d 121 } PACKED DeviceDescriptor;
beaglescout007 0:b5f79b4f741d 122
beaglescout007 0:b5f79b4f741d 123 typedef struct {
beaglescout007 0:b5f79b4f741d 124 uint8_t bLength;
beaglescout007 0:b5f79b4f741d 125 uint8_t bDescriptorType;
beaglescout007 0:b5f79b4f741d 126 uint16_t wTotalLength;
beaglescout007 0:b5f79b4f741d 127 uint8_t bNumInterfaces;
beaglescout007 0:b5f79b4f741d 128 uint8_t bConfigurationValue;
beaglescout007 0:b5f79b4f741d 129 uint8_t iConfiguration;
beaglescout007 0:b5f79b4f741d 130 uint8_t bmAttributes;
beaglescout007 0:b5f79b4f741d 131 uint8_t bMaxPower;
beaglescout007 0:b5f79b4f741d 132 } PACKED ConfigurationDescriptor;
beaglescout007 0:b5f79b4f741d 133
beaglescout007 0:b5f79b4f741d 134 typedef struct {
beaglescout007 0:b5f79b4f741d 135 uint8_t bLength;
beaglescout007 0:b5f79b4f741d 136 uint8_t bDescriptorType;
beaglescout007 0:b5f79b4f741d 137 uint8_t bInterfaceNumber;
beaglescout007 0:b5f79b4f741d 138 uint8_t bAlternateSetting;
beaglescout007 0:b5f79b4f741d 139 uint8_t bNumEndpoints;
beaglescout007 0:b5f79b4f741d 140 uint8_t bInterfaceClass;
beaglescout007 0:b5f79b4f741d 141 uint8_t bInterfaceSubClass;
beaglescout007 0:b5f79b4f741d 142 uint8_t bInterfaceProtocol;
beaglescout007 0:b5f79b4f741d 143 uint8_t iInterface;
beaglescout007 0:b5f79b4f741d 144 } InterfaceDescriptor;
beaglescout007 0:b5f79b4f741d 145
beaglescout007 0:b5f79b4f741d 146 typedef struct {
beaglescout007 0:b5f79b4f741d 147 uint8_t bLength;
beaglescout007 0:b5f79b4f741d 148 uint8_t bDescriptorType;
beaglescout007 0:b5f79b4f741d 149 uint8_t bEndpointAddress;
beaglescout007 0:b5f79b4f741d 150 uint8_t bmAttributes;
beaglescout007 0:b5f79b4f741d 151 uint16_t wMaxPacketSize;
beaglescout007 0:b5f79b4f741d 152 uint8_t bInterval;
beaglescout007 0:b5f79b4f741d 153 } EndpointDescriptor;
beaglescout007 0:b5f79b4f741d 154
beaglescout007 0:b5f79b4f741d 155 typedef struct {
beaglescout007 0:b5f79b4f741d 156 uint8_t bDescLength;
beaglescout007 0:b5f79b4f741d 157 uint8_t bDescriptorType;
beaglescout007 0:b5f79b4f741d 158 uint8_t bNbrPorts;
beaglescout007 0:b5f79b4f741d 159 uint16_t wHubCharacteristics;
beaglescout007 0:b5f79b4f741d 160 uint8_t bPwrOn2PwrGood;
beaglescout007 0:b5f79b4f741d 161 uint8_t bHubContrCurrent;
beaglescout007 0:b5f79b4f741d 162 uint8_t DeviceRemovable;
beaglescout007 0:b5f79b4f741d 163 uint8_t PortPweCtrlMak;
beaglescout007 0:b5f79b4f741d 164 } HubDescriptor;
beaglescout007 0:b5f79b4f741d 165 #pragma pack(pop)
beaglescout007 0:b5f79b4f741d 166
beaglescout007 0:b5f79b4f741d 167 #endif
beaglescout007 0:b5f79b4f741d 168