Skip to content
Snippets Groups Projects
Commit 345e9864 authored by Damien George's avatar Damien George
Browse files

stm32/modpyb: Add pyb.country() function to set the country.

To be used for peripherals (like radio) that must be location aware.
parent cf1c131f
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@ static const char fresh_boot_py[] =
"\r\n"
"import machine\r\n"
"import pyb\r\n"
"pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU\r\n"
"#pyb.main('main.py') # main script to run after this one\r\n"
#if MICROPY_HW_ENABLE_USB
"#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device\r\n"
......
......@@ -56,6 +56,8 @@
#include "extmod/vfs.h"
#include "extmod/utime_mphal.h"
char pyb_country_code[2];
STATIC mp_obj_t pyb_fault_debug(mp_obj_t value) {
pyb_hard_fault_debug = mp_obj_is_true(value);
return mp_const_none;
......@@ -112,6 +114,22 @@ STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uart);
STATIC mp_obj_t pyb_country(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return mp_obj_new_str(pyb_country_code, 2);
} else {
size_t len;
const char *str = mp_obj_str_get_data(args[0], &len);
if (len != 2) {
mp_raise_ValueError(NULL);
}
pyb_country_code[0] = str[0];
pyb_country_code[1] = str[1];
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_country_obj, 0, 1, pyb_country);
STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) },
......@@ -139,6 +157,7 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
#endif
{ MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&pyb_main_obj) },
{ MP_ROM_QSTR(MP_QSTR_repl_uart), MP_ROM_PTR(&pyb_repl_uart_obj) },
{ MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&pyb_country_obj) },
#if MICROPY_HW_ENABLE_USB
{ MP_ROM_QSTR(MP_QSTR_usb_mode), MP_ROM_PTR(&pyb_usb_mode_obj) },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment