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 #pragma once
beaglescout007 0:b5f79b4f741d 2
beaglescout007 0:b5f79b4f741d 3 template<class K,class T>
beaglescout007 0:b5f79b4f741d 4 class mymap {
beaglescout007 0:b5f79b4f741d 5 struct mypair {
beaglescout007 0:b5f79b4f741d 6 K first;
beaglescout007 0:b5f79b4f741d 7 T second;
beaglescout007 0:b5f79b4f741d 8 };
beaglescout007 0:b5f79b4f741d 9 public:
beaglescout007 0:b5f79b4f741d 10 mymap() {
beaglescout007 0:b5f79b4f741d 11 m_size = 0;
beaglescout007 0:b5f79b4f741d 12 }
beaglescout007 0:b5f79b4f741d 13 T& operator[](const K& key) {
beaglescout007 0:b5f79b4f741d 14 int it;
beaglescout007 0:b5f79b4f741d 15 if (count(key) == 0) {
beaglescout007 0:b5f79b4f741d 16 it = insert(key, 0);
beaglescout007 0:b5f79b4f741d 17 } else {
beaglescout007 0:b5f79b4f741d 18 it = find(key);
beaglescout007 0:b5f79b4f741d 19 }
beaglescout007 0:b5f79b4f741d 20 return m_buf[it].second;
beaglescout007 0:b5f79b4f741d 21 }
beaglescout007 0:b5f79b4f741d 22 bool empty() { return m_size == 0 ? true : false; }
beaglescout007 0:b5f79b4f741d 23 int size() { return m_size; }
beaglescout007 0:b5f79b4f741d 24 void clear() { m_size = 0; }
beaglescout007 0:b5f79b4f741d 25 int count(K key) {
beaglescout007 0:b5f79b4f741d 26 for(int i = 0; i < m_size; i++) {
beaglescout007 0:b5f79b4f741d 27 if (m_buf[i].first == key) {
beaglescout007 0:b5f79b4f741d 28 return 1;
beaglescout007 0:b5f79b4f741d 29 }
beaglescout007 0:b5f79b4f741d 30 }
beaglescout007 0:b5f79b4f741d 31 return 0;
beaglescout007 0:b5f79b4f741d 32 }
beaglescout007 0:b5f79b4f741d 33
beaglescout007 0:b5f79b4f741d 34 private:
beaglescout007 0:b5f79b4f741d 35 int find(K key) {
beaglescout007 0:b5f79b4f741d 36 for(int i = 0; i < m_size; i++) {
beaglescout007 0:b5f79b4f741d 37 if (m_buf[i].first == key) {
beaglescout007 0:b5f79b4f741d 38 return i;
beaglescout007 0:b5f79b4f741d 39 }
beaglescout007 0:b5f79b4f741d 40 }
beaglescout007 0:b5f79b4f741d 41 return -1;
beaglescout007 0:b5f79b4f741d 42 }
beaglescout007 0:b5f79b4f741d 43 int insert(K key, T value) {
beaglescout007 0:b5f79b4f741d 44 int it = find(key);
beaglescout007 0:b5f79b4f741d 45 if (it != -1) {
beaglescout007 0:b5f79b4f741d 46 m_buf[it].second = value;
beaglescout007 0:b5f79b4f741d 47 return it;
beaglescout007 0:b5f79b4f741d 48 }
beaglescout007 0:b5f79b4f741d 49 mypair* new_buf = new mypair[m_size+1];
beaglescout007 0:b5f79b4f741d 50 if (m_size > 0) {
beaglescout007 0:b5f79b4f741d 51 for(int i = 0; i < m_size; i++) {
beaglescout007 0:b5f79b4f741d 52 new_buf[i] = m_buf[i];
beaglescout007 0:b5f79b4f741d 53 }
beaglescout007 0:b5f79b4f741d 54 delete[] m_buf;
beaglescout007 0:b5f79b4f741d 55 }
beaglescout007 0:b5f79b4f741d 56 m_buf = new_buf;
beaglescout007 0:b5f79b4f741d 57 it = m_size++;
beaglescout007 0:b5f79b4f741d 58 m_buf[it].first = key;
beaglescout007 0:b5f79b4f741d 59 m_buf[it].second = value;
beaglescout007 0:b5f79b4f741d 60 return it;
beaglescout007 0:b5f79b4f741d 61 }
beaglescout007 0:b5f79b4f741d 62
beaglescout007 0:b5f79b4f741d 63 int m_size;
beaglescout007 0:b5f79b4f741d 64 mypair *m_buf;
beaglescout007 0:b5f79b4f741d 65 };
beaglescout007 0:b5f79b4f741d 66