Misc fixes for ledc
This commit is contained in:
parent
850aaf829e
commit
7d65fb46a0
|
@ -119,6 +119,7 @@ build_unflags = ${esp32c3.build_unflags}
|
||||||
build_flags =
|
build_flags =
|
||||||
-D FIRMWARE='"esp32c3"'
|
-D FIRMWARE='"esp32c3"'
|
||||||
-D SENSORS
|
-D SENSORS
|
||||||
|
-D ESP32C3
|
||||||
${esp32c3.build_flags}
|
${esp32c3.build_flags}
|
||||||
|
|
||||||
[env:esp32-verbose]
|
[env:esp32-verbose]
|
||||||
|
|
|
@ -71,6 +71,13 @@
|
||||||
#define DEFAULT_I2C_BUS_2_SCL 21
|
#define DEFAULT_I2C_BUS_2_SCL 21
|
||||||
#define DEFAULT_I2C_BUS 1
|
#define DEFAULT_I2C_BUS 1
|
||||||
#else
|
#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_SDA 21
|
||||||
#define DEFAULT_I2C_BUS_1_SCL 22
|
#define DEFAULT_I2C_BUS_1_SCL 22
|
||||||
#define DEFAULT_I2C_BUS_2_SDA -1
|
#define DEFAULT_I2C_BUS_2_SDA -1
|
||||||
|
@ -78,6 +85,7 @@
|
||||||
#define DEFAULT_I2C_BUS 1
|
#define DEFAULT_I2C_BUS 1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// TSL2561 Defaults
|
// TSL2561 Defaults
|
||||||
#define DEFAULT_TSL2561_I2C_GAIN "auto"
|
#define DEFAULT_TSL2561_I2C_GAIN "auto"
|
||||||
|
|
|
@ -5,13 +5,19 @@ SinglePWM::SinglePWM(uint8_t index, ControlType controlType, bool inverted, int
|
||||||
this->pin = pin;
|
this->pin = pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SinglePWM::begin() {
|
void SinglePWM::init() {
|
||||||
ledcSetup(LED::getIndex(), 12000, 12);
|
inited = true;
|
||||||
|
pinMode(pin, OUTPUT);
|
||||||
|
ledcSetup(LED::getIndex(), 5000, 12);
|
||||||
ledcAttachPin(pin, getIndex());
|
ledcAttachPin(pin, getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SinglePWM::begin() {
|
||||||
setDuty(LED::getBrightness());
|
setDuty(LED::getBrightness());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SinglePWM::setDuty(uint32_t x) {
|
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))));
|
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;
|
if (inverted) duty = 4096 - duty;
|
||||||
ledcWrite(LED::getIndex(), duty);
|
ledcWrite(LED::getIndex(), duty);
|
||||||
|
|
|
@ -13,7 +13,9 @@ class SinglePWM : public LED {
|
||||||
bool setBrightness(uint8_t brightness) override;
|
bool setBrightness(uint8_t brightness) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void init();
|
||||||
void setDuty(uint32_t value);
|
void setDuty(uint32_t value);
|
||||||
bool inverted;
|
bool inverted;
|
||||||
int pin;
|
int pin;
|
||||||
|
bool inited = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue