treewide: simplify the active-low line property
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Wed, 16 Dec 2020 12:19:59 +0000 (13:19 +0100)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Thu, 17 Dec 2020 17:04:17 +0000 (18:04 +0100)
Unlike line direction - where input and output modes are equal, no signal
inversion (active-high) is the natural state of the line while active-low
is less likely. Let's drop the ACTIVE_STATE enum treewide and provide a
boolean property for lines - is_active_low() - to reflect that fact. This
function returning false means the line is "active-high".

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
bindings/cxx/examples/gpioinfocxx.cpp
bindings/cxx/gpiod.hpp
bindings/cxx/line.cpp
bindings/cxx/tests/tests-line.cpp
bindings/python/examples/gpioinfo.py
bindings/python/gpiodmodule.c
bindings/python/tests/gpiod_py_test.py
include/gpiod.h
lib/core.c
tests/tests-line.c
tools/gpioinfo.c

index 2490abdf1290a29965ee0bca85d7cc6082a13ba9..384286ee2952b3b3f769a9ba7f34d694c02e0853 100644 (file)
@@ -44,8 +44,7 @@ int main(int argc, char **argv)
                                ::std::cout << " ";
 
                                ::std::cout.width(10);
-                               ::std::cout << (lit.active_state() == ::gpiod::line::ACTIVE_LOW
-                                                                       ? "active-low" : "active-high");
+                               ::std::cout << (lit.is_active_low() ? "active-low" : "active-high");
 
                                ::std::cout << ::std::endl;
                        }
index 6c9ccd63103de994f4f3bfca34f7ddf10f5fec4c..8b4a8f9a48b7ca523137a2aae3aa62524749ddab 100644 (file)
@@ -313,10 +313,10 @@ public:
        GPIOD_API int direction(void) const;
 
        /**
-        * @brief Get current active state of this line.
-        * @return Current active state setting.
+        * @brief Check if this line's signal is inverted.
+        * @return True if this line is "active-low", false otherwise.
         */
-       GPIOD_API int active_state(void) const;
+       GPIOD_API bool is_active_low(void) const;
 
        /**
         * @brief Get current bias of this line.
@@ -482,16 +482,6 @@ public:
                /**< Line's direction setting is output. */
        };
 
-       /**
-        * @brief Possible active state settings.
-        */
-       enum : int {
-               ACTIVE_LOW = 1,
-               /**< Line's active state is low. */
-               ACTIVE_HIGH,
-               /**< Line's active state is high. */
-       };
-
        /**
         * @brief Possible bias settings.
         */
index 54382e2283b470ae5fe957a8edeb7b80d59fea57..5a907dbd12d6a0065e6c64d90b044edc46ba54b6 100644 (file)
@@ -74,14 +74,12 @@ int line::direction(void) const
        return dir == GPIOD_LINE_DIRECTION_INPUT ? DIRECTION_INPUT : DIRECTION_OUTPUT;
 }
 
-int line::active_state(void) const
+bool line::is_active_low(void) const
 {
        this->throw_if_null();
        line::chip_guard lock_chip(*this);
 
-       int active = ::gpiod_line_active_state(this->_m_line);
-
-       return active == GPIOD_LINE_ACTIVE_STATE_HIGH ? ACTIVE_HIGH : ACTIVE_LOW;
+       return ::gpiod_line_is_active_low(this->_m_line);
 }
 
 int line::bias(void) const
index 53b1d03935e1e0a8dfee3b91883d425bb5c9f48e..3c7ea39dbf9311b25cdfe4d8a8288265bbd06acf 100644 (file)
@@ -29,7 +29,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.offset() == 4);
                REQUIRE(line.name() == "gpio-mockup-A-4");
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_INPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());
                REQUIRE(line.consumer().empty());
                REQUIRE_FALSE(line.is_requested());
                REQUIRE_FALSE(line.is_used());
@@ -49,7 +49,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.offset() == 4);
                REQUIRE(line.name() == "gpio-mockup-A-4");
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());
                REQUIRE(line.is_requested());
                REQUIRE(line.is_used());
                REQUIRE_FALSE(line.is_open_drain());
@@ -70,7 +70,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.offset() == 4);
                REQUIRE(line.name() == "gpio-mockup-A-4");
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_LOW);
+               REQUIRE(line.is_active_low());
                REQUIRE(line.is_requested());
                REQUIRE(line.is_used());
                REQUIRE(line.is_open_drain());
@@ -90,7 +90,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.offset() == 4);
                REQUIRE(line.name() == "gpio-mockup-A-4");
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());
                REQUIRE(line.is_requested());
                REQUIRE(line.is_used());
                REQUIRE_FALSE(line.is_open_drain());
@@ -110,7 +110,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.offset() == 4);
                REQUIRE(line.name() == "gpio-mockup-A-4");
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());
                REQUIRE(line.is_requested());
                REQUIRE(line.is_used());
                REQUIRE_FALSE(line.is_open_drain());
@@ -130,7 +130,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.offset() == 4);
                REQUIRE(line.name() == "gpio-mockup-A-4");
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());;
                REQUIRE(line.is_requested());
                REQUIRE(line.is_used());
                REQUIRE_FALSE(line.is_open_drain());
@@ -150,7 +150,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.offset() == 4);
                REQUIRE(line.name() == "gpio-mockup-A-4");
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());
                REQUIRE(line.is_requested());
                REQUIRE(line.is_used());
                REQUIRE_FALSE(line.is_open_drain());
@@ -320,19 +320,19 @@ TEST_CASE("Line can be reconfigured", "[line]")
                config.flags = 0;
                line.request(config);
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_INPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());
 
                line.set_config(::gpiod::line_request::DIRECTION_OUTPUT,
                        ::gpiod::line_request::FLAG_ACTIVE_LOW,1);
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_LOW);
+               REQUIRE(line.is_active_low());
                REQUIRE(mockup::instance().chip_get_value(0, 3) == 0);
                line.set_value(0);
                REQUIRE(mockup::instance().chip_get_value(0, 3) == 1);
 
                line.set_config(::gpiod::line_request::DIRECTION_OUTPUT, 0);
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());
                REQUIRE(mockup::instance().chip_get_value(0, 3) == 0);
                line.set_value(1);
                REQUIRE(mockup::instance().chip_get_value(0, 3) == 1);
@@ -348,12 +348,12 @@ TEST_CASE("Line can be reconfigured", "[line]")
 
                line.set_flags(::gpiod::line_request::FLAG_ACTIVE_LOW);
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_LOW);
+               REQUIRE(line.is_active_low());
                REQUIRE(mockup::instance().chip_get_value(0, 3) == 0);
 
                line.set_flags(0);
                REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE_FALSE(line.is_active_low());
                REQUIRE(mockup::instance().chip_get_value(0, 3) == 1);
        }
 
index 6a47b66653bf83f7e401d043b09fc91f73234ed0..1593337e166964e83b04ddef9e6a20d48e0663b6 100755 (executable)
@@ -23,11 +23,11 @@ if __name__ == '__main__':
                     name = line.name()
                     consumer = line.consumer()
                     direction = line.direction()
-                    active_state = line.active_state()
+                    active_low = line.is_active_low()
 
                     print('\tline {:>3}: {:>18} {:>12} {:>8} {:>10}'.format(
                           offset,
                           'unnamed' if name is None else name,
                           'unused' if consumer is None else consumer,
                           'input' if direction == gpiod.Line.DIRECTION_INPUT else 'output',
-                          'active-low' if active_state == gpiod.Line.ACTIVE_LOW else 'active-high'))
+                          'active-low' if active_low else 'active-high'))
index e8641f1cddcaf3f726639b08572932102d41d7f7..b48a83a9c73e908df5b9af612764d0a9f6fdf790 100644 (file)
@@ -67,11 +67,6 @@ enum {
        gpiod_DIRECTION_OUTPUT,
 };
 
