From 23cb8e76703d3bc90ad3a7098ea2e63d4a2d899b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Treffenst=C3=A4dt?= Date: Sat, 16 Apr 2022 11:14:53 +0200 Subject: [PATCH 1/6] Added pca95xx,54 and 36 classes. --- cmake/targets/detector.cmake | 5 + include/muonpi/serial/i2cdevices/pca9536.h | 116 ++++++++++++++++ include/muonpi/serial/i2cdevices/pca9554.h | 148 +++++++++++++++++++++ include/muonpi/serial/i2cdevices/pca95xx.h | 87 ++++++++++++ src/serial/i2cdevices/pca9536.cpp | 18 +++ src/serial/i2cdevices/pca9554.cpp | 18 +++ src/serial/i2cdevices/pca95xx.cpp | 1 + 7 files changed, 393 insertions(+) create mode 100644 include/muonpi/serial/i2cdevices/pca9536.h create mode 100644 include/muonpi/serial/i2cdevices/pca9554.h create mode 100644 include/muonpi/serial/i2cdevices/pca95xx.h create mode 100644 src/serial/i2cdevices/pca9536.cpp create mode 100644 src/serial/i2cdevices/pca9554.cpp create mode 100644 src/serial/i2cdevices/pca95xx.cpp diff --git a/cmake/targets/detector.cmake b/cmake/targets/detector.cmake index fec9942..144c29c 100644 --- a/cmake/targets/detector.cmake +++ b/cmake/targets/detector.cmake @@ -5,6 +5,8 @@ set(DETECTOR_SOURCE_FILES "${PROJECT_SRC_DIR}/serial/i2cdevice.cpp" "${PROJECT_SRC_DIR}/serial/i2cbus.cpp" "${PROJECT_SRC_DIR}/serial/i2cdevices/generalcall.cpp" + "${PROJECT_SRC_DIR}/serial/i2cdevices/pca9554.cpp" + "${PROJECT_SRC_DIR}/serial/i2cdevices/pca9536.cpp" ) set(DETECTOR_HEADER_FILES @@ -16,6 +18,9 @@ set(DETECTOR_HEADER_FILES "${PROJECT_HEADER_DIR}/muonpi/serial/i2cbus.h" "${PROJECT_HEADER_DIR}/muonpi/serial/i2ceeprom.h" "${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/generalcall.h" + "${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/pca95xx.h" + "${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/pca9554.h" + "${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/pca9536.h" ) if (NOT LIBMUONPI_FORMAT_ONLY) if (LIBMUONPI_BUILD_DETECTOR) # libraries specific to the Detector library diff --git a/include/muonpi/serial/i2cdevices/pca9536.h b/include/muonpi/serial/i2cdevices/pca9536.h new file mode 100644 index 0000000..2e45095 --- /dev/null +++ b/include/muonpi/serial/i2cdevices/pca9536.h @@ -0,0 +1,116 @@ +#ifndef MUONPI_SERIAL_I2CDEVICES_PCA9536_H +#define MUONPI_SERIAL_I2CDEVICES_PCA9536_H + +#include "muonpi/serial/i2cbus.h" +#include "muonpi/serial/i2cdevices/pca95xx.h" + +#include + +namespace muonpi::serial::devices { + +/** + * @brief I2C io extender device class. + * This class provides access to i2c 4-bit and 8-bit bidirectional digital i/o + * extenders. + * @note valid template specializations are available for values of the template + * parameter BITS of 4 and 8. + */ +class pca9536 : public pca95xx<4> { +public: + pca9536(traffic_t& bus_traffic, const std::string& path, i2c_device::address_type address); + pca9536(traffic_t& bus_traffic, const std::string& path); + + [[nodiscard]] auto identify() -> bool override; + + constexpr static std::array addresses {0b10000011}; + + template + using register_t = simple_register; + + struct input_r : public register_t<0x00> { + const value_type I4_7 : 4 {}; + value_type I3 : 1 {}; + value_type I2 : 1 {}; + value_type I1 : 1 {}; + value_type I0 : 1 {}; + + [[nodiscard]] constexpr auto get() const noexcept -> value_type override { + return static_cast((I3 << 3U) | (I2 << 2U) | (I1 << 1U) | I0); + } + + constexpr explicit input_r(value_type v) noexcept + : I3 {static_cast((v & 0x08U) >> 3U)} + , I2 {static_cast((v & 0x04U) >> 2U)} + , I1 {static_cast((v & 0x02U) >> 1U)} + , I0 {static_cast(v & 0x01U)} {} + + constexpr explicit input_r() noexcept = default; + }; + + struct output_r : public register_t<0x01> { + const value_type O4_7 : 4 {0xF}; + value_type O3 : 1 {1}; + value_type O2 : 1 {1}; + value_type O1 : 1 {1}; + value_type O0 : 1 {1}; + + [[nodiscard]] constexpr auto get() const noexcept -> value_type override { + return static_cast((O3 << 3U) | (O2 << 2U) | (O1 << 1U) | O0); + } + + constexpr explicit output_r(value_type v) noexcept + : O3 {static_cast((v & 0x08U) >> 3U)} + , O2 {static_cast((v & 0x04U) >> 2U)} + , O1 {static_cast((v & 0x02U) >> 1U)} + , O0 {static_cast(v & 0x01U)} {} + + constexpr explicit output_r() noexcept = default; + }; + + struct polarity_r : public register_t<0x02> { + constexpr static value_type invert {1}; + constexpr static value_type retain {0}; + + const value_type N4_7 : 4 {0x0}; + value_type N3 : 1 {retain}; + value_type N2 : 1 {retain}; + value_type N1 : 1 {retain}; + value_type N0 : 1 {retain}; + + [[nodiscard]] constexpr auto get() const noexcept -> value_type override { + return static_cast((N3 << 3U) | (N2 << 2U) | (N1 << 1U) | N0); + } + + constexpr explicit polarity_r(value_type v) noexcept + : N3 {static_cast((v & 0x08U) >> 3U)} + , N2 {static_cast((v & 0x04U) >> 2U)} + , N1 {static_cast((v & 0x02U) >> 1U)} + , N0 {static_cast(v & 0x01U)} {} + constexpr explicit polarity_r() noexcept = default; + }; + + struct configuration_r : public register_t<0x03> { + constexpr static value_type input {1}; + constexpr static value_type output {0}; + + const value_type C4_7 : 4 {0xF}; + value_type C3 : 1 {input}; + value_type C2 : 1 {input}; + value_type C1 : 1 {input}; + value_type C0 : 1 {input}; + + [[nodiscard]] constexpr auto get() const noexcept -> value_type override { + return static_cast((C3 << 3U) | (C2 << 2U) | (C1 << 1U) | C0); + } + + constexpr explicit configuration_r(value_type v) noexcept + : C3 {static_cast((v & 0x08U) >> 3U)} + , C2 {static_cast((v & 0x04U) >> 2U)} + , C1 {static_cast((v & 0x02U) >> 1U)} + , C0 {static_cast(v & 0x01U)} {} + constexpr explicit configuration_r() noexcept = default; + }; +}; + +} // namespace muonpi::serial::devices +#endif // MUONPI_SERIAL_I2CDEVICES_PCA9536_H diff --git a/include/muonpi/serial/i2cdevices/pca9554.h b/include/muonpi/serial/i2cdevices/pca9554.h new file mode 100644 index 0000000..7b3f42f --- /dev/null +++ b/include/muonpi/serial/i2cdevices/pca9554.h @@ -0,0 +1,148 @@ +#ifndef MUONPI_SERIAL_I2CDEVICES_PCA9554_H +#define MUONPI_SERIAL_I2CDEVICES_PCA9554_H + +#include "muonpi/multiaddressrange.h" +#include "muonpi/serial/i2cbus.h" +#include "muonpi/serial/i2cdevices/pca95xx.h" + +#include + +namespace muonpi::serial::devices { + +/** + * @brief I2C io extender device class. + * This class provides access to i2c 4-bit and 8-bit bidirectional digital i/o + * extenders. + * @note valid template specializations are available for values of the template + * parameter BITS of 4 and 8. + */ +class pca9554 : public pca95xx<8> { +public: + pca9554(traffic_t& bus_traffic, const std::string& path, i2c_device::address_type address); + pca9554(traffic_t& bus_traffic, const std::string& path); + + [[nodiscard]] auto identify() -> bool override; + + constexpr static multi_address_range addresses { + {address_range {0b01000000, {0b00000111}}, address_range {0b01110000, {0b00000111}}}}; + + template + using register_t = simple_register; + + struct input_r : public register_t<0x00> { + value_type I7 : 1 {}; + value_type I6 : 1 {}; + value_type I5 : 1 {}; + value_type I4 : 1 {}; + value_type I3 : 1 {}; + value_type I2 : 1 {}; + value_type I1 : 1 {}; + value_type I0 : 1 {}; + + [[nodiscard]] constexpr auto get() const noexcept -> value_type override { + return static_cast((I7 << 7U) | (I6 << 6U) | (I5 << 5U) | (I4 << 4U) + | (I3 << 3U) | (I2 << 2U) | (I1 << 1U) | I0); + } + + constexpr explicit input_r(value_type v) noexcept + : I7 {static_cast((v & 0x80U) >> 7U)} + , I6 {static_cast((v & 0x40U) >> 6U)} + , I5 {static_cast((v & 0x20U) >> 5U)} + , I4 {static_cast((v & 0x10U) >> 4U)} + , I3 {static_cast((v & 0x08U) >> 3U)} + , I2 {static_cast((v & 0x04U) >> 2U)} + , I1 {static_cast((v & 0x02U) >> 1U)} + , I0 {static_cast(v & 0x01U)} {} + constexpr explicit input_r() noexcept = default; + }; + + struct output_r : public register_t<0x01> { + value_type O7 : 1 {1}; + value_type O6 : 1 {1}; + value_type O5 : 1 {1}; + value_type O4 : 1 {1}; + value_type O3 : 1 {1}; + value_type O2 : 1 {1}; + value_type O1 : 1 {1}; + value_type O0 : 1 {1}; + + [[nodiscard]] constexpr auto get() const noexcept -> value_type override { + return static_cast((O7 << 7U) | (O6 << 6U) | (O5 << 5U) | (O4 << 4U) + | (O3 << 3U) | (O2 << 2U) | (O1 << 1U) | O0); + } + + constexpr explicit output_r(value_type v) noexcept + : O7 {static_cast((v & 0x80U) >> 7U)} + , O6 {static_cast((v & 0x40U) >> 6U)} + , O5 {static_cast((v & 0x20U) >> 5U)} + , O4 {static_cast((v & 0x10U) >> 4U)} + , O3 {static_cast((v & 0x08U) >> 3U)} + , O2 {static_cast((v & 0x04U) >> 2U)} + , O1 {static_cast((v & 0x02U) >> 1U)} + , O0 {static_cast(v & 0x01U)} {} + constexpr explicit output_r() noexcept = default; + }; + + struct polarity_r : public register_t<0x02> { + constexpr static value_type invert {1}; + constexpr static value_type retain {0}; + + value_type N7 : 1 {retain}; + value_type N6 : 1 {retain}; + value_type N5 : 1 {retain}; + value_type N4 : 1 {retain}; + value_type N3 : 1 {retain}; + value_type N2 : 1 {retain}; + value_type N1 : 1 {retain}; + value_type N0 : 1 {retain}; + + [[nodiscard]] constexpr auto get() const noexcept -> value_type override { + return static_cast((N7 << 7U) | (N6 << 6U) | (N5 << 5U) | (N4 << 4U) + | (N3 << 3U) | (N2 << 2U) | (N1 << 1U) | N0); + } + + constexpr explicit polarity_r(value_type v) noexcept + : N7 {static_cast((v & 0x80U) >> 7U)} + , N6 {static_cast((v & 0x40U) >> 6U)} + , N5 {static_cast((v & 0x20U) >> 5U)} + , N4 {static_cast((v & 0x10U) >> 4U)} + , N3 {static_cast((v & 0x08U) >> 3U)} + , N2 {static_cast((v & 0x04U) >> 2U)} + , N1 {static_cast((v & 0x02U) >> 1U)} + , N0 {static_cast(v & 0x01U)} {} + constexpr explicit polarity_r() noexcept = default; + }; + + struct configuration_r : public register_t<0x03> { + constexpr static value_type input {1}; + constexpr static value_type output {0}; + + value_type C7 : 1 {input}; + value_type C6 : 1 {input}; + value_type C5 : 1 {input}; + value_type C4 : 1 {input}; + value_type C3 : 1 {input}; + value_type C2 : 1 {input}; + value_type C1 : 1 {input}; + value_type C0 : 1 {input}; + + [[nodiscard]] constexpr auto get() const noexcept -> value_type override { + return static_cast((C7 << 7U) | (C6 << 6U) | (C5 << 5U) | (C4 << 4U) + | (C3 << 3U) | (C2 << 2U) | (C1 << 1U) | C0); + } + + constexpr explicit configuration_r(value_type v) noexcept + : C7 {static_cast((v & 0x80U) >> 7U)} + , C6 {static_cast((v & 0x40U) >> 6U)} + , C5 {static_cast((v & 0x20U) >> 5U)} + , C4 {static_cast((v & 0x10U) >> 4U)} + , C3 {static_cast((v & 0x08U) >> 3U)} + , C2 {static_cast((v & 0x04U) >> 2U)} + , C1 {static_cast((v & 0x02U) >> 1U)} + , C0 {static_cast(v & 0x01U)} {} + constexpr explicit configuration_r() noexcept = default; + }; +}; + +} // namespace muonpi::serial::devices +#endif // MUONPI_SERIAL_I2CDEVICES_PCA9554_H diff --git a/include/muonpi/serial/i2cdevices/pca95xx.h b/include/muonpi/serial/i2cdevices/pca95xx.h new file mode 100644 index 0000000..dd52645 --- /dev/null +++ b/include/muonpi/serial/i2cdevices/pca95xx.h @@ -0,0 +1,87 @@ +#ifndef MUONPI_SERIAL_I2CDEVICES_PCA95XX_H +#define MUONPI_SERIAL_I2CDEVICES_PCA95XX_H +#include "muonpi/serial/i2cbus.h" +#include "muonpi/serial/i2cdevice.h" + +#include + +namespace muonpi::serial::devices { + +template +concept bits_c = ((B == 4) || (B == 8)); + +template +requires bits_c + /** + * @brief I2C io extender device class. + * This class provides access to i2c 4-bit and 8-bit bidirectional digital i/o + * extenders. + * @note valid template specializations are available for values of the template + * parameter BITS of 4 and 8. + */ + class pca95xx : public i2c_device { +public: + static constexpr std::size_t width {BITS}; + +protected: + pca95xx(traffic_t& bus_traffic, const std::string& path, i2c_device::address_type address); + pca95xx(traffic_t& bus_traffic, + const std::string& path, + const address_iterable auto& addresses); + + template > T> + [[nodiscard]] auto identify_impl() -> bool { + if (flag_set(Flags::Error)) { + return false; + } + if (!present()) { + return false; + } + + const auto input {read()}; + if (!input.has_value()) { + return false; + } + const auto output {read()}; + if (!output.has_value()) { + return false; + } + if (output.value().get() != typename T::output_r {}.get()) { + return false; + } + const auto polarity {read()}; + if (!polarity.has_value()) { + return false; + } + if (polarity.value().get() != typename T::polarity_r {}.get()) { + return false; + } + const auto configuration {read()}; + if (!configuration.has_value()) { + return false; + } + if (configuration.value().get() != typename T::configuration_r {}.get()) { + return false; + } + return true; + } +}; + +/*************************** + * Implementation part + ***************************/ + +template +requires bits_c pca95xx::pca95xx(traffic_t& bus_traffic, + const std::string& path, + i2c_device::address_type address) + : i2c_device {bus_traffic, path, address} {} + +template +requires bits_c pca95xx::pca95xx(traffic_t& bus_traffic, + const std::string& path, + const address_iterable auto& addresses) + : i2c_device {bus_traffic, path, addresses} {} + +} // namespace muonpi::serial::devices +#endif // MUONPI_SERIAL_I2CDEVICES_PCA95XX_H diff --git a/src/serial/i2cdevices/pca9536.cpp b/src/serial/i2cdevices/pca9536.cpp new file mode 100644 index 0000000..6c735ef --- /dev/null +++ b/src/serial/i2cdevices/pca9536.cpp @@ -0,0 +1,18 @@ +#include "muonpi/serial/i2cdevices/pca9536.h" + +namespace muonpi::serial::devices { +pca9536::pca9536(traffic_t& bus_traffic, const std::string& path, i2c_device::address_type address) + : pca95xx<4> {bus_traffic, path, address} { + set_name("PCA9536"); +} + +pca9536::pca9536(traffic_t& bus_traffic, const std::string& path) + : pca95xx<4> {bus_traffic, path, addresses} { + set_name("PCA9536"); +} + +auto pca9536::identify() -> bool { + return identify_impl(); +} + +} // namespace muonpi::serial::devices diff --git a/src/serial/i2cdevices/pca9554.cpp b/src/serial/i2cdevices/pca9554.cpp new file mode 100644 index 0000000..2961375 --- /dev/null +++ b/src/serial/i2cdevices/pca9554.cpp @@ -0,0 +1,18 @@ +#include "muonpi/serial/i2cdevices/pca9554.h" + +namespace muonpi::serial::devices { +pca9554::pca9554(traffic_t& bus_traffic, const std::string& path, i2c_device::address_type address) + : pca95xx<8> {bus_traffic, path, address} { + set_name("PCA9554"); +} + +pca9554::pca9554(traffic_t& bus_traffic, const std::string& path) + : pca95xx<8> {bus_traffic, path, addresses} { + set_name("PCA9554"); +} + +auto pca9554::identify() -> bool { + return identify_impl(); +} + +} // namespace muonpi::serial::devices diff --git a/src/serial/i2cdevices/pca95xx.cpp b/src/serial/i2cdevices/pca95xx.cpp new file mode 100644 index 0000000..b066a17 --- /dev/null +++ b/src/serial/i2cdevices/pca95xx.cpp @@ -0,0 +1 @@ +#include "muonpi/serial/i2cdevices/pca95xx.h" From c6cab71d792dd4861520144ba5bd3d9122d9428e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Treffenst=C3=A4dt?= Date: Sat, 16 Apr 2022 12:07:32 +0200 Subject: [PATCH 2/6] Added register tags to PCA95xx register structs. --- include/muonpi/serial/i2cdevices/pca9536.h | 8 ++++++++ include/muonpi/serial/i2cdevices/pca9554.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/include/muonpi/serial/i2cdevices/pca9536.h b/include/muonpi/serial/i2cdevices/pca9536.h index 2e45095..dbb8dcf 100644 --- a/include/muonpi/serial/i2cdevices/pca9536.h +++ b/include/muonpi/serial/i2cdevices/pca9536.h @@ -28,6 +28,8 @@ class pca9536 : public pca95xx<4> { using register_t = simple_register; struct input_r : public register_t<0x00> { + constexpr static tag_type register_tag { i2c_register_tag::read }; + const value_type I4_7 : 4 {}; value_type I3 : 1 {}; value_type I2 : 1 {}; @@ -48,6 +50,8 @@ class pca9536 : public pca95xx<4> { }; struct output_r : public register_t<0x01> { + constexpr static tag_type register_tag { i2c_register_tag::read_write }; + const value_type O4_7 : 4 {0xF}; value_type O3 : 1 {1}; value_type O2 : 1 {1}; @@ -68,6 +72,8 @@ class pca9536 : public pca95xx<4> { }; struct polarity_r : public register_t<0x02> { + constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static value_type invert {1}; constexpr static value_type retain {0}; @@ -90,6 +96,8 @@ class pca9536 : public pca95xx<4> { }; struct configuration_r : public register_t<0x03> { + constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static value_type input {1}; constexpr static value_type output {0}; diff --git a/include/muonpi/serial/i2cdevices/pca9554.h b/include/muonpi/serial/i2cdevices/pca9554.h index 7b3f42f..7a48132 100644 --- a/include/muonpi/serial/i2cdevices/pca9554.h +++ b/include/muonpi/serial/i2cdevices/pca9554.h @@ -30,6 +30,8 @@ class pca9554 : public pca95xx<8> { using register_t = simple_register; struct input_r : public register_t<0x00> { + constexpr static tag_type register_tag { i2c_register_tag::read }; + value_type I7 : 1 {}; value_type I6 : 1 {}; value_type I5 : 1 {}; @@ -57,6 +59,8 @@ class pca9554 : public pca95xx<8> { }; struct output_r : public register_t<0x01> { + constexpr static tag_type register_tag { i2c_register_tag::read_write }; + value_type O7 : 1 {1}; value_type O6 : 1 {1}; value_type O5 : 1 {1}; @@ -84,6 +88,8 @@ class pca9554 : public pca95xx<8> { }; struct polarity_r : public register_t<0x02> { + constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static value_type invert {1}; constexpr static value_type retain {0}; @@ -114,6 +120,8 @@ class pca9554 : public pca95xx<8> { }; struct configuration_r : public register_t<0x03> { + constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static value_type input {1}; constexpr static value_type output {0}; From b7505daca57306bcda5912621ad9ee8efee66f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Treffenst=C3=A4dt?= Date: Sat, 16 Apr 2022 12:11:16 +0200 Subject: [PATCH 3/6] Added documentation to pca9554 and pca9536 classes. --- include/muonpi/serial/i2cdevices/pca9536.h | 26 +++++++++++++++++----- include/muonpi/serial/i2cdevices/pca9554.h | 25 ++++++++++++++++----- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/include/muonpi/serial/i2cdevices/pca9536.h b/include/muonpi/serial/i2cdevices/pca9536.h index dbb8dcf..3bfabdf 100644 --- a/include/muonpi/serial/i2cdevices/pca9536.h +++ b/include/muonpi/serial/i2cdevices/pca9536.h @@ -9,17 +9,31 @@ namespace muonpi::serial::devices { /** - * @brief I2C io extender device class. - * This class provides access to i2c 4-bit and 8-bit bidirectional digital i/o - * extenders. - * @note valid template specializations are available for values of the template - * parameter BITS of 4 and 8. + * @brief The pca9536 class. interact with the PCA9554 8 bit IO extender. + * This implementation follows the datasheet closely: + * https://www.ti.com/lit/ds/symlink/pca9536.pdf */ -class pca9536 : public pca95xx<4> { +class pca9536 : public pca95xx<8> { public: + /** + * @brief pca9536 + * @param bus_traffic The bus traffic object from the i2c_bus. + * @param path The path of the i2c bus file descriptor + * @param address The address to use + */ pca9536(traffic_t& bus_traffic, const std::string& path, i2c_device::address_type address); + + /** + * @brief pca9536 Attempts to auto setup the connection + * @param bus_traffic The bus traffic object from the i2c_bus. + * @param path The path of the i2c bus file descriptor + */ pca9536(traffic_t& bus_traffic, const std::string& path); + /** + * @brief identify Attempts to positively identify the device. + * @return true if identification was successful. + */ [[nodiscard]] auto identify() -> bool override; constexpr static std::array addresses {0b10000011}; diff --git a/include/muonpi/serial/i2cdevices/pca9554.h b/include/muonpi/serial/i2cdevices/pca9554.h index 7a48132..cc5966e 100644 --- a/include/muonpi/serial/i2cdevices/pca9554.h +++ b/include/muonpi/serial/i2cdevices/pca9554.h @@ -8,19 +8,32 @@ #include namespace muonpi::serial::devices { - /** - * @brief I2C io extender device class. - * This class provides access to i2c 4-bit and 8-bit bidirectional digital i/o - * extenders. - * @note valid template specializations are available for values of the template - * parameter BITS of 4 and 8. + * @brief The pca9554 class. interact with the PCA9554 8 bit IO extender. + * This implementation follows the datasheet closely: + * https://www.ti.com/lit/ds/symlink/pca9554.pdf */ class pca9554 : public pca95xx<8> { public: + /** + * @brief pca9554 + * @param bus_traffic The bus traffic object from the i2c_bus. + * @param path The path of the i2c bus file descriptor + * @param address The address to use + */ pca9554(traffic_t& bus_traffic, const std::string& path, i2c_device::address_type address); + + /** + * @brief pca9554 Attempts to auto setup the connection + * @param bus_traffic The bus traffic object from the i2c_bus. + * @param path The path of the i2c bus file descriptor + */ pca9554(traffic_t& bus_traffic, const std::string& path); + /** + * @brief identify Attempts to positively identify the device. + * @return true if identification was successful. + */ [[nodiscard]] auto identify() -> bool override; constexpr static multi_address_range addresses { From 7536dcc495c90ce73e80597a7596ff248b961e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Treffenst=C3=A4dt?= Date: Sat, 16 Apr 2022 12:50:15 +0200 Subject: [PATCH 4/6] Fixed hardware addresses of PCA95xx devices --- include/muonpi/serial/i2cdevices/pca9536.h | 2 +- include/muonpi/serial/i2cdevices/pca9554.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/muonpi/serial/i2cdevices/pca9536.h b/include/muonpi/serial/i2cdevices/pca9536.h index 3bfabdf..bfea52a 100644 --- a/include/muonpi/serial/i2cdevices/pca9536.h +++ b/include/muonpi/serial/i2cdevices/pca9536.h @@ -36,7 +36,7 @@ class pca9536 : public pca95xx<8> { */ [[nodiscard]] auto identify() -> bool override; - constexpr static std::array addresses {0b10000011}; + constexpr static std::array addresses {0b1000001}; template using register_t = simple_register; diff --git a/include/muonpi/serial/i2cdevices/pca9554.h b/include/muonpi/serial/i2cdevices/pca9554.h index cc5966e..4f69e53 100644 --- a/include/muonpi/serial/i2cdevices/pca9554.h +++ b/include/muonpi/serial/i2cdevices/pca9554.h @@ -37,7 +37,7 @@ class pca9554 : public pca95xx<8> { [[nodiscard]] auto identify() -> bool override; constexpr static multi_address_range addresses { - {address_range {0b01000000, {0b00000111}}, address_range {0b01110000, {0b00000111}}}}; + {address_range {0b0100000, {0b00000111}}, address_range {0b0111000, {0b00000111}}}}; template using register_t = simple_register; From e4ee0f6c4df7f2dc85c600d98b2fec5e31bbbc33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Treffenst=C3=A4dt?= Date: Sat, 16 Apr 2022 12:55:41 +0200 Subject: [PATCH 5/6] Fixed bit size of pca9536 inheritance --- include/muonpi/serial/i2cdevices/pca9536.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/muonpi/serial/i2cdevices/pca9536.h b/include/muonpi/serial/i2cdevices/pca9536.h index bfea52a..91e13d4 100644 --- a/include/muonpi/serial/i2cdevices/pca9536.h +++ b/include/muonpi/serial/i2cdevices/pca9536.h @@ -13,7 +13,7 @@ namespace muonpi::serial::devices { * This implementation follows the datasheet closely: * https://www.ti.com/lit/ds/symlink/pca9536.pdf */ -class pca9536 : public pca95xx<8> { +class pca9536 : public pca95xx<4> { public: /** * @brief pca9536 From 96bcdadeafcc528164886375ef9887d2f2920834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Treffenst=C3=A4dt?= Date: Sun, 31 Jul 2022 13:56:35 +0200 Subject: [PATCH 6/6] Updated use of i2c_tag_type alias --- include/muonpi/serial/i2cdevices/pca9536.h | 8 ++++---- include/muonpi/serial/i2cdevices/pca9554.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/muonpi/serial/i2cdevices/pca9536.h b/include/muonpi/serial/i2cdevices/pca9536.h index 91e13d4..5a5134d 100644 --- a/include/muonpi/serial/i2cdevices/pca9536.h +++ b/include/muonpi/serial/i2cdevices/pca9536.h @@ -42,7 +42,7 @@ class pca9536 : public pca95xx<4> { using register_t = simple_register; struct input_r : public register_t<0x00> { - constexpr static tag_type register_tag { i2c_register_tag::read }; + constexpr static i2c_tag_type register_tag { i2c_register_tag::read }; const value_type I4_7 : 4 {}; value_type I3 : 1 {}; @@ -64,7 +64,7 @@ class pca9536 : public pca95xx<4> { }; struct output_r : public register_t<0x01> { - constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static i2c_tag_type register_tag { i2c_register_tag::read_write }; const value_type O4_7 : 4 {0xF}; value_type O3 : 1 {1}; @@ -86,7 +86,7 @@ class pca9536 : public pca95xx<4> { }; struct polarity_r : public register_t<0x02> { - constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static i2c_tag_type register_tag { i2c_register_tag::read_write }; constexpr static value_type invert {1}; constexpr static value_type retain {0}; @@ -110,7 +110,7 @@ class pca9536 : public pca95xx<4> { }; struct configuration_r : public register_t<0x03> { - constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static i2c_tag_type register_tag { i2c_register_tag::read_write }; constexpr static value_type input {1}; constexpr static value_type output {0}; diff --git a/include/muonpi/serial/i2cdevices/pca9554.h b/include/muonpi/serial/i2cdevices/pca9554.h index 4f69e53..934d6d8 100644 --- a/include/muonpi/serial/i2cdevices/pca9554.h +++ b/include/muonpi/serial/i2cdevices/pca9554.h @@ -43,7 +43,7 @@ class pca9554 : public pca95xx<8> { using register_t = simple_register; struct input_r : public register_t<0x00> { - constexpr static tag_type register_tag { i2c_register_tag::read }; + constexpr static i2c_tag_type register_tag { i2c_register_tag::read }; value_type I7 : 1 {}; value_type I6 : 1 {}; @@ -72,7 +72,7 @@ class pca9554 : public pca95xx<8> { }; struct output_r : public register_t<0x01> { - constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static i2c_tag_type register_tag { i2c_register_tag::read_write }; value_type O7 : 1 {1}; value_type O6 : 1 {1}; @@ -101,7 +101,7 @@ class pca9554 : public pca95xx<8> { }; struct polarity_r : public register_t<0x02> { - constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static i2c_tag_type register_tag { i2c_register_tag::read_write }; constexpr static value_type invert {1}; constexpr static value_type retain {0}; @@ -133,7 +133,7 @@ class pca9554 : public pca95xx<8> { }; struct configuration_r : public register_t<0x03> { - constexpr static tag_type register_tag { i2c_register_tag::read_write }; + constexpr static i2c_tag_type register_tag { i2c_register_tag::read_write }; constexpr static value_type input {1}; constexpr static value_type output {0};