Skip to contentSkip to conversation

libgpoiod: add pull-up/pull-down flags for gpio lines

PATCH In review Drew Fustini 2 participants 2 messages Oct 9, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libgpoiod: add pull-up/pull-down flags for gpio lines

Add pull-up and pull-down flags to libgpiod now that libgpio in the kernel supports these flags for linehandle_create() and lineevent_create().

---
 bindings/cxx/gpiod.hpp        |  4 ++++
 bindings/cxx/line_bulk.cpp    |  4 ++++
 bindings/python/gpiodmodule.c | 14 ++++++++++++++
 include/gpiod.h               |  4 ++++
 lib/core.c                    |  8 ++++++++
 5 files changed, 34 insertions(+)
bindings/cxx/gpiod.hpp +4 -0
index 13b4d5b..0e53e89 100644
@@ -233,6 +233,10 @@ struct line_request
 	/**< The line is an open-source port. */
 	GPIOD_API static const ::std::bitset<32> FLAG_OPEN_DRAIN;
 	/**< The line is an open-drain port. */
+	GPIOD_API static const ::std::bitset<32> FLAG_PULL_UP;
+	/**< The line is has a configurable pull-up resistor */
+	GPIOD_API static const ::std::bitset<32> FLAG_PULL_DOWN;
+	/**< The line is has a configurable pull-down resistor */
 
 	::std::string consumer;
 	/**< Consumer name to pass to the request. */
