mirror of
https://github.com/jscrane/r65emu.git
synced 2025-01-03 04:30:38 +00:00
use waveform generator on esp8266
This commit is contained in:
parent
8681074427
commit
231041d7aa
@ -40,28 +40,32 @@ void PWM::set_freq(unsigned freq) {
|
|||||||
ESP_ERROR_CHECK(::ledc_set_freq(SPEED_MODE, TIMER, freq));
|
ESP_ERROR_CHECK(::ledc_set_freq(SPEED_MODE, TIMER, freq));
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(PWM_SOUND)
|
#elif defined(ESP8266)
|
||||||
static unsigned pin;
|
#include <core_esp8266_waveform.h>
|
||||||
|
|
||||||
|
static unsigned gpio, duty;
|
||||||
|
const unsigned period = 1024;
|
||||||
|
|
||||||
void PWM::begin(unsigned gpio) {
|
void PWM::begin(unsigned gpio) {
|
||||||
pin = gpio;
|
::gpio = gpio;
|
||||||
analogWriteRange(PWM_TOP);
|
pinMode(gpio, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PWM::set_duty(unsigned duty) {
|
void PWM::set_duty(unsigned duty) {
|
||||||
analogWrite(pin, duty);
|
::duty = duty;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PWM::stop() {
|
void PWM::stop() {
|
||||||
analogWrite(pin, 0);
|
stopWaveform(gpio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PWM::set_freq(unsigned freq) {
|
void PWM::set_freq(unsigned freq) {
|
||||||
analogWriteFreq(freq);
|
uint32_t t = 1000000 / freq;
|
||||||
|
uint32_t h = duty * t / period;
|
||||||
|
startWaveform(gpio, h, t-h, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void PWM::begin(unsigned gpio) {
|
void PWM::begin(unsigned gpio) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user