libgpiod 相关函数

记录学习libgpiod的相关库函数

文章目录


前言


一、bool gpiod_is_gpiochip_device(const char *path);

/**
 * @brief Check if the file pointed to by path is a GPIO chip character device.
 * @param path Path to check.
 * @return True if the file exists and is a GPIO chip character device or a
 *         symbolic link to it.
 */
bool gpiod_is_gpiochip_device(const char *path);

函数功能:检查path指向的文件是否是GPIO芯片字符设备
参数:path是要检查的路径
返回值:如果文件存在并且是GPIO芯片字符设备或符号链接到它,则返回true

二、struct gpiod_chip *gpiod_chip_open(const char *path);

/**
 * @brief Open a gpiochip by path.
 * @param path Path to the gpiochip device file.
 * @return GPIO chip handle or NULL if an error occurred.
 */
struct gpiod_chip *gpiod_chip_open(const char *path);

函数功能:通过路径打开gpiochip
参数:path是gpiochip设备文件的路径
返回值:返回DPIO芯片句柄,如果发生错误就返回NULL

三、struct gpiod_chip *gpiod_chip_ref(struct gpiod_chip *chip);

/**
 * @brief Increase the refcount on this GPIO object.
 * @param chip The GPIO chip object.
 * @return Passed reference to the GPIO chip.
 */
struct gpiod_chip *gpiod_chip_ref(struct gpiod_chip *chip);

函数功能:增加GPIO对象的引用次数
参数:GPIO芯片对象
返回值:返回一个GPIO芯片的引用

四、void gpiod_chip_unref(struct gpiod_chip *chip);

/**
 * @brief Decrease the refcount on this GPIO object. If the refcount reaches 0,
 *        close the chip device and free all associated resources.
 * @param chip The GPIO chip object.
 */
void gpiod_chip_unref(struct gpiod_chip *chip);

函数功能:减少GPIO对象的引用计数,如果引用计算达到0,则关闭芯片设备并释放所有相关资源
参数:GPIO芯片对象
返回值:无

五、const char *gpiod_chip_get_name(struct gpiod_chip *chip);

/**
 * @brief Get the GPIO chip name as represented in the kernel.
 * @param chip The GPIO chip object.
 * @return Pointer to a human-readable string containing the chip name.
 */
const char *gpiod_chip_get_name(struct gpiod_chip *chip);

函数功能:获取内核中表示的芯片名称
参数:GPIO对象
返回值:返回值指向人类刻度的字符串,包括芯片名称

六、const char *gpiod_chip_get_label(struct gpiod_chip *chip);

/**
 * @brief Get the GPIO chip label as represented in the kernel.
 * @param chip The GPIO chip object.
 * @return Pointer to a human-readable string containing the chip label.
 */
const char *gpiod_chip_get_label(struct gpiod_chip *chip);

函数功能:获取内核中GPIO芯片标签
参数:GPIO芯片对象
返回值:返回一个包含芯片标签的人类可读字符串的指针

七、unsigned int gpiod_chip_get_num_lines(struct gpiod_chip *chip);

/**
 * @brief Get the number of GPIO lines exposed by this chip.
 * @param chip The GPIO chip object.
 * @return Number of GPIO lines.
 */
unsigned int gpiod_chip_get_num_lines(struct gpiod_chip *chip);

函数功能:获取该芯片暴露的GPIO行数
参数:GPIO芯片对象
返回值:GPIO的行数

八、struct gpiod_line * gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset);

/**
 * @brief Get the handle to the GPIO line at given offset.
 * @param chip The GPIO chip object.
 * @param offset The offset of the GPIO line.
 * @return Pointer to the GPIO line handle or NULL if an error occured.
 */
struct gpiod_line *
gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset);

函数功能:获得给定偏移量的GPIO行句柄
参数:GPIO芯片对象和GPIO行偏移量
返回值:返回GPIO行句柄的指针,如果发生错误则返回NULL

九、struct gpiod_line_bulk * gpiod_chip_get_lines(struct gpiod_chip *chip, unsigned int *offsets, unsigned int num_offsets);

/**
 * @brief Retrieve a set of lines and store them in a line bulk object.
 * @param chip The GPIO chip object.
 * @param offsets Array of offsets of lines to retrieve.
 * @param num_offsets Number of lines to retrieve.
 * @return New line bulk object or NULL on error.
 */
