56static const char *
const TAG =
"tm1651.display";
58static const bool LINE_HIGH =
true;
59static const bool LINE_LOW =
false;
62static const uint8_t CLOCK_CYCLE = 8;
64static const uint8_t HALF_CLOCK_CYCLE = CLOCK_CYCLE / 2;
65static const uint8_t QUARTER_CLOCK_CYCLE = CLOCK_CYCLE / 4;
67static const uint8_t ADDR_FIXED = 0x44;
68static const uint8_t ADDR_START = 0xC0;
70static const uint8_t DISPLAY_OFF = 0x80;
71static const uint8_t DISPLAY_ON = 0x88;
73static const uint8_t MAX_DISPLAY_LEVELS = 7;
75static const uint8_t PERCENT100 = 100;
76static const uint8_t PERCENT50 = 50;
78static const uint8_t TM1651_BRIGHTNESS_DARKEST = 0;
79static const uint8_t TM1651_BRIGHTNESS_TYPICAL = 2;
80static const uint8_t TM1651_BRIGHTNESS_BRIGHTEST = 7;
82static const uint8_t TM1651_LEVEL_TAB[] = {0b00000000, 0b00000001, 0b00000011, 0b00000111,
83 0b00001111, 0b00011111, 0b00111111, 0b01111111};
102 ESP_LOGCONFIG(TAG,
"Battery Display");
115 if (new_level > MAX_DISPLAY_LEVELS)
116 new_level = MAX_DISPLAY_LEVELS;
145 if (percentage > PERCENT100)
146 percentage = PERCENT100;
149 uint16_t initial_scaling = (percentage * MAX_DISPLAY_LEVELS) + PERCENT50;
150 return (uint8_t) (initial_scaling / PERCENT100);
165 if (new_brightness <= 1)
166 return TM1651_BRIGHTNESS_DARKEST;
167 if (new_brightness == 2)
168 return TM1651_BRIGHTNESS_TYPICAL;
171 return TM1651_BRIGHTNESS_BRIGHTEST;
184 for (uint8_t i = 0; i < 8; i++) {