Skip to content

Commit 2c43b81

Browse files
author
Richard Unger
committed
add 1-PWM support to esp8266 driver
1 parent 07090bc commit 2c43b81

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/drivers/hardware_specific/esp8266_mcu.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ void _setHighFrequency(const long freq, const int pin){
1212
}
1313

1414

15+
// function setting the high pwm frequency to the supplied pins
16+
// - Stepper motor - 2PWM setting
17+
// - hardware speciffic
18+
void* _configure1PWM(long pwm_frequency, const int pinA) {
19+
if(!pwm_frequency || !_isset(pwm_frequency) ) pwm_frequency = _PWM_FREQUENCY; // default frequency 25khz
20+
else pwm_frequency = _constrain(pwm_frequency, 0, _PWM_FREQUENCY_MAX); // constrain to 50kHz max
21+
_setHighFrequency(pwm_frequency, pinA);
22+
GenericDriverParams* params = new GenericDriverParams {
23+
.pins = { pinA },
24+
.pwm_frequency = pwm_frequency
25+
};
26+
return params;
27+
}
28+
29+
30+
1531
// function setting the high pwm frequency to the supplied pins
1632
// - Stepper motor - 2PWM setting
1733
// - hardware speciffic
@@ -60,6 +76,13 @@ void* _configure4PWM(long pwm_frequency,const int pinA, const int pinB, const in
6076
return params;
6177
}
6278

79+
// function setting the pwm duty cycle to the hardware
80+
// - Stepper motor - 2PWM setting
81+
// - hardware speciffic
82+
void _writeDutyCycle1PWM(float dc_a, void* params){
83+
// transform duty cycle from [0,1] to [0,255]
84+
analogWrite(((GenericDriverParams*)params)->pins[0], 255.0f*dc_a);
85+
}
6386
// function setting the pwm duty cycle to the hardware
6487
// - Stepper motor - 2PWM setting
6588
// - hardware speciffic

0 commit comments

Comments
 (0)