Skip to content
Permalink
Browse files

Initial release

  • Loading branch information...
bootsector committed May 13, 2019
0 parents commit 4cdca1f6c2f75824e9099c9ebfec4411b78a780e
Showing with 32,621 additions and 0 deletions.
  1. +15 −0 .gitignore
  2. +674 −0 LICENSE
  3. +41 −0 README.md
  4. BIN doc/rj45_output_cables.png
  5. BIN doc/stm8blue-pinout.png
  6. BIN doc/usbhost_mini_5v_mod.png
  7. +17 −0 firmware/.vscode/c_cpp_properties.json
  8. +7 −0 firmware/.vscode/settings.json
  9. +50 −0 firmware/Makefile
  10. +26 −0 firmware/bitwise.h
  11. +54 −0 firmware/delay.c
  12. +26 −0 firmware/delay.h
  13. +59 −0 firmware/main.c
  14. +192 −0 firmware/max3421e.c
  15. +130 −0 firmware/max3421e.h
  16. +113 −0 firmware/multiout.c
  17. +42 −0 firmware/multiout.h
  18. +106 −0 firmware/ps3virtuastick.c
  19. +61 −0 firmware/ps3virtuastick.h
  20. +136 −0 firmware/ps4usb.c
  21. +26 −0 firmware/ps4usb.h
  22. +86 −0 firmware/stm8s.h
  23. +116 −0 firmware/usb_in.c
  24. +44 −0 firmware/usb_in.h
  25. +215 −0 firmware/usb_in_detect.c
  26. +34 −0 firmware/usb_in_detect.h
  27. +536 −0 firmware/usbhost.c
  28. +106 −0 firmware/usbhost.h
  29. +26 −0 firmware/util.c
  30. +68 −0 firmware/util.h
  31. +93 −0 firmware/xbox360rcv.c
  32. +26 −0 firmware/xbox360rcv.h
  33. +120 −0 firmware/xbox360usb.c
  34. +59 −0 firmware/xbox360usb.h
  35. +43 −0 multi-out/3dopad.v
  36. +84 −0 multi-out/3dopad_tb.v
  37. +6 −0 multi-out/multi-out.jdi
  38. +30 −0 multi-out/multi-out.qpf
  39. +88 −0 multi-out/multi-out.qsf
  40. +107 −0 multi-out/multi-out.sdc
  41. +126 −0 multi-out/multiout.v
  42. +92 −0 multi-out/multiout_tb.v
  43. +50 −0 multi-out/shiftin.v
  44. +81 −0 multi-out/shiftin_tb.v
  45. +92 −0 multi-out/smdsixbutton.v
  46. +108 −0 multi-out/smdsixbutton_tb.v
  47. +7 −0 pcb/LICENSE
  48. +2,157 −0 pcb/neogeo2tg16_12.brd
  49. +7,865 −0 pcb/neogeo2tg16_12.sch
  50. BIN pcb/neogeo2tg16_12_gerber.zip
  51. +6,636 −0 pcb/usb2classic.brd
  52. +11,745 −0 pcb/usb2classic.sch
  53. BIN pcb/usb2classic_gerber.zip
