Skip to content

Commit

Permalink
gpio: add pull up/down flags
Browse files Browse the repository at this point in the history
Signed-off-by: Nascs <[email protected]>
Co-authored-by: ZHANG Yuntian <[email protected]>
  • Loading branch information
nascs and RadxaYuntian committed Mar 7, 2024
1 parent e1bd6a3 commit 06de47f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/mraa/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef enum {
MRAA_GPIOD_ACTIVE_LOW = 4,
MRAA_GPIOD_OPEN_DRAIN = 5,
MRAA_GPIOD_OPEN_SOURCE = 6,
MRAA_GPIOD_BIAS_DISABLE = 7,
} mraa_gpio_mode_t;

/**
Expand Down
3 changes: 3 additions & 0 deletions include/gpio/gpio_chardev.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ mraa_boolean_t mraa_is_gpio_line_dir_out(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_active_low(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_open_drain(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_open_source(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_bias_pull_up(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_bias_pull_down(mraa_gpiod_line_info *linfo);
mraa_boolean_t mraa_is_gpio_line_bias_disable(mraa_gpiod_line_info *linfo);

int mraa_get_number_of_gpio_chips();
int mraa_get_chip_infos(mraa_gpiod_chip_info*** cinfos);
Expand Down
6 changes: 6 additions & 0 deletions include/linux/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ struct gpiochip_info {
#define GPIOLINE_FLAG_ACTIVE_LOW (1UL << 2)
#define GPIOLINE_FLAG_OPEN_DRAIN (1UL << 3)
#define GPIOLINE_FLAG_OPEN_SOURCE (1UL << 4)
#define GPIOLINE_FLAG_BIAS_PULL_UP (1UL << 5)
#define GPIOLINE_FLAG_BIAS_PULL_DOWN (1UL << 6)
#define GPIOLINE_FLAG_BIAS_DISABLE (1UL << 7)

struct gpioline_info {
__u32 line_offset;
Expand All @@ -36,6 +39,9 @@ struct gpioline_info {
#define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2)
#define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3)
#define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4)
#define GPIOHANDLE_REQUEST_BIAS_PULL_UP (1UL << 5)
#define GPIOHANDLE_REQUEST_BIAS_PULL_DOWN (1UL << 6)
#define GPIOHANDLE_REQUEST_BIAS_DISABLE (1UL << 7)

struct gpiohandle_request {
__u32 lineoffsets[GPIOHANDLES_MAX];
Expand Down
9 changes: 9 additions & 0 deletions src/gpio/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,15 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
case MRAA_GPIOD_OPEN_SOURCE:
flags |= GPIOHANDLE_REQUEST_OPEN_SOURCE;
break;
case MRAA_GPIO_PULLUP:
flags |= GPIOHANDLE_REQUEST_BIAS_PULL_UP;
break;
case MRAA_GPIO_PULLDOWN:
flags |= GPIOHANDLE_REQUEST_BIAS_PULL_DOWN;
break;
case MRAA_GPIOD_BIAS_DISABLE:
flags |= GPIOHANDLE_REQUEST_BIAS_DISABLE;
break;
default:
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
Expand Down
18 changes: 18 additions & 0 deletions src/gpio/gpio_chardev.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,24 @@ mraa_is_gpio_line_open_source(mraa_gpiod_line_info* linfo)
return (linfo->flags & GPIOLINE_FLAG_OPEN_SOURCE);
}

mraa_boolean_t
mraa_is_gpio_line_bias_pull_up(mraa_gpiod_line_info* linfo)
{
return (linfo->flags & GPIOLINE_FLAG_BIAS_PULL_UP);
}

mraa_boolean_t
mraa_is_gpio_line_bias_pull_down(mraa_gpiod_line_info* linfo)
{
return (linfo->flags & GPIOLINE_FLAG_BIAS_PULL_DOWN);
}

mraa_boolean_t
mraa_is_gpio_line_bias_disable(mraa_gpiod_line_info* linfo)
{
return (linfo->flags & GPIOLINE_FLAG_BIAS_DISABLE);
}

static int
dir_filter(const struct dirent* dir)
{
Expand Down

0 comments on commit 06de47f

Please sign in to comment.