mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 17:54:13 +01:00
MCP230xx open drain interrupt pins (#1243)
This commit is contained in:
parent
81b512a7b3
commit
b52f7cfe86
8 changed files with 24 additions and 7 deletions
|
@ -2,7 +2,7 @@ import esphome.codegen as cg
|
|||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import i2c
|
||||
from esphome.const import CONF_ID, CONF_NUMBER, CONF_MODE, CONF_INVERTED
|
||||
from esphome.const import CONF_ID, CONF_NUMBER, CONF_MODE, CONF_INVERTED, CONF_OPEN_DRAIN_INTERRUPT
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
MULTI_CONF = True
|
||||
|
@ -20,6 +20,7 @@ MCP23008GPIOPin = mcp23008_ns.class_('MCP23008GPIOPin', cg.GPIOPin)
|
|||
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.Required(CONF_ID): cv.declare_id(MCP23008),
|
||||
cv.Optional(CONF_OPEN_DRAIN_INTERRUPT, default=False): cv.boolean,
|
||||
}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x20))
|
||||
|
||||
|
||||
|
@ -27,6 +28,7 @@ def to_code(config):
|
|||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield i2c.register_i2c_device(var, config)
|
||||
cg.add(var.set_open_drain_ints(config[CONF_OPEN_DRAIN_INTERRUPT]))
|
||||
|
||||
|
||||
CONF_MCP23008 = 'mcp23008'
|
||||
|
|
|
@ -14,8 +14,10 @@ void MCP23008::setup() {
|
|||
return;
|
||||
}
|
||||
|
||||
// all pins input
|
||||
this->write_reg_(MCP23008_IODIR, 0xFF);
|
||||
if (this->open_drain_ints_) {
|
||||
// enable open-drain interrupt pins, 3.3V-safe
|
||||
this->write_reg_(MCP23008_IOCON, 0x04);
|
||||
}
|
||||
}
|
||||
bool MCP23008::digital_read(uint8_t pin) {
|
||||
uint8_t bit = pin % 8;
|
||||
|
|
|
@ -39,6 +39,8 @@ class MCP23008 : public Component, public i2c::I2CDevice {
|
|||
void digital_write(uint8_t pin, bool value);
|
||||
void pin_mode(uint8_t pin, uint8_t mode);
|
||||
|
||||
void set_open_drain_ints(const bool value) { open_drain_ints_ = value; }
|
||||
|
||||
float get_setup_priority() const override;
|
||||
|
||||
protected:
|
||||
|
@ -50,6 +52,7 @@ class MCP23008 : public Component, public i2c::I2CDevice {
|
|||
void update_reg_(uint8_t pin, bool pin_value, uint8_t reg_a);
|
||||
|
||||
uint8_t olat_{0x00};
|
||||
bool open_drain_ints_;
|
||||
};
|
||||
|
||||
class MCP23008GPIOPin : public GPIOPin {
|
||||
|
|
|
@ -2,7 +2,7 @@ import esphome.codegen as cg
|
|||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import i2c
|
||||
from esphome.const import CONF_ID, CONF_NUMBER, CONF_MODE, CONF_INVERTED
|
||||
from esphome.const import CONF_ID, CONF_NUMBER, CONF_MODE, CONF_INVERTED, CONF_OPEN_DRAIN_INTERRUPT
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
MULTI_CONF = True
|
||||
|
@ -20,6 +20,7 @@ MCP23017GPIOPin = mcp23017_ns.class_('MCP23017GPIOPin', cg.GPIOPin)
|
|||
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.Required(CONF_ID): cv.declare_id(MCP23017),
|
||||
cv.Optional(CONF_OPEN_DRAIN_INTERRUPT, default=False): cv.boolean,
|
||||
}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x20))
|
||||
|
||||
|
||||
|
@ -27,6 +28,7 @@ def to_code(config):
|
|||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield i2c.register_i2c_device(var, config)
|
||||
cg.add(var.set_open_drain_ints(config[CONF_OPEN_DRAIN_INTERRUPT]))
|
||||
|
||||
|
||||
CONF_MCP23017 = 'mcp23017'
|
||||
|
|
|
@ -14,9 +14,11 @@ void MCP23017::setup() {
|
|||
return;
|
||||
}
|
||||
|
||||
// all pins input
|
||||
this->write_reg_(MCP23017_IODIRA, 0xFF);
|
||||
this->write_reg_(MCP23017_IODIRB, 0xFF);
|
||||
if (this->open_drain_ints_) {
|
||||
// enable open-drain interrupt pins, 3.3V-safe
|
||||
this->write_reg_(MCP23017_IOCONA, 0x04);
|
||||
this->write_reg_(MCP23017_IOCONB, 0x04);
|
||||
}
|
||||
}
|
||||
bool MCP23017::digital_read(uint8_t pin) {
|
||||
uint8_t bit = pin % 8;
|
||||
|
|
|
@ -51,6 +51,8 @@ class MCP23017 : public Component, public i2c::I2CDevice {
|
|||
void digital_write(uint8_t pin, bool value);
|
||||
void pin_mode(uint8_t pin, uint8_t mode);
|
||||
|
||||
void set_open_drain_ints(const bool value) { open_drain_ints_ = value; }
|
||||
|
||||
float get_setup_priority() const override;
|
||||
|
||||
protected:
|
||||
|
@ -63,6 +65,7 @@ class MCP23017 : public Component, public i2c::I2CDevice {
|
|||
|
||||
uint8_t olat_a_{0x00};
|
||||
uint8_t olat_b_{0x00};
|
||||
bool open_drain_ints_;
|
||||
};
|
||||
|
||||
class MCP23017GPIOPin : public GPIOPin {
|
||||
|
|
|
@ -357,6 +357,7 @@ CONF_ON_VALUE = 'on_value'
|
|||
CONF_ON_VALUE_RANGE = 'on_value_range'
|
||||
CONF_ONE = 'one'
|
||||
CONF_OPEN_ACTION = 'open_action'
|
||||
CONF_OPEN_DRAIN_INTERRUPT = 'open_drain_interrupt'
|
||||
CONF_OPEN_DURATION = 'open_duration'
|
||||
CONF_OPEN_ENDSTOP = 'open_endstop'
|
||||
CONF_OPTIMISTIC = 'optimistic'
|
||||
|
|
|
@ -1921,10 +1921,12 @@ pcf8574:
|
|||
|
||||
mcp23017:
|
||||
- id: 'mcp23017_hub'
|
||||
open_drain_interrupt: 'true'
|
||||
|
||||
mcp23008:
|
||||
- id: 'mcp23008_hub'
|
||||
address: 0x22
|
||||
open_drain_interrupt: 'true'
|
||||
|
||||
mcp23016:
|
||||
- id: 'mcp23016_hub'
|
||||
|
|
Loading…
Reference in a new issue