Skip to contentSkip to conversation

treewide: an assortment of tweaks and improvements

PATCH In review Bartosz Golaszewski 3 participants 28 messages Nov 30, 2022 – Dec 7, 2022

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

cover treewide: an assortment of tweaks and improvements

From: Bartosz Golaszewski <[email protected]>

This series contains various changes for libgpiod v2. There's no main theme to it really, just fixing problems I noticed and introducing some more changes to the API.

Bartosz Golaszewski (11):
treewide: use C enum types explicitly
treewide: apply formatting changes with clang-format
treewide: use plural 'events' in read_edge_event() functions
treewide: rename EVENT_CLOCK to CLOCK
gpiosim: rename HOG_DIR to DIRECTION
tools: display the correct license with --version
bindings: rust: make reuse happy
bindings: rust: include rust sources in the release tarballs
bindings: python: decouple the version of the bindings from libgpiod
API version
bindings: python: fix the GPIOD_WITH_TESTS build flag
bindings: python: extend setup.py

 LICENSES/Apache-2.0.txt                       | 201 ++++++++++++++++++
 LICENSES/BSD-3-Clause.txt                     |  28 +++
 LICENSES/CC0-1.0.txt                          | 121 +++++++++++
 Makefile.am                                   |   9 +-
 bindings/cxx/edge-event-buffer.cpp            |   2 +-
 bindings/cxx/edge-event.cpp                   |   2 +-
 bindings/cxx/examples/gpiomoncxx.cpp          |   2 +-
 bindings/cxx/gpiodcxx/line-request.hpp        |   6 +-
 bindings/cxx/info-event.cpp                   |   2 +-
 bindings/cxx/internal.hpp                     |   6 +-
 bindings/cxx/line-info.cpp                    |   8 +-
 bindings/cxx/line-request.cpp                 |  24 ++-
 bindings/cxx/line-settings.cpp                |  87 ++++----
 bindings/cxx/tests/gpiosim.cpp                |  24 +--
 bindings/cxx/tests/gpiosim.hpp                |   4 +-
 bindings/cxx/tests/tests-edge-event.cpp       |  56 ++---
 bindings/cxx/tests/tests-line-info.cpp        |   2 +-
 bindings/python/examples/gpiomon.py           |   2 +-
 bindings/python/gpiod/__init__.py             |   3 +-
 bindings/python/gpiod/ext/line-settings.c     |  54 ++---
 bindings/python/gpiod/ext/module.c            |   8 +-
 bindings/python/gpiod/ext/request.c           |  12 +-
 bindings/python/gpiod/line_request.py         |   6 +-
 bindings/python/gpiod/version.py              |   5 +
 bindings/python/setup.py                      |  18 +-
 bindings/python/tests/gpiosim/ext.c           |   6 +-
 bindings/python/tests/tests_edge_event.py     |  38 ++--
 bindings/python/tests/tests_module.py         |  15 +-
 bindings/rust/.gitignore                      |   4 +-
 bindings/rust/Makefile.am                     |   4 +
 bindings/rust/gpiosim-sys/Makefile.am         |   6 +
 bindings/rust/gpiosim-sys/src/Makefile.am     |   5 +
 bindings/rust/gpiosim-sys/src/lib.rs          |  48 +++--
 bindings/rust/gpiosim-sys/src/sim.rs          |   2 +-
 bindings/rust/libgpiod-sys/Makefile.am        |   6 +
 bindings/rust/libgpiod-sys/src/Makefile.am    |   5 +
 bindings/rust/libgpiod/Makefile.am            |   6 +
 bindings/rust/libgpiod/examples/Makefile.am   |  14 ++
 .../rust/libgpiod/examples/gpio_events.rs     |   2 +-
 bindings/rust/libgpiod/examples/gpiomon.rs    |   2 +-
 bindings/rust/libgpiod/src/Makefile.am        |  15 ++
 bindings/rust/libgpiod/src/event_buffer.rs    |   2 +-
 bindings/rust/libgpiod/src/lib.rs             | 169 +++++++++------
 bindings/rust/libgpiod/src/line_info.rs       |  10 +-
 bindings/rust/libgpiod/src/line_request.rs    |   4 +-
 bindings/rust/libgpiod/src/line_settings.rs   |  30 +--
 bindings/rust/libgpiod/tests/Makefile.am      |  15 ++
 .../rust/libgpiod/tests/common/Makefile.am    |   5 +
 bindings/rust/libgpiod/tests/edge_event.rs    |  24 +--
 bindings/rust/libgpiod/tests/line_request.rs  |   2 +-
 configure.ac                                  |   9 +
 include/gpiod.h                               | 106 +++++----
 lib/edge-event.c                              |  13 +-
 lib/info-event.c                              |   5 +-
 lib/internal.c                                |   4 +-
 lib/internal.h                                |   3 +-
 lib/line-config.c                             |  55 ++---
 lib/line-info.c                               |  31 +--
 lib/line-request.c                            |  31 +--
 lib/line-settings.c                           |  50 ++---
 tests/gpiod-test-helpers.h                    |   2 +-
 tests/gpiod-test-sim.c                        |  53 +++--
 tests/gpiod-test-sim.h                        |   8 +-
 tests/gpiosim/gpiosim-selftest.c              |   2 +-
 tests/gpiosim/gpiosim.c                       |  50 +++--
 tests/gpiosim/gpiosim.h                       |  30 +--
 tests/tests-chip-info.c                       |   1 -
 tests/tests-edge-event.c                      |  98 ++++-----
 tests/tests-info-event.c                      |   2 +-
 tests/tests-line-config.c                     |   2 +-
 tests/tests-line-info.c                       |  39 ++--
 tests/tests-line-request.c                    |  58 ++---
 tests/tests-line-settings.c                   |  40 ++--
 tests/tests-request-config.c                  |  12 +-
 tools/gpiodetect.c                            |   3 +-
 tools/gpioget.c                               |   7 +-
 tools/gpioinfo.c                              |  12 +-
 tools/gpiomon.c                               |  31 ++-
 tools/gpionotify.c                            |  10 +-
 tools/gpioset.c                               |  85 ++++----
 tools/tools-common.c                          |  47 ++--
 tools/tools-common.h                          |  11 +-
 82 files changed, 1284 insertions(+), 757 deletions(-)
 create mode 100644 LICENSES/Apache-2.0.txt
 create mode 100644 LICENSES/BSD-3-Clause.txt
 create mode 100644 LICENSES/CC0-1.0.txt
 create mode 100644 bindings/python/gpiod/version.py
 create mode 100644 bindings/rust/gpiosim-sys/Makefile.am
 create mode 100644 bindings/rust/gpiosim-sys/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod-sys/Makefile.am
 create mode 100644 bindings/rust/libgpiod-sys/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod/Makefile.am
 create mode 100644 bindings/rust/libgpiod/examples/Makefile.am
 create mode 100644 bindings/rust/libgpiod/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod/tests/Makefile.am
 create mode 100644 bindings/rust/libgpiod/tests/common/Makefile.am
Signature · 1 line
2.37.2
#1 lore raw

PATCH 1/11 treewide: use C enum types explicitly

From: Bartosz Golaszewski <[email protected]>

Use enum types explicitly across the entire C API. Modern compilers can catch some bugs with enums and it also helps IDEs and general readability.

[Viresh: make rust bindings work with negative enum values]
---
 bindings/cxx/edge-event.cpp                 |   2 +-
 bindings/cxx/info-event.cpp                 |   2 +-
 bindings/cxx/internal.hpp                   |   6 +-
 bindings/cxx/line-info.cpp                  |   2 +-
 bindings/cxx/line-request.cpp               |  14 +-
 bindings/cxx/line-settings.cpp              |  81 +++++-----
 bindings/cxx/tests/gpiosim.cpp              |  14 +-
 bindings/python/gpiod/ext/line-settings.c   |  54 +++----
 bindings/python/gpiod/ext/request.c         |   4 +-
 bindings/rust/gpiosim-sys/src/lib.rs        |  42 +++--
 bindings/rust/gpiosim-sys/src/sim.rs        |   2 +-
 bindings/rust/libgpiod/src/lib.rs           | 169 ++++++++++++--------
 bindings/rust/libgpiod/src/line_info.rs     |  10 +-
 bindings/rust/libgpiod/src/line_settings.rs |  30 ++--
 include/gpiod.h                             |  84 ++++++----
 lib/edge-event.c                            |   5 +-
 lib/info-event.c                            |   5 +-
 lib/line-config.c                           |  12 +-
 lib/line-info.c                             |  25 +--
 lib/line-request.c                          |  21 +--
 lib/line-settings.c                         |  39 ++---
 tests/gpiosim/gpiosim.c                     |  26 +--
 tests/gpiosim/gpiosim.h                     |  18 ++-
 tests/tests-line-request.c                  |  25 +--
 tools/gpioget.c                             |   7 +-
 tools/gpiomon.c                             |   6 +-
 tools/gpioset.c                             |  45 +++---
 tools/tools-common.c                        |   7 +-
 tools/tools-common.h                        |   8 +-
 29 files changed, 431 insertions(+), 334 deletions(-)
bindings/cxx/edge-event.cpp +1 -1
index 5992934..9d12273 100644
@@ -100,7 +100,7 @@ GPIOD_CXX_API edge_event::event_type edge_event::type() const
 {
 	int evtype = ::gpiod_edge_event_get_event_type(this->_m_priv->get_event_ptr());
 
-	return map_int_to_enum(evtype, event_type_mapping);
+	return map_enum_c_to_cxx(evtype, event_type_mapping);
 }
 
 GPIOD_CXX_API timestamp edge_event::timestamp_ns() const noexcept
bindings/cxx/info-event.cpp +1 -1
index d9e14a3..f709408 100644
@@ -77,7 +77,7 @@ GPIOD_CXX_API info_event::event_type info_event::type() const
 {
 	int type = ::gpiod_info_event_get_event_type(this->_m_priv->event.get());
 
-	return map_int_to_enum(type, event_type_mapping);
+	return map_enum_c_to_cxx(type, event_type_mapping);
 }
 
 GPIOD_CXX_API ::std::uint64_t info_event::timestamp_ns() const noexcept
bindings/cxx/internal.hpp +3 -3
index 0703474..d27aa22 100644
@@ -18,15 +18,15 @@
 
 namespace gpiod {
 
-template<class enum_type> enum_type
-map_int_to_enum(int value, const ::std::map<int, enum_type>& mapping)
+template<class cxx_enum_type, class c_enum_type> cxx_enum_type
+map_enum_c_to_cxx(c_enum_type value, const ::std::map<c_enum_type, cxx_enum_type>& mapping)
 {
 	try {
 		return mapping.at(value);
 	} catch (const ::std::out_of_range& err) {
 		/* FIXME Demangle the name. */
 		throw bad_mapping(::std::string("invalid value for ") +
-				  typeid(enum_type).name());
+				  typeid(cxx_enum_type).name());
 	}
 }
 
bindings/cxx/line-info.cpp +1 -1
index a6b6dfa..944e34d 100644
@@ -114,7 +114,7 @@ GPIOD_CXX_API line::direction line_info::direction() const
 {
 	int direction = ::gpiod_line_info_get_direction(this->_m_priv->info.get());
 
-	return map_int_to_enum(direction, direction_mapping);
+	return map_enum_c_to_cxx(direction, direction_mapping);
 }
 
 GPIOD_CXX_API bool line_info::active_low() const noexcept
bindings/cxx/line-request.cpp +8 -6
index bde34e8..be0bac5 100644
@@ -115,9 +115,10 @@ GPIOD_CXX_API void line_request::get_values(const line::offsets& offsets, line::
 
 	this->_m_priv->fill_offset_buf(offsets);
 
-	int ret = ::gpiod_line_request_get_values_subset(this->_m_priv->request.get(),
-							 offsets.size(), this->_m_priv->offset_buf.data(),
-							 reinterpret_cast<int*>(values.data()));
+	int ret = ::gpiod_line_request_get_values_subset(
+					this->_m_priv->request.get(),
+					offsets.size(), this->_m_priv->offset_buf.data(),
+					reinterpret_cast<gpiod_line_value*>(values.data()));
 	if (ret)
 		throw_from_errno("unable to retrieve line values");
 }
