-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Samples: Introduce device_deinit()
sample
#89927
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
base: main
Are you sure you want to change the base?
Samples: Introduce device_deinit()
sample
#89927
Conversation
device_deinit()
sample
23af243
to
4b2375f
Compare
Note I'm all for chaning the name of the sample and its location :) |
Add DEVICE_DEINIT variants of SPI_DEVICE_ macros. These include - SPI_DEVICE_DT_DEINIT_DEFINE() - SPI_DEVICE_DT_INST_DEINIT_DEFINE() Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Implement device deinit fn for nrf spim device driver. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Implement deinit op in spi_nrfx_spi.c Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Introduce clearirqhandler which clears the irq handler of a peripheral. Useful for device_deinit(). Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Implement deinit op for NXP LPSPI device driver. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Introduce device deinit sample which demonstrates how to share hardware resources between application and device drivers using device_deinit(), specifically between a GPIO port and SPI peripheral. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
4b2375f
to
e34168b
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.
very very cool!
*/ | ||
|
||
&pinctrl { | ||
lpuart0_default: lpuart0_default { |
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.
lpuart0_default: lpuart0_default { | |
lpspi0_default: lpspi0_default { |
}; | ||
|
||
&lpspi0 { | ||
pinctrl-0 = <&lpuart0_default>; |
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.
pinctrl-0 = <&lpuart0_default>; | |
pinctrl-0 = <&lpspi0_default>; |
.. zephyr:code-sample:: deinit | ||
:name: Device deinit | ||
:relevant-api: gpio_interface spi_interface device_model | ||
|
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:code-sample:: deinit | |
:name: Device deinit | |
:relevant-api: gpio_interface spi_interface device_model | |
.. zephyr:code-sample:: deinit | |
:name: Device deinitialization | |
:relevant-api: gpio_interface spi_interface device_model | |
Initialize and deinitialize device drivers at runtime. | |
|
||
static int spi_nrfx_deinit(const struct device *dev) | ||
{ | ||
return 0; |
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 think that when CONFIG_PM_DEVICE=n this function should actually call spim_suspend(dev);
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.
@kl-cruz FYI
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.
100% agree, this PR is a bit out of date, see
zephyr/drivers/spi/spi_nrfx_spim.c
Lines 769 to 788 in ad4c3e3
static int spi_nrfx_deinit(const struct device *dev) | |
{ | |
#if defined(CONFIG_PM_DEVICE) | |
enum pm_device_state state; | |
/* | |
* PM must have suspended the device before driver can | |
* be deinitialized | |
*/ | |
(void)pm_device_state_get(dev, &state); | |
return state == PM_DEVICE_STATE_SUSPENDED || | |
state == PM_DEVICE_STATE_OFF ? | |
0 : -EBUSY; | |
#else | |
/* PM suspend implementation does everything we need */ | |
spim_suspend(dev); | |
#endif | |
return 0; | |
} |
Introduce sample which switches ownership of a pin between a GPIO controller and a SPI controller driver, specifically the CS. This specific usecase has been requested before to be able to monitor the CS pin using GPIO to then wake up and switch to SPI when asserted. Its also a generally useful and portable sample of
device_deinit()
,device_init()
and deferred init.With this, the SPI API is updated with new headers for the _DEINIT variants of SPI_DEVICE_DT_DEFINE, and select SPI device drivers are updated to implement device deinit, drivers for the nRF SPI, nRF SPIM, and NXP LPSPI