struct gpiod_line_bulk *
gpiod_chip_get_lines(struct gpiod_chip *chip, unsigned int *offsets,unsigned int num_offsets);

函数功能:获取一组行,并存储在一个行批量对象中
参数:GPIO芯片对象,要检索的行偏移量数组,要检索的行数
返回值:返回换行散装对象,或NULL错误

十、struct gpiod_line_bulk * gpiod_chip_get_all_lines(struct gpiod_chip *chip);

/**
 * @brief Retrieve all lines exposed by a chip and store them in a bulk object.
 * @param chip The GPIO chip object.
 * @return New line bulk object or NULL on error.
 */
struct gpiod_line_bulk *
gpiod_chip_get_all_lines(struct gpiod_chip *chip);

函数功能:检索由芯片暴露的所有行,并存储在一个批量对象
参数:GPIO芯片对象
返回值:返回换行散装对象或NULL错误

十一、int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name);

/**
 * @brief Map a GPIO line's name to its offset within the chip.
 * @param chip The GPIO chip object.
 * @param name Name of the GPIO line to map.
 * @return Offset of the line within the chip or -1 if a line with given name
 *         is not exposed by the chip.
 */
int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name);

函数功能:将GPIO行名映射到芯片内的偏移量
参数:GPIO芯片对象,要映射的GPIO行名
返回值:返回芯片内的行偏移量,如果是给定名称的行,则返回-1.

十二、struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines);

/**
 * @}
 * @defgroup lines GPIO line operations
 * @{
 * Functions and data structures dealing with GPIO lines.
 * @defgroup line_bulk Operating on multiple lines
 * @{
 * Convenience data structures and helper functions for storing and operating
 * on multiple lines at once.
 */
/**
 * @brief Allocate and initialize a new line bulk object.
 * @param max_lines Maximum number of lines this object can hold.
 * @return New line bulk object or NULL on error.
 */
struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines);

函数功能:分配并初始化一个新的行批量对象
参数:该对象可以容纳的最大行数
返回值:返回换行散装对象或NULL错误

十三、void gpiod_line_bulk_reset(struct gpiod_line_bulk *bulk);

/**
 * @brief Reset a bulk object. Remove all lines and set size to 0.
 * @param bulk Bulk object to reset.
 */
void gpiod_line_bulk_reset(struct gpiod_line_bulk *bulk);

函数功能:重置一个批量对象,删除所有行并设置大小为0
参数:要重置的批量对象
返回值:无

十四、void gpiod_line_bulk_free(struct gpiod_line_bulk *bulk);

/**
 * @brief Release all resources allocated for this bulk object.
 * @param bulk Bulk object to free.
 */
void gpiod_line_bulk_free(struct gpiod_line_bulk *bulk);

函数功能:释放分配给这个bulk对象的所有资源
参数:bulk 释放批量对象

十五、int gpiod_line_bulk_add_line(struct gpiod_line_bulk *bulk, struct gpiod_line *line);

/**
 * @brief Add a single line to a GPIO bulk object.
 * @param bulk Line bulk object.
 * @param line Line to add.
 * @return 0 on success, -1 on error.
 * @note The line is added at the next free bulk index.
 *
 * The function can fail if this bulk already holds its maximum amount of
 * lines or if the added line is associated with a different chip than all
 * the other lines already held by this object.
 */
int gpiod_line_bulk_add_line(struct gpiod_line_bulk *bulk,
			     struct gpiod_line *line);

函数功能:给GPIO大容量对象添加一行
参数:bulk行批量对象,line添加的行
返回值:成功返回0,错误返回-1

十六、struct gpiod_line * gpiod_line_bulk_get_line(struct gpiod_line_bulk *bulk, unsigned int index);

/**
 * @brief Retrieve the line handle from a line bulk object at given index.
 * @param bulk Line bulk object.
 * @param index Index of the line to retrieve.
 * @return Line handle at given index or NULL if index is greater or equal to
 *         the number of lines this bulk can hold.
 */
struct gpiod_line *
gpiod_line_bulk_get_line(struct gpiod_line_bulk *bulk, unsigned int index);

函数功能:从给定索引的行块对象中获取行句柄
参数:bulk行批量对象,index要检索行的索引
返回值:返回给定索引处的行句柄,如果检索大于等于,则返回NULL

