Skip to content

Commit

Permalink
fixed to work for LVGL v9.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
aa6164 committed Nov 6, 2024
0 parents commit bab7670
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
39 changes: 39 additions & 0 deletions include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
25 changes: 25 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
build_cache_dir = .pio/mycache

[env:disco_f469ni]
platform = ststm32
board = disco_f469ni
framework = mbed
upload_protocol = stlink

lib_deps =
mbed-st/BSP_DISCO_F469NI
mbed-st/LCD_DISCO_F469NI
mbed-st/TS_DISCO_F469NI
lvgl/lvgl

173 changes: 173 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// This code was written to work for LvGL version 9.2.2
// Read the LvGL documentation for more:
// https://docs.lvgl.io/9.2/porting/index.html
// Chris Bass - 06/11/2024

#include <mbed.h>
#include <LCD_DISCO_F469NI.h>
#include <TS_DISCO_F469NI.h>
#include <lvgl.h>

LCD_DISCO_F469NI lcd;
TS_DISCO_F469NI ts;
Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

void wait(int s) {
wait_us(s * 1000 * 1000);
}

// mbed OS 6 doesnt have a wait_ms function, and ST have not updated their libraries for DISCO_F469NI, so we can do this:
void wait_ms(int ms) {
wait_us(ms * 1000);
}

void my_flush_cb(lv_display_t * display, const lv_area_t * area, uint8_t * px_map)
{
/* The most simple case (also the slowest) to send all rendered pixels to the
* screen one-by-one. `put_px` is just an example. It needs to be implemented by you. */
//uint16_t * buf16 = (uint16_t *)px_map; /* Let's say it's a 16 bit (RGB565) display */
uint32_t * buf32 = (uint32_t *)px_map; /* Let's say it's a 32 bit (XRGB8888) display */

int32_t x, y;
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
lcd.DrawPixel(x, y, *buf32); // Pixel color in ARGB mode (8-8-8-8)
buf32++;
}
}

/* IMPORTANT!!!
* Inform LVGL that flushing is complete so buffer can be modified again. */
lv_display_flush_ready(display);
}

void tp_read_cb(lv_indev_t* drv, lv_indev_data_t* data)
{
static int16_t last_x = 0;
static int16_t last_y = 0;

TS_StateTypeDef tsState;
ts.GetState(&tsState);
if (tsState.touchDetected)
{
data->point.x = tsState.touchX[0];
data->point.y = tsState.touchY[0];
last_x = data->point.x;
last_y = data->point.y;
data->state = LV_INDEV_STATE_PRESSED;
}
else
{
data->point.x = last_x;
data->point.y = last_y;
data->state = LV_INDEV_STATE_RELEASED;
}
}

static void btn_event_cb(lv_event_t* e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t* lvbutton = (lv_obj_t*)lv_event_get_target(e);
if(code == LV_EVENT_CLICKED) {
static uint8_t count = 0;
count++;

// Get the first child of the button which is the label and change its text:
lv_obj_t * lvlabel = lv_obj_get_child(lvbutton, 0);
lv_label_set_text_fmt(lvlabel, "Button: %d", count);

led1 = !led1;
led2 = !led2;
led3 = !led3;
led4 = !led4;
}
}

void lv_tutorial_objects(void)
{
lv_obj_t * label1 = lv_label_create(lv_scr_act()); // Add a label to the active screen
lv_label_set_text(label1, "Hello LVGL world!");
lv_obj_align(label1, LV_ALIGN_CENTER, 0, 0);

lv_obj_t * btn = lv_button_create(lv_screen_active()); // new v9: Add a button to the active screen
lv_obj_set_pos(btn, 10, 10);
lv_obj_set_size(btn, 240, 100);
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_CLICKED, NULL); // Assign a callback to the button

lv_obj_t * lvlabel = lv_label_create(btn); // Add a lvlabel to the button
lv_label_set_text(lvlabel, "Button");
lv_obj_center(lvlabel);
}

void every1ms()
{
lv_tick_inc(1); // https://docs.lvgl.io/9.2/porting/index.html
}

int main()
{
lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE);
wait_us(1 * 1000 * 1000);

uint8_t status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
if (status != TS_OK) {
lcd.Clear(LCD_COLOR_RED);
lcd.SetBackColor(LCD_COLOR_RED);
lcd.SetTextColor(LCD_COLOR_WHITE);
lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
} else {
lcd.Clear(LCD_COLOR_GREEN);
lcd.SetBackColor(LCD_COLOR_GREEN);
lcd.SetTextColor(LCD_COLOR_WHITE);
lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
}

wait_ms(1000);
lcd.SetFont(&Font12);
lcd.SetBackColor(LCD_COLOR_BLUE);
lcd.SetTextColor(LCD_COLOR_WHITE);

// https://docs.lvgl.io/9.2/porting/index.html
lv_init();

// https://docs.lvgl.io/master/intro/add-lvgl-to-your-project/connecting_lvgl.html#initializing-lvgl
lv_tick_set_cb(HAL_GetTick);

// https://docs.lvgl.io/9.2/porting/index.html
//static lv_disp_draw_buf_t disp_buf; // A static or global variable to store the buffers
const int MY_DISP_HOR_RES = 800; // The display on the STM32F469-Discovery is 800 x 480 pixels
const int MY_DISP_VER_RES = 480;
static lv_color_t buf_1[MY_DISP_HOR_RES * 10]; // Static or global buffer(s). The second buffer is optional
static lv_color_t buf_2[MY_DISP_HOR_RES * 10];
// Initialize 'disp_buf' with the buffer(s). With only one buffer use NULL instead buf_2

// new v9:
lv_display_t* display1 = lv_display_create(MY_DISP_HOR_RES, MY_DISP_VER_RES);
lv_display_set_buffers(display1, buf_1, buf_2, MY_DISP_HOR_RES * 10, LV_DISPLAY_RENDER_MODE_PARTIAL);

// new v9 set flush cb:
lv_display_set_flush_cb(display1, my_flush_cb);

// new v9 touch:
/* Create and set up at least one display before you register any input devices. */
lv_indev_t * indev = lv_indev_create(); /* Create input device connected to Default Display. */
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); /* Touch pad is a pointer-like device. */
lv_indev_set_read_cb(indev, tp_read_cb); /* Set driver function. */

// call lv_tick_inc(x) every 1ms https://docs.lvgl.io/9.2/porting/index.html
ticker.attach(every1ms, 1ms);

// setup GUI
lv_tutorial_objects();

while (1)
{
lv_task_handler(); // https://docs.lvgl.io/9.2/porting/index.html
ThisThread::sleep_for(5ms);
}

}
11 changes: 11 additions & 0 deletions test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

This directory is intended for PlatformIO Test Runner and project tests.

Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.

More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html

0 comments on commit bab7670

Please sign in to comment.