summaryrefslogtreecommitdiffstatshomepage
path: root/ports/esp32/machine_pwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'ports/esp32/machine_pwm.c')
-rw-r--r--ports/esp32/machine_pwm.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/ports/esp32/machine_pwm.c b/ports/esp32/machine_pwm.c
index 445ac80fb2..462d0fa79c 100644
--- a/ports/esp32/machine_pwm.c
+++ b/ports/esp32/machine_pwm.c
@@ -34,6 +34,7 @@
#include "driver/ledc.h"
#include "esp_err.h"
+#include "soc/gpio_sig_map.h"
#define PWM_DBG(...)
// #define PWM_DBG(...) mp_printf(&mp_plat_print, __VA_ARGS__); mp_printf(&mp_plat_print, "\n");
@@ -164,13 +165,13 @@ STATIC void pwm_deinit(int channel_idx) {
// Mark it unused, and tell the hardware to stop routing
check_esp_err(ledc_stop(mode, channel, 0));
// Disable ledc signal for the pin
- // gpio_matrix_out(pin, SIG_GPIO_OUT_IDX, false, false);
+ // esp_rom_gpio_connect_out_signal(pin, SIG_GPIO_OUT_IDX, false, false);
if (mode == LEDC_LOW_SPEED_MODE) {
- gpio_matrix_out(pin, LEDC_LS_SIG_OUT0_IDX + channel, false, true);
+ esp_rom_gpio_connect_out_signal(pin, LEDC_LS_SIG_OUT0_IDX + channel, false, true);
} else {
#if LEDC_SPEED_MODE_MAX > 1
#if CONFIG_IDF_TARGET_ESP32
- gpio_matrix_out(pin, LEDC_HS_SIG_OUT0_IDX + channel, false, true);
+ esp_rom_gpio_connect_out_signal(pin, LEDC_HS_SIG_OUT0_IDX + channel, false, true);
#else
#error Add supported CONFIG_IDF_TARGET_ESP32_xxx
#endif
@@ -209,18 +210,13 @@ STATIC void configure_channel(machine_pwm_obj_t *self) {
STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_config_t *timer) {
if (freq != timer->freq_hz) {
// Find the highest bit resolution for the requested frequency
- unsigned int i = LEDC_APB_CLK_HZ; // 80 MHz
+ unsigned int i = APB_CLK_FREQ; // 80 MHz
#if SOC_LEDC_SUPPORT_REF_TICK
if (freq < EMPIRIC_FREQ) {
- i = LEDC_REF_CLK_HZ; // 1 MHz
+ i = REF_CLK_FREQ; // 1 MHz
}
#endif
- #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
- // original code
- i /= freq;
- #else
- // See https://github.com/espressif/esp-idf/issues/7722
int divider = (i + freq / 2) / freq; // rounded
if (divider == 0) {
divider = 1;
@@ -230,7 +226,6 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
f = 1.0;
}
i = (unsigned int)roundf((float)i / f);
- #endif
unsigned int res = 0;
for (; i > 1; i >>= 1) {
@@ -354,7 +349,7 @@ STATIC void set_duty_u16(machine_pwm_obj_t *self, int duty) {
// See https://github.com/espressif/esp-idf/issues/7288
if (duty != get_duty_u16(self)) {
PWM_DBG("set_duty_u16(%u), get_duty_u16():%u, channel_duty:%d, duty_resolution:%d, freq_hz:%d", duty, get_duty_u16(self), channel_duty, timer.duty_resolution, timer.freq_hz);
- ets_delay_us(2 * 1000000 / timer.freq_hz);
+ esp_rom_delay_us(2 * 1000000 / timer.freq_hz);
if (duty != get_duty_u16(self)) {
PWM_DBG("set_duty_u16(%u), get_duty_u16():%u, channel_duty:%d, duty_resolution:%d, freq_hz:%d", duty, get_duty_u16(self), channel_duty, timer.duty_resolution, timer.freq_hz);
}