Skip to content

Commit f7be803

Browse files
dpgeorgepfalcon
authored andcommitted
esp8266: Move pyb.freq to machine.freq.
1 parent 809fbee commit f7be803

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

esp8266/modmachine.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,27 @@
3636
#include "os_type.h"
3737
#include "osapi.h"
3838
#include "etshal.h"
39+
#include "user_interface.h"
3940

4041
#if MICROPY_PY_MACHINE
4142

43+
STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
44+
if (n_args == 0) {
45+
// get
46+
return mp_obj_new_int(system_get_cpu_freq() * 1000000);
47+
} else {
48+
// set
49+
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
50+
if (freq != 80 && freq != 160) {
51+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
52+
"frequency can only be either 80Mhz or 160MHz"));
53+
}
54+
system_update_cpu_freq(freq);
55+
return mp_const_none;
56+
}
57+
}
58+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
59+
4260
typedef struct _esp_timer_obj_t {
4361
mp_obj_base_t base;
4462
os_timer_t timer;
@@ -120,6 +138,8 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
120138
{ MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) },
121139
{ MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) },
122140

141+
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) },
142+
123143
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&esp_timer_type) },
124144
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pyb_pin_type) },
125145
};

esp8266/modpyb.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,6 @@ STATIC mp_obj_t pyb_info(mp_uint_t n_args, const mp_obj_t *args) {
7777
}
7878
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj, 0, 1, pyb_info);
7979

80-
STATIC mp_obj_t pyb_freq(mp_uint_t n_args, const mp_obj_t *args) {
81-
if (n_args == 0) {
82-
// get
83-
return mp_obj_new_int(system_get_cpu_freq() * 1000000);
84-
} else {
85-
// set
86-
mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
87-
if (freq != 80 && freq != 160) {
88-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
89-
"frequency can only be either 80Mhz or 160MHz"));
90-
}
91-
system_update_cpu_freq(freq);
92-
return mp_const_none;
93-
}
94-
}
95-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_freq_obj, 0, 1, pyb_freq);
96-
9780
STATIC mp_obj_t pyb_sync(void) {
9881
//storage_flush();
9982
return mp_const_none;
@@ -158,7 +141,6 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
158141
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) },
159142

160143
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj },
161-
{ MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_freq_obj },
162144

163145
{ MP_OBJ_NEW_QSTR(MP_QSTR_millis), (mp_obj_t)&pyb_millis_obj },
164146
{ MP_OBJ_NEW_QSTR(MP_QSTR_elapsed_millis), (mp_obj_t)&pyb_elapsed_millis_obj },

0 commit comments

Comments
 (0)