1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-19 11:42:20 +01:00

ESP-IDF support and generic target platforms (#2303)

* Socket refactor and SSL

* esp-idf temp

* Fixes

* Echo component and noise

* Add noise API transport support

* Updates

* ESP-IDF

* Complete

* Fixes

* Fixes

* Versions update

* New i2c APIs

* Complete i2c refactor

* SPI migration

* Revert ESP Preferences migration, too complex for now

* OTA support

* Remove echo again

* Remove ssl again

* GPIOFlags updates

* Rename esphal and ICACHE_RAM_ATTR

* Make ESP32 arduino compilable again

* Fix GPIO flags

* Complete pin registry refactor and fixes

* Fixes to make test1 compile

* Remove sdkconfig file

* Ignore sdkconfig file

* Fixes in reviewing

* Make test2 compile

* Make test4 compile

* Make test5 compile

* Run clang-format

* Fix lint errors

* Use esp-idf APIs instead of btStart

* Another round of fixes

* Start implementing ESP8266

* Make test3 compile

* Guard esp8266 code

* Lint

* Reformat

* Fixes

* Fixes v2

* more fixes

* ESP-IDF tidy target

* Convert ARDUINO_ARCH_ESPxx

* Update WiFiSignalSensor

* Update time ifdefs

* OTA needs millis from hal

* RestartSwitch needs delay from hal

* ESP-IDF Uart

* Fix OTA blank password

* Allow setting sdkconfig

* Fix idf partitions and allow setting sdkconfig from yaml

* Re-add read/write compat APIs and fix esp8266 uart

* Fix esp8266 store log strings in flash

* Fix ESP32 arduino preferences not initialized

* Update ifdefs

* Change how sdkconfig change is detected

* Add checks to ci-custom and fix them

* Run clang-format

* Add esp-idf clang-tidy target and fix errors

* Fixes from clang-tidy idf round 2

* Fixes from compiling tests with esp-idf

* Run clang-format

* Switch test5.yaml to esp-idf

* Implement ESP8266 Preferences

* Lint

* Re-do PIO package version selection a bit

* Fix arduinoespressif32 package version

* Fix unit tests

* Lint

* Lint fixes

* Fix readv/writev not defined

* Fix graphing component

* Re-add all old options from core/config.py

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Otto Winter
2021-09-20 11:47:51 +02:00
committed by GitHub
parent 1e8e471dec
commit ac0d921413
583 changed files with 9008 additions and 5420 deletions

View File

@@ -3,7 +3,9 @@
#include "esphome/core/application.h"
#include "esphome/core/helpers.h"
#ifdef ARDUINO_ARCH_ESP32
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
#include <esp32-hal-gpio.h>
namespace esphome {
namespace inkplate6 {
@@ -185,7 +187,7 @@ void Inkplate6::eink_on_() {
delay(2);
this->read_byte(0x00, &temperature_, 0);
this->read_register(0x00, nullptr, 0);
this->le_pin_->digital_write(false);
this->oe_pin_->digital_write(false);
@@ -208,7 +210,7 @@ void Inkplate6::fill(Color color) {
memset(this->partial_buffer_, fill, this->get_buffer_length_());
}
ESP_LOGV(TAG, "Fill finished (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Fill finished (%ums)", millis() - start_time);
}
void Inkplate6::display() {
ESP_LOGV(TAG, "Display called");
@@ -218,12 +220,12 @@ void Inkplate6::display() {
this->display3b_();
} else {
if (this->partial_updating_ && this->partial_update_()) {
ESP_LOGV(TAG, "Display finished (partial) (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Display finished (partial) (%ums)", millis() - start_time);
return;
}
this->display1b_();
}
ESP_LOGV(TAG, "Display finished (full) (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Display finished (full) (%ums)", millis() - start_time);
}
void Inkplate6::display1b_() {
ESP_LOGV(TAG, "Display1b called");
@@ -246,32 +248,32 @@ void Inkplate6::display1b_() {
clean_fast_(0, 11);
uint32_t clock = (1 << this->cl_pin_->get_pin());
ESP_LOGV(TAG, "Display1b start loops (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Display1b start loops (%ums)", millis() - start_time);
for (int k = 0; k < 3; k++) {
buffer_ptr = &this->buffer_[this->get_buffer_length_() - 1];
vscan_start_();
for (int i = 0; i < this->get_height_internal(); i++) {
buffer_value = *(buffer_ptr--);
data = LUTB[(buffer_value >> 4) & 0x0F];
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25);
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25);
hscan_start_(send);
data = LUTB[buffer_value & 0x0F];
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25) | clock;
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
for (int j = 0, jm = (this->get_width_internal() / 8) - 1; j < jm; j++) {
buffer_value = *(buffer_ptr--);
data = LUTB[(buffer_value >> 4) & 0x0F];
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25) | clock;
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
data = LUTB[buffer_value & 0x0F];
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25) | clock;
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
}
@@ -281,31 +283,31 @@ void Inkplate6::display1b_() {
}
delayMicroseconds(230);
}
ESP_LOGV(TAG, "Display1b first loop x %d (%lums)", 3, millis() - start_time);
ESP_LOGV(TAG, "Display1b first loop x %d (%ums)", 3, millis() - start_time);
buffer_ptr = &this->buffer_[this->get_buffer_length_() - 1];
vscan_start_();
for (int i = 0; i < this->get_height_internal(); i++) {
buffer_value = *(buffer_ptr--);
data = LUT2[(buffer_value >> 4) & 0x0F];
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25);
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25);
hscan_start_(send);
data = LUT2[buffer_value & 0x0F];
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25) | clock;
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
for (int j = 0, jm = (this->get_width_internal() / 8) - 1; j < jm; j++) {
buffer_value = *(buffer_ptr--);
data = LUT2[(buffer_value >> 4) & 0x0F];
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25) | clock;
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
data = LUT2[buffer_value & 0x0F];
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25) | clock;
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
}
@@ -314,13 +316,13 @@ void Inkplate6::display1b_() {
vscan_end_();
}
delayMicroseconds(230);
ESP_LOGV(TAG, "Display1b second loop (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Display1b second loop (%ums)", millis() - start_time);
vscan_start_();
for (int i = 0; i < this->get_height_internal(); i++) {
data = 0b00000000;
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25);
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25);
hscan_start_(send);
send |= clock;
GPIO.out_w1ts = send;
@@ -336,13 +338,13 @@ void Inkplate6::display1b_() {
vscan_end_();
}
delayMicroseconds(230);
ESP_LOGV(TAG, "Display1b third loop (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Display1b third loop (%ums)", millis() - start_time);
vscan_start_();
eink_off_();
this->block_partial_ = false;
this->partial_updates_ = 0;
ESP_LOGV(TAG, "Display1b finished (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Display1b finished (%ums)", millis() - start_time);
}
void Inkplate6::display3b_() {
ESP_LOGV(TAG, "Display3b called");
@@ -380,11 +382,11 @@ void Inkplate6::display3b_() {
pixel2 = (waveform3Bit[pix3 & 0x07][k] << 6) | (waveform3Bit[(pix3 >> 4) & 0x07][k] << 4) |
(waveform3Bit[pix4 & 0x07][k] << 2) | (waveform3Bit[(pix4 >> 4) & 0x07][k] << 0);
send = ((pixel & B00000011) << 4) | (((pixel & B00001100) >> 2) << 18) | (((pixel & B00010000) >> 4) << 23) |
(((pixel & B11100000) >> 5) << 25);
send = ((pixel & 0b00000011) << 4) | (((pixel & 0b00001100) >> 2) << 18) | (((pixel & 0b00010000) >> 4) << 23) |
(((pixel & 0b11100000) >> 5) << 25);
hscan_start_(send);
send = ((pixel2 & B00000011) << 4) | (((pixel2 & B00001100) >> 2) << 18) | (((pixel2 & B00010000) >> 4) << 23) |
(((pixel2 & B11100000) >> 5) << 25) | clock;
send = ((pixel2 & 0b00000011) << 4) | (((pixel2 & 0b00001100) >> 2) << 18) |
(((pixel2 & 0b00010000) >> 4) << 23) | (((pixel2 & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
@@ -398,13 +400,13 @@ void Inkplate6::display3b_() {
pixel2 = (waveform3Bit[pix3 & 0x07][k] << 6) | (waveform3Bit[(pix3 >> 4) & 0x07][k] << 4) |
(waveform3Bit[pix4 & 0x07][k] << 2) | (waveform3Bit[(pix4 >> 4) & 0x07][k] << 0);
send = ((pixel & B00000011) << 4) | (((pixel & B00001100) >> 2) << 18) | (((pixel & B00010000) >> 4) << 23) |
(((pixel & B11100000) >> 5) << 25) | clock;
send = ((pixel & 0b00000011) << 4) | (((pixel & 0b00001100) >> 2) << 18) | (((pixel & 0b00010000) >> 4) << 23) |
(((pixel & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
send = ((pixel2 & B00000011) << 4) | (((pixel2 & B00001100) >> 2) << 18) | (((pixel2 & B00010000) >> 4) << 23) |
(((pixel2 & B11100000) >> 5) << 25) | clock;
send = ((pixel2 & 0b00000011) << 4) | (((pixel2 & 0b00001100) >> 2) << 18) |
(((pixel2 & 0b00010000) >> 4) << 23) | (((pixel2 & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
}
@@ -418,7 +420,7 @@ void Inkplate6::display3b_() {
clean_fast_(3, 1);
vscan_start_();
eink_off_();
ESP_LOGV(TAG, "Display3b finished (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Display3b finished (%ums)", millis() - start_time);
}
bool Inkplate6::partial_update_() {
ESP_LOGV(TAG, "Partial update called");
@@ -445,7 +447,7 @@ bool Inkplate6::partial_update_() {
this->partial_buffer_2_[n--] = LUTW[diffw & 0x0F] & LUTB[diffb & 0x0F];
}
}
ESP_LOGV(TAG, "Partial update buffer built after (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Partial update buffer built after (%ums)", millis() - start_time);
eink_on_();
uint32_t clock = (1 << this->cl_pin_->get_pin());
@@ -454,13 +456,13 @@ bool Inkplate6::partial_update_() {
const uint8_t *data_ptr = &this->partial_buffer_2_[(this->get_buffer_length_() * 2) - 1];
for (int i = 0; i < this->get_height_internal(); i++) {
data = *(data_ptr--);
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25);
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25);
hscan_start_(send);
for (int j = 0, jm = (this->get_width_internal() / 4) - 1; j < jm; j++) {
data = *(data_ptr--);
send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25) | clock;
send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25) | clock;
GPIO.out_w1ts = send;
GPIO.out_w1tc = send;
}
@@ -469,7 +471,7 @@ bool Inkplate6::partial_update_() {
vscan_end_();
}
delayMicroseconds(230);
ESP_LOGV(TAG, "Partial update loop k=%d (%lums)", k, millis() - start_time);
ESP_LOGV(TAG, "Partial update loop k=%d (%ums)", k, millis() - start_time);
}
clean_fast_(2, 2);
clean_fast_(3, 1);
@@ -477,7 +479,7 @@ bool Inkplate6::partial_update_() {
eink_off_();
memcpy(this->buffer_, this->partial_buffer_, this->get_buffer_length_());
ESP_LOGV(TAG, "Partial update finished (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Partial update finished (%ums)", millis() - start_time);
return true;
}
void Inkplate6::vscan_start_() {
@@ -538,7 +540,7 @@ void Inkplate6::clean() {
clean_fast_(0, 8); // Black to Black
clean_fast_(2, 1); // Black to White
clean_fast_(1, 10); // White to White
ESP_LOGV(TAG, "Clean finished (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Clean finished (%ums)", millis() - start_time);
}
void Inkplate6::clean_fast_(uint8_t c, uint8_t rep) {
ESP_LOGV(TAG, "Clean fast called with: (%d, %d)", c, rep);
@@ -547,16 +549,16 @@ void Inkplate6::clean_fast_(uint8_t c, uint8_t rep) {
eink_on_();
uint8_t data = 0;
if (c == 0) // White
data = B10101010;
data = 0b10101010;
else if (c == 1) // Black
data = B01010101;
data = 0b01010101;
else if (c == 2) // Discharge
data = B00000000;
data = 0b00000000;
else if (c == 3) // Skip
data = B11111111;
data = 0b11111111;
uint32_t send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) |
(((data & B11100000) >> 5) << 25);
uint32_t send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25);
uint32_t clock = (1 << this->cl_pin_->get_pin());
for (int k = 0; k < rep; k++) {
@@ -576,46 +578,46 @@ void Inkplate6::clean_fast_(uint8_t c, uint8_t rep) {
vscan_end_();
}
delayMicroseconds(230);
ESP_LOGV(TAG, "Clean fast rep loop %d finished (%lums)", k, millis() - start_time);
ESP_LOGV(TAG, "Clean fast rep loop %d finished (%ums)", k, millis() - start_time);
}
ESP_LOGV(TAG, "Clean fast finished (%lums)", millis() - start_time);
ESP_LOGV(TAG, "Clean fast finished (%ums)", millis() - start_time);
}
void Inkplate6::pins_z_state_() {
this->ckv_pin_->pin_mode(INPUT);
this->sph_pin_->pin_mode(INPUT);
this->ckv_pin_->pin_mode(gpio::FLAG_INPUT);
this->sph_pin_->pin_mode(gpio::FLAG_INPUT);
this->oe_pin_->pin_mode(INPUT);
this->gmod_pin_->pin_mode(INPUT);
this->spv_pin_->pin_mode(INPUT);
this->oe_pin_->pin_mode(gpio::FLAG_INPUT);
this->gmod_pin_->pin_mode(gpio::FLAG_INPUT);
this->spv_pin_->pin_mode(gpio::FLAG_INPUT);
this->display_data_0_pin_->pin_mode(INPUT);
this->display_data_1_pin_->pin_mode(INPUT);
this->display_data_2_pin_->pin_mode(INPUT);
this->display_data_3_pin_->pin_mode(INPUT);
this->display_data_4_pin_->pin_mode(INPUT);
this->display_data_5_pin_->pin_mode(INPUT);
this->display_data_6_pin_->pin_mode(INPUT);
this->display_data_7_pin_->pin_mode(INPUT);
this->display_data_0_pin_->pin_mode(gpio::FLAG_INPUT);
this->display_data_1_pin_->pin_mode(gpio::FLAG_INPUT);
this->display_data_2_pin_->pin_mode(gpio::FLAG_INPUT);
this->display_data_3_pin_->pin_mode(gpio::FLAG_INPUT);
this->display_data_4_pin_->pin_mode(gpio::FLAG_INPUT);
this->display_data_5_pin_->pin_mode(gpio::FLAG_INPUT);
this->display_data_6_pin_->pin_mode(gpio::FLAG_INPUT);
this->display_data_7_pin_->pin_mode(gpio::FLAG_INPUT);
}
void Inkplate6::pins_as_outputs_() {
this->ckv_pin_->pin_mode(OUTPUT);
this->sph_pin_->pin_mode(OUTPUT);
this->ckv_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->sph_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->oe_pin_->pin_mode(OUTPUT);
this->gmod_pin_->pin_mode(OUTPUT);
this->spv_pin_->pin_mode(OUTPUT);
this->oe_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->gmod_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->spv_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->display_data_0_pin_->pin_mode(OUTPUT);
this->display_data_1_pin_->pin_mode(OUTPUT);
this->display_data_2_pin_->pin_mode(OUTPUT);
this->display_data_3_pin_->pin_mode(OUTPUT);
this->display_data_4_pin_->pin_mode(OUTPUT);
this->display_data_5_pin_->pin_mode(OUTPUT);
this->display_data_6_pin_->pin_mode(OUTPUT);
this->display_data_7_pin_->pin_mode(OUTPUT);
this->display_data_0_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->display_data_1_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->display_data_2_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->display_data_3_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->display_data_4_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->display_data_5_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->display_data_6_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->display_data_7_pin_->pin_mode(gpio::FLAG_OUTPUT);
}
} // namespace inkplate6
} // namespace esphome
#endif
#endif // USE_ESP32_FRAMEWORK_ARDUINO