-enum {
-       gpiod_ACTIVE_HIGH = 1,
-       gpiod_ACTIVE_LOW,
-};
-
 enum {
        gpiod_BIAS_AS_IS = 1,
        gpiod_BIAS_DISABLE,
@@ -341,28 +336,20 @@ static PyObject *gpiod_Line_direction(gpiod_LineObject *self,
        return ret;
 }
 
-PyDoc_STRVAR(gpiod_Line_active_state_doc,
-"active_state() -> integer\n"
+PyDoc_STRVAR(gpiod_Line_is_active_low_doc,
+"is_active_low() -> boolean\n"
 "\n"
-"Get the active state setting of this GPIO line.");
+"Check if this line's signal is inverted");
 
-static PyObject *gpiod_Line_active_state(gpiod_LineObject *self,
-                                        PyObject *Py_UNUSED(ignored))
+static PyObject *gpiod_Line_is_active_low(gpiod_LineObject *self,
+                                         PyObject *Py_UNUSED(ignored))
 {
-       PyObject *ret;
-       int active;
-
        if (gpiod_ChipIsClosed(self->owner))
                return NULL;
 
-       active = gpiod_line_active_state(self->line);
-
-       if (active == GPIOD_LINE_ACTIVE_STATE_HIGH)
-               ret = Py_BuildValue("I", gpiod_ACTIVE_HIGH);
-       else
-               ret = Py_BuildValue("I", gpiod_ACTIVE_LOW);
-
-       return ret;
+       if (gpiod_line_is_active_low(self->line))
+               Py_RETURN_TRUE;
+       Py_RETURN_FALSE;
 }
 
 PyDoc_STRVAR(gpiod_Line_bias_doc,
@@ -973,10 +960,10 @@ static PyMethodDef gpiod_Line_methods[] = {
                .ml_doc = gpiod_Line_direction_doc,
        },
        {
-               .ml_name = "active_state",
-               .ml_meth = (PyCFunction)gpiod_Line_active_state,
+               .ml_name = "is_active_low",
+               .ml_meth = (PyCFunction)gpiod_Line_is_active_low,
                .ml_flags = METH_NOARGS,
-               .ml_doc = gpiod_Line_active_state_doc,
+               .ml_doc = gpiod_Line_is_active_low_doc,
        },
        {
                .ml_name = "bias",
@@ -2538,16 +2525,6 @@ static gpiod_ConstDescr gpiod_ConstList[] = {
                .name = "DIRECTION_OUTPUT",
                .val = gpiod_DIRECTION_OUTPUT,
        },
-       {
-               .typeobj = &gpiod_LineType,
-               .name = "ACTIVE_HIGH",
-               .val = gpiod_ACTIVE_HIGH,
-       },
-       {
-               .typeobj = &gpiod_LineType,
-               .name = "ACTIVE_LOW",
-               .val = gpiod_ACTIVE_LOW,
-       },
        {
                .typeobj = &gpiod_LineType,
                .name = "BIAS_AS_IS",
index 79294bc749e1af3d7e224b10d8784dab3ce5f55b..3093a1ce5f8387386c0aa6148871922f18f5ddfc 100755 (executable)
@@ -205,7 +205,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_INPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), None)
             self.assertFalse(line.is_used())
             self.assertFalse(line.is_requested())
@@ -219,7 +219,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_LOW)
+            self.assertTrue(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -235,7 +235,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_LOW)
+            self.assertTrue(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -253,7 +253,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -271,7 +271,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -289,7 +289,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -307,7 +307,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -325,7 +325,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
index b073b3b7b25f77521f2743030ccfeac320f75a96..75da84c571c6a973b13ce5f0888142668f5b0f9a 100644 (file)
@@ -280,16 +280,6 @@ enum {
        /**< Direction is output - we're driving the GPIO line. */
 };
 
-/**
- * @brief Possible active state settings.
- */
-enum {
-       GPIOD_LINE_ACTIVE_STATE_HIGH = 1,
-       /**< The active state of a GPIO is active-high. */
-       GPIOD_LINE_ACTIVE_STATE_LOW,
-       /**< The active state of a GPIO is active-low. */
-};
-
 /**
  * @brief Possible internal bias settings.
  */
@@ -337,11 +327,11 @@ const char *gpiod_line_consumer(struct gpiod_line *line) GPIOD_API;
 int gpiod_line_direction(struct gpiod_line *line) GPIOD_API;
 
 /**
- * @brief Read the GPIO line active state setting.
+ * @brief Check if the signal of this line is inverted.
  * @param line GPIO line object.
- * @return Returns GPIOD_LINE_ACTIVE_STATE_HIGH or GPIOD_LINE_ACTIVE_STATE_LOW.
+ * @return True if this line is "active-low", false otherwise.
  */
-int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API;
+bool gpiod_line_is_active_low(struct gpiod_line *line) GPIOD_API;
 
 /**
  * @brief Read the GPIO line bias setting.
index d96e6cfb5ece62fcf199089cf9bf64c7b07149e6..c6fb4743ba404c2a65e490a3bb2360c1a4c2951a 100644 (file)
@@ -41,8 +41,8 @@ struct gpiod_line {
        /* The direction of the GPIO line. */
        int direction;
 
-       /* The active-state configuration. */
-       int active_state;
+       /* Is this line active-low?. */
+       bool active_low;
 
        /* The logical value last written to the line. */
        int output_value;
@@ -471,9 +471,9 @@ int gpiod_line_direction(struct gpiod_line *line)
        return line->direction;
 }
 
-int gpiod_line_active_state(struct gpiod_line *line)
+bool gpiod_line_is_active_low(struct gpiod_line *line)
 {
-       return line->active_state;
+       return line->active_low;
 }
 
 int gpiod_line_bias(struct gpiod_line *line)
@@ -541,9 +541,7 @@ int gpiod_line_update(struct gpiod_line *line)
                                                ? GPIOD_LINE_DIRECTION_OUTPUT
                                                : GPIOD_LINE_DIRECTION_INPUT;
 
-       line->active_state = info.flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW
-                                               ? GPIOD_LINE_ACTIVE_STATE_LOW
-                                               : GPIOD_LINE_ACTIVE_STATE_HIGH;
+       line->active_low = !!(info.flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW);
 
        line->info_flags = line_info_v2_to_info_flags(&info);
 
index cc66fcc0c5eb6e663b8e5ff9998d6902885950c6..d6264af60d417ee2c8cf45936d7ec91e2230be07 100644 (file)
@@ -340,12 +340,10 @@ GPIOD_TEST_CASE(set_config_bulk_null_values, 0, { 8 })
        ret = gpiod_line_request_bulk_output(bulk, GPIOD_TEST_CONSUMER, 0);
        g_assert_cmpint(ret, ==, 0);
        gpiod_test_return_if_failed();
-       g_assert_cmpint(gpiod_line_active_state(line0), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
-       g_assert_cmpint(gpiod_line_active_state(line1), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
-       g_assert_cmpint(gpiod_line_active_state(line2), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
+       g_assert_false(gpiod_line_is_active_low(line0));
+       g_assert_false(gpiod_line_is_active_low(line1));
+       g_assert_false(gpiod_line_is_active_low(line2));
+
        g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0);
        g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 0);
        g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0);
@@ -354,12 +352,9 @@ GPIOD_TEST_CASE(set_config_bulk_null_values, 0, { 8 })
                        GPIOD_LINE_REQUEST_DIRECTION_OUTPUT,
                        GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW, NULL);
        g_assert_cmpint(ret, ==, 0);
