speccery Posted July 19, 2022 Share Posted July 19, 2022 I have had for a while the desire to use an external keyboard with the TI, mainly to have more flexibility on my desk where to place the console. For the display I'm already using F18A board connected to VGA-to-HDMI converter connected to a USB3 HDMI grabber, so the TI's screen is visible as a Window on my Mac's desktop. If I had something similar for the keyboard, I could move the TI to the side, and just control it from my Mac's keyboard. There are existing great projects by @jedimatt42 and @Tursi to use USB or PS/2 keyboards with the TI. The TI99USBKeys USB host project is very desirable, but don't have a Teensy 3.1 or 3.2 board, and when searching for those I didn't find the boards anywhere available for purchase. I started thinking that even if I had that, I would end up having another USB keyboard on my desk to control the TI. So I thought I actually want something simpler, just a way to transfer keyboard information from my Mac to the TI. I also thought that since I already have many (and I mean many, I have lost count ages ago) development boards already, why not use something that I already have. I build a contraption which consists of a Nucleo-F767 board inside the TI, connected via USB to my Mac. This board connects to the keyboard connector of the TI, and basically just receives key codes from the Mac and presents them to the TI the way it understands them. Unlike many of my other projects, this one is simple, straightforward and started to work quickly. I initially controlled the keyboard with a simple terminal emulator program running on the Mac, but I quickly ran into problems. It was difficult to support shift keys and the like using a terminal program. Also key-up events don't exist with a normal terminal program... To remedy this I ditched the terminal program and wrote quickly a small app in C++ using the SDL2 framework for the Mac. This app just listens to keyboard presses and sends key up and key down events to the Nucleo board. Of course this meant developing yet another simple communication protocol... SDL2 is cross platform, so it would be easy to port the program to other operating systems. The key transfer protocol is very simple, and consists of two byte messages sent over USB serial port at 115200 bps: // My command codes. Transfer format contains two bytes: // one of the below, followed by the keycode. #define SERIAL_KEYDOWN '1' #define SERIAL_KEYUP '0' #define SERIAL_ALLUP '2' // The keycodes following the command code above: // These are mostly just ASCII codes, except for certain keys listed below. // TI specific keycodes for a few keys, selected not to collide with SDL key codes // used here. #define TI_SHIFT SDL_SCANCODE_LSHIFT // 225 #define TI_ALPHA_LOCK SDL_SCANCODE_CAPSLOCK // 57 #define TI_CTRL SDL_SCANCODE_LCTRL // 224 #define TI_FCTN SDL_SCANCODE_LALT // 226 #define TI_LEFT 128 #define TI_RIGHT 129 #define TI_UP 130 #define TI_DOWN 131 I haven't had yet much time to use setup, but it seems to work and is very convenient to use just one (did I say modern) keyboard to control both the Mac and the TI. I mapped the ESCape key to signal that all keys are forced up, to overcome issues where there might be a stuck key. It can happen when switching apps on the Mac with option-TAB. The Nucleo-F767 board is very powerful and huge overkill for this task. I chose it because among the development boards I have, it has very many 5V tolerant pins and it has an USB-to-go port. I am not using that port yet, but using it the board can support directly connected USB keyboards too, and STmicro has an example program which has the HID driver to be an USB host. I did try out that example, but I haven't integrated it and I am not sure if I will do that since for my use case this setup already works. 14 Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.