8000 esp32/machine_pwm: Add constants clock defintion. · micropython/micropython@51f1700 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51f1700

Browse files
committed
esp32/machine_pwm: Add constants clock defintion.
Add MP_ROM_QSTR(MP_QSTR_PWM_AUTO_CLK) etc... to have the constant for clock source in the python PWM object. extmod/machine_pwm: File has been updated to use (optionaly) the MICROPY_PY_MACHINE_PWM_CLASS_CONSTANTS define that should hold the constants. Signed-off-by: Yoann Darche <yoannd@hotmail.com>
1 parent 4bf685f commit 51f1700

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

extmod/machine_pwm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ static const mp_rom_map_elem_t machine_pwm_locals_dict_table[] = {
134134
#endif
135135
{ MP_ROM_QSTR(MP_QSTR_duty_u16), MP_ROM_PTR(&machine_pwm_duty_u16_obj) },
136136
{ MP_ROM_QSTR(MP_QSTR_duty_ns), MP_ROM_PTR(&machine_pwm_duty_ns_obj) },
137+
138+
// A port must add PWM class constants defining the following macro.
139+
// It can be defined to nothing if there are no constants.
140+
#ifdef MICROPY_PY_MACHINE_PWM_CLASS_CONSTANTS
141+
MICROPY_PY_MACHINE_PWM_CLASS_CONSTANTS
142+
#endif
137143
};
138144
static MP_DEFINE_CONST_DICT(machine_pwm_locals_dict, machine_pwm_locals_dict_table);
139145

ports/esp32/machine_pwm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ static const ledc_clk_cfg_t clk_source_map[] = {
142142
#endif
143143
};
144144

145+
// MicroPython bindings for ESP32-PWM
146+
#define MICROPY_PY_MACHINE_PWM_CLASS_CONSTANTS \
147+
{ MP_ROM_QSTR(MP_QSTR_PWM_AUTO_CLK), MP_ROM_INT(PWM_AUTO_CLK) }, \
148+
{ MP_ROM_QSTR(MP_QSTR_PWM_APB_CLK), MP_ROM_INT(PWM_APB_CLK) }, \
149+
{ MP_ROM_QSTR(MP_QSTR_PWM_RC_FAST_CLK), MP_ROM_INT(PWM_RC_FAST_CLK) }, \
150+
{ MP_ROM_QSTR(MP_QSTR_PWM_REF_TICK), MP_ROM_INT(PWM_REF_TICK) }, \
151+
{ MP_ROM_QSTR(MP_QSTR_PWM_XTAL_CLK), MP_ROM_INT(PWM_XTAL_CLK) }, \
152+
{ MP_ROM_QSTR(MP_QSTR_PWM_PLL_CLK), MP_ROM_INT(PWM_PLL_CLK) }, \
153+
145154
// Config of timer upon which we run all PWM'ed GPIO pins
146155
static bool pwm_inited = false;
147156

0 commit comments

Comments
 (0)
0