ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
max6956.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7namespace esphome::max6956 {
8
16
18enum MAX6956GPIORange : uint8_t {
21};
22
28 MAX6956_PORT_CONFIG_START = 0x09, // Port Configuration P7, P6, P5, P4
29 MAX6956_CURRENT_START = 0x12, // Current054
30 MAX6956_1PORT_VALUE_START = 0x20, // Port 0 only (virtual port, no action)
31 MAX6956_8PORTS_VALUE_START = 0x44, // 8 ports 4-11 (data bits D0-D7)
32};
33
34enum MAX6956GPIOFlag { FLAG_LED = 0x20 };
35
36enum MAX6956CURRENTMODE { GLOBAL = 0x00, SEGMENT = 0x01 };
37
38class MAX6956 : public Component, public i2c::I2CDevice {
39 public:
40 MAX6956() = default;
41
42 void setup() override;
43
44 bool digital_read(uint8_t pin);
45 void digital_write(uint8_t pin, bool value);
46 void pin_mode(uint8_t pin, gpio::Flags flags);
47 void pin_mode(uint8_t pin, max6956::MAX6956GPIOFlag flags);
48
49 float get_setup_priority() const override { return setup_priority::HARDWARE; }
50
51 void set_brightness_global(uint8_t current);
53 void set_pin_brightness(uint8_t pin, float brightness);
54
55 void dump_config() override;
56
59
60 protected:
61 // read a given register
62 bool read_reg_(uint8_t reg, uint8_t *value);
63 // write a value to a given register
64 bool write_reg_(uint8_t reg, uint8_t value);
67
68 private:
69 int8_t prev_bright_[28] = {0};
70};
71
72class MAX6956GPIOPin : public GPIOPin {
73 public:
74 void setup() override;
75 void pin_mode(gpio::Flags flags) override;
76 bool digital_read() override;
77 void digital_write(bool value) override;
78 size_t dump_summary(char *buffer, size_t len) const override;
79
80 void set_parent(MAX6956 *parent) { parent_ = parent; }
81 void set_pin(uint8_t pin) { pin_ = pin; }
82 void set_inverted(bool inverted) { inverted_ = inverted; }
84
85 gpio::Flags get_flags() const override { return this->flags_; }
86
87 protected:
89 uint8_t pin_;
92};
93
94} // namespace esphome::max6956
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:152
gpio::Flags get_flags() const override
Definition max6956.h:85
size_t dump_summary(char *buffer, size_t len) const override
Definition max6956.cpp:165
void digital_write(bool value) override
Definition max6956.cpp:164
void set_flags(gpio::Flags flags)
Definition max6956.h:83
void set_pin(uint8_t pin)
Definition max6956.h:81
void pin_mode(gpio::Flags flags) override
Definition max6956.cpp:162
void set_inverted(bool inverted)
Definition max6956.h:82
void set_parent(MAX6956 *parent)
Definition max6956.h:80
float get_setup_priority() const override
Definition max6956.h:49
bool read_reg_(uint8_t reg, uint8_t *value)
Definition max6956.cpp:131
void digital_write(uint8_t pin, bool value)
Definition max6956.cpp:49
void set_brightness_global(uint8_t current)
Definition max6956.cpp:90
void dump_config() override
Definition max6956.cpp:145
bool digital_read(uint8_t pin)
Definition max6956.cpp:42
void set_pin_brightness(uint8_t pin, float brightness)
Definition max6956.cpp:112
max6956::MAX6956CURRENTMODE brightness_mode_
Definition max6956.h:65
void setup() override
Definition max6956.cpp:21
void pin_mode(uint8_t pin, gpio::Flags flags)
Definition max6956.cpp:54
bool write_reg_(uint8_t reg, uint8_t value)
Definition max6956.cpp:138
void set_brightness_mode(max6956::MAX6956CURRENTMODE brightness_mode)
Definition max6956.cpp:100
uint16_t flags
@ MAX6956_8PORTS_VALUE_START
Definition max6956.h:31
@ MAX6956_TRANSITION_DETECT_MASK
Definition max6956.h:26
@ MAX6956_GLOBAL_CURRENT
Definition max6956.h:24
@ MAX6956_CONFIGURATION
Definition max6956.h:25
@ MAX6956_1PORT_VALUE_START
Definition max6956.h:30
@ MAX6956_PORT_CONFIG_START
Definition max6956.h:28
@ MAX6956_CURRENT_START
Definition max6956.h:29
MAX6956GPIORange
Range for MAX6956 pins.
Definition max6956.h:18
MAX6956GPIOMode
Modes for MAX6956 pins.
Definition max6956.h:10
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.h:41
const void size_t len
Definition hal.h:64