mirror of
https://github.com/esphome/esphome.git
synced 2025-10-29 22:24:26 +00:00
Partially revert make SPI CS pin optional (#1187)
This commit is contained in:
@@ -34,15 +34,15 @@ def to_code(config):
|
||||
cg.add(var.set_mosi(mosi))
|
||||
|
||||
|
||||
def spi_device_schema(CS_PIN_required=False):
|
||||
def spi_device_schema(cs_pin_required=True):
|
||||
"""Create a schema for an SPI device.
|
||||
:param CS_PIN_required: If true, make the CS_PIN required in the config.
|
||||
:param cs_pin_required: If true, make the CS_PIN required in the config.
|
||||
:return: The SPI device schema, `extend` this in your config schema.
|
||||
"""
|
||||
schema = {
|
||||
cv.GenerateID(CONF_SPI_ID): cv.use_id(SPIComponent),
|
||||
}
|
||||
if CS_PIN_required:
|
||||
if cs_pin_required:
|
||||
schema[cv.Required(CONF_CS_PIN)] = pins.gpio_output_pin_schema
|
||||
else:
|
||||
schema[cv.Optional(CONF_CS_PIN)] = pins.gpio_output_pin_schema
|
||||
|
||||
@@ -127,18 +127,20 @@ class SPIComponent : public Component {
|
||||
|
||||
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, uint32_t DATA_RATE>
|
||||
void enable(GPIOPin *cs) {
|
||||
if (cs) {
|
||||
if (cs != nullptr) {
|
||||
SPIComponent::debug_enable(cs->get_pin());
|
||||
}
|
||||
|
||||
if (this->hw_spi_ != nullptr) {
|
||||
uint8_t data_mode = (uint8_t(CLOCK_POLARITY) << 1) | uint8_t(CLOCK_PHASE);
|
||||
SPISettings settings(DATA_RATE, BIT_ORDER, data_mode);
|
||||
this->hw_spi_->beginTransaction(settings);
|
||||
} else {
|
||||
this->clk_->digital_write(CLOCK_POLARITY);
|
||||
this->wait_cycle_ = uint32_t(F_CPU) / DATA_RATE / 2ULL;
|
||||
}
|
||||
if (this->hw_spi_ != nullptr) {
|
||||
uint8_t data_mode = (uint8_t(CLOCK_POLARITY) << 1) | uint8_t(CLOCK_PHASE);
|
||||
SPISettings settings(DATA_RATE, BIT_ORDER, data_mode);
|
||||
this->hw_spi_->beginTransaction(settings);
|
||||
} else {
|
||||
this->clk_->digital_write(CLOCK_POLARITY);
|
||||
this->wait_cycle_ = uint32_t(F_CPU) / DATA_RATE / 2ULL;
|
||||
}
|
||||
|
||||
if (cs != nullptr) {
|
||||
this->active_cs_ = cs;
|
||||
this->active_cs_->digital_write(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user