mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
allow to set pin to OUTPUT_OPEN_DRAIN in analogWriteMode (#7841)
* allow to set pin to OUTPUT_OPEN_DRAIN in analogWrite * remove parameter with default value * Update core_esp8266_wiring_pwm.cpp * update documentation accordingly
This commit is contained in:
parent
53e5688453
commit
f2d83ba43d
@ -171,6 +171,7 @@ int digitalRead(uint8_t pin);
|
||||
int analogRead(uint8_t pin);
|
||||
void analogReference(uint8_t mode);
|
||||
void analogWrite(uint8_t pin, int val);
|
||||
void analogWriteMode(uint8_t pin, int val, bool openDrain);
|
||||
void analogWriteFreq(uint32_t freq);
|
||||
void analogWriteResolution(int res);
|
||||
void analogWriteRange(uint32_t range);
|
||||
|
@ -44,6 +44,10 @@ extern void __analogWriteFreq(uint32_t freq) {
|
||||
}
|
||||
|
||||
extern void __analogWrite(uint8_t pin, int val) {
|
||||
analogWriteMode(pin, val, false);
|
||||
}
|
||||
|
||||
extern void __analogWriteMode(uint8_t pin, int val, bool openDrain) {
|
||||
if (pin > 16) {
|
||||
return;
|
||||
}
|
||||
@ -62,8 +66,12 @@ extern void __analogWrite(uint8_t pin, int val) {
|
||||
analogMap &= ~(1 << pin);
|
||||
}
|
||||
else {
|
||||
if(openDrain) {
|
||||
pinMode(pin, OUTPUT_OPEN_DRAIN);
|
||||
} else {
|
||||
pinMode(pin, OUTPUT);
|
||||
}
|
||||
}
|
||||
uint32_t high = (analogPeriod * val) / analogScale;
|
||||
uint32_t low = analogPeriod - high;
|
||||
// Find the first GPIO being generated by checking GCC's find-first-set (returns 1 + the bit of the first 1 in an int32_t)
|
||||
@ -88,6 +96,7 @@ extern void __analogWriteResolution(int res) {
|
||||
}
|
||||
|
||||
extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite")));
|
||||
extern void analogWriteMode(uint8_t pin, int val, bool openDrain) __attribute__((weak, alias("__analogWriteMode")));
|
||||
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")));
|
||||
|
@ -109,6 +109,9 @@ PWM range may be changed by calling ``analogWriteRange(new_range)`` or
|
||||
``analogWriteResolution(bits)``. ``new_range`` may be from 15...65535
|
||||
or ``bits`` may be from 4...16.
|
||||
|
||||
The function ``analogWriteMode(pin, value, openDrain)`` allows to sets
|
||||
the pin mode to ``OUTPUT_OPEN_DRAIN`` instead of ``OUTPUT``.
|
||||
|
||||
**NOTE:** The default ``analogWrite`` range was 1023 in releases before
|
||||
3.0, but this lead to incompatibility with external libraries which
|
||||
depended on the Arduino core default of 256. Existing applications which
|
||||
|
Loading…
x
Reference in New Issue
Block a user