This example demonstrates the reading of the USB Gamepad in the Nucleo.
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
This circuit diagram was created by fritzing.
USB con. | Nucleo |
---|---|
GND | GND |
+ | PA_12 |
- | PA_11 |
5V | 5V |
Original Library
- F401RE-USBHost by Norimasa Okamoto
- USBHostGamepad by Yuuichi Akagawa
USBHost/mymap.h
- Committer:
- beaglescout007
- Date:
- 2016-03-15
- Revision:
- 0:b5f79b4f741d
File content as of revision 0:b5f79b4f741d:
#pragma once template<class K,class T> class mymap { struct mypair { K first; T second; }; public: mymap() { m_size = 0; } T& operator[](const K& key) { int it; if (count(key) == 0) { it = insert(key, 0); } else { it = find(key); } return m_buf[it].second; } bool empty() { return m_size == 0 ? true : false; } int size() { return m_size; } void clear() { m_size = 0; } int count(K key) { for(int i = 0; i < m_size; i++) { if (m_buf[i].first == key) { return 1; } } return 0; } private: int find(K key) { for(int i = 0; i < m_size; i++) { if (m_buf[i].first == key) { return i; } } return -1; } int insert(K key, T value) { int it = find(key); if (it != -1) { m_buf[it].second = value; return it; } mypair* new_buf = new mypair[m_size+1]; if (m_size > 0) { for(int i = 0; i < m_size; i++) { new_buf[i] = m_buf[i]; } delete[] m_buf; } m_buf = new_buf; it = m_size++; m_buf[it].first = key; m_buf[it].second = value; return it; } int m_size; mypair *m_buf; };