Skip to content

piotr-wiszowaty/db9_usb_adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DB9-USB-adapter

Adapter for connecting USB joystick/gamepad to DB9 joystick connector found in Atari, Commodore and Amiga computers.

Joystick/gamepad usage

Plug USB joystick or gamepad into adapter's USB socket, plug the adapter into an Atari/Commodore/Amiga computer's joystick port and turn on the computer. The yellow LED (D1) should turn on indicating successful joystick/gamepad recognition. At this point you can use the (USB) joystick/gamepad as you would a plain DB9 one.

If the joystick/gamepad is recognized but does not work out-of-the-box as expected you can write a custom joystick descriptor (see below).

Custom joystick descriptors

Overview

Custom joystick descriptor is a set of 'instructions' telling the adapter how to handle USB HID reports of a specific joystick/gamepad.

Data required to write a descriptor is transmitted through adapter's UART connector (3.3 V TTL logic, 38400 baud). You can also use a software tool and a computer with USB port to display USB HID reports generated by a joystick/gamepad.

Data sent through UART - example session

In the following example there are messages showing enumerated device's vendor identifier, product identifier (the second - final pair counts) and HID reports consisting of report identifier (here: 0000) and report data (in square brackets). The numbers in parenthesis at line ends are not sent.

I:reset                                 (1)
I:VID:PID 054C:0268                     (2)
I:VID:PID 0E8F:0003                     (3)
I:report:0000[80 80 80 80 00 0F 00 00]  (4) 
I:report:0000[80 80 80 80 00 00 00 01]  (5) 
I:report:0000[80 80 80 80 00 0F 00 00]  (6) 
I:report:0000[80 80 80 80 00 04 00 04]  (7) 
I:report:0000[80 80 80 80 00 0F 00 00]  (8) 
I:report:0000[80 80 80 80 00 06 00 08]  (9) 
I:report:0000[80 80 80 80 00 0F 00 00]  (10)
I:report:0000[80 80 80 80 00 02 00 02]  (11)
I:report:0000[80 80 80 80 00 0F 00 00]  (12)
I:report:0000[80 80 80 80 00 0F 01 00]  (13)
I:report:0000[80 80 80 80 00 0F 00 00]  (14)

Line descriptions:

  1. reset/power-up indicator
  2. device enumerated with VID:PID equal to 054C:0268
  3. device enumerated with VID:PID equal to 0E8F:0003
  4. idle state
  5. forward pressed
  6. forward released
  7. backward pressed
  8. backward released
  9. left pressed
  10. left released
  11. right pressed
  12. right released
  13. fire button 1 pressed
  14. fire button 5 released

Loading joystick descriptors into adapter's flash memory

Convert descriptor from text to binary form and write it to a FAT32-formatted pendrive. Target file must be named db9usb.dat. Example:

$ python tools/convert_descriptor.py data/db9usb.conf > /mnt/pendrive/db9usb.dat

Plug the pendrive into adapter's USB connector and adapter into a computer's joystick port. Turn on the computer. Wait until yellow LED (D1) and red LED (D2) turn on - this indicates the pendrive is recognized and the descriptor is loaded into adapter's flash memory.

Descriptor syntax

Descriptor file contains one or more descriptors. Lines starting with a # are ignored. BYTE is a 2-digit hexadecimal number, WORD - 4-digit hexadecimal number. Each of the actions (left, right, forward, backward or fire) is triggered when HID report data at offset masked with mask is equal/not equal to value.

descriptor ::= vid_pid report_id control+
vid_pid ::= 'vid:pid' vid ':' pid '\n'
'report_id' BYTE '\n'
vid ::= WORD
pid ::= WORD
control ::= action '[' offset ']' '&' mask operator value '\n'
action ::= 'left' | 'right' | 'forward' | 'backward' | 'fire'
offset ::= BYTE
mask ::= BYTE
operator ::= '==' | '!='
value ::= BYTE

Example descriptor

# GreenAsia Inc. USB Joystick aka. Sony Corp. Batoh Device / PlayStation 3 Controller
vid:pid 0e8f:0003
report_id 00
left     [7] & 0f = 08
right    [7] & 0f = 02
forward  [7] & 0f = 01
backward [7] & 0f = 04
fire     [5] & f0 != 00
fire     [6] & 0f != 00

Development

MPLABX settings

Microcontroller: PIC32MX250F128D

Include paths:

  • inc
  • <libraries-for-applications-2013-06-15>/Microchip/Include
  • <libraries-for-applications-2013-06-15>/Microchip/Include/MDD File System
  • <libraries-for-applications-2013-06-15>/Microchip/USB

Heap size: 8192

Files to be copied from libraries for applications 2013-06-15

  • USB/usb_host.c
  • USB/usb_host_hid.c
  • USB/usb_host_hid_parser.c
  • USB/usb_host_msd.c
  • USB/usb_host_msd_scsi.c
  • MDD File System/FSIO.c

Releases

No releases published

Packages

No packages published

Languages