PCA9685 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
pca9685_registers.hpp
Go to the documentation of this file.
1
16#ifndef PCA9685_REGISTERS_HPP
17#define PCA9685_REGISTERS_HPP
18
19#include <cstdint>
20
21#include "pca9685_detail.hpp"
22
24namespace pca9685::reg {
25
32inline constexpr uint8_t kMode1 = 0x00;
33inline constexpr uint8_t kMode2 = 0x01;
34inline constexpr uint8_t kSubAdr1 = 0x02;
35inline constexpr uint8_t kSubAdr2 = 0x03;
36inline constexpr uint8_t kSubAdr3 = 0x04;
37inline constexpr uint8_t kAllCallAdr = 0x05;
38inline constexpr uint8_t kLed0OnL = 0x06;
39inline constexpr uint8_t kLed15OffH = 0x45;
40inline constexpr uint8_t kAllLedOnL = 0xFA;
41inline constexpr uint8_t kAllLedOffH = 0xFD;
42inline constexpr uint8_t kPreScale = 0xFE;
43
45inline constexpr uint8_t kBytesPerChannel = 4;
47inline constexpr uint8_t kChannels = 16;
48
54[[nodiscard]] constexpr uint8_t ChannelBase(uint32_t channel) noexcept {
55 return static_cast<uint8_t>(uint32_t{kLed0OnL} +
56 (uint32_t{kBytesPerChannel} * (channel & 0x0FU)));
57}
58
60inline constexpr uint8_t kSubAdrReadOnly = 0x01;
62inline constexpr uint8_t kSubAdr1Reset = 0xE2;
63
64// MODE1 (table 5).
65inline constexpr uint8_t kMode1Restart = 1U << 7;
67inline constexpr uint8_t kMode1ExtClk = 1U << 6;
68inline constexpr uint8_t kMode1Ai = 1U << 5;
69inline constexpr uint8_t kMode1Sleep = 1U << 4;
70inline constexpr uint8_t kMode1Sub1 = 1U << 3;
71inline constexpr uint8_t kMode1Sub2 = 1U << 2;
72inline constexpr uint8_t kMode1Sub3 = 1U << 1;
73inline constexpr uint8_t kMode1AllCall = 1U << 0;
75inline constexpr uint8_t kMode1Reset = 0x11;
76
77// MODE2 (table 6).
78inline constexpr uint8_t kMode2Reserved = 0xE0;
79inline constexpr uint8_t kMode2Invrt = 1U << 4;
80inline constexpr uint8_t kMode2Och = 1U << 3;
81inline constexpr uint8_t kMode2OutDrv = 1U << 2;
83inline constexpr uint8_t kMode2Reset = 0x04;
85using Mode2Outne = detail::Field<uint8_t, 0U, 2U>;
86inline constexpr uint32_t kOutneLow = 0U;
87inline constexpr uint32_t kOutneHigh =
88 1U;
89inline constexpr uint32_t kOutneHiZ = 2U;
90
91// LEDn_ON_H and LEDn_OFF_H (table 7).
92inline constexpr uint8_t kLedHReserved = 0xE0;
93inline constexpr uint8_t kLedFull = 1U << 4;
94inline constexpr uint8_t kLedCountHigh = 0x0F;
96inline constexpr uint16_t kMaxCount = 4095;
98inline constexpr uint8_t kLedOffHReset = 0x10;
99
100// PRE_SCALE (table 8, section 7.3.5).
101inline constexpr uint8_t kPreScaleReset = 0x1E;
102inline constexpr uint8_t kPreScaleMin = 3;
103
104// The fields are the bits above, proved at build time (KB-CPP20-012).
105static_assert(Mode2Outne::kMask == 0x03U);
106static_assert(Mode2Outne::Insert(kMode2Reset, kOutneHiZ) == 0x06U);
107static_assert(ChannelBase(0U) == kLed0OnL);
108static_assert((ChannelBase(15U) + kBytesPerChannel - 1U) == kLed15OffH);
109static_assert(((kAllLedOffH - kAllLedOnL) + 1U) == kBytesPerChannel);
110static_assert(((kMode1Reset & kMode1Sleep) != 0U) && ((kMode1Reset & kMode1AllCall) != 0U) &&
111 ((kMode1Reset & kMode1Ai) == 0U));
112
115} // namespace pca9685::reg
116
117#endif // PCA9685_REGISTERS_HPP
constexpr uint8_t kMode2Reserved
Bits 7..5: reserved, read only, read 0.
Definition pca9685_registers.hpp:78
constexpr uint8_t kMode1Restart
Definition pca9685_registers.hpp:65
constexpr uint8_t kPreScaleReset
30: about 200 Hz from the 25 MHz oscillator.
Definition pca9685_registers.hpp:101
constexpr uint32_t kOutneHiZ
OUTNE = 10: LEDn = high impedance.
Definition pca9685_registers.hpp:89
constexpr uint8_t kMode1Ai
AI: register auto-increment.
Definition pca9685_registers.hpp:68
constexpr uint8_t kSubAdr2
SUBADR2 (R/W): I2C subaddress 2.
Definition pca9685_registers.hpp:35
constexpr uint8_t kSubAdr1
SUBADR1 (R/W): I2C subaddress 1 (section 7.3.6).
Definition pca9685_registers.hpp:34
constexpr uint8_t kMode1AllCall
Definition pca9685_registers.hpp:73
constexpr uint8_t kLedOffHReset
LEDn_OFF_H after a reset: full OFF (table 7). The other three bytes reset to 0.
Definition pca9685_registers.hpp:98
constexpr uint8_t kChannels
Number of LED channels.
Definition pca9685_registers.hpp:47
constexpr uint8_t kMode1Reset
MODE1 after a power-on or software reset: SLEEP and ALLCALL set (table 5).
Definition pca9685_registers.hpp:75
constexpr uint8_t kMode1Sleep
SLEEP: oscillator off, low-power mode.
Definition pca9685_registers.hpp:69
constexpr uint8_t kMode2
MODE2 (R/W): output inversion, change, drive, OE.
Definition pca9685_registers.hpp:33
constexpr uint8_t kSubAdrReadOnly
SUBADR1 to 3 and ALLCALLADR bit 0: read only, reads 0 (tables 9, 10).
Definition pca9685_registers.hpp:60
constexpr uint8_t kSubAdr1Reset
SUBADR1 after a reset (table 9).
Definition pca9685_registers.hpp:62
constexpr uint8_t kAllLedOffH
ALL_LED_OFF_H (W): loads every LEDn_OFF_H.
Definition pca9685_registers.hpp:41
constexpr uint8_t kMode2OutDrv
Definition pca9685_registers.hpp:81
constexpr uint8_t kMode1Sub3
SUB3: answer I2C subaddress 3.
Definition pca9685_registers.hpp:72
constexpr uint8_t kLed15OffH
LED15_OFF_H (R/W): the last channel byte.
Definition pca9685_registers.hpp:39
constexpr uint8_t kMode1Sub2
SUB2: answer I2C subaddress 2.
Definition pca9685_registers.hpp:71
constexpr uint8_t kBytesPerChannel
Bytes per channel: ON_L, ON_H, OFF_L, OFF_H (table 7).
Definition pca9685_registers.hpp:45
constexpr uint32_t kOutneLow
OUTNE = 00: LEDn = 0.
Definition pca9685_registers.hpp:86
constexpr uint16_t kMaxCount
Highest LEDn_ON and LEDn_OFF count: the 12-bit counter runs 0 to 4095 (section 7.3....
Definition pca9685_registers.hpp:96
constexpr uint8_t kLedHReserved
Bits 7..5 of the _H bytes: read only, read 0.
Definition pca9685_registers.hpp:92
constexpr uint8_t ChannelBase(uint32_t channel) noexcept
The address of LEDn_ON_L of a channel (table 4).
Definition pca9685_registers.hpp:54
constexpr uint8_t kAllCallAdr
ALLCALLADR (R/W): LED All Call address (7.3.7).
Definition pca9685_registers.hpp:37
constexpr uint8_t kMode2Och
OCH: outputs change on ACK, not on STOP.
Definition pca9685_registers.hpp:80
constexpr uint8_t kLedFull
Bit 4: full ON (ON_H) or full OFF (OFF_H).
Definition pca9685_registers.hpp:93
constexpr uint8_t kMode1
MODE1 (R/W): restart, clock, AI, sleep, group calls.
Definition pca9685_registers.hpp:32
constexpr uint8_t kMode2Reset
MODE2 after a reset: change on STOP, totem pole, not inverted, LEDn = 0 when OE = 1.
Definition pca9685_registers.hpp:83
constexpr uint8_t kMode2Invrt
INVRT: output logic inverted (OE = 0 only).
Definition pca9685_registers.hpp:79
constexpr uint8_t kPreScaleMin
The hardware forces at least 3 (1526 Hz).
Definition pca9685_registers.hpp:102
constexpr uint8_t kMode1ExtClk
EXTCLK: use the EXTCLK pin; sticky.
Definition pca9685_registers.hpp:67
constexpr uint32_t kOutneHigh
OUTNE = 01: LEDn = 1 (totem pole), Hi-Z (open drain).
Definition pca9685_registers.hpp:87
constexpr uint8_t kSubAdr3
SUBADR3 (R/W): I2C subaddress 3.
Definition pca9685_registers.hpp:36
constexpr uint8_t kLedCountHigh
Definition pca9685_registers.hpp:94
detail::Field< uint8_t, 0U, 2U > Mode2Outne
MODE2.OUTNE[1:0], the level of every output while OE is high (table 11).
Definition pca9685_registers.hpp:85
constexpr uint8_t kLed0OnL
LED0_ON_L (R/W): first of 16 x 4 channel bytes.
Definition pca9685_registers.hpp:38
constexpr uint8_t kMode1Sub1
SUB1: answer I2C subaddress 1.
Definition pca9685_registers.hpp:70
constexpr uint8_t kPreScale
PRE_SCALE (R/W): PWM frequency; written in SLEEP.
Definition pca9685_registers.hpp:42
constexpr uint8_t kAllLedOnL
ALL_LED_ON_L (W): loads every LEDn_ON_L (7.3.4).
Definition pca9685_registers.hpp:40
The PCA9685 register map.
Definition pca9685_registers.hpp:24
Compile-time helpers of the PCA9685 driver: typed integer literals, exact hook matching,...