Misc fixes for ledc

This commit is contained in:
DTTerastar 2022-09-06 17:44:30 -04:00
parent 850aaf829e
commit 7d65fb46a0
4 changed files with 19 additions and 2 deletions

View File

@ -119,6 +119,7 @@ build_unflags = ${esp32c3.build_unflags}
build_flags =
-D FIRMWARE='"esp32c3"'
-D SENSORS
-D ESP32C3
${esp32c3.build_flags}
[env:esp32-verbose]

View File

@ -71,6 +71,13 @@
#define DEFAULT_I2C_BUS_2_SCL 21
#define DEFAULT_I2C_BUS 1
#else
#ifdef ESP32C3
#define DEFAULT_I2C_BUS_1_SDA 19
#define DEFAULT_I2C_BUS_1_SCL 18
#define DEFAULT_I2C_BUS_2_SDA -1
#define DEFAULT_I2C_BUS_2_SCL -1
#define DEFAULT_I2C_BUS 1
#else
#define DEFAULT_I2C_BUS_1_SDA 21
#define DEFAULT_I2C_BUS_1_SCL 22
#define DEFAULT_I2C_BUS_2_SDA -1
@ -78,6 +85,7 @@
#define DEFAULT_I2C_BUS 1
#endif
#endif
#endif
// TSL2561 Defaults
#define DEFAULT_TSL2561_I2C_GAIN "auto"

View File

@ -5,13 +5,19 @@ SinglePWM::SinglePWM(uint8_t index, ControlType controlType, bool inverted, int
this->pin = pin;
}
void SinglePWM::begin() {
ledcSetup(LED::getIndex(), 12000, 12);
void SinglePWM::init() {
inited = true;
pinMode(pin, OUTPUT);
ledcSetup(LED::getIndex(), 5000, 12);
ledcAttachPin(pin, getIndex());
}
void SinglePWM::begin() {
setDuty(LED::getBrightness());
}
void SinglePWM::setDuty(uint32_t x) {
if (!inited) init();
uint32_t duty = x >= 255 ? 4096 : (x <= 0 ? 0 : round(4096.0 * pow(10.0, 0.0055 * (x - 255.0))));
if (inverted) duty = 4096 - duty;
ledcWrite(LED::getIndex(), duty);

View File

@ -13,7 +13,9 @@ class SinglePWM : public LED {
bool setBrightness(uint8_t brightness) override;
private:
void init();
void setDuty(uint32_t value);
bool inverted;
int pin;
bool inited = false;
};