linux的gpio操作的api寻找

本文主要介绍了如何在Linux中寻找GPIO操作的API。强调了掌握查找方法的重要性,提供了几个示例,帮助读者理解API的功能,并建议在实际应用中能快速调用相应API。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

linux的gpio操作的api寻找

授人以鱼不如授人以渔,那么,拿人以鱼不如学人以渔
在有需求的时候能够找到对应的寻找点,那么就成功了
文件drivers/gpio/gpiolib.c,所需要的gpio的api都在里面了,例如

/**
 * gpio_export - export a GPIO through sysfs     gpio在sysfs的出口,供用户使用
 * @gpio: gpio to make available, already requested
 * @direction_may_change: true if userspace may change gpio direction
 * Context: arch_initcall or later
 *
 * When drivers want to make a GPIO accessible to userspace after they
 * have requested it -- perhaps while debugging, or as part of their
 * public interface -- they may use this routine.  If the GPIO can
 * change direction (some can't) and the caller allows it, userspace
 * will see "direction" sysfs attribute which may be used to change
 * the gpio's direction.  A "value" attribute will always be provided.
 *
 * Returns zero on success, else an error.
 */
static int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
/**
 * gpio_sysfs_set_active_low - set the polarity of gpio sysfs value
 * @gpio: gpio to change
 * @value: non-zero to use active low, i.e. inverted values
 *
 * Set the polarity of /sys/class/gpio/gpioN/value sysfs attribute.
 * The GPIO does not have to be exported yet.  If poll(2) support has
 * been enabled for either rising or falling edge, it will be
 * reconfigured to follow the new polarity.
 *
 * Returns zero on success, else an error.
 */
static int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value)
/* Drivers MUST set GPIO direction before making get/set calls.  In
 * some cases this is done in early boot, before IRQs are enabled.
 *
 * As a rule these aren't called more than once (except for drivers
 * using the open-drain emulation idiom) so these are natural places
 * to accumulate extra debugging checks.  Note that we can't (yet)
 * rely on gpio_request() having been called beforehand.
 */

static int gpiod_direction_input(struct gpio_desc *desc)

总结

通过以上的几个例子可以看出对应的api都做了些什么事情,方向指在这里,大致掌握一遍,知道有哪些东西,知道可以用来做哪些事,真正需要的时候来这里调用,这已经成了应用工程师做的事情了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值