Skip to content

Commit c095fec

Browse files
committed
zephyrCommon: Improve analogWrite
- Replace pwm_set_cycles with pwm_set_pulse_dt. - Add check to ensure that pwm pin is ready Signed-off-by: Ayush Singh <[email protected]>
1 parent 347a80d commit c095fec

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cores/arduino/zephyrCommon.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ void analogWrite(pin_size_t pinNumber, int value)
217217
{
218218
size_t idx = pwm_pin_index(pinNumber);
219219

220+
if (!pwm_is_ready_dt(&arduino_pwm[idx])) {
221+
return;
222+
}
223+
220224
if (idx >= ARRAY_SIZE(arduino_pwm) ) {
221225
return;
222226
}
@@ -231,8 +235,7 @@ void analogWrite(pin_size_t pinNumber, int value)
231235
* A duty ratio determines by the period value defined in dts
232236
* and the value arguments. So usually the period value sets as 255.
233237
*/
234-
(void)pwm_set_cycles(arduino_pwm[idx].dev, arduino_pwm[idx].channel,
235-
arduino_pwm[idx].period, value, arduino_pwm[idx].flags);
238+
(void)pwm_set_pulse_dt(&arduino_pwm[idx], value);
236239
}
237240

238241
#endif

0 commit comments

Comments
 (0)