wallComputer / bbqX0kbd_driver

BBQX0KBD is a Keyboard Device Driver for the BB Q Keyboard
GNU General Public License v2.0
40 stars 22 forks source link

BBQX0KBD

BBQX0KBD is an I2C Keyboard Device Driver for keyboard devices made by Solder Party. The following keyboards are currently supported by this driver:

  1. BB Q10 Keyboard PMOD
  2. Keyboard FeatherWing
  3. BBQ20KBD

The current version supports the devices as Console Keyboards only, the desktop GUI usage has minor issues.

The drivers are named so (with an 'X'), so as to support future products by the original creator. The driver is mainly developed and tested on the following SBCs from Raspberry Pi Foundation's

  1. Raspberry Pi Zero W
  2. Raspberry Pi Zero 2 W
  3. Raspberry Pi 3 Model B.

Features

The original source code by arturo182, is a good starting point from where this driver builds on. This driver offers the following features:

*Available only on Keyboard FeatherWing for now.

**Available only on BBQ20KBD for now.

***Not tested this feature 100%.

Keyboard Layout

The keyboard layout is shown below.

The top row is unique to the Keyboard FeatherWing, while the BBQ20KBD has a similar top key row, with the essential difference that it uses a trackpad instead of 5-way key. Even then, except for the CTRL Key, every other keypress on this row can be executed from the keyboard/BB Q10 Keyboard PMOD module itself.

By default, each key on the keyboard itself signifies the middle element mentioned in the layout below.

To access the keys mentioned above a character, press and hold LFTALT (Left alt) and press the desired key. For example, Key(/) is presented by LFTALT+G.

To access the keys mentioned below a character, press and hold RTALT (Right alt) and press the desired key. For example, Key(=) is presented by RTALT+I.

Upper Case Letters can be executed by pressing LEFT_SHIFT + the key.

Caps Lock is toggled by pressing LFTALT + LEFT_SHIFT.

Num Lock is toggled by pressing LFTALT + RIGHT_SHIFT.

Screen Brightness can be increased or decreased by RTALT+Q and RTALT+W respectively. Toggling the same is done by RTALT+S.

Keyboard Brightness can be increased or decreased by RTALT+K and RTALT+L respectively. Toggling the same is done by RTALT+$.

