ESPHome 2025.5.0
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 {
8namespace max6956 {
9
17
19enum MAX6956GPIORange : uint8_t {
22};
23
29 MAX6956_PORT_CONFIG_START = 0x09, // Port Configuration P7, P6, P5, P4
30 MAX6956_CURRENT_START = 0x12, // Current054
31 MAX6956_1PORT_VALUE_START = 0x20, // Port 0 only (virtual port, no action)
32 MAX6956_8PORTS_VALUE_START = 0x44, // 8 ports 4-11 (data bits D0-D7)
33};
34
35enum MAX6956GPIOFlag { FLAG_LED = 0x20 };
36
37enum MAX6956CURRENTMODE { GLOBAL = 0x00, SEGMENT = 0x01 };
38
39class MAX6956 : public Component, public i2c::I2CDevice {
40 public:
41 MAX6956() = default;
42
43 void setup() override;
44
45 bool digital_read(uint8_t pin);
46 void digital_write(uint8_t pin, bool value);
47 void pin_mode(uint8_t pin, gpio::Flags flags);
48 void pin_mode(uint8_t pin, max6956::MAX6956GPIOFlag flags);
49
50 float get_setup_priority() const override { return setup_priority::HARDWARE; }
51
52 void set_brightness_global(uint8_t current);
54 void set_pin_brightness(uint8_t pin, float brightness);
55
56 void dump_config() override;
57
60
61 protected:
62 // read a given register
63 bool read_reg_(uint8_t reg, uint8_t *value);
64 // write a value to a given register
65 bool write_reg_(uint8_t reg, uint8_t value);
68
69 private:
70 int8_t prev_bright_[28] = {0};
71};
72
73class MAX6956GPIOPin : public GPIOPin {
74 public:
75 void setup() override;
76 void pin_mode(gpio::Flags flags) override;
77 bool digital_read() override;
78 void digital_write(bool value) override;
79 std::string dump_summary() const override;
80
81 void set_parent(MAX6956 *parent) { parent_ = parent; }
82 void set_pin(uint8_t pin) { pin_ = pin; }
83 void set_inverted(bool inverted) { inverted_ = inverted; }
84 void set_flags(gpio::Flags flags) { flags_ = flags; }
85
86 gpio::Flags get_flags() const override { return this->flags_; }
87
88 protected:
90 uint8_t pin_;
93};
94
95} // namespace max6956
96} // namespace esphome
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:153
gpio::Flags get_flags() const override
Definition max6956.h:86
std::string dump_summary() const override
Definition max6956.cpp:163
void digital_write(bool value) override
Definition max6956.cpp:162
void set_flags(gpio::Flags flags)
Definition max6956.h:84
void set_pin(uint8_t pin)
Definition max6956.h:82
void pin_mode(gpio::Flags flags) override
Definition max6956.cpp:160
void set_inverted(bool inverted)
Definition max6956.h:83
void set_parent(MAX6956 *parent)
Definition max6956.h:81
float get_setup_priority() const override
Definition max6956.h:50
bool read_reg_(uint8_t reg, uint8_t *value)
Definition max6956.cpp:131
void digital_write(uint8_t pin, bool value)
Definition max6956.cpp:51
void set_brightness_global(uint8_t current)
Definition max6956.cpp:92
void dump_config() override
Definition max6956.cpp:145
bool digital_read(uint8_t pin)
Definition max6956.cpp:44
void set_pin_brightness(uint8_t pin, float brightness)
Definition max6956.cpp:114
max6956::MAX6956CURRENTMODE brightness_mode_
Definition max6956.h:66
void setup() override
Definition max6956.cpp:22
void pin_mode(uint8_t pin, gpio::Flags flags)
Definition max6956.cpp:56
bool write_reg_(uint8_t reg, uint8_t value)
Definition max6956.cpp:138
void set_brightness_mode(max6956::MAX6956CURRENTMODE brightness_mode)
Definition max6956.cpp:102
@ MAX6956_8PORTS_VALUE_START
Definition max6956.h:32
@ MAX6956_TRANSITION_DETECT_MASK
Definition max6956.h:27
@ MAX6956_GLOBAL_CURRENT
Definition max6956.h:25
@ MAX6956_CONFIGURATION
Definition max6956.h:26
@ MAX6956_1PORT_VALUE_START
Definition max6956.h:31
@ MAX6956_PORT_CONFIG_START
Definition max6956.h:29
@ MAX6956_CURRENT_START
Definition max6956.h:30
MAX6956GPIORange
Range for MAX6956 pins.
Definition max6956.h:19
MAX6956GPIOMode
Modes for MAX6956 pins.
Definition max6956.h:11
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:18
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7