-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: sensors: silabs: add gecko acmp #83531
base: main
Are you sure you want to change the base?
drivers: sensors: silabs: add gecko acmp #83531
Conversation
- Enable ACMP hal in hal_silabs module Signed-off-by: Romain Pelletant <[email protected]>
- Enable ACMP HAL module for silabs gecko Signed-off-by: Romain Pelletant <[email protected]>
90db07d
to
26cafa8
Compare
- Add SiLabs Gecko ACMP sensor driver Signed-off-by: Romain Pelletant <[email protected]>
8d965a7
to
91032c1
Compare
- Add ACMP peripheral nodes for EFR32MG24 Signed-off-by: Romain Pelletant <[email protected]>
- Add sample for Gecko ACMP sensor driver Signed-off-by: Romain Pelletant <[email protected]>
91032c1
to
cf51ed1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @RomainPelletant !
I have 2 general questions:
- Is there any reason why you didn't use the comparator device API? It feels that it is a better place for this driver ?
- I see that you use em_cmu.h for clock and use function like CMU_ClockEnable(). Normally, on all series 2 boards (like the efr32mg24), we support clock control API which allows to directly use clock_control() functions. CMU_ClockEnable only need to be used in case that you want to use the driver for an old device (series 0 and series 1 boards). As it is also not tested on series 0 and 1, I suggest to keep the code clearer and only use clock_control API. What's your opinion ?
return 0; | ||
} | ||
|
||
static const struct sensor_driver_api gecko_acmp_driver_api = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a fairly new convention but I believe this should be using DEVICE_API().
Hello @Martinhoff-maker, thank you for reviewing and good questions.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SENSOR_CHAN_GECKO_ACMP_RISING_EDGE_COUNTER, | ||
/** ACMP falling edge counter. */ | ||
SENSOR_CHAN_GECKO_ACMP_FALLING_EDGE_COUNTER, | ||
#endif /* CONFIG_GECKO_ACMP_EDGE_COUNTER */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to keep definitions of SENSOR_CHAN_GECKO_ACMP_*_EDGE_COUNTER
even if CONFIG_GECKO_ACMP_EDGE_COUNTER
. Thus, the caller code will simpler (it will be probably able to remove some a #ifdef, or at least to change them is IS_ENABLE()
).
BTW, I wonder if it make sense to make all these features optional. This leads to increased maintenance cost. It make sense to make a feature optional if you could get rid of a dependency.
- "FallingEdge" # Interrupt on falling edge | ||
- "RisingEdge" # Interrupt on rising edge | ||
- "BothEdge" # Interrupt on both edges | ||
default: "Off" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Device Tree aims to includes required hardware configuration to have a working system. I feel the options above should rather be set during runtime. Maybe some of them should be replaced by sensor_attribute
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sensor attribute is only available on Sensor API. Can you tell me why you are talking about that while you're considering comparator API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to admit this is subjective thing.
comparator_set_trigger()
allows to change the trigger during the runtime (which is the attribute that make me raise the eyebrows).- Documentation of the comparator framework explicitly explain it is designed to watch power supply. In this case, it make sense the DT describe what is the power supply.
- Sensor framework is designed to make data acquisition. In this case, it sound more logical the application choose what data it wants to read.
static struct gecko_acmp_data gecko_acmp_data_##n = { \ | ||
.acmp_config = ACMP_INIT_DEFAULT, \ | ||
}; \ | ||
static const struct gecko_acmp_config gecko_acmp_config_##n; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call GECKO_ACMP_INIT_CONFIG()
before SENSOR_DEVICE_DT_INST_DEFINE()
and get rid of this line.
&gecko_acmp_config_##n, POST_KERNEL, \ | ||
CONFIG_SENSOR_INIT_PRIORITY, &gecko_acmp_driver_api); \ | ||
GECKO_ACMP_CONFIG_FUNC(n) \ | ||
GECKO_ACMP_INIT_CONFIG(n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GECKO_ACMP_INIT_CONFIG()
seems useless. Instead, you can inline the declaration of gecko_acmp_config_##n
.
CMU_Clock_TypeDef clock; | ||
#ifdef CONFIG_GECKO_ACMP_TRIGGER | ||
void (*irq_config_func)(const struct device *dev); | ||
#endif /* CONFIG_GECKO_ACMP_TRIGGER */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid to repeat the condition after #endif
if the condition is obvious (because of the Don't Repeat Yourself rule).
data->falling_edge_counter = atomic_clear(&data->falling_events); | ||
#endif /* CONFIG_GECKO_ACMP_EDGE_COUNTER */ | ||
|
||
data->cout = (config->base->STATUS & ACMP_STATUS_ACMPOUT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parentheses are not required.
CMU_ClockSelectSet(config->clock, cmuSelect_LFRCO); | ||
#endif | ||
|
||
CMU_ClockEnable(config->clock, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zephyr prefers to use the Zephyr API to manage clocks (clock_enable()
). This API only exist on Series-2. However, since Series-0/1 is deprecated and it seems you mainly target xg24, I suggest to use clock_enable()
and drop support for Series-1.
Once you only support Series-2, it will probably not make sense anymore to call this driver "gecko" ("gecko" is for Series 0/1 only). Probably "silabs,acmp"
will be better.
const struct gecko_acmp_config *config = dev->config; | ||
struct gecko_acmp_data *data = dev->data; | ||
|
||
__ASSERT_NO_MSG(val != NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... I believe val
is not defined.
CMU_ClockEnable(config->clock, false); | ||
#endif /* CONFIG_GECKO_ACMP_DISABLE_ON_SUSPEND */ | ||
#if CONFIG_GECKO_ACMP_DISABLE_INTERRUPT_ON_SUSPEND | ||
NVIC_DisableIRQ(ACMP_IRQ_NUM(config->base)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for the clock, I suggest to use Zephyr API for IRQ management.
I believe both option can be accepted. The API described in |
@RomainPelletant FYI, another contributor also contacted me because he started a driver for ACMP. His implementation is rather different because it is based on the comparator framework. |
@jerome-pouiller if someone else has a better proposal I won't force anything: please let me know and I will give up on this PR |
@RomainPelletant, @silabs-chgalant has shared an early version of his work here: #83980. Your feedback would be valuable. |
Fixes #83529