intermediate flexible

This commit is contained in:
Patrick Moessler 2024-01-23 21:33:46 +01:00
parent d59dadce77
commit a2cc74c626
4 changed files with 20 additions and 7 deletions

View file

@ -12,6 +12,7 @@ SPI_74HC595_DISPLAYComponent = spi_74hc595_display_ns.class_(
SPI_74HC595_DISPLAYComponentRef = SPI_74HC595_DISPLAYComponent.operator("ref") SPI_74HC595_DISPLAYComponentRef = SPI_74HC595_DISPLAYComponent.operator("ref")
CONF_REVERSE = "reverse" CONF_REVERSE = "reverse"
CONF_REVERSE_CHAIN = "reverse_chain"
CONF_SEGMENT_FIRST = "segment_first" CONF_SEGMENT_FIRST = "segment_first"
CONF_COMMON_CATHODE = "common_cathode" CONF_COMMON_CATHODE = "common_cathode"
@ -21,7 +22,8 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(SPI_74HC595_DISPLAYComponent), cv.GenerateID(): cv.declare_id(SPI_74HC595_DISPLAYComponent),
cv.Optional(CONF_NUM_CHIPS, default=1): cv.int_range(min=1, max=255), cv.Optional(CONF_NUM_CHIPS, default=1): cv.int_range(min=1, max=255),
cv.Optional(CONF_REVERSE, default=False): cv.boolean, cv.Optional(CONF_REVERSE, default=False): cv.boolean,
cv.Optional(CONF_SEGMENT_FIRST, default=False): cv.boolean, cv.Optional(CONF_REVERSE_CHAIN, default=False): cv.boolean,
cv.Optional(CONF_SEGMENT_FIRST, default=True): cv.boolean,
cv.Optional(CONF_COMMON_CATHODE, default=False): cv.boolean, cv.Optional(CONF_COMMON_CATHODE, default=False): cv.boolean,
} }
) )
@ -37,6 +39,7 @@ async def to_code(config):
cg.add(var.set_num_chips(config[CONF_NUM_CHIPS])) cg.add(var.set_num_chips(config[CONF_NUM_CHIPS]))
cg.add(var.set_reverse(config[CONF_REVERSE])) cg.add(var.set_reverse(config[CONF_REVERSE]))
cg.add(var.set_reverse_chain(config[CONF_REVERSE_CHAIN]))
cg.add(var.set_segment_first(config[CONF_SEGMENT_FIRST])) cg.add(var.set_segment_first(config[CONF_SEGMENT_FIRST]))
cg.add(var.set_common_cathode(config[CONF_COMMON_CATHODE])) cg.add(var.set_common_cathode(config[CONF_COMMON_CATHODE]))

View file

@ -116,8 +116,14 @@ void SPI_74HC595_DISPLAYComponent::setup() {
this->spi_setup(); this->spi_setup();
this->buffer_ = new uint8_t[this->num_chips_ * 8]; // NOLINT this->buffer_ = new uint8_t[this->num_chips_ * 8]; // NOLINT
for (uint8_t i = 0; i < this->num_chips_ * 8; i++) for (uint8_t i = 0; i < this->num_chips_ * 8; i++)
{
this->buffer_[i] = 0; this->buffer_[i] = 0;
} }
if (this->common_cathode_){
this->flip_digit_=0xff;
this->flip_segment_= ~this->flip_digit;
}
}
void SPI_74HC595_DISPLAYComponent::dump_config() { void SPI_74HC595_DISPLAYComponent::dump_config() {
ESP_LOGCONFIG(TAG, "SPI_74HC595_DISPLAY:"); ESP_LOGCONFIG(TAG, "SPI_74HC595_DISPLAY:");
@ -128,8 +134,6 @@ void SPI_74HC595_DISPLAYComponent::dump_config() {
void SPI_74HC595_DISPLAYComponent::display() { void SPI_74HC595_DISPLAYComponent::display() {
uint32_t delay = static_cast<uint64_t>(this->get_update_interval())*1000 / 8; uint32_t delay = static_cast<uint64_t>(this->get_update_interval())*1000 / 8;
uint8_t flip_digit=(this->common_cathode_)?0xFF:0x00;
uint8_t flip_segment = ~flip_digit;
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
this->enable(); this->enable();
for (uint8_t j = 0; j < this->num_chips_; j++) { for (uint8_t j = 0; j < this->num_chips_; j++) {

View file

@ -56,9 +56,15 @@ class SPI_74HC595_DISPLAYComponent : public PollingComponent,
uint8_t num_chips_{1}; uint8_t num_chips_{1};
uint8_t *buffer_; uint8_t *buffer_;
bool reverse_{false}; bool reverse_{false};
bool segment_first_{false}; bool reverse_chain_{false};
bool segment_first_{true};
bool common_cathode_{false}; bool common_cathode_{false};
optional<spi_74hc595_display_writer_t> writer_{}; optional<spi_74hc595_display_writer_t> writer_{};
uint8_t flip_digit_{0};
uint8_t flip_segment_{0xFF};
uint8_t digit_mask[8]{0x08,0x04,0x02,0x01,0x80,0x40,0x20,0x10};
}; };
} // namespace spi_74hc595_display } // namespace spi_74hc595_display

View file

@ -71,9 +71,9 @@ display:
data_rate: 1MHz #10MHz data_rate: 1MHz #10MHz
num_chips: 1 #3 num_chips: 1 #3
update_interval: 4s #16ms update_interval: 4s #16ms
common_cathode: false # common_cathode: false
segment_first: false # segment_first: true
reverse: false # reverse: false
lambda: |- lambda: |-
static uint32_t clock_frames=0; static uint32_t clock_frames=0;
static uint32_t old_clock=0; static uint32_t old_clock=0;