Merge pull request #8998 from Jason2866/patch-1

Add changes from https://github.com/esp8266/Arduino/commit/a6798691
This commit is contained in:
Theo Arends 2020-07-30 16:04:01 +02:00 committed by GitHub
commit 4068759a3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -29,15 +29,21 @@
extern "C" {
static uint32_t analogMap = 0;
static int32_t analogScale = PWMRANGE;
static int32_t analogScale = 255; // Match upstream default, breaking change from 2.x.x
static uint16_t analogFreq = 1000;
extern void __analogWriteRange(uint32_t range) {
if (range > 0) {
if ((range >= 15) && (range <= 65535)) {
analogScale = range;
}
}
extern void __analogWriteResolution(int res) {
if ((res >= 4) && (res <= 16)) {
analogScale = (1 << res) - 1;
}
}
extern void __analogWriteFreq(uint32_t freq) {
if (freq < 40) {
analogFreq = 40;
@ -61,6 +67,10 @@ extern void __analogWrite(uint8_t pin, int val) {
val = analogScale;
}
// Per the Arduino docs at https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
// val: the duty cycle: between 0 (always off) and 255 (always on).
// So if val = 0 we have digitalWrite(LOW), if we have val==range we have digitalWrite(HIGH)
if (analogMap & 1UL << pin) {
analogMap &= ~(1 << pin);
}
@ -79,6 +89,7 @@ extern void __analogWrite(uint8_t pin, int val) {
extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite")));
extern void analogWriteFreq(uint32_t freq) __attribute__((weak, alias("__analogWriteFreq")));
extern void analogWriteRange(uint32_t range) __attribute__((weak, alias("__analogWriteRange")));
extern void analogWriteResolution(int res) __attribute__((weak, alias("__analogWriteResolution")));
};