8static const char *
const TAG =
"sx1509";
11 ESP_LOGCONFIG(TAG,
"Running setup");
13 ESP_LOGV(TAG,
" Resetting devices");
36 ESP_LOGCONFIG(TAG,
"SX1509:");
38 ESP_LOGE(TAG,
"Setting up SX1509 failed!");
50 binary_sensor->process(key_data);
51 if (this->
keys_.empty())
58 for (row = 0; row < 7; row++) {
59 if (key_data & (1 << row))
62 for (col = 8; col < 15; col++) {
63 if (key_data & (1 << col))
67 uint8_t key = this->
keys_[row * this->
cols_ + col];
71 ESP_LOGV(TAG,
"row %d, col %d, key '%c'", row, col, key);
73 trigger->trigger(key);
80 uint16_t temp_reg_data;
83 if (temp_reg_data & (1 << pin))
92 uint16_t temp_reg_data = 0;
99 for (uint16_t b = 0x8000; b; b >>= 1) {
113 ESP_LOGI(TAG,
"Configuring pin %u with flags %x", pin, flags);
115 uint16_t temp_word = 0;
121 temp_word |= (1 << pin);
127 temp_word &= ~(1 << pin);
130 temp_word |= (1 << pin);
132 ESP_LOGD(TAG,
"Open drain output mode set for %u", pin);
134 ESP_LOGD(TAG,
"Output Mode for %u", pin);
141 ESP_LOGD(TAG,
"Input Mode for %u", pin);
145 temp_word &= ~(1 << pin);
151 temp_word |= (1 << pin);
153 temp_word &= ~(1 << pin);
160 temp_word |= (1 << pin);
162 temp_word &= ~(1 << pin);
173 uint16_t temp_word = 0;
174 uint8_t temp_byte = 0;
177 temp_word |= (1 << pin);
184 temp_byte |= (1 << 6);
185 temp_byte &= ~(1 << 5);
189 temp_byte &= ~(1 << 7);
190 temp_byte &= ~(1 << 3);
195 temp_word |= (1 << pin);
199 temp_word &= ~(1 << pin);
205 osc_source = (osc_source & 0b11) << 5;
206 osc_pin_function = (osc_pin_function & 1) << 4;
207 osc_freq_out = (osc_freq_out & 0b1111);
208 uint8_t reg_clock = osc_source | osc_pin_function | osc_freq_out;
213 osc_divider = (osc_divider & 0b111) << 4;
215 uint8_t reg_misc = 0;
217 reg_misc &= ~(0b111 << 4);
218 reg_misc |= osc_divider;
223 uint8_t temp_byte = 0;
227 for (
int i = 0; i < this->
rows_; i++)
229 for (
int i = 8; i < (this->
cols_ * 2); i++)
234 for (
int i = 0; i < this->
rows_; i++)
235 temp_byte |= (1 << i);
239 for (
int i = 0; i < this->
cols_; i++)
240 temp_byte |= (1 << i);
247 uint8_t scan_time_bits = 0;
248 for (uint8_t i = 7; i > 0; i--) {
254 scan_time_bits &= 0b111;
257 temp_byte = ((this->rows_ - 1) & 0b111) << 3;
258 temp_byte |= (this->cols_ - 1) & 0b111;
263 uint16_t key_data = 0;
265 return (0xFFFF ^ key_data);
270 uint8_t temp_byte = 0;
272 temp_byte |= (1 << 4);
275 temp_byte |= (1 << 6);
278 config_value &= 0b111;
283 uint8_t config_value = 0;
285 for (
int i = 7; i >= 0; i--) {
286 if (time & (1 << i)) {
287 config_value = i + 1;
297 uint16_t debounce_enable = 0;
299 debounce_enable |= (1 << pin);
307 for (uint16_t i = 0; i < num_rows; i++)
309 for (uint16_t i = 0; i < (8 + num_cols); i++)
virtual void mark_failed()
Mark this component as failed.
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
bool read_byte_16(uint8_t a_register, uint16_t *data)
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
bool write_byte_16(uint8_t a_register, uint16_t data)
void send_key_(uint8_t key)
void clock_(uint8_t osc_source=2, uint8_t osc_pin_function=1, uint8_t osc_freq_out=0, uint8_t osc_divider=0)
bool digital_read(uint8_t pin)
void dump_config() override
void set_debounce_pin_(uint8_t pin)
void set_debounce_config_(uint8_t config_value)
void digital_write(uint8_t pin, bool bit_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 setup_led_driver(uint8_t pin)
void set_debounce_enable_(uint8_t pin)
const uint32_t min_loop_period_
const uint8_t REG_DEBOUNCE_CONFIG
const uint8_t REG_KEY_CONFIG_2
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
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint32_t IRAM_ATTR HOT millis()
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)