-       g_assert_cmpint(gpiod_line_active_state(line0), ==,
-                       GPIOD_LINE_ACTIVE_STATE_LOW);
-       g_assert_cmpint(gpiod_line_active_state(line1), ==,
-                       GPIOD_LINE_ACTIVE_STATE_LOW);
-       g_assert_cmpint(gpiod_line_active_state(line2), ==,
-                       GPIOD_LINE_ACTIVE_STATE_LOW);
+       g_assert_true(gpiod_line_is_active_low(line0));
+       g_assert_true(gpiod_line_is_active_low(line1));
+       g_assert_true(gpiod_line_is_active_low(line2));
        g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 1);
        g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 1);
        g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1);
@@ -367,12 +362,9 @@ GPIOD_TEST_CASE(set_config_bulk_null_values, 0, { 8 })
        ret = gpiod_line_set_config_bulk(bulk,
                        GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, 0, NULL);
        g_assert_cmpint(ret, ==, 0);
-       g_assert_cmpint(gpiod_line_active_state(line0), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
-       g_assert_cmpint(gpiod_line_active_state(line1), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
-       g_assert_cmpint(gpiod_line_active_state(line2), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
+       g_assert_false(gpiod_line_is_active_low(line0));
+       g_assert_false(gpiod_line_is_active_low(line1));
+       g_assert_false(gpiod_line_is_active_low(line2));
        g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0);
        g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 0);
        g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0);
@@ -395,20 +387,17 @@ GPIOD_TEST_CASE(set_flags_active_state, 0, { 8 })
        ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 1);
        g_assert_cmpint(ret, ==, 0);
        gpiod_test_return_if_failed();
-       g_assert_cmpint(gpiod_line_active_state(line), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
+       g_assert_false(gpiod_line_is_active_low(line));
        g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1);
 
        ret = gpiod_line_set_flags(line, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW);
        g_assert_cmpint(ret, ==, 0);
