10 ESP_LOGV(TAG,
" Resetting devices");
23 this->
mark_failed(LOG_STR(
"Unexpected reset value"));
33 ESP_LOGCONFIG(TAG,
"SX1509:");
47 binary_sensor->process(key_data);
48 if (this->
keys_ ==
nullptr)
55 for (row = 0; row < 8; row++) {
56 if (key_data & (1 << row))
59 for (col = 8; col < 16; col++) {
60 if (key_data & (1 << col))
70 ESP_LOGV(TAG,
"row %d, col %d, key '%c'", row, col,
key);
72 trigger->trigger(
key);
93 uint16_t temp_reg_data = 0;
103 ESP_LOGI(TAG,
"Configuring pin %u with flags %x", pin,
flags);
105 uint16_t temp_word = 0;
111 temp_word |= (1 << pin);
117 temp_word &= ~(1 << pin);
120 temp_word |= (1 << pin);
122 ESP_LOGD(TAG,
"Open drain output mode set for %u", pin);
124 ESP_LOGD(TAG,
"Output Mode for %u", pin);
131 ESP_LOGD(TAG,
"Input Mode for %u", pin);
135 temp_word &= ~(1 << pin);
155 uint16_t temp_word = 0;
156 uint8_t temp_byte = 0;
159 temp_word |= (1 << pin);
166 temp_byte |= (1 << 6);
167 temp_byte &= ~(1 << 5);
171 temp_byte &= ~(1 << 7);
172 temp_byte &= ~(1 << 3);
177 temp_word |= (1 << pin);
181 temp_word &= ~(1 << pin);
187 osc_source = (osc_source & 0b11) << 5;
188 osc_pin_function = (osc_pin_function & 1) << 4;
189 osc_freq_out = (osc_freq_out & 0b1111);
190 uint8_t reg_clock = osc_source | osc_pin_function | osc_freq_out;
193 osc_divider = clamp<uint8_t>(osc_divider, 1, 7u);
195 osc_divider = (osc_divider & 0b111) << 4;
197 uint8_t reg_misc = 0;
199 reg_misc &= ~(0b111 << 4);
200 reg_misc |= osc_divider;
205 uint8_t temp_byte = 0;
209 for (
int i = 0; i < this->
rows_; i++)
211 for (
int i = 8; i < (8 + this->
cols_); i++)
216 for (
int i = 0; i < this->
rows_; i++)
217 temp_byte |= (1 << i);
221 for (
int i = 0; i < this->
cols_; i++)
222 temp_byte |= (1 << i);
229 uint8_t scan_time_bits = 0;
230 for (uint8_t i = 7; i > 0; i--) {
236 scan_time_bits &= 0b111;
239 temp_byte = ((this->rows_ - 1) & 0b111) << 3;
240 temp_byte |= (this->cols_ - 1) & 0b111;
245 uint16_t key_data = 0;
247 return (0xFFFF ^ key_data);
252 uint8_t temp_byte = 0;
254 temp_byte |= (1 << 4);
257 temp_byte |= (1 << 6);
260 config_value &= 0b111;
265 uint8_t config_value = 0;
267 for (
int i = 7; i >= 0; i--) {
268 if (time & (1 << i)) {
269 config_value = i + 1;
273 config_value = clamp<uint8_t>(config_value, 0, 7);
279 uint16_t debounce_enable = 0;
281 debounce_enable |= (1 << pin);
289 for (uint16_t i = 0; i < num_rows; i++)
291 for (uint16_t i = 0; i < num_cols; i++)
void mark_failed()
Mark this component as failed.
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
bool read_byte_16(uint8_t a_register, uint16_t *data)
bool write_byte_16(uint8_t a_register, uint16_t data) const
void send_key_(uint8_t key)
bool digital_read_cache(uint8_t pin) override
void clock_(uint8_t osc_source=2, uint8_t osc_pin_function=1, uint8_t osc_freq_out=0, uint8_t osc_divider=0)
void dump_config() override
void set_debounce_pin_(uint8_t pin)
bool digital_read_hw(uint8_t pin) override
void set_debounce_config_(uint8_t config_value)
std::vector< SX1509KeyTrigger * > key_triggers_
void set_debounce_time_(uint8_t time)
void set_debounce_keypad_(uint8_t time, uint8_t num_rows, uint8_t num_cols)
uint32_t last_loop_timestamp_
void pin_mode(uint8_t pin, gpio::Flags flags)
std::vector< SX1509Processor * > keypad_binary_sensors_
void digital_write_hw(uint8_t pin, bool value) override
void setup_led_driver(uint8_t pin)
void set_debounce_enable_(uint8_t pin)
const uint32_t min_loop_period_
Here you'll find the Arduino code used to interface with the SX1509 I2C 16 I/O expander.
const uint8_t REG_DEBOUNCE_CONFIG
const uint8_t REG_KEY_CONFIG_2
ESPHOME_LOG_TAG(TAG, "sx1509_float_channel")
const uint8_t REG_LED_DRIVER_ENABLE_B
const uint8_t REG_KEY_CONFIG_1
const uint8_t REG_OPEN_DRAIN_B
const uint8_t REG_PULL_UP_B
const uint8_t REG_INPUT_DISABLE_B
const uint8_t REG_DEBOUNCE_ENABLE_B
const uint8_t REG_INTERRUPT_MASK_A
const uint8_t REG_PULL_DOWN_B
const uint8_t INTERNAL_CLOCK_2MHZ
const uint8_t REG_OPEN_DRAIN_A
const uint8_t REG_KEY_DATA_1
ESPHOME_ALWAYS_INLINE constexpr void assign_bits(T &value, std::type_identity_t< T > mask, bool on)
Set the bits of mask in value when on is true, clear them otherwise.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint32_t IRAM_ATTR HOT millis()
uint8_t progmem_read_byte(const uint8_t *addr)