mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 01:58:39 +00:00
[multiple] Fix misc hardware register bugs (#15208)
This commit is contained in:
@@ -6,6 +6,8 @@ namespace mcp23008 {
|
||||
|
||||
static const char *const TAG = "mcp23008";
|
||||
|
||||
static constexpr uint8_t IOCON_ODR = 0x04; // Open-drain output for INT pin
|
||||
|
||||
void MCP23008::setup() {
|
||||
uint8_t iocon;
|
||||
if (!this->read_reg(mcp23x08_base::MCP23X08_IOCON, &iocon)) {
|
||||
@@ -18,7 +20,7 @@ void MCP23008::setup() {
|
||||
|
||||
if (this->open_drain_ints_) {
|
||||
// enable open-drain interrupt pins, 3.3V-safe
|
||||
this->write_reg(mcp23x08_base::MCP23X08_IOCON, 0x04);
|
||||
this->write_reg(mcp23x08_base::MCP23X08_IOCON, iocon | IOCON_ODR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace mcp23017 {
|
||||
|
||||
static const char *const TAG = "mcp23017";
|
||||
|
||||
static constexpr uint8_t IOCON_ODR = 0x04; // Open-drain output for INT pin
|
||||
|
||||
void MCP23017::setup() {
|
||||
uint8_t iocon;
|
||||
if (!this->read_reg(mcp23x17_base::MCP23X17_IOCONA, &iocon)) {
|
||||
@@ -19,8 +21,8 @@ void MCP23017::setup() {
|
||||
|
||||
if (this->open_drain_ints_) {
|
||||
// enable open-drain interrupt pins, 3.3V-safe
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONA, 0x04);
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONB, 0x04);
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONA, iocon | IOCON_ODR);
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONB, iocon | IOCON_ODR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,11 @@ namespace mcp23s08 {
|
||||
|
||||
static const char *const TAG = "mcp23s08";
|
||||
|
||||
// IOCON register bits
|
||||
static constexpr uint8_t IOCON_SEQOP = 0x20; // Sequential operation mode
|
||||
static constexpr uint8_t IOCON_HAEN = 0x08; // Hardware address enable
|
||||
static constexpr uint8_t IOCON_ODR = 0x04; // Open-drain output for INT pin
|
||||
|
||||
void MCP23S08::set_device_address(uint8_t device_addr) {
|
||||
if (device_addr != 0) {
|
||||
this->device_opcode_ |= ((device_addr & 0x03) << 1);
|
||||
@@ -15,19 +20,19 @@ void MCP23S08::set_device_address(uint8_t device_addr) {
|
||||
void MCP23S08::setup() {
|
||||
this->spi_setup();
|
||||
|
||||
// Enable HAEN (broadcast to all chips since HAEN isn't active yet)
|
||||
this->enable();
|
||||
uint8_t cmd = 0b01000000;
|
||||
this->transfer_byte(cmd);
|
||||
this->transfer_byte(0b01000000);
|
||||
this->transfer_byte(mcp23x08_base::MCP23X08_IOCON);
|
||||
this->transfer_byte(0b00011000); // Enable HAEN pins for addressing
|
||||
this->transfer_byte(IOCON_SEQOP | IOCON_HAEN);
|
||||
this->disable();
|
||||
|
||||
// Read current output register state
|
||||
this->read_reg(mcp23x08_base::MCP23X08_OLAT, &this->olat_);
|
||||
|
||||
if (this->open_drain_ints_) {
|
||||
// enable open-drain interrupt pins, 3.3V-safe
|
||||
this->write_reg(mcp23x08_base::MCP23X08_IOCON, 0x04);
|
||||
// enable open-drain interrupt pins, 3.3V-safe (addressed, only this chip)
|
||||
this->write_reg(mcp23x08_base::MCP23X08_IOCON, IOCON_SEQOP | IOCON_HAEN | IOCON_ODR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,11 @@ namespace mcp23s17 {
|
||||
|
||||
static const char *const TAG = "mcp23s17";
|
||||
|
||||
// IOCON register bits
|
||||
static constexpr uint8_t IOCON_SEQOP = 0x20; // Sequential operation mode
|
||||
static constexpr uint8_t IOCON_HAEN = 0x08; // Hardware address enable
|
||||
static constexpr uint8_t IOCON_ODR = 0x04; // Open-drain output for INT pin
|
||||
|
||||
void MCP23S17::set_device_address(uint8_t device_addr) {
|
||||
if (device_addr != 0) {
|
||||
this->device_opcode_ |= ((device_addr & 0b111) << 1);
|
||||
@@ -15,18 +20,17 @@ void MCP23S17::set_device_address(uint8_t device_addr) {
|
||||
void MCP23S17::setup() {
|
||||
this->spi_setup();
|
||||
|
||||
// Enable HAEN (broadcast to addresses 0 and 4 since HAEN isn't active yet)
|
||||
this->enable();
|
||||
uint8_t cmd = 0b01000000;
|
||||
this->transfer_byte(cmd);
|
||||
this->transfer_byte(0b01000000);
|
||||
this->transfer_byte(mcp23x17_base::MCP23X17_IOCONA);
|
||||
this->transfer_byte(0b00011000); // Enable HAEN pins for addressing
|
||||
this->transfer_byte(IOCON_SEQOP | IOCON_HAEN);
|
||||
this->disable();
|
||||
|
||||
this->enable();
|
||||
cmd = 0b01001000;
|
||||
this->transfer_byte(cmd);
|
||||
this->transfer_byte(0b01001000);
|
||||
this->transfer_byte(mcp23x17_base::MCP23X17_IOCONA);
|
||||
this->transfer_byte(0b00011000); // Enable HAEN pins for addressing
|
||||
this->transfer_byte(IOCON_SEQOP | IOCON_HAEN);
|
||||
this->disable();
|
||||
|
||||
// Read current output register state
|
||||
@@ -34,9 +38,9 @@ void MCP23S17::setup() {
|
||||
this->read_reg(mcp23x17_base::MCP23X17_OLATB, &this->olat_b_);
|
||||
|
||||
if (this->open_drain_ints_) {
|
||||
// enable open-drain interrupt pins, 3.3V-safe
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONA, 0x04);
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONB, 0x04);
|
||||
// enable open-drain interrupt pins, 3.3V-safe (addressed, only this chip)
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONA, IOCON_SEQOP | IOCON_HAEN | IOCON_ODR);
|
||||
this->write_reg(mcp23x17_base::MCP23X17_IOCONB, IOCON_SEQOP | IOCON_HAEN | IOCON_ODR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,21 +126,21 @@ void MMC5603Component::update() {
|
||||
int32_t raw_x = 0;
|
||||
raw_x |= buffer[0] << 12;
|
||||
raw_x |= buffer[1] << 4;
|
||||
raw_x |= buffer[2] << 0;
|
||||
raw_x |= buffer[2] & 0x0F;
|
||||
|
||||
const float x = 0.00625 * (raw_x - 524288);
|
||||
|
||||
int32_t raw_y = 0;
|
||||
raw_y |= buffer[3] << 12;
|
||||
raw_y |= buffer[4] << 4;
|
||||
raw_y |= buffer[5] << 0;
|
||||
raw_y |= buffer[5] & 0x0F;
|
||||
|
||||
const float y = 0.00625 * (raw_y - 524288);
|
||||
|
||||
int32_t raw_z = 0;
|
||||
raw_z |= buffer[6] << 12;
|
||||
raw_z |= buffer[7] << 4;
|
||||
raw_z |= buffer[8] << 0;
|
||||
raw_z |= buffer[8] & 0x0F;
|
||||
|
||||
const float z = 0.00625 * (raw_z - 524288);
|
||||
|
||||
|
||||
@@ -309,8 +309,8 @@ void SX1509Component::set_debounce_keypad_(uint8_t time, uint8_t num_rows, uint8
|
||||
set_debounce_time_(time);
|
||||
for (uint16_t i = 0; i < num_rows; i++)
|
||||
set_debounce_pin_(i);
|
||||
for (uint16_t i = 0; i < (8 + num_cols); i++)
|
||||
set_debounce_pin_(i);
|
||||
for (uint16_t i = 0; i < num_cols; i++)
|
||||
set_debounce_pin_(i + 8);
|
||||
}
|
||||
|
||||
} // namespace sx1509
|
||||
|
||||
Reference in New Issue
Block a user