to be compatible with Arduino master.
This commit is contained in:
Jason2866 2020-07-30 13:41:51 +02:00 committed by GitHub
parent ba79dc0415
commit 3b7305f20c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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")));
};