Skip to content
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

Add lis2du12 accelerometer driver #65734

Merged
merged 4 commits into from Dec 14, 2023

Conversation

avisconti
Copy link
Collaborator

The LIS2DU12 is a linear ultralow power 3-axis accelerometer sensor.
This driver is based on stmemsc HAL i/f v2.3

@avisconti
Copy link
Collaborator Author

Any feedback here?

drivers/sensor/lis2du12/lis2du12.c Show resolved Hide resolved
case SENSOR_ATTR_SAMPLING_FREQUENCY:
return lis2du12_accel_odr_set(dev, val->val1);
default:
LOG_DBG("Accel attribute not supported.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be a LOG_WRN and print the value of attr

Copy link
Collaborator Author

@avisconti avisconti Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put LOG_ERR here with attribute. Do you feel a warning would be more approriate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would do warning here and keep errors for stuff that breaks the driver permanently, like initialization errors.

drivers/sensor/lis2du12/lis2du12.c Outdated Show resolved Hide resolved
drivers/sensor/lis2du12/lis2du12.c Outdated Show resolved Hide resolved
tests/drivers/build_all/sensor/i2c.dtsi Outdated Show resolved Hide resolved
drivers/sensor/lis2du12/lis2du12_trigger.c Outdated Show resolved Hide resolved
drivers/sensor/lis2du12/lis2du12_trigger.c Outdated Show resolved Hide resolved
drivers/sensor/lis2du12/lis2du12_trigger.c Outdated Show resolved Hide resolved
Comment on lines 29 to 30
#define LIS2DU12_EN_BIT 0x01
#define LIS2DU12_DIS_BIT 0x00
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indentation looks funny, I'd sugget to just use a space

#define LIS2DU12_EN_BIT	 0x01
#define LIS2DU12_DIS_BIT 0x00

no need to make it fancy, same below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmh, I think that maybe tabs are better. But I'd agree to shorten it a bit and align with below

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just a space... it's just two, I wouldn't bother.

boards/arm/sensortile_box_pro/sensortile_box_pro.dts Outdated Show resolved Hide resolved
drivers/sensor/lis2du12/Kconfig Outdated Show resolved Hide resolved
Comment on lines 18 to 38
if LIS2DU12

choice LIS2DU12_TRIGGER_MODE
prompt "Trigger mode"
help
Specify the type of triggering to be used by the driver.

config LIS2DU12_TRIGGER_NONE
bool "No trigger"

config LIS2DU12_TRIGGER_GLOBAL_THREAD
bool "Use global thread"
depends on GPIO
select LIS2DU12_TRIGGER

config LIS2DU12_TRIGGER_OWN_THREAD
bool "Use own thread"
depends on GPIO
select LIS2DU12_TRIGGER

endchoice
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this PR but let me pitch the idea to you: this pattern of having an option for how to handle asyncronous events (thread, workqueue) is copypasted everywhere. How would you feel about having a Kconfig template to define these options (like the log one, the one you use with source "subsys/logging/Kconfig.template.log_config") and then common set of of macro to prepare and use the support data for the selected operating mode? (thread, workqueue, syncronous or none)

Haven't quite tried to do it but I think it could remove lot of duplicated code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks a great idea. Let me explore more on that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Collaborator Author

@avisconti avisconti Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, take a look just to see if I did it in the way you wanted to (not 100% sure)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brilliant, yeah I was actually thinking about also having a set of macros to dedup the code as well but this is a brilliant start and a step towards it, thanks for doing it, let's think about the code in followups

@MaureenHelm @teburd what do you think?

Copy link
Collaborator

@teburd teburd Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great, though to be frank I'd rather see us move in the newer sensor read API approach which avoids the need for work queues/threads at all and so the entire Kconfig around work queue or thread for trigger handling goes away.

drivers/sensor/lis2du12/lis2du12.c Outdated Show resolved Hide resolved
teburd
teburd previously approved these changes Dec 12, 2023
Add Kconfig.trigger_template to allow an extensive re-use of
trigger configuration inside all sensor drivers.

This template must be included as in the following example:

    module = LSM6DSO
    thread_priority = 10
    thread_stack_size = 1024
    source "drivers/sensor/Kconfig.trigger_template"

Signed-off-by: Armando Visconti <armando.visconti@st.com>
The LIS2DU12 is a linear 3-axis accelerometer with advanced digital
functions whose MEMS and ASIC have been expressly designed to build
an outstanding ultralow-power architecture in which the anti-aliasing
filter operates with a current consumption among the lowest in the
market.
This driver is based on stmemsc HAL i/f v2.3

https://www.st.com/en/datasheet/lis2du12.pdf

Signed-off-by: Armando Visconti <armando.visconti@st.com>
Extend sensortile_box_pro with lis2du12 accelerometer.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
Extend sensor sample reading also lis2du12 accelerometer data.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
@carlescufi carlescufi merged commit 3fe0ffb into zephyrproject-rtos:main Dec 14, 2023
19 checks passed
@avisconti avisconti deleted the add-lis2du12 branch December 14, 2023 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants