Page 2 of 3

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Thu Jun 29, 2023 9:02 am
by wayland
Excellent teamwork Rob.
Do you know how this can be fed back into Lee Smith's Github? He supports a number of home computer keyboards but obviously missing the Dragon and CoCo.

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Thu Jun 29, 2023 9:11 am
by robcfg
Yep, I'll try a CoCo keyboard and then make a pull request with the files for his repository.

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Thu Jun 29, 2023 9:42 am
by robcfg
Oh, I found that the XRoar mapping is also valid for MAME! :mrgreen:

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Thu Jun 29, 2023 10:02 am
by sixxie
I'd probably like to try this some time (though working Dragon keyboards are currently a little thin on the ground around here - that damn ribbon cable likes to break).

Would mapping left arrow to backspace and right arrow to tab make it more usable outside of emulation while still preserving its behaviour inside?

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Thu Jun 29, 2023 10:27 am
by robcfg
I have an alternative configuration more suitable to use with a regular PC/Mac (it's just 2-3 keys that have a different meaning).

Maybe assigning BACKSPACE to the CLEAR key (instead of being HOME) would be a good idea, but losing the cursors not that much.

Here's the alternative mapping, just change KC.HOME for KC.BKSP:

Code: Select all

# Dragon 32/64 Keyboard to USB Keyboard suitable for XRoar with translate OFF
#	Wayland, Robcfg
#
# Uses KMK Librarys for PI Pico.
# Uses Lee Smith's C64 PCB layout https://github.com/midicdj1000/RETRO-PICO-KMK-Keyboards
#
# The symbol keys do not actually return what's printed on them except in XRoar 
# which knows what they are supposed to do on the Dragon.
# 2023/04/15 Mostly working. Problems with some symbols, £ @ * =
# 2023/04/16 Works with XRoar. Everything except @ which comes out as "
# 2023/04/18 Finished for XRoar. All keys working.
# 2023/06/29 Modified config so that it works with all keyboards and doesn't need
#            to modify XRoar's config to get the @ symbol.

import board

from kmk.kmk_keyboard import KMKKeyboard
from kmk.keys import KC
from kmk.scanners import DiodeOrientation
from kmk.modules.layers import Layers


print("Starting")
keyboard = KMKKeyboard()
keyboard.modules.append(Layers())
#C64 pcb
keyboard.debug_enabled = True
keyboard.col_pins = (
 board.GP8 ,#9
 board.GP9 ,#10
 board.GP10,#11
 board.GP11,#13
 board.GP12,#12
 board.GP13,#14
 board.GP14,#15
 board.GP15,#16
)
keyboard.row_pins = (
  board.GP26,#1
  board.GP22,#2
  # Note: Pin #3 is not assigned as it's the GND pin
  board.GP20,#4
  board.GP16,#5
  board.GP17,#6
  board.GP18,#7
  board.GP19,#8
)

keyboard.diode_orientation = DiodeOrientation.COL2ROW

#   Dragon 32/64 Matrix from Dragon schematic
#
#          LSB              $FF02                    MSB
#        | PB0   PB1   PB2   PB3   PB4   PB5   PB6   PB7 <- column
#    ----|----------------------------------------------
#    PA0 |   0     1     2     3     4     5     6     7    LSB
#    PA1 |   8     9     :     ;     ,     -     .     /     $
#    PA2 |   @     A     B     C     D     E     F     G     F
#    PA3 |   H     I     J     K     L     M     N     O     F
#    PA4 |   P     Q     R     S     T     U     V     W     0
#    PA5 |   X     Y     Z    Up  Down  Left Right Space     0
#    PA6 | ENT   CLR   BRK   N/C   N/C   N/C   N/C  SHFT
#     ^
#     |
#    row

# PC keymap
keyboard.keymap = [
    [ KC.N0,  KC.N1,   KC.N2,   KC.N3,   KC.N4,   KC.N5,   KC.N6,   KC.N7, 
      KC.N8,  KC.N9,   KC.COLN, KC.SCLN, KC.COMM, KC.MINS, KC.DOT,  KC.SLSH, 
      KC.AT,  KC.A,    KC.B,    KC.C,    KC.D,    KC.E,    KC.F,    KC.G, 
      KC.H,   KC.I,    KC.J,    KC.K,    KC.L,    KC.M,    KC.N,    KC.O, 
      KC.P,   KC.Q,    KC.R,    KC.S,    KC.T,    KC.U,    KC.V,    KC.W, 
      KC.X,   KC.Y,    KC.Z,    KC.UP,   KC.DOWN, KC.LEFT ,KC.RIGHT,KC.SPC, 
      KC.ENT, KC.HOME, KC.ESC,  KC.NO,   KC.NO,   KC.NO,   KC.NO,   KC.LSFT
    ]
]

if __name__ == '__main__':
    keyboard.go()

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Thu Jun 29, 2023 12:31 pm
by wayland
If you study the KMK libraries there are ways of selecting from different key actions like using an ALT key. I did not get into that and massively simplified the code for the Dragon keyboard. However you have a whole empty row you could add a button or a selector switch to direct KMK to an alternative keymap array. This is all part of KMK and only requires adding extra sections to keyboard.keymap array.

It could be done with a selector knob that you simply point to the keyboard style you want. Or getting really fancy a key combination on the Dragon keyboard itself to change modes.

My aim was simply to use a Dragon keyboard with XRoar so I could fit a Raspberry PI or laptop motherboard inside my broken Dragon.

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Thu Jun 29, 2023 12:47 pm
by sixxie
wayland wrote: Thu Jun 29, 2023 12:31 pm My aim was simply to use a Dragon keyboard with XRoar so I could fit a Raspberry PI or laptop motherboard inside my broken Dragon.
Are you going to fit a pushbutton through this that simulates pressing Control+R? :)

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Thu Jun 29, 2023 10:53 pm
by wayland
Sorry I'm not with it. What's Control R?

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Fri Jun 30, 2023 8:28 am
by sixxie
soft reset in xroar - so you'd have a reset button too

Re: Dragon keyboard conversion to USB HID (XRoar)

Posted: Fri Jun 30, 2023 4:09 pm
by robcfg
I've edited my posts with the keyboard configurations with the latest version, which is cleaner.

Also a pull request is on the way to the original repository: https://github.com/midicdj1000/RETRO-PI ... rds/pull/2