十七、unsigned int gpiod_line_bulk_num_lines(struct gpiod_line_bulk *bulk);

/**
 * @brief Retrieve the number of GPIO lines held by this line bulk object.
 * @param bulk Line bulk object.
 * @return Number of lines held by this line bulk.
 */
unsigned int gpiod_line_bulk_num_lines(struct gpiod_line_bulk *bulk);

函数功能:获取由linebulk对象保存的GPIO行数
参数:bulk行批量对象
返回值:返回这个行块所包含的行数

十九、void gpiod_line_bulk_foreach_line(struct gpiod_line_bulk *bulk, gpiod_line_bulk_foreach_cb func, void *data);

/**
 * @brief Iterate over all lines held by this bulk object.
 * @param bulk Bulk object to iterate over.
 * @param func Callback to be called for each line.
 * @param data User data pointer that is passed to the callback.
 */
void gpiod_line_bulk_foreach_line(struct gpiod_line_bulk *bulk,
				  gpiod_line_bulk_foreach_cb func,
				  void *data);

函数功能:遍历该bulk对象持有的所有行
参数:bulk要迭代的批量对象,func’为每一行调用回调函数,data是传递给回调函数的用户数据指针
返回值:无

二十、unsigned int gpiod_line_offset(struct gpiod_line *line);

/**
 * @brief Read the GPIO line offset.
 * @param line GPIO line object.
 * @return Line offset.
 */
unsigned int gpiod_line_offset(struct gpiod_line *line);

函数功能:读取GPIO行偏移量
参数:line GPIO行对象
返回值:返回行偏移量

二十一、const char *gpiod_line_name(struct gpiod_line *line);

/**
 * @brief Read the GPIO line name.
 * @param line GPIO line object.
 * @return Name of the GPIO line as it is represented in the kernel. This
 *         routine returns a pointer to a null-terminated string or NULL if
 *         the line is unnamed.
 */
const char *gpiod_line_name(struct gpiod_line *line);

函数功能:读取GPIO行名
参数:line GPIO行对象
返回值:返回在内核中表示的GPIO行名,这例程返回一个指向以NULL结尾的字符串指针,如果该行未命名,返回NULL

二十二、const char *gpiod_line_consumer(struct gpiod_line *line);

/**
 * @brief Read the GPIO line consumer name.
 * @param line GPIO line object.
 * @return Name of the GPIO consumer name as it is represented in the
 *         kernel. This routine returns a pointer to a null-terminated string
 *         or NULL if the line is not used.
 */
const char *gpiod_line_consumer(struct gpiod_line *line);

函数功能:读取GPIO行消费者名称
参数:line GPIO行对象
返回值:返回GPIO客户端在内核中的名称,如果该行未使用,则返回一个指向以空结束的字符串的指针或NULL

二十三、int gpiod_line_direction(struct gpiod_line *line);

/**
 * @brief Read the GPIO line direction setting.
 * @param line GPIO line object.
 * @return Returns GPIOD_LINE_DIRECTION_INPUT or GPIOD_LINE_DIRECTION_OUTPUT.
 */
int gpiod_line_direction(struct gpiod_line *line);

函数功能:读取GPIO行向设置
参数:line GPIO行对象
返回值:返回上述代码中的两个宏之一

二十四、bool gpiod_line_is_active_low(struct gpiod_line *line);

/**
 * @brief Check if the signal of this line is inverted.
 * @param line GPIO line object.
 * @return True if this line is "active-low", false otherwise.
 */
bool gpiod_line_is_active_low(struct gpiod_line *line);

函数功能:检查这一行的信号是否颠倒
参数:GPIO行对象
返回值:如果这一行是"active-low",则返回True,否则返回false

二十五、int gpiod_line_bias(struct gpiod_line *line);

/**
 * @brief Read the GPIO line bias setting.
 * @param line GPIO line object.
 * @return Returns GPIOD_LINE_BIAS_PULL_UP, GPIOD_LINE_BIAS_PULL_DOWN,
 *         GPIOD_LINE_BIAS_DISABLE or GPIOD_LINE_BIAS_UNKNOWN.
 */
int gpiod_line_bias(struct gpiod_line *line);