-       g_assert_cmpint(gpiod_line_active_state(line), ==,
-                       GPIOD_LINE_ACTIVE_STATE_LOW);
+       g_assert_true(gpiod_line_is_active_low(line));
        g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0);
 
        ret = gpiod_line_set_flags(line, 0);
        g_assert_cmpint(ret, ==, 0);
-       g_assert_cmpint(gpiod_line_active_state(line), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
+       g_assert_false(gpiod_line_is_active_low(line));
        g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1);
 }
 
@@ -719,8 +708,7 @@ GPIOD_TEST_CASE(active_state, 0, { 8 })
        g_assert_cmpint(ret, ==, 0);
        gpiod_test_return_if_failed();
 
-       g_assert_cmpint(gpiod_line_active_state(line), ==,
-                       GPIOD_LINE_ACTIVE_STATE_HIGH);
+       g_assert_false(gpiod_line_is_active_low(line));
 
        gpiod_line_release(line);
 
@@ -842,8 +830,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
        g_assert_true(gpiod_line_is_open_drain(line));
        g_assert_false(gpiod_line_is_open_source(line));
        g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS);
-       g_assert_cmpint(gpiod_line_active_state(line), ==,
-                       GPIOD_LINE_ACTIVE_STATE_LOW);
+       g_assert_true(gpiod_line_is_active_low(line));
        g_assert_cmpint(gpiod_line_direction(line), ==,
                        GPIOD_LINE_DIRECTION_OUTPUT);
 
@@ -860,8 +847,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
        g_assert_false(gpiod_line_is_open_drain(line));
        g_assert_true(gpiod_line_is_open_source(line));
        g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS);
-       g_assert_cmpint(gpiod_line_active_state(line), ==,
-                       GPIOD_LINE_ACTIVE_STATE_LOW);
+       g_assert_true(gpiod_line_is_active_low(line));
 
        gpiod_line_release(line);
 
@@ -882,8 +868,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
        g_assert_false(gpiod_line_is_open_drain(line));
        g_assert_false(gpiod_line_is_open_source(line));
        g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_PULL_DOWN);
-       g_assert_cmpint(gpiod_line_active_state(line), ==,
-                       GPIOD_LINE_ACTIVE_STATE_LOW);
+       g_assert_true(gpiod_line_is_active_low(line));
        g_assert_cmpint(gpiod_line_direction(line), ==,
                        GPIOD_LINE_DIRECTION_INPUT);
 
@@ -903,8 +888,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
        g_assert_false(gpiod_line_is_open_drain(line));
        g_assert_false(gpiod_line_is_open_source(line));
        g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_PULL_UP);
-       g_assert_cmpint(gpiod_line_active_state(line), ==,
-                       GPIOD_LINE_ACTIVE_STATE_LOW);
+       g_assert_true(gpiod_line_is_active_low(line));
        g_assert_cmpint(gpiod_line_direction(line), ==,
                        GPIOD_LINE_DIRECTION_INPUT);
 
index 057a19fd7243e9734e67e9152b63cc552c6895fa..8d228ab7bf17b4321703ccd546f8de29648d705f 100644 (file)
@@ -117,11 +117,11 @@ static PRINTF(3, 4) void prinfo(bool *of,
 
 static void list_lines(struct gpiod_chip *chip)
 {
-       int direction, active_state;
+       bool flag_printed, of, active_low;
        const char *name, *consumer;
        struct gpiod_line *line;
        unsigned int i, offset;
-       bool flag_printed, of;
+       int direction;
 
        printf("%s - %u lines:\n",
               gpiod_chip_name(chip), gpiod_chip_num_lines(chip));
@@ -134,7 +134,7 @@ static void list_lines(struct gpiod_chip *chip)
                name = gpiod_line_name(line);
                consumer = gpiod_line_consumer(line);
                direction = gpiod_line_direction(line);
-               active_state = gpiod_line_active_state(line);
+               active_low = gpiod_line_is_active_low(line);
 
                of = false;
 
@@ -157,9 +157,7 @@ static void list_lines(struct gpiod_chip *chip)
                prinfo(&of, 8, "%s ", direction == GPIOD_LINE_DIRECTION_INPUT
                                                        ? "input" : "output");
                prinfo(&of, 13, "%s ",
-                      active_state == GPIOD_LINE_ACTIVE_STATE_LOW
-                                                       ? "active-low"
-                                                       : "active-high");
+                      active_low ? "active-low" : "active-high");
 
                flag_printed = false;
                for (i = 0; i < ARRAY_SIZE(flags); i++) {