Document fait avec Nvu Document made with Nvu




Emulator keyboard driver

FORTH mini system

Instructions
Use
Example

Principle

If the keyboard of the emulator is an addressable register in the extension registers area of the FORTH core described as follows:

278 (0x116) read only:

bits[15..4] = 0xFFF if key down
0x000 otherwise
bits[3,2] = line number (0 in top side)
bits[1,0] = row number (0 in left side)

bits[3..0] are memorized when key is released


The driver will allow to facilitate the use of this registes while making use of the real-time kernel. The principle consists in giving to the developer the code of the activated key with automatic managment of the auto repeat.

For the FORTH mini system emulator, a component PCF8574A of I2C port numero 7 is used with the following configuration:
bit[7] = 1 if key down
0 otherwise
bits[6..4] drive 3 white LEDs lit at 1
bits[3..0] have the same function
The electrical schematic is the following:


Instructions

- CW_CLAVIER 278

Numero of the keyboard extension register.
This instruction does not exist in the FORTH mini system,
the access to keyboard register is made with the instructions
I2C_PCF8574_C@ and I2C_PCF8574_C! numero 7.

adr_prg SYNC_CLAVIER -

Installation of the keyboard driver.
adr_prg is the address of the program called with the ASCII code of the activated key.
If adr_prg or msq is null, the driver is removed.

n SORT_CLAVIER -

This instruction does not exist in the FORTH Core.
Control of the white DELs, n is in the range 0 to 7.

Use

The driver not being integrated into the kernel, it is initially necessary to compile the source file petit_clavier.txt before being able to use it.

For the FORTH mini system emulator, it is necessary to compile firts the I2C driver described in the source file pcf8574.txt then compile petit_clavier.txt.

It is necessary to create the program called automatically by the driver by using following syntax:

: PROGRAM
 INSTRUCTION1 INSTRUCTION2 ... INSTRUCTIONn
;

WARNING: the program will have the ASCII code of the activated key on the data stack, one should not forget to remove this value.

It is then necessary to install the driver with the value of the desired mask:

FIND PROGRAM SYNC_CLAVIER

The driver manages automaticaly the installation of a task which scans the keyboard every 20 ms. As soon as a key is activated, the program is executed with its ASCII code. If a key is activated more than 500 ms, the program is automaticaly launched again every 100 ms during the key activation. This is realized with priority 49152.

Example

The following sequence allows to display the keyboard ASCII codes in the FORTH terminal:

FIND EMIT SYNC_CLAVIER

To remove this program, it is enough to make:

0 SYNC_CLAVIER

Here is a video: