A display can be added to your keyboard to show any kind of graphics. This is
especially useful for displaying live information such as battery level, output mode,
etc.
To set up your display, you must add display(driver_setup_fn = <setup_fn>) to your #[keyboard] macro invocation,
and your keyboard must implement the DisplayDevice trait.
The driver_setup_fn must be an async function that has no parameters, and returns a type that implements the
DisplayDriver<T> trait.
Lastly, you must set up the driver. To do this, you need to complete your driver_setup_fn by constructing the driver.
You can check the API reference for your chosen driver for a set up
function or macro to make this process easier.
Depending on the driver, you may also need to implement the appropriate trait that corresponds to your chosen driver.
Check the list of available display drivers for this information.
For example, with ssd1306, you must implement Ssd1306I2cDisplayDriver, and you can use the setup_ssd1306! macro to set up the driver:
Custom graphics
By default, the display will show information about the keyboard depending on
what features are being used. If you’re using any bluetooth features (e.g. bluetooth),
then the battery level will be displayed. If you are communicating
with your host device over USB and Bluetooth (usb and bluetooth enabled),
then it will also show the operation mode.
You are also able to display custom content using the embedded-graphics crate.
In every driver trait, you can change the default implementation of on_update,
which is called either every frame if you set DisplayDevice::FPS to a value
greater than 0, or only when information changes if it was set to 0.
Here’s an example that shows the text “test” on the display: