/*
 * Created by jiaqiang.ye@lnxall.com
 *
 * Simple GPIO module
 *
 * 2022/05/11
 */

#ifndef LNXHAL_GPIO_H
#define LNXHAL_GPIO_H 1
#ifdef __cplusplus
extern "C" {
#endif

struct lnxhal_gpio {
    int gpio_num;             /* number of GPIO */
    int gpio_fd;              /* gpio file descriptor */
    int gpio_val;             /* gpio current value */
    unsigned short isout;     /* true if the GPIO works as output */
    unsigned short changed;   /* for GPIO input, indicates that the value has changed */
};

#define LNXHAL_GPIO_MAXNUM    256

struct lnxhal_gpio * lnxhal_gpios_init(int gnum);

int lnxhal_gpio_open(struct lnxhal_gpio * gpios, int gnum);

int lnxhal_gpio_free(struct lnxhal_gpio * gpios, int gnum);

int lnxhal_gpio_poll(struct lnxhal_gpio * gpios, int gnum, int timeo);

int lnxhal_gpio_getval(struct lnxhal_gpio * gpios, int gnum);

int lnxhal_gpio_setval(struct lnxhal_gpio * gpio, int val);

#ifdef __cplusplus
};
#endif
#endif
