arduino / arduino/ArduinoCore-samd
_writeResolution, set by analogWriteResolution(), is shared by the DAC and PWM
- Dominant language
- C
- Stars
- 502
- Forks
- 740
- PR merge metrics
- No merged PRs in 30d
Description
The resolution value _writeResolution, set by analogWriteResolution(), is shared by the DAC and PWM. There is no reason why this needs to be so.
I recommend the following changes to fix this:
```
28c31,32
< static int _writeResolution = 8;
---
> static int _writeResolution_DAC = 8;
> static int _writeResolution_PWM = 8;
74c78,89
< _writeResolution = res;
---
> _writeResolution_DAC = res;
> _writeResolution_PWM = res;
> }
>
> void analogWriteResolution_DAC(int res)
> {
> _writeResolution_DAC = res;
> }
>
> void analogWriteResolution_PWM(int res)
> {
> _writeResolution_PWM = res;
207c240
< value = mapResolution(value, _writeResolution, 10);
---
> value = mapResolution(value, _writeResolution_DAC, 10);
219c252
< value = mapResolution(value, _writeResolution, 16);
---
> value = mapResolution(value, _writeResolution_PWM, 16);
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate analogWriteResolution(), analogWriteResolution_DAC(), analogWriteResolution_PWM(), and the DAC and PWM paths that call mapResolution(). Review how _writeResolution is currently used, then verify that DAC and PWM retain independent resolution values and that the proposed APIs behave as specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100