unified_retro_keyboard/firmware/asdf/README.md

238 lines
9.9 KiB
Markdown
Raw Permalink Normal View History

2022-09-08 02:56:24 +00:00
# ASDF Keyboard scanning firmware
2020-02-21 06:28:36 +00:00
This is a key matrix scanner that can detect and debounce keypress and release
events on a key matrix and either send codes or perform actions on keypress or
release. Keymaps are defined per application and may, for example, generate
ASCII codes, special keyscan codes, etc. The code is modular and may be
integrated into a larger system easily.
2019-12-12 20:46:29 +00:00
By default, the code supports any number of rows by 8 columns, which will give
the bestperformance on an 8-bit microcontroller. For more than 8 columns per
row, the row datatype would need to be changed to uint16_t to support 16
columns, etc.
The first supported application is a parallel ASCII output keyboard. If you want
serial or USB output, you can supply your own routines.
ASDF supports basic keyboard functionality and is configurable via a few
boolean variables, and via the key maps. The key maps are organized in
row,column format, with separate keymaps shift, capslock, and control-key modes.
2022-09-08 02:56:24 +00:00
## Downloads:
Download the latest release of the firmware [here](https://osiweb.github.io/unified_retro_keyboard)
## Features:
2022-09-08 03:22:51 +00:00
2019-12-12 20:46:29 +00:00
* modifiers: A set of modifier keys may be specified. When only a few modifiers
are used, this mechanism is a low-overhead alternative to a keymap overlay for
2020-04-15 20:23:42 +00:00
keyboard states that only change the key codes produced by a keypress, such as
SHIFT, CAPS LOCK, CONTROL, etc. The state of each modifier key is kept in a
state variable. In most cases, pressing the key will set the value to a
"pressed" state, and releasing will reset the value to an "unpressed" state.
However some functions interact. For example, Shift Lock is sticky, so
pressing Shift Lock toggles the Shift Lock state, and Releasing Shift Lock
does nothing; but pressing "Shift" will reset the "Shift Lock" state.
2019-12-12 20:46:29 +00:00
All modifier state variables are kept in a modifier state variable array. On a
regular keypress, all of the modifier state variables are OR'ed together to
produce an index into a value array for the standard key, to determine the
value sent by the standard keypress.
* DIP switches: DIP switches are implemented by adding them into the key
matrix, and providing activate() and deactivate() functions for the on and off
positions.
* Multiple keymaps. DIP switches 0-4 select the map. The current version
includes:
2020-02-20 07:18:37 +00:00
* (0): ADM-style ASCII keyboard
* (1): ADM-style ASCII keyboard (all caps)
2020-02-21 06:28:36 +00:00
* (2): Apple 2 ASCII keyboard (upper/lower)
* (3): Apple 2 ASCII keyboard (standard all caps)
2020-04-15 20:23:42 +00:00
* (4): Sol-20 ASCII keyboard
2023-03-19 00:33:51 +00:00
* (5): Franklin Ace-100 keyboard (Thanks to Chris Ryu)
2020-02-21 06:28:36 +00:00
2019-12-12 20:46:29 +00:00
* Debounce and Repeat functions: The main keyscan logic implements key
debouncing. Multiple keys may be debounced simultaneously using a separate
debounce counter for each key in the matrix.
* Repeat key and Autorepeat: This is provided by the repeat module. Autorepeat
may be disabled or enabled either by configuration, by activate()/deactivate()
functions, or other keyboard logic. Repeat and autorepeat only apply to the
most recently pressed key.
* ASCII output - supported via output_value function.
2022-09-08 02:56:24 +00:00
* Virtual Output layer: Indicator LEDs and other direct logic-level hardware
controls: supported via a virtual output layer. The keymaps (and certain
functions such as shiftlock and capslock) may bind virtual outputs. The keymaps
may then specify how the virtual outputs map to the available physical
resources. This allows one keymap to place the capslock LED in one position,
and another keymap may place the capslock LED elswhere. This simplifies support
of multiple keyboards and keymaps.
2019-12-12 20:46:29 +00:00
2022-09-08 02:56:24 +00:00
## Compiling and configuration
2022-12-04 16:08:55 +00:00
### Changing project name and version number.
- Edit the file "CMakeLists.txt"
2022-12-04 16:11:49 +00:00
- You will see a "project" section near the beginning of the file.
project("asdf"
VERSION 1.6.3
DESCRIPTION "A customizable keyboard matrix controller for retrocomputers"
LANGUAGES C)
- You can change the project name from "asdf" to whatever you like, and change the version number as you see fit. These values will be used to name the resulting hex files, and also to name the download links in the GitHub page, if you choose to create one.
project("my-keyboard"
VERSION 1.0
DESCRIPTION "My customized keyboard firmware"
LANGUAGES C)
2022-12-04 16:08:55 +00:00
2022-09-08 02:56:24 +00:00
### building using github actions:
If you have commit privileges to the repository, or if you have your own fork,
then push a commit to one of the following branches to trigger an automatic build:
- asdf-release
- asdf-build-test
This will generate a github page with downloadable hex files. You will find the
2022-12-04 16:08:55 +00:00
link to the github page in the "Actions" tab of the repository.
You will also need to activate GitHub pages. To do this:
- Click "Settings" at the top of this GitHub page, then along the menu bar on the left, select "Pages" in the "Code and Actions Section."
- In the "Build and deployment" section, select "Deploy from Branch"
- The "Branch" section will display a message that github pages is disabled. Select the branch "gh-pages" from the dropdown, and the "disabled" message will be replaced with a message that the site is being built from "gh-pages". Once you have triggered a build, you will see a message at the top of this page with a link to the live page.
-
2022-09-08 02:56:24 +00:00
### build using the make-build-dirs.sh script.
2022-09-08 03:13:14 +00:00
2022-09-08 02:56:24 +00:00
1) Run the make-targets.sh script
Options:
2022-09-08 03:22:51 +00:00
-x Before creating a build directgory or virtual env, remove
any pre-existing version
-t add an architecture directory
-a Add all valid architecture directories
-i Build each specified target and install to dist directory
-p Install pipenv virtual environment for python scripts
-c Clean all artifacts
-s Copy dist files to sphinx directory
2022-09-08 02:56:24 +00:00
Valid targets: atmega640, atmega1280, atmega2560
2022-09-08 03:22:51 +00:00
- To create build directories for all targets and install the python virtual
environment:
2022-09-08 02:56:24 +00:00
2022-09-08 03:22:51 +00:00
bash make-targets.sh -ap
2022-09-08 02:56:24 +00:00
- To create a a build directory for atmega1280, deleting any pre-existing directory:
2022-09-08 03:22:51 +00:00
bash make-targets.sh -xt atmega2560
2022-09-08 02:56:24 +00:00
- To remove and rebuild the python virtual environment:
2022-09-08 03:22:51 +00:00
bash make-targets.sh -xp
2022-09-08 02:56:24 +00:00
2022-09-08 03:13:14 +00:00
- To copy hex files to sphinx source tree (Requires the hex files
2022-09-08 02:56:24 +00:00
to be installed in ./dist either from make install in each target
directory, or 'bash make-targets.sh -ai')
2022-09-08 03:22:51 +00:00
bash make-targets.sh -s
2022-09-08 02:56:24 +00:00
- From a fresh checkout, build all targets and install hex files in
sphinx tree for the download links:
2022-09-08 03:22:51 +00:00
bash make-targets -pais
2022-09-08 02:56:24 +00:00
2) Enter the build directory for the desired architecture and build:
Only needed if working on single target. To make all targets at once,
use the make-targest script described in step 1.
Example: building the atmega2560 binary:
2022-09-08 03:22:51 +00:00
cd build-atmega2560
make
2022-09-08 02:56:24 +00:00
3) Build the sphinx documentation:
2022-09-08 03:22:51 +00:00
cd docs
pipenv run make html
### build manually (e.g., for development)
2022-09-08 02:56:24 +00:00
1) make and build directories for the desired architectures:
2022-09-08 03:22:51 +00:00
mkdir build-atmega328p build-atmega2560
2022-09-08 02:56:24 +00:00
2022-09-08 03:16:16 +00:00
3) enter each build directory and run cmake for the desired architecture.
2019-12-12 20:46:29 +00:00
2022-09-08 03:22:51 +00:00
cd build-atmega2560
cmake .. -DARCH=atmega2560 -DCMAKE_BUILD_TYPE=RELEASE
> make
2022-09-08 03:16:16 +00:00
4) to run unit tests, the process is the same as above, with "test" as the
target:
2022-09-08 03:13:14 +00:00
2022-09-08 03:22:51 +00:00
mkdir build-test
cd build-test
cmake .. -DARCH=test
cd src
ctest
2019-12-12 20:46:29 +00:00
2022-09-08 02:56:24 +00:00
## Porting
2022-09-08 03:22:51 +00:00
2019-12-12 20:46:29 +00:00
This firmware was written in modular, portable C99, to be compiled with GCC
(avr-gcc for the Atmega). The hardware-sepecific files are in Arch/*.[ch]. To
adapt the Atmega port for additional hardware, enter the ./src/Arch directory,
2020-04-15 20:23:42 +00:00
and copy the files asdf_arch_atmega2560.c and asdf_arch_astmeg2560.h to new
2019-12-12 20:46:29 +00:00
filenames, and edit them to suit the hardware changes.
The firmware is designed to run from ROM on a slow vintage processor, with a
small RAM footprint, and is not re-entrant. It is designed to compile on small
architectures, or to be hand-translated to assembly on small processors, or to
an HDL for a CPLD or FPGA.
The code was written to favor readability over cleverness. While tempted to
optimize bit testing via bithacks, I opted for code simplicity since the
performance benefit was not there for 8-bit values.
2020-04-15 20:23:42 +00:00
To port to a new processor architecture, you may use the atmega2560 files as an
2019-12-12 20:46:29 +00:00
example, and create a pair of architecture-specific .c and .h files for the new
hardware, exporting the following functions:
- asdf_arch_init: initializes the CPU and hardware
- asdf_arch_read_row: given a row number, output the row to the matrix, and read
all the columns on that row asdf_arch_send_code
- asdf_arch_send_code: given a key code, output the code to the computer, via
serial, parallel, I2C, whatever is appropriate.
- asdf_arch_tick: true once every 1ms. This tests a flag set in an interrupt
routine that is triggered every 1ms. The function return value is polled and a
keyscan initiated when true. An alternative, if you have an RTOS, or even just
a scheduler, would be to schedule the keyscan every 1 ms, rather than poll. In
that case, this function is not needed, and the "superloop" in main.c would
contain a call to the scheduler.
2020-03-13 05:09:08 +00:00
2020-04-15 20:23:42 +00:00
- asdf_arch_XXXX_set: The hardware provides a number of physical resources, such
as TTL or tri-state outputs, which can be used to drive LEDs, TTL logic output
lines, etc. These are driven by a virtual output layer. The virtual layer
requires a function to set the state of the physical resources. One function
is provided for each such resource. For example, if a TTL output is called
OUT1, then the function asdf_arch_out1_set() must be defined. For now, the
required devices are:
- LED1, LED2, LED3 (LED outputs)
- OUT1, OUT2, OUT3 (TTL outputs)
- OUT1\_OPEN\_HI, OUT2\_OPEN\_HI, OUT3\_OPEN\_HI (Open collector outputs)
- OUT1\_OPEN\_LO, OUT2\_OPEN\_LO, OUT3\_OPEN\_LO (Open emitter outputs)
2019-12-12 20:46:29 +00:00