Close

Ep. 3 - Firmware overview #code

A project log for K-Ability Toolkit

Toolkit for diy devices that allow the use of touchscreens to people with neuromuscular coordination problems

dariocosedariocose 05/30/2023 at 15:330 Comments

I developed the firmware with platformio, Esp32/Arduino framework, and it is based on bodmer/TFT_eSPI, t-vk/ESP32 BLE Keyboard, and t-vk/ESP32 BLE Mouse libraries.

Using the ESP32 BLE Keyboard and ESP32 BLE Mouse libraries, the device works on all desktop and mobile operating systems without any other apps, software, or other tools installed on the master machine. Connecting K-Ability to any device simply by Bluetooth pairing.
I organized the program in tasks with FreeRTOS. Although it seems a complicated approach,  I preferred to divide the various features of the code into different files and tasks, in order to make easier to copy/paste the code for other projects. 

bluetoothTask (include/bluetooth.h)
handles bluetooth connection. It checks for disconnection every second and reports events on the screen.

batteryTask (include/battery.h)
prints the battery status every 30 seconds. It will also handle the graphical representation of the battery status.

buttonsTask (include/buttons.h)
handles the events of the 7 buttons.
Right now the firmware manages  capacitive buttons only, by using default Esp32 "Capacitive Touch Sensor Pins" (gpio 2, 4, 12, 13, 14, 15, 27, 32 and 33 ). One of the upcoming developments will give the possibility to use normal tactile buttons as well.

4 out of 7 work as directional buttons (top, bottom, right and left), the fifth one as enter/click button, the sixth on as select button and the last one as cancel button.

"Select" button allows browsing through all over functions of the firmware.
"Cancel" button returns to the default function.

In this task I manage each button by valuing a global variable. Each individual function is managed by the mouseKeyboardTask task.

mouseKeyboardTask (include/mouseKeyboard.h)
handles all main firmware functions.
Up to now, the following functions have been implemented:

All keyboard-related functions will be documented and committed later

showOnDisplay(), refreshScreenState(), startDisplay()
I used T-Display tft screen to get visual feedback from the program. 

Getting access to functions from all parts of the firmware, I did not create a screen management task,.
These 3 functions initialize, display and refresh graphics on the screen.
Who hasn't a screen, just comment out these 3 functions and the TFT_eSPI library.

To better understand how it works, I share this old video. Of course the technology is different but the mechanism of operation is identical.

Discussions