summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Blakeney <mark.blakeney@bullet-systems.net>2023-10-24 10:24:26 +1000
committerDamien George <damien@micropython.org>2023-11-09 13:51:47 +1100
commitfbb7c32040c407a60126a879dc2afe07a0ef6e5d (patch)
treee97269dccb9c703a4c900730e8d5d22b0dccfe5f
parentf07f90f1abfd6784db9c47a5602fae319991f8e7 (diff)
esp32/esp32_rmt: Change RMT.source_freq() to class method.
To create an esp32.RMT() instance with an optimum (i.e. highest resolution) clock_div is currently awkward because you need to know the source clock frequency to calculate the best clock_div, but unfortunately that is only currently available as an source_freq() method on the instance after you have already created it. So RMT.source_freq() should really be a class method, not an instance method. This change is backwards compatible for existing code because you can still reference that function from an instance, or now also, from the class. Signed-off-by: Mark Blakeney <mark.blakeney@bullet-systems.net>
-rw-r--r--docs/library/esp32.rst2
-rw-r--r--ports/esp32/esp32_rmt.c9
2 files changed, 7 insertions, 4 deletions
diff --git a/docs/library/esp32.rst b/docs/library/esp32.rst
index 7701f4353..796dbbbc5 100644
--- a/docs/library/esp32.rst
+++ b/docs/library/esp32.rst
@@ -226,7 +226,7 @@ For more details see Espressif's `ESP-IDF RMT documentation.
``100``) and the output level to apply the carrier to (a boolean as per
*idle_level*).
-.. method:: RMT.source_freq()
+.. classmethod:: RMT.source_freq()
Returns the source clock frequency. Currently the source clock is not
configurable so this will always return 80MHz.
diff --git a/ports/esp32/esp32_rmt.c b/ports/esp32/esp32_rmt.c
index f92af636f..14caffdda 100644
--- a/ports/esp32/esp32_rmt.c
+++ b/ports/esp32/esp32_rmt.c
@@ -206,10 +206,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_rmt_deinit_obj, esp32_rmt_deinit);
// Return the source frequency.
// Currently only the APB clock (80MHz) can be used but it is possible other
// clock sources will added in the future.
-STATIC mp_obj_t esp32_rmt_source_freq(mp_obj_t self_in) {
+STATIC mp_obj_t esp32_rmt_source_freq() {
return mp_obj_new_int(APB_CLK_FREQ);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_rmt_source_freq_obj, esp32_rmt_source_freq);
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_rmt_source_freq_obj, esp32_rmt_source_freq);
+STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_rmt_source_obj, MP_ROM_PTR(&esp32_rmt_source_freq_obj));
// Return the clock divider.
STATIC mp_obj_t esp32_rmt_clock_div(mp_obj_t self_in) {
@@ -357,7 +358,6 @@ STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_rmt_bitstream_channel_obj, MP_ROM_
STATIC const mp_rom_map_elem_t esp32_rmt_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&esp32_rmt_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&esp32_rmt_deinit_obj) },
- { MP_ROM_QSTR(MP_QSTR_source_freq), MP_ROM_PTR(&esp32_rmt_source_freq_obj) },
{ MP_ROM_QSTR(MP_QSTR_clock_div), MP_ROM_PTR(&esp32_rmt_clock_div_obj) },
{ MP_ROM_QSTR(MP_QSTR_wait_done), MP_ROM_PTR(&esp32_rmt_wait_done_obj) },
{ MP_ROM_QSTR(MP_QSTR_loop), MP_ROM_PTR(&esp32_rmt_loop_obj) },
@@ -365,6 +365,9 @@ STATIC const mp_rom_map_elem_t esp32_rmt_locals_dict_table[] = {
// Static methods
{ MP_ROM_QSTR(MP_QSTR_bitstream_channel), MP_ROM_PTR(&esp32_rmt_bitstream_channel_obj) },
+
+ // Class methods
+ { MP_ROM_QSTR(MP_QSTR_source_freq), MP_ROM_PTR(&esp32_rmt_source_obj) },
};
STATIC MP_DEFINE_CONST_DICT(esp32_rmt_locals_dict, esp32_rmt_locals_dict_table);