linux的gpio操作的api寻找

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都做了些什么事情,方向指在这里,大致掌握一遍,知道有哪些东西,知道可以用来做哪些事,真正需要的时候来这里调用,这已经成了应用工程师做的事情了。

猜你喜欢

转载自blog.csdn.net/deggfg/article/details/88176084
今日推荐