mirror of
https://github.com/esphome/esphome.git
synced 2024-12-01 19:24:14 +01:00
Partially revert make SPI CS pin optional (#1187)
This commit is contained in:
parent
62468198d6
commit
275c12150e
7 changed files with 19 additions and 18 deletions
|
@ -11,7 +11,7 @@ SPIAS3935 = as3935_spi_ns.class_('SPIAS3935Component', as3935.AS3935, spi.SPIDev
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.All(as3935.AS3935_SCHEMA.extend({
|
CONFIG_SCHEMA = cv.All(as3935.AS3935_SCHEMA.extend({
|
||||||
cv.GenerateID(): cv.declare_id(SPIAS3935),
|
cv.GenerateID(): cv.declare_id(SPIAS3935),
|
||||||
}).extend(cv.COMPONENT_SCHEMA).extend(spi.spi_device_schema(CS_PIN_required=True)))
|
}).extend(cv.COMPONENT_SCHEMA).extend(spi.spi_device_schema(cs_pin_required=True)))
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
|
|
|
@ -39,7 +39,7 @@ CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend({
|
||||||
cv.Optional(CONF_SCROLL_SPEED, default='250ms'): cv.positive_time_period_milliseconds,
|
cv.Optional(CONF_SCROLL_SPEED, default='250ms'): cv.positive_time_period_milliseconds,
|
||||||
cv.Optional(CONF_SCROLL_DELAY, default='1000ms'): cv.positive_time_period_milliseconds,
|
cv.Optional(CONF_SCROLL_DELAY, default='1000ms'): cv.positive_time_period_milliseconds,
|
||||||
cv.Optional(CONF_SCROLL_DWELL, default='1000ms'): cv.positive_time_period_milliseconds,
|
cv.Optional(CONF_SCROLL_DWELL, default='1000ms'): cv.positive_time_period_milliseconds,
|
||||||
}).extend(cv.polling_component_schema('500ms')).extend(spi.spi_device_schema(CS_PIN_required=True))
|
}).extend(cv.polling_component_schema('500ms')).extend(spi.spi_device_schema(cs_pin_required=True))
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
|
|
|
@ -14,7 +14,7 @@ MCP3008 = mcp3008_ns.class_('MCP3008', cg.Component, spi.SPIDevice)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.Schema({
|
CONFIG_SCHEMA = cv.Schema({
|
||||||
cv.GenerateID(): cv.declare_id(MCP3008),
|
cv.GenerateID(): cv.declare_id(MCP3008),
|
||||||
}).extend(spi.spi_device_schema(CS_PIN_required=True))
|
}).extend(spi.spi_device_schema(cs_pin_required=True))
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
|
|
|
@ -31,7 +31,6 @@ void PN532::setup() {
|
||||||
// (this may time out, but that's ok)
|
// (this may time out, but that's ok)
|
||||||
// 3. Send SAM config command with normal mode without waiting for ready bit (IRQ not initialized yet)
|
// 3. Send SAM config command with normal mode without waiting for ready bit (IRQ not initialized yet)
|
||||||
// 4. Probably optional, send SAM config again, this time checking ACK and return value
|
// 4. Probably optional, send SAM config again, this time checking ACK and return value
|
||||||
if (this->cs_)
|
|
||||||
this->cs_->digital_write(false);
|
this->cs_->digital_write(false);
|
||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
|
|
|
@ -34,15 +34,15 @@ def to_code(config):
|
||||||
cg.add(var.set_mosi(mosi))
|
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.
|
"""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.
|
:return: The SPI device schema, `extend` this in your config schema.
|
||||||
"""
|
"""
|
||||||
schema = {
|
schema = {
|
||||||
cv.GenerateID(CONF_SPI_ID): cv.use_id(SPIComponent),
|
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
|
schema[cv.Required(CONF_CS_PIN)] = pins.gpio_output_pin_schema
|
||||||
else:
|
else:
|
||||||
schema[cv.Optional(CONF_CS_PIN)] = pins.gpio_output_pin_schema
|
schema[cv.Optional(CONF_CS_PIN)] = pins.gpio_output_pin_schema
|
||||||
|
|
|
@ -127,8 +127,9 @@ class SPIComponent : public Component {
|
||||||
|
|
||||||
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, uint32_t DATA_RATE>
|
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, uint32_t DATA_RATE>
|
||||||
void enable(GPIOPin *cs) {
|
void enable(GPIOPin *cs) {
|
||||||
if (cs) {
|
if (cs != nullptr) {
|
||||||
SPIComponent::debug_enable(cs->get_pin());
|
SPIComponent::debug_enable(cs->get_pin());
|
||||||
|
}
|
||||||
|
|
||||||
if (this->hw_spi_ != nullptr) {
|
if (this->hw_spi_ != nullptr) {
|
||||||
uint8_t data_mode = (uint8_t(CLOCK_POLARITY) << 1) | uint8_t(CLOCK_PHASE);
|
uint8_t data_mode = (uint8_t(CLOCK_POLARITY) << 1) | uint8_t(CLOCK_PHASE);
|
||||||
|
@ -139,6 +140,7 @@ class SPIComponent : public Component {
|
||||||
this->wait_cycle_ = uint32_t(F_CPU) / DATA_RATE / 2ULL;
|
this->wait_cycle_ = uint32_t(F_CPU) / DATA_RATE / 2ULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cs != nullptr) {
|
||||||
this->active_cs_ = cs;
|
this->active_cs_ = cs;
|
||||||
this->active_cs_->digital_write(false);
|
this->active_cs_->digital_write(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ SPISSD1325 = ssd1325_spi.class_('SPISSD1325', ssd1325_base.SSD1325, spi.SPIDevic
|
||||||
CONFIG_SCHEMA = cv.All(ssd1325_base.SSD1325_SCHEMA.extend({
|
CONFIG_SCHEMA = cv.All(ssd1325_base.SSD1325_SCHEMA.extend({
|
||||||
cv.GenerateID(): cv.declare_id(SPISSD1325),
|
cv.GenerateID(): cv.declare_id(SPISSD1325),
|
||||||
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
|
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
|
||||||
}).extend(cv.COMPONENT_SCHEMA).extend(spi.spi_device_schema()),
|
}).extend(cv.COMPONENT_SCHEMA).extend(spi.spi_device_schema(cs_pin_required=False)),
|
||||||
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
|
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue