I have ported my old project “pNesX” game console emulator to the nucleo.
Dependencies:
SDFileSystem
mbed
Intro
I have ported my old project “pNesX” to the STM32 Nucleo.
The pNesX is a NES emulator for the PlayStation that I have created 16 years ago!
Emulation part was almost without change, the sound part was newly added.
Parts
STM32 Nucleo F446RE
QVGA 2.2 TFT SPI (with the SD card slot)
Audio jack(TS or TRS)
USB Connector
Register 100k, 10k, 4.7k, 100
Capacitor 0.01uF, 2.2uF
Breadboard
Wires
Computer Speakers
USB GamePad
Wiring diagram
TFT J2 Nucleo
VCC 3V3
GND GND
CS PB_5(D4)
Reset PA_10(D2) Pull Up(100k)
D/C PA_8(D7)
MOSI PA_7(D11)
SCK PA_5(D13)
LED LED-100ohm-3V3
MISO PA_6(D12)
TFT J4 Nucleo
SD_CS PA_9
SD_MOSI PB_15
SD_MISO PB_14
SD_SCK PB_13
USB con. Nucleo
GND GND
+ PA_12
- PA_11
5V 5V
VIDEO
https://youtu.be/jL24IjT6LnI
Limitations
Since the rest of the RAM is about 50kbyte, maximum capacity of the game ROM is about 50kbyte.
The length of the file name up to 32 characters.
The number of files in the folder is up to 100.
Used Library
USBHost/USBHostGamepad.h@0:3dac1f1bc9e0, 2016-04-03 (annotated)
Committer:
beaglescout007
Date:
Sun Apr 03 07:45:29 2016 +0000
Revision:
0:3dac1f1bc9e0
Release
Who changed what in which revision?
User Revision Line number New contents of line
beaglescout007
0:3dac1f1bc9e0
1
/*
beaglescout007
0:3dac1f1bc9e0
2
* modified from
beaglescout007
0:3dac1f1bc9e0
3
* mbed USBHost Gamepad driver sample
beaglescout007
0:3dac1f1bc9e0
4
* Copyright (c) 2014 Yuuichi Akagawa
beaglescout007
0:3dac1f1bc9e0
5
*
beaglescout007
0:3dac1f1bc9e0
6
* modified from mbed USBHostMouse
beaglescout007
0:3dac1f1bc9e0
7
*
beaglescout007
0:3dac1f1bc9e0
8
* Copyright (c) 2014 mbed.org, MIT License
beaglescout007
0:3dac1f1bc9e0
9
*
beaglescout007
0:3dac1f1bc9e0
10
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
beaglescout007
0:3dac1f1bc9e0
11
* and associated documentation files (the "Software"), to deal in the Software without
beaglescout007
0:3dac1f1bc9e0
12
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
beaglescout007
0:3dac1f1bc9e0
13
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
beaglescout007
0:3dac1f1bc9e0
14
* Software is furnished to do so, subject to the following conditions:
beaglescout007
0:3dac1f1bc9e0
15
*
beaglescout007
0:3dac1f1bc9e0
16
* The above copyright notice and this permission notice shall be included in all copies or
beaglescout007
0:3dac1f1bc9e0
17
* substantial portions of the Software.
beaglescout007
0:3dac1f1bc9e0
18
*
beaglescout007
0:3dac1f1bc9e0
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
beaglescout007
0:3dac1f1bc9e0
20
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
beaglescout007
0:3dac1f1bc9e0
21
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
beaglescout007
0:3dac1f1bc9e0
22
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
beaglescout007
0:3dac1f1bc9e0
23
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
beaglescout007
0:3dac1f1bc9e0
24
*/
beaglescout007
0:3dac1f1bc9e0
25
beaglescout007
0:3dac1f1bc9e0
26
#ifndef USBHOSTGAMEPAD_H
beaglescout007
0:3dac1f1bc9e0
27
#define USBHOSTGAMEPAD_H
beaglescout007
0:3dac1f1bc9e0
28
beaglescout007
0:3dac1f1bc9e0
29
#include "USBHostConf.h"
beaglescout007
0:3dac1f1bc9e0
30
beaglescout007
0:3dac1f1bc9e0
31
//#if USBHOST_GAMEPAD
beaglescout007
0:3dac1f1bc9e0
32
beaglescout007
0:3dac1f1bc9e0
33
#include "USBHost.h"
beaglescout007
0:3dac1f1bc9e0
34
//HID Class Request
beaglescout007
0:3dac1f1bc9e0
35
#define HID_GET_REPORT 0x01
beaglescout007
0:3dac1f1bc9e0
36
#define HID_GET_IDLE 0x02
beaglescout007
0:3dac1f1bc9e0
37
#define HID_GET_PROTOCOL 0x03
beaglescout007
0:3dac1f1bc9e0
38
#define HID_GET_DESCRIPTOR 0x06
beaglescout007
0:3dac1f1bc9e0
39
#define HID_SET_REPORT 0x09
beaglescout007
0:3dac1f1bc9e0
40
#define HID_SET_IDLE 0x0a
beaglescout007
0:3dac1f1bc9e0
41
#define HID_SET_PROTOCOL 0x0b
beaglescout007
0:3dac1f1bc9e0
42
beaglescout007
0:3dac1f1bc9e0
43
/**
beaglescout007
0:3dac1f1bc9e0
44
* A class to communicate a USB MIDI device
beaglescout007
0:3dac1f1bc9e0
45
*/
beaglescout007
0:3dac1f1bc9e0
46
class USBHostGamepad : public IUSBEnumerator {
beaglescout007
0:3dac1f1bc9e0
47
public:
beaglescout007
0:3dac1f1bc9e0
48
/**
beaglescout007
0:3dac1f1bc9e0
49
* Constructor
beaglescout007
0:3dac1f1bc9e0
50
*/
beaglescout007
0:3dac1f1bc9e0
51
USBHostGamepad();
beaglescout007
0:3dac1f1bc9e0
52
beaglescout007
0:3dac1f1bc9e0
53
/**
beaglescout007
0:3dac1f1bc9e0
54
* Try to connect a gamepad device
beaglescout007
0:3dac1f1bc9e0
55
*
beaglescout007
0:3dac1f1bc9e0
56
* @return true if connection was successful
beaglescout007
0:3dac1f1bc9e0
57
*/
beaglescout007
0:3dac1f1bc9e0
58
bool connect();
beaglescout007
0:3dac1f1bc9e0
59
beaglescout007
0:3dac1f1bc9e0
60
/**
beaglescout007
0:3dac1f1bc9e0
61
* Check if a gamepad is connected
beaglescout007
0:3dac1f1bc9e0
62
*
beaglescout007
0:3dac1f1bc9e0
63
* @returns true if a gamepad is connected
beaglescout007
0:3dac1f1bc9e0
64
*/
beaglescout007
0:3dac1f1bc9e0
65
bool connected();
beaglescout007
0:3dac1f1bc9e0
66
beaglescout007
0:3dac1f1bc9e0
67
uint8_t report[8]; /* modified 2016 Racoon */
beaglescout007
0:3dac1f1bc9e0
68
int rxSize;
beaglescout007
0:3dac1f1bc9e0
69
beaglescout007
0:3dac1f1bc9e0
70
protected:
beaglescout007
0:3dac1f1bc9e0
71
//From IUSBEnumerator
beaglescout007
0:3dac1f1bc9e0
72
virtual void setVidPid(uint16_t vid, uint16_t pid);
beaglescout007
0:3dac1f1bc9e0
73
virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
beaglescout007
0:3dac1f1bc9e0
74
virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
beaglescout007
0:3dac1f1bc9e0
75
beaglescout007
0:3dac1f1bc9e0
76
private:
beaglescout007
0:3dac1f1bc9e0
77
USBHost * host;
beaglescout007
0:3dac1f1bc9e0
78
USBDeviceConnected * dev;
beaglescout007
0:3dac1f1bc9e0
79
USBEndpoint * int_in;
beaglescout007
0:3dac1f1bc9e0
80
beaglescout007
0:3dac1f1bc9e0
81
bool dev_connected;
beaglescout007
0:3dac1f1bc9e0
82
bool gamepad_device_found;
beaglescout007
0:3dac1f1bc9e0
83
int gamepad_intf;
beaglescout007
0:3dac1f1bc9e0
84
beaglescout007
0:3dac1f1bc9e0
85
void rxHandler();
beaglescout007
0:3dac1f1bc9e0
86
void init();
beaglescout007
0:3dac1f1bc9e0
87
};
beaglescout007
0:3dac1f1bc9e0
88
beaglescout007
0:3dac1f1bc9e0
89
#endif
beaglescout007
0:3dac1f1bc9e0
90