Skip to content

Commit

Permalink
feat(demos): Add demo for the OSAL
Browse files Browse the repository at this point in the history
Adds a demo demonstrating the use of the OSAL.

Resolves: lvgl#6049
  • Loading branch information
faxe1008 committed May 5, 2024
1 parent 37cf3bb commit 4d6eee4
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .devcontainer/__lv_conf.h__
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,9 @@

/*Vector graphic demo*/
#define LV_USE_DEMO_VECTOR_GRAPHIC 0

/*Demonstrate OSAL*/
#define LV_USE_DEMO_OSAL 1
/*--END OF LV_CONF_H--*/

#endif /*LV_CONF_H*/
Expand Down
4 changes: 4 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,10 @@ menu "LVGL configuration"
bool "vector graphic demo"
default n
depends on LV_USE_VECTOR_GRAPHIC
config LV_USE_DEMO_OSAL
bool "OSAL demo"
default n
depends on LV_USE_OS > 0
endmenu

endmenu
4 changes: 4 additions & 0 deletions demos/lv_demos.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ static const demo_entry_info_t demos_entry_info[] = {
{ "benchmark", .entry_cb = lv_demo_benchmark },
#endif

#if LV_USE_DEMO_OSAL
{ "osal", .entry_cb = lv_demo_osal },
#endif

{ "", .entry_cb = NULL }
};

Expand Down
3 changes: 3 additions & 0 deletions demos/lv_demos.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ extern "C" {
#include "render/lv_demo_render.h"
#endif

#if LV_USE_DEMO_OSAL
#include "osal/lv_demo_osal.h"
#endif
/*********************
* DEFINES
*********************/
Expand Down
11 changes: 11 additions & 0 deletions demos/osal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OSAL demo

## Overview

A OSAL test for LVGL.


## Run the demo
- In `lv_conf.h` or equivalent places set `LV_USE_DEMO_OSAL 1`
- In `lv_conf.h` enable all the widgets (`LV_USE_BUTTON 1`) and the label (`LV_USE_LABEL 1`)
- After `lv_init()` and initializing the drivers call `lv_demo_osal()`
88 changes: 88 additions & 0 deletions demos/osal/lv_demo_osal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* @file lv_demo_osal.c
*
*/

/*********************
* INCLUDES
*********************/
#include "lv_demo_osal.h"

#if LV_USE_DEMO_OSAL

/*********************
* DEFINES
*********************/

/**********************
* TYPEDEFS
**********************/

/**********************
* STATIC PROTOTYPES
**********************/
static void counter_button_event_cb(lv_event_t * e);
static void increment_thread_entry(void * user_data);

/**********************
* STATIC VARIABLES
**********************/
static lv_thread_sync_t press_sync;
static lv_thread_t increment_thread;

/**********************
* MACROS
**********************/

/**********************
* GLOBAL FUNCTIONS
**********************/

void lv_demo_osal(void)
{
lv_obj_t * counter_button;

counter_button = lv_button_create(lv_screen_active());
lv_obj_align(counter_button, LV_ALIGN_CENTER, 0, -15);
lv_obj_add_event_cb(counter_button, counter_button_event_cb, LV_EVENT_CLICKED, NULL);

if(lv_thread_sync_init(&press_sync) != LV_RESULT_OK) {
LV_LOG_ERROR("Error initializing thread sync");
}

if(lv_thread_init(&increment_thread, LV_THREAD_PRIO_MID, increment_thread_entry, 2048, NULL) != LV_RESULT_OK) {
LV_LOG_ERROR("Error initializing thread");
}
}

/**********************
* STATIC FUNCTIONS
**********************/

void counter_button_event_cb(lv_event_t * e)
{
if(lv_thread_sync_signal(&press_sync) != LV_RESULT_OK) {
LV_LOG_ERROR("Error signaling thread sync");
}
}

void increment_thread_entry(void * user_data)
{
lv_obj_t * counter_label;
uint32_t press_count = 0;

counter_label = lv_label_create(lv_scr_act());
lv_obj_align(counter_label, LV_ALIGN_CENTER, 0, 0);
lv_label_set_text_fmt("Pressed %u times", press_count);

while(true) {
if(lv_thread_sync_wait(&press_sync) != LV_RESULT_OK) {
LV_LOG_ERROR("Error awaiting thread sync");
}
press_count += 1;
lv_label_set_text_fmt("Pressed %u times", press_count);
}
}


#endif
39 changes: 39 additions & 0 deletions demos/osal/lv_demo_osal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @file lv_demo_osal.h
*
*/

#ifndef LV_DEMO_OSAL_H
#define LV_DEMO_OSAL_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
* INCLUDES
*********************/
#include "../lv_demos.h"

/*********************
* DEFINES
*********************/

/**********************
* TYPEDEFS
**********************/

/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_demo_osal(void);

/**********************
* MACROS
**********************/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*LV_DEMO_OSAL_H*/
3 changes: 3 additions & 0 deletions lv_conf_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,9 @@

/*Vector graphic demo*/
#define LV_USE_DEMO_VECTOR_GRAPHIC 0

/* OSAL demo */
#define LV_USE_DEMO_OSAL 0
/*--END OF LV_CONF_H--*/

#endif /*LV_CONF_H*/
Expand Down
9 changes: 8 additions & 1 deletion src/lv_conf_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,14 @@
#endif
#endif


/*OSAL demo*/
#ifndef LV_USE_DEMO_OSAL
#ifdef CONFIG_LV_USE_DEMO_OSAL
#define LV_USE_DEMO_OSAL CONFIG_LV_USE_DEMO_OSAL
#else
#define LV_USE_DEMO_OSAL 0
#endif
#endif
/*----------------------------------
* End of parsing lv_conf_template.h
-----------------------------------*/
Expand Down
1 change: 1 addition & 0 deletions tests/src/lv_test_conf_full.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
#define LV_USE_DEMO_BENCHMARK 1
#define LV_USE_DEMO_SCROLL 1
#define LV_USE_DEMO_VECTOR_GRAPHIC 1
#define LV_USE_DEMO_OSAL 1

#define LV_USE_OBJ_ID 1
#define LV_USE_OBJ_ID_BUILTIN 1
Expand Down

0 comments on commit 4d6eee4

Please sign in to comment.