śr., 9 paź 2019 o 15:22 Drew Fustini <drew@xxxxxxxx> napisał(a): > > Add pull-up and pull-down flags to libgpiod now that libgpio in the kernel > supports these flags for linehandle_create() and lineevent_create(). > > Signed-off-by: Drew Fustini <drew@xxxxxxxx> > --- > 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(+) > > diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp > index 13b4d5b..0e53e89 100644 > --- a/bindings/cxx/gpiod.hpp > +++ b/bindings/cxx/gpiod.hpp > @@ -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. */ > diff --git a/bindings/cxx/line_bulk.cpp b/bindings/cxx/line_bulk.cpp > index 8369930..7e583ba 100644 > --- a/bindings/cxx/line_bulk.cpp > +++ b/bindings/cxx/line_bulk.cpp > @@ -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 */ > diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c > index 69edbbc..75f33ba 100644 > --- a/bindings/python/gpiodmodule.c > +++ b/bindings/python/gpiodmodule.c > @@ -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, > + }, > { } > }; > > diff --git a/include/gpiod.h b/include/gpiod.h > index 9860ea8..0fe8abd 100644 > --- a/include/gpiod.h > +++ b/include/gpiod.h > @@ -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 */ > }; > > /** > diff --git a/lib/core.c b/lib/core.c > index a04514e..f13c752 100644 > --- a/lib/core.c > +++ b/lib/core.c > @@ -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; > -- > 2.20.1 > Thanks Drew, this looks good, but it'll have to wait for the relevant uAPI to be released in linux. Bart