mirror of
https://github.com/esphome/esphome.git
synced 2024-12-12 00:14:53 +01:00
5f2808ec2f
* added ANALOG_OUTPUT as first functionality
* added gpio
* seperated the code for different functions
* fixed code
* Revert "fixed code"
This reverts commit 0c6eacb225
.
* add timings for breathe and blink
* made the sx1509_float_output am output component
* add keypad
* implementation for sx1509 keypad
* keypad code cleanup and first device tests
* debounce
* keypad working now.
* update for timings.
does not compile yet
* added all options for breathe and blink
fixed var namings
* blink and breath still not ok
* fixed ms for timings
* sync with repo
* fixed issue with gpio pin output
* code cleanup
* lint
* more lint
* remove log from header
* Update esphome/components/sx1509/__init__.py
Co-Authored-By: Otto Winter <otto@otto-winter.com>
* review
* feedback
* fixed review issues
did some extended testing with mqtt spy
* code cleanup (comments)
* fixed row col swap for binarysensor_keypad
* flake and lint
* travis
* travis
* travis
* Update esphome/components/sx1509/sx1509.cpp
Co-Authored-By: Otto Winter <otto@otto-winter.com>
* review
* separated platforms
* code cleanup
* travis relative paths in python
* remove blink/breathe
code cleanup
* cpp lint
* feedback
* travis
* lint line to long
* check keypad settings to be valid
* clang
* keypad config
* text
* Remove wrong .gitignore from .gitignore
* Remove .pio folder from .gitignore (merge)
* Formatting
* Formatting
* Add i2c log in dump_config
* Remove unused variables
* Disable static for header files
We don't need internal linkage
* Use consistent member default argument style
* Run clang-format
Co-authored-by: null <m.vanturnhout@exxellence.nl>
Co-authored-by: Otto Winter <otto@otto-winter.com>
89 lines
3 KiB
C++
89 lines
3 KiB
C++
#pragma once
|
|
|
|
#include "esphome/components/i2c/i2c.h"
|
|
#include "esphome/core/component.h"
|
|
#include "sx1509_gpio_pin.h"
|
|
#include "sx1509_registers.h"
|
|
|
|
namespace esphome {
|
|
namespace sx1509 {
|
|
|
|
// These are used for clock config:
|
|
const uint8_t INTERNAL_CLOCK_2MHZ = 2;
|
|
const uint8_t EXTERNAL_CLOCK = 1;
|
|
const uint8_t SOFTWARE_RESET = 0;
|
|
const uint8_t HARDWARE_RESET = 1;
|
|
|
|
const uint8_t ANALOG_OUTPUT = 0x03; // To set a pin mode for PWM output
|
|
|
|
// PinModes for SX1509 pins
|
|
enum SX1509GPIOMode : uint8_t {
|
|
SX1509_INPUT = INPUT, // 0x00
|
|
SX1509_INPUT_PULLUP = INPUT_PULLUP, // 0x02
|
|
SX1509_ANALOG_OUTPUT = ANALOG_OUTPUT, // 0x03
|
|
SX1509_OUTPUT = OUTPUT, // 0x01
|
|
};
|
|
|
|
const uint8_t REG_I_ON[16] = {REG_I_ON_0, REG_I_ON_1, REG_I_ON_2, REG_I_ON_3, REG_I_ON_4, REG_I_ON_5,
|
|
REG_I_ON_6, REG_I_ON_7, REG_I_ON_8, REG_I_ON_9, REG_I_ON_10, REG_I_ON_11,
|
|
REG_I_ON_12, REG_I_ON_13, REG_I_ON_14, REG_I_ON_15};
|
|
|
|
// for all components that implement the process(uint16_t data )
|
|
class SX1509Processor {
|
|
public:
|
|
virtual void process(uint16_t data){};
|
|
};
|
|
|
|
class SX1509Component : public Component, public i2c::I2CDevice {
|
|
public:
|
|
SX1509Component() = default;
|
|
|
|
void setup() override;
|
|
void dump_config() override;
|
|
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
|
void loop() override;
|
|
|
|
bool digital_read(uint8_t pin);
|
|
uint16_t read_key_data();
|
|
void set_pin_value(uint8_t pin, uint8_t i_on) { this->write_byte(REG_I_ON[pin], i_on); };
|
|
void pin_mode(uint8_t pin, uint8_t mode);
|
|
void digital_write(uint8_t pin, bool bit_value);
|
|
u_long get_clock() { return this->clk_x_; };
|
|
void set_rows_cols(uint8_t rows, uint8_t cols) {
|
|
this->rows_ = rows;
|
|
this->cols_ = cols;
|
|
this->has_keypad_ = true;
|
|
};
|
|
void set_sleep_time(uint16_t sleep_time) { this->sleep_time_ = sleep_time; };
|
|
void set_scan_time(uint8_t scan_time) { this->scan_time_ = scan_time; };
|
|
void set_debounce_time(uint8_t debounce_time = 1) { this->debounce_time_ = debounce_time; };
|
|
void register_keypad_binary_sensor(SX1509Processor *binary_sensor) {
|
|
this->keypad_binary_sensors_.push_back(binary_sensor);
|
|
};
|
|
|
|
protected:
|
|
u_long clk_x_ = 2000000;
|
|
uint8_t frequency_ = 0;
|
|
uint16_t ddr_mask_ = 0x00;
|
|
uint16_t input_mask_ = 0x00;
|
|
uint16_t port_mask_ = 0x00;
|
|
bool has_keypad_ = false;
|
|
uint8_t rows_ = 0;
|
|
uint8_t cols_ = 0;
|
|
uint16_t sleep_time_ = 128;
|
|
uint8_t scan_time_ = 1;
|
|
uint8_t debounce_time_ = 1;
|
|
std::vector<SX1509Processor *> keypad_binary_sensors_;
|
|
|
|
void setup_keypad_();
|
|
void set_debounce_config_(uint8_t config_value);
|
|
void set_debounce_time_(uint8_t time);
|
|
void set_debounce_pin_(uint8_t pin);
|
|
void set_debounce_enable_(uint8_t pin);
|
|
void set_debounce_keypad_(uint8_t time, uint8_t num_rows, uint8_t num_cols);
|
|
void setup_led_driver_(uint8_t pin);
|
|
void clock_(uint8_t osc_source = 2, uint8_t osc_pin_function = 1, uint8_t osc_freq_out = 0, uint8_t osc_divider = 0);
|
|
};
|
|
|
|
} // namespace sx1509
|
|
} // namespace esphome
|