PCAL9555 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
pcal9555_registers.hpp
Go to the documentation of this file.
1
19#ifndef PCAL9555_REGISTERS_HPP
20#define PCAL9555_REGISTERS_HPP
21
22#include <cstdint>
23
25namespace pcal9555::reg {
26
33// Both parts: four register pairs.
34inline constexpr uint8_t kInputPort0 = 0x00;
35inline constexpr uint8_t kOutputPort0 = 0x02;
36inline constexpr uint8_t kPolarityPort0 = 0x04;
37inline constexpr uint8_t kConfigPort0 = 0x06;
38
39// PCAL9555A only: the Agile I/O bank.
40inline constexpr uint8_t kDriveStrength0 = 0x40;
41inline constexpr uint8_t kDriveStrength2 = 0x42;
42inline constexpr uint8_t kInputLatch0 = 0x44;
43inline constexpr uint8_t kPullEnable0 = 0x46;
44inline constexpr uint8_t kPullSelect0 = 0x48;
45inline constexpr uint8_t kInterruptMask0 = 0x4A;
46inline constexpr uint8_t kInterruptStatus0 = 0x4C;
47inline constexpr uint8_t kOutputPortConfig = 0x4F;
48
49inline constexpr uint8_t kOutputConfigOden0 = 1U << 0;
50inline constexpr uint8_t kOutputConfigOden1 = 1U << 1;
54inline constexpr uint16_t kIdentityPattern = 0x55AA;
56inline constexpr uint8_t kOutputConfigReservedMask = 0xFC;
57
59inline constexpr uint32_t kDriveBitsPerPin = 2U;
61inline constexpr uint32_t kDriveCodeMask = 0x3;
62
63// Power-up defaults (PCAL9555A table 4; the PCA9555 has the same first three).
64inline constexpr uint16_t kOutputReset = 0xFFFF;
65inline constexpr uint16_t kPolarityReset = 0x0000;
66inline constexpr uint16_t kConfigReset = 0xFFFF;
68inline constexpr uint32_t kDriveStrengthReset = 0xFFFF'FFFFU;
69inline constexpr uint16_t kInputLatchReset = 0x0000;
70inline constexpr uint16_t kPullEnableReset = 0xFFFF;
71inline constexpr uint16_t kPullSelectReset = 0xFFFF;
72inline constexpr uint16_t kInterruptMaskReset = 0xFFFF;
73inline constexpr uint8_t kOutputPortConfigReset = 0x00;
74
83[[nodiscard]] constexpr bool IsImplemented(uint8_t command, bool agile) noexcept {
84 const auto c = static_cast<uint32_t>(command);
85 if (c <= (static_cast<uint32_t>(kConfigPort0) + 1U)) {
86 return true;
87 }
88 return agile && (((c >= static_cast<uint32_t>(kDriveStrength0)) &&
89 (c <= (static_cast<uint32_t>(kInterruptStatus0) + 1U))) ||
90 (c == static_cast<uint32_t>(kOutputPortConfig)));
91}
92
93static_assert(IsImplemented(uint8_t{0x07}, false) && !IsImplemented(kDriveStrength0, false));
94static_assert(IsImplemented(uint8_t{0x4D}, true) && !IsImplemented(uint8_t{0x4E}, true) &&
95 IsImplemented(kOutputPortConfig, true) && !IsImplemented(uint8_t{0x08}, true));
96
99} // namespace pcal9555::reg
100
101#endif // PCAL9555_REGISTERS_HPP
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 kIdentityPattern
Definition pcal9555_registers.hpp:54
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 uint8_t kOutputConfigReservedMask
0x4F bits 7..2 are reserved and read 0 (PCAL9555A table 27).
Definition pcal9555_registers.hpp:56
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 kInterruptStatus0
Interrupt status 0 (R); 0x4D is port 1.
Definition pcal9555_registers.hpp:46
constexpr uint8_t kInterruptMask0
Interrupt mask 0 (R/W): 1 = masked.
Definition pcal9555_registers.hpp:45
The PCA9555 / PCAL9555A register map.
Definition pcal9555_registers.hpp:25