-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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: pwm: implement fake-pwm driver #79861
base: main
Are you sure you want to change the base?
drivers: pwm: implement fake-pwm driver #79861
Conversation
9d3d339
to
1aecbfb
Compare
dts/bindings/pwm/fake-pwm.yaml
Outdated
This binding provides a fake PWM for use as either a stub or a mock in Zephyr | ||
testing. | ||
compatible: "fake-pwm" |
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.
prefix with zephyr,
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 updated the compatible and renamed the bindings
1aecbfb
to
55e10bf
Compare
55e10bf
to
8c30a5b
Compare
this looks like a great addition, @anangl can you please help review/approve? |
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.
Have you actually tried to build it for native_sim
? Apparently CI did not do it as no build errors were reported.
drivers/pwm/pwm_fake.c
Outdated
|
||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/pwm.h> | ||
#include <drivers/pwm/pwm_fake.h> |
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.
#include <drivers/pwm/pwm_fake.h> | |
#include <zephyr/drivers/pwm/pwm_fake.h> |
drivers/pwm/pwm_fake.c
Outdated
.frequency_hz = DT_INST_PROP(inst, frequency), \ | ||
}; \ | ||
\ | ||
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &fake_pwm_data_##inst, &fake_pwm_config_##inst, \ |
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_DT_INST_DEFINE(inst, NULL, NULL, &fake_pwm_data_##inst, &fake_pwm_config_##inst, \ | |
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, NULL, &fake_pwm_config_##inst, \ |
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, I updated the code.
}; | ||
|
||
aliases { | ||
pwm-0 = &pwm; |
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.
pwm-0 = &pwm; | |
pwm-0 = &pwm0; |
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, overlay fixed.
|
||
/{ | ||
pwm0: pwm0 { | ||
compatible = "zephyr,fake-pwm"; |
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.
Isn't it needed to add DEFINE_FFF_GLOBALS;
in the test code so that this fake driver can be actually used with it?
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 the test is used for both native_sim and others, how should I proceed to add the DEFINE in the test ? I have not found a twister test that is run both on hardware and on native_sim using FFF.
I tried adding the DEFINE in the test_pwm file under a ifdef HAS_DT
I am actually using the fake_pwm module in a project I have. When I try running the test I indeed see that it is not run. It seems to be filtered out. I added a new test in the testcase. If this is not the right way to do it please tell. I'm not very familiar with testcase filters. I also took the liberty to rebase from latest main branch |
13e4d8a
8c30a5b
to
13e4d8a
Compare
13e4d8a
to
46969b7
Compare
46969b7
to
099f052
Compare
@nono313 looks like you now have CI errors :) |
099f052
to
78d610e
Compare
Thanks for the notice, I started a discussion about it on Discord in #twister |
implement fake-pwm driver with binding using fff Signed-off-by: Nathan Olff <[email protected]>
create native_sim overlay to use fake pwm for test of pwm_api Signed-off-by: Nathan Olff <[email protected]>
78d610e
to
8233d31
Compare
Based on fake can and fake gpio driver, this PR implements a fake pwm driver to be used with native_sim target for unit testing purposes
It only implements basic PWM functionality (no capture)