57static const char *
const TAG =
"tm1651.display";
59static const bool LINE_HIGH =
true;
60static const bool LINE_LOW =
false;
63static const uint8_t CLOCK_CYCLE = 8;
65static const uint8_t HALF_CLOCK_CYCLE = CLOCK_CYCLE / 2;
66static const uint8_t QUARTER_CLOCK_CYCLE = CLOCK_CYCLE / 4;
68static const uint8_t ADDR_FIXED = 0x44;
69static const uint8_t ADDR_START = 0xC0;
71static const uint8_t DISPLAY_OFF = 0x80;
72static const uint8_t DISPLAY_ON = 0x88;
74static const uint8_t MAX_DISPLAY_LEVELS = 7;
76static const uint8_t PERCENT100 = 100;
77static const uint8_t PERCENT50 = 50;
79static const uint8_t TM1651_BRIGHTNESS_DARKEST = 0;
80static const uint8_t TM1651_BRIGHTNESS_TYPICAL = 2;
81static const uint8_t TM1651_BRIGHTNESS_BRIGHTEST = 7;
83static const uint8_t TM1651_LEVEL_TAB[] = {0b00000000, 0b00000001, 0b00000011, 0b00000111,
84 0b00001111, 0b00011111, 0b00111111, 0b01111111};
103 ESP_LOGCONFIG(TAG,
"Battery Display");
116 if (new_level > MAX_DISPLAY_LEVELS)
117 new_level = MAX_DISPLAY_LEVELS;
146 if (percentage > PERCENT100)
147 percentage = PERCENT100;
150 uint16_t initial_scaling = (percentage * MAX_DISPLAY_LEVELS) + PERCENT50;
151 return (uint8_t) (initial_scaling / PERCENT100);
166 if (new_brightness <= 1)
167 return TM1651_BRIGHTNESS_DARKEST;
168 if (new_brightness == 2)
169 return TM1651_BRIGHTNESS_TYPICAL;
172 return TM1651_BRIGHTNESS_BRIGHTEST;
185 for (uint8_t i = 0; i < 8; i++) {
virtual void pin_mode(gpio::Flags flags)=0
virtual void digital_write(bool value)=0
virtual bool digital_read()=0
InternalGPIOPin * clk_pin_
void update_brightness_(uint8_t on_off_control)
bool half_cycle_clock_high_ack_()
void set_level_percent(uint8_t percentage)
void set_brightness(uint8_t new_brightness)
void delineate_transmission_(bool dio_state)
void half_cycle_clock_high_()
uint8_t calculate_level_(uint8_t percentage)
bool write_byte_(uint8_t data)
uint8_t remap_brightness_(uint8_t new_brightness)
void half_cycle_clock_low_(bool data_bit)
InternalGPIOPin * dio_pin_
void set_level(uint8_t new_level)
void dump_config() override
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)