This example demonstrates the reading of the USB Gamepad in the Nucleo.

Dependencies:   mbed

Intro

This example demonstrates the reading of the USB Gamepad in the Nucleo.

Parts

STM32 Nucleo F446RE
USB Connector
LED 2pcs
Register 470 ohm 2pcs
Breadboard
Wires

Wiring diagram

/media/uploads/beaglescout007/nucleo_ex04_usbpad.png This circuit diagram was created by fritzing.

/media/uploads/beaglescout007/usbcon.jpg

USB con.Nucleo
GNDGND
+PA_12
-PA_11
5V5V

https://youtu.be/EYIukjwJSew

Original Library

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 #include "USBDeviceConnected.h"
beaglescout007 0:b5f79b4f741d 18 #include "dbg.h"
beaglescout007 0:b5f79b4f741d 19
beaglescout007 0:b5f79b4f741d 20 USBDeviceConnected::USBDeviceConnected() {
beaglescout007 0:b5f79b4f741d 21 init();
beaglescout007 0:b5f79b4f741d 22 }
beaglescout007 0:b5f79b4f741d 23
beaglescout007 0:b5f79b4f741d 24 void USBDeviceConnected::init() {
beaglescout007 0:b5f79b4f741d 25 port = 0;
beaglescout007 0:b5f79b4f741d 26 vid = 0;
beaglescout007 0:b5f79b4f741d 27 pid = 0;
beaglescout007 0:b5f79b4f741d 28 nb_interf = 0;
beaglescout007 0:b5f79b4f741d 29 enumerated = false;
beaglescout007 0:b5f79b4f741d 30 device_class = 0;
beaglescout007 0:b5f79b4f741d 31 device_subclass = 0;
beaglescout007 0:b5f79b4f741d 32 proto = 0;
beaglescout007 0:b5f79b4f741d 33 lowSpeed = false;
beaglescout007 0:b5f79b4f741d 34 hub_parent = NULL;
beaglescout007 0:b5f79b4f741d 35 }
beaglescout007 0:b5f79b4f741d 36
beaglescout007 0:b5f79b4f741d 37 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
beaglescout007 0:b5f79b4f741d 38 USB_DBG("intf_nb=%d", intf_nb);
beaglescout007 0:b5f79b4f741d 39 if (intf.count(intf_nb) > 0) {
beaglescout007 0:b5f79b4f741d 40 return false;
beaglescout007 0:b5f79b4f741d 41 }
beaglescout007 0:b5f79b4f741d 42 intf[intf_nb] = new INTERFACE(intf_class, intf_subclass, intf_protocol);
beaglescout007 0:b5f79b4f741d 43 return true;
beaglescout007 0:b5f79b4f741d 44 }
beaglescout007 0:b5f79b4f741d 45
beaglescout007 0:b5f79b4f741d 46 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
beaglescout007 0:b5f79b4f741d 47 if (intf.count(intf_nb) > 0) {
beaglescout007 0:b5f79b4f741d 48 intf[intf_nb]->ep.push_back(ept);
beaglescout007 0:b5f79b4f741d 49 return true;
beaglescout007 0:b5f79b4f741d 50 }
beaglescout007 0:b5f79b4f741d 51 return false;
beaglescout007 0:b5f79b4f741d 52 }
beaglescout007 0:b5f79b4f741d 53
beaglescout007 0:b5f79b4f741d 54 void USBDeviceConnected::init(USBDeviceConnected* parent, uint8_t port_, bool lowSpeed_) {
beaglescout007 0:b5f79b4f741d 55 USB_DBG("init dev: %p", this);
beaglescout007 0:b5f79b4f741d 56 init();
beaglescout007 0:b5f79b4f741d 57 hub_parent = parent;
beaglescout007 0:b5f79b4f741d 58 port = port_;
beaglescout007 0:b5f79b4f741d 59 lowSpeed = lowSpeed_;
beaglescout007 0:b5f79b4f741d 60 }
beaglescout007 0:b5f79b4f741d 61
beaglescout007 0:b5f79b4f741d 62 void USBDeviceConnected::disconnect() {
beaglescout007 0:b5f79b4f741d 63 //for(int i = 0; i < MAX_INTF; i++) {
beaglescout007 0:b5f79b4f741d 64 // intf[i].detach.call();
beaglescout007 0:b5f79b4f741d 65 //}
beaglescout007 0:b5f79b4f741d 66 //init();
beaglescout007 0:b5f79b4f741d 67 }
beaglescout007 0:b5f79b4f741d 68
beaglescout007 0:b5f79b4f741d 69
beaglescout007 0:b5f79b4f741d 70 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
beaglescout007 0:b5f79b4f741d 71 USB_DBG("intf_nb=%d", intf_nb);
beaglescout007 0:b5f79b4f741d 72 USB_TEST_ASSERT(intf.count(intf_nb) > 0);
beaglescout007 0:b5f79b4f741d 73 INTERFACE* inter = intf[intf_nb];
beaglescout007 0:b5f79b4f741d 74 for (int i = 0; i < inter->ep.size(); i++) {
beaglescout007 0:b5f79b4f741d 75 if ((inter->ep[i]->getType() == type) && (inter->ep[i]->getDir() == dir)) {
beaglescout007 0:b5f79b4f741d 76 if(index) {
beaglescout007 0:b5f79b4f741d 77 index--;
beaglescout007 0:b5f79b4f741d 78 } else {
beaglescout007 0:b5f79b4f741d 79 return inter->ep[i];
beaglescout007 0:b5f79b4f741d 80 }
beaglescout007 0:b5f79b4f741d 81 }
beaglescout007 0:b5f79b4f741d 82 }
beaglescout007 0:b5f79b4f741d 83 return NULL;
beaglescout007 0:b5f79b4f741d 84 }
beaglescout007 0:b5f79b4f741d 85
beaglescout007 0:b5f79b4f741d 86 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
beaglescout007 0:b5f79b4f741d 87 USB_TEST_ASSERT(intf.count(intf_nb) > 0);
beaglescout007 0:b5f79b4f741d 88 return intf[intf_nb]->ep[index];
beaglescout007 0:b5f79b4f741d 89 }
beaglescout007 0:b5f79b4f741d 90