Hello Bowen,
Thank you for responding to my question. Yes I think the relay framework
will do what I want, I will try it out.
Kind regards
Stewart Charnell
On 17/01/2024 03:23, 汪博文 wrote:
Hello,
I'm Bowen Wang and nice to answer your question. Please correct me If
I understand wrong.
I think you want to use the relay framework
in nuttx/drivers/power/relay/relay.c and relay_gpio.c,
which are added by me in PR: power/relay: add relay driver framework
for NuttX by CV-Bowen · Pull Request #7954 · apache/nuttx (github.com)
<https://github.com/apache/nuttx/pull/7954>.
The realy framework has two part:
1. The first part is relay.c, relay.c did a very simple thing: convert
user ioctl(RELAYIOC_SET/GET) to the relay driver implemented
dev->ops->set()/get(),
and you can follow the following steps to implement a relay driver:
a. implement the relay ops (set()/get());
b. call relay_register() to register your relay driver (just like
relay_gpio.c does);
2. The second part is relay_gpio.c, relay_gpio.c base on the *alreay
implemented* gpio driver (ioexpander) to resigter a relay driver, so
if you has implemented
a ioexpander driver, you can enable config: CONFIG_RELAY_GPIO and then
call relay_gpio_register() to register a driver, a simple example in
sim is:
```c
diff --git a/boards/sim/sim/sim/src/sim_ioexpander.c
b/boards/sim/sim/sim/src/sim_ioexpander.c
index 599ac68743..9397967a24 100644
--- a/boards/sim/sim/sim/src/sim_ioexpander.c
+++ b/boards/sim/sim/sim/src/sim_ioexpander.c
@@ -29,6 +29,7 @@
#include <nuttx/ioexpander/gpio.h>
#include <nuttx/ioexpander/ioe_dummy.h>
+#include <nuttx/power/relay.h>
#include "sim.h"
@@ -76,6 +77,11 @@ int sim_gpio_initialize(void)
IOEXP_SETOPTION(ioe, 1, IOEXPANDER_OPTION_INTCFG,
(void *)IOEXPANDER_VAL_DISABLE);
gpio_lower_half(ioe, 1, GPIO_OUTPUT_PIN, 1);
+ int ret = relay_gpio_register(ioe, 1, false, "/dev/relay0");
+ if (ret < 0)
+ {
+ _err("relay register error\n");
+ }
/* Pin 2: an non-inverted, edge interrupting pin */
```
And I'm sorry that I missed the docs and examples about the new added
relay framework, I will add this later.
Kind regards
Bowen Wang
------------------------------------------------------------------------
Bowen Wang, wangbow...@xiaomi.com
*From:* Stewart Charnell <mailto:nu...@charnell.plus.com>
*Date:* 2024-01-17 04:33
*To:* dev@nuttx.apache.org
*Subject:* [External Mail][Quarantine]GPIO drivers
Hello,
I have a processor board with GPIO ports which I would like to use to
control such things as relays and PSU enable pins.
Do I need to write a GPIO driver? There is an I/O expander driver. Is
the I/O expander driver specific to expanders or can it be used
for GPIO
control?
Kind regards
Stewart Charnell
#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!
This e-mail and its attachments contain confidential information from
XIAOMI, which is intended only for the person or entity whose address
is listed above. Any use of the information contained herein in any
way (including, but not limited to, total or partial disclosure,
reproduction, or dissemination) by persons other than the intended
recipient(s) is prohibited. If you receive this e-mail in error,
please notify the sender by phone or email immediately and delete
it!******/#