Skip to content

Commit fbb7c32

Browse files
bulletmarkdpgeorge
authored andcommitted
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>
1 parent f07f90f commit fbb7c32

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

docs/library/esp32.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ For more details see Espressif's `ESP-IDF RMT documentation.
226226
``100``) and the output level to apply the carrier to (a boolean as per
227227
*idle_level*).
228228

229-
.. method:: RMT.source_freq()
229+
.. classmethod:: RMT.source_freq()
230230

231231
Returns the source clock frequency. Currently the source clock is not
232232
configurable so this will always return 80MHz.

ports/esp32/esp32_rmt.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_rmt_deinit_obj, esp32_rmt_deinit);
206206
// Return the source frequency.
207207
// Currently only the APB clock (80MHz) can be used but it is possible other
208208
// clock sources will added in the future.
209-
STATIC mp_obj_t esp32_rmt_source_freq(mp_obj_t self_in) {
209+
STATIC mp_obj_t esp32_rmt_source_freq() {
210210
return mp_obj_new_int(APB_CLK_FREQ);
211211
}
212-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_rmt_source_freq_obj, esp32_rmt_source_freq);
212+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_rmt_source_freq_obj, esp32_rmt_source_freq);
213+
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_rmt_source_obj, MP_ROM_PTR(&esp32_rmt_source_freq_obj));
213214

214215
// Return the clock divider.
215216
STATIC mp_obj_t esp32_rmt_clock_div(mp_obj_t self_in) {
@@ -357,14 +358,16 @@ STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_rmt_bitstream_channel_obj, MP_ROM_
357358
STATIC const mp_rom_map_elem_t esp32_rmt_locals_dict_table[] = {
358359
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&esp32_rmt_deinit_obj) },
359360
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&esp32_rmt_deinit_obj) },
360-
{ MP_ROM_QSTR(MP_QSTR_source_freq), MP_ROM_PTR(&esp32_rmt_source_freq_obj) },
361361
{ MP_ROM_QSTR(MP_QSTR_clock_div), MP_ROM_PTR(&esp32_rmt_clock_div_obj) },
362362
{ MP_ROM_QSTR(MP_QSTR_wait_done), MP_ROM_PTR(&esp32_rmt_wait_done_obj) },
363363
{ MP_ROM_QSTR(MP_QSTR_loop), MP_ROM_PTR(&esp32_rmt_loop_obj) },
364364
{ MP_ROM_QSTR(MP_QSTR_write_pulses), MP_ROM_PTR(&esp32_rmt_write_pulses_obj) },
365365

366366
// Static methods
367367
{ MP_ROM_QSTR(MP_QSTR_bitstream_channel), MP_ROM_PTR(&esp32_rmt_bitstream_channel_obj) },
368+
369+
// Class methods
370+
{ MP_ROM_QSTR(MP_QSTR_source_freq), MP_ROM_PTR(&esp32_rmt_source_obj) },
368371
};
369372
STATIC MP_DEFINE_CONST_DICT(esp32_rmt_locals_dict, esp32_rmt_locals_dict_table);
370373

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy