Hi there,
How can I copy and customize an existing Zephyr driver?
I'm looking to extend the implementation of the LIS2DH driver in Zephyr.
The driver does not support FIFO, and I want to add it to the original driver, as I assumed that would be the easiest approach—simply copying it into my project and customizing it.
However, this approach has proven more challenging than I expected.
I tried creating a directory in my project:
drivers/sensor/st/lis2dh/
and copied the driver files there.
Then, I modified the CMakeLists.txt
file to include the new paths:
target_include_directories(app PUBLIC
drivers
drivers/sensor
drivers/sensor/st
drivers/sensor/st/lis2dh
)
set(ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/drivers)
set(ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sensor/st/lis2dh)
I also tried adding the driver source file because my IDE flagged errors for all includes in that file:
target_sources(app PRIVATE
drivers/sensor/st/lis2dh/lis2dh.c
)
Additionally, I attempted to create a module.yml
file in the driver directory.
However, when I try to build the project, I run into conflicts with the original driver and its methods.
How can I copy and customize an existing Zephyr driver? (without having to rename all macros and functions)
Thanks!
my overlay:
&spi1 {
status = "okay";
cs-gpios = <&gpio0 28 GPIO_ACTIVE_LOW>;
lis2dh12: lis2dh12@0 {
compatible = "st,lis2dh";
reg = <0>;
spi-max-frequency = <10000000>;
irq-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
// anym-mode = <LIS2DH_DT_ANYM_OR_COMBINATION>;
// anym-on-int1;
};
};