Fix SPI inverted clock on ESP8266 (#5416)

This commit is contained in:
Clyde Stubbs 2023-09-22 14:15:50 +10:00 committed by Jesse Hills
parent 55e36ab982
commit b07a038bc8
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A
2 changed files with 7 additions and 4 deletions

View file

@ -351,6 +351,7 @@ class SPIClient {
: bit_order_(bit_order), mode_(mode), data_rate_(data_rate) {} : bit_order_(bit_order), mode_(mode), data_rate_(data_rate) {}
virtual void spi_setup() { virtual void spi_setup() {
esph_log_d("spi_device", "mode %u, data_rate %ukHz", (unsigned) this->mode_, (unsigned) (this->data_rate_ / 1000));
this->delegate_ = this->parent_->register_device(this, this->mode_, this->bit_order_, this->data_rate_, this->cs_); this->delegate_ = this->parent_->register_device(this, this->mode_, this->bit_order_, this->data_rate_, this->cs_);
} }
@ -398,10 +399,7 @@ class SPIDevice : public SPIClient {
void set_data_rate(uint32_t data_rate) { this->data_rate_ = data_rate; } void set_data_rate(uint32_t data_rate) { this->data_rate_ = data_rate; }
void set_bit_order(SPIBitOrder order) { void set_bit_order(SPIBitOrder order) { this->bit_order_ = order; }
this->bit_order_ = order;
esph_log_d("spi.h", "bit order set to %d", order);
}
void set_mode(SPIMode mode) { this->mode_ = mode; } void set_mode(SPIMode mode) { this->mode_ = mode; }

View file

@ -15,6 +15,11 @@ class SPIDelegateHw : public SPIDelegate {
void begin_transaction() override { void begin_transaction() override {
#ifdef USE_RP2040 #ifdef USE_RP2040
SPISettings const settings(this->data_rate_, static_cast<BitOrder>(this->bit_order_), this->mode_); SPISettings const settings(this->data_rate_, static_cast<BitOrder>(this->bit_order_), this->mode_);
#elif defined(ESP8266)
// Arduino ESP8266 library has mangled values for SPI modes :-(
auto mode = (this->mode_ & 0x01) + ((this->mode_ & 0x02) << 3);
ESP_LOGV(TAG, "8266 mangled SPI mode 0x%X", mode);
SPISettings const settings(this->data_rate_, this->bit_order_, mode);
#else #else
SPISettings const settings(this->data_rate_, this->bit_order_, this->mode_); SPISettings const settings(this->data_rate_, this->bit_order_, this->mode_);
#endif #endif