bindings/cxx/line_bulk.cpp +4 -0
index 8369930..7e583ba 100644
@@ -14,6 +14,8 @@ namespace gpiod {
 const ::std::bitset<32> line_request::FLAG_ACTIVE_LOW("001");
 const ::std::bitset<32> line_request::FLAG_OPEN_SOURCE("010");
 const ::std::bitset<32> line_request::FLAG_OPEN_DRAIN("100");
+const ::std::bitset<32> line_request::FLAG_PULL_UP("101");
+const ::std::bitset<32> line_request::FLAG_PULL_DOWN("111");
 
 namespace {
 
@@ -38,6 +40,8 @@ const ::std::map<::std::bitset<32>, int, bitset_cmp> reqflag_mapping = {
 	{ line_request::FLAG_ACTIVE_LOW,	GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW, },
 	{ line_request::FLAG_OPEN_DRAIN,	GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN, },
 	{ line_request::FLAG_OPEN_SOURCE,	GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE, },
+	{ line_request::FLAG_PULL_UP,	GPIOD_LINE_REQUEST_FLAG_PULL_UP, },
+	{ line_request::FLAG_PULL_DOWN,	GPIOD_LINE_REQUEST_FLAG_PULL_DOWN, },
 };
 
 } /* namespace */
bindings/python/gpiodmodule.c +14 -0
index 69edbbc..75f33ba 100644
@@ -60,6 +60,8 @@ enum {
 	gpiod_LINE_REQ_FLAG_OPEN_DRAIN		= GPIOD_BIT(0),
 	gpiod_LINE_REQ_FLAG_OPEN_SOURCE		= GPIOD_BIT(1),
 	gpiod_LINE_REQ_FLAG_ACTIVE_LOW		= GPIOD_BIT(2),
+	gpiod_LINE_REQ_FLAG_PULL_UP		= GPIOD_BIT(3),
+	gpiod_LINE_REQ_FLAG_PULL_DOWN		= GPIOD_BIT(4),
 };
 
 enum {
@@ -1032,6 +1034,10 @@ static void gpiod_MakeRequestConfig(struct gpiod_line_request_config *conf,
 		conf->flags |= GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE;
 	if (flags & gpiod_LINE_REQ_FLAG_ACTIVE_LOW)
 		conf->flags |= GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW;
+	if (flags & gpiod_LINE_REQ_FLAG_PULL_UP)
+		conf->flags |= GPIOD_LINE_REQUEST_FLAG_PULL_UP;
+	if (flags & gpiod_LINE_REQ_FLAG_PULL_DOWN)
+		conf->flags |= GPIOD_LINE_REQUEST_FLAG_PULL_DOWN;
 }
 
 PyDoc_STRVAR(gpiod_LineBulk_request_doc,
@@ -2396,6 +2402,14 @@ static gpiod_ModuleConst gpiod_ModuleConsts[] = {
 		.name = "LINE_REQ_FLAG_ACTIVE_LOW",
 		.value = gpiod_LINE_REQ_FLAG_ACTIVE_LOW,
 	},
+	{
+		.name = "LINE_REQ_FLAG_PULL_UP",
+		.value = gpiod_LINE_REQ_FLAG_PULL_UP,
+	},
+	{
+		.name = "LINE_REQ_FLAG_PULL_DOWN",
+		.value = gpiod_LINE_REQ_FLAG_PULL_DOWN,
+	},
 	{ }
 };
 
include/gpiod.h +4 -0
index 9860ea8..0fe8abd 100644
@@ -792,6 +792,10 @@ enum {
 	/**< The line is an open-source port. */
 	GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW	= GPIOD_BIT(2),
 	/**< The active state of the line is low (high is the default). */
+	GPIOD_LINE_REQUEST_FLAG_PULL_UP	= GPIOD_BIT(3),
+	/**< The line can be configured for pull-up resistor */
+	GPIOD_LINE_REQUEST_FLAG_PULL_DOWN	= GPIOD_BIT(4),
+	/**< The line can be configured for pull-down resistor */
 };
 
 /**
lib/core.c +8 -0
index a04514e..f13c752 100644
@@ -494,6 +494,10 @@ static int line_request_values(struct gpiod_line_bulk *bulk,
 		req.flags |= GPIOHANDLE_REQUEST_OPEN_SOURCE;
 	if (config->flags & GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW)
 		req.flags |= GPIOHANDLE_REQUEST_ACTIVE_LOW;
+	if (config->flags & GPIOD_LINE_REQUEST_FLAG_PULL_UP)
+		req.flags |= GPIOHANDLE_REQUEST_PULL_UP;
+	if (config->flags & GPIOD_LINE_REQUEST_FLAG_PULL_DOWN)
+		req.flags |= GPIOHANDLE_REQUEST_PULL_DOWN;
 
 	if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_INPUT)
 		req.flags |= GPIOHANDLE_REQUEST_INPUT;
@@ -556,6 +560,10 @@ static int line_request_event_single(struct gpiod_line *line,
 		req.handleflags |= GPIOHANDLE_REQUEST_OPEN_SOURCE;
 	if (config->flags & GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW)
 		req.handleflags |= GPIOHANDLE_REQUEST_ACTIVE_LOW;
+	if (config->flags & GPIOD_LINE_REQUEST_FLAG_PULL_UP)
+		req.handleflags |= GPIOHANDLE_REQUEST_PULL_UP;
+	if (config->flags & GPIOD_LINE_REQUEST_FLAG_PULL_DOWN)
+		req.handleflags |= GPIOHANDLE_REQUEST_PULL_DOWN;
 
 	if (config->request_type == GPIOD_LINE_REQUEST_EVENT_RISING_EDGE)
 		req.eventflags |= GPIOEVENT_REQUEST_RISING_EDGE;
Signature · 1 line
2.20.1
#1 lore raw

śr., 9 paź 2019 o 15:22 Drew Fustini <[email protected]> napisał(a):

Quoted 131 lines

Add pull-up and pull-down flags to libgpiod now that libgpio in the kernel supports these flags for linehandle_create() and lineevent_create().

---
 bindings/cxx/gpiod.hpp        |  4 ++++
 bindings/cxx/line_bulk.cpp    |  4 ++++
 bindings/python/gpiodmodule.c | 14 ++++++++++++++
 include/gpiod.h               |  4 ++++
 lib/core.c                    |  8 ++++++++
 5 files changed, 34 insertions(+)
bindings/cxx/gpiod.hpp +4 -0
index 13b4d5b..0e53e89 100644
@@ -233,6 +233,10 @@ struct line_request
        /**< The line is an open-source port. */
        GPIOD_API static const ::std::bitset<32> FLAG_OPEN_DRAIN;
        /**< The line is an open-drain port. */
+       GPIOD_API static const ::std::bitset<32> FLAG_PULL_UP;
+       /**< The line is has a configurable pull-up resistor */
+       GPIOD_API static const ::std::bitset<32> FLAG_PULL_DOWN;
+       /**< The line is has a configurable pull-down resistor */
 
        ::std::string consumer;
        /**< Consumer name to pass to the request. */
bindings/cxx/line_bulk.cpp +4 -0
index 8369930..7e583ba 100644
@@ -14,6 +14,8 @@ namespace gpiod {
 const ::std::bitset<32> line_request::FLAG_ACTIVE_LOW("001");
 const ::std::bitset<32> line_request::FLAG_OPEN_SOURCE("010");
 const ::std::bitset<32> line_request::FLAG_OPEN_DRAIN("100");
+const ::std::bitset<32> line_request::FLAG_PULL_UP("101");
+const ::std::bitset<32> line_request::FLAG_PULL_DOWN("111");
 
 namespace {
 
@@ -38,6 +40,8 @@ const ::std::map<::std::bitset<32>, int, bitset_cmp> reqflag_mapping = {
        { line_request::FLAG_ACTIVE_LOW,        GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW, },
        { line_request::FLAG_OPEN_DRAIN,        GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN, },
        { line_request::FLAG_OPEN_SOURCE,       GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE, },
+       { line_request::FLAG_PULL_UP,   GPIOD_LINE_REQUEST_FLAG_PULL_UP, },
+       { line_request::FLAG_PULL_DOWN, GPIOD_LINE_REQUEST_FLAG_PULL_DOWN, },
 };
 
 } /* namespace */
bindings/python/gpiodmodule.c +14 -0
index 69edbbc..75f33ba 100644
@@ -60,6 +60,8 @@ enum {
        gpiod_LINE_REQ_FLAG_OPEN_DRAIN          = GPIOD_BIT(0),
        gpiod_LINE_REQ_FLAG_OPEN_SOURCE         = GPIOD_BIT(1),
        gpiod_LINE_REQ_FLAG_ACTIVE_LOW          = GPIOD_BIT(2),
+       gpiod_LINE_REQ_FLAG_PULL_UP             = GPIOD_BIT(3),
+       gpiod_LINE_REQ_FLAG_PULL_DOWN           = GPIOD_BIT(4),
 };
 
 enum {
@@ -1032,6 +1034,10 @@ static void gpiod_MakeRequestConfig(struct gpiod_line_request_config *conf,
                conf->flags |= GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE;
        if (flags & gpiod_LINE_REQ_FLAG_ACTIVE_LOW)
                conf->flags |= GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW;
+       if (flags & gpiod_LINE_REQ_FLAG_PULL_UP)
+               conf->flags |= GPIOD_LINE_REQUEST_FLAG_PULL_UP;
+       if (flags & gpiod_LINE_REQ_FLAG_PULL_DOWN)
+               conf->flags |= GPIOD_LINE_REQUEST_FLAG_PULL_DOWN;
 }
 
 PyDoc_STRVAR(gpiod_LineBulk_request_doc,
@@ -2396,6 +2402,14 @@ static gpiod_ModuleConst gpiod_ModuleConsts[] = {
                .name = "LINE_REQ_FLAG_ACTIVE_LOW",
                .value = gpiod_LINE_REQ_FLAG_ACTIVE_LOW,
        },
+       {
+               .name = "LINE_REQ_FLAG_PULL_UP",
+               .value = gpiod_LINE_REQ_FLAG_PULL_UP,
+       },
+       {
+               .name = "LINE_REQ_FLAG_PULL_DOWN",
+               .value = gpiod_LINE_REQ_FLAG_PULL_DOWN,
+       },
        { }
 };
 
include/gpiod.h +4 -0
index 9860ea8..0fe8abd 100644
@@ -792,6 +792,10 @@ enum {
        /**< The line is an open-source port. */
        GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW      = GPIOD_BIT(2),
        /**< The active state of the line is low (high is the default). */
+       GPIOD_LINE_REQUEST_FLAG_PULL_UP = GPIOD_BIT(3),
+       /**< The line can be configured for pull-up resistor */
+       GPIOD_LINE_REQUEST_FLAG_PULL_DOWN       = GPIOD_BIT(4),
+       /**< The line can be configured for pull-down resistor */
 };
 
 /**
lib/core.c +8 -1
index a04514e..f13c752 100644
@@ -494,6 +494,10 @@ static int line_request_values(struct gpiod_line_bulk *bulk,
                req.flags |= GPIOHANDLE_REQUEST_OPEN_SOURCE;
        if (config->flags & GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW)
                req.flags |= GPIOHANDLE_REQUEST_ACTIVE_LOW;
+       if (config->flags & GPIOD_LINE_REQUEST_FLAG_PULL_UP)
+               req.flags |= GPIOHANDLE_REQUEST_PULL_UP;
+       if (config->flags & GPIOD_LINE_REQUEST_FLAG_PULL_DOWN)
+               req.flags |= GPIOHANDLE_REQUEST_PULL_DOWN;
 
        if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_INPUT)
                req.flags |= GPIOHANDLE_REQUEST_INPUT;
@@ -556,6 +560,10 @@ static int line_request_event_single(struct gpiod_line *line,
                req.handleflags |= GPIOHANDLE_REQUEST_OPEN_SOURCE;
        if (config->flags & GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW)
                req.handleflags |= GPIOHANDLE_REQUEST_ACTIVE_LOW;
+       if (config->flags & GPIOD_LINE_REQUEST_FLAG_PULL_UP)
+               req.handleflags |= GPIOHANDLE_REQUEST_PULL_UP;
+       if (config->flags & GPIOD_LINE_REQUEST_FLAG_PULL_DOWN)
+               req.handleflags |= GPIOHANDLE_REQUEST_PULL_DOWN;
 
        if (config->request_type == GPIOD_LINE_REQUEST_EVENT_RISING_EDGE)
                req.eventflags |= GPIOEVENT_REQUEST_RISING_EDGE;
--
Quoted 2 lines

2.20.1

Thanks Drew, this looks good, but it'll have to wait for the relevant uAPI to be released in linux.

Bart