PCAL9555 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
pcal9555.hpp
Go to the documentation of this file.
1
12#ifndef PCAL9555_HPP
13#define PCAL9555_HPP
14
15#include <array>
16#include <cstddef>
17#include <cstdint>
18#include <span>
19
20#include "pcal9555_detail.hpp"
23#include "pcal9555_types.hpp"
24#include "pcal9555_version.h"
25
26namespace pcal9555 {
27
28namespace detail {
29
31[[nodiscard]] constexpr uint16_t Apply(uint16_t value, uint16_t mask, bool set) noexcept {
32 const auto v = static_cast<uint32_t>(value);
33 const auto m = static_cast<uint32_t>(mask);
34 return static_cast<uint16_t>(set ? (v | m) : (v & ~m));
35}
36
39[[nodiscard]] constexpr uint32_t ApplyDrive(uint32_t codes, uint16_t mask,
40 DriveStrength level) noexcept {
41 const uint32_t code = static_cast<uint32_t>(ToUnderlying(level)) & reg::kDriveCodeMask;
42 for (uint32_t pin = 0U; pin < kPinCount; ++pin) {
43 if ((static_cast<uint32_t>(mask) & (uint32_t{1} << pin)) != 0U) {
44 const uint32_t shift = reg::kDriveBitsPerPin * pin;
45 codes = (codes & ~(reg::kDriveCodeMask << shift)) | (code << shift);
46 }
47 }
48 return codes;
49}
50
52[[nodiscard]] constexpr uint16_t PairValueOf(std::span<const uint8_t, 2> bytes) noexcept {
53 return static_cast<uint16_t>(static_cast<uint32_t>(bytes[0]) |
54 (static_cast<uint32_t>(bytes[1]) << 8U));
55}
56
58[[nodiscard]] constexpr uint16_t WithByte(uint16_t value, uint32_t port, uint8_t byte) noexcept {
59 const uint32_t shift = (port & 1U) * 8U;
60 return static_cast<uint16_t>((static_cast<uint32_t>(value) & ~(0xFFU << shift)) |
61 (static_cast<uint32_t>(byte) << shift));
62}
63
65struct PairValue {
66 uint8_t reg;
67 uint16_t value;
68};
69
71[[nodiscard]] constexpr std::array<PairValue, 3> StandardPairs(const Config& c) noexcept {
72 return {{{.reg = reg::kOutputPort0, .value = c.output_high_mask},
73 {.reg = reg::kPolarityPort0, .value = c.polarity_invert_mask},
74 {.reg = reg::kConfigPort0, .value = c.input_mask}}};
75}
76
78[[nodiscard]] constexpr std::array<PairValue, 6> AgilePairs(const Config& c) noexcept {
79 return {
80 {{.reg = reg::kDriveStrength0,
81 .value = static_cast<uint16_t>(c.drive_strength_codes & 0xFFFFU)},
82 {.reg = reg::kDriveStrength2, .value = static_cast<uint16_t>(c.drive_strength_codes >> 16U)},
83 {.reg = reg::kInputLatch0, .value = c.input_latch_mask},
84 {.reg = reg::kPullSelect0, .value = c.pull_up_mask},
85 {.reg = reg::kPullEnable0, .value = c.pull_enable_mask},
86 {.reg = reg::kInterruptMask0, .value = c.interrupt_mask}}};
87}
88
90[[nodiscard]] constexpr uint8_t OutputPortConfig(const Config& config) noexcept {
91 uint32_t value = 0U;
92 if (config.port0_mode == OutputMode::OpenDrain) {
93 value |= static_cast<uint32_t>(reg::kOutputConfigOden0);
94 }
95 if (config.port1_mode == OutputMode::OpenDrain) {
96 value |= static_cast<uint32_t>(reg::kOutputConfigOden1);
97 }
98 return static_cast<uint8_t>(value);
99}
100
103inline constexpr uint8_t kNoSentinel = 0x00U;
104static_assert(kNoSentinel == reg::kInputPort0);
105
107struct ResetSentinel {
108 uint8_t reg;
109 uint16_t value;
110 uint16_t reset;
111 bool pair;
112 bool only;
113};
114
117[[nodiscard]] constexpr uint32_t UncertainIndex(uint8_t command) noexcept {
118 const auto c = static_cast<uint32_t>(command);
119 if (c == static_cast<uint32_t>(reg::kOutputPortConfig)) {
120 return 10U;
121 }
122 if (c >= static_cast<uint32_t>(reg::kDriveStrength0)) {
123 return (4U + ((c - static_cast<uint32_t>(reg::kDriveStrength0)) / 2U)) & 0x0FU;
124 }
125 return (c / 2U) & 0x0FU;
126}
127
129[[nodiscard]] constexpr uint32_t UncertainBit(uint8_t command) noexcept {
130 return uint32_t{1} << UncertainIndex(command);
131}
132
134inline constexpr uint32_t kAllUncertain = 0x07FEU;
135
137[[nodiscard]] constexpr uint32_t StrongerDrive(uint32_t a, uint32_t b) noexcept {
138 uint32_t codes = 0U;
139 for (uint32_t pin = 0U; pin < kPinCount; ++pin) {
140 const uint32_t shift = reg::kDriveBitsPerPin * pin;
141 const uint32_t ca = (a >> shift) & reg::kDriveCodeMask;
142 const uint32_t cb = (b >> shift) & reg::kDriveCodeMask;
143 codes |= ((ca > cb) ? ca : cb) << shift;
144 }
145 return codes;
146}
147
155[[nodiscard]] constexpr Config Riskier(const Config& old, const Config& asked) noexcept {
156 Config r = asked;
157 r.input_mask = static_cast<uint16_t>(static_cast<uint32_t>(old.input_mask) &
158 static_cast<uint32_t>(asked.input_mask));
160 if (old.port0_mode == OutputMode::PushPull) {
162 }
163 if (old.port1_mode == OutputMode::PushPull) {
165 }
166 return r;
167}
168
170[[nodiscard]] constexpr uint16_t RegisterValue(const Config& c, uint8_t command) noexcept {
171 uint32_t v = 0U;
172 if (command == reg::kOutputPort0) {
173 v = c.output_high_mask;
174 } else if (command == reg::kPolarityPort0) {
176 } else if (command == reg::kConfigPort0) {
177 v = c.input_mask;
178 } else if (command == reg::kDriveStrength0) {
179 v = c.drive_strength_codes & 0xFFFFU;
180 } else if (command == reg::kDriveStrength2) {
181 v = c.drive_strength_codes >> 16U;
182 } else if (command == reg::kInputLatch0) {
183 v = c.input_latch_mask;
184 } else if (command == reg::kPullEnable0) {
185 v = c.pull_enable_mask;
186 } else if (command == reg::kPullSelect0) {
187 v = c.pull_up_mask;
188 } else if (command == reg::kInterruptMask0) {
189 v = c.interrupt_mask;
190 } else if (command == reg::kOutputPortConfig) {
191 v = OutputPortConfig(c);
192 } else {
193 // Not a register the driver writes.
194 }
195 return static_cast<uint16_t>(v);
196}
197
199constexpr void Adopt(Config& c, uint8_t command, uint16_t value) noexcept {
200 const auto v = static_cast<uint32_t>(value);
201 if (command == reg::kOutputPort0) {
202 c.output_high_mask = value;
203 } else if (command == reg::kPolarityPort0) {
204 c.polarity_invert_mask = value;
205 } else if (command == reg::kConfigPort0) {
206 c.input_mask = value;
207 } else if (command == reg::kDriveStrength0) {
208 c.drive_strength_codes = (c.drive_strength_codes & 0xFFFF'0000U) | v;
209 } else if (command == reg::kDriveStrength2) {
210 c.drive_strength_codes = (c.drive_strength_codes & 0x0000'FFFFU) | (v << 16U);
211 } else if (command == reg::kInputLatch0) {
212 c.input_latch_mask = value;
213 } else if (command == reg::kPullEnable0) {
214 c.pull_enable_mask = value;
215 } else if (command == reg::kPullSelect0) {
216 c.pull_up_mask = value;
217 } else if (command == reg::kInterruptMask0) {
218 c.interrupt_mask = value;
219 } else if (command == reg::kOutputPortConfig) {
220 c.port0_mode = ((v & static_cast<uint32_t>(reg::kOutputConfigOden0)) != 0U)
223 c.port1_mode = ((v & static_cast<uint32_t>(reg::kOutputConfigOden1)) != 0U)
226 } else {
227 // Not a register the driver writes: nothing to adopt.
228 }
229}
230
232[[nodiscard]] constexpr ResetSentinel Candidate(uint8_t command, uint16_t value, uint16_t reset,
233 bool pair = true) noexcept {
234 return {.reg = command, .value = value, .reset = reset, .pair = pair, .only = true};
235}
236
249[[nodiscard]] constexpr ResetSentinel FindResetSentinel(const Config& c, bool agile,
250 uint32_t uncertain = 0U) noexcept {
251 const auto drive_low = static_cast<uint16_t>(c.drive_strength_codes & 0xFFFFU);
252 const auto drive_high = static_cast<uint16_t>(c.drive_strength_codes >> 16U);
253 const auto drive_reset = static_cast<uint16_t>(reg::kDriveStrengthReset & 0xFFFFU);
254 const std::array<ResetSentinel, 10> candidates{{
259 Candidate(reg::kDriveStrength0, drive_low, drive_reset),
260 Candidate(reg::kDriveStrength2, drive_high, drive_reset),
262 Candidate(reg::kOutputPortConfig, OutputPortConfig(c), reg::kOutputPortConfigReset, false),
265 }};
266 ResetSentinel found{.reg = kNoSentinel, .value = 0U, .reset = 0U, .pair = true, .only = true};
267 for (const ResetSentinel& candidate : candidates) {
268 if (!reg::IsImplemented(candidate.reg, agile) || (candidate.value == candidate.reset) ||
269 ((uncertain & UncertainBit(candidate.reg)) != 0U)) {
270 continue; // an unknown register proves nothing either way
271 }
272 if (found.reg != kNoSentinel) {
273 found.only = false;
274 break;
275 }
276 found = candidate;
277 }
278 if (uncertain != 0U) {
279 found.only = false; // an unknown register may differ too
280 }
281 return found;
282}
283
284// The power-up configuration encodes to the power-up register values (table 4), and the helpers
285// put each field where the register map says (KB-CPP20-012).
286static_assert((StandardPairs(Config{})[0].value == reg::kOutputReset) &&
287 (StandardPairs(Config{})[1].value == reg::kPolarityReset) &&
288 (StandardPairs(Config{})[2].value == reg::kConfigReset));
289static_assert((AgilePairs(Config{})[0].value == 0xFFFFU) &&
290 (AgilePairs(Config{})[1].value == 0xFFFFU) &&
291 (AgilePairs(Config{})[2].value == reg::kInputLatchReset) &&
292 (AgilePairs(Config{})[3].value == reg::kPullSelectReset) &&
293 (AgilePairs(Config{})[4].value == reg::kPullEnableReset) &&
294 (AgilePairs(Config{})[5].value == reg::kInterruptMaskReset));
295static_assert(OutputPortConfig(Config{}) == reg::kOutputPortConfigReset);
297static_assert(ApplyDrive(0_u32, PinMask(15_u8), DriveStrength::Full) == 0xC000'0000U);
298static_assert(ApplyDrive(0xFFFF'FFFF_u32, PinMask(0_u8), DriveStrength::Quarter) == 0xFFFF'FFFCU);
299static_assert(PairValueOf(std::array<uint8_t, 2>{0x34, 0x12}) == 0x1234U);
300static_assert((UncertainBit(reg::kOutputPort0) == 0x0002U) &&
301 (UncertainBit(reg::kConfigPort0) == 0x0008U) &&
302 (UncertainBit(reg::kDriveStrength0) == 0x0010U) &&
303 (UncertainBit(reg::kInterruptMask0) == 0x0200U) &&
304 (UncertainBit(reg::kOutputPortConfig) == kAllUncertain - 0x03FEU));
305static_assert(StrongerDrive(0x0000'00F0_u32, 0x0000'003C_u32) == 0x0000'00FCU);
306static_assert((RegisterValue(Config{}, reg::kConfigPort0) == reg::kConfigReset) &&
307 (RegisterValue(Config{}, reg::kDriveStrength2) == 0xFFFFU) &&
309static_assert((WithByte(0x1234_u16, 1_u32, 0xAB_u8) == 0xAB34U) &&
310 (WithByte(0x1234_u16, 0_u32, 0xAB_u8) == 0x12ABU));
311static_assert((FindResetSentinel(Config{.output_high_mask = 0U, .input_mask = 0U}, false).reg ==
313 !FindResetSentinel(Config{.output_high_mask = 0U, .input_mask = 0U}, false).only);
314static_assert((FindResetSentinel(Config{}, true).reg == kNoSentinel) &&
315 (FindResetSentinel(
317 .reg == reg::kOutputPortConfig));
318static_assert((Apply(0x00F0_u16, 0x0F0F_u16, true) == 0x0FFFU) &&
319 (Apply(0xFFFF_u16, 0x0F0F_u16, false) == 0xF0F0U));
320
321} // namespace detail
322
329// clang-format off: the hook table below must keep one row per line.
382// clang-format on
383template <I2cPort Port>
384class PCAL9555 {
385 static_assert(!detail::DeclaresLog<Port> || detail::HasLog<Port>,
386 "pcal9555: the optional Log hook must be `void Log(LogLevel, const char* message) "
387 "noexcept`");
388 static_assert(!detail::DeclaresGetLastFailure<Port> || detail::HasGetLastFailure<Port>,
389 "pcal9555: the optional GetLastFailure hook must be `bool "
390 "GetLastFailure(I2cFailure& failure) noexcept`");
391
392public:
401 explicit PCAL9555(Port& port, uint8_t address = kI2cAddress, const Config& config = {}) noexcept
402 : bus_(port, address), config_(config) {}
403
405 PCAL9555(const PCAL9555&) = delete;
407 PCAL9555& operator=(const PCAL9555&) = delete;
408
411
433
435 [[nodiscard]] bool IsInitialized() const noexcept {
436 return initialized_;
437 }
438
451
455
467 Result<void> ApplyConfig(const Config& config) noexcept;
468
481 [[nodiscard]] const Config& GetConfig() const& noexcept {
482 return config_;
483 }
485 void GetConfig() const&& = delete;
486
488 [[nodiscard]] uint8_t GetAddress() const noexcept {
489 return bus_.GetAddress();
490 }
491
515
519
548 Result<void> SetDirection(uint16_t mask, Direction direction,
549 Verify verify = Verify::None) noexcept;
550
560 Result<void> SetOutputs(uint16_t mask, bool high, Verify verify = Verify::None) noexcept;
561
569 Result<void> WriteOutputs(uint16_t high_mask, Verify verify = Verify::None) noexcept;
570
583 Result<void> ToggleOutputs(uint16_t mask, Verify verify = Verify::None) noexcept;
584
593 Result<void> SetPolarityInversion(uint16_t mask, bool invert,
594 Verify verify = Verify::None) noexcept;
595
607 Result<uint16_t> ReadInputs() noexcept;
608
616 Result<bool> ReadPin(uint8_t pin) noexcept;
617
621
631 Result<void> SetDriveStrength(uint16_t mask, DriveStrength level,
632 Verify verify = Verify::None) noexcept;
633
645 Result<void> SetPull(uint16_t mask, Pull pull, Verify verify = Verify::None) noexcept;
646
657 Result<void> SetInputLatch(uint16_t mask, bool latch, Verify verify = Verify::None) noexcept;
658
669 Result<void> SetInterruptEnabled(uint16_t mask, bool enable,
670 Verify verify = Verify::None) noexcept;
671
677 Result<uint16_t> ReadInterruptStatus() noexcept;
678
688 Result<void> SetOutputMode(Bank bank, OutputMode mode, Verify verify = Verify::None) noexcept;
692
702 Result<uint16_t> ReadOutputLatch() noexcept;
703
708 Result<uint16_t> ReadInputMask() noexcept;
709
714 Result<uint16_t> ReadPolarityInversion() noexcept;
715
719
734 Result<uint8_t> ReadRegister(uint8_t command) noexcept;
735
740 [[nodiscard]] uint16_t GetLastInputs() const noexcept {
741 return last_inputs_;
742 }
743
750 [[nodiscard]] uint16_t GetLastOutput() const noexcept {
751 return last_output_;
752 }
753
764 [[nodiscard]] uint16_t GetLatchedInterrupts() const noexcept {
765 return latched_interrupts_;
766 }
767
769 void ClearLatchedInterrupts() noexcept {
770 latched_interrupts_ = 0U;
771 }
772
774
775private:
776 Result<void> initialize() noexcept;
777 Result<void> checkPresence() noexcept;
778 Result<void> writeAll(const Config& c, uint8_t& failed) noexcept;
779 void noteApplyFailure(const Config& asked, uint8_t failed, Error error) noexcept;
780 Result<void> resolveAll() noexcept;
781 Result<void> checkUnknown() noexcept;
782 Result<void> writeStage() noexcept;
783 void forget(uint8_t reg) noexcept;
784 Result<void> verifyAll(const Config& c) noexcept;
785 Result<void> checkCall(uint16_t mask, bool agile, Verify verify = Verify::None) const noexcept;
786 Result<void> storeMask(uint8_t reg, uint16_t Config::* field, uint16_t value,
787 Verify verify) noexcept;
788 Result<void> checkReset() noexcept;
789 Result<void> guardWrite(uint8_t first, uint8_t second) noexcept;
790 Result<void> noteInterrupts() noexcept;
791 Result<void> prepare(uint8_t first, uint8_t second) noexcept;
792 Result<void> resolve(uint8_t reg) noexcept;
793 void markFailed(const Config& asked, uint8_t reg, Error error) noexcept;
794 [[nodiscard]] bool isUncertain(uint8_t reg) const noexcept {
795 return (static_cast<uint32_t>(uncertain_) & detail::UncertainBit(reg)) != 0U;
796 }
797 Result<void> writeDrive(uint32_t codes, Verify verify) noexcept;
798 Result<void> storeDrive(uint8_t reg, uint32_t codes, uint16_t value, Verify verify) noexcept;
799 Result<uint16_t> readPair(uint8_t reg) noexcept;
800 Result<uint8_t> readByte(uint8_t reg) noexcept;
801 Result<void> writeByte(uint8_t reg, uint8_t value) noexcept;
802 void notePair(uint8_t reg, uint16_t value) noexcept;
803 void noteByte(uint8_t reg, uint8_t value) noexcept;
804 Result<void> writePair(uint8_t reg, uint16_t value) noexcept;
805 Result<void> writePairChecked(uint8_t reg, uint16_t value, Verify verify) noexcept;
806 Result<uint16_t> readStarted(uint8_t reg) noexcept;
807 template <std::size_t N>
808 Result<void> verifyPairs(const std::array<detail::PairValue, N>& pairs) noexcept;
809 Result<void> fail(Error error, const char* message) noexcept;
810
811 [[nodiscard]] bool isAgile() const noexcept {
812 return config_.variant == Variant::Pcal9555a;
813 }
814
815 detail::RegisterBus<Port> bus_;
816 Config config_{};
817 uint16_t last_inputs_{0U};
818 uint16_t last_output_{reg::kOutputReset};
819 uint16_t latched_interrupts_{0U};
820 uint16_t uncertain_{0U};
821 bool initialized_{false};
822};
823
826} // namespace pcal9555
827
828// codeql::misra_deviation_next_line(MD-CPP-009)
829#include "../src/pcal9555.ipp" // IWYU pragma: export
830
831#endif // PCAL9555_HPP
Driver for one PCA9555 or PCAL9555A on a platform port.
Definition pcal9555.hpp:384
Result< void > SetOutputMode(Bank bank, OutputMode mode, Verify verify=Verify::None) noexcept
Select push-pull or open-drain outputs for a whole port (output port configuration).
Result< uint16_t > ReadPolarityInversion() noexcept
Read both polarity inversion registers.
Result< uint16_t > ReadInputs() noexcept
Read both input ports: the level of every pin, inputs and outputs, after polarity inversion....
Result< bool > ReadPin(uint8_t pin) noexcept
Read the level of one pin. Reads its port's input register only, which clears that port's interrupt....
Result< void > WriteOutputs(uint16_t high_mask, Verify verify=Verify::None) noexcept
Write both output port registers at once.
uint16_t GetLatchedInterrupts() const noexcept
The pins any read of the interrupt status registers has reported since ClearLatchedInterrupts(),...
Definition pcal9555.hpp:764
bool IsInitialized() const noexcept
Definition pcal9555.hpp:435
uint16_t GetLastInputs() const noexcept
Definition pcal9555.hpp:740
uint8_t GetAddress() const noexcept
Definition pcal9555.hpp:488
Result< void > SetPull(uint16_t mask, Pull pull, Verify verify=Verify::None) noexcept
Connect a pull-up or pull-down to the pins in mask, or disconnect it. Writes the selection pair,...
Result< uint16_t > ReadInterruptStatus() noexcept
Read which pins raised the interrupt (interrupt status registers). Masked pins read 0....
Result< void > ApplyConfig(const Config &config) noexcept
Replace the configuration. When initialised, check for a reset (one read, see CheckForReset()),...
Result< void > SetDirection(uint16_t mask, Direction direction, Verify verify=Verify::None) noexcept
Set the direction of the pins in mask (configuration registers).
Result< void > SetPolarityInversion(uint16_t mask, bool invert, Verify verify=Verify::None) noexcept
Invert (or stop inverting) how the input pins in mask read (polarity inversion).
void ClearLatchedInterrupts() noexcept
Empty the latch of GetLatchedInterrupts(). No I/O; the chip is not touched.
Definition pcal9555.hpp:769
PCAL9555 & operator=(const PCAL9555 &)=delete
One driver object per chip.
Result< void > Deinitialize() noexcept
Make every pin a high-impedance input (the power-up direction), the safe state, and mark the driver u...
Result< void > SetDriveStrength(uint16_t mask, DriveStrength level, Verify verify=Verify::None) noexcept
Set the output drive strength of the pins in mask. Writes both drive strength pairs.
PCAL9555(Port &port, uint8_t address=kI2cAddress, const Config &config={}) noexcept
Bind the driver to a port, a 7-bit I2C address and a configuration. No I/O, no checks: EnsureInitiali...
Definition pcal9555.hpp:401
PCAL9555(const PCAL9555 &)=delete
One driver object per chip.
uint16_t GetLastOutput() const noexcept
Definition pcal9555.hpp:750
Result< uint8_t > ReadRegister(uint8_t command) noexcept
Read one register, once: one 1-byte write-read, no retry, no check of the value (handbook KB-CPP-129)...
void GetConfig() const &&=delete
Not on a temporary driver: the reference would dangle (handbook KB-CPP20-044).
Result< void > CheckForReset() noexcept
Find out whether the chip went through a power-on reset since the start.
Result< void > SetInterruptEnabled(uint16_t mask, bool enable, Verify verify=Verify::None) noexcept
Let the input pins in mask raise INT on a change, or mask them (interrupt mask registers; every pin i...
Result< uint16_t > ReadOutputLatch() noexcept
Read both output port registers: the level each pin is told to drive.
Result< void > SetOutputs(uint16_t mask, bool high, Verify verify=Verify::None) noexcept
Drive the pins in mask high or low (output port registers). Pins configured as inputs keep the value ...
Result< void > EnsureInitialized() noexcept
Start the chip on the first call; Ok at once, with no I/O, once it has succeeded.
Result< void > SetInputLatch(uint16_t mask, bool latch, Verify verify=Verify::None) noexcept
Latch (or stop latching) input changes of the pins in mask: a latched pin keeps the level that raised...
Result< void > ToggleOutputs(uint16_t mask, Verify verify=Verify::None) noexcept
Invert the output value of the pins in mask.
const Config & GetConfig() const &noexcept
Definition pcal9555.hpp:481
Result< uint16_t > ReadInputMask() noexcept
Read both configuration registers.
constexpr uint8_t kOutputConfigOden0
0x4F ODEN0: port 0 open-drain.
Definition pcal9555_registers.hpp:49
constexpr bool IsImplemented(uint8_t command, bool agile) noexcept
Whether a part implements a command byte (table 4): 0x00 to 0x07 on both parts, and on the PCAL9555A ...
Definition pcal9555_registers.hpp:83
constexpr uint16_t kOutputReset
Output ports: every pin high.
Definition pcal9555_registers.hpp:64
constexpr uint8_t kPullSelect0
Pull-up/pull-down selection 0 (R/W): 1 = pull-up.
Definition pcal9555_registers.hpp:44
constexpr uint16_t kConfigReset
Definition pcal9555_registers.hpp:66
constexpr uint32_t kDriveStrengthReset
Drive strength: full on every pin (0x40 to 0x43 all 0xFF).
Definition pcal9555_registers.hpp:68
constexpr uint8_t kConfigPort0
Configuration 0 (R/W): 1 = input; 0x07 port 1.
Definition pcal9555_registers.hpp:37
constexpr uint16_t kPullEnableReset
Pull resistors: enabled.
Definition pcal9555_registers.hpp:70
constexpr uint8_t kOutputPortConfig
Output port configuration (R/W).
Definition pcal9555_registers.hpp:47
constexpr uint8_t kOutputConfigOden1
Definition pcal9555_registers.hpp:50
constexpr uint8_t kPullEnable0
Pull-up/pull-down enable 0 (R/W); 0x47 port 1.
Definition pcal9555_registers.hpp:43
constexpr uint16_t kInterruptMaskReset
Interrupts: every pin masked.
Definition pcal9555_registers.hpp:72
constexpr uint32_t kDriveCodeMask
Mask of one pin's drive strength code.
Definition pcal9555_registers.hpp:61
constexpr uint8_t kDriveStrength0
Drive strength 0 (R/W): P0_0-3; 0x41 P0_4-7.
Definition pcal9555_registers.hpp:40
constexpr uint8_t kInputLatch0
Input latch 0 (R/W): 1 = latched; 0x45 port 1.
Definition pcal9555_registers.hpp:42
constexpr uint8_t kInputPort0
Input port 0 (R): pin levels; 0x01 is port 1.
Definition pcal9555_registers.hpp:34
constexpr uint8_t kOutputPortConfigReset
Both ports push-pull.
Definition pcal9555_registers.hpp:73
constexpr uint16_t kPullSelectReset
Pull resistors: pull-up.
Definition pcal9555_registers.hpp:71
constexpr uint16_t kInputLatchReset
Input latch: off.
Definition pcal9555_registers.hpp:69
constexpr uint32_t kDriveBitsPerPin
Bits per pin in the drive strength registers: pin n of a port uses bits 2(n%4)+1.....
Definition pcal9555_registers.hpp:59
constexpr uint8_t kPolarityPort0
Polarity inversion 0 (R/W); 0x05 is port 1.
Definition pcal9555_registers.hpp:36
constexpr uint8_t kOutputPort0
Output port 0 (R/W); 0x03 is port 1.
Definition pcal9555_registers.hpp:35
constexpr uint8_t kDriveStrength2
Drive strength 2 (R/W): P1_0-3; 0x43 P1_4-7.
Definition pcal9555_registers.hpp:41
constexpr uint16_t kPolarityReset
Polarity inversion: none.
Definition pcal9555_registers.hpp:65
constexpr uint8_t kInterruptMask0
Interrupt mask 0 (R/W): 1 = masked.
Definition pcal9555_registers.hpp:45
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition pcal9555_types.hpp:36
constexpr uint8_t kPinCount
Number of pins.
Definition pcal9555_types.hpp:245
Direction
Direction of a pin (configuration register: 1 = input).
Definition pcal9555_types.hpp:196
Pull
Pull resistor of a pin, PCAL9555A only (pull enable and selection registers).
Definition pcal9555_types.hpp:226
constexpr uint32_t DriveStrengthAll(DriveStrength level) noexcept
Drive strength codes with every pin at one level, in the layout of Config.
Definition pcal9555_types.hpp:283
DriveStrength
Output drive strength of a pin, PCAL9555A only (data sheet section 6.2.6).
Definition pcal9555_types.hpp:202
OutputMode
Output stage of a whole port, PCAL9555A only (output port configuration register).
Definition pcal9555_types.hpp:233
Verify
Whether a pin call reads back what it wrote, chosen per call (the last parameter of every pin and Agi...
Definition pcal9555_types.hpp:220
Bank
One of the two 8-pin ports.
Definition pcal9555_types.hpp:239
constexpr uint16_t PinMask(uint8_t pin) noexcept
The mask of one pin.
Definition pcal9555_types.hpp:261
@ Quarter
0.25 of the maximum drive.
@ Full
The maximum drive. Power-up value.
@ OpenDrain
Low-side transistor only; the pull resistors of the port are disconnected.
@ PushPull
Both transistors active. Power-up value.
@ Pcal9555a
PCAL9555A: also the Agile I/O bank at 0x40 to 0x4F.
@ None
Write only. Default.
The PCAL9555 driver: everything it declares lives here; internals in detail.
Definition pcal9555.hpp:26
constexpr uint8_t kI2cAddress
Definition pcal9555_i2c_interface.hpp:49
Compile-time helpers of the PCAL9555 driver: exact hook matching and enumeration checks.
The I2C port of the PCAL9555 driver: the bus requirements, the CRTP base, the I2cPort concept,...
PCA9555 / PCAL9555A register map: command bytes, fields and power-up defaults.
Public types of the PCAL9555 driver: errors, Result<T>, pins and configuration.
Everything EnsureInitialized() and ApplyConfig() write to the chip.
Definition pcal9555_types.hpp:302
Variant variant
Driver side: which part is fitted. The Agile I/O calls need Variant::Pcal9555a.
Definition pcal9555_types.hpp:304
uint16_t interrupt_mask
PCAL9555A: 1 = the pin raises no interrupt.
Definition pcal9555_types.hpp:315
uint16_t polarity_invert_mask
Polarity inversion: 1 = input reads inverted.
Definition pcal9555_types.hpp:307
OutputMode port1_mode
PCAL9555A: output stage of port 1 (ODEN1).
Definition pcal9555_types.hpp:317
OutputMode port0_mode
PCAL9555A: output stage of port 0 (ODEN0).
Definition pcal9555_types.hpp:316
uint16_t pull_enable_mask
PCAL9555A: 1 = pull resistor connected.
Definition pcal9555_types.hpp:313
uint16_t input_mask
Configuration: 1 = input, 0 = output. Power-up: inputs.
Definition pcal9555_types.hpp:308
uint16_t input_latch_mask
PCAL9555A: 1 = input change latched until read.
Definition pcal9555_types.hpp:312
uint16_t output_high_mask
Output ports: 1 = drive high. Power-up: all high.
Definition pcal9555_types.hpp:306
uint32_t drive_strength_codes
PCAL9555A: drive strength codes (DriveStrength), two bits per pin, pin n at bits 2n+1....
Definition pcal9555_types.hpp:311
uint16_t pull_up_mask
PCAL9555A: 1 = pull-up, 0 = pull-down.
Definition pcal9555_types.hpp:314
The value of a call, or why there is none.
Definition pcal9555_types.hpp:119