1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

Add more efficient SPI implementation (#622)

* Add more efficient SPI implementation

* Lint

* Add 200KHZ

* Updates

* Fix write_byte

* Update from datasheet

* Shift clock

* Fix calculation
This commit is contained in:
Otto Winter
2019-06-07 14:25:57 +02:00
committed by GitHub
parent 88ccd60a08
commit 726b0e73d9
14 changed files with 300 additions and 111 deletions

View File

@@ -155,7 +155,6 @@ void MAX7219Component::send_to_all_(uint8_t a_register, uint8_t data) {
this->send_byte_(a_register, data);
this->disable();
}
bool MAX7219Component::is_device_msb_first() { return true; }
void MAX7219Component::update() {
for (uint8_t i = 0; i < this->num_chips_ * 8; i++)
this->buffer_[i] = 0;

View File

@@ -16,7 +16,9 @@ class MAX7219Component;
using max7219_writer_t = std::function<void(MAX7219Component &)>;
class MAX7219Component : public PollingComponent, public spi::SPIDevice {
class MAX7219Component : public PollingComponent,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ> {
public:
void set_writer(max7219_writer_t &&writer);
@@ -54,7 +56,6 @@ class MAX7219Component : public PollingComponent, public spi::SPIDevice {
protected:
void send_byte_(uint8_t a_register, uint8_t data);
void send_to_all_(uint8_t a_register, uint8_t data);
bool is_device_msb_first() override;
uint8_t intensity_{15}; /// Intensity of the display from 0 to 15 (most)
uint8_t num_chips_{1};