You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.8 KiB

Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
  1. #pragma once
  2. #include "common.h"
  3. #include "esphome/core/component.h"
  4. #include "esphome/core/esphal.h"
  5. #include "esphome/components/ledc/ledc_output.h"
  6. #include "esphome/components/gpio/output/gpio_binary_output.h"
  7. #include "esphome/components/i2c/i2c.h"
  8. namespace esphome {
  9. namespace yeelight {
  10. namespace bs2 {
  11. struct TriggerPinStore {
  12. volatile int queue_length = 0;
  13. static void isr(TriggerPinStore *store);
  14. };
  15. /**
  16. * This ISR is used to handle IRQ triggers from the front panel.
  17. *
  18. * The front panel pulls the trigger pin low when a new event
  19. * is available. All we do here to handle the interrupt, is
  20. * increment a simple queue length counter. Reading the event
  21. * from the I2C bus will be handled in the main loop, based
  22. * on this counter.
  23. */
  24. void ICACHE_RAM_ATTR HOT TriggerPinStore::isr(TriggerPinStore *store) {
  25. store->queue_length++;
  26. }
  27. class YeelightBS2Hub : public Component {
  28. public:
  29. // Pins that are used for the RGBWW light.
  30. ledc::LEDCOutput *red;
  31. ledc::LEDCOutput *green;
  32. ledc::LEDCOutput *blue;
  33. ledc::LEDCOutput *white;
  34. gpio::GPIOBinaryOutput *master1;
  35. gpio::GPIOBinaryOutput *master2;
  36. void set_trigger_pin(GPIOPin *pin) { i2c_trigger_pin_ = pin; }
  37. void set_red_pin(ledc::LEDCOutput *pin) { red = pin; }
  38. void set_green_pin(ledc::LEDCOutput *pin) { green = pin; }
  39. void set_blue_pin(ledc::LEDCOutput *pin) { blue = pin; }
  40. void set_white_pin(ledc::LEDCOutput *pin) { white = pin; }
  41. void set_master1_pin(gpio::GPIOBinaryOutput *pin) { master1 = pin; }
  42. void set_master2_pin(gpio::GPIOBinaryOutput *pin) { master2 = pin; }
  43. void set_front_panel_i2c(i2c::I2CComponent *fp_i2c) { fp_i2c_ = fp_i2c; }
  44. void setup() {
  45. ESP_LOGCONFIG(TAG, "Setting up I2C trigger pin interrupt...");
  46. this->i2c_trigger_pin_->setup();
  47. this->i2c_trigger_pin_->attach_interrupt(
  48. TriggerPinStore::isr, &this->trigger_pin_store_, FALLING);
  49. }
  50. void dump_config() {
  51. ESP_LOGCONFIG(TAG, "I2C");
  52. LOG_PIN(" Interrupt pin: ", this->i2c_trigger_pin_);
  53. }
  54. void loop() {
  55. if (this->trigger_pin_store_.queue_length > 0) {
  56. this->counter_++;
  57. ESP_LOGD(TAG, "Front Panel interrupt queue=%d, counter=%d",
  58. this->trigger_pin_store_.queue_length, this->counter_);
  59. this->trigger_pin_store_.queue_length--;
  60. }
  61. }
  62. protected:
  63. // Pin that is used by the front panel to notify the ESP that
  64. // a touch/release event can be read using I2C.
  65. GPIOPin *i2c_trigger_pin_;
  66. // The I2C bus that is connected to the front panel.
  67. i2c::I2CComponent *fp_i2c_;
  68. // Fields that are used for trigger pin interrupt handling.
  69. int counter_ = 0;
  70. TriggerPinStore trigger_pin_store_{};
  71. };
  72. } // namespace bs2
  73. } // namespace yeelight
  74. } // namespace esphome