diff options
author | Damien George <damien.p.george@gmail.com> | 2016-02-17 15:19:03 +0000 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-03-09 09:03:59 +0700 |
commit | f7be80398e8f38c9695d2ebabcb2e19e80e60f0f (patch) | |
tree | 7e7101d499c10a92444ee3f51774b36e5acb59ce /esp8266/modmachine.c | |
parent | 809fbeefb7533a1f83339c28a92d213a1a5990d0 (diff) | |
download | micropython-f7be80398e8f38c9695d2ebabcb2e19e80e60f0f.tar.gz micropython-f7be80398e8f38c9695d2ebabcb2e19e80e60f0f.zip |
esp8266: Move pyb.freq to machine.freq.
Diffstat (limited to 'esp8266/modmachine.c')
-rw-r--r-- | esp8266/modmachine.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c index f7a799bf01..8500086425 100644 --- a/esp8266/modmachine.c +++ b/esp8266/modmachine.c @@ -36,9 +36,27 @@ #include "os_type.h" #include "osapi.h" #include "etshal.h" +#include "user_interface.h" #if MICROPY_PY_MACHINE +STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) { + if (n_args == 0) { + // get + return mp_obj_new_int(system_get_cpu_freq() * 1000000); + } else { + // set + mp_int_t freq = mp_obj_get_int(args[0]) / 1000000; + if (freq != 80 && freq != 160) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, + "frequency can only be either 80Mhz or 160MHz")); + } + system_update_cpu_freq(freq); + return mp_const_none; + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq); + typedef struct _esp_timer_obj_t { mp_obj_base_t base; os_timer_t timer; @@ -120,6 +138,8 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, { MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) }, + { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, + { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&esp_timer_type) }, { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pyb_pin_type) }, }; |