Volume can be increased or decreased by RTALT+Z and RTALT+X respectively. Muting the same is done by RTALT+~.

 *         BBQ10KBD PMOD KEYBOARD LAYOUT
 *
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |#     |1    |2   |3   |(   |   )|_   |    -|    +|      @|
 *  |  Q   |  W  | E  | R  | T  |  Y |  U |  I  |  O  |   P   |
 *  |    S+|   S-|PgUp|PgDn|   \|UP  |^   |=    |{    |}      |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |*     |4    |5   |6   |/   |   :|;   |    '|    "|    ESC|
 *  |  A   |  S  | D  | F  | G  |  H |  J |  K  |  L  |  BKSP |
 *  |     ?|   Sx|   [|   ]|LEFT|HOME|RGHT|V+   |V-   |DLT    |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |      |7    |8   |9   |?   |   !|,   |    .|    `|       |
 *  |LFTALT|  Z  | X  | C  | V  |  B |  N |  M  |  $  | ENTER |
 *  |      |   K+|  K-|   °|   <|DOWN|>   |MENU |Vx   |       |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |            |0   |TAB                |     |             |
 *  | LEFT_SHIFT | ~  |       SPACE       |RTALT| RIGHT_SHIFT |
 *  |            |  Kx|                  &|     |             |
 *  +------------+----+-------------------+-----+-------------+
 *
 *      BBQ10KBD FEATHERWING KEYBOARD LAYOUT
 *
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |      |          |        UP         |           |       |
 *  | Ctrl |   PgDn   |  LEFT HOME RIGHT  |   PgUp    | MENU  |
 *  |      |          |       DOWN        |           |       |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |                                                         |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |#     |1    |2   |3   |(   |   )|_   |    -|    +|      @|
 *  |  Q   |  W  | E  | R  | T  |  Y |  U |  I  |  O  |   P   |
 *  |    S+|   S-|PgDn|PgUp|   \|UP  |^   |=    |{    |}      |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |*     |4    |5   |6   |/   |   :|;   |    '|    "|    ESC|
 *  |  A   |  S  | D  | F  | G  |  H |  J |  K  |  L  |  BKSP |
 *  |     ?|   Sx|   [|   ]|LEFT|HOME|RGHT|V+   |V-   |DLT    |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |      |7    |8   |9   |?   |   !|,   |    .|    `|       |
 *  |LFTALT|  Z  | X  | C  | V  |  B |  N |  M  |  $  | ENTER |
 *  |      |   K+|  K-|   °|   <|DOWN|>   |MENU |Vx   |       |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |            |0   |TAB                |     |             |
 *  | LEFT_SHIFT | ~  |       SPACE       |RTALT| RIGHT_SHIFT |
 *  |            |  Kx|                  &|     |             |
 *  +------------+----+-------------------+-----+-------------+
 *
 *                 BBQ20KBD PMOD KEYBOARD LAYOUT
 *
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |      |          |BR     ↑TPY-       |           |       |
 *  | Ctrl |   PgDn   |←TPX- BL(HOME)TPX+→|   PgUp    | MENU  |
 *  |      |          |       ↓TPY+       |           |       |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |                                                         |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |#     |1    |2   |3   |(   |   )|_   |    -|    +|      @|
 *  |  Q   |  W  | E  | R  | T  |  Y |  U |  I  |  O  |   P   |
 *  |      |     |PgDn|PgUp|   \|UP  |^   |=    |{    |}      |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |*     |4    |5   |6   |/   |   :|;   |    '|    "|    ESC|
 *  |  A   |  S  | D  | F  | G  |  H |  J |  K  |  L  |  BKSP |
 *  |     ?|     |   [|   ]|LEFT|HOME|RGHT|V+   |V-   |DLT    |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |      |7    |8   |9   |?   |   !|,   |    .|    `|       |
 *  |LFTALT|  Z  | X  | C  | V  |  B |  N |  M  |  $  | ENTER |
 *  |      |   K+|  K-|   °|   <|DOWN|>   |MENU |Vx   |       |
 *  +------+-----+----+----+----+----+----+-----+-----+-------+
 *  |            |0   |TAB                |     |             |
 *  | LEFT_SHIFT | ~  |       SPACE       |RTALT| RIGHT_SHIFT |
 *  |            |  Kx|                  &|     |             |
 *  +------------+----+-------------------+-----+-------------+
 *

Pre-requisites, Download, and Installation.

Pre-requisites

Download

Copy the Git repository from above and download it on your Pi, preferably on /home/pi/ using the below command and change in to the folder.

git clone https://github.com/wallComputer/bbqX0kbd_driver.git
cd bbqX0kbd_driver/

Installation

The following examples may be useful:

./installer.sh

This is the default option. It creates a Keyboard Driver for BBQ20KBD on I2C Address 0x1F. The Keyboard does not need Int Pin and instead polls the Keyboard every 40ms. The trackpad is used as a mouse, and the button is used as mouse left click. On pressing the button with Left Alt as LFTALT + BTN_LEFT, a mouse right key is registered.

./installer.sh --BBQX0KBD_TYPE BBQ10KBD_FEATHERWING --BBQX0KBD_INT BBQX0KBD_NO_INT --BBQX0KBD_POLL_PERIOD 25

This creates the kernel driver for Keyboard Featherwing. It does not use the Interrupt Pin, instead polls the keyboard every 25ms.

./installer.sh --BBQX0KBD_TYPE BBQ10KBD_PMOD --BBQX0KBD_INT BBQX0KBD_USE_INT --BBQX0KBD_INT_PIN 23

This creates the kernel driver for BBQ10KBD_PMOD. It does use the Interrupt Pin, namely, BCM Pin GPIO 23 (Pin 16 on the header).

./installer.sh --BBQX0KBD_TYPE BBQ20KBD_PMOD --BBQX0KBD_INT BBQX0KBD_NO_INT --BBQX0KBD_ASSIGNED_I2C_ADDRESS 0x45

This creates the kernel driver for BBQ20KBD_PMOD. The Driver assumes the Keyboard is available on I2C Address 0x45, as well as polls it at default poll rate of 40ms.

./installer.sh --BBQX0KBD_TYPE BBQ20KBD_PMOD --BBQ20KBD_TRACKPAD_USE BBQ20KBD_TRACKPAD_AS_KEYS

This creates the kernel driver for BBQ20KBD_PMOD and uses the trackpad as KEY_HOME. The Mouse movement is not registered.

After following guide, reboot your pi and on login, the Keyboard should be working on /dev/tty1. To view the above console, Use an LCD such as the one on the Keyboard FeatherWing, or any other you can get to work with your Pi. The easiest way is to either use a Adafruit PiTFT, or use the below example of using juj's frcp-ili9341 project.

(Optional) Setting Up a Screen with the Keyboard Module

Keyboard FeatherWing has an ILI9341 on it. Using it for the main console can be of great use. The below steps describe how to connect and control this LCD from the Pi.

  1. Hardware connections
     3.3V on Pi ----> 3.3V on Keyboard FeatherWing.
     GND on Pi -----> GND on Keyboard FeatherWing.
     SCLK(Pi Pin 23/BCM GPIO 11) ---> SCK on Keyboard FeatherWing.
     MOSI(Pi Pin 19/BCM GPIO 10) ---> CO on Keyboard FeatherWing.
     CE0(Pi Pin 24/BCM GPIO 8) ---> LCD_CS on Keyboard FeatherWing.
     GPIO9(Pi Pin 13/BCM GPIO 27) ---> LCD_DC on Keyboard FeatherWing.

    If you are using the Keyboard FeatherWing, you will also need to pull the RST Pin on the Featherwing to 3.3V.

     3.3V on Pi ----> RST on Keyboard FeatherWing.
  2. Install git and cmake.
     sudo apt install git cmake
  3. Clone juj's project, and create a directory build inside it, and change in to it.
     git clone https://github.com/juj/fbcp-ili9341.git
     cd fbcp-ili9341
     mkdir build
     cd build/
  4. Inside the build directory, run the below cmake command.
     cmake -DILI9341=ON -DSPI_BUS_CLOCK_DIVISOR=40 -DGPIO_TFT_DATA_CONTROL=27 -DSTATISTICS=0 ..
  5. Run a make command as
     make -j
  6. The result of the above file will be a fbcp-ili9341 file. Place the absolute path of this file in the last line but one of /etc/rc.local as below (assuming the absolute path is correct)
     sudo /home/pi/fbcp-ili9341/build/fbcp-ili9341 &
  7. Place the below text in /boot/config.txt
     hdmi_group=2
     hdmi_mode=87
     hdmi_cvt=320 240 60 1 0 0 0
     hdmi_force_hotplug=1
  8. From sudo raspi-config, under System Options, set the Boot / Auto Login feature to Console or Console Autologin.
  9. Reboot.
  10. On boot up, the LCD should start showing console. It might be useful to run sudo dpkg-reconfigure console-setup (can be done over ssh), choose the desired font and size, and place a sudo /etc/init.d/console-setup.sh reload & in the /etc/rc.local file just as in step 5.

Customisation

Known Issues

Future Work

Contributing

Pull requests are welcome.

Special thanks

License

The code itself is LGPL-2.0 though I'm not going to stick it to you, I just chose what I saw, if you want to do awesome stuff useful to others with it without harming anyone, go for it and have fun just as I did.