From 50b9d2bb3ff180e72f6b4fb0dfc67629a9d61cdf Mon Sep 17 00:00:00 2001 From: Daniel Kampert Date: Mon, 27 May 2024 09:06:11 +0200 Subject: [PATCH] - Add skeleton for RV-8263-C8 RTC - Rename display driver to match it with the vendor_type scheme of the other drivers - Remove Funkytown song from Buzzer driver --- .../zswatch_nrf5340_cpuapp_5.conf | 3 +- .../zswatch_nrf5340_cpuapp_5.overlay | 22 +++++- app/drivers/CMakeLists.txt | 1 + app/drivers/Kconfig | 1 + app/drivers/display/gc9a01/CMakeLists.txt | 2 +- .../gc9a01/{gc9a01.c => buydisplay_gc9a01.c} | 0 app/drivers/rtc/CMakeLists.txt | 6 ++ app/drivers/rtc/Kconfig | 3 + app/drivers/rtc/rv8263c8/CMakeLists.txt | 6 ++ app/drivers/rtc/rv8263c8/Kconfig | 21 +++++ .../rtc/rv8263c8/microcrystal_rv8263c8.c | 79 +++++++++++++++++++ .../rtc/rv8263c8/microcrystal_rv8263c8.h | 9 +++ .../bindings/rtc/microcrystal,rv-8263-c8.yml | 9 +++ app/src/drivers/zsw_buzzer.c | 16 ---- 14 files changed, 158 insertions(+), 20 deletions(-) rename app/drivers/display/gc9a01/{gc9a01.c => buydisplay_gc9a01.c} (100%) create mode 100644 app/drivers/rtc/CMakeLists.txt create mode 100644 app/drivers/rtc/Kconfig create mode 100644 app/drivers/rtc/rv8263c8/CMakeLists.txt create mode 100644 app/drivers/rtc/rv8263c8/Kconfig create mode 100644 app/drivers/rtc/rv8263c8/microcrystal_rv8263c8.c create mode 100644 app/drivers/rtc/rv8263c8/microcrystal_rv8263c8.h create mode 100644 app/dts/bindings/rtc/microcrystal,rv-8263-c8.yml diff --git a/app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_5.conf b/app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_5.conf index c2368b48..5685a1bb 100644 --- a/app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_5.conf +++ b/app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_5.conf @@ -1,9 +1,7 @@ CONFIG_ZSWATCH_PCB_REV=5 CONFIG_BT_DIS_HW_REV_STR="5" -#--------------- # FLASH -#----------------- CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_STREAM_FLASH=y @@ -49,3 +47,4 @@ CONFIG_NVS=y CONFIG_DEBUG_COREDUMP_BACKEND_OTHER=y +CONFIG_RTC=y \ No newline at end of file diff --git a/app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_5.overlay b/app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_5.overlay index ed16b9ff..b22340af 100644 --- a/app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_5.overlay +++ b/app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_5.overlay @@ -77,6 +77,7 @@ ; low-power-enable; }; + group2 { psels = ; low-power-enable; @@ -125,21 +126,25 @@ buttons: buttons { compatible = "gpio-keys"; + button1: button_1 { label = "top-right"; gpios = <&gpio0 27 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; zephyr,code = ; }; + button2: button_2 { label = "bottom-left"; gpios = <&gpio1 10 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; zephyr,code = ; }; + button3: button_3 { label = "bottom-right"; gpios = <&gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; zephyr,code = ; }; + button4: button_4 { label = "top-left"; gpios = <&gpio0 26 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; @@ -167,12 +172,15 @@ pwmleds { compatible = "pwm-leds"; + display_blk: pwm_led_0 { pwms = <&pwm0 0 PWM_USEC(15) PWM_POLARITY_INVERTED>; }; + vibrator_pwm: pwm_led_1 { pwms = <&pwm1 0 PWM_MSEC(20) 0>; }; + buzzer_pwm: pwm_led_2 { pwms = <&pwm2 0 PWM_HZ(880) PWM_POLARITY_NORMAL>; }; @@ -181,6 +189,12 @@ }; &i2c1 { + rv_8263_c8: rv-8263-c8@A2 { + compatible = "microcrystal,rv-8263-c8"; + reg = <0xA2>; + status = "okay"; + }; + bmi270: bmi270@68 { compatible = "bosch,bmi270-plus"; reg = <0x68>; @@ -200,6 +214,7 @@ resolution = <0>; frequency = <0>; }; + npm1300_ek_pmic: pmic@6b { compatible = "nordic,npm1300"; reg = <0x6b>; @@ -253,6 +268,7 @@ thermistor-beta = <3380>; charging-enable; }; + npm1300_ek_buttons: buttons { compatible = "gpio-keys"; status = "disabled"; @@ -286,6 +302,7 @@ pinctrl-0 = <&qspi_default>; pinctrl-1 = <&qspi_sleep>; pinctrl-names = "default", "sleep"; + gd25lq128d: gd25lq128d@0 { compatible = "nordic,qspi-nor"; reg = <0>; @@ -309,6 +326,7 @@ / { fstab { compatible = "zephyr,fstab"; + lvgl_lfs: lvgl_lfs { compatible = "zephyr,fstab,littlefs"; mount-point = "/lvgl_lfs"; @@ -336,13 +354,15 @@ label = "littlefs_storage"; reg = <0x00000000 0x00200000>; }; + lvgl_raw_partition: partition@200000 { label = "lvgl_raw_partition"; reg = <0x00200000 0x00200000>; }; + storage_partition: partition@400000 { label = "storage_partition"; reg = <0x400000 0x100000 >; }; }; -}; +}; \ No newline at end of file diff --git a/app/drivers/CMakeLists.txt b/app/drivers/CMakeLists.txt index 31f019e0..5c438f54 100644 --- a/app/drivers/CMakeLists.txt +++ b/app/drivers/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(display) add_subdirectory(input) +add_subdirectory(rtc) add_subdirectory_ifdef(CONFIG_SENSOR sensor) \ No newline at end of file diff --git a/app/drivers/Kconfig b/app/drivers/Kconfig index aa785211..e5128844 100644 --- a/app/drivers/Kconfig +++ b/app/drivers/Kconfig @@ -1,5 +1,6 @@ rsource "display/Kconfig" rsource "input/Kconfig" +rsource "rtc/Kconfig" menu "Drivers" rsource "sensor/Kconfig" diff --git a/app/drivers/display/gc9a01/CMakeLists.txt b/app/drivers/display/gc9a01/CMakeLists.txt index a58a904e..860978b4 100644 --- a/app/drivers/display/gc9a01/CMakeLists.txt +++ b/app/drivers/display/gc9a01/CMakeLists.txt @@ -1 +1 @@ -zephyr_sources(gc9a01.c) \ No newline at end of file +zephyr_sources(buydisplay_gc9a01.c) \ No newline at end of file diff --git a/app/drivers/display/gc9a01/gc9a01.c b/app/drivers/display/gc9a01/buydisplay_gc9a01.c similarity index 100% rename from app/drivers/display/gc9a01/gc9a01.c rename to app/drivers/display/gc9a01/buydisplay_gc9a01.c diff --git a/app/drivers/rtc/CMakeLists.txt b/app/drivers/rtc/CMakeLists.txt new file mode 100644 index 00000000..a095c974 --- /dev/null +++ b/app/drivers/rtc/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2024, Daniel Kampert +# +# SPDX-License-Identifier: Apache-2.0 +# + +add_subdirectory_ifdef(CONFIG_RV_8263_C8 rv8263c8) \ No newline at end of file diff --git a/app/drivers/rtc/Kconfig b/app/drivers/rtc/Kconfig new file mode 100644 index 00000000..903dd8f1 --- /dev/null +++ b/app/drivers/rtc/Kconfig @@ -0,0 +1,3 @@ +if RTC + rsource "rv8263c8/Kconfig" +endif \ No newline at end of file diff --git a/app/drivers/rtc/rv8263c8/CMakeLists.txt b/app/drivers/rtc/rv8263c8/CMakeLists.txt new file mode 100644 index 00000000..089d3e28 --- /dev/null +++ b/app/drivers/rtc/rv8263c8/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2024, Daniel Kampert +# +# SPDX-License-Identifier: Apache-2.0 +# + +zephyr_sources(microcrystal_rv8263c8.c) \ No newline at end of file diff --git a/app/drivers/rtc/rv8263c8/Kconfig b/app/drivers/rtc/rv8263c8/Kconfig new file mode 100644 index 00000000..f6c4760a --- /dev/null +++ b/app/drivers/rtc/rv8263c8/Kconfig @@ -0,0 +1,21 @@ +# RV-8263-C8 RTC configuration options. + +# Copyright (c) 240, Daniel Kampert +# +# SPDX-License-Identifier: Apache-2.0 + +menuconfig RV_8263_C8 + bool "RV-8263-C8 RTC" + depends on DT_HAS_MICROCRYSTAL_RV_8263_C8_ENABLED + default y + select I2C + help + Enable the driver for the RV-8263-C8 RTC. + +if RV_8263_C8 + +module = MICROCRYSTAL_RV_8263_C8 +module-str = MICROCRYSTAL_RV_8263_C8 +source "subsys/logging/Kconfig.template.log_config" + +endif \ No newline at end of file diff --git a/app/drivers/rtc/rv8263c8/microcrystal_rv8263c8.c b/app/drivers/rtc/rv8263c8/microcrystal_rv8263c8.c new file mode 100644 index 00000000..b4b0b7ff --- /dev/null +++ b/app/drivers/rtc/rv8263c8/microcrystal_rv8263c8.c @@ -0,0 +1,79 @@ +/* microcrystal_rv8263c8.c - Driver for Micro Crystal RV-8263-C8 RTC. */ + +/* + * Copyright (c) 2024, Daniel Kampert + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "microcrystal_rv8263c8.h" + +#define RV8263C8_REGISTER_CONTROL1 0x00 +#define RV8263C8_REGISTER_CONTROL2 0x01 +#define RV8263C8_REGISTER_OFFSET 0x02 +#define RV8263C8_REGISTER_RAM 0x03 +#define RV8263C8_REGISTER_SECONDS 0x04 +#define RV8263C8_REGISTER_MINUTES 0x05 +#define RV8263C8_REGISTER_HOURS 0x06 +#define RV8263C8_REGISTER_DATE 0x07 +#define RV8263C8_REGISTER_WEEKDAY 0x08 +#define RV8263C8_REGISTER_MONTH 0x09 +#define RV8263C8_REGISTER_YEAR 0x0A +#define RV8263C8_REGISTER_SECONDS_ALARM 0x0B +#define RV8263C8_REGISTER_MINUTES_ALARM 0x0C +#define RV8263C8_REGISTER_HOURS_ALARM 0x0D +#define RV8263C8_REGISTER_DATE_ALARM 0x0E +#define RV8263C8_REGISTER_WEEKDAY_ALARM 0x0F +#define RV8263C8_REGISTER_TIMER_VALUE 0x10 +#define RV8263C8_REGISTER_TIMER_MODE 0x11 + +#define DT_DRV_COMPAT microcrystal_rv_8263_c8 + +LOG_MODULE_REGISTER(microcrystal_rv8263c8, CONFIG_MICROCRYSTAL_RV_8263_C8_LOG_LEVEL); + +struct rv8263c8_config { + struct i2c_dt_spec i2c_bus; +}; + +struct rv8263c8_data { + struct k_spinlock lock; +}; + +static const struct rtc_driver_api rv8263c8_driver_api = { + .set_time = NULL, + .get_time = NULL, +}; + +static int rv8263c8_init(const struct device *dev) +{ + int err; + const struct rv8263c8_config *config = dev->config; + + if (!i2c_is_ready_dt(&config->i2c_bus)) { + LOG_ERR("I2C bus not ready"); + return -ENODEV; + } + + return 0; +} + +#define RV8263C8_DEFINE(inst) \ + static struct rv8263c8_data rv8263c8_data_##inst; \ + static const struct rv8263c8_config rv8263c8_config_##inst = { \ + .i2c_bus = I2C_DT_SPEC_INST_GET(inst), \ + }; \ + DEVICE_DT_INST_DEFINE(inst, &rv8263c8_init, NULL, &rv8263c8_data_##inst, \ + &rv8263c8_config_##inst, POST_KERNEL, CONFIG_RTC_INIT_PRIORITY, \ + &rv8263c8_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(RV8263C8_DEFINE) \ No newline at end of file diff --git a/app/drivers/rtc/rv8263c8/microcrystal_rv8263c8.h b/app/drivers/rtc/rv8263c8/microcrystal_rv8263c8.h new file mode 100644 index 00000000..7651c51f --- /dev/null +++ b/app/drivers/rtc/rv8263c8/microcrystal_rv8263c8.h @@ -0,0 +1,9 @@ +/* microcrystal_rv8263c8.h - Driver for Micro Crystal RV-8263-C8 RTC. */ + +/* + * Copyright (c 2024, Daniel Kampert + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once \ No newline at end of file diff --git a/app/dts/bindings/rtc/microcrystal,rv-8263-c8.yml b/app/dts/bindings/rtc/microcrystal,rv-8263-c8.yml new file mode 100644 index 00000000..ae935f5a --- /dev/null +++ b/app/dts/bindings/rtc/microcrystal,rv-8263-c8.yml @@ -0,0 +1,9 @@ +description: | + The RV-8263-C8 is a CMOS real-time clock/calendar module optimized for low power consumption. An Offset + register makes it possible to compensate for the frequency deviation of the clock of 32.768 kHz + +compatible: "microcrystal,rv-8263-c8" + +include: [rtc-device.yaml, i2c-device.yaml] + +#properties: \ No newline at end of file diff --git a/app/src/drivers/zsw_buzzer.c b/app/src/drivers/zsw_buzzer.c index f5fcc1d5..ed95e744 100644 --- a/app/src/drivers/zsw_buzzer.c +++ b/app/src/drivers/zsw_buzzer.c @@ -71,22 +71,6 @@ static void buzzer_off_work_handler(struct k_work *work); static void run_next_tone_state(note_duration_t *state); static void pattern_timer_timeout(struct k_timer *timer_id); -static struct note_duration_t funkytown_song[] = { - {.note = C5, .duration = quarter}, - {.note = REST, .duration = eigth}, - {.note = C5, .duration = quarter}, - {.note = Bb4, .duration = quarter}, - {.note = C5, .duration = quarter}, - {.note = REST, .duration = quarter}, - {.note = G4, .duration = quarter}, - {.note = REST, .duration = quarter}, - {.note = G4, .duration = quarter}, - {.note = C5, .duration = quarter}, - {.note = F5, .duration = quarter}, - {.note = E5, .duration = quarter}, - {.note = C5, .duration = quarter} -}; - static struct note_duration_t mario_song[] = { {.note = E6, .duration = quarter}, {.note = REST, .duration = eigth},