Skip to content

Commit 9bdd146

Browse files
feat: update main to enable rtc, wip
1 parent 0693167 commit 9bdd146

File tree

2 files changed

+90
-11
lines changed

2 files changed

+90
-11
lines changed

prj.conf

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,40 @@ CONFIG_LV_USE_LOG=n
2020
CONFIG_LVGL=y
2121
CONFIG_LV_FONT_MONTSERRAT_46=y
2222
CONFIG_LV_FONT_MONTSERRAT_18=y
23-
# CONFIG_LV_Z_POINTER_KSCAN_MSGQ_COUNT=1
2423

2524
# PWM Configurations
26-
CONFIG_PWM=y
25+
CONFIG_PWM=y
26+
27+
# Bluetooth Configurations
28+
CONFIG_BT=y
29+
CONFIG_BT_PERIPHERAL=y
30+
CONFIG_BT_SETTINGS=y
31+
CONFIG_BT_DEVICE_NAME="ZephyrWatch"
32+
CONFIG_BT_SMP=y
33+
CONFIG_BT_SIGNING=y
34+
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
35+
CONFIG_BT_PRIVACY=y
36+
37+
# Bluetooth GATT Device Information Service Configuration
38+
CONFIG_BT_DIS=y
39+
CONFIG_BT_DIS_PNP=n
40+
CONFIG_BT_DIS_MODEL="ZephyrWatch_001"
41+
CONFIG_BT_DIS_MANUF="github.com/electricalgorithm"
42+
CONFIG_BT_DIS_SERIAL_NUMBER=y
43+
CONFIG_BT_DIS_FW_REV=y
44+
CONFIG_BT_DIS_HW_REV=y
45+
CONFIG_BT_DIS_SW_REV=y
46+
CONFIG_BT_DIS_SERIAL_NUMBER_STR="0.0.1"
47+
CONFIG_BT_DIS_FW_REV_STR="0.0.1"
48+
CONFIG_BT_DIS_HW_REV_STR="0.0.1"
49+
CONFIG_BT_DIS_SW_REV_STR="0.0.1"
50+
CONFIG_BT_DIS_SETTINGS=y
51+
CONFIG_BT_DIS_STR_MAX=21
52+
53+
# Flash Configurations
54+
CONFIG_FLASH=y
55+
CONFIG_FLASH_MAP=y
56+
CONFIG_NVS=y
57+
58+
# RTC
59+
CONFIG_RTC=y

src/main.c

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,98 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <stdio.h>
8+
#include <string.h>
9+
10+
#include <lvgl.h>
11+
#include <lvgl_input_device.h>
12+
13+
#include <zephyr/kernel.h>
714
#include <zephyr/device.h>
815
#include <zephyr/devicetree.h>
16+
#include <zephyr/logging/log.h>
17+
918
#include <zephyr/drivers/display.h>
1019
#include <zephyr/drivers/gpio.h>
1120
#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>
21+
#include <zephyr/drivers/rtc.h>
22+
1823
#include "user_interface/ui.h"
24+
#include "bluetooth/current_time_service.h"
1925

20-
LOG_MODULE_REGISTER(SmartWatch_OS, LOG_LEVEL_INF);
26+
LOG_MODULE_REGISTER(ZephyrWatch, LOG_LEVEL_INF);
2127

2228

2329
int main(void) {
30+
int ret;
31+
32+
// Initialize the RTC device.
33+
const struct device *rtc_dev = DEVICE_DT_GET(DT_NODELABEL(rtc));
34+
if (!device_is_ready(rtc_dev)) {
35+
LOG_ERR("RTC device is not ready, exiting...");
36+
return 0;
37+
}
38+
LOG_INF("RTC device is ready.");
39+
40+
// struct rtc_time time = {
41+
// .tm_sec = 0,
42+
// .tm_min = 58,
43+
// .tm_hour = 0,
44+
// .tm_mday = 15,
45+
// .tm_mon = 5,
46+
// .tm_year = 2024,
47+
// .tm_wday = 4,
48+
// .tm_yday = 0,
49+
// .tm_isdst = 0,
50+
// .tm_nsec = 0,
51+
// };
52+
53+
// ret = rtc_set_time(rtc_dev, &time);
54+
// if (ret < 0) {
55+
// LOG_ERR("Failed to set time to RTC, exiting...");
56+
// return 0;
57+
// }
58+
// LOG_INF("Time set to RTC.");
59+
60+
// ret = rtc_get_time(rtc_dev, &time);
61+
// if (ret < 0) {
62+
// LOG_ERR("Failed to get time from RTC, exiting...");
63+
// return 0;
64+
// }
65+
//LOG_INF("Current time: %d-%d-%d %d:%d:%d", time.tm_year, time.tm_mon, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
2466

2567
// Check if the display device is ready.
2668
const struct device *display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
2769
if (!device_is_ready(display_dev)) {
2870
LOG_ERR("Display device is not ready, exiting...");
2971
return 0;
3072
}
73+
LOG_INF("Display device is ready.");
3174

3275
const struct pwm_dt_spec backlight = PWM_DT_SPEC_GET_BY_IDX(DT_NODELABEL(pwm_lcd0), 0);
3376
if (!pwm_is_ready_dt(&backlight)) {
3477
LOG_ERR("PWM device is not ready, exiting...");
3578
return 0;
3679
}
80+
LOG_INF("PWM device is ready.");
3781

3882
// Initialize the PWM device.
39-
int ret = pwm_set_dt(&backlight, 500, 250);
83+
ret = pwm_set_dt(&backlight, 500, 250);
4084
if (ret < 0) {
4185
LOG_ERR("Failed to set PWM pulse, exiting...");
4286
return 0;
4387
}
88+
LOG_INF("PWM pulse for LCD backlight set.");
4489

4590
// Initialize the display device with initial GUI.
4691
ui_init();
92+
LOG_INF("UI initialized.");
4793

4894
lv_task_handler();
4995
display_blanking_off(display_dev);
5096

5197
while (1) {
5298
lv_task_handler();
53-
k_usleep(10);
99+
k_sleep(K_USEC(10));
54100
}
55101
}

0 commit comments

Comments
 (0)