USB to quadrature encoder so you use modern USB mice on the Amiga.

Dependencies:   USBHOST

Introduction

This project is devised so you can attach a mouse (and/or steam controller) to a classic computer such as an Amiga. Computers of that era use bus mice which just send the pulses from the quadrature encoder wheels on the mouse directly to the computer with out interpretation.

Use

Program a build base on this repository to a STM32 nucleo board (I tested this on a NUCLEO STM32F411 board). You will then need connect the Nucleo board to your computers joystick and mouse ports as follows (if you only use a mouse you won't need a joystick lead :) ). If you use a steam controller the thumb stick and left pad are mapped to the Amiga's joystick port and the right pad and front trigger buttons are mapped to the mouse.

mouse_port_forward(D10) - Amiga Joystick pin 1
mouse_port_back(D11) - Amiga Joystick pin 2
mouse_port_left(D12) - Amiga Joystick pin 3
mouse_port_right(D13) - Amiga Joystick pin 4
mouse_port_left_button(D9) - Amiga Joystick pin 6
GND - Amiga joystick pin 8
mouse_port_right_button(D8) - Amiga Joystick pin 9

game_port_forward(PC_8) - Amiga Joystick pin 1
game_port_back(PC_12) - Amiga Joystick pin 2
game_port_left(PC_10) - Amiga Joystick pin 3
game_port_right(PC_11) - Amiga Joystick pin 4
game_port_left_button(PC_6) - Amiga Joystick pin 6
GND - Amiga joystick pin 8
game_port_right_button(PC_5) - Amiga Joystick pin 9

It is best NOT to use the 5V pin from the Amiga's joystick port to power the nucleo board as the power suppled by the Amiga is limited!

You will also need to attach a USB socket to the nuclea board so you can use the Nucleo's usb OTG support.

(1) 5V     - 5v
(2) PA11 - Data-
(3) PA12 - Data+
(4) GND - GND

According to the usb spec it is required to attach a 15k ohm resistor between D-/+ and ground but it appears the USB host works fine without this.

NOTES:

  • The right touch pad can take a little while before it generates mouse events.
  • I found that the STM USBHost library needed some modifications to correctly work with boot protocol (it needs to call set protocol) and hubs (getSize doesn't report the correct size). This project uses a modified USB host library with fixes for this (they will need a little more work before I can create a pull request).
Revision:
1:ab916b5c1a4d
Parent:
0:d0c521cb6c90
Child:
2:095eb20f0d3b
--- a/main.cpp	Thu Aug 17 22:13:12 2017 +0000
+++ b/main.cpp	Sat Aug 19 19:48:20 2017 +0000
@@ -2,11 +2,12 @@
 #include "USBHostMSD.h"
 #include "USBHostMouse.h"
 #include "USBHostKeyboard.h"
+#include "USBHostSteamController.h"
 #include "FATFileSystem.h"
 #include <stdlib.h>
 
-int x_cur;   
-int y_cur;
+int x_cur = 0;   
+int y_cur = 0;
 
 DigitalOut led(LED1);
 DigitalOut led2(LED2);
@@ -14,7 +15,7 @@
 DigitalOut led4(A0);
 
 
-void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) {
+void onMouseEvent(uint8_t buttons, int16_t x, int16_t y, int8_t z) {
     //printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
     
     led = buttons & 1;
@@ -56,6 +57,15 @@
         Thread::wait(1);
     }
 }
+
+void onJSEvent(uint32_t buttons, int8_t x, int8_t y, int16_t x_b, int16_t y_b) {
+    //printf("buttons: %x, x: %d, y: %d, x_b: %d y_b:%d\r\n", buttons, x, y, x_b, y_b);
+    
+    led = buttons & 1;
+    led4 = buttons & 0x2;
+         
+    Thread::wait(1);
+}
  
 void mouse_task(void const *) {
 
@@ -97,6 +107,24 @@
     }
 }
 
+void steamctrl_task(void const *) {
+    
+    USBHostSteamController steam_controller;
+    
+    while(1) {
+        // try to connect a USB keyboard
+        while(!steam_controller.connect())
+            Thread::wait(500);
+    
+        // when connected, attach handler called on keyboard event
+        steam_controller.attachEvent(onJSEvent);
+        
+        // wait until the keyboard is disconnected
+        while(steam_controller.connected())
+            Thread::wait(500);
+    }
+}
+
 
 
 void msd_task(void const *) {
@@ -153,7 +181,8 @@
 int main() {
     Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4);
     Thread mouseTask(mouse_task, NULL, osPriorityNormal, 1024* 4);
-    Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 1024 * 4);
+    Thread steamctrlTask(steamctrl_task, NULL, osPriorityNormal, 1024* 4);
+    //Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 1024 * 4);
     
     int x,y = 0;
     for(y=-10; y<10; y++)