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.

82 lines
2.6 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
  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. namespace esphome {
  8. namespace yeelight {
  9. namespace bs2 {
  10. struct TriggerPinStore {
  11. volatile int queue_length = 0;
  12. static void isr(TriggerPinStore *store);
  13. };
  14. /**
  15. * This ISR is used to handle IRQ triggers from the front panel.
  16. *
  17. * The front panel pulls the trigger pin low when a new event
  18. * is available. All we do here to handle the interrupt, is
  19. * increment a simple queue length counter. Reading the event
  20. * from the I2C bus will be handled in the main loop, based
  21. * on this counter.
  22. */
  23. void ICACHE_RAM_ATTR HOT TriggerPinStore::isr(TriggerPinStore *store) {
  24. store->queue_length++;
  25. }
  26. class YeelightBS2Hub : public Component {
  27. public:
  28. // Pins that are used for the RGBWW light.
  29. ledc::LEDCOutput *red;
  30. ledc::LEDCOutput *green;
  31. ledc::LEDCOutput *blue;
  32. ledc::LEDCOutput *white;
  33. gpio::GPIOBinaryOutput *master1;
  34. gpio::GPIOBinaryOutput *master2;
  35. void set_trigger_pin(GPIOPin *pin) { i2c_trigger_pin_ = pin; }
  36. void set_red_pin(ledc::LEDCOutput *pin) { red = pin; }
  37. void set_green_pin(ledc::LEDCOutput *pin) { green = pin; }
  38. void set_blue_pin(ledc::LEDCOutput *pin) { blue = pin; }
  39. void set_white_pin(ledc::LEDCOutput *pin) { white = pin; }
  40. void set_master1_pin(gpio::GPIOBinaryOutput *pin) { master1 = pin; }
  41. void set_master2_pin(gpio::GPIOBinaryOutput *pin) { master2 = pin; }
  42. void setup() {
  43. ESP_LOGCONFIG(TAG, "Setting up I2C trigger pin interrupt...");
  44. this->i2c_trigger_pin_->setup();
  45. this->i2c_trigger_pin_->attach_interrupt(
  46. TriggerPinStore::isr, &this->trigger_pin_store_, FALLING);
  47. }
  48. void dump_config() {
  49. ESP_LOGCONFIG(TAG, "I2C");
  50. LOG_PIN(" Interrupt pin: ", this->i2c_trigger_pin_);
  51. }
  52. void loop() {
  53. if (this->trigger_pin_store_.queue_length > 0) {
  54. this->counter_++;
  55. ESP_LOGD(TAG, "Front Panel interrupt queue=%d, counter=%d",
  56. this->trigger_pin_store_.queue_length, this->counter_);
  57. this->trigger_pin_store_.queue_length--;
  58. }
  59. }
  60. protected:
  61. // Pin that is used by the front panel to notify the ESP that
  62. // a touch/release event can be read using I2C.
  63. GPIOPin *i2c_trigger_pin_;
  64. // Fields that are used for trigger pin interrupt handling.
  65. int counter_ = 0;
  66. TriggerPinStore trigger_pin_store_{};
  67. };
  68. } // namespace bs2
  69. } // namespace yeelight
  70. } // namespace esphome