diff --git a/boards/silabs/dev_kits/xg24_dk2601b/doc/index.rst b/boards/silabs/dev_kits/xg24_dk2601b/doc/index.rst index 3ed0d292ba0a..769692c66fe2 100644 --- a/boards/silabs/dev_kits/xg24_dk2601b/doc/index.rst +++ b/boards/silabs/dev_kits/xg24_dk2601b/doc/index.rst @@ -69,6 +69,8 @@ The board configuration supports the following hardware features: +-----------+------------+------------------------------------+ | RADIO | on-chip | bluetooth | +-----------+------------+------------------------------------+ +| ACMP | on-chip | comparator | ++-----------+------------+------------------------------------+ Other hardware features are currently not supported by the port. diff --git a/boards/silabs/dev_kits/xg24_dk2601b/xg24_dk2601b.yaml b/boards/silabs/dev_kits/xg24_dk2601b/xg24_dk2601b.yaml index af937c8b4a21..271581b996d9 100644 --- a/boards/silabs/dev_kits/xg24_dk2601b/xg24_dk2601b.yaml +++ b/boards/silabs/dev_kits/xg24_dk2601b/xg24_dk2601b.yaml @@ -15,6 +15,7 @@ supported: - dma - watchdog - clock_control + - comparator testing: ignore_tags: - pm diff --git a/boards/silabs/dev_kits/xg24_ek2703a/doc/index.rst b/boards/silabs/dev_kits/xg24_ek2703a/doc/index.rst index e841838b1be4..5161fa1455dd 100644 --- a/boards/silabs/dev_kits/xg24_ek2703a/doc/index.rst +++ b/boards/silabs/dev_kits/xg24_ek2703a/doc/index.rst @@ -56,6 +56,8 @@ The ``xg24_ek2703a`` board supports the following hardware features: +-----------+------------+-------------------------------------+ | RADIO | on-chip | bluetooth | +-----------+------------+-------------------------------------+ +| ACMP | on-chip | comparator | ++-----------+------------+-------------------------------------+ Other hardware features are currently not supported by the port. diff --git a/boards/silabs/dev_kits/xg24_ek2703a/xg24_ek2703a.yaml b/boards/silabs/dev_kits/xg24_ek2703a/xg24_ek2703a.yaml index 1a5d73e8ebbb..9a0285d44237 100644 --- a/boards/silabs/dev_kits/xg24_ek2703a/xg24_ek2703a.yaml +++ b/boards/silabs/dev_kits/xg24_ek2703a/xg24_ek2703a.yaml @@ -14,6 +14,7 @@ supported: - uart - watchdog - clock_control + - comparator testing: ignore_tags: - pm diff --git a/boards/silabs/dev_kits/xg27_dk2602a/doc/index.rst b/boards/silabs/dev_kits/xg27_dk2602a/doc/index.rst index c700e1cf9c00..19123e7bf0af 100644 --- a/boards/silabs/dev_kits/xg27_dk2602a/doc/index.rst +++ b/boards/silabs/dev_kits/xg27_dk2602a/doc/index.rst @@ -49,6 +49,8 @@ The xg27_dk2602a board configuration supports the following hardware features: +-----------+------------+-------------------------------------+ | DMA | on-chip | ldma | +-----------+------------+-------------------------------------+ +| ACMP | on-chip | comparator | ++-----------+------------+-------------------------------------+ Flashing ======== diff --git a/boards/silabs/dev_kits/xg27_dk2602a/xg27_dk2602a.yaml b/boards/silabs/dev_kits/xg27_dk2602a/xg27_dk2602a.yaml index 1e170e40af5a..230a791b326a 100644 --- a/boards/silabs/dev_kits/xg27_dk2602a/xg27_dk2602a.yaml +++ b/boards/silabs/dev_kits/xg27_dk2602a/xg27_dk2602a.yaml @@ -14,4 +14,5 @@ supported: - uart - dma - clock_control + - comparator vendor: silabs diff --git a/boards/silabs/radio_boards/xg23_rb4210a/doc/index.rst b/boards/silabs/radio_boards/xg23_rb4210a/doc/index.rst index e093f20594d6..b3642243e64a 100644 --- a/boards/silabs/radio_boards/xg23_rb4210a/doc/index.rst +++ b/boards/silabs/radio_boards/xg23_rb4210a/doc/index.rst @@ -66,6 +66,8 @@ The board configuration supports the following hardware features: +-----------+------------+-------------------------------------+ | WATCHDOG | on-chip | watchdog | +-----------+------------+-------------------------------------+ +| ACMP | on-chip | comparator | ++-----------+------------+-------------------------------------+ Other hardware features are currently not supported by the port. diff --git a/boards/silabs/radio_boards/xg23_rb4210a/xg23_rb4210a.yaml b/boards/silabs/radio_boards/xg23_rb4210a/xg23_rb4210a.yaml index a80e566c65a3..1a95532a64fe 100644 --- a/boards/silabs/radio_boards/xg23_rb4210a/xg23_rb4210a.yaml +++ b/boards/silabs/radio_boards/xg23_rb4210a/xg23_rb4210a.yaml @@ -20,6 +20,7 @@ supported: - uart - dma - watchdog + - comparator testing: ignore_tags: - pm diff --git a/boards/silabs/radio_boards/xg24_rb4187c/doc/index.rst b/boards/silabs/radio_boards/xg24_rb4187c/doc/index.rst index f104714f2b3f..ac1dfc1f9a2a 100644 --- a/boards/silabs/radio_boards/xg24_rb4187c/doc/index.rst +++ b/boards/silabs/radio_boards/xg24_rb4187c/doc/index.rst @@ -61,6 +61,8 @@ The board configuration supports the following hardware features: +-----------+------------+-------------------------------------+ | WATCHDOG | on-chip | watchdog | +-----------+------------+-------------------------------------+ +| ACMP | on-chip | comparator | ++-----------+------------+-------------------------------------+ Other hardware features are currently not supported by the port. diff --git a/boards/silabs/radio_boards/xg24_rb4187c/xg24_rb4187c.yaml b/boards/silabs/radio_boards/xg24_rb4187c/xg24_rb4187c.yaml index 3109386af573..705f74253c93 100644 --- a/boards/silabs/radio_boards/xg24_rb4187c/xg24_rb4187c.yaml +++ b/boards/silabs/radio_boards/xg24_rb4187c/xg24_rb4187c.yaml @@ -13,6 +13,7 @@ supported: - uart - dma - watchdog + - comparator testing: ignore_tags: - pm diff --git a/boards/silabs/radio_boards/xg29_rb4412a/doc/index.rst b/boards/silabs/radio_boards/xg29_rb4412a/doc/index.rst index d00a2d086757..85d017f32ffb 100644 --- a/boards/silabs/radio_boards/xg29_rb4412a/doc/index.rst +++ b/boards/silabs/radio_boards/xg29_rb4412a/doc/index.rst @@ -50,6 +50,8 @@ The ``xg29_rb4412a`` board target supports the following hardware features: +-----------+------------+------------------------+ | RADIO | on-chip | bluetooth | +-----------+------------+------------------------+ +| ACMP | on-chip | comparator | ++-----------+------------+------------------------+ Programming and Debugging ************************* diff --git a/boards/silabs/radio_boards/xg29_rb4412a/xg29_rb4412a.yaml b/boards/silabs/radio_boards/xg29_rb4412a/xg29_rb4412a.yaml index 814a49ca9071..989719eda22a 100644 --- a/boards/silabs/radio_boards/xg29_rb4412a/xg29_rb4412a.yaml +++ b/boards/silabs/radio_boards/xg29_rb4412a/xg29_rb4412a.yaml @@ -14,6 +14,7 @@ supported: - uart - dma - watchdog + - comparator testing: ignore_tags: - pm diff --git a/drivers/comparator/CMakeLists.txt b/drivers/comparator/CMakeLists.txt index 43462d64288a..cbfa301d580f 100644 --- a/drivers/comparator/CMakeLists.txt +++ b/drivers/comparator/CMakeLists.txt @@ -6,6 +6,7 @@ zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/comparator.h) zephyr_library() zephyr_library_sources_ifdef(CONFIG_USERSPACE comparator_handlers.c) +zephyr_library_sources_ifdef(CONFIG_COMPARATOR_SILABS_ACMP comparator_silabs_acmp.c) zephyr_library_sources_ifdef(CONFIG_COMPARATOR_FAKE_COMP comparator_fake_comp.c) zephyr_library_sources_ifdef(CONFIG_COMPARATOR_MCUX_ACMP comparator_mcux_acmp.c) zephyr_library_sources_ifdef(CONFIG_COMPARATOR_NRF_COMP comparator_nrf_comp.c) diff --git a/drivers/comparator/Kconfig b/drivers/comparator/Kconfig index 978adc032517..79538a6cc222 100644 --- a/drivers/comparator/Kconfig +++ b/drivers/comparator/Kconfig @@ -19,6 +19,7 @@ config COMPARATOR_INIT_PRIORITY Comparator device driver initialization priority. rsource "Kconfig.fake_comp" +rsource "Kconfig.silabs_acmp" rsource "Kconfig.mcux_acmp" rsource "Kconfig.nrf_comp" rsource "Kconfig.nrf_lpcomp" diff --git a/drivers/comparator/Kconfig.silabs_acmp b/drivers/comparator/Kconfig.silabs_acmp new file mode 100644 index 000000000000..db684e91f9b3 --- /dev/null +++ b/drivers/comparator/Kconfig.silabs_acmp @@ -0,0 +1,12 @@ +# Copyright (c) 2025 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 +config COMPARATOR_SILABS_ACMP + bool "Silabs ACMP comparator driver" + default y + depends on DT_HAS_SILABS_ACMP_ENABLED + select PINCTRL + select SOC_SILABS_ACMP + help + Enable the comparator driver for the Analog Comparator hardware block + present on Silicon Labs devices. This block is commonly used to + monitor the power supply. diff --git a/drivers/comparator/comparator_silabs_acmp.c b/drivers/comparator/comparator_silabs_acmp.c new file mode 100644 index 000000000000..479472f790f0 --- /dev/null +++ b/drivers/comparator/comparator_silabs_acmp.c @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2025 Silicon Laboratories Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(silabs_acmp, CONFIG_COMPARATOR_LOG_LEVEL); + +#define DT_DRV_COMPAT silabs_acmp + +struct acmp_config { + ACMP_TypeDef *base; + const struct pinctrl_dev_config *pincfg; + const struct device *clock_dev; + const struct silabs_clock_control_cmu_config clock_cfg; + void (*irq_init)(void); + ACMP_Init_TypeDef init; + int input_negative; + int input_positive; +}; + +struct acmp_data { + uint32_t interrupt_mask; + comparator_callback_t callback; + void *user_data; +}; + +static int acmp_init(const struct device *dev) +{ + int err; + const struct acmp_config *config = dev->config; + + /* Enable ACMP Clock */ + err = clock_control_on(config->clock_dev, (clock_control_subsys_t)&config->clock_cfg); + if (err < 0) { + return err; + } + + err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); + if (err < 0 && err != -ENOENT) { + LOG_ERR("failed to allocate silabs,analog-bus via pinctrl"); + return err; + } + + /* Initialize the ACMP */ + ACMP_Init(config->base, &config->init); + + /* Configure the ACMP Input Channels */ + ACMP_ChannelSet(config->base, config->input_negative, config->input_positive); + + /* Initialize the irq handler */ + config->irq_init(); + + return 0; +} + +static int acmp_get_output(const struct device *dev) +{ + const struct acmp_config *config = dev->config; + + return config->base->STATUS & ACMP_STATUS_ACMPOUT; +} + +static int acmp_set_trigger(const struct device *dev, enum comparator_trigger trigger) +{ + const struct acmp_config *config = dev->config; + struct acmp_data *data = dev->data; + + /* Disable ACMP trigger interrupts */ + ACMP_IntDisable(config->base, ACMP_IEN_RISE | ACMP_IEN_FALL); + + /* Clear ACMP trigger interrupt flags */ + ACMP_IntClear(config->base, ACMP_IEN_RISE | ACMP_IEN_FALL); + + switch (trigger) { + case COMPARATOR_TRIGGER_BOTH_EDGES: + data->interrupt_mask = ACMP_IEN_RISE | ACMP_IEN_FALL; + break; + case COMPARATOR_TRIGGER_RISING_EDGE: + data->interrupt_mask = ACMP_IEN_RISE; + break; + case COMPARATOR_TRIGGER_FALLING_EDGE: + data->interrupt_mask = ACMP_IEN_FALL; + break; + case COMPARATOR_TRIGGER_NONE: + data->interrupt_mask = 0; + break; + default: + return -EINVAL; + } + + /* Only enable interrupts when the trigger is not none and if a + * callback is set. + */ + if (data->interrupt_mask && data->callback != NULL) { + ACMP_IntEnable(config->base, data->interrupt_mask); + } + + return 0; +} + +static int acmp_set_trigger_callback(const struct device *dev, comparator_callback_t callback, + void *user_data) +{ + const struct acmp_config *config = dev->config; + struct acmp_data *data = dev->data; + + /* Disable ACMP trigger interrupts while setting callback */ + ACMP_IntDisable(config->base, ACMP_IEN_RISE | ACMP_IEN_FALL); + + data->callback = callback; + data->user_data = user_data; + + if (data->callback == NULL) { + return 0; + } + + /* Re-enable currently set ACMP trigger interrupts */ + if (data->interrupt_mask) { + ACMP_IntEnable(config->base, data->interrupt_mask); + } + + return 0; +} + +static int acmp_trigger_is_pending(const struct device *dev) +{ + const struct acmp_config *config = dev->config; + const struct acmp_data *data = dev->data; + + if (ACMP_IntGet(config->base) & data->interrupt_mask) { + ACMP_IntClear(config->base, data->interrupt_mask); + return 1; + } + + return 0; +} + +static void acmp_irq_handler(const struct device *dev) +{ + const struct acmp_config *config = dev->config; + struct acmp_data *data = dev->data; + + ACMP_IntClear(config->base, ACMP_IF_RISE | ACMP_IF_FALL); + + if (data->callback == NULL) { + return; + } + + data->callback(dev, data->user_data); +} + +static DEVICE_API(comparator, acmp_api) = { + .get_output = acmp_get_output, + .set_trigger = acmp_set_trigger, + .set_trigger_callback = acmp_set_trigger_callback, + .trigger_is_pending = acmp_trigger_is_pending, +}; + +#define ACMP_DEVICE(inst) \ + PINCTRL_DT_INST_DEFINE(inst); \ + \ + static void acmp_irq_init##inst(void) \ + { \ + IRQ_CONNECT(DT_INST_IRQN(inst), DT_INST_IRQ(inst, priority), acmp_irq_handler, \ + DEVICE_DT_INST_GET(inst), 0); \ + \ + irq_enable(DT_INST_IRQN(inst)); \ + } \ + \ + static struct acmp_data acmp_data##inst; \ + \ + static const struct acmp_config acmp_config##inst = { \ + .base = (ACMP_TypeDef *)DT_INST_REG_ADDR(inst), \ + .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ + .clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(inst)), \ + .clock_cfg = SILABS_DT_INST_CLOCK_CFG(inst), \ + .irq_init = acmp_irq_init##inst, \ + .init.biasProg = DT_INST_PROP(inst, bias), \ + .init.inputRange = DT_INST_ENUM_IDX(inst, input_range), \ + .init.accuracy = DT_INST_ENUM_IDX(inst, accuracy_mode), \ + .init.hysteresisLevel = DT_INST_ENUM_IDX(inst, hysteresis_mode), \ + .init.inactiveValue = false, \ + .init.vrefDiv = DT_INST_PROP(inst, vref_divider), \ + .init.enable = true, \ + .input_negative = DT_INST_PROP(inst, input_negative), \ + .input_positive = DT_INST_PROP(inst, input_positive), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, acmp_init, NULL, &acmp_data##inst, &acmp_config##inst, \ + POST_KERNEL, CONFIG_COMPARATOR_INIT_PRIORITY, &acmp_api); + +DT_INST_FOREACH_STATUS_OKAY(ACMP_DEVICE) diff --git a/dts/arm/silabs/efr32bg27.dtsi b/dts/arm/silabs/efr32bg27.dtsi index 1a39b55a9753..4afac453eef3 100644 --- a/dts/arm/silabs/efr32bg27.dtsi +++ b/dts/arm/silabs/efr32bg27.dtsi @@ -34,6 +34,13 @@ reg = <0x5003c460 0x4>; clock-frequency = ; }; + acmp0: acmp@5a008000 { + compatible = "silabs,acmp"; + reg = <0x5a008000 0x4000>; + interrupts = <48 0>; + clocks = <&cmu CLOCK_ACMP0 CLOCK_BRANCH_EM01GRPACLK>; + status = "disabled"; + }; }; }; diff --git a/dts/arm/silabs/efr32mg21.dtsi b/dts/arm/silabs/efr32mg21.dtsi index ed0b86efcabb..7ddaf4f65573 100644 --- a/dts/arm/silabs/efr32mg21.dtsi +++ b/dts/arm/silabs/efr32mg21.dtsi @@ -353,6 +353,14 @@ clocks = <&cmu CLOCK_AUTO CLOCK_BRANCH_WDOG1CLK>; status = "disabled"; }; + + acmp0: acmp@0x5a008000 { + compatible = "silabs,acmp"; + reg = <0x5a008000 0x4000>; + interrupts = <41 0>; + clocks = <&cmu CLOCK_AUTO CLOCK_BRANCH_EM01GRPACLK>; + status = "disabled"; + }; }; }; diff --git a/dts/arm/silabs/efr32mg24.dtsi b/dts/arm/silabs/efr32mg24.dtsi index 59929b174467..7bc78ba2d060 100644 --- a/dts/arm/silabs/efr32mg24.dtsi +++ b/dts/arm/silabs/efr32mg24.dtsi @@ -434,6 +434,14 @@ interrupts = <53 0>; status = "disabled"; }; + + acmp0: acmp@59008000 { + compatible = "silabs,acmp"; + reg = <0x59008000 0x4000>; + interrupts = <40 0>; + clocks = <&cmu CLOCK_ACMP0 CLOCK_BRANCH_EM01GRPACLK>; + status = "disabled"; + }; }; diff --git a/dts/arm/silabs/efr32xg23.dtsi b/dts/arm/silabs/efr32xg23.dtsi index ce2124246eff..c9bbaec65a1b 100644 --- a/dts/arm/silabs/efr32xg23.dtsi +++ b/dts/arm/silabs/efr32xg23.dtsi @@ -464,6 +464,14 @@ interrupts = <54 0>; status = "disabled"; }; + + acmp0: acmp@59008000 { + compatible = "silabs,acmp"; + reg = <0x59008000 0x4000>; + interrupts = <41 0>; + clocks = <&cmu CLOCK_ACMP0 CLOCK_BRANCH_EM01GRPACLK>; + status = "disabled"; + }; }; hwinfo: hwinfo { diff --git a/dts/arm/silabs/xg29/xg29.dtsi b/dts/arm/silabs/xg29/xg29.dtsi index 6a9321ed544e..488861bf1adb 100644 --- a/dts/arm/silabs/xg29/xg29.dtsi +++ b/dts/arm/silabs/xg29/xg29.dtsi @@ -437,6 +437,14 @@ #io-channel-cells = <1>; }; + acmp0: acmp@5a008000 { + compatible = "silabs,acmp"; + reg = <0x5a008000 0x4000>; + interrupts = <48 0>; + clocks = <&cmu CLOCK_ACMP0 CLOCK_BRANCH_EM01GRPACLK>; + status = "disabled"; + }; + se: semailbox@4c000000 { compatible = "silabs,gecko-semailbox"; reg = <0x4c000000 0x1000>; diff --git a/dts/bindings/comparator/silabs,acmp.yaml b/dts/bindings/comparator/silabs,acmp.yaml new file mode 100644 index 000000000000..ccd63b5053b0 --- /dev/null +++ b/dts/bindings/comparator/silabs,acmp.yaml @@ -0,0 +1,124 @@ +# Copyright (c) 2025 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 +description: | + Silabs ACMP (Analog Comparator) + + The minimal default configuration for the silabs acmp node is as follows: + + #include + + &acmp0 { + status = "okay"; + + input-positive = ; + input-negative = ; + }; + + Note that there are bindings to retrieve the values for `input-positive` and + `input-negative` properties. See the included bindings in the example above. + + When using the minimal default configuration in the snippet above, some + properties will be implicitly configured with default values. An equivalent + device tree node is therefore as follows: + + #include + + &acmp0 { + status = "okay"; + + bias = <0>; + hysteresis-mode = "disabled"; + accuracy-mode = "low"; + input-range = "full"; + input-positive = ; + input-negative = ; + vref-divider = <63>; + }; + + It is also possible to select a GPIO pin for either/both of the + `input-positive` or `input-negative` properties. In those cases, the + `pinctrl` driver must be configured to allocate an analog bus corresponding + to the port and pin of each GPIO input selected. The following is an example + of how that can be configured: + + #include + #include + + &pinctrl { + acmp0_default: acmp0_default { + group0 { + silabs,analog-bus = ; + }; + }; + }; + + &acmp0 { + pinctrl-0 = <&acmp0_default>; + pinctrl-names = "default"; + status = "okay"; + + bias = <0>; + hysteresis-mode = "disabled"; + accuracy-mode = "low"; + input-range = "full"; + input-positive = ; + input-negative = ; + vref-divider = <63>; + }; + + In the above example, note that the device specific bindings for pinctrl + were included. This header defines the set of analog bus allocations possible + for xg24 parts, and similar headers exist for other parts. + + +compatible: "silabs,acmp" + +include: + - base.yaml + - pinctrl-device.yaml + +properties: + bias: + type: int + default: 0 + + hysteresis-mode: + type: string + enum: + - "disabled" + - "sym10mv" + - "sym20mv" + - "sym30mv" + - "pos10mv" + - "pos20mv" + - "pos30mv" + - "neg10mv" + - "neg20mv" + - "neg30mv" + default: "disabled" + + accuracy-mode: + type: string + enum: + - "low" + - "high" + default: "low" + + input-range: + type: string + enum: + - "full" + - "reduced" + default: "full" + + input-positive: + type: int + required: true + + input-negative: + type: int + required: true + + vref-divider: + type: int + default: 63 diff --git a/include/zephyr/dt-bindings/comparator/silabs-acmp.h b/include/zephyr/dt-bindings/comparator/silabs-acmp.h new file mode 100644 index 000000000000..e326c2b3ebe4 --- /dev/null +++ b/include/zephyr/dt-bindings/comparator/silabs-acmp.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2025 Silicon Laboratories Inc. + * + * SPDX-License-Identifier: Apache-2.0 + * + * This file was generated by the script gen_acmp.py in the hal_silabs module. + * Do not manually edit. + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_COMPARATOR_SILABS_ACMP_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_COMPARATOR_SILABS_ACMP_H_ + +/* ACMP Input Aliases */ +#define ACMP_INPUT_VDACOUT0 ACMP_INPUT_VDAC0OUT0 +#define ACMP_INPUT_VDACOUT1 ACMP_INPUT_VDAC0OUT1 + +/* ACMP Input Definitions */ +#define ACMP_INPUT_VSS 0x0 +#define ACMP_INPUT_VREFDIVAVDD 0x10 +#define ACMP_INPUT_VREFDIVAVDDLP 0x11 +#define ACMP_INPUT_VREFDIV1V25 0x12 +#define ACMP_INPUT_VREFDIV1V25LP 0x13 +#define ACMP_INPUT_VREFDIV2V5 0x14 +#define ACMP_INPUT_VREFDIV2V5LP 0x15 +#define ACMP_INPUT_VSENSE01DIV4 0x20 +#define ACMP_INPUT_VSENSE01DIV4LP 0x21 +#define ACMP_INPUT_VSENSE11DIV4 0x22 +#define ACMP_INPUT_VSENSE11DIV4LP 0x23 +#define ACMP_INPUT_CAPSENSE 0x30 +#define ACMP_INPUT_VDAC0OUT0 0x40 +#define ACMP_INPUT_VDAC0OUT1 0x41 +#define ACMP_INPUT_VDAC1OUT0 0x42 +#define ACMP_INPUT_VDAC1OUT1 0x43 +#define ACMP_INPUT_EXTPA 0x50 +#define ACMP_INPUT_EXTPB 0x51 +#define ACMP_INPUT_EXTPC 0x52 +#define ACMP_INPUT_EXTPD 0x53 +#define ACMP_INPUT_PA0 0x80 +#define ACMP_INPUT_PA1 0x81 +#define ACMP_INPUT_PA2 0x82 +#define ACMP_INPUT_PA3 0x83 +#define ACMP_INPUT_PA4 0x84 +#define ACMP_INPUT_PA5 0x85 +#define ACMP_INPUT_PA6 0x86 +#define ACMP_INPUT_PA7 0x87 +#define ACMP_INPUT_PA8 0x88 +#define ACMP_INPUT_PA9 0x89 +#define ACMP_INPUT_PA10 0x8a +#define ACMP_INPUT_PA11 0x8b +#define ACMP_INPUT_PA12 0x8c +#define ACMP_INPUT_PA13 0x8d +#define ACMP_INPUT_PA14 0x8e +#define ACMP_INPUT_PA15 0x8f +#define ACMP_INPUT_PB0 0x90 +#define ACMP_INPUT_PB1 0x91 +#define ACMP_INPUT_PB2 0x92 +#define ACMP_INPUT_PB3 0x93 +#define ACMP_INPUT_PB4 0x94 +#define ACMP_INPUT_PB5 0x95 +#define ACMP_INPUT_PB6 0x96 +#define ACMP_INPUT_PB7 0x97 +#define ACMP_INPUT_PB8 0x98 +#define ACMP_INPUT_PB9 0x99 +#define ACMP_INPUT_PB10 0x9a +#define ACMP_INPUT_PB11 0x9b +#define ACMP_INPUT_PB12 0x9c +#define ACMP_INPUT_PB13 0x9d +#define ACMP_INPUT_PB14 0x9e +#define ACMP_INPUT_PB15 0x9f +#define ACMP_INPUT_PC0 0xa0 +#define ACMP_INPUT_PC1 0xa1 +#define ACMP_INPUT_PC2 0xa2 +#define ACMP_INPUT_PC3 0xa3 +#define ACMP_INPUT_PC4 0xa4 +#define ACMP_INPUT_PC5 0xa5 +#define ACMP_INPUT_PC6 0xa6 +#define ACMP_INPUT_PC7 0xa7 +#define ACMP_INPUT_PC8 0xa8 +#define ACMP_INPUT_PC9 0xa9 +#define ACMP_INPUT_PC10 0xaa +#define ACMP_INPUT_PC11 0xab +#define ACMP_INPUT_PC12 0xac +#define ACMP_INPUT_PC13 0xad +#define ACMP_INPUT_PC14 0xae +#define ACMP_INPUT_PC15 0xaf +#define ACMP_INPUT_PD0 0xb0 +#define ACMP_INPUT_PD1 0xb1 +#define ACMP_INPUT_PD2 0xb2 +#define ACMP_INPUT_PD3 0xb3 +#define ACMP_INPUT_PD4 0xb4 +#define ACMP_INPUT_PD5 0xb5 +#define ACMP_INPUT_PD6 0xb6 +#define ACMP_INPUT_PD7 0xb7 +#define ACMP_INPUT_PD8 0xb8 +#define ACMP_INPUT_PD9 0xb9 +#define ACMP_INPUT_PD10 0xba +#define ACMP_INPUT_PD11 0xbb +#define ACMP_INPUT_PD12 0xbc +#define ACMP_INPUT_PD13 0xbd +#define ACMP_INPUT_PD14 0xbe +#define ACMP_INPUT_PD15 0xbf + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_COMPARATOR_SILABS_ACMP_H_ */ diff --git a/modules/hal_silabs/simplicity_sdk/CMakeLists.txt b/modules/hal_silabs/simplicity_sdk/CMakeLists.txt index ccd2232cffea..05df125eaa59 100644 --- a/modules/hal_silabs/simplicity_sdk/CMakeLists.txt +++ b/modules/hal_silabs/simplicity_sdk/CMakeLists.txt @@ -209,6 +209,7 @@ if(CONFIG_SOC_GECKO_CORE) SL_CODE_COMPONENT_CORE=core ) endif() +zephyr_library_sources_ifdef(CONFIG_SOC_SILABS_ACMP ${EMLIB_DIR}/src/em_acmp.c) zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_CRYOTIMER ${EMLIB_DIR}/src/em_cryotimer.c) zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_EMU ${EMLIB_DIR}/src/em_emu.c) if(CONFIG_SOC_GECKO_GPIO) diff --git a/soc/silabs/Kconfig b/soc/silabs/Kconfig index 07c20603780a..dcf8de541c63 100644 --- a/soc/silabs/Kconfig +++ b/soc/silabs/Kconfig @@ -23,6 +23,11 @@ config SOC_GECKO_CORE help Set if the Core interrupt handling (CORE) HAL module is used. +config SOC_SILABS_ACMP + bool + help + Set if the Analog comparator (ACMP) HAL module is used. + config SOC_GECKO_ADC bool help diff --git a/tests/drivers/build_all/comparator/silabs_acmp/vsense_avdd.overlay b/tests/drivers/build_all/comparator/silabs_acmp/vsense_avdd.overlay new file mode 100644 index 000000000000..2ab5dafffd13 --- /dev/null +++ b/tests/drivers/build_all/comparator/silabs_acmp/vsense_avdd.overlay @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Silicon Laboratories Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +&acmp0 { + status = "okay"; + + bias = <0>; + hysteresis-mode = "disabled"; + accuracy-mode = "low"; + input-range = "full"; + input-positive = ; + input-negative = ; + vref-divider = <63>; +}; diff --git a/tests/drivers/build_all/comparator/testcase.yaml b/tests/drivers/build_all/comparator/testcase.yaml index ad0161d03e9e..45c239892221 100644 --- a/tests/drivers/build_all/comparator/testcase.yaml +++ b/tests/drivers/build_all/comparator/testcase.yaml @@ -4,6 +4,16 @@ common: - drivers - comparator tests: + drivers.build_all.comparator.silabs_acmp.vsense_avdd: + extra_args: + - DTC_OVERLAY_FILE="silabs_acmp/vsense_avdd.overlay" + platform_allow: + - xg23_rb4210a + - xg24_dk2601b + - xg24_ek2703a + - xg24_rb4187c + - xg27_dk2602a + - xg29_rb4412a drivers.build_all.comparator.nrf_comp.diff: extra_args: - DTC_OVERLAY_FILE="nrf_comp/diff.overlay" diff --git a/tests/drivers/comparator/gpio_loopback/boards/xg24_dk2601b.overlay b/tests/drivers/comparator/gpio_loopback/boards/xg24_dk2601b.overlay new file mode 100644 index 000000000000..d4759d66a20a --- /dev/null +++ b/tests/drivers/comparator/gpio_loopback/boards/xg24_dk2601b.overlay @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Silicon Laboratories Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +/ { + aliases { + test-comp = &acmp0; + }; + + zephyr,user { + test-gpios = <&gpioc 3 GPIO_ACTIVE_HIGH>; + }; + +}; + +&pinctrl { + acmp0_default: acmp0_default { + group0 { + silabs,analog-bus = ; + }; + }; +}; + +&acmp0 { + pinctrl-0 = <&acmp0_default>; + pinctrl-names = "default"; + status = "okay"; + + hysteresis-mode = "disabled"; + accuracy-mode = "high"; + input-range = "full"; + input-positive = ; + input-negative = ; + vref-divider = <63>; +}; diff --git a/tests/drivers/comparator/gpio_loopback/boards/xg29_rb4412a.overlay b/tests/drivers/comparator/gpio_loopback/boards/xg29_rb4412a.overlay new file mode 100644 index 000000000000..2930ea787884 --- /dev/null +++ b/tests/drivers/comparator/gpio_loopback/boards/xg29_rb4412a.overlay @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Silicon Laboratories Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +/ { + aliases { + test-comp = &acmp0; + }; + + zephyr,user { + test-gpios = <&gpioc 3 GPIO_ACTIVE_HIGH>; + }; + +}; + +&pinctrl { + acmp0_default: acmp0_default { + group0 { + silabs,analog-bus = ; + }; + }; +}; + +&acmp0 { + pinctrl-0 = <&acmp0_default>; + pinctrl-names = "default"; + status = "okay"; + + bias = <0>; + hysteresis-mode = "disabled"; + accuracy-mode = "high"; + input-range = "full"; + input-positive = ; + input-negative = ; + vref-divider = <63>; +}; diff --git a/tests/drivers/comparator/gpio_loopback/testcase.yaml b/tests/drivers/comparator/gpio_loopback/testcase.yaml index beb5cd392765..ac3e43cb0480 100644 --- a/tests/drivers/comparator/gpio_loopback/testcase.yaml +++ b/tests/drivers/comparator/gpio_loopback/testcase.yaml @@ -8,6 +8,10 @@ common: - drivers - comparator tests: + drivers.comparator.gpio_loopback.silabs_acmp: + platform_allow: + - xg24_dk2601b + - xg29_rb4412a drivers.comparator.gpio_loopback.mcux_acmp: platform_allow: - frdm_ke15z