Skip to content

Commit

Permalink
[Core] Quantum Painter - LVGL Integration (qmk#18499)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Brassel <[email protected]>
  • Loading branch information
Jpe230 and tzarc authored Dec 12, 2022
1 parent 2d19e59 commit 102f22f
Show file tree
Hide file tree
Showing 24 changed files with 1,140 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
[submodule "lib/pico-sdk"]
path = lib/pico-sdk
url = https://github.com/qmk/pico-sdk.git
[submodule "lib/lvgl"]
path = lib/lvgl
url = https://github.com/qmk/lvgl.git
branch = release/v8.2
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ ifndef SKIP_GIT
if [ ! -e lib/vusb ]; then git submodule sync lib/vusb && git submodule update --depth 50 --init lib/vusb; fi
if [ ! -e lib/printf ]; then git submodule sync lib/printf && git submodule update --depth 50 --init lib/printf; fi
if [ ! -e lib/pico-sdk ]; then git submodule sync lib/pico-sdk && git submodule update --depth 50 --init lib/pico-sdk; fi
if [ ! -e lib/lvgl ]; then git submodule sync lib/lvgl && git submodule update --depth 50 --init lib/lvgl; fi
git submodule status --recursive 2>/dev/null | \
while IFS= read -r x; do \
case "$$x" in \
Expand Down Expand Up @@ -432,6 +433,7 @@ git-submodule:
[ -e lib/ugfx ] && rm -rf lib/ugfx || true
[ -e lib/pico-sdk ] && rm -rf lib/pico-sdk || true
[ -e lib/chibios-contrib/ext/mcux-sdk ] && rm -rf lib/chibios-contrib/ext/mcux-sdk || true
[ -e lib/lvgl ] && rm -rf lib/lvgl || true
git submodule sync --recursive
git submodule update --init --recursive --progress

Expand Down
10 changes: 10 additions & 0 deletions data/templates/config-overrides/common/lv_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2022 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

// #define LV_DITHER_GRADIENT 1

#include_next <lv_conf.h>

// #undef LV_COLOR_16_SWAP
// #define LV_COLOR_16_SWAP 0
1 change: 1 addition & 0 deletions docs/_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
* Hardware Features
* Displays
* [Quantum Painter](quantum_painter.md)
* [Quantum Painter LVGL Integration](quantum_painter_lvgl.md)
* [HD44780 LCD Driver](feature_hd44780.md)
* [ST7565 LCD Driver](feature_st7565.md)
* [OLED Driver](feature_oled_driver.md)
Expand Down
55 changes: 55 additions & 0 deletions docs/quantum_painter_lvgl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Quantum Painter LVGL Integration :id=lvgl

LVGL (Light and Versatile Graphics Library) is an open-source graphics library providing everything you need to create an embedded GUI for your board with easy-to-use graphical elements.

LVGL integrates with [Quantum Painter's](quantum_painter.md) API and drivers to render to the display, the hardware supported by Quantum Painter is also supported by LVGL.

?> Keep in mind that enabling the LVGL integration has a big impact in firmware size, it is recommeded to use a supported MCU with >256 kB of flash space.

To learn more about LVGL and how to use it please take a look at their [official documentation](https://docs.lvgl.io/8.2/intro/)

## Enabling LVGL :id=lvgl-enabling
To enable LVGL to be built into your firmware, add the following to `rules.mk`:

```make
QUANTUM_PAINTER_ENABLE = yes
QUANTUM_PAINTER_DRIVERS = ......
QUANTUM_PAINTER_LVGL_INTEGRATION = yes
```
To configure the Quantum Painter Display Drivers please read the [Quantum Painter Display Drivers](quantum_painter.md#quantum-painter-drivers) section.

## Quantum Painter LVGL API :id=lvgl-api

### Quantum Painter LVGL Attach :id=lvgl-api-init

```c
bool qp_lvgl_attach(painter_device_t device);
```
The `qp_lvgl_attach` function is used to set up LVGL with the supplied display, and requires an already configured display.
```c
static painter_device_t display;
void keyboard_post_init_kb(void) {
display = qp_make_.......; // Create the display
qp_init(display, QP_ROTATION_0); // Initialise the display
if (qp_lvgl_attach(display)) { // Attach LVGL to the display
...Your code to draw // Run LVGL specific code to draw
}
}
```
To init. the display please read the [Display Initialisation](quantum_painter.md#quantum-painter-api-init) section.

!> Attaching LVGL to a display means LVGL subsequently "owns" the display. Using standard Quantum Painter drawing operations with the display after LVGL attachment will likely result in display artifacts.
### Quantum Painter LVGL Detach :id=lvgl-api-init

```c
void qp_lvgl_detach()
```

The `qp_lvgl_detach` function stops the internal LVGL ticks and releases resources related to it.

## Enabling/Disabling LVGL features :id=lvgl-configuring

You can overwrite LVGL specific features in your `lv_conf.h` file.
15 changes: 15 additions & 0 deletions keyboards/handwired/onekey/keymaps/lvgl/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2022 Jose Pablo Ramirez (@jpe230)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

/* SPI pins */
#define SPI_DRIVER SPID0
#define SPI_SCK_PIN GP18
#define SPI_MOSI_PIN GP19
#define SPI_MISO_PIN GP20

/* LCD Configuration */
#define LCD_RST_PIN GP0
#define LCD_DC_PIN GP1
#define LCD_CS_PIN GP2
12 changes: 12 additions & 0 deletions keyboards/handwired/onekey/keymaps/lvgl/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2022 Jose Pablo Ramirez (@jpe230)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include_next <halconf.h>

#undef HAL_USE_SPI
#define HAL_USE_SPI TRUE

#undef SPI_USE_WAIT
#define SPI_USE_WAIT TRUE
50 changes: 50 additions & 0 deletions keyboards/handwired/onekey/keymaps/lvgl/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2022 Jose Pablo Ramirez (@jpe230)
// SPDX-License-Identifier: GPL-2.0-or-later

#include QMK_KEYBOARD_H
#include "qp.h"

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LAYOUT_ortho_1x1(JS_BUTTON0)
};

painter_device_t lcd;

void lv_example_arc_2(void);

void keyboard_post_init_user(void) {
lcd = qp_gc9a01_make_spi_device(240, 240, LCD_CS_PIN, LCD_DC_PIN, LCD_RST_PIN, 4, 0);
qp_init(lcd, QP_ROTATION_0);
qp_rect(lcd, 0, 0, 239, 319, 0, 255, 255, true);

if (qp_lvgl_attach(lcd)) {
lv_example_arc_2();
}
}

static void set_angle(void* obj, int32_t v) {
lv_arc_set_value(obj, v);
}

/**
* Create an arc which acts as a loader.
*/
void lv_example_arc_2(void) {
/*Create an Arc*/
lv_obj_t* arc = lv_arc_create(lv_scr_act());
lv_arc_set_rotation(arc, 270);
lv_arc_set_bg_angles(arc, 0, 360);
lv_obj_remove_style(arc, NULL, LV_PART_KNOB); /*Be sure the knob is not displayed*/
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE); /*To not allow adjusting by click*/
lv_obj_center(arc);

static lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, arc);
lv_anim_set_exec_cb(&a, set_angle);
lv_anim_set_time(&a, 1000);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); /*Just for the demo*/
lv_anim_set_repeat_delay(&a, 500);
lv_anim_set_values(&a, 0, 100);
lv_anim_start(&a);
}
9 changes: 9 additions & 0 deletions keyboards/handwired/onekey/keymaps/lvgl/mcuconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2022 Jose Pablo Ramirez (@jpe230)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include_next <mcuconf.h>

#undef RP_SPI_USE_SPI0
#define RP_SPI_USE_SPI0 TRUE
3 changes: 3 additions & 0 deletions keyboards/handwired/onekey/keymaps/lvgl/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
QUANTUM_PAINTER_ENABLE = yes
QUANTUM_PAINTER_LVGL_INTEGRATION = yes
QUANTUM_PAINTER_DRIVERS = gc9a01_spi
1 change: 1 addition & 0 deletions lib/lvgl
Submodule lvgl added at e19410
Loading

0 comments on commit 102f22f

Please sign in to comment.