Skip to content

Commit 93f6033

Browse files
feat: working version
0 parents  commit 93f6033

File tree

6 files changed

+789
-0
lines changed

6 files changed

+789
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/*
2+
.vscode/*

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(BOARD esp32s3_touch_lcd_1_28/esp32s3/procpu)
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(Esp32SmartWatch)
6+
7+
target_sources(app PRIVATE src/main.c)
8+
target_include_directories(app PRIVATE inc)

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Whitespace-only changes.

prj.conf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Important for LVGL to work.
2+
CONFIG_MAIN_STACK_SIZE=4096
3+
CONFIG_LV_MEM_CUSTOM=y
4+
CONFIG_LV_Z_MEM_POOL_SIZE=16384
5+
6+
# Display Configurations
7+
CONFIG_DISPLAY=y
8+
CONFIG_DISPLAY_LOG_LEVEL_ERR=y
9+
10+
# Log Configurations
11+
CONFIG_LOG=y
12+
CONFIG_LV_USE_LOG=y
13+
14+
# Shell Configurations
15+
CONFIG_SHELL=y
16+
CONFIG_LV_Z_SHELL=y
17+
CONFIG_PWM_SHELL=y
18+
19+
# LVGL Configurations
20+
CONFIG_LVGL=y
21+
CONFIG_LV_USE_LABEL=y
22+
CONFIG_LV_USE_BTN=y
23+
24+
# PWM Configurations
25+
CONFIG_PWM=y

src/main.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2018 Jan Van Winkel <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/device.h>
8+
#include <zephyr/devicetree.h>
9+
#include <zephyr/drivers/display.h>
10+
#include <zephyr/drivers/gpio.h>
11+
#include <zephyr/drivers/pwm.h>
12+
#include <lvgl.h>
13+
#include <stdio.h>
14+
#include <string.h>
15+
#include <zephyr/kernel.h>
16+
#include <zephyr/logging/log.h>
17+
#include <lvgl_input_device.h>
18+
19+
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
20+
LOG_MODULE_REGISTER(SmartWatch_OS);
21+
22+
static void lv_btn_click_callback(lv_event_t *e) {
23+
LOG_INF("Button clicked");
24+
}
25+
26+
int main(void) {
27+
28+
// Check if the display device is ready.
29+
const struct device *display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
30+
if (!device_is_ready(display_dev)) {
31+
LOG_ERR("Display device is not ready, exiting...");
32+
return 0;
33+
}
34+
LOG_INF("Display device is ready.");
35+
36+
const struct pwm_dt_spec backlight = PWM_DT_SPEC_GET_BY_IDX(DT_NODELABEL(pwm_lcd0), 0);
37+
if (!pwm_is_ready_dt(&backlight)) {
38+
LOG_ERR("PWM device is not ready, exiting...");
39+
return 0;
40+
}
41+
LOG_INF("PWM device is ready.");
42+
43+
// Log PWM backlight information.
44+
LOG_INF("PWM device: %s", backlight.dev->name);
45+
LOG_INF("PWM channel: %d", backlight.channel);
46+
LOG_INF("PWM period: %d", backlight.period);
47+
LOG_INF("PWM flags: %d", backlight.flags);
48+
49+
// Initialize the PWM device.
50+
int ret = pwm_set_dt(&backlight, 500, 250);
51+
if (ret < 0) {
52+
LOG_ERR("Failed to set PWM pulse, exiting...");
53+
return 0;
54+
}
55+
56+
// Initialize the display device with initial GUI.
57+
if (IS_ENABLED(CONFIG_LV_Z_POINTER_INPUT)) {
58+
59+
// Create a button.
60+
lv_obj_t *hello_world_button = lv_btn_create(lv_scr_act());
61+
lv_obj_align(hello_world_button, LV_ALIGN_CENTER, 0, -15);
62+
lv_obj_add_event_cb(hello_world_button,
63+
lv_btn_click_callback,
64+
LV_EVENT_CLICKED, NULL);
65+
// Create a label for the button.
66+
lv_obj_t *hello_world_label = lv_label_create(hello_world_button);
67+
lv_label_set_text(hello_world_label, "Hello world!");
68+
lv_obj_align(hello_world_label, LV_ALIGN_CENTER, 0, 0);
69+
70+
LOG_INF("LVGL initialized.");
71+
}
72+
73+
lv_task_handler();
74+
display_blanking_off(display_dev);
75+
76+
while (1) {
77+
lv_task_handler();
78+
k_sleep(K_MSEC(10));
79+
}
80+
}

0 commit comments

Comments
 (0)