Skip to content

Commit 7e58ca1

Browse files
facchinmsoburi
authored andcommitted
analogWrite: implement DAC pins
1 parent 2656df1 commit 7e58ca1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cores/arduino/Arduino.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ enum dacPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), dac_channels, DAC_ENUM
6464

6565
#endif
6666

67+
#ifdef CONFIG_DAC
68+
69+
#undef DAC0
70+
#undef DAC1
71+
#undef DAC2
72+
#undef DAC3
73+
#define DAC_ENUMS(n, p, i) DAC ## i = i,
74+
enum dacPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), dac_channels, DAC_ENUMS) NUM_OF_DACS };
75+
76+
#endif
77+
6778
void interrupts(void);
6879
void noInterrupts(void);
6980

cores/arduino/zephyrCommon.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ int analogWriteResolution() {
329329
}
330330
#endif
331331

332+
#if defined(CONFIG_DAC) || defined(CONFIG_PWM)
333+
static int _analog_write_resolution = 8;
334+
void analogWriteResolution(int bits) {
335+
_analog_write_resolution = bits;
336+
}
337+
int analogWriteResolution() {
338+
return _analog_write_resolution;
339+
}
340+
#endif
341+
332342
#ifdef CONFIG_PWM
333343

334344
void analogWrite(pin_size_t pinNumber, int value)

0 commit comments

Comments
 (0)