@@ -157,9 +158,10 @@ GPIOD_CXX_API line_request& line_request::set_values(const line::offsets& offset
 
 	this->_m_priv->fill_offset_buf(offsets);
 
-	int ret = ::gpiod_line_request_set_values_subset(this->_m_priv->request.get(),
-							 offsets.size(), this->_m_priv->offset_buf.data(),
-							 reinterpret_cast<const int*>(values.data()));
+	int ret = ::gpiod_line_request_set_values_subset(
+					this->_m_priv->request.get(),
+					offsets.size(), this->_m_priv->offset_buf.data(),
+					reinterpret_cast<const enum gpiod_line_value*>(values.data()));
 	if (ret)
 		throw_from_errno("unable to set line values");
 
bindings/cxx/line-settings.cpp +42 -39

220 lines not on this page · raw message

bindings/cxx/tests/gpiosim.cpp +7 -7
index 0a29efe..281f9cc 100644
@@ -12,18 +12,18 @@ namespace gpiosim {
 
 namespace {
 
-const ::std::map<chip::pull, int> pull_mapping = {
+const ::std::map<chip::pull, gpiosim_pull> pull_mapping = {
 	{ chip::pull::PULL_UP,		GPIOSIM_PULL_UP },
 	{ chip::pull::PULL_DOWN,	GPIOSIM_PULL_DOWN }
 };
 
-const ::std::map<chip_builder::hog_direction, int> hog_dir_mapping = {
+const ::std::map<chip_builder::hog_direction, gpiosim_direction> hog_dir_mapping = {
 	{ chip_builder::hog_direction::INPUT,		GPIOSIM_HOG_DIR_INPUT },
 	{ chip_builder::hog_direction::OUTPUT_HIGH,	GPIOSIM_HOG_DIR_OUTPUT_HIGH },
 	{ chip_builder::hog_direction::OUTPUT_LOW,	GPIOSIM_HOG_DIR_OUTPUT_LOW }
 };
 
-const ::std::map<int, chip::value> value_mapping = {
+const ::std::map<gpiosim_value, chip::value> value_mapping = {
 	{ GPIOSIM_VALUE_INACTIVE,	chip::value::INACTIVE },
 	{ GPIOSIM_VALUE_ACTIVE,		chip::value::ACTIVE }
 };
@@ -137,8 +137,8 @@ chip& chip::operator=(chip&& other)
 
 chip::value chip::get_value(unsigned int offset)
 {
-	int val = ::gpiosim_bank_get_value(this->_m_priv->bank.get(), offset);
-	if (val < 0)
+	auto val = ::gpiosim_bank_get_value(this->_m_priv->bank.get(), offset);
+	if (val == GPIOSIM_VALUE_ERROR)
 		throw ::std::system_error(errno, ::std::system_category(),
 					  "failed to read the simulated GPIO line value");
 
@@ -147,8 +147,8 @@ chip::value chip::get_value(unsigned int offset)
 
 void chip::set_pull(unsigned int offset, pull pull)
 {
-	int ret = ::gpiosim_bank_set_pull(this->_m_priv->bank.get(),
-					  offset, pull_mapping.at(pull));
+	auto ret = ::gpiosim_bank_set_pull(this->_m_priv->bank.get(),
+					   offset, pull_mapping.at(pull));
 	if (ret)
 		throw ::std::system_error(errno, ::std::system_category(),
 					  "failed to set the pull of simulated GPIO line");
bindings/python/gpiod/ext/line-settings.c +23 -31

89 lines not on this page · raw message

bindings/python/gpiod/ext/request.c +2 -2
index 820d1e1..62378f5 100644
@@ -7,7 +7,7 @@ typedef struct {
 	PyObject_HEAD;
 	struct gpiod_line_request *request;
 	unsigned int *offsets;
-	int *values;
+	enum gpiod_line_value *values;
 	size_t num_lines;
 	struct gpiod_edge_event_buffer *buffer;
 } request_object;
@@ -360,10 +360,10 @@ PyObject *Py_gpiod_MakeRequestObject(struct gpiod_line_request *request,
 				     size_t event_buffer_size)
 {
 	struct gpiod_edge_event_buffer *buffer;
+	enum gpiod_line_value *values;
 	request_object *req_obj;
 	unsigned int *offsets;
 	size_t num_lines;
-	int *values;
 
 	num_lines = gpiod_line_request_get_num_lines(request);
 
bindings/rust/gpiosim-sys/src/lib.rs +29 -13

76 lines not on this page · raw message

bindings/rust/gpiosim-sys/src/sim.rs +1 -1
index 4930fb6..777bf08 100644
@@ -164,7 +164,7 @@ impl SimBank {
                 errno::errno(),
             ))
         } else {
-            Value::new(ret as u32)
+            Value::new(ret as i32)
         }
     }
 
bindings/rust/libgpiod/src/lib.rs +102 -67

263 lines not on this page · raw message

bindings/rust/libgpiod/src/line_info.rs +5 -5
index 1784cde..b45878c 100644
@@ -100,7 +100,7 @@ impl Info {
     /// Get the GPIO line's direction.
     pub fn direction(&self) -> Result<Direction> {
         // SAFETY: `gpiod_line_info` is guaranteed to be valid here.
-        Direction::new(unsafe { gpiod::gpiod_line_info_get_direction(self.info) } as u32)
+        Direction::new(unsafe { gpiod::gpiod_line_info_get_direction(self.info) })
     }
 
     /// Returns true if the line is "active-low", false otherwise.
@@ -112,25 +112,25 @@ impl Info {
     /// Get the GPIO line's bias setting.
     pub fn bias(&self) -> Result<Option<Bias>> {
         // SAFETY: `gpiod_line_info` is guaranteed to be valid here.
-        Bias::new(unsafe { gpiod::gpiod_line_info_get_bias(self.info) } as u32)
+        Bias::new(unsafe { gpiod::gpiod_line_info_get_bias(self.info) })
     }
 
     /// Get the GPIO line's drive setting.
     pub fn drive(&self) -> Result<Drive> {
         // SAFETY: `gpiod_line_info` is guaranteed to be valid here.
-        Drive::new(unsafe { gpiod::gpiod_line_info_get_drive(self.info) } as u32)
+        Drive::new(unsafe { gpiod::gpiod_line_info_get_drive(self.info) })
     }
 
     /// Get the current edge detection setting of the line.
     pub fn edge_detection(&self) -> Result<Option<Edge>> {
         // SAFETY: `gpiod_line_info` is guaranteed to be valid here.
-        Edge::new(unsafe { gpiod::gpiod_line_info_get_edge_detection(self.info) } as u32)
+        Edge::new(unsafe { gpiod::gpiod_line_info_get_edge_detection(self.info) })
     }
 
     /// Get the current event clock setting used for edge event timestamps.
     pub fn event_clock(&self) -> Result<EventClock> {
         // SAFETY: `gpiod_line_info` is guaranteed to be valid here.
-        EventClock::new(unsafe { gpiod::gpiod_line_info_get_event_clock(self.info) } as u32)
+        EventClock::new(unsafe { gpiod::gpiod_line_info_get_event_clock(self.info) })
     }
 
     /// Returns true if the line is debounced (either by hardware or by the
bindings/rust/libgpiod/src/line_settings.rs +11 -19
index cedf7ca..1c5ac66 100644
@@ -102,10 +102,7 @@ impl Settings {
     pub fn set_direction(&mut self, direction: Direction) -> Result<&mut Self> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
         let ret = unsafe {
-            gpiod::gpiod_line_settings_set_direction(
-                self.settings,
-                direction.gpiod_direction() as i32,
-            )
+            gpiod::gpiod_line_settings_set_direction(self.settings, direction.gpiod_direction())
         };
 
         if ret == -1 {
@@ -121,17 +118,14 @@ impl Settings {
     /// Get the direction setting.
     pub fn direction(&self) -> Result<Direction> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
-        Direction::new(unsafe { gpiod::gpiod_line_settings_get_direction(self.settings) } as u32)
+        Direction::new(unsafe { gpiod::gpiod_line_settings_get_direction(self.settings) })
     }
 
     /// Set the edge event detection setting.
     pub fn set_edge_detection(&mut self, edge: Option<Edge>) -> Result<&mut Self> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
         let ret = unsafe {
-            gpiod::gpiod_line_settings_set_edge_detection(
-                self.settings,
-                Edge::gpiod_edge(edge) as i32,
-            )
+            gpiod::gpiod_line_settings_set_edge_detection(self.settings, Edge::gpiod_edge(edge))
         };
 
         if ret == -1 {
@@ -147,15 +141,14 @@ impl Settings {
     /// Get the edge event detection setting.
     pub fn edge_detection(&self) -> Result<Option<Edge>> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
-        Edge::new(unsafe { gpiod::gpiod_line_settings_get_edge_detection(self.settings) } as u32)
+        Edge::new(unsafe { gpiod::gpiod_line_settings_get_edge_detection(self.settings) })
     }
 
     /// Set the bias setting.
     pub fn set_bias(&mut self, bias: Option<Bias>) -> Result<&mut Self> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
-        let ret = unsafe {
-            gpiod::gpiod_line_settings_set_bias(self.settings, Bias::gpiod_bias(bias) as i32)
-        };
+        let ret =
+            unsafe { gpiod::gpiod_line_settings_set_bias(self.settings, Bias::gpiod_bias(bias)) };
 
         if ret == -1 {
             Err(Error::OperationFailed(
@@ -170,15 +163,14 @@ impl Settings {
     /// Get the bias setting.
     pub fn bias(&self) -> Result<Option<Bias>> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
-        Bias::new(unsafe { gpiod::gpiod_line_settings_get_bias(self.settings) } as u32)
+        Bias::new(unsafe { gpiod::gpiod_line_settings_get_bias(self.settings) })
     }
 
     /// Set the drive setting.
     pub fn set_drive(&mut self, drive: Drive) -> Result<&mut Self> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
-        let ret = unsafe {
-            gpiod::gpiod_line_settings_set_drive(self.settings, drive.gpiod_drive() as i32)
-        };
+        let ret =
+            unsafe { gpiod::gpiod_line_settings_set_drive(self.settings, drive.gpiod_drive()) };
 
         if ret == -1 {
             Err(Error::OperationFailed(
@@ -193,7 +185,7 @@ impl Settings {
     /// Get the drive setting.
     pub fn drive(&self) -> Result<Drive> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
-        Drive::new(unsafe { gpiod::gpiod_line_settings_get_drive(self.settings) } as u32)
+        Drive::new(unsafe { gpiod::gpiod_line_settings_get_drive(self.settings) })
     }
 
     /// Set active-low setting.
@@ -236,7 +228,7 @@ impl Settings {
     pub fn set_event_clock(&mut self, clock: EventClock) -> Result<&mut Self> {
         // SAFETY: `gpiod_line_settings` is guaranteed to be valid here.
         let ret = unsafe {
-            gpiod::gpiod_line_settings_set_event_clock(self.settings, clock.gpiod_clock() as i32)
+            gpiod::gpiod_line_settings_set_event_clock(self.settings, clock.gpiod_clock())
         };
 
         if ret == -1 {
include/gpiod.h +50 -34

282 lines not on this page · raw message

lib/edge-event.c +3 -2
index 48a0f95..ad8a7d1 100644
@@ -13,7 +13,7 @@
 #define EVENT_BUFFER_MAX_CAPACITY (GPIO_V2_LINES_MAX * 16)
 
 struct gpiod_edge_event {
-	int event_type;
+	enum gpiod_edge_event_type event_type;
 	uint64_t timestamp;
 	unsigned int line_offset;
 	unsigned long global_seqno;
@@ -49,7 +49,8 @@ gpiod_edge_event_copy(struct gpiod_edge_event *event)
 	return copy;
 }
 
-GPIOD_API int gpiod_edge_event_get_event_type(struct gpiod_edge_event *event)
+GPIOD_API enum gpiod_edge_event_type
+gpiod_edge_event_get_event_type(struct gpiod_edge_event *event)
 {
 	return event->event_type;
 }
lib/info-event.c +3 -2
index 73a3d6d..c0d7307 100644
@@ -9,7 +9,7 @@
 #include "internal.h"
 
 struct gpiod_info_event {
-	int event_type;
+	enum gpiod_info_event_type event_type;
 	uint64_t timestamp;
 	struct gpiod_line_info *info;
 };
@@ -61,7 +61,8 @@ GPIOD_API void gpiod_info_event_free(struct gpiod_info_event *event)
 	free(event);
 }
 
-GPIOD_API int gpiod_info_event_get_event_type(struct gpiod_info_event *event)
+GPIOD_API enum gpiod_info_event_type
+gpiod_info_event_get_event_type(struct gpiod_info_event *event)
 {
 	return event->event_type;
 }
lib/line-config.c +11 -1
index 5ee7390..48ea618 100644
@@ -194,7 +194,7 @@ static void set_kernel_output_values(uint64_t *mask, uint64_t *vals,
 				     struct gpiod_line_config *config)
 {
 	struct per_line_config *per_line;
-	int value;
+	enum gpiod_line_value value;
 	size_t i;
 
 	gpiod_line_mask_zero(mask);
@@ -292,6 +292,8 @@ static uint64_t make_kernel_flags(struct gpiod_line_settings *settings)
 	case GPIOD_LINE_DIRECTION_OUTPUT:
 		flags |= GPIO_V2_LINE_FLAG_OUTPUT;
 		break;
+	default:
+		break;
 	}
 
 	switch (gpiod_line_settings_get_edge_detection(settings)) {
@@ -311,6 +313,8 @@ static uint64_t make_kernel_flags(struct gpiod_line_settings *settings)
 			   GPIO_V2_LINE_FLAG_INPUT);
 		flags &= ~GPIOD_LINE_DIRECTION_OUTPUT;
 		break;
+	default:
+		break;
 	}
 
 	switch (gpiod_line_settings_get_drive(settings)) {
@@ -320,6 +324,8 @@ static uint64_t make_kernel_flags(struct gpiod_line_settings *settings)
 	case GPIOD_LINE_DRIVE_OPEN_SOURCE:
 		flags |= GPIO_V2_LINE_FLAG_OPEN_SOURCE;
 		break;
+	default:
+		break;
 	}
 
 	switch (gpiod_line_settings_get_bias(settings)) {
@@ -332,6 +338,8 @@ static uint64_t make_kernel_flags(struct gpiod_line_settings *settings)
 	case GPIOD_LINE_BIAS_PULL_DOWN:
 		flags |= GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN;
 		break;
+	default:
+		break;
 	}
 
 	if (gpiod_line_settings_get_active_low(settings))
@@ -344,6 +352,8 @@ static uint64_t make_kernel_flags(struct gpiod_line_settings *settings)
 	case GPIOD_LINE_EVENT_CLOCK_HTE:
 		flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE;
 		break;
+	default:
+		break;
 	}
 
 	return flags;
lib/line-info.c +15 -10
index 9809c43..75d886f 100644
@@ -12,12 +12,12 @@ struct gpiod_line_info {
 	char name[GPIO_MAX_NAME_SIZE];
 	bool used;
 	char consumer[GPIO_MAX_NAME_SIZE];
-	int direction;
+	enum gpiod_line_direction direction;
 	bool active_low;
-	int bias;
-	int drive;
-	int edge;
-	int event_clock;
+	enum gpiod_line_bias bias;
+	enum gpiod_line_drive drive;
+	enum gpiod_line_edge edge;
+	enum gpiod_line_event_clock event_clock;
 	bool debounced;
 	unsigned long debounce_period_us;
 };
@@ -64,7 +64,8 @@ GPIOD_API const char *gpiod_line_info_get_consumer(struct gpiod_line_info *info)
 	return info->consumer[0] == '\0' ? NULL : info->consumer;
 }
 
-GPIOD_API int gpiod_line_info_get_direction(struct gpiod_line_info *info)
+GPIOD_API enum gpiod_line_direction
+gpiod_line_info_get_direction(struct gpiod_line_info *info)
 {
 	return info->direction;
 }
@@ -74,22 +75,26 @@ GPIOD_API bool gpiod_line_info_is_active_low(struct gpiod_line_info *info)
 	return info->active_low;
 }
 
-GPIOD_API int gpiod_line_info_get_bias(struct gpiod_line_info *info)
+GPIOD_API enum gpiod_line_bias
+gpiod_line_info_get_bias(struct gpiod_line_info *info)
 {
 	return info->bias;
 }
 
-GPIOD_API int gpiod_line_info_get_drive(struct gpiod_line_info *info)
+GPIOD_API enum gpiod_line_drive
+gpiod_line_info_get_drive(struct gpiod_line_info *info)
 {
 	return info->drive;
 }
 
-GPIOD_API int gpiod_line_info_get_edge_detection(struct gpiod_line_info *info)
+GPIOD_API enum gpiod_line_edge
+gpiod_line_info_get_edge_detection(struct gpiod_line_info *info)
 {
 	return info->edge;
 }
 
-GPIOD_API int gpiod_line_info_get_event_clock(struct gpiod_line_info *info)
+GPIOD_API enum gpiod_line_event_clock
+gpiod_line_info_get_event_clock(struct gpiod_line_info *info)
 {
 	return info->event_clock;
 }
lib/line-request.c +12 -9
index ee452e7..5936593 100644
@@ -57,15 +57,16 @@ gpiod_line_request_get_offsets(struct gpiod_line_request *request,
 	       sizeof(*offsets) * request->num_lines);
 }
 
-GPIOD_API int gpiod_line_request_get_value(struct gpiod_line_request *request,
-					   unsigned int offset)
+GPIOD_API enum gpiod_line_value
+gpiod_line_request_get_value(struct gpiod_line_request *request,
+			     unsigned int offset)
 {
+	enum gpiod_line_value val;
 	unsigned int ret;
-	int val;
 
 	ret = gpiod_line_request_get_values_subset(request, 1, &offset, &val);
 	if (ret)
-		return -1;
+		return GPIOD_LINE_VALUE_ERROR;
 
 	return val;
 }
@@ -86,7 +87,8 @@ static int offset_to_bit(struct gpiod_line_request *request,
 GPIOD_API int
 gpiod_line_request_get_values_subset(struct gpiod_line_request *request,
 				     size_t num_values,
-				     const unsigned int *offsets, int *values)
+				     const unsigned int *offsets,
+				     enum gpiod_line_value *values)
 {
 	struct gpio_v2_line_values uapi_values;
 	uint64_t mask = 0, bits = 0;
@@ -123,14 +125,15 @@ gpiod_line_request_get_values_subset(struct gpiod_line_request *request,
 }
 
 GPIOD_API int gpiod_line_request_get_values(struct gpiod_line_request *request,
-					    int *values)
+					    enum gpiod_line_value *values)
 {
 	return gpiod_line_request_get_values_subset(request, request->num_lines,
 						    request->offsets, values);
 }
 
 GPIOD_API int gpiod_line_request_set_value(struct gpiod_line_request *request,
-					   unsigned int offset, int value)
+					   unsigned int offset,
+					   enum gpiod_line_value value)
 {
 	return gpiod_line_request_set_values_subset(request, 1,
 						    &offset, &value);
@@ -140,7 +143,7 @@ GPIOD_API int
 gpiod_line_request_set_values_subset(struct gpiod_line_request *request,
 				     size_t num_values,
 				     const unsigned int *offsets,
-				     const int *values)
+				     const enum gpiod_line_value *values)
 {
 	struct gpio_v2_line_values uapi_values;
 	uint64_t mask = 0, bits = 0;
@@ -166,7 +169,7 @@ gpiod_line_request_set_values_subset(struct gpiod_line_request *request,
 }
 
 GPIOD_API int gpiod_line_request_set_values(struct gpiod_line_request *request,
-					    const int *values)
+					    const enum gpiod_line_value *values)
 {
 	return gpiod_line_request_set_values_subset(request, request->num_lines,
 						    request->offsets, values);
lib/line-settings.c +21 -18
index f97a90e..f245b20 100644
@@ -9,14 +9,14 @@
 #include "internal.h"
 
 struct gpiod_line_settings {
-	int direction;
-	int edge_detection;
-	int drive;
-	int bias;
+	enum gpiod_line_direction direction;
+	enum gpiod_line_edge edge_detection;
+	enum gpiod_line_drive drive;
+	enum gpiod_line_bias bias;
 	bool active_low;
-	int event_clock;
+	enum gpiod_line_event_clock event_clock;
 	long debounce_period_us;
-	int output_value;
+	enum gpiod_line_value output_value;
 };
 
 GPIOD_API struct gpiod_line_settings *gpiod_line_settings_new(void)
@@ -65,7 +65,7 @@ gpiod_line_settings_copy(struct gpiod_line_settings *settings)
 
 GPIOD_API int
 gpiod_line_settings_set_direction(struct gpiod_line_settings *settings,
-				  int direction)
+				  enum gpiod_line_direction direction)
 {
 	switch (direction) {
 	case GPIOD_LINE_DIRECTION_INPUT:
@@ -82,7 +82,7 @@ gpiod_line_settings_set_direction(struct gpiod_line_settings *settings,
 	return 0;
 }
 
-GPIOD_API int
+GPIOD_API enum gpiod_line_direction
 gpiod_line_settings_get_direction(struct gpiod_line_settings *settings)
 {
 	return settings->direction;
@@ -90,7 +90,7 @@ gpiod_line_settings_get_direction(struct gpiod_line_settings *settings)
 
 GPIOD_API int
 gpiod_line_settings_set_edge_detection(struct gpiod_line_settings *settings,
-				       int edge)
+				       enum gpiod_line_edge edge)
 {
 	switch (edge) {
 	case GPIOD_LINE_EDGE_NONE:
@@ -108,14 +108,15 @@ gpiod_line_settings_set_edge_detection(struct gpiod_line_settings *settings,
 	return 0;
 }
 
-GPIOD_API int
+GPIOD_API enum gpiod_line_edge
 gpiod_line_settings_get_edge_detection(struct gpiod_line_settings *settings)
 {
 	return settings->edge_detection;
 }
 
 GPIOD_API int
-gpiod_line_settings_set_bias(struct gpiod_line_settings *settings, int bias)
+gpiod_line_settings_set_bias(struct gpiod_line_settings *settings,
+			     enum gpiod_line_bias bias)
 {
 	switch (bias) {
 	case GPIOD_LINE_BIAS_AS_IS:
@@ -133,13 +134,15 @@ gpiod_line_settings_set_bias(struct gpiod_line_settings *settings, int bias)
 	return 0;
 }
 
-GPIOD_API int gpiod_line_settings_get_bias(struct gpiod_line_settings *settings)
+GPIOD_API enum gpiod_line_bias
+gpiod_line_settings_get_bias(struct gpiod_line_settings *settings)
 {
 	return settings->bias;
 }
 
 GPIOD_API int
-gpiod_line_settings_set_drive(struct gpiod_line_settings *settings, int drive)
+gpiod_line_settings_set_drive(struct gpiod_line_settings *settings,
+			      enum gpiod_line_drive drive)
 {
 	switch (drive) {
 	case GPIOD_LINE_DRIVE_PUSH_PULL:
@@ -156,7 +159,7 @@ gpiod_line_settings_set_drive(struct gpiod_line_settings *settings, int drive)
 	return 0;
 }
 
-GPIOD_API int
+GPIOD_API enum gpiod_line_drive
 gpiod_line_settings_get_drive(struct gpiod_line_settings *settings)
 {
 	return settings->drive;
@@ -190,7 +193,7 @@ gpiod_line_settings_get_debounce_period_us(struct gpiod_line_settings *settings)
 
 GPIOD_API int
 gpiod_line_settings_set_event_clock(struct gpiod_line_settings *settings,
-				    int event_clock)
+				    enum gpiod_line_event_clock event_clock)
 {
 	switch (event_clock) {
 	case GPIOD_LINE_EVENT_CLOCK_MONOTONIC:
@@ -207,7 +210,7 @@ gpiod_line_settings_set_event_clock(struct gpiod_line_settings *settings,
 	return 0;
 }
 
-GPIOD_API int
+GPIOD_API enum gpiod_line_event_clock
 gpiod_line_settings_get_event_clock(struct gpiod_line_settings *settings)
 {
 	return settings->event_clock;
@@ -215,7 +218,7 @@ gpiod_line_settings_get_event_clock(struct gpiod_line_settings *settings)
 
 GPIOD_API int
 gpiod_line_settings_set_output_value(struct gpiod_line_settings *settings,
-				     int value)
+				     enum gpiod_line_value value)
 {
 	switch (value) {
 	case GPIOD_LINE_VALUE_INACTIVE:
@@ -231,7 +234,7 @@ gpiod_line_settings_set_output_value(struct gpiod_line_settings *settings,
 	return 0;
 }
 
-GPIOD_API int
+GPIOD_API enum gpiod_line_value
 gpiod_line_settings_get_output_value(struct gpiod_line_settings *settings)
 {
 	return settings->output_value;
tests/gpiosim/gpiosim.c +14 -12
index ea638cd..5a8ec88 100644
@@ -1007,8 +1007,8 @@ GPIOSIM_API int gpiosim_bank_set_line_name(struct gpiosim_bank *bank,
 }
 
 GPIOSIM_API int gpiosim_bank_hog_line(struct gpiosim_bank *bank,
-				      unsigned int offset,
-				      const char *name, int direction)
+				      unsigned int offset, const char *name,
+				      enum gpiosim_direction direction)
 {
 	char buf[64], *dir;
 	int ret, fd;
@@ -1081,15 +1081,16 @@ static int sysfs_read_bank_attr(struct gpiosim_bank *bank, unsigned int offset,
 	return open_read_close(bank->sysfs_dir_fd, where, buf, bufsize);
 }
 
-GPIOSIM_API int gpiosim_bank_get_value(struct gpiosim_bank *bank,
-				       unsigned int offset)
+GPIOSIM_API enum
+gpiosim_value gpiosim_bank_get_value(struct gpiosim_bank *bank,
+				     unsigned int offset)
 {
 	char what[3];
 	int ret;
 
 	ret = sysfs_read_bank_attr(bank, offset, "value", what, sizeof(what));
 	if (ret)
-		return ret;
+		return GPIOSIM_VALUE_ERROR;
 
 	if (what[0] == '0')
 		return GPIOSIM_VALUE_INACTIVE;
@@ -1097,18 +1098,18 @@ GPIOSIM_API int gpiosim_bank_get_value(struct gpiosim_bank *bank,
 		return GPIOSIM_VALUE_ACTIVE;
 
 	errno = EIO;
-	return -1;
+	return GPIOSIM_VALUE_ERROR;
 }
 
-GPIOSIM_API int gpiosim_bank_get_pull(struct gpiosim_bank *bank,
-				      unsigned int offset)
+GPIOSIM_API enum gpiosim_pull
+gpiosim_bank_get_pull(struct gpiosim_bank *bank, unsigned int offset)
 {
 	char what[16];
 	int ret;
 
 	ret = sysfs_read_bank_attr(bank, offset, "pull", what, sizeof(what));
 	if (ret)
-		return ret;
+		return GPIOSIM_PULL_ERROR;
 
 	if (strcmp(what, "pull-down") == 0)
 		return GPIOSIM_PULL_DOWN;
@@ -1116,11 +1117,12 @@ GPIOSIM_API int gpiosim_bank_get_pull(struct gpiosim_bank *bank,
 		return GPIOSIM_PULL_UP;
 
 	errno = EIO;
-	return -1;
+	return GPIOSIM_PULL_ERROR;
 }
 
-GPIOSIM_API int gpiosim_bank_set_pull(struct gpiosim_bank *bank,
-				      unsigned int offset, int pull)
+GPIOSIM_API int
+gpiosim_bank_set_pull(struct gpiosim_bank *bank,
+		      unsigned int offset, enum gpiosim_pull pull)
 {
 	struct gpiosim_dev *dev = bank->dev;
 	char where[32], what[16];
tests/gpiosim/gpiosim.h +11 -7
index 8013595..80d437e 100644
@@ -15,17 +15,19 @@ struct gpiosim_ctx;
 struct gpiosim_dev;
 struct gpiosim_bank;
 
-enum {
+enum gpiosim_value {
+	GPIOSIM_VALUE_ERROR = -1,
 	GPIOSIM_VALUE_INACTIVE = 0,
 	GPIOSIM_VALUE_ACTIVE = 1,
 };
 
-enum {
+enum gpiosim_pull {
+	GPIOSIM_PULL_ERROR = -1,
 	GPIOSIM_PULL_DOWN = 1,
 	GPIOSIM_PULL_UP,
 };
 
-enum {
+enum gpiosim_direction {
 	GPIOSIM_HOG_DIR_INPUT = 1,
 	GPIOSIM_HOG_DIR_OUTPUT_HIGH,
 	GPIOSIM_HOG_DIR_OUTPUT_LOW,
@@ -59,13 +61,15 @@ int gpiosim_bank_set_num_lines(struct gpiosim_bank *bank, size_t num_lines);
 int gpiosim_bank_set_line_name(struct gpiosim_bank *bank,
 			       unsigned int offset, const char *name);
 int gpiosim_bank_hog_line(struct gpiosim_bank *bank, unsigned int offset,
-			  const char *name, int direction);
+			  const char *name, enum gpiosim_direction direction);
 int gpiosim_bank_clear_hog(struct gpiosim_bank *bank, unsigned int offset);
 
-int gpiosim_bank_get_value(struct gpiosim_bank *bank, unsigned int offset);
-int gpiosim_bank_get_pull(struct gpiosim_bank *bank, unsigned int offset);
+enum gpiosim_value
+gpiosim_bank_get_value(struct gpiosim_bank *bank, unsigned int offset);
+enum gpiosim_pull
+gpiosim_bank_get_pull(struct gpiosim_bank *bank, unsigned int offset);
 int gpiosim_bank_set_pull(struct gpiosim_bank *bank,
-			  unsigned int offset, int pull);
+			  unsigned int offset, enum gpiosim_pull pull);
 
 #ifdef __cplusplus
 } /* extern "C" */
tests/tests-line-request.c +15 -10
index 92e3028..6cf85ab 100644
@@ -173,7 +173,8 @@ GPIOD_TEST_CASE(read_all_values)
 	g_autoptr(struct_gpiod_line_settings) settings = NULL;
 	g_autoptr(struct_gpiod_line_config) line_cfg = NULL;
 	g_autoptr(struct_gpiod_line_request) request = NULL;
-	gint ret, values[5];
+	enum gpiod_line_value values[5];
+	gint ret;
 	guint i;
 
 	chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
@@ -232,11 +233,13 @@ GPIOD_TEST_CASE(request_multiple_values_but_read_one)
 GPIOD_TEST_CASE(set_all_values)
 {
 	static const guint offsets[] = { 0, 2, 4, 5, 6 };
-	static const gint values[] = { GPIOD_LINE_VALUE_ACTIVE,
-				       GPIOD_LINE_VALUE_INACTIVE,
-				       GPIOD_LINE_VALUE_ACTIVE,
-				       GPIOD_LINE_VALUE_ACTIVE,
-				       GPIOD_LINE_VALUE_ACTIVE };
+	static const enum gpiod_line_value values[] = {
+		GPIOD_LINE_VALUE_ACTIVE,
+		GPIOD_LINE_VALUE_INACTIVE,
+		GPIOD_LINE_VALUE_ACTIVE,
+		GPIOD_LINE_VALUE_ACTIVE,
+		GPIOD_LINE_VALUE_ACTIVE
+	};
 
 	g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 8, NULL);
 	g_autoptr(struct_gpiod_chip) chip = NULL;
@@ -270,9 +273,11 @@ GPIOD_TEST_CASE(set_values_subset_of_lines)
 {
 	static const guint offsets[] = { 0, 1, 2, 3 };
 	static const guint offsets_to_set[] = { 0, 1, 3 };
-	static const gint values[] = { GPIOD_LINE_VALUE_ACTIVE,
-				       GPIOD_LINE_VALUE_INACTIVE,
-				       GPIOD_LINE_VALUE_ACTIVE };
+	static const enum gpiod_line_value values[] = {
+		GPIOD_LINE_VALUE_ACTIVE,
+		GPIOD_LINE_VALUE_INACTIVE,
+		GPIOD_LINE_VALUE_ACTIVE
+	};
 
 	g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 4, NULL);
 	g_autoptr(struct_gpiod_chip) chip = NULL;
@@ -508,8 +513,8 @@ GPIOD_TEST_CASE(request_lines_with_unordered_offsets)
 	g_autoptr(struct_gpiod_line_settings) settings = NULL;
 	g_autoptr(struct_gpiod_line_config) line_cfg = NULL;
 	g_autoptr(struct_gpiod_line_request) request = NULL;
+	enum gpiod_line_value values[4];
 	guint set_offsets[4];
-	gint values[4];
 
 	chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
 	settings = gpiod_test_create_line_settings_or_fail();
tools/gpioget.c +4 -3
index 31a3102..08c17e6 100644
@@ -17,8 +17,8 @@ struct config {
 	bool numeric;
 	bool strict;
 	bool unquoted;
-	int bias;
-	int direction;
+	enum gpiod_line_bias bias;
+	enum gpiod_line_direction direction;
 	unsigned int hold_period_us;
 	const char *chip_id;
 	const char *consumer;
@@ -137,11 +137,12 @@ int main(int argc, char **argv)
 	struct gpiod_request_config *req_cfg;
 	struct gpiod_line_request *request;
 	struct gpiod_line_config *line_cfg;
-	int i, num_lines, ret, *values;
 	struct line_resolver *resolver;
+	enum gpiod_line_value *values;
 	struct resolved_line *line;
 	struct gpiod_chip *chip;
 	unsigned int *offsets;
+	int i, num_lines, ret;
 	struct config cfg;
 	const char *fmt;
 
tools/gpiomon.c +3 -3
index 45e4471..dc157df 100644
@@ -21,14 +21,14 @@ struct config {
 	bool quiet;
 	bool strict;
 	bool unquoted;
-	int bias;
-	int edges;
+	enum gpiod_line_bias bias;
+	enum gpiod_line_edge edges;
 	int events_wanted;
 	unsigned int debounce_period_us;
 	const char *chip_id;
 	const char *consumer;
 	const char *fmt;
-	int event_clock;
+	enum gpiod_line_event_clock event_clock;
 	int timestamp_fmt;
 };
 
tools/gpioset.c +24 -21

115 lines not on this page · raw message

tools/tools-common.c +4 -3
index 69af77a..6dbcf57 100644
@@ -336,7 +336,7 @@ static void print_consumer(struct gpiod_line_info *info, bool unquoted)
 
 void print_line_attributes(struct gpiod_line_info *info, bool unquoted_strings)
 {
-	int direction;
+	enum gpiod_line_direction direction;
 
 	direction = gpiod_line_info_get_direction(info);
 
@@ -714,7 +714,7 @@ void free_line_resolver(struct line_resolver *resolver)
 
 int get_line_offsets_and_values(struct line_resolver *resolver,
 				int chip_num, unsigned int *offsets,
-				int *values)
+				enum gpiod_line_value *values)
 {
 	struct resolved_line *line;
 	int i, num_lines = 0;
@@ -754,7 +754,8 @@ const char *get_line_name(struct line_resolver *resolver,
 	return 0;
 }
 
-void set_line_values(struct line_resolver *resolver, int chip_num, int *values)
+void set_line_values(struct line_resolver *resolver, int chip_num,
+		     enum gpiod_line_value *values)
 {
 	int i, j;
 
tools/tools-common.h +5 -3
index aa697de..d467197 100644
@@ -110,11 +110,13 @@ bool resolve_lines_by_offset(struct line_resolver *resolver,
 bool resolve_done(struct line_resolver *resolver);
 void validate_resolution(struct line_resolver *resolver, const char *chip_id);
 void free_line_resolver(struct line_resolver *resolver);
-int get_line_offsets_and_values(struct line_resolver *resolver,
-		int chip_num, unsigned int *offsets, int *values);
+int get_line_offsets_and_values(struct line_resolver *resolver, int chip_num,
+				unsigned int *offsets,
+				enum gpiod_line_value *values);
 const char *get_chip_name(struct line_resolver *resolver, int chip_num);
 const char *get_line_name(struct line_resolver *resolver, int chip_num,
 			  unsigned int offset);
-void set_line_values(struct line_resolver *resolver, int chip_num, int *values);
+void set_line_values(struct line_resolver *resolver, int chip_num,
+		     enum gpiod_line_value *values);
 
 #endif /* __GPIOD_TOOLS_COMMON_H__ */
Signature · 1 line
2.37.2
Acked-by on v1 1/11
#2 lore raw

Re: [libgpiod][PATCH 01/11] treewide: use C enum types explicitly

Quoted 5 lines · Bartosz Golaszewski
 bindings/rust/gpiosim-sys/src/lib.rs        |  42 +++--
 bindings/rust/gpiosim-sys/src/sim.rs        |   2 +-
 bindings/rust/libgpiod/src/lib.rs           | 169 ++++++++++++--------
 bindings/rust/libgpiod/src/line_info.rs     |  10 +-
 bindings/rust/libgpiod/src/line_settings.rs |  30 ++--
Signature · 1 line
viresh
#3 lore raw

PATCH 2/11 treewide: apply formatting changes with clang-format

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Use linux kernel's .clang-format file to automatically improve the coding style of libgpiod's C code base. We don't import the file into the repository as it's not perfect and certain converted fragments were rolled back because they looked better before the conversion.

---
 lib/edge-event.c             |  8 +++---
 lib/internal.c               |  4 +--
 lib/internal.h               |  3 ++-
 lib/line-config.c            | 39 +++++++++++++--------------
 lib/line-settings.c          |  5 ++--
 tests/gpiod-test-sim.c       | 41 +++++++++++++++++-----------
 tests/gpiosim/gpiosim.c      | 18 +++++--------
 tests/gpiosim/gpiosim.h      |  6 ++---
 tests/tests-chip-info.c      |  1 -
 tests/tests-edge-event.c     | 52 +++++++++++++++---------------------
 tests/tests-info-event.c     |  2 +-
 tests/tests-line-config.c    |  2 +-
 tests/tests-line-info.c      | 23 ++++++++--------
 tests/tests-line-request.c   | 33 ++++++++++++-----------
 tests/tests-line-settings.c  | 16 +++++------
 tests/tests-request-config.c | 12 ++++-----
 tools/gpiodetect.c           |  3 +--
 tools/gpioinfo.c             | 12 ++++-----
 tools/gpiomon.c              | 11 ++++----
 tools/gpionotify.c           | 10 +++----
 tools/gpioset.c              | 48 +++++++++++++++------------------
 tools/tools-common.c         | 34 +++++++++++------------
 tools/tools-common.h         |  3 ++-
 23 files changed, 182 insertions(+), 204 deletions(-)
lib/edge-event.c +4 -4
index ad8a7d1..fbbe4a8 100644
@@ -131,7 +131,7 @@ gpiod_edge_event_buffer_free(struct gpiod_edge_event_buffer *buffer)
 
 GPIOD_API struct gpiod_edge_event *
 gpiod_edge_event_buffer_get_event(struct gpiod_edge_event_buffer *buffer,
-				   unsigned long index)
+				  unsigned long index)
 {
 	if (index >= buffer->num_events) {
 		errno = EINVAL;
@@ -179,9 +179,9 @@ int gpiod_edge_event_buffer_read_fd(int fd,
 		event = &buffer->events[i];
 
 		event->line_offset = curr->offset;
-		event->event_type = curr->id == GPIO_V2_LINE_EVENT_RISING_EDGE
-					? GPIOD_EDGE_EVENT_RISING_EDGE
-					: GPIOD_EDGE_EVENT_FALLING_EDGE;
+		event->event_type = curr->id == GPIO_V2_LINE_EVENT_RISING_EDGE ?
+					    GPIOD_EDGE_EVENT_RISING_EDGE :
+					    GPIOD_EDGE_EVENT_FALLING_EDGE;
 		event->timestamp = curr->timestamp_ns;
 		event->global_seqno = curr->seqno;
 		event->line_seqno = curr->line_seqno;
lib/internal.c +2 -2
index ef87ecd..5d79ff7 100644
@@ -29,8 +29,8 @@ bool gpiod_check_gpiochip_device(const char *path, bool set_errno)
 	 * Is it a symbolic link? We have to resolve it before checking
 	 * the rest.
 	 */
-	realname = S_ISLNK(statbuf.st_mode) ? realpath(path, NULL)
-					    : strdup(path);
+	realname = S_ISLNK(statbuf.st_mode) ? realpath(path, NULL) :
+					      strdup(path);
 	if (realname == NULL)
 		goto out;
 
lib/internal.h +2 -1
index eef70aa..6646647 100644
@@ -27,7 +27,8 @@ int gpiod_line_config_to_uapi(struct gpiod_line_config *config,
 			      struct gpio_v2_line_request *uapi_cfg);
 struct gpiod_line_request *
 gpiod_line_request_from_uapi(struct gpio_v2_line_request *uapi_req);
-int gpiod_edge_event_buffer_read_fd(int fd, struct gpiod_edge_event_buffer *buffer,
+int gpiod_edge_event_buffer_read_fd(int fd,
+				    struct gpiod_edge_event_buffer *buffer,
 				    size_t max_events);
 struct gpiod_info_event *
 gpiod_info_event_from_uapi(struct gpio_v2_line_info_changed *uapi_evt);
lib/line-config.c +18 -21
index 48ea618..436f4e8 100644
@@ -63,8 +63,8 @@ GPIOD_API void gpiod_line_config_reset(struct gpiod_line_config *config)
 	memset(config, 0, sizeof(*config));
 }
 
-static struct per_line_config *
-find_config(struct gpiod_line_config *config, unsigned int offset)
+static struct per_line_config *find_config(struct gpiod_line_config *config,
+					   unsigned int offset)
 {
 	struct per_line_config *per_line;
 	size_t i;
@@ -79,11 +79,9 @@ find_config(struct gpiod_line_config *config, unsigned int offset)
 	return &config->line_configs[config->num_configs++];
 }
 
-GPIOD_API int
-gpiod_line_config_add_line_settings(struct gpiod_line_config *config,
-				    const unsigned int *offsets,
-				    size_t num_offsets,
-				    struct gpiod_line_settings *settings)
+GPIOD_API int gpiod_line_config_add_line_settings(
+	struct gpiod_line_config *config, const unsigned int *offsets,
+	size_t num_offsets, struct gpiod_line_settings *settings)
 {
 	struct per_line_config *per_line;
 	struct settings_node *node;
@@ -139,10 +137,9 @@ gpiod_line_config_get_line_settings(struct gpiod_line_config *config,
 	return NULL;
 }
 
-GPIOD_API int
-gpiod_line_config_get_offsets(struct gpiod_line_config *config,
-			      size_t *num_offsets,
-			      unsigned int **offsets)
+GPIOD_API int gpiod_line_config_get_offsets(struct gpiod_line_config *config,
+					    size_t *num_offsets,
+					    unsigned int **offsets)
 {
 	unsigned int *offs;
 	size_t i;
@@ -182,7 +179,7 @@ static bool has_at_least_one_output_direction(struct gpiod_line_config *config)
 
 	for (i = 0; i < config->num_configs; i++) {
 		if (gpiod_line_settings_get_direction(
-				config->line_configs[i].node->settings) ==
+			    config->line_configs[i].node->settings) ==
 		    GPIOD_LINE_DIRECTION_OUTPUT)
 			return true;
 	}
@@ -204,15 +201,15 @@ static void set_kernel_output_values(uint64_t *mask, uint64_t *vals,
 		per_line = &config->line_configs[i];
 
 		if (gpiod_line_settings_get_direction(
-				per_line->node->settings) !=
+			    per_line->node->settings) !=
 		    GPIOD_LINE_DIRECTION_OUTPUT)
 			continue;
 
 		gpiod_line_mask_set_bit(mask, i);
 		value = gpiod_line_settings_get_output_value(
-						per_line->node->settings);
-		gpiod_line_mask_assign_bit(vals, i,
-				value == GPIOD_LINE_VALUE_ACTIVE ? 1 : 0);
+			per_line->node->settings);
+		gpiod_line_mask_assign_bit(
+			vals, i, value == GPIOD_LINE_VALUE_ACTIVE ? 1 : 0);
 	}
 }
 
@@ -299,18 +296,18 @@ static uint64_t make_kernel_flags(struct gpiod_line_settings *settings)
 	switch (gpiod_line_settings_get_edge_detection(settings)) {
 	case GPIOD_LINE_EDGE_FALLING:
 		flags |= (GPIO_V2_LINE_FLAG_EDGE_FALLING |
-			   GPIO_V2_LINE_FLAG_INPUT);
+			  GPIO_V2_LINE_FLAG_INPUT);
 		flags &= ~GPIOD_LINE_DIRECTION_OUTPUT;
 		break;
 	case GPIOD_LINE_EDGE_RISING:
 		flags |= (GPIO_V2_LINE_FLAG_EDGE_RISING |
-			   GPIO_V2_LINE_FLAG_INPUT);
+			  GPIO_V2_LINE_FLAG_INPUT);
 		flags &= ~GPIOD_LINE_DIRECTION_OUTPUT;
 		break;
 	case GPIOD_LINE_EDGE_BOTH:
 		flags |= (GPIO_V2_LINE_FLAG_EDGE_FALLING |
-			   GPIO_V2_LINE_FLAG_EDGE_RISING |
-			   GPIO_V2_LINE_FLAG_INPUT);
+			  GPIO_V2_LINE_FLAG_EDGE_RISING |
+			  GPIO_V2_LINE_FLAG_INPUT);
 		flags &= ~GPIOD_LINE_DIRECTION_OUTPUT;
 		break;
 	default:
@@ -360,7 +357,7 @@ static uint64_t make_kernel_flags(struct gpiod_line_settings *settings)
 }
 
 static bool settings_equal(struct gpiod_line_settings *left,
-			 struct gpiod_line_settings *right)
+			   struct gpiod_line_settings *right)
 {
 	if (gpiod_line_settings_get_direction(left) !=
 	    gpiod_line_settings_get_direction(right))
lib/line-settings.c +2 -3
index f245b20..dcd0f6b 100644
@@ -114,9 +114,8 @@ gpiod_line_settings_get_edge_detection(struct gpiod_line_settings *settings)
 	return settings->edge_detection;
 }
 
-GPIOD_API int
-gpiod_line_settings_set_bias(struct gpiod_line_settings *settings,
-			     enum gpiod_line_bias bias)
+GPIOD_API int gpiod_line_settings_set_bias(struct gpiod_line_settings *settings,
+					   enum gpiod_line_bias bias)
 {
 	switch (bias) {
 	case GPIOD_LINE_BIAS_AS_IS:
tests/gpiod-test-sim.c +25 -16

60 lines not on this page · raw message

tests/gpiosim/gpiosim.c +7 -11
index 5a8ec88..9e6c635 100644
@@ -213,8 +213,7 @@ static void list_del(struct list_head *entry)
 	((type *)(__mptr - offsetof(type, member))); \
 })
 
-#define list_entry(ptr, type, member) \
-	container_of(ptr, type, member)
+#define list_entry(ptr, type, member) container_of(ptr, type, member)
 
 #define list_first_entry(ptr, type, member) \
 	list_entry((ptr)->next, type, member)
@@ -222,8 +221,7 @@ static void list_del(struct list_head *entry)
 #define list_next_entry(pos, member) \
 	list_entry((pos)->member.next, typeof(*(pos)), member)
 
-#define list_entry_is_head(pos, head, member) \
-	(&pos->member == (head))
+#define list_entry_is_head(pos, head, member) (&pos->member == (head))
 
 #define list_for_each_entry(pos, head, member) \
 	for (pos = list_first_entry(head, typeof(*pos), member); \
@@ -334,9 +332,9 @@ again:
 				goto out_unref_module;
 			}
 
-			ret = kmod_module_probe_insert_module(module,
-						KMOD_PROBE_IGNORE_LOADED,
-						NULL, NULL, NULL, NULL);
+			ret = kmod_module_probe_insert_module(
+				module, KMOD_PROBE_IGNORE_LOADED, NULL, NULL,
+				NULL, NULL);
 			if (ret)
 				goto out_unref_module;
 
@@ -577,8 +575,7 @@ static void dev_release(struct refcount *ref)
 	free(dev);
 }
 
-GPIOSIM_API struct gpiosim_dev *
-gpiosim_dev_new(struct gpiosim_ctx *ctx)
+GPIOSIM_API struct gpiosim_dev *gpiosim_dev_new(struct gpiosim_ctx *ctx)
 {
 	int configfs_fd, ret, id;
 	struct gpiosim_dev *dev;
@@ -855,8 +852,7 @@ static void bank_release(struct refcount *ref)
 	free(bank);
 }
 
-GPIOSIM_API struct gpiosim_bank*
-gpiosim_bank_new(struct gpiosim_dev *dev)
+GPIOSIM_API struct gpiosim_bank *gpiosim_bank_new(struct gpiosim_dev *dev)
 {
 	struct gpiosim_bank *bank;
 	int configfs_fd, id;
tests/gpiosim/gpiosim.h +2 -4
index 80d437e..ab26900 100644
@@ -37,8 +37,7 @@ struct gpiosim_ctx *gpiosim_ctx_new(void);
 struct gpiosim_ctx *gpiosim_ctx_ref(struct gpiosim_ctx *ctx);
 void gpiosim_ctx_unref(struct gpiosim_ctx *ctx);
 
-struct gpiosim_dev *
-gpiosim_dev_new(struct gpiosim_ctx *ctx);
+struct gpiosim_dev *gpiosim_dev_new(struct gpiosim_ctx *ctx);
 struct gpiosim_dev *gpiosim_dev_ref(struct gpiosim_dev *dev);
 void gpiosim_dev_unref(struct gpiosim_dev *dev);
 struct gpiosim_ctx *gpiosim_dev_get_ctx(struct gpiosim_dev *dev);
@@ -48,8 +47,7 @@ int gpiosim_dev_enable(struct gpiosim_dev *dev);
 int gpiosim_dev_disable(struct gpiosim_dev *dev);
 bool gpiosim_dev_is_live(struct gpiosim_dev *dev);
 
-struct gpiosim_bank*
-gpiosim_bank_new(struct gpiosim_dev *dev);
+struct gpiosim_bank *gpiosim_bank_new(struct gpiosim_dev *dev);
 struct gpiosim_bank *gpiosim_bank_ref(struct gpiosim_bank *bank);
 void gpiosim_bank_unref(struct gpiosim_bank *bank);
 struct gpiosim_dev *gpiosim_bank_get_dev(struct gpiosim_bank *bank);
tests/tests-chip-info.c +0 -1
index 85477c6..c43cfbe 100644
@@ -48,4 +48,3 @@ GPIOD_TEST_CASE(get_num_lines)
 
 	g_assert_cmpuint(gpiod_chip_info_get_num_lines(info), ==, 16);
 }
-
tests/tests-edge-event.c +22 -30

142 lines not on this page · raw message

tests/tests-info-event.c +1 -1
index a960ba9..a0cf5b6 100644
@@ -199,7 +199,7 @@ GPIOD_TEST_CASE(request_reconfigure_release_events)
 }
 
 GPIOD_TEST_CASE(chip_fd_can_be_polled)
-{\
+{
 	g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 8, NULL);
 	g_autoptr(struct_gpiod_chip) chip = NULL;
 	g_autoptr(struct_gpiod_line_info) info = NULL;
tests/tests-line-config.c +1 -1
index 27cc228..5dc9022 100644
@@ -110,7 +110,7 @@ GPIOD_TEST_CASE(too_many_attrs)
 							 settings);
 
 	gpiod_line_settings_set_event_clock(settings,
-					     GPIOD_LINE_EVENT_CLOCK_REALTIME);
+					    GPIOD_LINE_EVENT_CLOCK_REALTIME);
 	offset = 7;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
tests/tests-line-info.c +11 -12
index 8ec1b1b..4751db2 100644
@@ -66,11 +66,9 @@ GPIOD_TEST_CASE(line_info_basic_properties)
 	g_autoptr(struct_gpiod_line_info) info4 = NULL;
 	g_autoptr(struct_gpiod_line_info) info6 = NULL;
 
-	sim = g_gpiosim_chip_new(
-			"num-lines", 8,
-			"line-names", gpiod_test_package_line_names(names),
-			"hogs", gpiod_test_package_hogs(hogs),
-			NULL);
+	sim = g_gpiosim_chip_new("num-lines", 8, "line-names",
+				 gpiod_test_package_line_names(names), "hogs",
+				 gpiod_test_package_hogs(hogs), NULL);
 
 	chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
 	info4 = gpiod_test_get_line_info_or_fail(chip, 4);
@@ -137,8 +135,7 @@ GPIOD_TEST_CASE(direction_settings)
 	offset = 1;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
-	gpiod_line_settings_set_direction(settings,
-					  GPIOD_LINE_DIRECTION_AS_IS);
+	gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_AS_IS);
 	offset = 2;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
@@ -202,7 +199,8 @@ GPIOD_TEST_CASE(edge_detection_settings)
 	offset = 0;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
-	gpiod_line_settings_set_edge_detection(settings, GPIOD_LINE_EDGE_RISING);
+	gpiod_line_settings_set_edge_detection(settings,
+					       GPIOD_LINE_EDGE_RISING);
 	offset = 1;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
@@ -249,7 +247,8 @@ GPIOD_TEST_CASE(bias_settings)
 	settings = gpiod_test_create_line_settings_or_fail();
 	line_cfg = gpiod_test_create_line_config_or_fail();
 
-	gpiod_line_settings_set_direction(settings,GPIOD_LINE_DIRECTION_OUTPUT);
+	gpiod_line_settings_set_direction(settings,
+					  GPIOD_LINE_DIRECTION_OUTPUT);
 	offset = 0;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
@@ -349,8 +348,8 @@ GPIOD_TEST_CASE(debounce_period)
 	request = gpiod_test_request_lines_or_fail(chip, NULL, line_cfg);
 	info = gpiod_test_get_line_info_or_fail(chip, 5);
 
-	g_assert_cmpuint(gpiod_line_info_get_debounce_period_us(info),
-			 ==, 1000);
+	g_assert_cmpuint(gpiod_line_info_get_debounce_period_us(info), ==,
+			 1000);
 }
 
 GPIOD_TEST_CASE(event_clock)
@@ -391,7 +390,7 @@ GPIOD_TEST_CASE(event_clock)
 	}
 
 	gpiod_test_return_if_failed();
-	
+
 	info0 = gpiod_test_get_line_info_or_fail(chip, 0);
 	info1 = gpiod_test_get_line_info_or_fail(chip, 1);
 	info2 = gpiod_test_get_line_info_or_fail(chip, 2);
tests/tests-line-request.c +17 -16
index 6cf85ab..2c2af01 100644
@@ -156,8 +156,8 @@ GPIOD_TEST_CASE(default_output_value)
 	request = gpiod_test_request_lines_or_fail(chip, NULL, line_cfg);
 
 	for (i = 0; i < 4; i++)
-		g_assert_cmpint(g_gpiosim_chip_get_value(sim, offsets[i]),
-				==, GPIOD_LINE_VALUE_ACTIVE);
+		g_assert_cmpint(g_gpiosim_chip_get_value(sim, offsets[i]), ==,
+				GPIOD_LINE_VALUE_ACTIVE);
 
 	g_assert_cmpint(g_gpiosim_chip_get_value(sim, 2), ==,
 			GPIOD_LINE_VALUE_INACTIVE);
@@ -189,7 +189,8 @@ GPIOD_TEST_CASE(read_all_values)
 
 	for (i = 0; i < 5; i++)
 		g_gpiosim_chip_set_pull(sim, offsets[i],
-			pulls[i] ? G_GPIOSIM_PULL_UP : G_GPIOSIM_PULL_DOWN);
+					pulls[i] ? G_GPIOSIM_PULL_UP :
+						   G_GPIOSIM_PULL_DOWN);
 
 	ret = gpiod_line_request_get_values(request, values);
 	g_assert_cmpint(ret, ==, 0);
@@ -224,7 +225,8 @@ GPIOD_TEST_CASE(request_multiple_values_but_read_one)
 
 	for (i = 0; i < 5; i++)
 		g_gpiosim_chip_set_pull(sim, offsets[i],
-			pulls[i] ? G_GPIOSIM_PULL_UP : G_GPIOSIM_PULL_DOWN);
+					pulls[i] ? G_GPIOSIM_PULL_UP :
+						   G_GPIOSIM_PULL_DOWN);
 
 	ret = gpiod_line_request_get_value(request, 5);
 	g_assert_cmpint(ret, ==, 1);
@@ -265,8 +267,8 @@ GPIOD_TEST_CASE(set_all_values)
 	gpiod_test_return_if_failed();
 
 	for (i = 0; i < 5; i++)
-		g_assert_cmpint(g_gpiosim_chip_get_value(sim, offsets[i]),
-				==, values[i]);
+		g_assert_cmpint(g_gpiosim_chip_get_value(sim, offsets[i]), ==,
+				values[i]);
 }
 
 GPIOD_TEST_CASE(set_values_subset_of_lines)
@@ -297,17 +299,17 @@ GPIOD_TEST_CASE(set_values_subset_of_lines)
 
 	request = gpiod_test_request_lines_or_fail(chip, NULL, line_cfg);
 
-	ret = gpiod_line_request_set_values_subset(request, 3,
-						   offsets_to_set, values);
+	ret = gpiod_line_request_set_values_subset(request, 3, offsets_to_set,
+						   values);
 	g_assert_cmpint(ret, ==, 0);
 	gpiod_test_return_if_failed();
 
-	g_assert_cmpint(g_gpiosim_chip_get_value(sim, 0),
-			==, GPIOD_LINE_VALUE_ACTIVE);
-	g_assert_cmpint(g_gpiosim_chip_get_value(sim, 1),
-			==, GPIOD_LINE_VALUE_INACTIVE);
-	g_assert_cmpint(g_gpiosim_chip_get_value(sim, 3),
-			==, GPIOD_LINE_VALUE_ACTIVE);
+	g_assert_cmpint(g_gpiosim_chip_get_value(sim, 0), ==,
+			GPIOD_LINE_VALUE_ACTIVE);
+	g_assert_cmpint(g_gpiosim_chip_get_value(sim, 1), ==,
+			GPIOD_LINE_VALUE_INACTIVE);
+	g_assert_cmpint(g_gpiosim_chip_get_value(sim, 3), ==,
+			GPIOD_LINE_VALUE_ACTIVE);
 }
 
 GPIOD_TEST_CASE(set_line_after_requesting)
@@ -358,8 +360,7 @@ GPIOD_TEST_CASE(request_survives_parent_chip)
 
 	gpiod_line_settings_set_direction(settings,
 					  GPIOD_LINE_DIRECTION_OUTPUT);
-	gpiod_line_settings_set_output_value(settings,
-					     GPIOD_LINE_VALUE_ACTIVE);
+	gpiod_line_settings_set_output_value(settings, GPIOD_LINE_VALUE_ACTIVE);
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
 
tests/tests-line-settings.c +6 -10
index bdf932d..e6c0277 100644
@@ -26,7 +26,7 @@ GPIOD_TEST_CASE(default_config)
 			GPIOD_LINE_DRIVE_PUSH_PULL);
 	g_assert_false(gpiod_line_settings_get_active_low(settings));
 	g_assert_cmpuint(gpiod_line_settings_get_debounce_period_us(settings),
-			==, 0);
+			 ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(settings), ==,
 			GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
 	g_assert_cmpint(gpiod_line_settings_get_output_value(settings), ==,
@@ -110,26 +110,22 @@ GPIOD_TEST_CASE(set_bias)
 
 	settings = gpiod_test_create_line_settings_or_fail();
 
-	ret = gpiod_line_settings_set_bias(settings,
-					   GPIOD_LINE_BIAS_DISABLED);
+	ret = gpiod_line_settings_set_bias(settings, GPIOD_LINE_BIAS_DISABLED);
 	g_assert_cmpint(ret, ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_bias(settings), ==,
 			GPIOD_LINE_BIAS_DISABLED);
 
-	ret = gpiod_line_settings_set_bias(settings,
-					   GPIOD_LINE_BIAS_AS_IS);
+	ret = gpiod_line_settings_set_bias(settings, GPIOD_LINE_BIAS_AS_IS);
 	g_assert_cmpint(ret, ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_bias(settings), ==,
 			GPIOD_LINE_BIAS_AS_IS);
 
-	ret = gpiod_line_settings_set_bias(settings,
-					   GPIOD_LINE_BIAS_PULL_DOWN);
+	ret = gpiod_line_settings_set_bias(settings, GPIOD_LINE_BIAS_PULL_DOWN);
 	g_assert_cmpint(ret, ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_bias(settings), ==,
 			GPIOD_LINE_BIAS_PULL_DOWN);
 
-	ret = gpiod_line_settings_set_bias(settings,
-					   GPIOD_LINE_BIAS_PULL_UP);
+	ret = gpiod_line_settings_set_bias(settings, GPIOD_LINE_BIAS_PULL_UP);
 	g_assert_cmpint(ret, ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_bias(settings), ==,
 			GPIOD_LINE_BIAS_PULL_UP);
@@ -312,7 +308,7 @@ GPIOD_TEST_CASE(reset_settings)
 			GPIOD_LINE_DRIVE_PUSH_PULL);
 	g_assert_false(gpiod_line_settings_get_active_low(settings));
 	g_assert_cmpuint(gpiod_line_settings_get_debounce_period_us(settings),
-			==, 0);
+			 ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(settings), ==,
 			GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
 	g_assert_cmpint(gpiod_line_settings_get_output_value(settings), ==,
tests/tests-request-config.c +6 -6
index f26c05a..71fccde 100644
@@ -16,8 +16,8 @@ GPIOD_TEST_CASE(default_config)
 	config = gpiod_test_create_request_config_or_fail();
 
 	g_assert_null(gpiod_request_config_get_consumer(config));
-	g_assert_cmpuint(gpiod_request_config_get_event_buffer_size(config),
-			 ==, 0);
+	g_assert_cmpuint(gpiod_request_config_get_event_buffer_size(config), ==,
+			 0);
 }
 
 GPIOD_TEST_CASE(set_consumer)
@@ -27,8 +27,8 @@ GPIOD_TEST_CASE(set_consumer)
 	config = gpiod_test_create_request_config_or_fail();
 
 	gpiod_request_config_set_consumer(config, "foobar");
-	g_assert_cmpstr(gpiod_request_config_get_consumer(config),
-			==, "foobar");
+	g_assert_cmpstr(gpiod_request_config_get_consumer(config), ==,
+			"foobar");
 }
 
 GPIOD_TEST_CASE(set_event_buffer_size)
@@ -38,6 +38,6 @@ GPIOD_TEST_CASE(set_event_buffer_size)
 	config = gpiod_test_create_request_config_or_fail();
 
 	gpiod_request_config_set_event_buffer_size(config, 128);
-	g_assert_cmpuint(gpiod_request_config_get_event_buffer_size(config),
-			 ==, 128);
+	g_assert_cmpuint(gpiod_request_config_get_event_buffer_size(config), ==,
+			 128);
 }
tools/gpiodetect.c +1 -2
index 671ed6a..f0211da 100644
@@ -74,8 +74,7 @@ static int print_chip_info(const char *path)
 	if (!info)
 		die_perror("unable to read info for '%s'", path);
 
-	printf("%s [%s] (%zu lines)\n",
-	       gpiod_chip_info_get_name(info),
+	printf("%s [%s] (%zu lines)\n", gpiod_chip_info_get_name(info),
 	       gpiod_chip_info_get_label(info),
 	       gpiod_chip_info_get_num_lines(info));
 
tools/gpioinfo.c +5 -7
index 592f4a6..1ec7f63 100644
@@ -100,7 +100,7 @@ static int parse_config(int argc, char **argv, struct config *cfg)
  * Does not die on non-unique lines.
  */
 static bool resolve_line(struct line_resolver *resolver,
-			  struct gpiod_line_info *info, int chip_num)
+			 struct gpiod_line_info *info, int chip_num)
 {
 	struct resolved_line *line;
 	bool resolved = false;
@@ -114,8 +114,7 @@ static bool resolve_line(struct line_resolver *resolver,
 		line = &resolver->lines[i];
 
 		/* already resolved by offset? */
-		if (line->resolved &&
-		    (line->offset == offset) &&
+		if (line->resolved && (line->offset == offset) &&
 		    (line->chip_num == chip_num)) {
 			resolved = true;
 		}
@@ -187,9 +186,8 @@ static void list_lines(struct line_resolver *resolver, struct gpiod_chip *chip,
 	if ((chip_num == 0) && (cfg->chip_id && !cfg->by_name))
 		resolve_lines_by_offset(resolver, num_lines);
 
-	for (offset = 0;
-	     ((offset < num_lines) &&
-	      !(resolver->num_lines && resolve_done(resolver)));
+	for (offset = 0; ((offset < num_lines) &&
+			  !(resolver->num_lines && resolve_done(resolver)));
 	     offset++) {
 		info = gpiod_chip_get_line_info(chip, offset);
 		if (!info)
@@ -238,7 +236,7 @@ int main(int argc, char **argv)
 		cfg.by_name = true;
 
 	num_chips = chip_paths(cfg.chip_id, &paths);
-	if (cfg.chip_id  && (num_chips == 0))
+	if (cfg.chip_id && (num_chips == 0))
 		die("cannot find GPIO chip character device '%s'", cfg.chip_id);
 
 	resolver = resolver_init(argc, argv, num_chips, cfg.strict,
tools/gpiomon.c +5 -6
index dc157df..ba457e4 100644
@@ -210,7 +210,7 @@ static int parse_config(int argc, char **argv, struct config *cfg)
 		else
 			cfg->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC;
 	} else if ((cfg->event_clock == GPIOD_LINE_EVENT_CLOCK_REALTIME) &&
-		 (cfg->timestamp_fmt == 0)) {
+		   (cfg->timestamp_fmt == 0)) {
 		cfg->timestamp_fmt = 1;
 	}
 
@@ -234,8 +234,8 @@ static void print_banner(int num_lines, char **lines)
 }
 
 static void event_print_formatted(struct gpiod_edge_event *event,
-			struct line_resolver *resolver, int chip_num,
-			struct config *cfg)
+				  struct line_resolver *resolver, int chip_num,
+				  struct config *cfg)
 {
 	const char *lname, *prev, *curr;
 	unsigned int offset;
@@ -381,8 +381,8 @@ int main(int argc, char **argv)
 		gpiod_line_settings_set_active_low(settings, true);
 
 	if (cfg.debounce_period_us)
-		gpiod_line_settings_set_debounce_period_us(settings,
-					cfg.debounce_period_us);
+		gpiod_line_settings_set_debounce_period_us(
+			settings, cfg.debounce_period_us);
 
 	gpiod_line_settings_set_event_clock(settings, cfg.event_clock);
 	gpiod_line_settings_set_edge_detection(settings, cfg.edges);
@@ -484,4 +484,3 @@ done:
 
 	return EXIT_SUCCESS;
 }
-
tools/gpionotify.c +5 -5
index 2367495..a0976f7 100644
@@ -216,7 +216,7 @@ static uint64_t monotonic_to_realtime(uint64_t evtime)
 	clock_gettime(CLOCK_REALTIME, &ts);
 	after = ts.tv_nsec + ((uint64_t)ts.tv_sec) * 1000000000;
 
-	evtime += (after/2 - mono + before/2);
+	evtime += (after / 2 - mono + before / 2);
 
 	return evtime;
 }
@@ -230,7 +230,7 @@ static void event_print_formatted(struct gpiod_info_event *event,
 	unsigned int offset;
 	uint64_t evtime;
 	int evtype;
-	char  fmt;
+	char fmt;
 
 	info = gpiod_info_event_get_line_info(event);
 	evtime = gpiod_info_event_get_timestamp_ns(event);
@@ -310,8 +310,8 @@ end:
 }
 
 static void event_print_human_readable(struct gpiod_info_event *event,
-			struct line_resolver *resolver, int chip_num,
-			struct config *cfg)
+				       struct line_resolver *resolver,
+				       int chip_num, struct config *cfg)
 {
 	struct gpiod_line_info *info;
 	unsigned int offset;
@@ -397,7 +397,7 @@ int main(int argc, char **argv)
 		for (j = 0; j < resolver->num_lines; j++)
 			if ((resolver->lines[j].chip_num == i) &&
 			    !gpiod_chip_watch_line_info(
-					chip, resolver->lines[j].offset))
+				    chip, resolver->lines[j].offset))
 				die_perror("unable to watch line on chip '%s'",
 					   resolver->chips[i].path);
 
tools/gpioset.c +22 -26

129 lines not on this page · raw message

tools/tools-common.c +16 -18
index 6dbcf57..4477ac8 100644
@@ -214,10 +214,10 @@ void print_event_time(uint64_t evtime, int format)
 			tz = "Z";
 		}
 		strftime(tbuf, TIME_BUFFER_SIZE, "%FT%T", &t);
-		printf("%s.%09"PRIu64"%s", tbuf, evtime % 1000000000, tz);
+		printf("%s.%09" PRIu64 "%s", tbuf, evtime % 1000000000, tz);
 	} else {
-		printf("%"PRIu64".%09"PRIu64,
-		       evtime / 1000000000, evtime % 1000000000);
+		printf("%" PRIu64 ".%09" PRIu64, evtime / 1000000000,
+		       evtime % 1000000000);
 	}
 }
 
@@ -380,8 +380,7 @@ static int chip_dir_filter(const struct dirent *entry)
 	if (asprintf(&path, "/dev/%s", entry->d_name) < 0)
 		return 0;
 
-	if ((lstat(path, &sb) == 0) &&
-	    (!S_ISLNK(sb.st_mode)) &&
+	if ((lstat(path, &sb) == 0) && (!S_ISLNK(sb.st_mode)) &&
 	    gpiod_is_gpiochip_device(path))
 		ret = 1;
 
@@ -482,8 +481,7 @@ int all_chip_paths(char ***paths_ptr)
 }
 
 static bool resolve_line(struct line_resolver *resolver,
-			  struct gpiod_line_info *info,
-			  int chip_num)
+			 struct gpiod_line_info *info, int chip_num)
 {
 	struct resolved_line *line;
 	bool resolved = false;
@@ -495,8 +493,7 @@ static bool resolve_line(struct line_resolver *resolver,
 	for (i = 0; i < resolver->num_lines; i++) {
 		line = &resolver->lines[i];
 		/* already resolved by offset? */
-		if (line->resolved &&
-		    (line->offset == offset) &&
+		if (line->resolved && (line->offset == offset) &&
 		    (line->chip_num == chip_num)) {
 			line->info = info;
 			resolver->num_found++;
@@ -548,7 +545,6 @@ bool resolve_lines_by_offset(struct line_resolver *resolver,
 	return used;
 }
 
-
 bool resolve_done(struct line_resolver *resolver)
 {
 	return (!resolver->strict &&
@@ -588,7 +584,8 @@ struct line_resolver *resolver_init(int num_lines, char **lines, int num_chips,
 }
 
 struct line_resolver *resolve_lines(int num_lines, char **lines,
-			const char *chip_id, bool strict, bool by_name)
+				    const char *chip_id, bool strict,
+				    bool by_name)
 {
 	struct gpiod_chip_info *chip_info;
 	struct gpiod_line_info *line_info;
@@ -602,7 +599,7 @@ struct line_resolver *resolve_lines(int num_lines, char **lines,
 		by_name = true;
 
 	num_chips = chip_paths(chip_id, &paths);
-	if (chip_id  && (num_chips == 0))
+	if (chip_id && (num_chips == 0))
 		die("cannot find GPIO chip character device '%s'", chip_id);
 
 	resolver = resolver_init(num_lines, lines, num_chips, strict, by_name);
@@ -666,7 +663,7 @@ void validate_resolution(struct line_resolver *resolver, const char *chip_id)
 	bool valid = true;
 	int i, j;
 
-	for (i = 0 ; i < resolver->num_lines; i++) {
+	for (i = 0; i < resolver->num_lines; i++) {
 		line = &resolver->lines[i];
 		if (line->resolved) {
 			for (j = 0; j < i; j++) {
@@ -712,8 +709,8 @@ void free_line_resolver(struct line_resolver *resolver)
 	free(resolver);
 }
 
-int get_line_offsets_and_values(struct line_resolver *resolver,
-				int chip_num, unsigned int *offsets,
+int get_line_offsets_and_values(struct line_resolver *resolver, int chip_num,
+				unsigned int *offsets,
 				enum gpiod_line_value *values)
 {
 	struct resolved_line *line;
@@ -738,8 +735,8 @@ const char *get_chip_name(struct line_resolver *resolver, int chip_num)
 	return gpiod_chip_info_get_name(resolver->chips[chip_num].info);
 }
 
-const char *get_line_name(struct line_resolver *resolver,
-			  int chip_num, unsigned int offset)
+const char *get_line_name(struct line_resolver *resolver, int chip_num,
+			  unsigned int offset)
 {
 	struct resolved_line *line;
 	int i;
@@ -748,7 +745,8 @@ const char *get_line_name(struct line_resolver *resolver,
 		line = &resolver->lines[i];
 		if (line->info && (line->offset == offset) &&
 		    (line->chip_num == chip_num))
-			return gpiod_line_info_get_name(resolver->lines[i].info);
+			return gpiod_line_info_get_name(
+				resolver->lines[i].info);
 	}
 
 	return 0;
tools/tools-common.h +2 -1
index d467197..efbeeb8 100644
@@ -102,7 +102,8 @@ bool chip_path_lookup(const char *id, char **path_ptr);
 int chip_paths(const char *id, char ***paths_ptr);
 int all_chip_paths(char ***paths_ptr);
 struct line_resolver *resolve_lines(int num_lines, char **lines,
-		const char *chip_id, bool strict, bool by_name);
+				    const char *chip_id, bool strict,
+				    bool by_name);
 struct line_resolver *resolver_init(int num_lines, char **lines, int num_chips,
 				    bool strict, bool by_name);
 bool resolve_lines_by_offset(struct line_resolver *resolver,
Signature · 1 line
2.37.2
#4 lore raw

Re: [libgpiod][PATCH 02/11] treewide: apply formatting changes with clang-format

Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Use linux kernel's .clang-format file to automatically improve the coding style of libgpiod's C code base. We don't import the file into the repository as it's not perfect and certain converted fragments were rolled back because they looked better before the conversion.

...

lib/line-config.c static void set_kernel_output_values(uint64_t *mask, uint64_t *vals, · line 206

Quoted 5 lines
lib/line-config.c +1 -1
 		if (gpiod_line_settings_get_direction(
-				per_line->node->settings) !=
+			    per_line->node->settings) !=
 		    GPIOD_LINE_DIRECTION_OUTPUT)
 			continue;

Personally I percept this as an ugly indented code...

One reason is too strict 80 or whatever rule (we are almost in the second quarter of the 21st century!), another is that trailing opening parenthesis.

That said, some of the changes in this patch I like, some I disgust. Quite controversial to me, but it's your project and esp. taking into account that it's a user space, the kernel or other project rules are not applicable in a general sense anyway.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [libgpiod][PATCH 02/11] treewide: apply formatting changes with clang-format

Quoted 17 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Use linux kernel's .clang-format file to automatically improve the coding style of libgpiod's C code base. We don't import the file into the repository as it's not perfect and certain converted fragments were rolled back because they looked better before the conversion.

...

lib/line-config.c static void set_kernel_output_values(uint64_t *mask, uint64_t *vals, · line 206

Quoted 5 lines
              if (gpiod_line_settings_get_direction(
lib/line-config.c +1 -1
-                             per_line->node->settings) !=
+                         per_line->node->settings) !=
                  GPIOD_LINE_DIRECTION_OUTPUT)
                      continue;
Quoted 5 lines

Personally I percept this as an ugly indented code...

One reason is too strict 80 or whatever rule (we are almost in the second quarter of the 21st century!), another is that trailing opening parenthesis.

This is very much a question of personal preference and as the maintainer I get to pick and choose the coding style for the project but let me provide a personal argument in favor of the 80 line limit. I mostly work with C and use a single big screen for work. When the limit is set to 80 chars (or 88 which is standard for python), I get to have four columns of code on my screen and still work comfortably. Unless it really adds to the readability, I prefer to keep it.

Bart

Quoted 11 lines

That said, some of the changes in this patch I like, some I disgust. Quite controversial to me, but it's your project and esp. taking into account that it's a user space, the kernel or other project rules are not applicable in a general sense anyway.

--
With Best Regards,
Andy Shevchenko

#6 lore raw

PATCH 3/11 treewide: use plural 'events' in read_edge_event() functions

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

The read_edge_event() family of functions should actually be called read_edge_events() as they universally allow to read more than one event. We're converting wait_edge_event() too for consistency.

---
 bindings/cxx/edge-event-buffer.cpp            |  2 +-
 bindings/cxx/examples/gpiomoncxx.cpp          |  2 +-
 bindings/cxx/gpiodcxx/line-request.hpp        |  6 +-
 bindings/cxx/line-request.cpp                 | 10 ++--
 bindings/cxx/tests/tests-edge-event.cpp       | 56 +++++++++----------
 bindings/python/examples/gpiomon.py           |  2 +-
 bindings/python/gpiod/ext/request.c           |  8 +--
 bindings/python/gpiod/line_request.py         |  6 +-
 bindings/python/tests/tests_edge_event.py     | 38 ++++++-------
 .../rust/libgpiod/examples/gpio_events.rs     |  2 +-
 bindings/rust/libgpiod/examples/gpiomon.rs    |  2 +-
 bindings/rust/libgpiod/src/event_buffer.rs    |  2 +-
 bindings/rust/libgpiod/src/line_request.rs    |  4 +-
 bindings/rust/libgpiod/tests/edge_event.rs    | 24 ++++----
 bindings/rust/libgpiod/tests/line_request.rs  |  2 +-
 include/gpiod.h                               | 10 ++--
 lib/line-request.c                            | 10 ++--
 tests/tests-edge-event.c                      | 46 +++++++--------
 tools/gpiomon.c                               |  2 +-
 19 files changed, 117 insertions(+), 117 deletions(-)
bindings/cxx/edge-event-buffer.cpp +1 -1
index ff398f1..3c551df 100644
@@ -36,7 +36,7 @@ edge_event_buffer::impl::impl(unsigned int capacity)
 
 int edge_event_buffer::impl::read_events(const line_request_ptr& request, unsigned int max_events)
 {
-	int ret = ::gpiod_line_request_read_edge_event(request.get(),
+	int ret = ::gpiod_line_request_read_edge_events(request.get(),
 						       this->buffer.get(), max_events);
 	if (ret < 0)
 		throw_from_errno("error reading edge events from file descriptor");
bindings/cxx/examples/gpiomoncxx.cpp +1 -1
index c351567..4f765ba 100644
@@ -56,7 +56,7 @@ int main(int argc, char **argv)
 	::gpiod::edge_event_buffer buffer;
 
 	for (;;) {
-		request.read_edge_event(buffer);
+		request.read_edge_events(buffer);
 
 		for (const auto& event: buffer)
 			print_event(event);
bindings/cxx/gpiodcxx/line-request.hpp +3 -3
index 659251b..f9f0322 100644
@@ -180,7 +180,7 @@ public:
 	 * @return True if at least one event is ready to be read. False if the
 	 *         wait timed out.
 	 */
-	bool wait_edge_event(const ::std::chrono::nanoseconds& timeout) const;
+	bool wait_edge_events(const ::std::chrono::nanoseconds& timeout) const;
 
 	/**
 	 * @brief Read a number of edge events from this request up to the
@@ -188,7 +188,7 @@ public:
 	 * @param buffer Edge event buffer to read events into.
 	 * @return Number of events read.
 	 */
-	::std::size_t read_edge_event(edge_event_buffer& buffer);
+	::std::size_t read_edge_events(edge_event_buffer& buffer);
 
 	/**
 	 * @brief Read a number of edge events from this request.
@@ -197,7 +197,7 @@ public:
 	 *                   capacity of the buffer.
 	 * @return Number of events read.
 	 */
-	::std::size_t read_edge_event(edge_event_buffer& buffer, ::std::size_t max_events);
+	::std::size_t read_edge_events(edge_event_buffer& buffer, ::std::size_t max_events);
 
 private:
 
bindings/cxx/line-request.cpp +5 -5
index be0bac5..34c5850 100644
@@ -192,11 +192,11 @@ GPIOD_CXX_API int line_request::fd() const
 	return ::gpiod_line_request_get_fd(this->_m_priv->request.get());
 }
 
-GPIOD_CXX_API bool line_request::wait_edge_event(const ::std::chrono::nanoseconds& timeout) const
+GPIOD_CXX_API bool line_request::wait_edge_events(const ::std::chrono::nanoseconds& timeout) const
 {
 	this->_m_priv->throw_if_released();
 
-	int ret = ::gpiod_line_request_wait_edge_event(this->_m_priv->request.get(),
+	int ret = ::gpiod_line_request_wait_edge_events(this->_m_priv->request.get(),
 						       timeout.count());
 	if (ret < 0)
 		throw_from_errno("error waiting for edge events");
@@ -204,13 +204,13 @@ GPIOD_CXX_API bool line_request::wait_edge_event(const ::std::chrono::nanosecond
 	return ret;
 }
 
-GPIOD_CXX_API ::std::size_t line_request::read_edge_event(edge_event_buffer& buffer)
+GPIOD_CXX_API ::std::size_t line_request::read_edge_events(edge_event_buffer& buffer)
 {
-	return this->read_edge_event(buffer, buffer.capacity());
+	return this->read_edge_events(buffer, buffer.capacity());
 }
 
 GPIOD_CXX_API ::std::size_t
-line_request::read_edge_event(edge_event_buffer& buffer, ::std::size_t max_events)
+line_request::read_edge_events(edge_event_buffer& buffer, ::std::size_t max_events)
 {
 	this->_m_priv->throw_if_released();
 
bindings/cxx/tests/tests-edge-event.cpp +28 -28

148 lines not on this page · raw message

bindings/python/examples/gpiomon.py +1 -1
index 58d47a5..702d7c8 100755
@@ -22,5 +22,5 @@ if __name__ == "__main__":
         config={tuple(lines): gpiod.LineSettings(edge_detection=Edge.BOTH)},
     ) as request:
         while True:
-            for event in request.read_edge_event():
+            for event in request.read_edge_events():
                 print(event)
bindings/python/gpiod/ext/request.c +4 -4
index 62378f5..d3e1448 100644
@@ -249,7 +249,7 @@ static PyObject *request_reconfigure_lines(request_object *self, PyObject *args)
 	Py_RETURN_NONE;
 }
 
-static PyObject *request_read_edge_event(request_object *self, PyObject *args)
+static PyObject *request_read_edge_events(request_object *self, PyObject *args)
 {
 	PyObject *max_events_obj, *event_obj, *events, *type;
 	size_t max_events, num_events, i;
@@ -273,7 +273,7 @@ static PyObject *request_read_edge_event(request_object *self, PyObject *args)
 		return NULL;
 
 	Py_BEGIN_ALLOW_THREADS;
-	ret = gpiod_line_request_read_edge_event(self->request,
+	ret = gpiod_line_request_read_edge_events(self->request,
 						 self->buffer, max_events);
 	Py_END_ALLOW_THREADS;
 	if (ret < 0)
@@ -336,8 +336,8 @@ static PyMethodDef request_methods[] = {
 		.ml_flags = METH_VARARGS,
 	},
 	{
-		.ml_name = "read_edge_event",
-		.ml_meth = (PyCFunction)request_read_edge_event,
+		.ml_name = "read_edge_events",
+		.ml_meth = (PyCFunction)request_read_edge_events,
 		.ml_flags = METH_VARARGS,
 	},
 	{ }
bindings/python/gpiod/line_request.py +3 -3
index 1796069..a0f97b7 100644
@@ -169,7 +169,7 @@ class LineRequest:
 
         self._req.reconfigure_lines(line_cfg)
 
-    def wait_edge_event(
+    def wait_edge_events(
         self, timeout: Optional[Union[timedelta, float]] = None
     ) -> bool:
         """
@@ -187,7 +187,7 @@ class LineRequest:
 
         return poll_fd(self.fd, timeout)
 
-    def read_edge_event(self, max_events: Optional[int] = None) -> list[EdgeEvent]:
+    def read_edge_events(self, max_events: Optional[int] = None) -> list[EdgeEvent]:
         """
         Read a number of edge events from a line request.
 
@@ -200,7 +200,7 @@ class LineRequest:
         """
         self._check_released()
 
-        return self._req.read_edge_event(max_events)
+        return self._req.read_edge_events(max_events)
 
     def __str__(self):
         """
bindings/python/tests/tests_edge_event.py +19 -19
index c443772..430b27d 100644
@@ -23,7 +23,7 @@ class EdgeEventWaitTimeout(TestCase):
             sim.dev_path,
             {0: gpiod.LineSettings(edge_detection=Edge.BOTH)},
         ) as req:
-            self.assertEqual(req.wait_edge_event(timedelta(microseconds=10000)), False)
+            self.assertEqual(req.wait_edge_events(timedelta(microseconds=10000)), False)
 
     def test_event_wait_timeout_float(self):
         sim = gpiosim.Chip()
@@ -32,7 +32,7 @@ class EdgeEventWaitTimeout(TestCase):
             sim.dev_path,
             {0: gpiod.LineSettings(edge_detection=Edge.BOTH)},
         ) as req:
-            self.assertEqual(req.wait_edge_event(0.01), False)
+            self.assertEqual(req.wait_edge_events(0.01), False)
 
 
 class EdgeEventInvalidConfig(TestCase):
@@ -82,16 +82,16 @@ class WaitingForEdgeEvents(TestCase):
             )
             self.thread.start()
 
-            self.assertTrue(req.wait_edge_event(timedelta(seconds=1)))
-            events = req.read_edge_event()
+            self.assertTrue(req.wait_edge_events(timedelta(seconds=1)))
+            events = req.read_edge_events()
             self.assertEqual(len(events), 1)
             event = events[0]
             self.assertEqual(event.event_type, EventType.RISING_EDGE)
             self.assertEqual(event.line_offset, 2)
             ts_rising = event.timestamp_ns
 
-            self.assertTrue(req.wait_edge_event(timedelta(seconds=1)))
-            events = req.read_edge_event()
+            self.assertTrue(req.wait_edge_events(timedelta(seconds=1)))
+            events = req.read_edge_events()
             self.assertEqual(len(events), 1)
             event = events[0]
             self.assertEqual(event.event_type, EventType.FALLING_EDGE)
@@ -109,14 +109,14 @@ class WaitingForEdgeEvents(TestCase):
             )
             self.thread.start()
 
-            self.assertTrue(req.wait_edge_event(timedelta(seconds=1)))
-            events = req.read_edge_event()
+            self.assertTrue(req.wait_edge_events(timedelta(seconds=1)))
+            events = req.read_edge_events()
             self.assertEqual(len(events), 1)
             event = events[0]
             self.assertEqual(event.event_type, EventType.RISING_EDGE)
             self.assertEqual(event.line_offset, 6)
 
-            self.assertFalse(req.wait_edge_event(timedelta(microseconds=10000)))
+            self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000)))
 
     def test_rising_edge_event(self):
         with gpiod.request_lines(
@@ -127,14 +127,14 @@ class WaitingForEdgeEvents(TestCase):
             )
             self.thread.start()
 
-            self.assertTrue(req.wait_edge_event(timedelta(seconds=1)))
-            events = req.read_edge_event()
+            self.assertTrue(req.wait_edge_events(timedelta(seconds=1)))
+            events = req.read_edge_events()
             self.assertEqual(len(events), 1)
             event = events[0]
             self.assertEqual(event.event_type, EventType.FALLING_EDGE)
             self.assertEqual(event.line_offset, 6)
 
-            self.assertFalse(req.wait_edge_event(timedelta(microseconds=10000)))
+            self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000)))
 
     def test_sequence_numbers(self):
         with gpiod.request_lines(
@@ -145,8 +145,8 @@ class WaitingForEdgeEvents(TestCase):
             )
             self.thread.start()
 
-            self.assertTrue(req.wait_edge_event(timedelta(seconds=1)))
-            events = req.read_edge_event()
+            self.assertTrue(req.wait_edge_events(timedelta(seconds=1)))
+            events = req.read_edge_events()
             self.assertEqual(len(events), 1)
             event = events[0]
             self.assertEqual(event.event_type, EventType.RISING_EDGE)
@@ -154,8 +154,8 @@ class WaitingForEdgeEvents(TestCase):
             self.assertEqual(event.global_seqno, 1)
             self.assertEqual(event.line_seqno, 1)
 
-            self.assertTrue(req.wait_edge_event(timedelta(seconds=1)))
-            events = req.read_edge_event()
+            self.assertTrue(req.wait_edge_events(timedelta(seconds=1)))
+            events = req.read_edge_events()
             self.assertEqual(len(events), 1)
             event = events[0]
             self.assertEqual(event.event_type, EventType.RISING_EDGE)
@@ -185,8 +185,8 @@ class ReadingMultipleEdgeEvents(TestCase):
         del self.sim
 
     def test_read_multiple_events(self):
-        self.assertTrue(self.request.wait_edge_event(timedelta(seconds=1)))
-        events = self.request.read_edge_event()
+        self.assertTrue(self.request.wait_edge_events(timedelta(seconds=1)))
+        events = self.request.read_edge_events()
         self.assertEqual(len(events), 3)
 
         for event in events:
@@ -205,7 +205,7 @@ class EdgeEventStringRepresentation(TestCase):
             path=sim.dev_path, config={0: gpiod.LineSettings(edge_detection=Edge.BOTH)}
         ) as req:
             sim.set_pull(0, Pull.UP)
-            event = req.read_edge_event()[0]
+            event = req.read_edge_events()[0]
             self.assertRegex(
                 str(event),
                 "<EdgeEvent type=Type\.RISING_EDGE timestamp_ns=[0-9]+ line_offset=0 global_seqno=1 line_seqno=1>",
bindings/rust/libgpiod/examples/gpio_events.rs +1 -1
index 9810050..04267d9 100644
@@ -45,7 +45,7 @@ fn main() -> Result<()> {
     let request = chip.request_lines(&rconfig, &lconfig)?;
 
     loop {
-        match request.wait_edge_event(None) {
+        match request.wait_edge_events(None) {
             Err(x) => {
                 println!("{:?}", x);
                 return Err(Error::InvalidArguments);
bindings/rust/libgpiod/examples/gpiomon.rs +1 -1
index c38652c..f17a81f 100644
@@ -44,7 +44,7 @@ fn main() -> Result<()> {
     let request = chip.request_lines(&rconfig, &lconfig)?;
 
     loop {
-        match request.wait_edge_event(None) {
+        match request.wait_edge_events(None) {
             Err(x) => {
                 println!("{:?}", x);
                 return Err(Error::InvalidArguments);
bindings/rust/libgpiod/src/event_buffer.rs +1 -1
index b56be9a..5a72ddb 100644
@@ -106,7 +106,7 @@ impl Buffer {
 
         // SAFETY: `gpiod_line_request` is guaranteed to be valid here.
         let ret = unsafe {
-            gpiod::gpiod_line_request_read_edge_event(
+            gpiod::gpiod_line_request_read_edge_events(
                 request.request,
                 self.buffer,
                 self.events.len().try_into().unwrap(),
bindings/rust/libgpiod/src/line_request.rs +2 -2
index 3215ab8..c16ec9f 100644
@@ -178,7 +178,7 @@ impl Request {
     }
 
     /// Wait for edge events on any of the lines associated with the request.
-    pub fn wait_edge_event(&self, timeout: Option<Duration>) -> Result<bool> {
+    pub fn wait_edge_events(&self, timeout: Option<Duration>) -> Result<bool> {
         let timeout = match timeout {
             Some(x) => x.as_nanos() as i64,
             // Block indefinitely
@@ -186,7 +186,7 @@ impl Request {
         };
 
         // SAFETY: `gpiod_line_request` is guaranteed to be valid here.
-        let ret = unsafe { gpiod::gpiod_line_request_wait_edge_event(self.request, timeout) };
+        let ret = unsafe { gpiod::gpiod_line_request_wait_edge_events(self.request, timeout) };
 
         match ret {
             -1 => Err(Error::OperationFailed(
bindings/rust/libgpiod/tests/edge_event.rs +12 -12
index 571e574..45c1cfc 100644
@@ -89,7 +89,7 @@ mod edge_event {
             // Rising event
             assert!(config
                 .request()
-                .wait_edge_event(Some(Duration::from_secs(1)))
+                .wait_edge_events(Some(Duration::from_secs(1)))
                 .unwrap());
 
             let mut events = config.request().read_edge_events(&mut buf).unwrap();
@@ -103,7 +103,7 @@ mod edge_event {
             // Falling event
             assert!(config
                 .request()
-                .wait_edge_event(Some(Duration::from_secs(1)))
+                .wait_edge_events(Some(Duration::from_secs(1)))
                 .unwrap());
 
             let mut events = config.request().read_edge_events(&mut buf).unwrap();
@@ -117,7 +117,7 @@ mod edge_event {
             // No events available
             assert!(!config
                 .request()
-                .wait_edge_event(Some(Duration::from_millis(100)))
+                .wait_edge_events(Some(Duration::from_millis(100)))
                 .unwrap());
 
             assert!(ts_falling > ts_rising);
@@ -138,7 +138,7 @@ mod edge_event {
             // Rising event
             assert!(config
                 .request()
-                .wait_edge_event(Some(Duration::from_secs(1)))
+                .wait_edge_events(Some(Duration::from_secs(1)))
                 .unwrap());
 
             let mut events = config.request().read_edge_events(&mut buf).unwrap();
@@ -151,7 +151,7 @@ mod edge_event {
             // No events available
             assert!(!config
                 .request()
-                .wait_edge_event(Some(Duration::from_millis(100)))
+                .wait_edge_events(Some(Duration::from_millis(100)))
                 .unwrap());
         }
 
@@ -170,7 +170,7 @@ mod edge_event {
             // Falling event
             assert!(config
                 .request()
-                .wait_edge_event(Some(Duration::from_secs(1)))
+                .wait_edge_events(Some(Duration::from_secs(1)))
                 .unwrap());
 
             let mut events = config.request().read_edge_events(&mut buf).unwrap();
@@ -183,7 +183,7 @@ mod edge_event {
             // No events available
             assert!(!config
                 .request()
-                .wait_edge_event(Some(Duration::from_millis(100)))
+                .wait_edge_events(Some(Duration::from_millis(100)))
                 .unwrap());
         }
 
@@ -202,7 +202,7 @@ mod edge_event {
             let mut buf = request::Buffer::new(0).unwrap();
             assert!(config
                 .request()
-                .wait_edge_event(Some(Duration::from_secs(1)))
+                .wait_edge_events(Some(Duration::from_secs(1)))
                 .unwrap());
 
             let mut events = config.request().read_edge_events(&mut buf).unwrap();
@@ -217,7 +217,7 @@ mod edge_event {
             // Rising event GPIO 1
             assert!(config
                 .request()
-                .wait_edge_event(Some(Duration::from_secs(1)))
+                .wait_edge_events(Some(Duration::from_secs(1)))
                 .unwrap());
 
             let mut events = config.request().read_edge_events(&mut buf).unwrap();
@@ -232,7 +232,7 @@ mod edge_event {
             // No events available
             assert!(!config
                 .request()
-                .wait_edge_event(Some(Duration::from_millis(100)))
+                .wait_edge_events(Some(Duration::from_millis(100)))
                 .unwrap());
         }
 
@@ -251,7 +251,7 @@ mod edge_event {
             // Read multiple events
             assert!(config
                 .request()
-                .wait_edge_event(Some(Duration::from_secs(1)))
+                .wait_edge_events(Some(Duration::from_secs(1)))
                 .unwrap());
 
             let events = config.request().read_edge_events(&mut buf).unwrap();
@@ -287,7 +287,7 @@ mod edge_event {
             // Read multiple events
             assert!(config
                 .request()
-                .wait_edge_event(Some(Duration::from_secs(1)))
+                .wait_edge_events(Some(Duration::from_secs(1)))
                 .unwrap());
 
             let events = config.request().read_edge_events(&mut buf).unwrap();
bindings/rust/libgpiod/tests/line_request.rs +1 -1
index 286cd6c..c3fc37b 100644
@@ -231,7 +231,7 @@ mod line_request {
             // No events available
             assert!(!config
                 .request()
-                .wait_edge_event(Some(Duration::from_millis(100)))
+                .wait_edge_events(Some(Duration::from_millis(100)))
                 .unwrap());
         }
     }
include/gpiod.h +5 -5
index f4bb5f2..fc9d4c0 100644
@@ -1008,8 +1008,8 @@ int gpiod_line_request_get_fd(struct gpiod_line_request *request);
  * Lines must have edge detection set for edge events to be emitted.
  * By default edge detection is disabled.
  */
-int gpiod_line_request_wait_edge_event(struct gpiod_line_request *request,
-				       int64_t timeout_ns);
+int gpiod_line_request_wait_edge_events(struct gpiod_line_request *request,
+					int64_t timeout_ns);
 
 /**
  * @brief Read a number of edge events from a line request.
@@ -1022,9 +1022,9 @@ int gpiod_line_request_wait_edge_event(struct gpiod_line_request *request,
  * @note Any exising events in the buffer are overwritten.  This is not an
  *       append operation.
  */
-int gpiod_line_request_read_edge_event(struct gpiod_line_request *request,
-				       struct gpiod_edge_event_buffer *buffer,
-				       size_t max_events);
+int gpiod_line_request_read_edge_events(struct gpiod_line_request *request,
+					struct gpiod_edge_event_buffer *buffer,
+					size_t max_events);
 
 /**
  * @}
lib/line-request.c +5 -5
index 5936593..58dc3c9 100644
@@ -223,16 +223,16 @@ GPIOD_API int gpiod_line_request_get_fd(struct gpiod_line_request *request)
 }
 
 GPIOD_API int
-gpiod_line_request_wait_edge_event(struct gpiod_line_request *request,
-				   int64_t timeout_ns)
+gpiod_line_request_wait_edge_events(struct gpiod_line_request *request,
+				    int64_t timeout_ns)
 {
 	return gpiod_poll_fd(request->fd, timeout_ns);
 }
 
 GPIOD_API int
-gpiod_line_request_read_edge_event(struct gpiod_line_request *request,
-				   struct gpiod_edge_event_buffer *buffer,
-				   size_t max_events)
+gpiod_line_request_read_edge_events(struct gpiod_line_request *request,
+				    struct gpiod_edge_event_buffer *buffer,
+				    size_t max_events)
 {
 	return gpiod_edge_event_buffer_read_fd(request->fd, buffer, max_events);
 }
tests/tests-edge-event.c +23 -23

160 lines not on this page · raw message

tools/gpiomon.c +1 -1
index ba457e4..0bc057a 100644
@@ -451,7 +451,7 @@ int main(int argc, char **argv)
 			if (pollfds[i].revents == 0)
 				continue;
 
-			ret = gpiod_line_request_read_edge_event(requests[i],
+			ret = gpiod_line_request_read_edge_events(requests[i],
 					 event_buffer, EVENT_BUF_SIZE);
 			if (ret < 0)
 				die_perror("error reading line events");
Signature · 1 line
2.37.2
Acked-by on v1 3/11
#7 lore raw

Re: [libgpiod][PATCH 03/11] treewide: use plural 'events' in read_edge_event() functions

Quoted 6 lines · Bartosz Golaszewski
 .../rust/libgpiod/examples/gpio_events.rs     |  2 +-
 bindings/rust/libgpiod/examples/gpiomon.rs    |  2 +-
 bindings/rust/libgpiod/src/event_buffer.rs    |  2 +-
 bindings/rust/libgpiod/src/line_request.rs    |  4 +-
 bindings/rust/libgpiod/tests/edge_event.rs    | 24 ++++----
 bindings/rust/libgpiod/tests/line_request.rs  |  2 +-
Signature · 1 line
viresh
#8 lore raw

PATCH 4/11 treewide: rename EVENT_CLOCK to CLOCK

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

While we use it for edge event timestamps exclusively at the moment, the actual enum names shouldn't limit its application and simply just refer to existing clock types known by the GPIO uAPI. The relevant functions are still called set/get_event_clock() as it's in line with their functionality.

---
 bindings/cxx/line-info.cpp                |  6 +++---
 bindings/cxx/line-settings.cpp            | 14 ++++++-------
 bindings/python/gpiod/ext/line-settings.c |  2 +-
 bindings/python/gpiod/ext/module.c        |  6 +++---
 bindings/rust/libgpiod/src/lib.rs         | 22 ++++++++++-----------
 include/gpiod.h                           | 20 +++++++++----------
 lib/line-config.c                         |  4 ++--
 lib/line-info.c                           | 10 +++++-----
 lib/line-settings.c                       | 16 +++++++--------
 tests/tests-line-config.c                 |  2 +-
 tests/tests-line-info.c                   | 12 ++++++------
 tests/tests-line-settings.c               | 24 +++++++++++------------
 tools/gpiomon.c                           | 14 ++++++-------
 tools/tools-common.c                      |  4 ++--
 14 files changed, 78 insertions(+), 78 deletions(-)
bindings/cxx/line-info.cpp +3 -3
index 944e34d..5eb2a3f 100644
@@ -37,9 +37,9 @@ const ::std::map<int, line::edge> edge_mapping = {
 };
 
 const ::std::map<int, line::clock> clock_mapping = {
-	{ GPIOD_LINE_EVENT_CLOCK_MONOTONIC,	line::clock::MONOTONIC },
-	{ GPIOD_LINE_EVENT_CLOCK_REALTIME,	line::clock::REALTIME },
-	{ GPIOD_LINE_EVENT_CLOCK_HTE,		line::clock::HTE }
+	{ GPIOD_LINE_CLOCK_MONOTONIC,		line::clock::MONOTONIC },
+	{ GPIOD_LINE_CLOCK_REALTIME,		line::clock::REALTIME },
+	{ GPIOD_LINE_CLOCK_HTE,			line::clock::HTE }
 };
 
 } /* namespace */
bindings/cxx/line-settings.cpp +7 -7
index 17c5ca2..58860db 100644
@@ -57,13 +57,13 @@ const ::std::map<line::drive, gpiod_line_drive> drive_mapping = {
 
 const ::std::map<gpiod_line_drive, line::drive> reverse_drive_mapping = make_reverse_maping(drive_mapping);
 
-const ::std::map<line::clock, gpiod_line_event_clock> clock_mapping = {
-	{ line::clock::MONOTONIC,	GPIOD_LINE_EVENT_CLOCK_MONOTONIC },
-	{ line::clock::REALTIME,	GPIOD_LINE_EVENT_CLOCK_REALTIME },
-	{ line::clock::HTE,		GPIOD_LINE_EVENT_CLOCK_HTE }
+const ::std::map<line::clock, gpiod_line_clock> clock_mapping = {
+	{ line::clock::MONOTONIC,	GPIOD_LINE_CLOCK_MONOTONIC },
+	{ line::clock::REALTIME,	GPIOD_LINE_CLOCK_REALTIME },
+	{ line::clock::HTE,		GPIOD_LINE_CLOCK_HTE }
 };
 
-const ::std::map<gpiod_line_event_clock, line::clock>
+const ::std::map<gpiod_line_clock, line::clock>
 reverse_clock_mapping = make_reverse_maping(clock_mapping);
 
 const ::std::map<line::value, gpiod_line_value> value_mapping = {
@@ -257,7 +257,7 @@ GPIOD_CXX_API ::std::chrono::microseconds line_settings::debounce_period() const
 
 GPIOD_CXX_API line_settings& line_settings::set_event_clock(line::clock event_clock)
 {
-	set_mapped_value<line::clock, gpiod_line_event_clock,
+	set_mapped_value<line::clock, gpiod_line_clock,
 			 ::gpiod_line_settings_set_event_clock>(this->_m_priv->settings.get(),
 								event_clock, clock_mapping);
 
@@ -266,7 +266,7 @@ GPIOD_CXX_API line_settings& line_settings::set_event_clock(line::clock event_cl
 
 GPIOD_CXX_API line::clock line_settings::event_clock() const
 {
-	return get_mapped_value<line::clock, gpiod_line_event_clock,
+	return get_mapped_value<line::clock, gpiod_line_clock,
 				::gpiod_line_settings_get_event_clock>(
 							this->_m_priv->settings.get(),
 							reverse_clock_mapping);
bindings/python/gpiod/ext/line-settings.c +1 -1
index 8ec1390..2cacbef 100644
@@ -29,7 +29,7 @@ line_settings_init(line_settings_object *self, PyObject *args, PyObject *kwargs)
 		NULL
 	};
 
-	enum gpiod_line_event_clock event_clock;
+	enum gpiod_line_clock event_clock;
 	enum gpiod_line_direction direction;
 	enum gpiod_line_value output_value;
 	unsigned long debounce_period;
bindings/python/gpiod/ext/module.c +3 -3
index 8725ef2..12fb92c 100644
@@ -80,15 +80,15 @@ static const struct module_const module_constants[] = {
 	},
 	{
 		.name = "CLOCK_MONOTONIC",
-		.val = GPIOD_LINE_EVENT_CLOCK_MONOTONIC,
+		.val = GPIOD_LINE_CLOCK_MONOTONIC,
 	},
 	{
 		.name = "CLOCK_REALTIME",
-		.val = GPIOD_LINE_EVENT_CLOCK_REALTIME,
+		.val = GPIOD_LINE_CLOCK_REALTIME,
 	},
 	{
 		.name = "CLOCK_HTE",
-		.val = GPIOD_LINE_EVENT_CLOCK_HTE,
+		.val = GPIOD_LINE_CLOCK_HTE,
 	},
 	{
 		.name = "EDGE_EVENT_TYPE_RISING",
bindings/rust/libgpiod/src/lib.rs +11 -11
index d7a0615..1b2c765 100644
@@ -45,9 +45,9 @@ use gpiod::{
     gpiod_line_edge_GPIOD_LINE_EDGE_FALLING as GPIOD_LINE_EDGE_FALLING,
     gpiod_line_edge_GPIOD_LINE_EDGE_NONE as GPIOD_LINE_EDGE_NONE,
     gpiod_line_edge_GPIOD_LINE_EDGE_RISING as GPIOD_LINE_EDGE_RISING,
-    gpiod_line_event_clock_GPIOD_LINE_EVENT_CLOCK_HTE as GPIOD_LINE_EVENT_CLOCK_HTE,
-    gpiod_line_event_clock_GPIOD_LINE_EVENT_CLOCK_MONOTONIC as GPIOD_LINE_EVENT_CLOCK_MONOTONIC,
-    gpiod_line_event_clock_GPIOD_LINE_EVENT_CLOCK_REALTIME as GPIOD_LINE_EVENT_CLOCK_REALTIME,
+    gpiod_line_clock_GPIOD_LINE_CLOCK_HTE as GPIOD_LINE_CLOCK_HTE,
+    gpiod_line_clock_GPIOD_LINE_CLOCK_MONOTONIC as GPIOD_LINE_CLOCK_MONOTONIC,
+    gpiod_line_clock_GPIOD_LINE_CLOCK_REALTIME as GPIOD_LINE_CLOCK_REALTIME,
     gpiod_line_value_GPIOD_LINE_VALUE_ACTIVE as GPIOD_LINE_VALUE_ACTIVE,
     gpiod_line_value_GPIOD_LINE_VALUE_INACTIVE as GPIOD_LINE_VALUE_INACTIVE,
     gpiod_line_value_GPIOD_LINE_VALUE_ERROR as GPIOD_LINE_VALUE_ERROR,
@@ -393,20 +393,20 @@ pub mod line {
     }
 
     impl EventClock {
-        pub(crate) fn new(clock: gpiod::gpiod_line_event_clock) -> Result<Self> {
+        pub(crate) fn new(clock: gpiod::gpiod_line_clock) -> Result<Self> {
             Ok(match clock {
-                GPIOD_LINE_EVENT_CLOCK_MONOTONIC => EventClock::Monotonic,
-                GPIOD_LINE_EVENT_CLOCK_REALTIME => EventClock::Realtime,
-                GPIOD_LINE_EVENT_CLOCK_HTE => EventClock::HTE,
+                GPIOD_LINE_CLOCK_MONOTONIC => EventClock::Monotonic,
+                GPIOD_LINE_CLOCK_REALTIME => EventClock::Realtime,
+                GPIOD_LINE_CLOCK_HTE => EventClock::HTE,
                 _ => return Err(Error::InvalidEnumValue("Eventclock", clock as i32)),
             })
         }
 
-        pub(crate) fn gpiod_clock(&self) -> gpiod::gpiod_line_event_clock {
+        pub(crate) fn gpiod_clock(&self) -> gpiod::gpiod_line_clock {
             match self {
-                EventClock::Monotonic => GPIOD_LINE_EVENT_CLOCK_MONOTONIC,
-                EventClock::Realtime => GPIOD_LINE_EVENT_CLOCK_REALTIME,
-                EventClock::HTE => GPIOD_LINE_EVENT_CLOCK_HTE,
+                EventClock::Monotonic => GPIOD_LINE_CLOCK_MONOTONIC,
+                EventClock::Realtime => GPIOD_LINE_CLOCK_REALTIME,
+                EventClock::HTE => GPIOD_LINE_CLOCK_HTE,
             }
         }
     }
include/gpiod.h +10 -10
index fc9d4c0..2ad028d 100644
@@ -308,14 +308,14 @@ enum gpiod_line_drive {
 };
 
 /**
- * @brief Event clock settings.
+ * @brief Clock settings.
  */
-enum gpiod_line_event_clock {
-	GPIOD_LINE_EVENT_CLOCK_MONOTONIC = 1,
+enum gpiod_line_clock {
+	GPIOD_LINE_CLOCK_MONOTONIC = 1,
 	/**< Line uses the monotonic clock for edge event timestamps. */
-	GPIOD_LINE_EVENT_CLOCK_REALTIME,
+	GPIOD_LINE_CLOCK_REALTIME,
 	/**< Line uses the realtime clock for edge event timestamps. */
-	GPIOD_LINE_EVENT_CLOCK_HTE,
+	GPIOD_LINE_CLOCK_HTE,
 	/**< Line uses the hardware timestamp engine for event timestamps. */
 };
 
@@ -465,10 +465,10 @@ gpiod_line_info_get_debounce_period_us(struct gpiod_line_info *info);
  * @brief Get the event clock setting used for edge event timestamps for the
  *	  line.
  * @param info GPIO line info object.
- * @return Returns ::GPIOD_LINE_EVENT_CLOCK_MONOTONIC or
- *	   ::GPIOD_LINE_EVENT_CLOCK_REALTIME.
+ * @return Returns ::GPIOD_LINE_CLOCK_MONOTONIC, ::GPIOD_LINE_CLOCK_HTE or
+ *	   ::GPIOD_LINE_CLOCK_REALTIME.
  */
-enum gpiod_line_event_clock
+enum gpiod_line_clock
 gpiod_line_info_get_event_clock(struct gpiod_line_info *info);
 
 /**
@@ -684,14 +684,14 @@ gpiod_line_settings_get_debounce_period_us(
  * @return 0 on success, -1 on failure.
  */
 int gpiod_line_settings_set_event_clock(struct gpiod_line_settings *settings,
-				enum gpiod_line_event_clock event_clock);
+				enum gpiod_line_clock event_clock);
 
 /**
  * @brief Get event clock setting.
  * @param settings Line settings object.
  * @return Current event clock setting.
  */
-enum gpiod_line_event_clock
+enum gpiod_line_clock
 gpiod_line_settings_get_event_clock(struct gpiod_line_settings *settings);
 
 /**
lib/line-config.c +2 -2
index 436f4e8..ce23792 100644
@@ -343,10 +343,10 @@ static uint64_t make_kernel_flags(struct gpiod_line_settings *settings)
 		flags |= GPIO_V2_LINE_FLAG_ACTIVE_LOW;
 
 	switch (gpiod_line_settings_get_event_clock(settings)) {
-	case GPIOD_LINE_EVENT_CLOCK_REALTIME:
+	case GPIOD_LINE_CLOCK_REALTIME:
 		flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME;
 		break;
-	case GPIOD_LINE_EVENT_CLOCK_HTE:
+	case GPIOD_LINE_CLOCK_HTE:
 		flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE;
 		break;
 	default:
lib/line-info.c +5 -5
index 75d886f..6c2c9ce 100644
@@ -17,7 +17,7 @@ struct gpiod_line_info {
 	enum gpiod_line_bias bias;
 	enum gpiod_line_drive drive;
 	enum gpiod_line_edge edge;
-	enum gpiod_line_event_clock event_clock;
+	enum gpiod_line_clock event_clock;
 	bool debounced;
 	unsigned long debounce_period_us;
 };
@@ -93,7 +93,7 @@ gpiod_line_info_get_edge_detection(struct gpiod_line_info *info)
 	return info->edge;
 }
 
-GPIOD_API enum gpiod_line_event_clock
+GPIOD_API enum gpiod_line_clock
 gpiod_line_info_get_event_clock(struct gpiod_line_info *info)
 {
 	return info->event_clock;
@@ -164,11 +164,11 @@ gpiod_line_info_from_uapi(struct gpio_v2_line_info *uapi_info)
 		info->edge = GPIOD_LINE_EDGE_NONE;
 
 	if (uapi_info->flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME)
-		info->event_clock = GPIOD_LINE_EVENT_CLOCK_REALTIME;
+		info->event_clock = GPIOD_LINE_CLOCK_REALTIME;
 	else if (uapi_info->flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE)
-		info->event_clock = GPIOD_LINE_EVENT_CLOCK_HTE;
+		info->event_clock = GPIOD_LINE_CLOCK_HTE;
 	else
-		info->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC;
+		info->event_clock = GPIOD_LINE_CLOCK_MONOTONIC;
 
 	/*
 	 * We assume that the kernel returns correct configuration and that no
lib/line-settings.c +8 -8
index dcd0f6b..808819c 100644
@@ -14,7 +14,7 @@ struct gpiod_line_settings {
 	enum gpiod_line_drive drive;
 	enum gpiod_line_bias bias;
 	bool active_low;
-	enum gpiod_line_event_clock event_clock;
+	enum gpiod_line_clock event_clock;
 	long debounce_period_us;
 	enum gpiod_line_value output_value;
 };
@@ -45,7 +45,7 @@ GPIOD_API void gpiod_line_settings_reset(struct gpiod_line_settings *settings)
 	settings->drive = GPIOD_LINE_DRIVE_PUSH_PULL;
 	settings->active_low = false;
 	settings->debounce_period_us = 0;
-	settings->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC;
+	settings->event_clock = GPIOD_LINE_CLOCK_MONOTONIC;
 	settings->output_value = GPIOD_LINE_VALUE_INACTIVE;
 }
 
@@ -192,16 +192,16 @@ gpiod_line_settings_get_debounce_period_us(struct gpiod_line_settings *settings)
 
 GPIOD_API int
 gpiod_line_settings_set_event_clock(struct gpiod_line_settings *settings,
-				    enum gpiod_line_event_clock event_clock)
+				    enum gpiod_line_clock event_clock)
 {
 	switch (event_clock) {
-	case GPIOD_LINE_EVENT_CLOCK_MONOTONIC:
-	case GPIOD_LINE_EVENT_CLOCK_REALTIME:
-	case GPIOD_LINE_EVENT_CLOCK_HTE:
+	case GPIOD_LINE_CLOCK_MONOTONIC:
+	case GPIOD_LINE_CLOCK_REALTIME:
+	case GPIOD_LINE_CLOCK_HTE:
 		settings->event_clock = event_clock;
 		break;
 	default:
-		settings->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC;
+		settings->event_clock = GPIOD_LINE_CLOCK_MONOTONIC;
 		errno = EINVAL;
 		return -1;
 	}
@@ -209,7 +209,7 @@ gpiod_line_settings_set_event_clock(struct gpiod_line_settings *settings,
 	return 0;
 }
 
-GPIOD_API enum gpiod_line_event_clock
+GPIOD_API enum gpiod_line_clock
 gpiod_line_settings_get_event_clock(struct gpiod_line_settings *settings)
 {
 	return settings->event_clock;
tests/tests-line-config.c +1 -1
index 5dc9022..c615084 100644
@@ -110,7 +110,7 @@ GPIOD_TEST_CASE(too_many_attrs)
 							 settings);
 
 	gpiod_line_settings_set_event_clock(settings,
-					    GPIOD_LINE_EVENT_CLOCK_REALTIME);
+					    GPIOD_LINE_CLOCK_REALTIME);
 	offset = 7;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
tests/tests-line-info.c +6 -6
index 4751db2..1627764 100644
@@ -88,7 +88,7 @@ GPIOD_TEST_CASE(line_info_basic_properties)
 	g_assert_cmpint(gpiod_line_info_get_drive(info4), ==,
 			GPIOD_LINE_DRIVE_PUSH_PULL);
 	g_assert_cmpint(gpiod_line_info_get_event_clock(info4), ==,
-			GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
+			GPIOD_LINE_CLOCK_MONOTONIC);
 	g_assert_false(gpiod_line_info_is_debounced(info4));
 	g_assert_cmpuint(gpiod_line_info_get_debounce_period_us(info4), ==, 0);
 }
@@ -372,13 +372,13 @@ GPIOD_TEST_CASE(event_clock)
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
 	gpiod_line_settings_set_event_clock(settings,
-					    GPIOD_LINE_EVENT_CLOCK_REALTIME);
+					    GPIOD_LINE_CLOCK_REALTIME);
 	offset = 1;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
 
 	gpiod_line_settings_set_event_clock(settings,
-					    GPIOD_LINE_EVENT_CLOCK_HTE);
+					    GPIOD_LINE_CLOCK_HTE);
 	offset = 2;
 	gpiod_test_line_config_add_line_settings_or_fail(line_cfg, &offset, 1,
 							 settings);
@@ -396,9 +396,9 @@ GPIOD_TEST_CASE(event_clock)
 	info2 = gpiod_test_get_line_info_or_fail(chip, 2);
 
 	g_assert_cmpint(gpiod_line_info_get_event_clock(info0), ==,
-			GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
+			GPIOD_LINE_CLOCK_MONOTONIC);
 	g_assert_cmpint(gpiod_line_info_get_event_clock(info1), ==,
-			GPIOD_LINE_EVENT_CLOCK_REALTIME);
+			GPIOD_LINE_CLOCK_REALTIME);
 	g_assert_cmpint(gpiod_line_info_get_event_clock(info2), ==,
-			GPIOD_LINE_EVENT_CLOCK_HTE);
+			GPIOD_LINE_CLOCK_HTE);
 }
tests/tests-line-settings.c +12 -12
index e6c0277..b86fd26 100644
@@ -28,7 +28,7 @@ GPIOD_TEST_CASE(default_config)
 	g_assert_cmpuint(gpiod_line_settings_get_debounce_period_us(settings),
 			 ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(settings), ==,
-			GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
+			GPIOD_LINE_CLOCK_MONOTONIC);
 	g_assert_cmpint(gpiod_line_settings_get_output_value(settings), ==,
 			GPIOD_LINE_VALUE_INACTIVE);
 }
@@ -207,28 +207,28 @@ GPIOD_TEST_CASE(set_event_clock)
 	settings = gpiod_test_create_line_settings_or_fail();
 
 	ret = gpiod_line_settings_set_event_clock(settings,
-					GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
+					GPIOD_LINE_CLOCK_MONOTONIC);
 	g_assert_cmpint(ret, ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(settings), ==,
-			GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
+			GPIOD_LINE_CLOCK_MONOTONIC);
 
 	ret = gpiod_line_settings_set_event_clock(settings,
-					GPIOD_LINE_EVENT_CLOCK_REALTIME);
+					GPIOD_LINE_CLOCK_REALTIME);
 	g_assert_cmpint(ret, ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(settings), ==,
-			GPIOD_LINE_EVENT_CLOCK_REALTIME);
+			GPIOD_LINE_CLOCK_REALTIME);
 
 	ret = gpiod_line_settings_set_event_clock(settings,
-					GPIOD_LINE_EVENT_CLOCK_HTE);
+					GPIOD_LINE_CLOCK_HTE);
 	g_assert_cmpint(ret, ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(settings), ==,
-			GPIOD_LINE_EVENT_CLOCK_HTE);
+			GPIOD_LINE_CLOCK_HTE);
 
 	ret = gpiod_line_settings_set_event_clock(settings, 999);
 	g_assert_cmpint(ret, <, 0);
 	g_assert_cmpint(errno, ==, EINVAL);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(settings), ==,
-			GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
+			GPIOD_LINE_CLOCK_MONOTONIC);
 }
 
 GPIOD_TEST_CASE(set_output_value)
@@ -268,7 +268,7 @@ GPIOD_TEST_CASE(copy_line_settings)
 	gpiod_line_settings_set_edge_detection(settings, GPIOD_LINE_EDGE_BOTH);
 	gpiod_line_settings_set_debounce_period_us(settings, 2000);
 	gpiod_line_settings_set_event_clock(settings,
-					    GPIOD_LINE_EVENT_CLOCK_REALTIME);
+					    GPIOD_LINE_CLOCK_REALTIME);
 
 	copy = gpiod_line_settings_copy(settings);
 	g_assert_nonnull(copy);
@@ -281,7 +281,7 @@ GPIOD_TEST_CASE(copy_line_settings)
 	g_assert_cmpint(gpiod_line_settings_get_debounce_period_us(copy), ==,
 			2000);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(copy), ==,
-			GPIOD_LINE_EVENT_CLOCK_REALTIME);
+			GPIOD_LINE_CLOCK_REALTIME);
 }
 
 GPIOD_TEST_CASE(reset_settings)
@@ -294,7 +294,7 @@ GPIOD_TEST_CASE(reset_settings)
 	gpiod_line_settings_set_edge_detection(settings, GPIOD_LINE_EDGE_BOTH);
 	gpiod_line_settings_set_debounce_period_us(settings, 2000);
 	gpiod_line_settings_set_event_clock(settings,
-					    GPIOD_LINE_EVENT_CLOCK_REALTIME);
+					    GPIOD_LINE_CLOCK_REALTIME);
 
 	gpiod_line_settings_reset(settings);
 
@@ -310,7 +310,7 @@ GPIOD_TEST_CASE(reset_settings)
 	g_assert_cmpuint(gpiod_line_settings_get_debounce_period_us(settings),
 			 ==, 0);
 	g_assert_cmpint(gpiod_line_settings_get_event_clock(settings), ==,
-			GPIOD_LINE_EVENT_CLOCK_MONOTONIC);
+			GPIOD_LINE_CLOCK_MONOTONIC);
 	g_assert_cmpint(gpiod_line_settings_get_output_value(settings), ==,
 			GPIOD_LINE_VALUE_INACTIVE);
 }
tools/gpiomon.c +7 -7
index 0bc057a..93ff463 100644
@@ -28,7 +28,7 @@ struct config {
 	const char *chip_id;
 	const char *consumer;
 	const char *fmt;
-	enum gpiod_line_event_clock event_clock;
+	enum gpiod_line_clock event_clock;
 	int timestamp_fmt;
 };
 
@@ -98,13 +98,13 @@ static int parse_edges_or_die(const char *option)
 static int parse_event_clock_or_die(const char *option)
 {
 	if (strcmp(option, "realtime") == 0)
-		return GPIOD_LINE_EVENT_CLOCK_REALTIME;
+		return GPIOD_LINE_CLOCK_REALTIME;
 	if (strcmp(option, "hte") != 0)
-		return GPIOD_LINE_EVENT_CLOCK_HTE;
+		return GPIOD_LINE_CLOCK_HTE;
 	if (strcmp(option, "monotonic") != 0)
 		die("invalid event clock: %s", option);
 
-	return GPIOD_LINE_EVENT_CLOCK_MONOTONIC;
+	return GPIOD_LINE_CLOCK_MONOTONIC;
 }
 
 static int parse_config(int argc, char **argv, struct config *cfg)
@@ -206,10 +206,10 @@ static int parse_config(int argc, char **argv, struct config *cfg)
 	/* setup default clock/format combinations, where not overridden */
 	if (cfg->event_clock == 0) {
 		if (cfg->timestamp_fmt)
-			cfg->event_clock = GPIOD_LINE_EVENT_CLOCK_REALTIME;
+			cfg->event_clock = GPIOD_LINE_CLOCK_REALTIME;
 		else
-			cfg->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC;
-	} else if ((cfg->event_clock == GPIOD_LINE_EVENT_CLOCK_REALTIME) &&
+			cfg->event_clock = GPIOD_LINE_CLOCK_MONOTONIC;
+	} else if ((cfg->event_clock == GPIOD_LINE_CLOCK_REALTIME) &&
 		   (cfg->timestamp_fmt == 0)) {
 		cfg->timestamp_fmt = 1;
 	}
tools/tools-common.c +2 -2
index 4477ac8..44988d4 100644
@@ -286,10 +286,10 @@ static void print_event_clock(struct gpiod_line_info *info)
 	const char *name;
 
 	switch (gpiod_line_info_get_event_clock(info)) {
-	case GPIOD_LINE_EVENT_CLOCK_REALTIME:
+	case GPIOD_LINE_CLOCK_REALTIME:
 		name = "realtime";
 		break;
-	case GPIOD_LINE_EVENT_CLOCK_HTE:
+	case GPIOD_LINE_CLOCK_HTE:
 		name = "hte";
 		break;
 	default:
Signature · 1 line
2.37.2
Acked-by on v1 4/11
#9 lore raw

Re: [libgpiod][PATCH 04/11] treewide: rename EVENT_CLOCK to CLOCK

Quoted 1 line · Bartosz Golaszewski
 bindings/rust/libgpiod/src/lib.rs         | 22 ++++++++++-----------
Signature · 1 line
viresh
#10 lore raw

PATCH 5/11 gpiosim: rename HOG_DIR to DIRECTION

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

The enum itself should just define direction settings, it's the functions that use it that should refer to hogging.

---
 bindings/cxx/tests/gpiosim.cpp         | 12 ++++++------
 bindings/cxx/tests/gpiosim.hpp         |  4 ++--
 bindings/cxx/tests/tests-line-info.cpp |  2 +-
 bindings/python/tests/gpiosim/ext.c    |  6 +++---
 bindings/rust/gpiosim-sys/src/lib.rs   | 12 ++++++------
 tests/gpiod-test-helpers.h             |  2 +-
 tests/gpiod-test-sim.c                 | 12 ++++++------
 tests/gpiod-test-sim.h                 |  8 ++++----
 tests/gpiosim/gpiosim-selftest.c       |  2 +-
 tests/gpiosim/gpiosim.c                |  6 +++---
 tests/gpiosim/gpiosim.h                |  6 +++---
 tests/tests-line-info.c                |  4 ++--
 12 files changed, 38 insertions(+), 38 deletions(-)
bindings/cxx/tests/gpiosim.cpp +6 -6
index 281f9cc..a36c59e 100644
@@ -17,10 +17,10 @@ const ::std::map<chip::pull, gpiosim_pull> pull_mapping = {
 	{ chip::pull::PULL_DOWN,	GPIOSIM_PULL_DOWN }
 };
 
-const ::std::map<chip_builder::hog_direction, gpiosim_direction> hog_dir_mapping = {
-	{ chip_builder::hog_direction::INPUT,		GPIOSIM_HOG_DIR_INPUT },
-	{ chip_builder::hog_direction::OUTPUT_HIGH,	GPIOSIM_HOG_DIR_OUTPUT_HIGH },
-	{ chip_builder::hog_direction::OUTPUT_LOW,	GPIOSIM_HOG_DIR_OUTPUT_LOW }
+const ::std::map<chip_builder::direction, gpiosim_direction> hog_dir_mapping = {
+	{ chip_builder::direction::INPUT,	GPIOSIM_DIRECTION_INPUT },
+	{ chip_builder::direction::OUTPUT_HIGH,	GPIOSIM_DIRECTION_OUTPUT_HIGH },
+	{ chip_builder::direction::OUTPUT_LOW,	GPIOSIM_DIRECTION_OUTPUT_LOW }
 };
 
 const ::std::map<gpiosim_value, chip::value> value_mapping = {
@@ -168,7 +168,7 @@ struct chip_builder::impl
 	::std::size_t num_lines;
 	::std::string label;
 	::std::map<unsigned int, ::std::string> line_names;
-	::std::map<unsigned int, ::std::pair<::std::string, hog_direction>> hogs;
+	::std::map<unsigned int, ::std::pair<::std::string, direction>> hogs;
 };
 
 chip_builder::chip_builder()
@@ -216,7 +216,7 @@ chip_builder& chip_builder::set_line_name(unsigned int offset, const ::std::stri
 	return *this;
 }
 
-chip_builder& chip_builder::set_hog(unsigned int offset, const ::std::string& name, hog_direction direction)
+chip_builder& chip_builder::set_hog(unsigned int offset, const ::std::string& name, direction direction)
 {
 	this->_m_priv->hogs[offset] = { name, direction };
 
bindings/cxx/tests/gpiosim.hpp +2 -2
index c9300ef..1dab191 100644
@@ -51,7 +51,7 @@ private:
 class chip_builder
 {
 public:
-	enum class hog_direction {
+	enum class direction {
 		INPUT = 1,
 		OUTPUT_HIGH,
 		OUTPUT_LOW
@@ -68,7 +68,7 @@ public:
 	chip_builder& set_num_lines(::std::size_t num_lines);
 	chip_builder& set_label(const ::std::string& label);
 	chip_builder& set_line_name(unsigned int offset, const ::std::string& name);
-	chip_builder& set_hog(unsigned int offset, const ::std::string& name, hog_direction direction);
+	chip_builder& set_hog(unsigned int offset, const ::std::string& name, direction direction);
 
 	chip build();
 
bindings/cxx/tests/tests-line-info.cpp +1 -1
index 1d8c293..21211f2 100644
@@ -9,7 +9,7 @@
 #include "gpiosim.hpp"
 
 using ::gpiosim::make_sim;
-using hog_dir = ::gpiosim::chip_builder::hog_direction;
+using hog_dir = ::gpiosim::chip_builder::direction;
 using direction = ::gpiod::line::direction;
 using edge = ::gpiod::line::edge;
 using bias = ::gpiod::line::bias;
bindings/python/tests/gpiosim/ext.c +3 -3
index 7846321..272e6f7 100644
@@ -28,15 +28,15 @@ static const struct module_const module_constants[] = {
 	},
 	{
 		.name = "DIRECTION_INPUT",
-		.val = GPIOSIM_HOG_DIR_INPUT,
+		.val = GPIOSIM_DIRECTION_INPUT,
 	},
 	{
 		.name = "DIRECTION_OUTPUT_HIGH",
-		.val = GPIOSIM_HOG_DIR_OUTPUT_HIGH,
+		.val = GPIOSIM_DIRECTION_OUTPUT_HIGH,
 	},
 	{
 		.name = "DIRECTION_OUTPUT_LOW",
-		.val = GPIOSIM_HOG_DIR_OUTPUT_LOW,
+		.val = GPIOSIM_DIRECTION_OUTPUT_LOW,
 	},
 	{ }
 };
bindings/rust/gpiosim-sys/src/lib.rs +6 -6
index 420e015..55cc183 100644
@@ -19,9 +19,9 @@ use crate::{
     gpiosim_value_GPIOSIM_VALUE_INACTIVE as GPIOSIM_VALUE_INACTIVE,
     gpiosim_value_GPIOSIM_VALUE_ACTIVE as GPIOSIM_VALUE_ACTIVE,	
     gpiosim_value_GPIOSIM_VALUE_ERROR as GPIOSIM_VALUE_ERROR,
-    gpiosim_direction_GPIOSIM_HOG_DIR_INPUT as GPIOSIM_HOG_DIR_INPUT,
-    gpiosim_direction_GPIOSIM_HOG_DIR_OUTPUT_HIGH as GPIOSIM_HOG_DIR_OUTPUT_HIGH,
-    gpiosim_direction_GPIOSIM_HOG_DIR_OUTPUT_LOW as GPIOSIM_HOG_DIR_OUTPUT_LOW,
+    gpiosim_direction_GPIOSIM_DIRECTION_INPUT as GPIOSIM_DIRECTION_INPUT,
+    gpiosim_direction_GPIOSIM_DIRECTION_OUTPUT_HIGH as GPIOSIM_DIRECTION_OUTPUT_HIGH,
+    gpiosim_direction_GPIOSIM_DIRECTION_OUTPUT_LOW as GPIOSIM_DIRECTION_OUTPUT_LOW,
     gpiosim_pull_GPIOSIM_PULL_UP as GPIOSIM_PULL_UP,
     gpiosim_pull_GPIOSIM_PULL_DOWN as GPIOSIM_PULL_DOWN,
 };
@@ -64,9 +64,9 @@ pub enum Direction {
 impl Direction {
     fn val(self) -> gpiosim_direction {
         match self {
-            Direction::Input => GPIOSIM_HOG_DIR_INPUT,
-            Direction::OutputHigh => GPIOSIM_HOG_DIR_OUTPUT_HIGH,
-            Direction::OutputLow => GPIOSIM_HOG_DIR_OUTPUT_LOW,
+            Direction::Input => GPIOSIM_DIRECTION_INPUT,
+            Direction::OutputHigh => GPIOSIM_DIRECTION_OUTPUT_HIGH,
+            Direction::OutputLow => GPIOSIM_DIRECTION_OUTPUT_LOW,
         }
     }
 }
tests/gpiod-test-helpers.h +1 -1
index c3363bf..60c60b1 100644
@@ -164,7 +164,7 @@ struct gpiod_test_line_name {
 struct gpiod_test_hog {
 	guint offset;
 	const gchar *name;
-	GPIOSimHogDir direction;
+	GPIOSimDirection direction;
 };
 
 GVariant *
tests/gpiod-test-sim.c +6 -6
index fe9f822..9029382 100644
@@ -127,14 +127,14 @@ static void g_gpiosim_chip_set_property(GObject *obj, guint prop_id,
 		while (g_variant_iter_loop(iter, "(usi)",
 					   &offset, &name, &vdir)) {
 			switch (vdir) {
-			case G_GPIOSIM_HOG_DIR_INPUT:
-				dir = GPIOSIM_HOG_DIR_INPUT;
+			case G_GPIOSIM_DIRECTION_INPUT:
+				dir = GPIOSIM_DIRECTION_INPUT;
 				break;
-			case G_GPIOSIM_HOG_DIR_OUTPUT_HIGH:
-				dir = GPIOSIM_HOG_DIR_OUTPUT_HIGH;
+			case G_GPIOSIM_DIRECTION_OUTPUT_HIGH:
+				dir = GPIOSIM_DIRECTION_OUTPUT_HIGH;
 				break;
-			case G_GPIOSIM_HOG_DIR_OUTPUT_LOW:
-				dir = GPIOSIM_HOG_DIR_OUTPUT_LOW;
+			case G_GPIOSIM_DIRECTION_OUTPUT_LOW:
+				dir = GPIOSIM_DIRECTION_OUTPUT_LOW;
 				break;
 			default:
 				g_error("Invalid hog direction value: %d",
tests/gpiod-test-sim.h +4 -4
index 0cc2a0b..3012d49 100644
@@ -15,10 +15,10 @@ typedef enum {
 } GPIOSimPull;
 
 typedef enum {
-	G_GPIOSIM_HOG_DIR_INPUT = 1,
-	G_GPIOSIM_HOG_DIR_OUTPUT_HIGH,
-	G_GPIOSIM_HOG_DIR_OUTPUT_LOW,
-} GPIOSimHogDir;
+	G_GPIOSIM_DIRECTION_INPUT = 1,
+	G_GPIOSIM_DIRECTION_OUTPUT_HIGH,
+	G_GPIOSIM_DIRECTION_OUTPUT_LOW,
+} GPIOSimDirection;
 
 typedef struct _GPIOSimChip GPIOSimChip;
 
tests/gpiosim/gpiosim-selftest.c +1 -1
index b970755..ce6beee 100644
@@ -92,7 +92,7 @@ int main(int argc UNUSED, char **argv UNUSED)
 	printf("Hog a line on bank #2\n");
 
 	ret = gpiosim_bank_hog_line(bank1, 3, "xyz",
-				    GPIOSIM_HOG_DIR_OUTPUT_HIGH);
+				    GPIOSIM_DIRECTION_OUTPUT_HIGH);
 	if (ret) {
 		perror("Unable to hog a line");
 		return EXIT_FAILURE;
tests/gpiosim/gpiosim.c +3 -3
index 9e6c635..881ecc8 100644
@@ -1010,13 +1010,13 @@ GPIOSIM_API int gpiosim_bank_hog_line(struct gpiosim_bank *bank,
 	int ret, fd;
 
 	switch (direction) {
-	case GPIOSIM_HOG_DIR_INPUT:
+	case GPIOSIM_DIRECTION_INPUT:
 		dir = "input";
 		break;
-	case GPIOSIM_HOG_DIR_OUTPUT_HIGH:
+	case GPIOSIM_DIRECTION_OUTPUT_HIGH:
 		dir = "output-high";
 		break;
-	case GPIOSIM_HOG_DIR_OUTPUT_LOW:
+	case GPIOSIM_DIRECTION_OUTPUT_LOW:
 		dir = "output-low";
 		break;
 	default:
tests/gpiosim/gpiosim.h +3 -3
index ab26900..7d75852 100644
@@ -28,9 +28,9 @@ enum gpiosim_pull {
 };
 
 enum gpiosim_direction {
-	GPIOSIM_HOG_DIR_INPUT = 1,
-	GPIOSIM_HOG_DIR_OUTPUT_HIGH,
-	GPIOSIM_HOG_DIR_OUTPUT_LOW,
+	GPIOSIM_DIRECTION_INPUT = 1,
+	GPIOSIM_DIRECTION_OUTPUT_HIGH,
+	GPIOSIM_DIRECTION_OUTPUT_LOW,
 };
 
 struct gpiosim_ctx *gpiosim_ctx_new(void);
tests/tests-line-info.c +2 -2
index 1627764..90c7c2f 100644
@@ -51,12 +51,12 @@ GPIOD_TEST_CASE(line_info_basic_properties)
 		{
 			.offset = 3,
 			.name = "hog3",
-			.direction = G_GPIOSIM_HOG_DIR_OUTPUT_HIGH,
+			.direction = G_GPIOSIM_DIRECTION_OUTPUT_HIGH,
 		},
 		{
 			.offset = 4,
 			.name = "hog4",
-			.direction = G_GPIOSIM_HOG_DIR_OUTPUT_LOW,
+			.direction = G_GPIOSIM_DIRECTION_OUTPUT_LOW,
 		},
 		{ }
 	};
Signature · 1 line
2.37.2
Acked-by on v1 5/11
#11 lore raw

Re: [libgpiod][PATCH 05/11] gpiosim: rename HOG_DIR to DIRECTION

Quoted 1 line · Bartosz Golaszewski
 bindings/rust/gpiosim-sys/src/lib.rs   | 12 ++++++------
Signature · 1 line
viresh
#12 lore raw

PATCH 6/11 tools: display the correct license with --version

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

The tools are licensed under GPL-2.0-or-later so fix the output of --version.

---
 tools/tools-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/tools-common.c +1 -1
index 44988d4..3480ede 100644
@@ -78,7 +78,7 @@ void print_version(void)
 	printf("%s (libgpiod) v%s\n",
 	       program_invocation_short_name, gpiod_version_string());
 	printf("Copyright (C) 2017-2018 Bartosz Golaszewski\n");
-	printf("License: LGPLv2.1\n");
+	printf("License: GPL-2.0-or-later\n");
 	printf("This is free software: you are free to change and redistribute it.\n");
 	printf("There is NO WARRANTY, to the extent permitted by law.\n");
 }
Signature · 1 line
2.37.2
#13 lore raw

PATCH 7/11 bindings: rust: make reuse happy

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add missing license text files and use the CC0-1.0 license for the rust-specific .gitignore file.

---
 LICENSES/Apache-2.0.txt   | 201 ++++++++++++++++++++++++++++++++++++++
 LICENSES/BSD-3-Clause.txt |  28 ++++++
 LICENSES/CC0-1.0.txt      | 121 +++++++++++++++++++++++
 Makefile.am               |   9 +-
 bindings/rust/.gitignore  |   4 +-
 5 files changed, 359 insertions(+), 4 deletions(-)
 create mode 100644 LICENSES/Apache-2.0.txt
 create mode 100644 LICENSES/BSD-3-Clause.txt
 create mode 100644 LICENSES/CC0-1.0.txt
LICENSES/Apache-2.0.txt new file +201 -0
new file mode 100644
index 0000000..261eeb9
@@ -0,0 +1,201 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
LICENSES/BSD-3-Clause.txt new file +28 -0
new file mode 100644
index 0000000..ddd44f6
@@ -0,0 +1,28 @@
+BSD 3-Clause License
+
+Copyright (c) [year], [fullname]
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+   list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LICENSES/CC0-1.0.txt new file +121 -0

121 lines not on this page · raw message

Makefile.am +6 -3
index dfc6c95..59d8762 100644
@@ -6,12 +6,15 @@ AUTOMAKE_OPTIONS = foreign
 SUBDIRS = include lib
 
 EXTRA_DIST = \
-	LICENSES/CC-BY-SA-4.0.txt \
-	LICENSES/GPL-2.0-only.txt \
 	LICENSES/GPL-2.0-or-later.txt \
+	LICENSES/Apache-2.0.txt \
 	LICENSES/LGPL-2.1-or-later.txt \
+	LICENSES/CC-BY-SA-4.0.txt \
+	LICENSES/CC0-1.0.txt \
+	LICENSES/GPL-2.0-only.txt \
+	LICENSES/Linux-syscall-note.txt \
 	LICENSES/LGPL-3.0-or-later.txt \
-	LICENSES/Linux-syscall-note.txt
+	LICENSES/BSD-3-Clause.txt
 
 if WITH_TOOLS
 
bindings/rust/.gitignore +3 -1
index 95054d9..6fe7bde 100644
@@ -1,4 +1,6 @@
-# Added by cargo
+# SPDX-License-Identifier: CC0-1.0
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Viresh Kumar <[email protected]>
 
 target
 Cargo.lock
Signature · 1 line
2.37.2
#14 lore raw

Re: [libgpiod][PATCH 07/11] bindings: rust: make reuse happy

Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add missing license text files and use the CC0-1.0 license for the rust-specific .gitignore file.

...

bindings/rust/.gitignore line 2

Quoted 7 lines
bindings/rust/.gitignore +0 -1
index 95054d9..6fe7bde 100644
@@ -1,4 +1,6 @@
 
-# Added by cargo

Seems like automatically generated, which means that next time something comes here may well screw up the below.

Quoted 3 lines
bindings/rust/.gitignore +3 -0
+# SPDX-License-Identifier: CC0-1.0
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Viresh Kumar <[email protected]>
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#15 lore raw

Re: [libgpiod][PATCH 07/11] bindings: rust: make reuse happy

Quoted 15 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add missing license text files and use the CC0-1.0 license for the rust-specific .gitignore file.

...

Quoted 5 lines
bindings/rust/.gitignore +0 -0
index 95054d9..6fe7bde 100644
@@ -1,4 +1,6 @@
Quoted 5 lines

bindings/rust/.gitignore line 1

Quoted 1 line
bindings/rust/.gitignore +0 -1
-# Added by cargo

Seems like automatically generated, which means that next time something comes here may well screw up the below.

I think the comment refers to the *ignored* files *added* by cargo, not saying that .gitignore was added by cargo.

Viresh, please confirm.

Bart

#16 lore raw

Re: [libgpiod][PATCH 07/11] bindings: rust: make reuse happy

Quoted 17 lines · Bartosz Golaszewski
Quoted 15 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add missing license text files and use the CC0-1.0 license for the rust-specific .gitignore file.

...

Quoted 5 lines
bindings/rust/.gitignore +0 -0
index 95054d9..6fe7bde 100644
@@ -1,4 +1,6 @@
Quoted 8 lines
Quoted 5 lines

bindings/rust/.gitignore line 1

Quoted 1 line
bindings/rust/.gitignore +0 -1
-# Added by cargo

Seems like automatically generated, which means that next time something comes here may well screw up the below.

I think the comment refers to the *ignored* files *added* by cargo, not saying that .gitignore was added by cargo.

Yes. Cargo, by itself, updated the root folder's .gitignore I think and I had to copy/paste stuff here.

Signature · 1 line
viresh
#17 lore raw

Re: [libgpiod][PATCH 07/11] bindings: rust: make reuse happy

Quoted 25 lines · Viresh Kumar
Quoted 23 lines · Bartosz Golaszewski
Quoted 20 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add missing license text files and use the CC0-1.0 license for the rust-specific .gitignore file.

...

bindings/rust/.gitignore line 2

Quoted 7 lines
bindings/rust/.gitignore +0 -1
index 95054d9..6fe7bde 100644
@@ -1,4 +1,6 @@
 
-# Added by cargo

Seems like automatically generated, which means that next time something comes here may well screw up the below.

Quoted 6 lines
Quoted 2 lines

I think the comment refers to the *ignored* files *added* by cargo, not saying that .gitignore was added by cargo.

Yes. Cargo, by itself, updated the root folder's .gitignore I think and I had to copy/paste stuff here.

OMG cargo cares about the VCS of the project it builds? Good to know I guess.

Bart

#18 lore raw

Re: [libgpiod][PATCH 07/11] bindings: rust: make reuse happy

Quoted 1 line · Bartosz Golaszewski

OMG cargo cares about the VCS of the project it builds? Good to know I guess.

By default it is git. You can specify --vcs option to Cargo init [1].

--vcs vcs

Initialize a new VCS repository for the given version control system (git, hg, pijul, or fossil) or do not initialize any version control at all (none). If not specified, defaults to git or the configuration value cargo-new.vcs, or none if already inside a VCS repository.

Signature · 3 lines
viresh

[1] https://doc.rust-lang.org/cargo/commands/cargo-new.html
Acked-by on v1 7/11
#19 lore raw

Re: [libgpiod][PATCH 07/11] bindings: rust: make reuse happy

In reply to Bartosz Golaszewski
Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add missing license text files and use the CC0-1.0 license for the rust-specific .gitignore file.

Quoted 10 lines
---
 LICENSES/Apache-2.0.txt   | 201 ++++++++++++++++++++++++++++++++++++++
 LICENSES/BSD-3-Clause.txt |  28 ++++++
 LICENSES/CC0-1.0.txt      | 121 +++++++++++++++++++++++
 Makefile.am               |   9 +-
 bindings/rust/.gitignore  |   4 +-
 5 files changed, 359 insertions(+), 4 deletions(-)
 create mode 100644 LICENSES/Apache-2.0.txt
 create mode 100644 LICENSES/BSD-3-Clause.txt
 create mode 100644 LICENSES/CC0-1.0.txt
Signature · 1 line
viresh
#20 lore raw

PATCH 8/11 bindings: rust: include rust sources in the release tarballs

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Rust sources and Cargo files are not added to EXTRA_DIST. Add them so that they end up in the release tarballs generated by autotools.

---
 bindings/rust/Makefile.am                       |  4 ++++
 bindings/rust/gpiosim-sys/Makefile.am           |  6 ++++++
 bindings/rust/gpiosim-sys/src/Makefile.am       |  5 +++++
 bindings/rust/libgpiod-sys/Makefile.am          |  6 ++++++
 bindings/rust/libgpiod-sys/src/Makefile.am      |  5 +++++
 bindings/rust/libgpiod/Makefile.am              |  6 ++++++
 bindings/rust/libgpiod/examples/Makefile.am     | 14 ++++++++++++++
 bindings/rust/libgpiod/src/Makefile.am          | 15 +++++++++++++++
 bindings/rust/libgpiod/tests/Makefile.am        | 15 +++++++++++++++
 bindings/rust/libgpiod/tests/common/Makefile.am |  5 +++++
 configure.ac                                    |  9 +++++++++
 11 files changed, 90 insertions(+)
 create mode 100644 bindings/rust/gpiosim-sys/Makefile.am
 create mode 100644 bindings/rust/gpiosim-sys/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod-sys/Makefile.am
 create mode 100644 bindings/rust/libgpiod-sys/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod/Makefile.am
 create mode 100644 bindings/rust/libgpiod/examples/Makefile.am
 create mode 100644 bindings/rust/libgpiod/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod/tests/Makefile.am
 create mode 100644 bindings/rust/libgpiod/tests/common/Makefile.am
bindings/rust/Makefile.am +4 -0
index a0d0772..1e01024 100644
@@ -17,3 +17,7 @@ all:
 
 clean:
 	cargo clean
+
+EXTRA_DIST = Cargo.toml
+
+SUBDIRS = gpiosim-sys libgpiod libgpiod-sys
bindings/rust/gpiosim-sys/Makefile.am new file +6 -0
new file mode 100644
index 0000000..9471b0e
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = build.rs Cargo.toml README.md
+SUBDIRS = src
bindings/rust/gpiosim-sys/src/Makefile.am new file +5 -0
new file mode 100644
index 0000000..af104d0
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = lib.rs sim.rs
bindings/rust/libgpiod-sys/Makefile.am new file +6 -0
new file mode 100644
index 0000000..9471b0e
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = build.rs Cargo.toml README.md
+SUBDIRS = src
bindings/rust/libgpiod-sys/src/Makefile.am new file +5 -0
new file mode 100644
index 0000000..36361e7
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = lib.rs
bindings/rust/libgpiod/Makefile.am new file +6 -0
new file mode 100644
index 0000000..6b55d0d
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = Cargo.toml
+SUBDIRS = examples src tests
bindings/rust/libgpiod/examples/Makefile.am new file +14 -0
new file mode 100644
index 0000000..6028fff
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = \
+	gpiodetect.rs \
+	gpio_events.rs \
+	gpiofind.rs \
+	gpioget.rs \
+	gpioinfo.rs \
+	gpiomon.rs \
+	gpioset.rs \
+	gpio_threaded_info_events.rs \
+	gpiowatch.rs
bindings/rust/libgpiod/src/Makefile.am new file +15 -0
new file mode 100644
index 0000000..df63c72
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = \
+	chip.rs \
+	edge_event.rs \
+	event_buffer.rs \
+	info_event.rs \
+	lib.rs \
+	line_config.rs \
+	line_info.rs \
+	line_request.rs \
+	line_settings.rs \
+	request_config.rs
bindings/rust/libgpiod/tests/Makefile.am new file +15 -0
new file mode 100644
index 0000000..198f4e4
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = \
+	chip.rs \
+	edge_event.rs \
+	info_event.rs \
+	line_config.rs \
+	line_info.rs \
+	line_request.rs \
+	line_settings.rs \
+	request_config.rs
+
+SUBDIRS = common
bindings/rust/libgpiod/tests/common/Makefile.am new file +5 -0
new file mode 100644
index 0000000..4cfc355
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+EXTRA_DIST = config.rs mod.rs
configure.ac +9 -0
index ccbb88a..dc945ef 100644
@@ -266,7 +266,16 @@ AC_CONFIG_FILES([Makefile
 		 bindings/python/examples/Makefile
 		 bindings/python/tests/Makefile
 		 bindings/python/tests/gpiosim/Makefile
+		 bindings/rust/libgpiod-sys/src/Makefile
+		 bindings/rust/libgpiod-sys/Makefile
+		 bindings/rust/libgpiod/src/Makefile
+		 bindings/rust/libgpiod/tests/common/Makefile
+		 bindings/rust/libgpiod/tests/Makefile
+		 bindings/rust/libgpiod/Makefile
+		 bindings/rust/libgpiod/examples/Makefile
 		 bindings/rust/Makefile
+		 bindings/rust/gpiosim-sys/src/Makefile
+		 bindings/rust/gpiosim-sys/Makefile
 		 man/Makefile])
 
 AC_OUTPUT
Signature · 1 line
2.37.2
Acked-by on v1 8/11
#21 lore raw

Re: [libgpiod][PATCH 08/11] bindings: rust: include rust sources in the release tarballs

Quoted 20 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Rust sources and Cargo files are not added to EXTRA_DIST. Add them so that they end up in the release tarballs generated by autotools.

---
 bindings/rust/Makefile.am                       |  4 ++++
 bindings/rust/gpiosim-sys/Makefile.am           |  6 ++++++
 bindings/rust/gpiosim-sys/src/Makefile.am       |  5 +++++
 bindings/rust/libgpiod-sys/Makefile.am          |  6 ++++++
 bindings/rust/libgpiod-sys/src/Makefile.am      |  5 +++++
 bindings/rust/libgpiod/Makefile.am              |  6 ++++++
 bindings/rust/libgpiod/examples/Makefile.am     | 14 ++++++++++++++
 bindings/rust/libgpiod/src/Makefile.am          | 15 +++++++++++++++
 bindings/rust/libgpiod/tests/Makefile.am        | 15 +++++++++++++++
 bindings/rust/libgpiod/tests/common/Makefile.am |  5 +++++
 configure.ac                                    |  9 +++++++++
 11 files changed, 90 insertions(+)
 create mode 100644 bindings/rust/gpiosim-sys/Makefile.am
Quoted 8 lines
 create mode 100644 bindings/rust/gpiosim-sys/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod-sys/Makefile.am
 create mode 100644 bindings/rust/libgpiod-sys/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod/Makefile.am
 create mode 100644 bindings/rust/libgpiod/examples/Makefile.am
 create mode 100644 bindings/rust/libgpiod/src/Makefile.am
 create mode 100644 bindings/rust/libgpiod/tests/Makefile.am
 create mode 100644 bindings/rust/libgpiod/tests/common/Makefile.am
Signature · 1 line
viresh
#22 lore raw

PATCH 9/11 bindings: python: decouple the version of the bindings from libgpiod API version

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Python bindings now have their own setup.py script and can be built separately from the rest of the code-base. Let's decouple the python package version from libgpiod API (but let's keep a module attribute containing the API version) by introducing a version.py submodule that can be executed by the setup.py script. This way we have a single canonical place defining the version number.

---
 bindings/python/gpiod/__init__.py     |  3 ++-
 bindings/python/gpiod/ext/module.c    |  2 +-
 bindings/python/gpiod/version.py      |  5 +++++
 bindings/python/setup.py              | 10 +++-------
 bindings/python/tests/tests_module.py | 15 ++++++++-------
 5 files changed, 19 insertions(+), 16 deletions(-)
 create mode 100644 bindings/python/gpiod/version.py
bindings/python/gpiod/__init__.py +2 -1
index 7854cfd..9cbb8df 100644
@@ -16,8 +16,9 @@ from .exception import ChipClosedError, RequestReleasedError
 from .info_event import InfoEvent
 from .line_request import LineRequest
 from .line_settings import LineSettings
+from .version import __version__
 
-__version__ = _ext.__version__
+api_version = _ext.api_version
 
 
 def is_gpiochip_device(path: str) -> bool:
bindings/python/gpiod/ext/module.c +1 -1
index 12fb92c..8b5a032 100644
@@ -165,7 +165,7 @@ PyMODINIT_FUNC PyInit__ext(void)
 	if (!module)
 		return NULL;
 
-	ret = PyModule_AddStringConstant(module, "__version__",
+	ret = PyModule_AddStringConstant(module, "api_version",
 					 gpiod_version_string());
 	if (ret) {
 		Py_DECREF(module);
bindings/python/gpiod/version.py new file +5 -0
new file mode 100644
index 0000000..c650969
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <[email protected]>
+
+__version__ = "2.0.0"
bindings/python/setup.py +3 -7
index ec8f99d..2a8481c 100644
@@ -32,16 +32,12 @@ with_tests = bool(environ["GPIOD_WITH_TESTS"])
 if with_tests:
     extensions.append(gpiosim_ext)
 
-# FIXME Find a better way to get the version
-version = None
-try:
-    version = environ["GPIOD_VERSION_STR"]
-except KeyError:
-    pass
+with open("gpiod/version.py", "r") as fd:
+    exec(fd.read())
 
 setup(
     name="gpiod",
     packages=find_packages(include=["gpiod"]),
     ext_modules=extensions,
-    version=version,
+    version=__version__,
 )
bindings/python/tests/tests_module.py +8 -7
index 4eeae76..de56356 100644
@@ -3,7 +3,6 @@
 
 import gpiod
 import os
-import re
 import unittest
 
 from . import gpiosim
@@ -51,9 +50,11 @@ class IsGPIOChip(TestCase):
 
 
 class VersionString(TestCase):
-    def test_version_string(self):
-        self.assertTrue(
-            re.match(
-                "^[0-9][1-9]?\\.[0-9][1-9]?([\\.0-9]?|\\-devel)$", gpiod.__version__
-            )
-        )
+
+    VERSION_PATTERN = "^[0-9][1-9]?\\.[0-9][1-9]?(\\.[0-9]?|\\-devel)$"
+
+    def test_api_version_string(self):
+        self.assertRegex(gpiod.api_version, VersionString.VERSION_PATTERN)
+
+    def test_module_version(self):
+        self.assertRegex(gpiod.__version__, VersionString.VERSION_PATTERN)
Signature · 1 line
2.37.2
#23 lore raw

PATCH 10/11 bindings: python: fix the GPIOD_WITH_TESTS build flag

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Currently in order to disable test the variable needs to be explicitly set to GPIOD_WITH_TESTS= in the environment or setup.py will crash.

Assume tests should not be built if the variable is not set at all.

---
 bindings/python/setup.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
bindings/python/setup.py +1 -2
index 2a8481c..c90d7d7 100644
@@ -28,8 +28,7 @@ gpiosim_ext = Extension(
 )
 
 extensions = [gpiod_ext]
-with_tests = bool(environ["GPIOD_WITH_TESTS"])
-if with_tests:
+if "GPIOD_WITH_TESTS" in environ and environ["GPIOD_WITH_TESTS"] == "1":
     extensions.append(gpiosim_ext)
 
 with open("gpiod/version.py", "r") as fd:
Signature · 1 line
2.37.2
#24 lore raw

PATCH 11/11 bindings: python: extend setup.py

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add additional information to setup.py. This will be visible in the EGG file.

---
 bindings/python/setup.py | 5 +++++
 1 file changed, 5 insertions(+)
bindings/python/setup.py +5 -0
index c90d7d7..7ad5de3 100644
@@ -39,4 +39,9 @@ setup(
     packages=find_packages(include=["gpiod"]),
     ext_modules=extensions,
     version=__version__,
+    author="Bartosz Golaszewski",
+    author_email="[email protected]",
+    description="Python bindings for libgpiod",
+    platforms=["linux"],
+    license="LGPLv2.1",
 )
Signature · 1 line
2.37.2
#25 lore raw

Re: [libgpiod][PATCH 11/11] bindings: python: extend setup.py

Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add additional information to setup.py. This will be visible in the EGG file.

...

bindings/python/setup.py setup( · line 46

Quoted 9 lines
     packages=find_packages(include=["gpiod"]),
     ext_modules=extensions,
     version=__version__,
bindings/python/setup.py +5 -0
+    author="Bartosz Golaszewski",
+    author_email="[email protected]",
+    description="Python bindings for libgpiod",
+    platforms=["linux"],
 
+    license="LGPLv2.1",

Is it applicable to the bindings only? I am not familiar with the code base, but one of the patches in this series makes me wonder if you are not going to make same mistake by licensing tools, if any written in pure Python, with a wrong license.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#26 lore raw

Re: [libgpiod][PATCH 11/11] bindings: python: extend setup.py

Quoted 17 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add additional information to setup.py. This will be visible in the EGG file.

...

Quoted 7 lines
     packages=find_packages(include=["gpiod"]),
     ext_modules=extensions,
     version=__version__,
bindings/python/setup.py +4 -0
+    author="Bartosz Golaszewski",
+    author_email="[email protected]",
+    description="Python bindings for libgpiod",
+    platforms=["linux"],
Quoted 7 lines
Quoted 1 line

+ license="LGPLv2.1",

Is it applicable to the bindings only? I am not familiar with the code base, but one of the patches in this series makes me wonder if you are not going to make same mistake by licensing tools, if any written in pure Python, with a wrong license.

Every file has its own SPDX identifier that takes precedence anyway. The module is licensed under LGPLv2.1. The tests and examples are under GPLv2. The setup.py applies to the importable library so LGPLv2.1 sounds good to me.

Bart

#27 lore raw
In reply to Bartosz Golaszewski
Quoted 7 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

This series contains various changes for libgpiod v2. There's no main theme to it really, just fixing problems I noticed and introducing some more changes to the API.

It's been a week, there are no objections so I applied the series.

Bart