函数功能:读取GPIO行偏置设置
参数:GPIO行对象
返回值:返回代码中的两个宏之一

二十六、bool gpiod_line_is_used(struct gpiod_line *line);

/**
 * @brief Check if the line is currently in use.
 * @param line GPIO line object.
 * @return True if the line is in use, false otherwise.
 *
 * The user space can't know exactly why a line is busy. It may have been
 * requested by another process or hogged by the kernel. It only matters that
 * the line is used and we can't request it.
 */
bool gpiod_line_is_used(struct gpiod_line *line);

函数功能:检查线路是否正在使用中
参数:line,GPIO行对象
返回值:返回True如果行正在使用,否则false。

二十七、int gpiod_line_drive(struct gpiod_line *line);

/**
 * @brief Read the GPIO line drive setting.
 * @param line GPIO line object.
 * @return Returns GPIOD_LINE_DRIVE_PUSH_PULL, GPIOD_LINE_DRIVE_OPEN_DRAIN or
 *         GPIOD_LINE_DRIVE_OPEN_SOURCE.
 */
int gpiod_line_drive(struct gpiod_line *line);

函数功能:读取GPIO行驱动设置
参数:line GPIO行对象
返回值:返回两个宏之一

二十八、struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line);

int gpiod_line_drive(struct gpiod_line *line);

/**
 * @brief Get the handle to the GPIO chip controlling this line.
 * @param line The GPIO line object.
 * @return Pointer to the GPIO chip handle controlling this line.
 */
struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line);

函数功能:得到控制这一行的GPIO芯片的句柄
参数:line GPIO行对象
返回值:返回指向控制这一行的GPIO芯片句柄的指针

二十九、int gpiod_line_request(struct gpiod_line *line,const struct gpiod_line_request_config *config, int default_val);

/**
 * @brief Reserve a single line.
 * @param line GPIO line object.
 * @param config Request options.
 * @param default_val Initial line value - only relevant if we're setting
 *                    the direction to output.
 * @return 0 if the line was properly reserved. In case of an error this
 *         routine returns -1 and sets the last error number.
 *
 * If this routine succeeds, the caller takes ownership of the GPIO line until
 * it's released.
 */
int gpiod_line_request(struct gpiod_line *line,
		       const struct gpiod_line_request_config *config,
		       int default_val);

函数功能:保留一行
参数:line GPIO行对象,config请求选项,default_val初始行值,只有当我们设置时才相关
返回值:返回0,如果行被正确保留。在错误的情况下,这
例程返回-1并设置最后一个错误号

三十、int gpiod_line_request_input(struct gpiod_line *line, const char *consumer);

/**
 * @brief Reserve a single line, set the direction to input.
 * @param line GPIO line object.
 * @param consumer Name of the consumer.
 * @return 0 if the line was properly reserved, -1 on failure.
 */
int gpiod_line_request_input(struct gpiod_line *line, const char *consumer);

函数功能:保留一行,设置输入方向
参数:line GPIO对象,consumer用户名
返回值:如果行被正确保留,则返回0,如果失败则返回-1

三十一、int gpiod_line_request_output(struct gpiod_line *line,const char *consumer, int default_val);

/**
 * @brief Reserve a single line, set the direction to output.
 * @param line GPIO line object.
 * @param consumer Name of the consumer.
 * @param default_val Initial line value.
 * @return 0 if the line was properly reserved, -1 on failure.
 */
int gpiod_line_request_output(struct gpiod_line *line,
			      const char *consumer, int default_val);

函数功能:保留一行,设置输出方向
参数:line GPIO行对象,consumer用户名,default_val初始行值
返回值:如果行被正确保留,则返回0,如果失败则返回-1

三十二、int gpiod_line_request_rising_edge_events(struct gpiod_line *line, const char *consumer);

/**
 * @brief Request rising edge event notifications on a single line.
 * @param line GPIO line object.
 * @param consumer Name of the consumer.
 * @return 0 if the operation succeeds, -1 on failure.
 */
int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
					  const char *consumer);

函数功能:请求上升边缘事件通知在单行
参数:line GPIO行对象,consumer用户名
返回值:如果操作成功,返回0,如果操作失败,返回-1


有空下次再说,下一篇就写常用的函数就好了,太多了…

头文件中的函数
有缘就把更完,没缘就更常用的部分

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值