PCA9685 Driver
API reference
Loading...
Searching...
No Matches
pca9685_i2c_interface.hpp
Go to the documentation of this file.
1
6#pragma once
7#include <cstddef>
8#include <cstdint>
9
10namespace pca9685 {
11
12// ============================================================================
13// GPIO Enums -- Standardised Control Pin Model
14// ============================================================================
15
27enum class CtrlPin : uint8_t {
28 OE = 0
29};
30
37enum class GpioSignal : uint8_t {
38 INACTIVE = 0,
39 ACTIVE = 1
40};
41
76template <typename Derived>
78public:
87 bool Write(uint8_t addr, uint8_t reg, const uint8_t* data, size_t len) noexcept {
88 return static_cast<Derived*>(this)->Write(addr, reg, data, len);
89 }
90
99 bool Read(uint8_t addr, uint8_t reg, uint8_t* data, size_t len) noexcept {
100 return static_cast<Derived*>(this)->Read(addr, reg, data, len);
101 }
102
114 bool EnsureInitialized() noexcept {
115 return static_cast<Derived*>(this)->EnsureInitialized();
116 }
117
118 // --------------------------------------------------------------------------
123
138 void GpioSet(CtrlPin pin, GpioSignal signal) noexcept {
139 (void)pin;
140 (void)signal;
141 }
142
147 void GpioSetActive(CtrlPin pin) noexcept {
148 static_cast<Derived*>(this)->GpioSet(pin, GpioSignal::ACTIVE);
149 }
150
155 void GpioSetInactive(CtrlPin pin) noexcept {
156 static_cast<Derived*>(this)->GpioSet(pin, GpioSignal::INACTIVE);
157 }
158
160
162 I2cInterface(const I2cInterface&) = delete;
169
170protected:
174 I2cInterface() = default;
175
180 ~I2cInterface() = default;
181};
182
183} // namespace pca9685
CRTP-based template interface for I2C bus operations.
Definition pca9685_i2c_interface.hpp:77
I2cInterface & operator=(I2cInterface &&)=delete
Move assignment deleted (non-movable).
void GpioSetInactive(CtrlPin pin) noexcept
Deassert a control pin (set to INACTIVE).
Definition pca9685_i2c_interface.hpp:155
I2cInterface(const I2cInterface &)=delete
Copy constructor deleted (non-copyable; avoids slicing).
I2cInterface()=default
Protected constructor to prevent direct instantiation.
~I2cInterface()=default
Protected destructor.
bool Write(uint8_t addr, uint8_t reg, const uint8_t *data, size_t len) noexcept
Write bytes to a device register.
Definition pca9685_i2c_interface.hpp:87
bool Read(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) noexcept
Read bytes from a device register.
Definition pca9685_i2c_interface.hpp:99
bool EnsureInitialized() noexcept
Ensure the I2C bus is initialized and ready for communication.
Definition pca9685_i2c_interface.hpp:114
I2cInterface(I2cInterface &&)=delete
Move constructor deleted (non-movable; use derived type to move).
void GpioSetActive(CtrlPin pin) noexcept
Assert a control pin (set to ACTIVE).
Definition pca9685_i2c_interface.hpp:147
void GpioSet(CtrlPin pin, GpioSignal signal) noexcept
Set a control pin to the specified signal state.
Definition pca9685_i2c_interface.hpp:138
I2cInterface & operator=(const I2cInterface &)=delete
Copy assignment deleted (non-copyable).
Definition pca9685.hpp:16
GpioSignal
Abstract signal level for control pins.
Definition pca9685_i2c_interface.hpp:37
@ ACTIVE
Pin function is asserted.
@ INACTIVE
Pin function is deasserted.
CtrlPin
Identifies the hardware control pins of the PCA9685.
Definition pca9685_i2c_interface.hpp:27
@ OE
Output Enable (active-low on the physical pin)