8 static const char *
const TAG =
"sx1509";
11 ESP_LOGCONFIG(TAG,
"Setting up SX1509Component...");
13 ESP_LOGV(TAG,
" Resetting devices...");
36 ESP_LOGCONFIG(TAG,
"SX1509:");
38 ESP_LOGE(TAG,
"Setting up SX1509 failed!");
56 uint16_t temp_reg_data;
59 if (temp_reg_data & (1 << pin))
68 uint16_t temp_reg_data = 0;
75 for (uint16_t b = 0x8000; b; b >>= 1) {
89 ESP_LOGI(TAG,
"Configuring pin %u with flags %x", pin, flags);
91 uint16_t temp_word = 0;
97 temp_word |= (1 << pin);
103 temp_word &= ~(1 << pin);
106 temp_word |= (1 << pin);
108 ESP_LOGD(TAG,
"Open drain output mode set for %u", pin);
110 ESP_LOGD(TAG,
"Output Mode for %u", pin);
117 ESP_LOGD(TAG,
"Input Mode for %u", pin);
121 temp_word &= ~(1 << pin);
127 temp_word |= (1 << pin);
129 temp_word &= ~(1 << pin);
136 temp_word |= (1 << pin);
138 temp_word &= ~(1 << pin);
149 uint16_t temp_word = 0;
150 uint8_t temp_byte = 0;
153 temp_word |= (1 << pin);
160 temp_byte |= (1 << 6);
161 temp_byte &= ~(1 << 5);
165 temp_byte &= ~(1 << 7);
166 temp_byte &= ~(1 << 3);
171 temp_word |= (1 << pin);
175 temp_word &= ~(1 << pin);
181 osc_source = (osc_source & 0
b11) << 5;
182 osc_pin_function = (osc_pin_function & 1) << 4;
183 osc_freq_out = (osc_freq_out & 0b1111);
184 uint8_t reg_clock = osc_source | osc_pin_function | osc_freq_out;
187 osc_divider = clamp<uint8_t>(osc_divider, 1, 7u);
189 osc_divider = (osc_divider & 0b111) << 4;
191 uint8_t reg_misc = 0;
193 reg_misc &= ~(0b111 << 4);
194 reg_misc |= osc_divider;
199 uint8_t temp_byte = 0;
203 for (
int i = 0; i < this->
rows_; i++)
205 for (
int i = 8; i < (this->
cols_ * 2); i++)
210 for (
int i = 0; i < this->
rows_; i++)
211 temp_byte |= (1 << i);
215 for (
int i = 0; i < this->
cols_; i++)
216 temp_byte |= (1 << i);
223 uint8_t scan_time_bits = 0;
224 for (uint8_t i = 7; i > 0; i--) {
230 scan_time_bits &= 0b111;
233 rows_ = (rows_ - 1) & 0b111;
234 cols_ = (cols_ - 1) & 0b111;
239 uint16_t key_data = 0;
241 return (0xFFFF ^ key_data);
246 uint8_t temp_byte = 0;
248 temp_byte |= (1 << 4);
251 temp_byte |= (1 << 6);
254 config_value &= 0b111;
259 uint8_t config_value = 0;
261 for (
int i = 7; i >= 0; i--) {
262 if (time & (1 << i)) {
263 config_value = i + 1;
267 config_value = clamp<uint8_t>(config_value, 0, 7);
273 uint16_t debounce_enable = 0;
275 debounce_enable |= (1 << pin);
283 for (uint16_t i = 0; i < num_rows; i++)
285 for (uint16_t i = 0; i < (8 + num_cols); i++)
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
bool read_byte_16(uint8_t a_register, uint16_t *data)
void set_debounce_config_(uint8_t config_value)
const uint8_t REG_KEY_DATA_1
uint32_t last_loop_timestamp_
const uint8_t REG_LED_DRIVER_ENABLE_B
uint32_t IRAM_ATTR HOT millis()
const uint8_t REG_DEBOUNCE_ENABLE_B
const uint8_t INTERNAL_CLOCK_2MHZ
void pin_mode(uint8_t pin, gpio::Flags flags)
const uint8_t REG_INPUT_DISABLE_B
void clock_(uint8_t osc_source=2, uint8_t osc_pin_function=1, uint8_t osc_freq_out=0, uint8_t osc_divider=0)
const uint8_t REG_KEY_CONFIG_1
const uint32_t min_loop_period_
std::vector< SX1509Processor * > keypad_binary_sensors_
const uint8_t REG_INTERRUPT_MASK_A
void set_debounce_enable_(uint8_t pin)
esphome::binary_sensor::BinarySensor * binary_sensor
void set_debounce_time_(uint8_t time)
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
void setup_led_driver(uint8_t pin)
virtual void mark_failed()
Mark this component as failed.
void set_debounce_pin_(uint8_t pin)
void dump_config() override
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
void digital_write(uint8_t pin, bool bit_value)
void set_debounce_keypad_(uint8_t time, uint8_t num_rows, uint8_t num_cols)
const uint8_t REG_PULL_UP_B
bool write_byte_16(uint8_t a_register, uint16_t data)
const uint8_t REG_KEY_CONFIG_2
const uint8_t REG_OPEN_DRAIN_A
bool digital_read(uint8_t pin)
const uint8_t REG_OPEN_DRAIN_B
const uint8_t REG_PULL_DOWN_B
const uint8_t REG_DEBOUNCE_CONFIG