@@ -0,0 +1,15 @@
.DS_Store
*.code-workspace
**/.vscode/ipch/*
**/.settings/*
*.asm
*.cdb
*.ihx
*.lk
*.lst
*.map
*.noi
*.rel
*.sym
*.rst
*.bin
674 LICENSE

Large diffs are not rendered by default.

@@ -0,0 +1,41 @@
# USB2Classic - USB controllers adapter for retro consoles!
(c) Bruno Freitas - 04/2019 - http://www.brunofreitas.com/

This project is Open Source (GPLv3) and Open Hardware (CC BY-SA 4.0)

I've bought some super-cheap STM8S 8-bit microcontroller based boards and I
was wondering what kind of cool project I could put them to use. I've mixed
it with an USB Host Mini 2.0 module a CPLD and some discrete components and
then the USB2Classic adapter was born!

This adapter allows you to use USB controllers with old consoles, such as:

* Sega Genesis / Mega Drive (can emulate either a 3 button or 6 button pad)
* Sega Master System, Atari 2600 and others
* Panasonic 3DO
* NES
* Super NES
* Sega Saturn
* Neo Geo
* TG16/PC-Engine (through adapter board connected to the Neo Geo output)

Currently compatible USB controllers are:

* Playstation 4 USB controller
* XBOX 360 USB controller (and compatible XInput devices)
* XBOX 360 USB Wireless Receiver
* 8BitDo Wireless USB Adapter (in XInput mode)
* Some PS3 USB arcade stick controllers

The CPLD originally used by this adapter is an EPM7064SLC44-10N which is 5V
based. Verilog sources are inside the multi-out directory along with Quartus II
project files.

The USB Host Mini board **MUST** be modified for 5V as shown in the
doc/usbhost_mini_5v_mod.png diagram.

Firmware was compiled using SDCC version 3.8.0

Thanks to Bruno Duarte Gouveia (brNX) for all the help with Verilog!

Enjoy!
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/Applications/sdcc-3.8.0/share/sdcc/include"
],
"defines": [],
"compilerPath": "/Applications/sdcc-3.8.0/bin/sdcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
@@ -0,0 +1,7 @@
{
"files.associations": {
"delay.h": "c",
"stm8s.h": "c",
"ps4usb.h": "c"
}
}
@@ -0,0 +1,50 @@
# USB2Classic - USB controllers adapter for retro consoles!
# Copyright (c) 2019 Bruno Freitas - bruno@brunofreitas.com

CC = sdcc
ASM = sdasstm8
OBJCOPY = sdobjcopy
RM = rm -f

DEVICE = stm8s103f3

TARGET = USB2CLASSIC

SRC_MAIN = main.c
SRC_OTHERS = delay.c util.c max3421e.c usbhost.c usb_in.c usb_in_detect.c \
ps4usb.c xbox360rcv.c xbox360usb.c ps3virtuastick.c multiout.c
SRC_ASM =

OBJ_OTHERS = $(SRC_OTHERS:%.c=%.rel)
OBJ_ASM = $(SRC_ASM:%.s=%.rel)

INCLUDE = -I .
PARAMS = -lstm8 -mstm8 --opt-code-size --std-sdcc11

all: sdccversion build

sdccversion:
@$(CC) -v

%.rel : %.c
${CC} -c ${INCLUDE} ${PARAMS} $< $(OBJ_ASM)

%.rel : %.s
${ASM} -l -o $<

$(TARGET).ihx: $(OBJ_ASM) $(OBJ_OTHERS)
${CC} ${SRC_MAIN} ${INCLUDE} ${PARAMS} ${OBJ_ASM} ${OBJ_OTHERS} --out-fmt-ihx -o ${TARGET}.ihx

$(TARGET).bin: $(TARGET).ihx
${OBJCOPY} -I ihex ${TARGET}.ihx -O binary ${TARGET}.bin

build: $(TARGET).ihx

flash: $(TARGET).ihx
stm8flash -c stlinkv2 -p ${DEVICE} -w $(TARGET).ihx

flash_unlock:
stm8flash -c stlinkv2 -p ${DEVICE} -u

clean:
${RM} *.asm *.cdb *.ihx *.lk *.lst *.map *.noi *.rel *.sym *.rst *.bin
@@ -0,0 +1,26 @@
/*
* USB2Classic - USB controllers adapter for retro consoles!
* Copyright (c) 2019 Bruno Freitas - bruno@brunofreitas.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BITWISE_H_
#define BITWISE_H_

#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &= ~(m))
#define bit_check(value, bit) (((value) >> (bit)) & 0x01)
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))

#endif /* BITWISE_H_ */
@@ -0,0 +1,54 @@
/*
* USB2Classic - USB controllers adapter for retro consoles!
* Copyright (c) 2019 Bruno Freitas - bruno@brunofreitas.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stm8s.h"
#include "delay.h"

/* Functions below assume a 16Mhz Clock */

void delay_us(uint16_t us) {
// Prescaler = 2^4: Increments at every 1uS
TIM2_PSCR = 0x04;

// Initialize counter
bit_set(TIM2_EGR, 1 << 0);

// Enable counter
bit_set(TIM2_CR1, 1 << 0);

// Wait until counter reaches requested us
while(TIM2_CNTR < us);
}

void delay_ms(uint16_t ms) {
// 125 times in 1ms
TIM2_PSCR = 0x07;

// Initialize counter
bit_set(TIM2_EGR, 1 << 0);

// Enable counter
bit_set(TIM2_CR1, 1 << 0);

while(ms > 0) {
while(TIM2_CNTR < 125);

TIM2_CNTR = 0;

ms--;
}
}
@@ -0,0 +1,26 @@
/*
* USB2Classic - USB controllers adapter for retro consoles!
* Copyright (c) 2019 Bruno Freitas - bruno@brunofreitas.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DELAY_H_
#define DELAY_H_

#include <stdint.h>

void delay_us(uint16_t us);
void delay_ms(uint16_t ms);

#endif /* DELAY_H_ */
@@ -0,0 +1,59 @@
/*
* USB2Classic - USB controllers adapter for retro consoles!
* Copyright (c) 2019 Bruno Freitas - bruno@brunofreitas.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stm8s.h"
#include "delay.h"
#include "usb_in.h"
#include "multiout.h"

static AbstractPad_t pad_data;

static void Set16MhzInternalClock() {
disableInterrupts();

CLK_ICKR = 0; // Reset the Internal Clock Register.
CLK_ICKR = 1 << 0; // Enable the HSI.

while (!(CLK_ICKR & (1 << 1))); // Wait for HSIRDY.

CLK_CKDIVR = 0; // Ensure the clocks are running at full speed.
CLK_SWR = 0xE1; // Use HSI as the clock source.
CLK_SWCR = 0; // Reset the clock switch control register.
CLK_SWCR = 1 << 1; // Enable switching.

while (CLK_SWCR & (1 << 0)); // Pause while the clock switch is busy.

enableInterrupts();
}

void main() {
/* Set internal clock to 16Mhz */
Set16MhzInternalClock();

/* Reset pad data buffer */
ResetBuffer(&pad_data);

/* Initialize USB input and serial output drivers */
usb_in_init();
multiout_init();

/* Main polling loop */
for(;;) {
usb_in_get_pad_state(&pad_data);
multiout_update(&pad_data);
}
}

0 comments on commit 4cdca1f

Please sign in to comment.
You can’t perform that action at this time.