ESPHome  2024.3.2
max6956.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace max6956 {
9 
11 enum MAX6956GPIOMode : uint8_t {
12  MAX6956_LED = 0x00,
14  MAX6956_INPUT = 0x02,
16 };
17 
19 enum 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 
35 enum MAX6956GPIOFlag { FLAG_LED = 0x20 };
36 
37 enum MAX6956CURRENTMODE { GLOBAL = 0x00, SEGMENT = 0x01 };
38 
39 class 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 
59  void write_brightness_mode();
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 
73 class 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  protected:
88  uint8_t pin_;
89  bool inverted_;
91 };
92 
93 } // namespace max6956
94 } // namespace esphome
MAX6956GPIORange
Range for MAX6956 pins.
Definition: max6956.h:19
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition: i2c.h:149
max6956::MAX6956CURRENTMODE brightness_mode_
Definition: max6956.h:66
void pin_mode(uint8_t pin, gpio::Flags flags)
Definition: max6956.cpp:56
void dump_config() override
Definition: max6956.cpp:145
void set_inverted(bool inverted)
Definition: max6956.h:83
MAX6956GPIOMode
Modes for MAX6956 pins.
Definition: max6956.h:11
void set_brightness_mode(max6956::MAX6956CURRENTMODE brightness_mode)
Definition: max6956.cpp:102
bool digital_read(uint8_t pin)
Definition: max6956.cpp:44
void digital_write(uint8_t pin, bool value)
Definition: max6956.cpp:51
bool write_reg_(uint8_t reg, uint8_t value)
Definition: max6956.cpp:138
void set_flags(gpio::Flags flags)
Definition: max6956.h:84
void setup() override
Definition: max6956.cpp:22
const uint32_t flags
Definition: stm32flash.h:85
void set_brightness_global(uint8_t current)
Definition: max6956.cpp:92
void set_parent(MAX6956 *parent)
Definition: max6956.h:81
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
bool read_reg_(uint8_t reg, uint8_t *value)
Definition: max6956.cpp:131
float get_setup_priority() const override
Definition: max6956.h:50
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
uint8_t global_brightness_
Definition: max6956.h:67
void set_pin_brightness(uint8_t pin, float brightness)
Definition: max6956.cpp:114
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
void set_pin(uint8_t pin)
Definition: max6956.h:82