BlueUSB with USB-> SERIAL (CP210x) GPIO pins working.

Dependencies:   mbed

Committer:
tecnosys
Date:
Fri Apr 23 05:04:28 2010 +0000
Revision:
0:a14eaa2e1445

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tecnosys 0:a14eaa2e1445 1
tecnosys 0:a14eaa2e1445 2 /*
tecnosys 0:a14eaa2e1445 3 Copyright (c) 2010 Peter Barrett
tecnosys 0:a14eaa2e1445 4
tecnosys 0:a14eaa2e1445 5 Permission is hereby granted, free of charge, to any person obtaining a copy
tecnosys 0:a14eaa2e1445 6 of this software and associated documentation files (the "Software"), to deal
tecnosys 0:a14eaa2e1445 7 in the Software without restriction, including without limitation the rights
tecnosys 0:a14eaa2e1445 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tecnosys 0:a14eaa2e1445 9 copies of the Software, and to permit persons to whom the Software is
tecnosys 0:a14eaa2e1445 10 furnished to do so, subject to the following conditions:
tecnosys 0:a14eaa2e1445 11
tecnosys 0:a14eaa2e1445 12 The above copyright notice and this permission notice shall be included in
tecnosys 0:a14eaa2e1445 13 all copies or substantial portions of the Software.
tecnosys 0:a14eaa2e1445 14
tecnosys 0:a14eaa2e1445 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tecnosys 0:a14eaa2e1445 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
tecnosys 0:a14eaa2e1445 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
tecnosys 0:a14eaa2e1445 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
tecnosys 0:a14eaa2e1445 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tecnosys 0:a14eaa2e1445 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
tecnosys 0:a14eaa2e1445 21 THE SOFTWARE.
tecnosys 0:a14eaa2e1445 22 */
tecnosys 0:a14eaa2e1445 23 /*
tecnosys 0:a14eaa2e1445 24 CP210
tecnosys 0:a14eaa2e1445 25 HubStatusChange Hub:0 Port:1 00010101
tecnosys 0:a14eaa2e1445 26 ResetPort Hub:0 Port:1
tecnosys 0:a14eaa2e1445 27 HubStatusChange Hub:0 Port:1 00100103
tecnosys 0:a14eaa2e1445 28 Connect Hub:0 Port:1 full
tecnosys 0:a14eaa2e1445 29 Class 00 found 10C4:EA60
tecnosys 0:a14eaa2e1445 30 AddEndpoint D:01 A:01 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 31 LoadDevice 1 FF:00:00
tecnosys 0:a14eaa2e1445 32 1: Silicon Labs
tecnosys 0:a14eaa2e1445 33 2: CP2103 USB to UART Bridge Controller
tecnosys 0:a14eaa2e1445 34
tecnosys 0:a14eaa2e1445 35 ////
tecnosys 0:a14eaa2e1445 36 CP210
tecnosys 0:a14eaa2e1445 37 HubStatusChange Hub:0 Port:1 00010101
tecnosys 0:a14eaa2e1445 38 ResetPort Hub:0 Port:1
tecnosys 0:a14eaa2e1445 39 HubStatusChange Hub:0 Port:1 00100103
tecnosys 0:a14eaa2e1445 40 Connect Hub:0 Port:1 full
tecnosys 0:a14eaa2e1445 41 Class 00 found 10C4:EA60
tecnosys 0:a14eaa2e1445 42 AddEndpoint D:01 A:00 T:00 P:0040 I:00
tecnosys 0:a14eaa2e1445 43 AddEndpoint D:01 A:81 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 44 AddEndpoint D:01 A:01 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 45 LoadDevice 1 FF:00:00
tecnosys 0:a14eaa2e1445 46 1: Silicon Labs
tecnosys 0:a14eaa2e1445 47 2: CP2103 USB to UART Bridge Controller
tecnosys 0:a14eaa2e1445 48
tecnosys 0:a14eaa2e1445 49 ///
tecnosys 0:a14eaa2e1445 50 FTDI
tecnosys 0:a14eaa2e1445 51 HubStatusChange Hub:0 Port:1 00010101
tecnosys 0:a14eaa2e1445 52 ResetPort Hub:0 Port:1
tecnosys 0:a14eaa2e1445 53 HubStatusChange Hub:0 Port:1 00100103
tecnosys 0:a14eaa2e1445 54 Connect Hub:0 Port:1 full
tecnosys 0:a14eaa2e1445 55
tecnosys 0:a14eaa2e1445 56 Class 00 found 0403:6001
tecnosys 0:a14eaa2e1445 57 AddEndpoint D:01 A:00 T:00 P:0008 I:00
tecnosys 0:a14eaa2e1445 58 AddEndpoint D:01 A:81 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 59 AddEndpoint D:01 A:02 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 60 LoadDevice 1 FF:FF:FF
tecnosys 0:a14eaa2e1445 61 1: FTDI
tecnosys 0:a14eaa2e1445 62 2: FT232R USB UART
tecnosys 0:a14eaa2e1445 63 //
tecnosys 0:a14eaa2e1445 64
tecnosys 0:a14eaa2e1445 65 mouse
tecnosys 0:a14eaa2e1445 66 HubStatusChange Hub:0 Port:1 00010301
tecnosys 0:a14eaa2e1445 67 ResetPort Hub:0 Port:1
tecnosys 0:a14eaa2e1445 68 HubStatusChange Hub:0 Port:1 00100303
tecnosys 0:a14eaa2e1445 69 Connect Hub:0 Port:1 slow
tecnosys 0:a14eaa2e1445 70 Class 00 found 046D:C019
tecnosys 0:a14eaa2e1445 71 AddEndpoint D:01 A:00 T:00 P:0008 I:00
tecnosys 0:a14eaa2e1445 72 Skipping descriptor 21 (9 bytes)
tecnosys 0:a14eaa2e1445 73 AddEndpoint D:01 A:81 T:03 P:0005 I:0A
tecnosys 0:a14eaa2e1445 74 LoadDevice 1 03:01:02
tecnosys 0:a14eaa2e1445 75 1: Logitech
tecnosys 0:a14eaa2e1445 76 2: Logitech USB Optical Mouse
tecnosys 0:a14eaa2e1445 77 Auto Event for 81 00030102
tecnosys 0:a14eaa2e1445 78
tecnosys 0:a14eaa2e1445 79
tecnosys 0:a14eaa2e1445 80 usbhd
tecnosys 0:a14eaa2e1445 81
tecnosys 0:a14eaa2e1445 82 HubStatusChange Hub:0 Port:1 00010101
tecnosys 0:a14eaa2e1445 83 ResetPort Hub:0 Port:1
tecnosys 0:a14eaa2e1445 84 HubStatusChange Hub:0 Port:1 00100103
tecnosys 0:a14eaa2e1445 85 Connect Hub:0 Port:1 full
tecnosys 0:a14eaa2e1445 86 Class 00 found 1E3D:2088
tecnosys 0:a14eaa2e1445 87 AddEndpoint D:01 A:00 T:00 P:0040 I:00
tecnosys 0:a14eaa2e1445 88 AddEndpoint D:01 A:01 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 89 AddEndpoint D:01 A:81 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 90 LoadDevice 1 08:06:50
tecnosys 0:a14eaa2e1445 91 1: V88
tecnosys 0:a14eaa2e1445 92 2: V88
tecnosys 0:a14eaa2e1445 93 Dumping root dir
tecnosys 0:a14eaa2e1445 94 _START~1.HTM 256
tecnosys 0:a14eaa2e1445 95 AUTORUN.INF 256
tecnosys 0:a14eaa2e1445 96 desktop.ini 256
tecnosys 0:a14eaa2e1445 97 STARTH~1.HTM 256
tecnosys 0:a14eaa2e1445 98 html 256
tecnosys 0:a14eaa2e1445 99
tecnosys 0:a14eaa2e1445 100 some tplink shit usb 54mbit wireless
tecnosys 0:a14eaa2e1445 101
tecnosys 0:a14eaa2e1445 102 sChange Hub:0 Port:1 00010101
tecnosys 0:a14eaa2e1445 103 ResetPort Hub:0 Port:1
tecnosys 0:a14eaa2e1445 104 HubStatusChange Hub:0 Port:1 00100103
tecnosys 0:a14eaa2e1445 105 Connect Hub:0 Port:1 full
tecnosys 0:a14eaa2e1445 106 Class 00 found 148F:2573
tecnosys 0:a14eaa2e1445 107 AddEndpoint D:01 A:00 T:00 P:0040 I:00
tecnosys 0:a14eaa2e1445 108 AddEndpoint D:01 A:81 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 109 AddEndpoint D:01 A:01 T:02 P:0040 I:00
tecnosys 0:a14eaa2e1445 110 LoadDevice 1 FF:FF:FF
tecnosys 0:a14eaa2e1445 111 1: Ralink
tecnosys 0:a14eaa2e1445 112 2: 54M.USB.......
tecnosys 0:a14eaa2e1445 113
tecnosys 0:a14eaa2e1445 114
tecnosys 0:a14eaa2e1445 115 */
tecnosys 0:a14eaa2e1445 116
tecnosys 0:a14eaa2e1445 117 #include "mbed.h"
tecnosys 0:a14eaa2e1445 118 #include "USBHost.h"
tecnosys 0:a14eaa2e1445 119 #include "Utils.h"
tecnosys 0:a14eaa2e1445 120
tecnosys 0:a14eaa2e1445 121 //#include "CP2103.h"
tecnosys 0:a14eaa2e1445 122
tecnosys 0:a14eaa2e1445 123 /* Config request types */
tecnosys 0:a14eaa2e1445 124 #define REQTYPE_HOST_TO_DEVICE 0x40
tecnosys 0:a14eaa2e1445 125 #define REQTYPE_DEVICE_TO_HOST 0xc0
tecnosys 0:a14eaa2e1445 126
tecnosys 0:a14eaa2e1445 127 /* Config request codes */
tecnosys 0:a14eaa2e1445 128 #define CP210X_SPECIFIC 0xFF
tecnosys 0:a14eaa2e1445 129
tecnosys 0:a14eaa2e1445 130 /* CP210X_SPECIFIC */
tecnosys 0:a14eaa2e1445 131 #define GPIO_WRITE 0x37E1
tecnosys 0:a14eaa2e1445 132 #define GPIO_READ 0x00C2
tecnosys 0:a14eaa2e1445 133 #define PORT_CONFIG 0x370C
tecnosys 0:a14eaa2e1445 134 #define WRITE_VID 0x3701
tecnosys 0:a14eaa2e1445 135 #define WRITE_PID 0x3702
tecnosys 0:a14eaa2e1445 136 #define WRITE_PRODUCT 0x3703
tecnosys 0:a14eaa2e1445 137 #define WRITE_SERIAL 0x3704
tecnosys 0:a14eaa2e1445 138 #define WRITE_POWER 0x3706
tecnosys 0:a14eaa2e1445 139 #define WRITE_RELEASE 0x3707
tecnosys 0:a14eaa2e1445 140
tecnosys 0:a14eaa2e1445 141
tecnosys 0:a14eaa2e1445 142 /* CP210X_IFC_ENABLE */
tecnosys 0:a14eaa2e1445 143 #define UART_ENABLE 0x0001
tecnosys 0:a14eaa2e1445 144 #define UART_DISABLE 0x0000
tecnosys 0:a14eaa2e1445 145
tecnosys 0:a14eaa2e1445 146 #define CP210X_IFC_ENABLE 0x00
tecnosys 0:a14eaa2e1445 147
tecnosys 0:a14eaa2e1445 148 #define CP210X_GPIO0 (1<<0)
tecnosys 0:a14eaa2e1445 149 #define CP210X_GPIO1 (1<<1)
tecnosys 0:a14eaa2e1445 150 #define CP210X_GPIO2 (1<<2)
tecnosys 0:a14eaa2e1445 151 #define CP210X_GPIO3 (1<<3)
tecnosys 0:a14eaa2e1445 152
tecnosys 0:a14eaa2e1445 153 struct cp210x_port_state_t {
tecnosys 0:a14eaa2e1445 154 uint16_t mode;
tecnosys 0:a14eaa2e1445 155 uint16_t low_power;
tecnosys 0:a14eaa2e1445 156 uint16_t latch;
tecnosys 0:a14eaa2e1445 157 } ;//cp210x_get_config
tecnosys 0:a14eaa2e1445 158
tecnosys 0:a14eaa2e1445 159 struct cp210x_port_config_t {
tecnosys 0:a14eaa2e1445 160 struct cp210x_port_state_t reset; /**< Port state applied on after reset. */
tecnosys 0:a14eaa2e1445 161 struct cp210x_port_state_t suspend; /**< Port state applied on suspend. */
tecnosys 0:a14eaa2e1445 162 unsigned char enhanced_fxn; /**< Enable/disable enhanced port functions. */
tecnosys 0:a14eaa2e1445 163 } ;//__attribute__ ((packed));
tecnosys 0:a14eaa2e1445 164
tecnosys 0:a14eaa2e1445 165
tecnosys 0:a14eaa2e1445 166 typedef struct
tecnosys 0:a14eaa2e1445 167 {
tecnosys 0:a14eaa2e1445 168 char *device_name;
tecnosys 0:a14eaa2e1445 169 uint8_t input; /**< Mask of GPIOs to be configured as inputs. */
tecnosys 0:a14eaa2e1445 170 uint8_t output; /**< Mask of GPIOs to be configured as outputs. */
tecnosys 0:a14eaa2e1445 171 uint8_t hi; /**< Mask of GPIOs to be set. */
tecnosys 0:a14eaa2e1445 172 uint8_t lo; /**< Mask of GPIOs to be cleared. */
tecnosys 0:a14eaa2e1445 173 uint8_t toggle; /**< Mask of GPIOs to be toggled. */
tecnosys 0:a14eaa2e1445 174 int dump; /**< Dump structures. */
tecnosys 0:a14eaa2e1445 175 }
tecnosys 0:a14eaa2e1445 176 config_t;
tecnosys 0:a14eaa2e1445 177
tecnosys 0:a14eaa2e1445 178
tecnosys 0:a14eaa2e1445 179 static const char *pin_names[] =
tecnosys 0:a14eaa2e1445 180 {
tecnosys 0:a14eaa2e1445 181 "RI", "DCD", "DTR", "DSR", "TXD", "RXD", "RTS", "CTS",
tecnosys 0:a14eaa2e1445 182 "GPIO_0", "GPIO_1", "GPIO_2", "GPIO_3",
tecnosys 0:a14eaa2e1445 183 "reserved", "reserved", "SUSPEND", "/SUSPEND"
tecnosys 0:a14eaa2e1445 184 };
tecnosys 0:a14eaa2e1445 185
tecnosys 0:a14eaa2e1445 186 static const char *fxn_names[] =
tecnosys 0:a14eaa2e1445 187 {
tecnosys 0:a14eaa2e1445 188 "GPIO_0_TXLED",
tecnosys 0:a14eaa2e1445 189 "GPIO_1_RXLED",
tecnosys 0:a14eaa2e1445 190 "GPIO_2_RS485",
tecnosys 0:a14eaa2e1445 191 "reserved",
tecnosys 0:a14eaa2e1445 192 "WEAKPULLUP_RESET",
tecnosys 0:a14eaa2e1445 193 "WEAKPULLUP_SUSPEND",
tecnosys 0:a14eaa2e1445 194 "SERIAL_DYNAMIC_SUSPEND",
tecnosys 0:a14eaa2e1445 195 "GPIO_DYNAMIC_SUSPEND"
tecnosys 0:a14eaa2e1445 196 };
tecnosys 0:a14eaa2e1445 197
tecnosys 0:a14eaa2e1445 198 #define AUTOEVT(_class,_subclass,_protocol) (((_class) << 16) | ((_subclass) << 8) | _protocol)
tecnosys 0:a14eaa2e1445 199 #define AUTO_KEYBOARD AUTOEVT(CLASS_HID,1,1)
tecnosys 0:a14eaa2e1445 200 #define AUTO_MOUSE AUTOEVT(CLASS_HID,1,2)
tecnosys 0:a14eaa2e1445 201
tecnosys 0:a14eaa2e1445 202 u8 auto_mouse[4]; // buttons,dx,dy,scroll
tecnosys 0:a14eaa2e1445 203 u8 auto_keyboard[8]; // modifiers,reserved,keycode1..keycode6
tecnosys 0:a14eaa2e1445 204 u8 auto_joystick[4]; // x,y,buttons,throttle
tecnosys 0:a14eaa2e1445 205
tecnosys 0:a14eaa2e1445 206 void AutoEventCallback(int device, int endpoint, int status, u8* data, int len, void* userData)
tecnosys 0:a14eaa2e1445 207 {
tecnosys 0:a14eaa2e1445 208 int evt = (int)userData;
tecnosys 0:a14eaa2e1445 209 switch (evt)
tecnosys 0:a14eaa2e1445 210 {
tecnosys 0:a14eaa2e1445 211 case AUTO_KEYBOARD:
tecnosys 0:a14eaa2e1445 212 printf("AUTO_KEYBOARD ");
tecnosys 0:a14eaa2e1445 213 break;
tecnosys 0:a14eaa2e1445 214 case AUTO_MOUSE:
tecnosys 0:a14eaa2e1445 215 printf("AUTO_MOUSE ");
tecnosys 0:a14eaa2e1445 216 break;
tecnosys 0:a14eaa2e1445 217 default:
tecnosys 0:a14eaa2e1445 218 printf("HUH ");
tecnosys 0:a14eaa2e1445 219 }
tecnosys 0:a14eaa2e1445 220 printfBytes("data",data,len);
tecnosys 0:a14eaa2e1445 221 USBInterruptTransfer(device,endpoint,data,len,AutoEventCallback,userData);
tecnosys 0:a14eaa2e1445 222 }
tecnosys 0:a14eaa2e1445 223
tecnosys 0:a14eaa2e1445 224 // Establish transfers for interrupt events
tecnosys 0:a14eaa2e1445 225 void AddAutoEvent(int device, InterfaceDescriptor* id, EndpointDescriptor* ed)
tecnosys 0:a14eaa2e1445 226 {
tecnosys 0:a14eaa2e1445 227 if ((ed->bmAttributes & 3) != ENDPOINT_INTERRUPT || !(ed->bEndpointAddress & 0x80))
tecnosys 0:a14eaa2e1445 228 return;
tecnosys 0:a14eaa2e1445 229
tecnosys 0:a14eaa2e1445 230 // Make automatic interrupt enpoints for known devices
tecnosys 0:a14eaa2e1445 231 u32 evt = AUTOEVT(id->bInterfaceClass,id->bInterfaceSubClass,id->bInterfaceProtocol);
tecnosys 0:a14eaa2e1445 232 u8* dst = 0;
tecnosys 0:a14eaa2e1445 233 int len;
tecnosys 0:a14eaa2e1445 234 switch (evt)
tecnosys 0:a14eaa2e1445 235 {
tecnosys 0:a14eaa2e1445 236 case AUTO_MOUSE:
tecnosys 0:a14eaa2e1445 237 dst = auto_mouse;
tecnosys 0:a14eaa2e1445 238 len = sizeof(auto_mouse);
tecnosys 0:a14eaa2e1445 239 break;
tecnosys 0:a14eaa2e1445 240 case AUTO_KEYBOARD:
tecnosys 0:a14eaa2e1445 241 dst = auto_keyboard;
tecnosys 0:a14eaa2e1445 242 len = sizeof(auto_keyboard);
tecnosys 0:a14eaa2e1445 243 break;
tecnosys 0:a14eaa2e1445 244 default:
tecnosys 0:a14eaa2e1445 245 printf("Interrupt endpoint %02X %08X\n",ed->bEndpointAddress,evt);
tecnosys 0:a14eaa2e1445 246 break;
tecnosys 0:a14eaa2e1445 247 }
tecnosys 0:a14eaa2e1445 248 if (dst)
tecnosys 0:a14eaa2e1445 249 {
tecnosys 0:a14eaa2e1445 250 printf("Auto Event for %02X %08X\n",ed->bEndpointAddress,evt);
tecnosys 0:a14eaa2e1445 251 USBInterruptTransfer(device,ed->bEndpointAddress,dst,len,AutoEventCallback,(void*)evt);
tecnosys 0:a14eaa2e1445 252 }
tecnosys 0:a14eaa2e1445 253 }
tecnosys 0:a14eaa2e1445 254
tecnosys 0:a14eaa2e1445 255 void PrintString(int device, int i)
tecnosys 0:a14eaa2e1445 256 {
tecnosys 0:a14eaa2e1445 257 u8 buffer[256];
tecnosys 0:a14eaa2e1445 258 int le = GetDescriptor(device,DESCRIPTOR_TYPE_STRING,i,buffer,255);
tecnosys 0:a14eaa2e1445 259 if (le < 0)
tecnosys 0:a14eaa2e1445 260 return;
tecnosys 0:a14eaa2e1445 261 char* dst = (char*)buffer;
tecnosys 0:a14eaa2e1445 262 for (int j = 2; j < le; j += 2)
tecnosys 0:a14eaa2e1445 263 *dst++ = buffer[j];
tecnosys 0:a14eaa2e1445 264 *dst = 0;
tecnosys 0:a14eaa2e1445 265 printf("%d:%s\n",i,(const char*)buffer);
tecnosys 0:a14eaa2e1445 266 }
tecnosys 0:a14eaa2e1445 267
tecnosys 0:a14eaa2e1445 268 // Walk descriptors and create endpoints for a given device
tecnosys 0:a14eaa2e1445 269 int StartAutoEvent(int device, int configuration, int interfaceNumber)
tecnosys 0:a14eaa2e1445 270 {
tecnosys 0:a14eaa2e1445 271 u8 buffer[255];
tecnosys 0:a14eaa2e1445 272 int err = GetDescriptor(device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,255);
tecnosys 0:a14eaa2e1445 273 if (err < 0)
tecnosys 0:a14eaa2e1445 274 return err;
tecnosys 0:a14eaa2e1445 275
tecnosys 0:a14eaa2e1445 276 int len = buffer[2] | (buffer[3] << 8);
tecnosys 0:a14eaa2e1445 277 u8* d = buffer;
tecnosys 0:a14eaa2e1445 278 u8* end = d + len;
tecnosys 0:a14eaa2e1445 279 while (d < end)
tecnosys 0:a14eaa2e1445 280 {
tecnosys 0:a14eaa2e1445 281 if (d[1] == DESCRIPTOR_TYPE_INTERFACE)
tecnosys 0:a14eaa2e1445 282 {
tecnosys 0:a14eaa2e1445 283 InterfaceDescriptor* id = (InterfaceDescriptor*)d;
tecnosys 0:a14eaa2e1445 284 if (id->bInterfaceNumber == interfaceNumber)
tecnosys 0:a14eaa2e1445 285 {
tecnosys 0:a14eaa2e1445 286 d += d[0];
tecnosys 0:a14eaa2e1445 287 while (d < end && d[1] != DESCRIPTOR_TYPE_INTERFACE)
tecnosys 0:a14eaa2e1445 288 {
tecnosys 0:a14eaa2e1445 289 if (d[1] == DESCRIPTOR_TYPE_ENDPOINT)
tecnosys 0:a14eaa2e1445 290 AddAutoEvent(device,id,(EndpointDescriptor*)d);
tecnosys 0:a14eaa2e1445 291 d += d[0];
tecnosys 0:a14eaa2e1445 292 }
tecnosys 0:a14eaa2e1445 293 }
tecnosys 0:a14eaa2e1445 294 }
tecnosys 0:a14eaa2e1445 295 d += d[0];
tecnosys 0:a14eaa2e1445 296 }
tecnosys 0:a14eaa2e1445 297 return 0;
tecnosys 0:a14eaa2e1445 298 }
tecnosys 0:a14eaa2e1445 299
tecnosys 0:a14eaa2e1445 300
tecnosys 0:a14eaa2e1445 301
tecnosys 0:a14eaa2e1445 302 // Implemented in main.cpp
tecnosys 0:a14eaa2e1445 303 int OnDiskInsert(int device);
tecnosys 0:a14eaa2e1445 304
tecnosys 0:a14eaa2e1445 305 // Implemented in TestShell.cpp
tecnosys 0:a14eaa2e1445 306 int OnBluetoothInsert(int device);
tecnosys 0:a14eaa2e1445 307
tecnosys 0:a14eaa2e1445 308 static int cp210x_set_config(int device, u8 request,
tecnosys 0:a14eaa2e1445 309 unsigned int *data, int size)
tecnosys 0:a14eaa2e1445 310 {
tecnosys 0:a14eaa2e1445 311 /*
tecnosys 0:a14eaa2e1445 312 result = usb_control_msg(serial->dev,
tecnosys 0:a14eaa2e1445 313 usb_sndctrlpipe(serial->dev, 0),
tecnosys 0:a14eaa2e1445 314 request, REQTYPE_HOST_TO_DEVICE, 0x0000,
tecnosys 0:a14eaa2e1445 315 0, buf, size, 300);
tecnosys 0:a14eaa2e1445 316 */
tecnosys 0:a14eaa2e1445 317
tecnosys 0:a14eaa2e1445 318 return USBControlTransfer(device,
tecnosys 0:a14eaa2e1445 319 REQTYPE_HOST_TO_DEVICE, request, 0x0000, 0,
tecnosys 0:a14eaa2e1445 320 (u8*)data, sizeof(*data),0);
tecnosys 0:a14eaa2e1445 321
tecnosys 0:a14eaa2e1445 322
tecnosys 0:a14eaa2e1445 323 }
tecnosys 0:a14eaa2e1445 324
tecnosys 0:a14eaa2e1445 325
tecnosys 0:a14eaa2e1445 326 void
tecnosys 0:a14eaa2e1445 327 print_bits8( const uint8_t value )
tecnosys 0:a14eaa2e1445 328 {
tecnosys 0:a14eaa2e1445 329 int i = 7;
tecnosys 0:a14eaa2e1445 330 printf("b");
tecnosys 0:a14eaa2e1445 331 do
tecnosys 0:a14eaa2e1445 332 {
tecnosys 0:a14eaa2e1445 333 printf("%c", value & (1<<i) ? '1' : '0');
tecnosys 0:a14eaa2e1445 334 }
tecnosys 0:a14eaa2e1445 335 while( i-- );
tecnosys 0:a14eaa2e1445 336 }
tecnosys 0:a14eaa2e1445 337
tecnosys 0:a14eaa2e1445 338 void
tecnosys 0:a14eaa2e1445 339 print_bits16( const uint16_t value )
tecnosys 0:a14eaa2e1445 340 {
tecnosys 0:a14eaa2e1445 341 int i = 15;
tecnosys 0:a14eaa2e1445 342 printf("b");
tecnosys 0:a14eaa2e1445 343 do
tecnosys 0:a14eaa2e1445 344 {
tecnosys 0:a14eaa2e1445 345 printf("%c", value & (1<<i) ? '1' : '0');
tecnosys 0:a14eaa2e1445 346 }
tecnosys 0:a14eaa2e1445 347 while( i-- );
tecnosys 0:a14eaa2e1445 348 }
tecnosys 0:a14eaa2e1445 349
tecnosys 0:a14eaa2e1445 350
tecnosys 0:a14eaa2e1445 351 int cp210x_get_port_config(int device,struct cp210x_port_config_t *data)
tecnosys 0:a14eaa2e1445 352 {
tecnosys 0:a14eaa2e1445 353 int result;
tecnosys 0:a14eaa2e1445 354
tecnosys 0:a14eaa2e1445 355 /* Issue the request, attempting to read 'size' bytes */
tecnosys 0:a14eaa2e1445 356 //result = cp2103_usb_control_msg(
tecnosys 0:a14eaa2e1445 357 // CP210X_SPECIFIC, REQTYPE_DEVICE_TO_HOST, PORT_CONFIG, 0,
tecnosys 0:a14eaa2e1445 358 // data, sizeof(*data));
tecnosys 0:a14eaa2e1445 359
tecnosys 0:a14eaa2e1445 360 result = USBControlTransfer(device,
tecnosys 0:a14eaa2e1445 361 REQTYPE_DEVICE_TO_HOST, CP210X_SPECIFIC, PORT_CONFIG, 0,
tecnosys 0:a14eaa2e1445 362 (u8*)data, sizeof(*data),0);
tecnosys 0:a14eaa2e1445 363
tecnosys 0:a14eaa2e1445 364 if (result != sizeof(*data)) {
tecnosys 0:a14eaa2e1445 365 printf("Unable to get port_config, result = %d", result);
tecnosys 0:a14eaa2e1445 366 return -1;
tecnosys 0:a14eaa2e1445 367 }
tecnosys 0:a14eaa2e1445 368
tecnosys 0:a14eaa2e1445 369 printf("reset: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
tecnosys 0:a14eaa2e1445 370 " - supend: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
tecnosys 0:a14eaa2e1445 371 " - enhanced_fxn: 0x%02X",
tecnosys 0:a14eaa2e1445 372 data->reset.mode, data->reset.low_power, data->reset.latch,
tecnosys 0:a14eaa2e1445 373 data->suspend.mode, data->suspend.low_power,
tecnosys 0:a14eaa2e1445 374 data->suspend.latch, data->enhanced_fxn
tecnosys 0:a14eaa2e1445 375 );
tecnosys 0:a14eaa2e1445 376
tecnosys 0:a14eaa2e1445 377 return 0;
tecnosys 0:a14eaa2e1445 378 }
tecnosys 0:a14eaa2e1445 379
tecnosys 0:a14eaa2e1445 380 int cp210x_set_port_config(int device,struct cp210x_port_config_t *data)
tecnosys 0:a14eaa2e1445 381 {
tecnosys 0:a14eaa2e1445 382 int result;
tecnosys 0:a14eaa2e1445 383
tecnosys 0:a14eaa2e1445 384 printf("reset: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
tecnosys 0:a14eaa2e1445 385 " - supend: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
tecnosys 0:a14eaa2e1445 386 " - enhanced_fxn: 0x%02X",
tecnosys 0:a14eaa2e1445 387 data->reset.mode, data->reset.low_power, data->reset.latch,
tecnosys 0:a14eaa2e1445 388 data->suspend.mode, data->suspend.low_power,
tecnosys 0:a14eaa2e1445 389 data->suspend.latch, data->enhanced_fxn
tecnosys 0:a14eaa2e1445 390 );
tecnosys 0:a14eaa2e1445 391
tecnosys 0:a14eaa2e1445 392 /* Issue the request, attempting to read 'size' bytes */
tecnosys 0:a14eaa2e1445 393 // result = cp2103_usb_control_msg(
tecnosys 0:a14eaa2e1445 394 // CP210X_SPECIFIC, REQTYPE_HOST_TO_DEVICE, PORT_CONFIG, 0,
tecnosys 0:a14eaa2e1445 395 // data, sizeof(*data));
tecnosys 0:a14eaa2e1445 396
tecnosys 0:a14eaa2e1445 397 result = USBControlTransfer(device,
tecnosys 0:a14eaa2e1445 398 REQTYPE_HOST_TO_DEVICE, CP210X_SPECIFIC, PORT_CONFIG, 0,
tecnosys 0:a14eaa2e1445 399 (u8*)data, sizeof(*data),0);
tecnosys 0:a14eaa2e1445 400
tecnosys 0:a14eaa2e1445 401
tecnosys 0:a14eaa2e1445 402
tecnosys 0:a14eaa2e1445 403 if (result != sizeof(*data)) {
tecnosys 0:a14eaa2e1445 404 printf("Unable to set port_config, result = %d", result);
tecnosys 0:a14eaa2e1445 405 return -1;
tecnosys 0:a14eaa2e1445 406 }
tecnosys 0:a14eaa2e1445 407
tecnosys 0:a14eaa2e1445 408 return 0;
tecnosys 0:a14eaa2e1445 409 }
tecnosys 0:a14eaa2e1445 410
tecnosys 0:a14eaa2e1445 411 static int cp210x_set_config_single(int device,
tecnosys 0:a14eaa2e1445 412 u8 request, unsigned int data)
tecnosys 0:a14eaa2e1445 413 {
tecnosys 0:a14eaa2e1445 414 return cp210x_set_config(device, request, &data, 2);
tecnosys 0:a14eaa2e1445 415 }
tecnosys 0:a14eaa2e1445 416
tecnosys 0:a14eaa2e1445 417 static int cp210x_read_gpio(int device, int offset)
tecnosys 0:a14eaa2e1445 418 {
tecnosys 0:a14eaa2e1445 419 int result;
tecnosys 0:a14eaa2e1445 420 u8 *data;
tecnosys 0:a14eaa2e1445 421 /* Issue the request, attempting to read 'size' bytes */
tecnosys 0:a14eaa2e1445 422 //result = cp210x_control_msg(serial,
tecnosys 0:a14eaa2e1445 423 // CP210X_SPECIFIC, REQTYPE_DEVICE_TO_HOST, GPIO_READ,
tecnosys 0:a14eaa2e1445 424 // 0, data, sizeof(*data));
tecnosys 0:a14eaa2e1445 425
tecnosys 0:a14eaa2e1445 426 result = USBControlTransfer(device,
tecnosys 0:a14eaa2e1445 427 REQTYPE_DEVICE_TO_HOST, CP210X_SPECIFIC, GPIO_READ, 0,
tecnosys 0:a14eaa2e1445 428 (u8*)data, sizeof(*data),0);
tecnosys 0:a14eaa2e1445 429
tecnosys 0:a14eaa2e1445 430
tecnosys 0:a14eaa2e1445 431 if (result != sizeof(*data)) {
tecnosys 0:a14eaa2e1445 432 printf("%s: Unable to read gpio latch, ");
tecnosys 0:a14eaa2e1445 433 return -1;
tecnosys 0:a14eaa2e1445 434 }
tecnosys 0:a14eaa2e1445 435
tecnosys 0:a14eaa2e1445 436 printf("\n\rread latch value = 0x%02X", *data);
tecnosys 0:a14eaa2e1445 437 print_bits8(*data);
tecnosys 0:a14eaa2e1445 438 return 0;// data & (1<<(offset & 0x0F));
tecnosys 0:a14eaa2e1445 439 }
tecnosys 0:a14eaa2e1445 440
tecnosys 0:a14eaa2e1445 441 static int cp210x_write_gpio(int device, const u8 mask,
tecnosys 0:a14eaa2e1445 442 const u8 value)
tecnosys 0:a14eaa2e1445 443 {
tecnosys 0:a14eaa2e1445 444
tecnosys 0:a14eaa2e1445 445 int result;
tecnosys 0:a14eaa2e1445 446
tecnosys 0:a14eaa2e1445 447 printf("writing to latch mask = 0x%02X, value = 0x%02X", mask, value);
tecnosys 0:a14eaa2e1445 448
tecnosys 0:a14eaa2e1445 449 //result = cp210x_control_msg(serial,
tecnosys 0:a14eaa2e1445 450 // CP210X_SPECIFIC, REQTYPE_HOST_TO_DEVICE, GPIO_WRITE,
tecnosys 0:a14eaa2e1445 451 // (value << 8) | mask, NULL, 0);
tecnosys 0:a14eaa2e1445 452
tecnosys 0:a14eaa2e1445 453 u8 val = (value << 8)| mask ;
tecnosys 0:a14eaa2e1445 454 result = USBControlTransfer(device,
tecnosys 0:a14eaa2e1445 455 REQTYPE_HOST_TO_DEVICE, CP210X_SPECIFIC, GPIO_WRITE,
tecnosys 0:a14eaa2e1445 456 (value << 8)| mask,
tecnosys 0:a14eaa2e1445 457 0, NULL,0);
tecnosys 0:a14eaa2e1445 458
tecnosys 0:a14eaa2e1445 459 if (result < 0) {
tecnosys 0:a14eaa2e1445 460 printf( "%s: Unable to write into gpio latch, ");
tecnosys 0:a14eaa2e1445 461 return -1;
tecnosys 0:a14eaa2e1445 462 }
tecnosys 0:a14eaa2e1445 463
tecnosys 0:a14eaa2e1445 464 return 0;
tecnosys 0:a14eaa2e1445 465 }
tecnosys 0:a14eaa2e1445 466
tecnosys 0:a14eaa2e1445 467 static void cp210x_gpio_set(int device,
tecnosys 0:a14eaa2e1445 468 unsigned offset, int value)
tecnosys 0:a14eaa2e1445 469 {
tecnosys 0:a14eaa2e1445 470 (void)cp210x_write_gpio(device,
tecnosys 0:a14eaa2e1445 471 (1<<(offset & 0x0F)), value ? 0xFF : 0x00);
tecnosys 0:a14eaa2e1445 472 }
tecnosys 0:a14eaa2e1445 473 static int cp210x_gpio_input_mask(int device, u8 mask)
tecnosys 0:a14eaa2e1445 474 {
tecnosys 0:a14eaa2e1445 475 struct cp210x_port_config_t config = {};
tecnosys 0:a14eaa2e1445 476 int result;
tecnosys 0:a14eaa2e1445 477
tecnosys 0:a14eaa2e1445 478 mask &= 0x0F;
tecnosys 0:a14eaa2e1445 479
tecnosys 0:a14eaa2e1445 480 /* configure masked gpio as open-drain and set masked latch bits */
tecnosys 0:a14eaa2e1445 481 result = cp210x_get_port_config(device, &config);
tecnosys 0:a14eaa2e1445 482 if (result == 0) {
tecnosys 0:a14eaa2e1445 483 config.reset.mode &= ~(((u16)mask)<<8);
tecnosys 0:a14eaa2e1445 484 config.reset.latch |= ((u16)mask)<<8;
tecnosys 0:a14eaa2e1445 485 config.suspend.mode &= ~(((u16)mask)<<8);
tecnosys 0:a14eaa2e1445 486 config.suspend.latch |= ((u16)mask)<<8;
tecnosys 0:a14eaa2e1445 487 result = cp210x_set_port_config(device, &config);
tecnosys 0:a14eaa2e1445 488 }
tecnosys 0:a14eaa2e1445 489 return result;
tecnosys 0:a14eaa2e1445 490 }
tecnosys 0:a14eaa2e1445 491
tecnosys 0:a14eaa2e1445 492 static int cp210x_gpio_output_mask(int device, u8 mask)
tecnosys 0:a14eaa2e1445 493 {
tecnosys 0:a14eaa2e1445 494 struct cp210x_port_config_t config = {};
tecnosys 0:a14eaa2e1445 495 int result;
tecnosys 0:a14eaa2e1445 496
tecnosys 0:a14eaa2e1445 497 mask &= 0x0F;
tecnosys 0:a14eaa2e1445 498
tecnosys 0:a14eaa2e1445 499 /* configure masked gpio as push-pull */
tecnosys 0:a14eaa2e1445 500 result = cp210x_get_port_config(device, &config);
tecnosys 0:a14eaa2e1445 501 if (result == 0) {
tecnosys 0:a14eaa2e1445 502 config.reset.mode |= ((u16)mask)<<8;
tecnosys 0:a14eaa2e1445 503 config.suspend.mode |= ((u16)mask)<<8;
tecnosys 0:a14eaa2e1445 504 result = cp210x_set_port_config(device, &config);
tecnosys 0:a14eaa2e1445 505 }
tecnosys 0:a14eaa2e1445 506 return result;
tecnosys 0:a14eaa2e1445 507 }
tecnosys 0:a14eaa2e1445 508
tecnosys 0:a14eaa2e1445 509
tecnosys 0:a14eaa2e1445 510 void
tecnosys 0:a14eaa2e1445 511 dump_port_config( const struct cp210x_port_config_t config )
tecnosys 0:a14eaa2e1445 512 {
tecnosys 0:a14eaa2e1445 513 int i;
tecnosys 0:a14eaa2e1445 514 printf("--- Dump of port configuration --- \n\r");
tecnosys 0:a14eaa2e1445 515 printf("Raw data:\n\r");
tecnosys 0:a14eaa2e1445 516 printf("reset.mode = 0x%04X ", config.reset.mode);
tecnosys 0:a14eaa2e1445 517 print_bits16(config.reset.mode); printf("\n\r");
tecnosys 0:a14eaa2e1445 518 printf("reset.low_power = 0x%04X ", config.reset.low_power);
tecnosys 0:a14eaa2e1445 519 print_bits16(config.reset.low_power); printf("\n\r");
tecnosys 0:a14eaa2e1445 520 printf("reset.latch = 0x%04X ", config.reset.latch);
tecnosys 0:a14eaa2e1445 521 print_bits16(config.reset.latch); printf("\n\r");
tecnosys 0:a14eaa2e1445 522 printf("suspend.mode = 0x%04X ", config.suspend.mode);
tecnosys 0:a14eaa2e1445 523 print_bits16(config.suspend.mode); printf("\n\r");
tecnosys 0:a14eaa2e1445 524 printf("suspend.low_power = 0x%04X ", config.suspend.low_power);
tecnosys 0:a14eaa2e1445 525 print_bits16(config.suspend.low_power); printf("\n\r");
tecnosys 0:a14eaa2e1445 526 printf("suspend.latch = 0x%04X ", config.suspend.latch);
tecnosys 0:a14eaa2e1445 527 print_bits16(config.suspend.latch); printf("\n\r");
tecnosys 0:a14eaa2e1445 528 printf("enhanced_fxn = 0x%02X ", config.enhanced_fxn);
tecnosys 0:a14eaa2e1445 529 print_bits8(config.enhanced_fxn); printf("\n\r");
tecnosys 0:a14eaa2e1445 530 printf("\n\r");
tecnosys 0:a14eaa2e1445 531 printf("Configuration applied on after reset / suspend (mode, low_power, latch):\n\r");
tecnosys 0:a14eaa2e1445 532 for ( i=0; i<16; i++ )
tecnosys 0:a14eaa2e1445 533 {
tecnosys 0:a14eaa2e1445 534 printf("%-20s %s %s/%s %c/%c %c/%c\n\r",
tecnosys 0:a14eaa2e1445 535 pin_names[i],
tecnosys 0:a14eaa2e1445 536 ((config.reset.mode & (1<<i)) == 0 && (config.reset.latch & (1<<i))) ? "IN " : "OUT",
tecnosys 0:a14eaa2e1445 537 (config.reset.mode & (1<<i)) ? " Push-Pull" : "Open-Drain",
tecnosys 0:a14eaa2e1445 538 (config.suspend.mode & (1<<i)) ? "Push-Pull " : "Open-Drain",
tecnosys 0:a14eaa2e1445 539 (config.reset.low_power & (1<<i)) ? '1' : '0',
tecnosys 0:a14eaa2e1445 540 (config.suspend.low_power & (1<<i)) ? '1' : '0',
tecnosys 0:a14eaa2e1445 541 (config.reset.latch & (1<<i)) ? '1' : '0',
tecnosys 0:a14eaa2e1445 542 (config.suspend.latch & (1<<i)) ? '1' : '0');
tecnosys 0:a14eaa2e1445 543 }
tecnosys 0:a14eaa2e1445 544 printf("\n\r");
tecnosys 0:a14eaa2e1445 545 printf("Enhanced functions:\n\r");
tecnosys 0:a14eaa2e1445 546 for ( i=0; i<8; i++ )
tecnosys 0:a14eaa2e1445 547 {
tecnosys 0:a14eaa2e1445 548 printf("%-24s %s\n\r",
tecnosys 0:a14eaa2e1445 549 fxn_names[i],
tecnosys 0:a14eaa2e1445 550 (config.enhanced_fxn & (1<<i)) ? "ENABLED" : "DISABLED");
tecnosys 0:a14eaa2e1445 551 }
tecnosys 0:a14eaa2e1445 552 printf("--- End of Dump --- \n\r");
tecnosys 0:a14eaa2e1445 553 printf("\n\r");
tecnosys 0:a14eaa2e1445 554 }
tecnosys 0:a14eaa2e1445 555
tecnosys 0:a14eaa2e1445 556
tecnosys 0:a14eaa2e1445 557
tecnosys 0:a14eaa2e1445 558
tecnosys 0:a14eaa2e1445 559 int OnCP210xInsert(int device)
tecnosys 0:a14eaa2e1445 560 {
tecnosys 0:a14eaa2e1445 561 printf("CP210x inserted of %d\n",device);
tecnosys 0:a14eaa2e1445 562
tecnosys 0:a14eaa2e1445 563 struct cp210x_port_config_t *data;
tecnosys 0:a14eaa2e1445 564
tecnosys 0:a14eaa2e1445 565 int result;
tecnosys 0:a14eaa2e1445 566 u16 *tes;
tecnosys 0:a14eaa2e1445 567
tecnosys 0:a14eaa2e1445 568 result = cp210x_get_port_config( device,data);
tecnosys 0:a14eaa2e1445 569
tecnosys 0:a14eaa2e1445 570
tecnosys 0:a14eaa2e1445 571
tecnosys 0:a14eaa2e1445 572
tecnosys 0:a14eaa2e1445 573
tecnosys 0:a14eaa2e1445 574 // for (i = 0; i < sizeof(*data); i++)
tecnosys 0:a14eaa2e1445 575 // data[i] = le32_to_cpu(data[i]);
tecnosys 0:a14eaa2e1445 576
tecnosys 0:a14eaa2e1445 577 printf("reset: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
tecnosys 0:a14eaa2e1445 578 " - supend: mode = 0x%04X, low_power = 0x%04X, latch = 0x%04X"
tecnosys 0:a14eaa2e1445 579 " - enhanced_fxn: 0x%02X --------------------------------------------------",
tecnosys 0:a14eaa2e1445 580 data->reset.mode, data->reset.low_power, data->reset.latch,
tecnosys 0:a14eaa2e1445 581 data->suspend.mode, data->suspend.low_power,
tecnosys 0:a14eaa2e1445 582 data->suspend.latch, data->enhanced_fxn
tecnosys 0:a14eaa2e1445 583 );
tecnosys 0:a14eaa2e1445 584 printf(" HERE \n\r");
tecnosys 0:a14eaa2e1445 585
tecnosys 0:a14eaa2e1445 586 dump_port_config(*data);
tecnosys 0:a14eaa2e1445 587
tecnosys 0:a14eaa2e1445 588 // if (cp210x_set_config_single(device, CP210X_IFC_ENABLE, UART_ENABLE)) {
tecnosys 0:a14eaa2e1445 589 // printf(" Unable to enable UART\n");
tecnosys 0:a14eaa2e1445 590
tecnosys 0:a14eaa2e1445 591 // }
tecnosys 0:a14eaa2e1445 592 cp210x_gpio_output_mask(device,0xf);
tecnosys 0:a14eaa2e1445 593 cp210x_read_gpio(device,0);cp210x_read_gpio(device,1);cp210x_read_gpio(device,2);cp210x_read_gpio(device,3);
tecnosys 0:a14eaa2e1445 594
tecnosys 0:a14eaa2e1445 595 cp210x_gpio_set(device,0,0xff);
tecnosys 0:a14eaa2e1445 596 cp210x_gpio_set(device,1,0x0);
tecnosys 0:a14eaa2e1445 597
tecnosys 0:a14eaa2e1445 598 cp210x_gpio_set(device,2,0xff);
tecnosys 0:a14eaa2e1445 599 cp210x_gpio_set(device,3,0x0);
tecnosys 0:a14eaa2e1445 600
tecnosys 0:a14eaa2e1445 601 // cp210x_gpio_set(device,2,0xff);
tecnosys 0:a14eaa2e1445 602 // cp210x_gpio_set(device,3,0xf);
tecnosys 0:a14eaa2e1445 603
tecnosys 0:a14eaa2e1445 604 cp210x_read_gpio(device,0);cp210x_read_gpio(device,1);cp210x_read_gpio(device,2);cp210x_read_gpio(device,3);
tecnosys 0:a14eaa2e1445 605
tecnosys 0:a14eaa2e1445 606 printf(" HERE2 \n\r");
tecnosys 0:a14eaa2e1445 607 result = cp210x_get_port_config( device,data);
tecnosys 0:a14eaa2e1445 608 dump_port_config(*data);
tecnosys 0:a14eaa2e1445 609 return 0;
tecnosys 0:a14eaa2e1445 610 }
tecnosys 0:a14eaa2e1445 611
tecnosys 0:a14eaa2e1445 612
tecnosys 0:a14eaa2e1445 613 int OnFTDIInsert(int device);
tecnosys 0:a14eaa2e1445 614
tecnosys 0:a14eaa2e1445 615 void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc)
tecnosys 0:a14eaa2e1445 616 {
tecnosys 0:a14eaa2e1445 617 printf("LoadDevice %d %02X:%02X:%02X\n",device,interfaceDesc->bInterfaceClass,interfaceDesc->bInterfaceSubClass,interfaceDesc->bInterfaceProtocol);
tecnosys 0:a14eaa2e1445 618 char s[128];
tecnosys 0:a14eaa2e1445 619 for (int i = 1; i < 3; i++)
tecnosys 0:a14eaa2e1445 620 {
tecnosys 0:a14eaa2e1445 621 if (GetString(device,i,s,sizeof(s)) < 0)
tecnosys 0:a14eaa2e1445 622 break;
tecnosys 0:a14eaa2e1445 623 printf("%d: %s\n",i,s);
tecnosys 0:a14eaa2e1445 624 }
tecnosys 0:a14eaa2e1445 625
tecnosys 0:a14eaa2e1445 626 switch (interfaceDesc->bInterfaceClass)
tecnosys 0:a14eaa2e1445 627 {
tecnosys 0:a14eaa2e1445 628 case CLASS_MASS_STORAGE:
tecnosys 0:a14eaa2e1445 629 if (interfaceDesc->bInterfaceSubClass == 0x06 && interfaceDesc->bInterfaceProtocol == 0x50)
tecnosys 0:a14eaa2e1445 630 OnDiskInsert(device); // it's SCSI!
tecnosys 0:a14eaa2e1445 631 break;
tecnosys 0:a14eaa2e1445 632 case CLASS_WIRELESS_CONTROLLER:
tecnosys 0:a14eaa2e1445 633 if (interfaceDesc->bInterfaceSubClass == 0x01 && interfaceDesc->bInterfaceProtocol == 0x01)
tecnosys 0:a14eaa2e1445 634 OnBluetoothInsert(device); // it's bluetooth!
tecnosys 0:a14eaa2e1445 635 break;
tecnosys 0:a14eaa2e1445 636 case CLASS_VENDOR_SPECIFIC:
tecnosys 0:a14eaa2e1445 637 //Silicon Labs CP210x
tecnosys 0:a14eaa2e1445 638 if (interfaceDesc->bInterfaceSubClass == 0x00 && interfaceDesc->bInterfaceProtocol == 0x00) {
tecnosys 0:a14eaa2e1445 639 OnCP210xInsert(device);
tecnosys 0:a14eaa2e1445 640
tecnosys 0:a14eaa2e1445 641 }
tecnosys 0:a14eaa2e1445 642 //FTDI Serial
tecnosys 0:a14eaa2e1445 643 if (interfaceDesc->bInterfaceSubClass == 0xFF && interfaceDesc->bInterfaceProtocol == 0xFF)
tecnosys 0:a14eaa2e1445 644 OnFTDIInsert(device);
tecnosys 0:a14eaa2e1445 645 break;
tecnosys 0:a14eaa2e1445 646 default:
tecnosys 0:a14eaa2e1445 647 StartAutoEvent(device,1,0);
tecnosys 0:a14eaa2e1445 648 break;
tecnosys 0:a14eaa2e1445 649 }
tecnosys 0:a14eaa2e1445 650 }