all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
committed by
Damien George
parent
b3f2f18f92
commit
decf8e6a8b
@@ -135,7 +135,7 @@ bool microbit_display_active_animation(void) {
|
||||
return async_mode == ASYNC_MODE_ANIMATION;
|
||||
}
|
||||
|
||||
STATIC void async_stop(void) {
|
||||
static void async_stop(void) {
|
||||
async_iterator = NULL;
|
||||
async_mode = ASYNC_MODE_STOPPED;
|
||||
async_tick = 0;
|
||||
@@ -146,7 +146,7 @@ STATIC void async_stop(void) {
|
||||
wakeup_event = true;
|
||||
}
|
||||
|
||||
STATIC void wait_for_event(void) {
|
||||
static void wait_for_event(void) {
|
||||
while (!wakeup_event) {
|
||||
// allow CTRL-C to stop the animation
|
||||
if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL) {
|
||||
@@ -508,7 +508,7 @@ void microbit_display_set_pixel(microbit_display_obj_t *display, mp_int_t x, mp_
|
||||
display->brightnesses |= (1 << bright);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t microbit_display_set_pixel_func(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t microbit_display_set_pixel_func(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
microbit_display_obj_t *self = (microbit_display_obj_t*)args[0];
|
||||
microbit_display_set_pixel(self, mp_obj_get_int(args[1]), mp_obj_get_int(args[2]), mp_obj_get_int(args[3]));
|
||||
@@ -523,13 +523,13 @@ mp_int_t microbit_display_get_pixel(microbit_display_obj_t *display, mp_int_t x,
|
||||
return display->image_buffer[x][y];
|
||||
}
|
||||
|
||||
STATIC mp_obj_t microbit_display_get_pixel_func(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
|
||||
static mp_obj_t microbit_display_get_pixel_func(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
|
||||
microbit_display_obj_t *self = (microbit_display_obj_t*)self_in;
|
||||
return MP_OBJ_NEW_SMALL_INT(microbit_display_get_pixel(self, mp_obj_get_int(x_in), mp_obj_get_int(y_in)));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(microbit_display_get_pixel_obj, microbit_display_get_pixel_func);
|
||||
|
||||
STATIC const mp_rom_map_elem_t microbit_display_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t microbit_display_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(µbit_display_get_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(µbit_display_set_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(µbit_display_show_obj) },
|
||||
@@ -540,7 +540,7 @@ STATIC const mp_rom_map_elem_t microbit_display_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_is_on), MP_ROM_PTR(µbit_display_is_on_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
microbit_display_type,
|
||||
|
||||
@@ -40,7 +40,7 @@ const monochrome_5by5_t microbit_blank_image = {
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
STATIC void microbit_image_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void microbit_image_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
microbit_image_obj_t *self = (microbit_image_obj_t*)self_in;
|
||||
mp_printf(print, "Image(");
|
||||
if (kind == PRINT_STR)
|
||||
@@ -112,7 +112,7 @@ mp_int_t imageHeight(microbit_image_obj_t * p_image) {
|
||||
return p_image->greyscale.height;
|
||||
}
|
||||
|
||||
STATIC greyscale_t *greyscale_new(mp_int_t w, mp_int_t h) {
|
||||
static greyscale_t *greyscale_new(mp_int_t w, mp_int_t h) {
|
||||
greyscale_t *result = mp_obj_malloc_var(greyscale_t, byte_data, uint8_t, (w*h+1)>>1, µbit_image_type);
|
||||
result->five = 0;
|
||||
result->width = w;
|
||||
@@ -144,7 +144,7 @@ greyscale_t * imageInvert(microbit_image_obj_t * p_image) {
|
||||
return result;
|
||||
}
|
||||
|
||||
STATIC microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len) {
|
||||
static microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len) {
|
||||
mp_int_t w = 0;
|
||||
mp_int_t h = 0;
|
||||
mp_int_t line_len = 0;
|
||||
@@ -201,7 +201,7 @@ STATIC microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len)
|
||||
}
|
||||
|
||||
|
||||
STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 3, false);
|
||||
|
||||
@@ -270,7 +270,7 @@ static void clear_rect(greyscale_t *img, mp_int_t x0, mp_int_t y0,mp_int_t x1, m
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void image_blit(microbit_image_obj_t *src, greyscale_t *dest, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h, mp_int_t xdest, mp_int_t ydest) {
|
||||
static void image_blit(microbit_image_obj_t *src, greyscale_t *dest, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h, mp_int_t xdest, mp_int_t ydest) {
|
||||
if (w < 0)
|
||||
w = 0;
|
||||
if (h < 0)
|
||||
@@ -323,7 +323,7 @@ greyscale_t *image_shift(microbit_image_obj_t *self, mp_int_t x, mp_int_t y) {
|
||||
return result;
|
||||
}
|
||||
|
||||
STATIC microbit_image_obj_t *image_crop(microbit_image_obj_t *img, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h) {
|
||||
static microbit_image_obj_t *image_crop(microbit_image_obj_t *img, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h) {
|
||||
if (w < 0)
|
||||
w = 0;
|
||||
if (h < 0)
|
||||
@@ -483,7 +483,7 @@ mp_obj_t microbit_image_invert(mp_obj_t self_in) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(microbit_image_invert_obj, microbit_image_invert);
|
||||
|
||||
|
||||
STATIC const mp_rom_map_elem_t microbit_image_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t microbit_image_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(µbit_image_width_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(µbit_image_height_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(µbit_image_get_pixel_obj) },
|
||||
@@ -565,14 +565,14 @@ STATIC const mp_rom_map_elem_t microbit_image_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_SNAKE), MP_ROM_PTR(µbit_const_image_snake_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(microbit_image_locals_dict, microbit_image_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(microbit_image_locals_dict, microbit_image_locals_dict_table);
|
||||
|
||||
#define THE_FONT font_pendolino3_5x5_pad3msb
|
||||
|
||||
#define ASCII_START 32
|
||||
#define ASCII_END 126
|
||||
|
||||
STATIC const unsigned char *get_font_data_from_char(char c) {
|
||||
static const unsigned char *get_font_data_from_char(char c) {
|
||||
if (c < ASCII_START || c > ASCII_END) {
|
||||
c = '?';
|
||||
}
|
||||
@@ -580,7 +580,7 @@ STATIC const unsigned char *get_font_data_from_char(char c) {
|
||||
return THE_FONT + offset;
|
||||
}
|
||||
|
||||
STATIC mp_int_t get_pixel_from_font_data(const unsigned char *data, int x, int y) {
|
||||
static mp_int_t get_pixel_from_font_data(const unsigned char *data, int x, int y) {
|
||||
/* The following logic belongs in MicroBitFont */
|
||||
return ((data[y]>>(4-x))&1);
|
||||
}
|
||||
@@ -645,7 +645,7 @@ microbit_image_obj_t *microbit_image_sum(microbit_image_obj_t *lhs, microbit_ima
|
||||
return (microbit_image_obj_t *)result;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
static mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
if (mp_obj_get_type(lhs_in) != µbit_image_type) {
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
@@ -724,7 +724,7 @@ mp_obj_t scrolling_string_image_iterable(const char* str, mp_uint_t len, mp_obj_
|
||||
return result;
|
||||
}
|
||||
|
||||
STATIC int font_column_non_blank(const unsigned char *font_data, unsigned int col) {
|
||||
static int font_column_non_blank(const unsigned char *font_data, unsigned int col) {
|
||||
for (int y = 0; y < 5; ++y) {
|
||||
if (get_pixel_from_font_data(font_data, col, y)) {
|
||||
return 1;
|
||||
@@ -734,7 +734,7 @@ STATIC int font_column_non_blank(const unsigned char *font_data, unsigned int co
|
||||
}
|
||||
|
||||
/* Not strictly the rightmost non-blank column, but the rightmost in columns 2,3 or 4. */
|
||||
STATIC unsigned int rightmost_non_blank_column(const unsigned char *font_data) {
|
||||
static unsigned int rightmost_non_blank_column(const unsigned char *font_data) {
|
||||
if (font_column_non_blank(font_data, 4)) {
|
||||
return 4;
|
||||
}
|
||||
@@ -760,7 +760,7 @@ static void restart(scrolling_string_iterator_t *iter) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
|
||||
static mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
|
||||
(void)iter_buf;
|
||||
scrolling_string_t *str = (scrolling_string_t *)o_in;
|
||||
scrolling_string_iterator_t *result = mp_obj_malloc(scrolling_string_iterator_t, µbit_scrolling_string_iterator_type);
|
||||
@@ -774,7 +774,7 @@ STATIC mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_bu
|
||||
return result;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t microbit_scrolling_string_iter_next(mp_obj_t o_in) {
|
||||
static mp_obj_t microbit_scrolling_string_iter_next(mp_obj_t o_in) {
|
||||
scrolling_string_iterator_t *iter = (scrolling_string_iterator_t *)o_in;
|
||||
if (iter->next_char == iter->end && iter->offset == 5) {
|
||||
if (iter->repeat) {
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
|
||||
extern uint32_t ticks;
|
||||
|
||||
STATIC mp_obj_t microbit_reset_(void) {
|
||||
static mp_obj_t microbit_reset_(void) {
|
||||
NVIC_SystemReset();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(microbit_reset_obj, microbit_reset_);
|
||||
|
||||
STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) {
|
||||
static mp_obj_t microbit_sleep(mp_obj_t ms_in) {
|
||||
mp_int_t ms = 0;
|
||||
if (mp_obj_is_integer(ms_in)) {
|
||||
ms = mp_obj_get_int(ms_in);
|
||||
@@ -57,7 +57,7 @@ STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(microbit_sleep_obj, microbit_sleep);
|
||||
|
||||
STATIC mp_obj_t microbit_running_time(void) {
|
||||
static mp_obj_t microbit_running_time(void) {
|
||||
return MP_OBJ_NEW_SMALL_INT(ticks);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(microbit_running_time_obj, microbit_running_time);
|
||||
@@ -70,7 +70,7 @@ static const monochrome_5by5_t panic = SMALL_IMAGE(
|
||||
1,0,0,0,1
|
||||
);
|
||||
|
||||
STATIC mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
while(true) {
|
||||
microbit_display_show(µbit_display_obj, (microbit_image_obj_t*)&panic);
|
||||
mp_hal_delay_ms(1000);
|
||||
@@ -95,7 +95,7 @@ STATIC mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_panic_obj, 0, 1, microbit_panic);
|
||||
|
||||
STATIC mp_obj_t microbit_temperature(void) {
|
||||
static mp_obj_t microbit_temperature(void) {
|
||||
int temp = temp_read();
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
return mp_obj_new_float((mp_float_t)temp / MICROPY_FLOAT_CONST(100.0));
|
||||
@@ -109,7 +109,7 @@ void board_modules_init0(void) {
|
||||
ticker_register_low_pri_callback(microbit_display_tick);
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t microbit_module_globals_table[] = {
|
||||
static const mp_rom_map_elem_t microbit_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_Image), MP_ROM_PTR(µbit_image_type) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_display), MP_ROM_PTR(µbit_display_obj) },
|
||||
@@ -150,7 +150,7 @@ STATIC const mp_rom_map_elem_t microbit_module_globals_table[] = {
|
||||
*/
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(microbit_module_globals, microbit_module_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(microbit_module_globals, microbit_module_globals_table);
|
||||
|
||||
const mp_obj_module_t microbit_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -241,7 +241,7 @@ class Pins(object):
|
||||
|
||||
def print_named(self, label, named_pins, out_source):
|
||||
print(
|
||||
"STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label),
|
||||
"static const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label),
|
||||
file=out_source,
|
||||
)
|
||||
for named_pin in named_pins:
|
||||
|
||||
@@ -173,7 +173,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) {
|
||||
static void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) {
|
||||
ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (event_id == 16) { // connect event
|
||||
@@ -187,7 +187,7 @@ STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) {
|
||||
static void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) {
|
||||
ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
(void)self;
|
||||
|
||||
|
||||
@@ -33,13 +33,13 @@
|
||||
#include "nrf_soc.h"
|
||||
|
||||
// Rotates bits in `value` left `shift` times.
|
||||
STATIC inline uint32_t rotate_left(uint32_t value, uint32_t shift) {
|
||||
static inline uint32_t rotate_left(uint32_t value, uint32_t shift) {
|
||||
return (value << shift) | (value >> (32 - shift));
|
||||
}
|
||||
|
||||
STATIC volatile flash_state_t flash_operation_state = FLASH_STATE_BUSY;
|
||||
static volatile flash_state_t flash_operation_state = FLASH_STATE_BUSY;
|
||||
|
||||
STATIC void operation_init(void) {
|
||||
static void operation_init(void) {
|
||||
flash_operation_state = FLASH_STATE_BUSY;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ void flash_operation_finished(flash_state_t result) {
|
||||
flash_operation_state = result;
|
||||
}
|
||||
|
||||
STATIC bool operation_wait(uint32_t result) {
|
||||
static bool operation_wait(uint32_t result) {
|
||||
if (ble_drv_stack_enabled() != 1) {
|
||||
// SoftDevice is not enabled, no event will be generated.
|
||||
return result == NRF_SUCCESS;
|
||||
|
||||
@@ -81,12 +81,12 @@ mp_obj_t ble_obj_address(void) {
|
||||
return mac_str;
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enable_obj, ble_obj_enable);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_disable_obj, ble_obj_disable);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enabled_obj, ble_obj_enabled);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_address_obj, ble_obj_address);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enable_obj, ble_obj_enable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_disable_obj, ble_obj_disable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enabled_obj, ble_obj_enabled);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_address_obj, ble_obj_address);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ble_module_globals_table[] = {
|
||||
static const mp_rom_map_elem_t ble_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ble) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&ble_obj_enable_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&ble_obj_disable_obj) },
|
||||
@@ -95,7 +95,7 @@ STATIC const mp_rom_map_elem_t ble_module_globals_table[] = {
|
||||
};
|
||||
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ble_module_globals, ble_module_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(ble_module_globals, ble_module_globals_table);
|
||||
|
||||
const mp_obj_module_t ble_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -142,7 +142,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki
|
||||
/// Create an LED object associated with the given LED:
|
||||
///
|
||||
/// - `id` is the LED number, 1-4.
|
||||
STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
@@ -182,17 +182,17 @@ mp_obj_t led_obj_toggle(mp_obj_t self_in) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle);
|
||||
|
||||
STATIC const mp_rom_map_elem_t led_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t led_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&led_obj_on_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&led_obj_off_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&led_obj_toggle_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
board_led_type,
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#define PYB_LED_MODULE
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
||||
static const mp_rom_map_elem_t board_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_board) },
|
||||
#if MICROPY_REPL_INFO
|
||||
{ MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) },
|
||||
@@ -47,7 +47,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
||||
};
|
||||
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
||||
|
||||
const mp_obj_module_t board_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct _machine_adc_obj_t {
|
||||
#endif
|
||||
} machine_adc_obj_t;
|
||||
|
||||
STATIC const machine_adc_obj_t machine_adc_obj[] = {
|
||||
static const machine_adc_obj_t machine_adc_obj[] = {
|
||||
#if NRF51
|
||||
{{&machine_adc_type}, .id = 0, .ain = NRF_ADC_CONFIG_INPUT_0},
|
||||
{{&machine_adc_type}, .id = 1, .ain = NRF_ADC_CONFIG_INPUT_1},
|
||||
@@ -73,7 +73,7 @@ void adc_init0(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC int adc_find(mp_obj_t id) {
|
||||
static int adc_find(mp_obj_t id) {
|
||||
int adc_idx;
|
||||
if (mp_obj_is_int(id)) {
|
||||
// Given an integer id
|
||||
@@ -104,14 +104,14 @@ STATIC int adc_find(mp_obj_t id) {
|
||||
{ MP_ROM_QSTR(MP_QSTR_battery_level), MP_ROM_PTR(&mp_machine_adc_battery_level_obj) }, /* class method */ \
|
||||
|
||||
// Return a string describing the ADC object.
|
||||
STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
machine_adc_obj_t *self = o;
|
||||
|
||||
mp_printf(print, "ADC(%u)", self->id);
|
||||
}
|
||||
|
||||
// for make_new
|
||||
STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum { ARG_id };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1) } },
|
||||
@@ -171,7 +171,7 @@ int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj) {
|
||||
}
|
||||
|
||||
// read_u16()
|
||||
STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) {
|
||||
static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) {
|
||||
int16_t raw = machine_adc_value_read(self);
|
||||
#if defined(NRF52_SERIES)
|
||||
// raw is signed but the channel is in single-ended mode and this method cannot return negative values
|
||||
@@ -192,7 +192,7 @@ mp_obj_t machine_adc_value(mp_obj_t self_in) {
|
||||
|
||||
return MP_OBJ_NEW_SMALL_INT(value);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_machine_adc_value_obj, machine_adc_value);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(mp_machine_adc_value_obj, machine_adc_value);
|
||||
|
||||
#if NRF51
|
||||
|
||||
@@ -278,4 +278,4 @@ mp_obj_t machine_adc_battery_level(void) {
|
||||
|
||||
return MP_OBJ_NEW_SMALL_INT(batt_in_percent);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_machine_adc_battery_level_obj, machine_adc_battery_level);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(mp_machine_adc_battery_level_obj, machine_adc_battery_level);
|
||||
|
||||
@@ -71,7 +71,7 @@ typedef struct _machine_hard_i2c_obj_t {
|
||||
nrfx_twi_t p_twi; // Driver instance
|
||||
} machine_hard_i2c_obj_t;
|
||||
|
||||
STATIC const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = {
|
||||
static const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = {
|
||||
{{&machine_i2c_type}, .p_twi = NRFX_TWI_INSTANCE(0)},
|
||||
{{&machine_i2c_type}, .p_twi = NRFX_TWI_INSTANCE(1)},
|
||||
};
|
||||
@@ -79,7 +79,7 @@ STATIC const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = {
|
||||
void i2c_init0(void) {
|
||||
}
|
||||
|
||||
STATIC int i2c_find(mp_obj_t id) {
|
||||
static int i2c_find(mp_obj_t id) {
|
||||
// given an integer id
|
||||
int i2c_id = mp_obj_get_int(id);
|
||||
if (i2c_id >= 0 && i2c_id < MP_ARRAY_SIZE(machine_hard_i2c_obj)) {
|
||||
@@ -88,7 +88,7 @@ STATIC int i2c_find(mp_obj_t id) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("I2C doesn't exist"));
|
||||
}
|
||||
|
||||
STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_hard_i2c_obj_t *self = self_in;
|
||||
mp_printf(print, "I2C(%u)", self->p_twi.drv_inst_idx);
|
||||
}
|
||||
@@ -171,7 +171,7 @@ int machine_hard_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size
|
||||
return transfer_ret;
|
||||
}
|
||||
|
||||
STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = {
|
||||
static const mp_machine_i2c_p_t machine_hard_i2c_p = {
|
||||
.transfer = mp_machine_i2c_transfer_adaptor,
|
||||
.transfer_single = machine_hard_i2c_transfer_single,
|
||||
};
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
{ MP_ROM_QSTR(MP_QSTR_DEBUG_IF_RESET), MP_ROM_INT(PYB_RESET_DIF) }, \
|
||||
MICROPY_PY_MACHINE_NFC_RESET_ENTRY \
|
||||
|
||||
STATIC uint32_t reset_cause;
|
||||
static uint32_t reset_cause;
|
||||
|
||||
void machine_init(void) {
|
||||
uint32_t state = NRF_POWER->RESETREAS;
|
||||
@@ -134,7 +134,7 @@ void machine_init(void) {
|
||||
|
||||
// machine.info([dump_alloc_table])
|
||||
// Print out lots of information about the board.
|
||||
STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
// to print info about memory
|
||||
{
|
||||
printf("_etext=%p\n", &_etext);
|
||||
@@ -174,14 +174,14 @@ STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info);
|
||||
|
||||
STATIC mp_obj_t mp_machine_unique_id(void) {
|
||||
static mp_obj_t mp_machine_unique_id(void) {
|
||||
return mp_const_empty_bytes;
|
||||
}
|
||||
|
||||
// Resets the board in a manner similar to pushing the external RESET button.
|
||||
NORETURN STATIC void mp_machine_reset(void) {
|
||||
NORETURN static void mp_machine_reset(void) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
@@ -191,31 +191,31 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_idle(void) {
|
||||
static void mp_machine_idle(void) {
|
||||
MICROPY_EVENT_POLL_HOOK;
|
||||
}
|
||||
|
||||
STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
||||
__WFE();
|
||||
}
|
||||
|
||||
NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
mp_machine_reset();
|
||||
}
|
||||
|
||||
STATIC mp_int_t mp_machine_reset_cause(void) {
|
||||
static mp_int_t mp_machine_reset_cause(void) {
|
||||
return reset_cause;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_get_freq(void) {
|
||||
static mp_obj_t mp_machine_get_freq(void) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_enable_irq(void) {
|
||||
static mp_obj_t machine_enable_irq(void) {
|
||||
#ifndef BLUETOOTH_SD
|
||||
__enable_irq();
|
||||
#else
|
||||
@@ -226,7 +226,7 @@ STATIC mp_obj_t machine_enable_irq(void) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_enable_irq_obj, machine_enable_irq);
|
||||
|
||||
// Resets the board in a manner similar to pushing the external RESET button.
|
||||
STATIC mp_obj_t machine_disable_irq(void) {
|
||||
static mp_obj_t machine_disable_irq(void) {
|
||||
#ifndef BLUETOOTH_SD
|
||||
__disable_irq();
|
||||
#else
|
||||
|
||||
@@ -107,7 +107,7 @@ extern const uint8_t machine_pin_num_of_board_pins;
|
||||
|
||||
// Pin class variables
|
||||
#if PIN_DEBUG
|
||||
STATIC bool pin_class_debug;
|
||||
static bool pin_class_debug;
|
||||
#else
|
||||
#define pin_class_debug (0)
|
||||
#endif
|
||||
@@ -218,7 +218,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
|
||||
|
||||
/// \method __str__()
|
||||
/// Return a string describing the pin object.
|
||||
STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pin_obj_t *self = self_in;
|
||||
|
||||
char *pull = "PULL_DISABLED";
|
||||
@@ -239,12 +239,12 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
pull);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
|
||||
static mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
|
||||
|
||||
/// \classmethod \constructor(id, ...)
|
||||
/// Create a new Pin object associated with the id. If additional arguments are given,
|
||||
/// they are used to initialise the pin. See `init`.
|
||||
STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
// Run an argument through the mapper and return the result.
|
||||
@@ -261,7 +261,7 @@ STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uin
|
||||
}
|
||||
|
||||
// fast method for getting/setting pin value
|
||||
STATIC mp_obj_t pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
pin_obj_t *self = self_in;
|
||||
if (n_args == 0) {
|
||||
@@ -274,47 +274,47 @@ STATIC mp_obj_t pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, con
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_off(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_off(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_hal_pin_low(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off);
|
||||
|
||||
STATIC mp_obj_t pin_on(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_on(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_hal_pin_high(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on);
|
||||
|
||||
/// \classmethod mapper([fun])
|
||||
/// Get or set the pin mapper function.
|
||||
STATIC mp_obj_t pin_mapper(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_mapper(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if (n_args > 1) {
|
||||
MP_STATE_PORT(pin_class_mapper) = args[1];
|
||||
return mp_const_none;
|
||||
}
|
||||
return MP_STATE_PORT(pin_class_mapper);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mapper_fun_obj, 1, 2, pin_mapper);
|
||||
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, (mp_obj_t)&pin_mapper_fun_obj);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mapper_fun_obj, 1, 2, pin_mapper);
|
||||
static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, (mp_obj_t)&pin_mapper_fun_obj);
|
||||
|
||||
/// \classmethod dict([dict])
|
||||
/// Get or set the pin mapper dictionary.
|
||||
STATIC mp_obj_t pin_map_dict(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_map_dict(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if (n_args > 1) {
|
||||
MP_STATE_PORT(pin_class_map_dict) = args[1];
|
||||
return mp_const_none;
|
||||
}
|
||||
return MP_STATE_PORT(pin_class_map_dict);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict);
|
||||
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, (mp_obj_t)&pin_map_dict_fun_obj);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict);
|
||||
static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, (mp_obj_t)&pin_map_dict_fun_obj);
|
||||
|
||||
/// \classmethod af_list()
|
||||
/// Returns an array of alternate functions available for this pin.
|
||||
STATIC mp_obj_t pin_af_list(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_af_list(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_obj_t result = mp_obj_new_list(0, NULL);
|
||||
|
||||
@@ -324,24 +324,24 @@ STATIC mp_obj_t pin_af_list(mp_obj_t self_in) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
|
||||
|
||||
#if PIN_DEBUG
|
||||
/// \classmethod debug([state])
|
||||
/// Get or set the debugging state (`True` or `False` for on or off).
|
||||
STATIC mp_obj_t pin_debug(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_debug(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if (n_args > 1) {
|
||||
pin_class_debug = mp_obj_is_true(args[1]);
|
||||
return mp_const_none;
|
||||
}
|
||||
return mp_obj_new_bool(pin_class_debug);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug);
|
||||
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_obj);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug);
|
||||
static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_obj);
|
||||
#endif
|
||||
|
||||
// init(mode, pull=None, af=-1, *, value, alt)
|
||||
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none}},
|
||||
@@ -387,7 +387,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
|
||||
@@ -399,40 +399,40 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
|
||||
/// - With `value` given, set the logic level of the pin. `value` can be
|
||||
/// anything that converts to a boolean. If it converts to `True`, the pin
|
||||
/// is set high, otherwise it is set low.
|
||||
STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
return pin_call(args[0], n_args - 1, 0, args + 1);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
|
||||
|
||||
/// \method low()
|
||||
/// Set the pin to a low logic level.
|
||||
STATIC mp_obj_t pin_low(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_low(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_hal_pin_low(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low);
|
||||
|
||||
/// \method high()
|
||||
/// Set the pin to a high logic level.
|
||||
STATIC mp_obj_t pin_high(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_high(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_hal_pin_high(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high);
|
||||
|
||||
/// \method name()
|
||||
/// Get the pin name.
|
||||
STATIC mp_obj_t pin_name(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_name(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
return MP_OBJ_NEW_QSTR(self->name);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name);
|
||||
|
||||
/// \method names()
|
||||
/// Returns the cpu and board names for this pin.
|
||||
STATIC mp_obj_t pin_names(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_names(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
mp_obj_t result = mp_obj_new_list(0, NULL);
|
||||
mp_obj_list_append(result, MP_OBJ_NEW_QSTR(self->name));
|
||||
@@ -447,53 +447,53 @@ STATIC mp_obj_t pin_names(mp_obj_t self_in) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names);
|
||||
|
||||
/// \method port()
|
||||
/// Get the pin port.
|
||||
STATIC mp_obj_t pin_port(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_port(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
return MP_OBJ_NEW_SMALL_INT(self->pin / 32);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
|
||||
|
||||
/// \method pin()
|
||||
/// Get the pin number.
|
||||
STATIC mp_obj_t pin_pin(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_pin(mp_obj_t self_in) {
|
||||
pin_obj_t *self = self_in;
|
||||
return MP_OBJ_NEW_SMALL_INT(self->pin);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin);
|
||||
|
||||
/// \method mode()
|
||||
/// Returns the currently configured mode of the pin. The integer returned
|
||||
/// will match one of the allowed constants for the mode argument to the init
|
||||
/// function.
|
||||
STATIC mp_obj_t pin_mode(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_mode(mp_obj_t self_in) {
|
||||
return mp_const_none; // TODO: MP_OBJ_NEW_SMALL_INT(pin_get_mode(self_in));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode);
|
||||
|
||||
/// \method pull()
|
||||
/// Returns the currently configured pull of the pin. The integer returned
|
||||
/// will match one of the allowed constants for the pull argument to the init
|
||||
/// function.
|
||||
STATIC mp_obj_t pin_pull(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_pull(mp_obj_t self_in) {
|
||||
return mp_const_none; // TODO: MP_OBJ_NEW_SMALL_INT(pin_get_pull(self_in));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull);
|
||||
|
||||
/// \method af()
|
||||
/// Returns the currently configured alternate-function of the pin. The
|
||||
/// integer returned will match one of the allowed constants for the af
|
||||
/// argument to the init function.
|
||||
STATIC mp_obj_t pin_af(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_af(mp_obj_t self_in) {
|
||||
return mp_const_none; // TODO: MP_OBJ_NEW_SMALL_INT(pin_get_af(self_in));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
|
||||
|
||||
|
||||
STATIC void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
||||
static void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
||||
mp_obj_t pin_handler = MP_STATE_PORT(pin_irq_handlers)[pin];
|
||||
mp_obj_t pin_number = MP_OBJ_NEW_SMALL_INT(pin);
|
||||
const pin_obj_t *pin_obj = pin_find(pin_number);
|
||||
@@ -501,7 +501,7 @@ STATIC void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t
|
||||
mp_call_function_1(pin_handler, (mp_obj_t)pin_obj);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum {ARG_handler, ARG_trigger, ARG_wake};
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_handler, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = mp_const_none} },
|
||||
@@ -536,9 +536,9 @@ STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
||||
// return the irq object
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
// instance methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) },
|
||||
@@ -594,7 +594,7 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = {
|
||||
#include "genhdr/pins_af_const.h"
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pin_type,
|
||||
@@ -635,42 +635,42 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
|
||||
/// \method __str__()
|
||||
/// Return a string describing the alternate function.
|
||||
STATIC void pin_af_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pin_af_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pin_af_obj_t *self = self_in;
|
||||
mp_printf(print, "Pin.%q", self->name);
|
||||
}
|
||||
|
||||
/// \method index()
|
||||
/// Return the alternate function index.
|
||||
STATIC mp_obj_t pin_af_index(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_af_index(mp_obj_t self_in) {
|
||||
pin_af_obj_t *af = self_in;
|
||||
return MP_OBJ_NEW_SMALL_INT(af->idx);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_index_obj, pin_af_index);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_index_obj, pin_af_index);
|
||||
|
||||
/// \method name()
|
||||
/// Return the name of the alternate function.
|
||||
STATIC mp_obj_t pin_af_name(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_af_name(mp_obj_t self_in) {
|
||||
pin_af_obj_t *af = self_in;
|
||||
return MP_OBJ_NEW_QSTR(af->name);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name);
|
||||
|
||||
/// \method reg()
|
||||
/// Return the base register associated with the peripheral assigned to this
|
||||
/// alternate function.
|
||||
STATIC mp_obj_t pin_af_reg(mp_obj_t self_in) {
|
||||
static mp_obj_t pin_af_reg(mp_obj_t self_in) {
|
||||
pin_af_obj_t *af = self_in;
|
||||
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)af->reg);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_reg_obj, pin_af_reg);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_reg_obj, pin_af_reg);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pin_af_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t pin_af_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&pin_af_index_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_af_name_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_reg), MP_ROM_PTR(&pin_af_reg_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
pin_af_type,
|
||||
|
||||
@@ -81,7 +81,7 @@ typedef struct _machine_pwm_obj_t {
|
||||
uint8_t channel;
|
||||
} machine_pwm_obj_t;
|
||||
|
||||
STATIC const nrfx_pwm_t machine_hard_pwm_instances[] = {
|
||||
static const nrfx_pwm_t machine_hard_pwm_instances[] = {
|
||||
#if defined(NRF52_SERIES)
|
||||
NRFX_PWM_INSTANCE(0),
|
||||
NRFX_PWM_INSTANCE(1),
|
||||
@@ -92,9 +92,9 @@ STATIC const nrfx_pwm_t machine_hard_pwm_instances[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC machine_pwm_config_t hard_configs[MP_ARRAY_SIZE(machine_hard_pwm_instances)];
|
||||
static machine_pwm_config_t hard_configs[MP_ARRAY_SIZE(machine_hard_pwm_instances)];
|
||||
|
||||
STATIC const machine_pwm_obj_t machine_hard_pwm_obj[] = {
|
||||
static const machine_pwm_obj_t machine_hard_pwm_obj[] = {
|
||||
#if defined(NRF52_SERIES)
|
||||
{{&machine_pwm_type}, .p_pwm = &machine_hard_pwm_instances[0], .p_config = &hard_configs[0], 0, 0},
|
||||
{{&machine_pwm_type}, .p_pwm = &machine_hard_pwm_instances[0], .p_config = &hard_configs[0], 0, 1},
|
||||
@@ -127,7 +127,7 @@ void pwm_init0(void) {
|
||||
}
|
||||
|
||||
// Find a free PWM object
|
||||
STATIC int hard_pwm_find() {
|
||||
static int hard_pwm_find() {
|
||||
// look for a free module.
|
||||
for (int j = 0; j < MP_ARRAY_SIZE(hard_configs); j++) {
|
||||
if (hard_configs[j].active == FREE) {
|
||||
@@ -137,7 +137,7 @@ STATIC int hard_pwm_find() {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("all PWM devices in use"));
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_pwm_obj_t *self = self_in;
|
||||
static char *duty_suffix[] = { "", "", "_u16", "_ns" };
|
||||
mp_printf(print, "<PWM: Pin=%u freq=%dHz duty%s=%d invert=%d id=%u channel=%u>",
|
||||
@@ -149,7 +149,7 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings for machine API */
|
||||
|
||||
STATIC void machine_hard_pwm_start(const machine_pwm_obj_t *self);
|
||||
static void machine_hard_pwm_start(const machine_pwm_obj_t *self);
|
||||
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
@@ -162,7 +162,7 @@ static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||
};
|
||||
|
||||
STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin, ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device, ARG_channel };
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
@@ -190,7 +190,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, c
|
||||
}
|
||||
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum { ARG_pin, ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device, ARG_channel };
|
||||
|
||||
// parse args
|
||||
@@ -250,17 +250,17 @@ void pwm_deinit_all(void) {
|
||||
}
|
||||
|
||||
// Stop the PWM module, but do not release it.
|
||||
STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
|
||||
static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
|
||||
self->p_config->active = STOPPED;
|
||||
nrfx_pwm_stop(self->p_pwm, true);
|
||||
nrfx_pwm_uninit(self->p_pwm);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) {
|
||||
static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) {
|
||||
return MP_OBJ_NEW_SMALL_INT(self->p_config->freq);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
|
||||
static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
|
||||
|
||||
uint8_t div = 0;
|
||||
if (freq > (PWM_MAX_BASE_FREQ / 3) || freq <= (PWM_MIN_BASE_FREQ / PWM_MAX_PERIOD)) {
|
||||
@@ -276,7 +276,7 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
|
||||
machine_hard_pwm_start(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) {
|
||||
static mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) {
|
||||
if (self->p_config->duty_mode[self->channel] == DUTY_PERCENT) {
|
||||
return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]);
|
||||
} else if (self->p_config->duty_mode[self->channel] == DUTY_U16) {
|
||||
@@ -286,13 +286,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
static void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
self->p_config->duty[self->channel] = duty;
|
||||
self->p_config->duty_mode[self->channel] = DUTY_PERCENT;
|
||||
machine_hard_pwm_start(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
|
||||
static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
|
||||
if (self->p_config->duty_mode[self->channel] == DUTY_U16) {
|
||||
return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]);
|
||||
} else if (self->p_config->duty_mode[self->channel] == DUTY_PERCENT) {
|
||||
@@ -302,13 +302,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
self->p_config->duty[self->channel] = duty;
|
||||
self->p_config->duty_mode[self->channel] = DUTY_U16;
|
||||
machine_hard_pwm_start(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
|
||||
static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
|
||||
if (self->p_config->duty_mode[self->channel] == DUTY_NS) {
|
||||
return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]);
|
||||
} else {
|
||||
@@ -316,7 +316,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
self->p_config->duty[self->channel] = duty;
|
||||
self->p_config->duty_mode[self->channel] = DUTY_NS;
|
||||
machine_hard_pwm_start(self);
|
||||
@@ -324,7 +324,7 @@ STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
|
||||
/* code for hard implementation ***********************************************/
|
||||
|
||||
STATIC void machine_hard_pwm_start(const machine_pwm_obj_t *self) {
|
||||
static void machine_hard_pwm_start(const machine_pwm_obj_t *self) {
|
||||
|
||||
nrfx_pwm_config_t config;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ typedef struct _machine_rtc_obj_t {
|
||||
machine_rtc_config_t * config; // pointer to volatile part
|
||||
} machine_rtc_obj_t;
|
||||
|
||||
STATIC const nrfx_rtc_t machine_rtc_instances[] = {
|
||||
static const nrfx_rtc_t machine_rtc_instances[] = {
|
||||
NRFX_RTC_INSTANCE(0),
|
||||
NRFX_RTC_INSTANCE(1),
|
||||
#if defined(NRF52_SERIES)
|
||||
@@ -63,15 +63,15 @@ STATIC const nrfx_rtc_t machine_rtc_instances[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC machine_rtc_config_t configs[MP_ARRAY_SIZE(machine_rtc_instances)];
|
||||
static machine_rtc_config_t configs[MP_ARRAY_SIZE(machine_rtc_instances)];
|
||||
|
||||
STATIC void interrupt_handler0(nrfx_rtc_int_type_t int_type);
|
||||
STATIC void interrupt_handler1(nrfx_rtc_int_type_t int_type);
|
||||
static void interrupt_handler0(nrfx_rtc_int_type_t int_type);
|
||||
static void interrupt_handler1(nrfx_rtc_int_type_t int_type);
|
||||
#if defined(NRF52_SERIES)
|
||||
STATIC void interrupt_handler2(nrfx_rtc_int_type_t int_type);
|
||||
static void interrupt_handler2(nrfx_rtc_int_type_t int_type);
|
||||
#endif
|
||||
|
||||
STATIC const machine_rtc_obj_t machine_rtc_obj[] = {
|
||||
static const machine_rtc_obj_t machine_rtc_obj[] = {
|
||||
{{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[0], .handler=interrupt_handler0, .config=&configs[0]},
|
||||
{{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[1], .handler=interrupt_handler1, .config=&configs[1]},
|
||||
#if defined(NRF52_SERIES)
|
||||
@@ -79,7 +79,7 @@ STATIC const machine_rtc_obj_t machine_rtc_obj[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC void interrupt_handler(size_t instance_id) {
|
||||
static void interrupt_handler(size_t instance_id) {
|
||||
const machine_rtc_obj_t * self = &machine_rtc_obj[instance_id];
|
||||
machine_rtc_config_t *config = self->config;
|
||||
if (config->callback != NULL) {
|
||||
@@ -93,16 +93,16 @@ STATIC void interrupt_handler(size_t instance_id) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void interrupt_handler0(nrfx_rtc_int_type_t int_type) {
|
||||
static void interrupt_handler0(nrfx_rtc_int_type_t int_type) {
|
||||
interrupt_handler(0);
|
||||
}
|
||||
|
||||
STATIC void interrupt_handler1(nrfx_rtc_int_type_t int_type) {
|
||||
static void interrupt_handler1(nrfx_rtc_int_type_t int_type) {
|
||||
interrupt_handler(1);
|
||||
}
|
||||
|
||||
#if defined(NRF52_SERIES)
|
||||
STATIC void interrupt_handler2(nrfx_rtc_int_type_t int_type) {
|
||||
static void interrupt_handler2(nrfx_rtc_int_type_t int_type) {
|
||||
interrupt_handler(2);
|
||||
}
|
||||
#endif
|
||||
@@ -110,7 +110,7 @@ STATIC void interrupt_handler2(nrfx_rtc_int_type_t int_type) {
|
||||
void rtc_init0(void) {
|
||||
}
|
||||
|
||||
STATIC int rtc_find(mp_obj_t id) {
|
||||
static int rtc_find(mp_obj_t id) {
|
||||
// given an integer id
|
||||
int rtc_id = mp_obj_get_int(id);
|
||||
if (rtc_id >= 0 && rtc_id < MP_ARRAY_SIZE(machine_rtc_obj)) {
|
||||
@@ -119,7 +119,7 @@ STATIC int rtc_find(mp_obj_t id) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("RTCounter doesn't exist"));
|
||||
}
|
||||
|
||||
STATIC void rtc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void rtc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_rtc_obj_t *self = self_in;
|
||||
mp_printf(print, "RTCounter(%u)", self->p_rtc->instance_id);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ const nrfx_rtc_config_t machine_rtc_config = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum { ARG_id, ARG_period, ARG_mode, ARG_callback };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} },
|
||||
@@ -201,54 +201,54 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
|
||||
/// Start the RTCounter. Timeout occurs after number of periods
|
||||
/// in the configured frequency has been reached.
|
||||
///
|
||||
STATIC mp_obj_t machine_rtc_start(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_rtc_start(mp_obj_t self_in) {
|
||||
machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
nrfx_rtc_enable(self->p_rtc);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_start_obj, machine_rtc_start);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_start_obj, machine_rtc_start);
|
||||
|
||||
/// \method stop()
|
||||
/// Stop the RTCounter.
|
||||
///
|
||||
STATIC mp_obj_t machine_rtc_stop(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_rtc_stop(mp_obj_t self_in) {
|
||||
machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
nrfx_rtc_disable(self->p_rtc);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_stop_obj, machine_rtc_stop);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_stop_obj, machine_rtc_stop);
|
||||
|
||||
/// \method counter()
|
||||
/// Return the current counter value. Wraps around after about 24 days
|
||||
/// with the current prescaler (2^24 / 8 = 2097152 seconds).
|
||||
///
|
||||
STATIC mp_obj_t machine_rtc_counter(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_rtc_counter(mp_obj_t self_in) {
|
||||
machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
uint32_t counter = nrfx_rtc_counter_get(self->p_rtc);
|
||||
|
||||
return MP_OBJ_NEW_SMALL_INT(counter);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_counter_obj, machine_rtc_counter);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_counter_obj, machine_rtc_counter);
|
||||
|
||||
/// \method deinit()
|
||||
/// Free resources associated with this RTC.
|
||||
///
|
||||
STATIC mp_obj_t machine_rtc_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_rtc_deinit(mp_obj_t self_in) {
|
||||
machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
nrfx_rtc_uninit(self->p_rtc);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_deinit_obj, machine_rtc_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_deinit_obj, machine_rtc_deinit);
|
||||
|
||||
|
||||
STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&machine_rtc_start_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&machine_rtc_stop_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_counter), MP_ROM_PTR(&machine_rtc_counter_obj) },
|
||||
@@ -260,7 +260,7 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_FREQUENCY), MP_ROM_INT(RTC_FREQUENCY) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
machine_rtcounter_type,
|
||||
|
||||
@@ -49,7 +49,7 @@ typedef struct _machine_pwm_obj_t {
|
||||
#define SOFT_PWM_BASE_FREQ (1000000)
|
||||
#define DUTY_FULL_SCALE (1024)
|
||||
|
||||
STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_pwm_obj_t *self = self_in;
|
||||
static char *duty_suffix[] = { "", "", "_u16", "_ns" };
|
||||
mp_printf(print, "<PWM: Pin=%u freq=%dHz duty%s=%d>",
|
||||
@@ -59,9 +59,9 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p
|
||||
|
||||
// MicroPython bindings for machine API
|
||||
|
||||
STATIC void machine_soft_pwm_start(machine_pwm_obj_t *self);
|
||||
static void machine_soft_pwm_start(machine_pwm_obj_t *self);
|
||||
|
||||
STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||
@@ -91,7 +91,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, c
|
||||
machine_soft_pwm_start(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
enum { ARG_pin, ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns, ARG_id };
|
||||
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
@@ -117,15 +117,15 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
|
||||
static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) {
|
||||
pwm_release(self->pwm_pin);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) {
|
||||
static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) {
|
||||
return MP_OBJ_NEW_SMALL_INT(self->freq);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
|
||||
static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
|
||||
|
||||
if (freq > (SOFT_PWM_BASE_FREQ / 256)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("frequency out of range"));
|
||||
@@ -134,7 +134,7 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) {
|
||||
machine_soft_pwm_start(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) {
|
||||
static mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) {
|
||||
if (self->duty_mode) {
|
||||
return MP_OBJ_NEW_SMALL_INT(self->duty);
|
||||
} else if (self->duty_mode == DUTY_U16) {
|
||||
@@ -144,13 +144,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
static void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
self->duty = duty;
|
||||
self->duty_mode = DUTY;
|
||||
machine_soft_pwm_start(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
|
||||
static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
|
||||
if (self->duty_mode == DUTY_U16) {
|
||||
return MP_OBJ_NEW_SMALL_INT(self->duty);
|
||||
} else if (self->duty_mode == DUTY) {
|
||||
@@ -160,13 +160,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
self->duty = duty;
|
||||
self->duty_mode = DUTY_U16;
|
||||
machine_soft_pwm_start(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
|
||||
static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
|
||||
if (self->duty_mode == DUTY_NS) {
|
||||
return MP_OBJ_NEW_SMALL_INT(self->duty);
|
||||
} else {
|
||||
@@ -174,7 +174,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
self->duty = duty;
|
||||
self->duty_mode = DUTY_NS;
|
||||
machine_soft_pwm_start(self);
|
||||
@@ -182,7 +182,7 @@ STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) {
|
||||
|
||||
/* Interface for the implementation */
|
||||
|
||||
STATIC void machine_soft_pwm_start(machine_pwm_obj_t *self) {
|
||||
static void machine_soft_pwm_start(machine_pwm_obj_t *self) {
|
||||
|
||||
// check if ready to go
|
||||
if (self->defer_start == true || self->freq == 0 || self->duty_mode == DUTY_NOT_SET) {
|
||||
|
||||
@@ -103,7 +103,7 @@ typedef struct _machine_hard_spi_obj_t {
|
||||
nrfx_spi_config_t * p_config; // pointer to volatile part
|
||||
} machine_hard_spi_obj_t;
|
||||
|
||||
STATIC const nrfx_spi_t machine_spi_instances[] = {
|
||||
static const nrfx_spi_t machine_spi_instances[] = {
|
||||
NRFX_SPI_INSTANCE(0),
|
||||
NRFX_SPI_INSTANCE(1),
|
||||
#if defined(NRF52_SERIES)
|
||||
@@ -114,9 +114,9 @@ STATIC const nrfx_spi_t machine_spi_instances[] = {
|
||||
#endif // NRF52_SERIES
|
||||
};
|
||||
|
||||
STATIC nrfx_spi_config_t configs[MP_ARRAY_SIZE(machine_spi_instances)];
|
||||
static nrfx_spi_config_t configs[MP_ARRAY_SIZE(machine_spi_instances)];
|
||||
|
||||
STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
|
||||
static const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
|
||||
{{&machine_spi_type}, .p_spi = &machine_spi_instances[0], .p_config = &configs[0]},
|
||||
{{&machine_spi_type}, .p_spi = &machine_spi_instances[1], .p_config = &configs[1]},
|
||||
#if defined(NRF52_SERIES)
|
||||
@@ -130,7 +130,7 @@ STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
|
||||
void spi_init0(void) {
|
||||
}
|
||||
|
||||
STATIC int spi_find(mp_obj_t id) {
|
||||
static int spi_find(mp_obj_t id) {
|
||||
if (mp_obj_is_str(id)) {
|
||||
// given a string id
|
||||
const char *port = mp_obj_str_get_str(id);
|
||||
@@ -187,14 +187,14 @@ enum {
|
||||
ARG_INIT_firstbit
|
||||
};
|
||||
|
||||
STATIC void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_arg_val_t *args);
|
||||
static void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_arg_val_t *args);
|
||||
|
||||
STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_hard_spi_obj_t *self = self_in;
|
||||
mp_printf(print, "SPI(%u)", self->p_spi->drv_inst_idx);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} },
|
||||
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 1000000} },
|
||||
@@ -243,7 +243,7 @@ STATIC mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_ar
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_arg_val_t *args) {
|
||||
static void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_arg_val_t *args) {
|
||||
int baudrate = args[ARG_INIT_baudrate].u_int;
|
||||
|
||||
if (baudrate <= 125000) {
|
||||
@@ -304,7 +304,7 @@ STATIC void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000000} },
|
||||
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
@@ -321,17 +321,17 @@ STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const m
|
||||
machine_hard_spi_init_helper(self, args);
|
||||
}
|
||||
|
||||
STATIC void machine_hard_spi_deinit(mp_obj_base_t *self_in) {
|
||||
static void machine_hard_spi_deinit(mp_obj_base_t *self_in) {
|
||||
const machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
nrfx_spi_uninit(self->p_spi);
|
||||
}
|
||||
|
||||
STATIC void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
static void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
const machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t*)self_in;
|
||||
spi_transfer(self, len, src, dest);
|
||||
}
|
||||
|
||||
STATIC const mp_machine_spi_p_t machine_hard_spi_p = {
|
||||
static const mp_machine_spi_p_t machine_hard_spi_p = {
|
||||
.init = machine_hard_spi_init,
|
||||
.deinit = machine_hard_spi_deinit,
|
||||
.transfer = machine_hard_spi_transfer,
|
||||
|
||||
@@ -50,7 +50,7 @@ typedef struct _machine_temp_obj_t {
|
||||
|
||||
/// \method __str__()
|
||||
/// Return a string describing the Temp object.
|
||||
STATIC void machine_temp_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void machine_temp_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
machine_temp_obj_t *self = o;
|
||||
|
||||
(void)self;
|
||||
@@ -61,7 +61,7 @@ STATIC void machine_temp_print(const mp_print_t *print, mp_obj_t o, mp_print_kin
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings for machine API */
|
||||
|
||||
STATIC mp_obj_t machine_temp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t machine_temp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ },
|
||||
};
|
||||
@@ -89,7 +89,7 @@ int32_t temp_read(void) {
|
||||
|
||||
/// \method read()
|
||||
/// Get temperature.
|
||||
STATIC mp_obj_t machine_temp_read(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t machine_temp_read(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
|
||||
#if BLUETOOTH_SD
|
||||
if (BLUETOOTH_STACK_ENABLED() == 1) {
|
||||
@@ -102,15 +102,15 @@ STATIC mp_obj_t machine_temp_read(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
return MP_OBJ_NEW_SMALL_INT(temp_read());
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_temp_read_obj, 0, 1, machine_temp_read);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_temp_read_obj, 0, 1, machine_temp_read);
|
||||
|
||||
STATIC const mp_rom_map_elem_t machine_temp_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t machine_temp_locals_dict_table[] = {
|
||||
// instance methods
|
||||
// class methods
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_machine_temp_read_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(machine_temp_locals_dict, machine_temp_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(machine_temp_locals_dict, machine_temp_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
machine_temp_type,
|
||||
|
||||
@@ -41,7 +41,7 @@ typedef struct _machine_timer_obj_t {
|
||||
nrfx_timer_t p_instance;
|
||||
} machine_timer_obj_t;
|
||||
|
||||
STATIC mp_obj_t machine_timer_callbacks[] = {
|
||||
static mp_obj_t machine_timer_callbacks[] = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
@@ -51,7 +51,7 @@ STATIC mp_obj_t machine_timer_callbacks[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC const machine_timer_obj_t machine_timer_obj[] = {
|
||||
static const machine_timer_obj_t machine_timer_obj[] = {
|
||||
{{&machine_timer_type}, NRFX_TIMER_INSTANCE(0)},
|
||||
#if MICROPY_PY_MACHINE_SOFT_PWM
|
||||
{ },
|
||||
@@ -71,7 +71,7 @@ void timer_init0(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int timer_find(mp_obj_t id) {
|
||||
static int timer_find(mp_obj_t id) {
|
||||
// given an integer id
|
||||
int timer_id = mp_obj_get_int(id);
|
||||
if (timer_id >= 0 && timer_id < MP_ARRAY_SIZE(machine_timer_obj)) {
|
||||
@@ -80,12 +80,12 @@ STATIC int timer_find(mp_obj_t id) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("Timer doesn't exist"));
|
||||
}
|
||||
|
||||
STATIC void timer_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void timer_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
machine_timer_obj_t *self = o;
|
||||
mp_printf(print, "Timer(%u)", self->p_instance.instance_id);
|
||||
}
|
||||
|
||||
STATIC void timer_event_handler(nrf_timer_event_t event_type, void *p_context) {
|
||||
static void timer_event_handler(nrf_timer_event_t event_type, void *p_context) {
|
||||
machine_timer_obj_t *self = p_context;
|
||||
mp_obj_t callback = machine_timer_callbacks[self->p_instance.instance_id];
|
||||
if (callback != NULL) {
|
||||
@@ -96,7 +96,7 @@ STATIC void timer_event_handler(nrf_timer_event_t event_type, void *p_context) {
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings for machine API */
|
||||
|
||||
STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum { ARG_id, ARG_period, ARG_mode, ARG_callback };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} },
|
||||
@@ -175,52 +175,52 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
/// \method period()
|
||||
/// Return counter value, which is currently in us.
|
||||
///
|
||||
STATIC mp_obj_t machine_timer_period(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_timer_period(mp_obj_t self_in) {
|
||||
machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
uint32_t period = nrfx_timer_capture(&self->p_instance, NRF_TIMER_CC_CHANNEL1);
|
||||
|
||||
return MP_OBJ_NEW_SMALL_INT(period);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_period_obj, machine_timer_period);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_period_obj, machine_timer_period);
|
||||
|
||||
/// \method start()
|
||||
/// Start the timer.
|
||||
///
|
||||
STATIC mp_obj_t machine_timer_start(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_timer_start(mp_obj_t self_in) {
|
||||
machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
nrfx_timer_enable(&self->p_instance);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_start_obj, machine_timer_start);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_start_obj, machine_timer_start);
|
||||
|
||||
/// \method stop()
|
||||
/// Stop the timer.
|
||||
///
|
||||
STATIC mp_obj_t machine_timer_stop(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_timer_stop(mp_obj_t self_in) {
|
||||
machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
nrfx_timer_disable(&self->p_instance);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_stop_obj, machine_timer_stop);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_stop_obj, machine_timer_stop);
|
||||
|
||||
/// \method deinit()
|
||||
/// Free resources associated with the timer.
|
||||
///
|
||||
STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
|
||||
machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
nrfx_timer_uninit(&self->p_instance);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit);
|
||||
|
||||
STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t machine_timer_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&machine_timer_period_obj) }, // alias
|
||||
{ MP_ROM_QSTR(MP_QSTR_period), MP_ROM_PTR(&machine_timer_period_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&machine_timer_start_obj) },
|
||||
@@ -232,7 +232,7 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(TIMER_MODE_PERIODIC) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
machine_timer_type,
|
||||
|
||||
@@ -97,14 +97,14 @@ typedef struct _machine_uart_obj_t {
|
||||
|
||||
static const nrfx_uart_t instance0 = NRFX_UART_INSTANCE(0);
|
||||
|
||||
STATIC machine_uart_obj_t machine_uart_obj[] = {
|
||||
static machine_uart_obj_t machine_uart_obj[] = {
|
||||
{{&machine_uart_type}, .p_uart = &instance0}
|
||||
};
|
||||
|
||||
void uart_init0(void) {
|
||||
}
|
||||
|
||||
STATIC int uart_find(mp_obj_t id) {
|
||||
static int uart_find(mp_obj_t id) {
|
||||
// given an integer id
|
||||
int uart_id = mp_obj_get_int(id);
|
||||
if (uart_id >= 0 && uart_id < MP_ARRAY_SIZE(machine_uart_obj)) {
|
||||
@@ -113,7 +113,7 @@ STATIC int uart_find(mp_obj_t id) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("UART doesn't exist"));
|
||||
}
|
||||
|
||||
STATIC void uart_event_handler(nrfx_uart_event_t const *p_event, void *p_context) {
|
||||
static void uart_event_handler(nrfx_uart_event_t const *p_event, void *p_context) {
|
||||
machine_uart_obj_t *self = p_context;
|
||||
if (p_event->type == NRFX_UART_EVT_RX_DONE) {
|
||||
nrfx_uart_rx(self->p_uart, &self->buf.rx_buf[0], 1);
|
||||
@@ -142,7 +142,7 @@ int uart_rx_char(machine_uart_obj_t *self) {
|
||||
return ringbuf_get((ringbuf_t *)&self->buf.rx_ringbuf);
|
||||
}
|
||||
|
||||
STATIC nrfx_err_t uart_tx_char(machine_uart_obj_t *self, int c) {
|
||||
static nrfx_err_t uart_tx_char(machine_uart_obj_t *self, int c) {
|
||||
while (nrfx_uart_tx_in_progress(self->p_uart)) {
|
||||
;
|
||||
}
|
||||
@@ -172,11 +172,11 @@ void uart_tx_strn_cooked(machine_uart_obj_t *uart_obj, const char *str, uint len
|
||||
// The UART class doesn't have any constants for this port.
|
||||
#define MICROPY_PY_MACHINE_UART_CLASS_CONSTANTS
|
||||
|
||||
STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
mp_printf(print, "UART(0)");
|
||||
}
|
||||
|
||||
STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
// Parse args (none supported at this stage).
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, 0, NULL, NULL);
|
||||
}
|
||||
@@ -186,7 +186,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
|
||||
// Initialise the UART bus with the given parameters:
|
||||
// - `id`is bus id.
|
||||
// - `baudrate` is the clock rate.
|
||||
STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum { ARG_id, ARG_baudrate, ARG_timeout, ARG_timeout_char };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
@@ -266,12 +266,12 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) {
|
||||
static void mp_machine_uart_deinit(machine_uart_obj_t *self) {
|
||||
(void)self;
|
||||
}
|
||||
|
||||
// Write a single character on the bus. `data` is an integer to write.
|
||||
STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) {
|
||||
static void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) {
|
||||
nrfx_err_t err = uart_tx_char(self, data);
|
||||
if (err != NRFX_SUCCESS) {
|
||||
mp_hal_raise(err);
|
||||
@@ -280,21 +280,21 @@ STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) {
|
||||
|
||||
// Receive a single character on the bus.
|
||||
// Return value: The character read, as an integer. Returns -1 on timeout.
|
||||
STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) {
|
||||
static mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) {
|
||||
return uart_rx_char(self);
|
||||
}
|
||||
|
||||
// uart.any()
|
||||
STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) {
|
||||
static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) {
|
||||
return ringbuf_avail((ringbuf_t *)&self->buf.rx_ringbuf);
|
||||
}
|
||||
|
||||
// uart.txdone()
|
||||
STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
|
||||
static bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
|
||||
return !nrfx_uart_tx_in_progress(self->p_uart);
|
||||
}
|
||||
|
||||
STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
machine_uart_obj_t *self = self_in;
|
||||
byte *buf = buf_in;
|
||||
uint32_t t = self->timeout + mp_hal_ticks_ms();
|
||||
@@ -319,7 +319,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t
|
||||
return size;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
|
||||
machine_uart_obj_t *self = self_in;
|
||||
|
||||
nrfx_err_t err = nrfx_uart_tx(self->p_uart, buf_in, size);
|
||||
@@ -335,7 +335,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
machine_uart_obj_t *self = self_in;
|
||||
(void)self;
|
||||
mp_uint_t ret = 0;
|
||||
|
||||
@@ -74,7 +74,7 @@ enum {
|
||||
|
||||
extern volatile uint32_t ticks;
|
||||
|
||||
STATIC uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_t *pin);
|
||||
static uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_t *pin);
|
||||
|
||||
void microbit_music_init0(void) {
|
||||
ticker_register_low_pri_callback(microbit_music_tick);
|
||||
@@ -136,7 +136,7 @@ void microbit_music_tick(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void wait_async_music_idle(void) {
|
||||
static void wait_async_music_idle(void) {
|
||||
// wait for the async music state to become idle
|
||||
while (music_data->async_state != ASYNC_MUSIC_STATE_IDLE) {
|
||||
// allow CTRL-C to stop the music
|
||||
@@ -148,7 +148,7 @@ STATIC void wait_async_music_idle(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_t *pin) {
|
||||
static uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_t *pin) {
|
||||
pwm_set_duty_cycle(pin->pin, 128); // TODO: remove pin setting.
|
||||
|
||||
// [NOTE](#|b)(octave)(:length)
|
||||
@@ -157,9 +157,9 @@ STATIC uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_
|
||||
// array of us periods
|
||||
|
||||
// these are the periods of note4 (the octave ascending from middle c) from A->B then C->G
|
||||
STATIC uint16_t periods_us[] = {2273, 2025, 3822, 3405, 3034, 2863, 2551};
|
||||
static uint16_t periods_us[] = {2273, 2025, 3822, 3405, 3034, 2863, 2551};
|
||||
// A#, -, C#, D#, -, F#, G#
|
||||
STATIC uint16_t periods_sharps_us[] = {2145, 0, 3608, 3214, 0, 2703, 2408};
|
||||
static uint16_t periods_sharps_us[] = {2145, 0, 3608, 3214, 0, 2703, 2408};
|
||||
|
||||
// we'll represent the note as an integer (A=0, G=6)
|
||||
// TODO: validate the note
|
||||
@@ -258,7 +258,7 @@ STATIC uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_
|
||||
return gap_ms;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t microbit_music_reset(void) {
|
||||
static mp_obj_t microbit_music_reset(void) {
|
||||
music_data->bpm = DEFAULT_BPM;
|
||||
music_data->ticks = DEFAULT_TICKS;
|
||||
music_data->last_octave = DEFAULT_OCTAVE;
|
||||
@@ -268,7 +268,7 @@ STATIC mp_obj_t microbit_music_reset(void) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(microbit_music_reset_obj, microbit_music_reset);
|
||||
|
||||
STATIC mp_obj_t microbit_music_get_tempo(void) {
|
||||
static mp_obj_t microbit_music_get_tempo(void) {
|
||||
mp_obj_t tempo_tuple[2];
|
||||
|
||||
tempo_tuple[0] = mp_obj_new_int(music_data->bpm);
|
||||
@@ -278,7 +278,7 @@ STATIC mp_obj_t microbit_music_get_tempo(void) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(microbit_music_get_tempo_obj, microbit_music_get_tempo);
|
||||
|
||||
STATIC mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
const pin_obj_t *pin;
|
||||
if (n_args == 0) {
|
||||
#ifdef MICROPY_HW_MUSIC_PIN
|
||||
@@ -301,7 +301,7 @@ STATIC mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_music_stop_obj, 0, 1, microbit_music_stop);
|
||||
|
||||
STATIC mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_music, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_pin, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
@@ -370,7 +370,7 @@ STATIC mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args,
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(microbit_music_play_obj, 0, microbit_music_play);
|
||||
|
||||
STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_frequency, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_duration, MP_ARG_INT, {.u_int = -1} },
|
||||
@@ -433,7 +433,7 @@ STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args,
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(microbit_music_pitch_obj, 0, microbit_music_pitch);
|
||||
|
||||
STATIC mp_obj_t microbit_music_set_tempo(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t microbit_music_set_tempo(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_ticks, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_bpm, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
@@ -469,7 +469,7 @@ static mp_obj_t music_init(void) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(music___init___obj, music_init);
|
||||
|
||||
STATIC const mp_rom_map_elem_t microbit_music_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t microbit_music_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&music___init___obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(µbit_music_reset_obj) },
|
||||
@@ -502,7 +502,7 @@ STATIC const mp_rom_map_elem_t microbit_music_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_POWER_DOWN), MP_ROM_PTR(µbit_music_tune_power_down_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(microbit_music_locals_dict, microbit_music_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(microbit_music_locals_dict, microbit_music_locals_dict_table);
|
||||
|
||||
const mp_obj_module_t music_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -74,7 +74,7 @@ mp_obj_t nrf_flashbdev_readblocks(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return MP_OBJ_NEW_SMALL_INT(0);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nrf_flashbdev_readblocks_obj, 3, 4, nrf_flashbdev_readblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nrf_flashbdev_readblocks_obj, 3, 4, nrf_flashbdev_readblocks);
|
||||
|
||||
mp_obj_t nrf_flashbdev_writeblocks(size_t n_args, const mp_obj_t *args) {
|
||||
nrf_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
@@ -95,7 +95,7 @@ mp_obj_t nrf_flashbdev_writeblocks(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return MP_OBJ_NEW_SMALL_INT(0);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nrf_flashbdev_writeblocks_obj, 3, 4, nrf_flashbdev_writeblocks);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nrf_flashbdev_writeblocks_obj, 3, 4, nrf_flashbdev_writeblocks);
|
||||
|
||||
mp_obj_t nrf_flashbdev_ioctl(mp_obj_t self_in, mp_obj_t op_in, mp_obj_t arg_in) {
|
||||
nrf_flash_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
@@ -137,21 +137,21 @@ mp_obj_t nrf_flashbdev_ioctl(mp_obj_t self_in, mp_obj_t op_in, mp_obj_t arg_in)
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(nrf_flashbdev_ioctl_obj, nrf_flashbdev_ioctl);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_3(nrf_flashbdev_ioctl_obj, nrf_flashbdev_ioctl);
|
||||
|
||||
STATIC const mp_rom_map_elem_t nrf_flashbdev_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t nrf_flashbdev_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&nrf_flashbdev_readblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&nrf_flashbdev_writeblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&nrf_flashbdev_ioctl_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(nrf_flashbdev_locals_dict, nrf_flashbdev_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(nrf_flashbdev_locals_dict, nrf_flashbdev_locals_dict_table);
|
||||
|
||||
STATIC void nrf_flashbdev_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void nrf_flashbdev_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
nrf_flash_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "Flash(start=0x%08x, len=%u)", self->start, self->len);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t nrf_flashbdev_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t nrf_flashbdev_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
// Parse arguments
|
||||
enum { ARG_start, ARG_len };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
|
||||
@@ -45,7 +45,7 @@ extern uint32_t _unused_flash_start;
|
||||
extern uint32_t _unused_flash_len;
|
||||
|
||||
#if NRF_POWER_HAS_DCDCEN
|
||||
STATIC mp_obj_t dcdc(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t dcdc(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args > 0) {
|
||||
bool dcdc_state = mp_obj_is_true(args[0]);
|
||||
#if BLUETOOTH_SD
|
||||
@@ -59,14 +59,14 @@ STATIC mp_obj_t dcdc(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
return mp_obj_new_bool(nrf_power_dcdcen_get(NRF_POWER));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dcdc_obj, 0, 1, dcdc);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dcdc_obj, 0, 1, dcdc);
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
|
||||
mp_obj_t nrf_modnrf_freeflash_start_aligned(void) {
|
||||
return mp_obj_new_int_from_uint(FLASH_PAGE_ALIGN_UP((uint32_t)&_unused_flash_start));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_start_aligned_obj, nrf_modnrf_freeflash_start_aligned);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_start_aligned_obj, nrf_modnrf_freeflash_start_aligned);
|
||||
|
||||
mp_obj_t nrf_modnrf_freeflash_length_aligned(void) {
|
||||
uint32_t align_diff = FLASH_PAGE_ALIGN_UP((uint32_t)&_unused_flash_start) - ((uint32_t)&_unused_flash_start);
|
||||
@@ -74,10 +74,10 @@ mp_obj_t nrf_modnrf_freeflash_length_aligned(void) {
|
||||
uint32_t len_page_aligned = (temp_len / FLASH_PAGESIZE) * FLASH_PAGESIZE;
|
||||
return mp_obj_new_int_from_uint(len_page_aligned);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_length_aligned_obj, nrf_modnrf_freeflash_length_aligned);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_length_aligned_obj, nrf_modnrf_freeflash_length_aligned);
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t nrf_module_globals_table[] = {
|
||||
static const mp_rom_map_elem_t nrf_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_nrf) },
|
||||
#if NRF_POWER_HAS_DCDCEN
|
||||
{ MP_ROM_QSTR(MP_QSTR_dcdc), MP_ROM_PTR(&dcdc_obj) },
|
||||
@@ -88,7 +88,7 @@ STATIC const mp_rom_map_elem_t nrf_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_unused_flash_length), MP_ROM_PTR(&nrf_modnrf_freeflash_length_aligned_obj) },
|
||||
#endif
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(nrf_module_globals, nrf_module_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(nrf_module_globals, nrf_module_globals_table);
|
||||
|
||||
const mp_obj_module_t nrf_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -121,13 +121,13 @@ extern const mp_obj_type_t os_mbfs_fileio_type;
|
||||
extern const mp_obj_type_t os_mbfs_textio_type;
|
||||
|
||||
// Page indexes count down from the end of ROM.
|
||||
STATIC uint8_t first_page_index;
|
||||
STATIC uint8_t last_page_index;
|
||||
static uint8_t first_page_index;
|
||||
static uint8_t last_page_index;
|
||||
// The number of usable chunks in the file system.
|
||||
STATIC uint8_t chunks_in_file_system;
|
||||
static uint8_t chunks_in_file_system;
|
||||
// Index of chunk to start searches. This is randomised to even out wear.
|
||||
STATIC uint8_t start_index;
|
||||
STATIC file_chunk *file_system_chunks;
|
||||
static uint8_t start_index;
|
||||
static file_chunk *file_system_chunks;
|
||||
|
||||
// Defined by the linker
|
||||
extern byte _fs_start[];
|
||||
@@ -136,25 +136,25 @@ extern byte _fs_end[];
|
||||
STATIC_ASSERT((sizeof(file_chunk) == CHUNK_SIZE));
|
||||
|
||||
// From micro:bit memory.h
|
||||
STATIC inline byte *rounddown(byte *addr, uint32_t align) {
|
||||
static inline byte *rounddown(byte *addr, uint32_t align) {
|
||||
return (byte*)(((uint32_t)addr)&(-align));
|
||||
}
|
||||
|
||||
// From micro:bit memory.h
|
||||
STATIC inline byte *roundup(byte *addr, uint32_t align) {
|
||||
static inline byte *roundup(byte *addr, uint32_t align) {
|
||||
return (byte*)((((uint32_t)addr)+align-1)&(-align));
|
||||
}
|
||||
|
||||
|
||||
STATIC inline void *first_page(void) {
|
||||
static inline void *first_page(void) {
|
||||
return _fs_end - FLASH_PAGESIZE * first_page_index;
|
||||
}
|
||||
|
||||
STATIC inline void *last_page(void) {
|
||||
static inline void *last_page(void) {
|
||||
return _fs_end - FLASH_PAGESIZE * last_page_index;
|
||||
}
|
||||
|
||||
STATIC void init_limits(void) {
|
||||
static void init_limits(void) {
|
||||
// First determine where to end
|
||||
byte *end = _fs_end;
|
||||
end = rounddown(end, FLASH_PAGESIZE)-FLASH_PAGESIZE;
|
||||
@@ -169,7 +169,7 @@ STATIC void init_limits(void) {
|
||||
chunks_in_file_system = (end-start)>>MBFS_LOG_CHUNK_SIZE;
|
||||
}
|
||||
|
||||
STATIC void randomise_start_index(void) {
|
||||
static void randomise_start_index(void) {
|
||||
start_index = rng_generate_random_word() % chunks_in_file_system + 1;
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ void microbit_filesystem_init(void) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void copy_page(void *dest, void *src) {
|
||||
static void copy_page(void *dest, void *src) {
|
||||
DEBUG(("FILE DEBUG: Copying page from %lx to %lx.\r\n", (uint32_t)src, (uint32_t)dest));
|
||||
flash_page_erase((uint32_t)dest);
|
||||
file_chunk *src_chunk = src;
|
||||
@@ -210,7 +210,7 @@ STATIC void copy_page(void *dest, void *src) {
|
||||
// Then all the pages are copied, one by one, into the adjacent newly unused page.
|
||||
// Finally, the persistent data is saved back to the opposite end of the filesystem from whence it came.
|
||||
//
|
||||
STATIC void filesystem_sweep(void) {
|
||||
static void filesystem_sweep(void) {
|
||||
persistent_config_t config;
|
||||
uint8_t *page;
|
||||
uint8_t *end_page;
|
||||
@@ -240,11 +240,11 @@ STATIC void filesystem_sweep(void) {
|
||||
}
|
||||
|
||||
|
||||
STATIC inline byte *seek_address(file_descriptor_obj *self) {
|
||||
static inline byte *seek_address(file_descriptor_obj *self) {
|
||||
return (byte*)&(file_system_chunks[self->seek_chunk].data[self->seek_offset]);
|
||||
}
|
||||
|
||||
STATIC uint8_t microbit_find_file(const char *name, int name_len) {
|
||||
static uint8_t microbit_find_file(const char *name, int name_len) {
|
||||
for (uint8_t index = 1; index <= chunks_in_file_system; index++) {
|
||||
const file_chunk *p = &file_system_chunks[index];
|
||||
if (p->marker != FILE_START)
|
||||
@@ -268,7 +268,7 @@ STATIC uint8_t microbit_find_file(const char *name, int name_len) {
|
||||
// 3a. Sweep the filesystem and restart.
|
||||
// 3b. Otherwise, fail and return FILE_NOT_FOUND.
|
||||
//
|
||||
STATIC uint8_t find_chunk_and_erase(void) {
|
||||
static uint8_t find_chunk_and_erase(void) {
|
||||
// Start search at a random chunk to spread the wear more evenly.
|
||||
// Search for unused chunk
|
||||
uint8_t index = start_index;
|
||||
@@ -316,13 +316,13 @@ STATIC uint8_t find_chunk_and_erase(void) {
|
||||
return find_chunk_and_erase();
|
||||
}
|
||||
|
||||
STATIC mp_obj_t microbit_file_name(file_descriptor_obj *fd) {
|
||||
static mp_obj_t microbit_file_name(file_descriptor_obj *fd) {
|
||||
return mp_obj_new_str(&(file_system_chunks[fd->start_chunk].header.filename[0]), file_system_chunks[fd->start_chunk].header.name_len);
|
||||
}
|
||||
|
||||
STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary);
|
||||
static file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary);
|
||||
|
||||
STATIC void clear_file(uint8_t chunk) {
|
||||
static void clear_file(uint8_t chunk) {
|
||||
do {
|
||||
flash_write_byte((uint32_t)&(file_system_chunks[chunk].marker), FREED_CHUNK);
|
||||
DEBUG(("FILE DEBUG: Freeing chunk %d.\n", chunk));
|
||||
@@ -330,7 +330,7 @@ STATIC void clear_file(uint8_t chunk) {
|
||||
} while (chunk <= chunks_in_file_system);
|
||||
}
|
||||
|
||||
STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len, bool write, bool binary) {
|
||||
static file_descriptor_obj *microbit_file_open(const char *name, size_t name_len, bool write, bool binary) {
|
||||
if (name_len > MAX_FILENAME_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -355,7 +355,7 @@ STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len
|
||||
return microbit_file_descriptor_new(index, write, binary);
|
||||
}
|
||||
|
||||
STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) {
|
||||
static file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) {
|
||||
file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &os_mbfs_fileio_type : &os_mbfs_textio_type);
|
||||
res->start_chunk = start_chunk;
|
||||
res->seek_chunk = start_chunk;
|
||||
@@ -366,7 +366,7 @@ STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bo
|
||||
return res;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t microbit_remove(mp_obj_t filename) {
|
||||
static mp_obj_t microbit_remove(mp_obj_t filename) {
|
||||
size_t name_len;
|
||||
const char *name = mp_obj_str_get_data(filename, &name_len);
|
||||
mp_uint_t index = microbit_find_file(name, name_len);
|
||||
@@ -377,13 +377,13 @@ STATIC mp_obj_t microbit_remove(mp_obj_t filename) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC void check_file_open(file_descriptor_obj *self) {
|
||||
static void check_file_open(file_descriptor_obj *self) {
|
||||
if (!self->open) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file"));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC int advance(file_descriptor_obj *self, uint32_t n, bool write) {
|
||||
static int advance(file_descriptor_obj *self, uint32_t n, bool write) {
|
||||
DEBUG(("FILE DEBUG: Advancing from chunk %d, offset %d.\r\n", self->seek_chunk, self->seek_offset));
|
||||
self->seek_offset += n;
|
||||
if (self->seek_offset == DATA_PER_CHUNK) {
|
||||
@@ -405,7 +405,7 @@ STATIC int advance(file_descriptor_obj *self, uint32_t n, bool write) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) {
|
||||
file_descriptor_obj *self = (file_descriptor_obj *)obj;
|
||||
check_file_open(self);
|
||||
if (self->writable || file_system_chunks[self->start_chunk].marker == FREED_CHUNK) {
|
||||
@@ -435,7 +435,7 @@ STATIC mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) {
|
||||
static mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) {
|
||||
file_descriptor_obj *self = (file_descriptor_obj *)obj;
|
||||
check_file_open(self);
|
||||
if (!self->writable || file_system_chunks[self->start_chunk].marker == FREED_CHUNK) {
|
||||
@@ -458,14 +458,14 @@ STATIC mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t si
|
||||
return size;
|
||||
}
|
||||
|
||||
STATIC void microbit_file_close(file_descriptor_obj *fd) {
|
||||
static void microbit_file_close(file_descriptor_obj *fd) {
|
||||
if (fd->writable) {
|
||||
flash_write_byte((uint32_t)&(file_system_chunks[fd->start_chunk].header.end_offset), fd->seek_offset);
|
||||
}
|
||||
fd->open = false;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t microbit_file_list(void) {
|
||||
static mp_obj_t microbit_file_list(void) {
|
||||
mp_obj_t res = mp_obj_new_list(0, NULL);
|
||||
for (uint8_t index = 1; index <= chunks_in_file_system; index++) {
|
||||
if (file_system_chunks[index].marker == FILE_START) {
|
||||
@@ -476,7 +476,7 @@ STATIC mp_obj_t microbit_file_list(void) {
|
||||
return res;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t microbit_file_size(mp_obj_t filename) {
|
||||
static mp_obj_t microbit_file_size(mp_obj_t filename) {
|
||||
size_t name_len;
|
||||
const char *name = mp_obj_str_get_data(filename, &name_len);
|
||||
uint8_t chunk = microbit_find_file(name, name_len);
|
||||
@@ -495,7 +495,7 @@ STATIC mp_obj_t microbit_file_size(mp_obj_t filename) {
|
||||
return mp_obj_new_int(len);
|
||||
}
|
||||
|
||||
STATIC mp_uint_t file_read_byte(file_descriptor_obj *fd) {
|
||||
static mp_uint_t file_read_byte(file_descriptor_obj *fd) {
|
||||
if (file_system_chunks[fd->seek_chunk].next_chunk == UNUSED_CHUNK) {
|
||||
uint8_t end_offset = file_system_chunks[fd->start_chunk].header.end_offset;
|
||||
if (end_offset == UNUSED_CHUNK || fd->seek_offset == end_offset) {
|
||||
@@ -530,29 +530,29 @@ mp_import_stat_t os_mbfs_import_stat(const char *path) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t os_mbfs_file_name(mp_obj_t self) {
|
||||
static mp_obj_t os_mbfs_file_name(mp_obj_t self) {
|
||||
file_descriptor_obj *fd = (file_descriptor_obj*)self;
|
||||
return microbit_file_name(fd);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name);
|
||||
|
||||
STATIC mp_obj_t os_mbfs_file_close(mp_obj_t self) {
|
||||
static mp_obj_t os_mbfs_file_close(mp_obj_t self) {
|
||||
file_descriptor_obj *fd = (file_descriptor_obj*)self;
|
||||
microbit_file_close(fd);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close);
|
||||
|
||||
STATIC mp_obj_t os_mbfs_remove(mp_obj_t name) {
|
||||
static mp_obj_t os_mbfs_remove(mp_obj_t name) {
|
||||
return microbit_remove(name);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_remove_obj, os_mbfs_remove);
|
||||
|
||||
STATIC mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
return os_mbfs_file_close(args[0]);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__);
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
@@ -560,7 +560,7 @@ typedef struct {
|
||||
uint8_t index;
|
||||
} os_mbfs_ilistdir_it_t;
|
||||
|
||||
STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
static mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
os_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// Read until the next FILE_START chunk.
|
||||
@@ -585,7 +585,7 @@ STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
return MP_OBJ_STOP_ITERATION;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t os_mbfs_ilistdir(void) {
|
||||
static mp_obj_t os_mbfs_ilistdir(void) {
|
||||
os_mbfs_ilistdir_it_t *iter = mp_obj_malloc(os_mbfs_ilistdir_it_t, &mp_type_polymorph_iter);
|
||||
iter->iternext = os_mbfs_ilistdir_it_iternext;
|
||||
iter->index = 1;
|
||||
@@ -596,12 +596,12 @@ MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj, os_mbfs_ilistdir);
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj, microbit_file_list);
|
||||
|
||||
STATIC mp_obj_t microbit_file_writable(mp_obj_t self) {
|
||||
static mp_obj_t microbit_file_writable(mp_obj_t self) {
|
||||
return mp_obj_new_bool(((file_descriptor_obj *)self)->writable);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable);
|
||||
|
||||
STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = {
|
||||
static const mp_map_elem_t os_mbfs_file_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&os_mbfs_file_close_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&os_mbfs_file_name_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), (mp_obj_t)&mp_identity_obj },
|
||||
@@ -613,10 +613,10 @@ STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table);
|
||||
|
||||
|
||||
STATIC const mp_stream_p_t textio_stream_p = {
|
||||
static const mp_stream_p_t textio_stream_p = {
|
||||
.read = microbit_file_read,
|
||||
.write = microbit_file_write,
|
||||
.is_text = true,
|
||||
@@ -631,7 +631,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
);
|
||||
|
||||
|
||||
STATIC const mp_stream_p_t fileio_stream_p = {
|
||||
static const mp_stream_p_t fileio_stream_p = {
|
||||
.read = microbit_file_read,
|
||||
.write = microbit_file_write,
|
||||
};
|
||||
@@ -679,7 +679,7 @@ mode_error:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("illegal mode"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t os_mbfs_stat(mp_obj_t filename) {
|
||||
static mp_obj_t os_mbfs_stat(mp_obj_t filename) {
|
||||
mp_obj_t file_size = microbit_file_size(filename);
|
||||
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
#if MICROPY_PY_OS_URANDOM
|
||||
// Return a bytes object with n random bytes, generated by the hardware random number generator.
|
||||
STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
static mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
mp_int_t n = mp_obj_get_int(num);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, n);
|
||||
@@ -42,7 +42,7 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) {
|
||||
}
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom);
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
|
||||
@@ -37,7 +37,7 @@ extern const mp_obj_type_t ubluepy_constants_type;
|
||||
extern const mp_obj_type_t ubluepy_scanner_type;
|
||||
extern const mp_obj_type_t ubluepy_scan_entry_type;
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = {
|
||||
static const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluepy) },
|
||||
#if MICROPY_PY_UBLUEPY_PERIPHERAL
|
||||
{ MP_ROM_QSTR(MP_QSTR_Peripheral), MP_ROM_PTR(&ubluepy_peripheral_type) },
|
||||
@@ -60,7 +60,7 @@ STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = {
|
||||
};
|
||||
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_ubluepy_globals, mp_module_ubluepy_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(mp_module_ubluepy_globals, mp_module_ubluepy_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_ubluepy = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
#include "modubluepy.h"
|
||||
#include "ble_drv.h"
|
||||
|
||||
STATIC void ubluepy_characteristic_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void ubluepy_characteristic_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
ubluepy_characteristic_obj_t * self = (ubluepy_characteristic_obj_t *)o;
|
||||
|
||||
mp_printf(print, "Characteristic(handle: 0x" HEX2_FMT ", conn_handle: " HEX2_FMT ")",
|
||||
self->handle, self->p_service->p_periph->conn_handle);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ubluepy_characteristic_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t ubluepy_characteristic_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_uuid, MP_ARG_REQUIRED| MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_props, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = UBLUEPY_PROP_READ | UBLUEPY_PROP_WRITE} },
|
||||
@@ -90,7 +90,7 @@ void char_data_callback(mp_obj_t self_in, uint16_t length, uint8_t * p_data) {
|
||||
/// \method read()
|
||||
/// Read Characteristic value.
|
||||
///
|
||||
STATIC mp_obj_t char_read(mp_obj_t self_in) {
|
||||
static mp_obj_t char_read(mp_obj_t self_in) {
|
||||
ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
#if MICROPY_PY_UBLUEPY_CENTRAL
|
||||
@@ -107,12 +107,12 @@ STATIC mp_obj_t char_read(mp_obj_t self_in) {
|
||||
return mp_const_none;
|
||||
#endif
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_read_obj, char_read);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_read_obj, char_read);
|
||||
|
||||
/// \method write(data, [with_response=False])
|
||||
/// Write Characteristic value.
|
||||
///
|
||||
STATIC mp_obj_t char_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t char_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
ubluepy_characteristic_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
mp_obj_t data = pos_args[1];
|
||||
|
||||
@@ -155,28 +155,28 @@ STATIC mp_obj_t char_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_characteristic_write_obj, 2, char_write);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_characteristic_write_obj, 2, char_write);
|
||||
|
||||
/// \method properties()
|
||||
/// Read Characteristic value properties.
|
||||
///
|
||||
STATIC mp_obj_t char_properties(mp_obj_t self_in) {
|
||||
static mp_obj_t char_properties(mp_obj_t self_in) {
|
||||
ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
return MP_OBJ_NEW_SMALL_INT(self->props);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_get_properties_obj, char_properties);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_get_properties_obj, char_properties);
|
||||
|
||||
/// \method uuid()
|
||||
/// Get UUID instance of the characteristic.
|
||||
///
|
||||
STATIC mp_obj_t char_uuid(mp_obj_t self_in) {
|
||||
static mp_obj_t char_uuid(mp_obj_t self_in) {
|
||||
ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
return MP_OBJ_FROM_PTR(self->p_uuid);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_get_uuid_obj, char_uuid);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_get_uuid_obj, char_uuid);
|
||||
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_characteristic_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_characteristic_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&ubluepy_characteristic_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&ubluepy_characteristic_write_obj) },
|
||||
#if 0
|
||||
@@ -207,7 +207,7 @@ STATIC const mp_rom_map_elem_t ubluepy_characteristic_locals_dict_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_characteristic_locals_dict, ubluepy_characteristic_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_characteristic_locals_dict, ubluepy_characteristic_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_characteristic_type,
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#include "modubluepy.h"
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_constants_ad_types_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_constants_ad_types_locals_dict_table[] = {
|
||||
// GAP AD Types
|
||||
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_FLAGS), MP_ROM_INT(0x01) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE), MP_ROM_INT(0x02) },
|
||||
@@ -67,7 +67,7 @@ STATIC const mp_rom_map_elem_t ubluepy_constants_ad_types_locals_dict_table[] =
|
||||
{ MP_ROM_QSTR(MP_QSTR_AD_TYPE_MANUFACTURER_SPECIFIC_DATA), MP_ROM_INT(0xFF) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_ad_types_locals_dict, ubluepy_constants_ad_types_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_constants_ad_types_locals_dict, ubluepy_constants_ad_types_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_constants_ad_types_type,
|
||||
@@ -76,7 +76,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &ubluepy_constants_ad_types_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = {
|
||||
// GAP events
|
||||
{ MP_ROM_QSTR(MP_QSTR_EVT_GAP_CONNECTED), MP_ROM_INT(16) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_EVT_GAP_DISCONNECTED), MP_ROM_INT(17) },
|
||||
@@ -89,7 +89,7 @@ STATIC const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_ad_types), MP_ROM_PTR(&ubluepy_constants_ad_types_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_locals_dict, ubluepy_constants_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_constants_locals_dict, ubluepy_constants_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_constants_type,
|
||||
|
||||
@@ -31,13 +31,13 @@
|
||||
|
||||
#include "modubluepy.h"
|
||||
|
||||
STATIC void ubluepy_delegate_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void ubluepy_delegate_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
ubluepy_delegate_obj_t * self = (ubluepy_delegate_obj_t *)o;
|
||||
(void)self;
|
||||
mp_printf(print, "DefaultDelegate()");
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ubluepy_delegate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t ubluepy_delegate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
ubluepy_delegate_obj_t *s = mp_obj_malloc(ubluepy_delegate_obj_t, type);
|
||||
|
||||
return MP_OBJ_FROM_PTR(s);
|
||||
@@ -46,28 +46,28 @@ STATIC mp_obj_t ubluepy_delegate_make_new(const mp_obj_type_t *type, size_t n_ar
|
||||
/// \method handleConnection()
|
||||
/// Handle connection events.
|
||||
///
|
||||
STATIC mp_obj_t delegate_handle_conn(mp_obj_t self_in) {
|
||||
static mp_obj_t delegate_handle_conn(mp_obj_t self_in) {
|
||||
ubluepy_delegate_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
(void)self;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_conn_obj, delegate_handle_conn);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_conn_obj, delegate_handle_conn);
|
||||
|
||||
/// \method handleNotification()
|
||||
/// Handle notification events.
|
||||
///
|
||||
STATIC mp_obj_t delegate_handle_notif(mp_obj_t self_in) {
|
||||
static mp_obj_t delegate_handle_notif(mp_obj_t self_in) {
|
||||
ubluepy_delegate_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
(void)self;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_notif_obj, delegate_handle_notif);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_notif_obj, delegate_handle_notif);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_delegate_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_delegate_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_handleConnection), MP_ROM_PTR(&ubluepy_delegate_handle_conn_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_handleNotification), MP_ROM_PTR(&ubluepy_delegate_handle_notif_obj) },
|
||||
#if 0
|
||||
@@ -75,7 +75,7 @@ STATIC const mp_rom_map_elem_t ubluepy_delegate_locals_dict_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_delegate_locals_dict, ubluepy_delegate_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_delegate_locals_dict, ubluepy_delegate_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_delegate_type,
|
||||
|
||||
@@ -34,14 +34,14 @@
|
||||
#include "modubluepy.h"
|
||||
#include "ble_drv.h"
|
||||
|
||||
STATIC void ubluepy_descriptor_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void ubluepy_descriptor_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
ubluepy_descriptor_obj_t * self = (ubluepy_descriptor_obj_t *)o;
|
||||
|
||||
mp_printf(print, "Descriptor(uuid: 0x" HEX2_FMT HEX2_FMT ")",
|
||||
self->p_uuid->value[1], self->p_uuid->value[0]);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ubluepy_descriptor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t ubluepy_descriptor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
|
||||
enum { ARG_NEW_UUID };
|
||||
|
||||
@@ -62,13 +62,13 @@ STATIC mp_obj_t ubluepy_descriptor_make_new(const mp_obj_type_t *type, size_t n_
|
||||
return MP_OBJ_FROM_PTR(s);
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_descriptor_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_descriptor_locals_dict_table[] = {
|
||||
#if 0
|
||||
{ MP_ROM_QSTR(MP_QSTR_binVal), MP_ROM_PTR(&ubluepy_descriptor_bin_val_obj) },
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_descriptor_locals_dict, ubluepy_descriptor_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_descriptor_locals_dict, ubluepy_descriptor_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_descriptor_type,
|
||||
|
||||
@@ -34,14 +34,14 @@
|
||||
|
||||
#include "ble_drv.h"
|
||||
|
||||
STATIC void ubluepy_peripheral_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void ubluepy_peripheral_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
ubluepy_peripheral_obj_t * self = (ubluepy_peripheral_obj_t *)o;
|
||||
(void)self;
|
||||
mp_printf(print, "Peripheral(conn_handle: " HEX2_FMT ")",
|
||||
self->conn_handle);
|
||||
}
|
||||
|
||||
STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) {
|
||||
static void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (event_id == 16) { // connect event
|
||||
@@ -68,7 +68,7 @@ STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn
|
||||
(void)self;
|
||||
}
|
||||
|
||||
STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) {
|
||||
static void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (self->conn_handler != mp_const_none) {
|
||||
@@ -92,14 +92,14 @@ STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t at
|
||||
|
||||
static volatile bool m_disc_evt_received;
|
||||
|
||||
STATIC void gattc_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) {
|
||||
static void gattc_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
(void)self;
|
||||
m_disc_evt_received = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum {
|
||||
ARG_NEW_DEVICE_ADDR,
|
||||
ARG_NEW_ADDR_TYPE
|
||||
@@ -129,45 +129,45 @@ STATIC mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_
|
||||
/// \method withDelegate(DefaultDelegate)
|
||||
/// Set delegate instance for handling Bluetooth LE events.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_with_delegate(mp_obj_t self_in, mp_obj_t delegate) {
|
||||
static mp_obj_t peripheral_with_delegate(mp_obj_t self_in, mp_obj_t delegate) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
self->delegate = delegate;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_with_delegate_obj, peripheral_with_delegate);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_with_delegate_obj, peripheral_with_delegate);
|
||||
|
||||
/// \method setNotificationHandler(func)
|
||||
/// Set handler for Bluetooth LE notification events.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_set_notif_handler(mp_obj_t self_in, mp_obj_t func) {
|
||||
static mp_obj_t peripheral_set_notif_handler(mp_obj_t self_in, mp_obj_t func) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
self->notif_handler = func;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_notif_handler_obj, peripheral_set_notif_handler);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_notif_handler_obj, peripheral_set_notif_handler);
|
||||
|
||||
/// \method setConnectionHandler(func)
|
||||
/// Set handler for Bluetooth LE connection events.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_set_conn_handler(mp_obj_t self_in, mp_obj_t func) {
|
||||
static mp_obj_t peripheral_set_conn_handler(mp_obj_t self_in, mp_obj_t func) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
self->conn_handler = func;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_conn_handler_obj, peripheral_set_conn_handler);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_conn_handler_obj, peripheral_set_conn_handler);
|
||||
|
||||
#if MICROPY_PY_UBLUEPY_PERIPHERAL
|
||||
|
||||
/// \method advertise(device_name, [service=[service1, service2, ...]], [data=bytearray], [connectable=True])
|
||||
/// Start advertising. Connectable advertisement type by default.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_device_name, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_services, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
@@ -231,12 +231,12 @@ STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args,
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_advertise_obj, 0, peripheral_advertise);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_advertise_obj, 0, peripheral_advertise);
|
||||
|
||||
/// \method advertise_stop()
|
||||
/// Stop advertisement if any onging advertisement.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_advertise_stop(mp_obj_t self_in) {
|
||||
static mp_obj_t peripheral_advertise_stop(mp_obj_t self_in) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
(void)self;
|
||||
@@ -245,26 +245,26 @@ STATIC mp_obj_t peripheral_advertise_stop(mp_obj_t self_in) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_advertise_stop_obj, peripheral_advertise_stop);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_advertise_stop_obj, peripheral_advertise_stop);
|
||||
|
||||
#endif // MICROPY_PY_UBLUEPY_PERIPHERAL
|
||||
|
||||
/// \method disconnect()
|
||||
/// disconnect connection.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_disconnect(mp_obj_t self_in) {
|
||||
static mp_obj_t peripheral_disconnect(mp_obj_t self_in) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
(void)self;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_disconnect_obj, peripheral_disconnect);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_disconnect_obj, peripheral_disconnect);
|
||||
|
||||
/// \method addService(Service)
|
||||
/// Add service to the Peripheral.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_add_service(mp_obj_t self_in, mp_obj_t service) {
|
||||
static mp_obj_t peripheral_add_service(mp_obj_t self_in, mp_obj_t service) {
|
||||
ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
ubluepy_service_obj_t * p_service = MP_OBJ_TO_PTR(service);
|
||||
|
||||
@@ -274,17 +274,17 @@ STATIC mp_obj_t peripheral_add_service(mp_obj_t self_in, mp_obj_t service) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_add_service_obj, peripheral_add_service);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_add_service_obj, peripheral_add_service);
|
||||
|
||||
/// \method getServices()
|
||||
/// Return list with all service registered in the Peripheral.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_get_services(mp_obj_t self_in) {
|
||||
static mp_obj_t peripheral_get_services(mp_obj_t self_in) {
|
||||
ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
return self->service_list;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_get_services_obj, peripheral_get_services);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_get_services_obj, peripheral_get_services);
|
||||
|
||||
#if MICROPY_PY_UBLUEPY_CENTRAL
|
||||
|
||||
@@ -337,7 +337,7 @@ void static disc_add_char(mp_obj_t service_in, ble_drv_char_data_t * p_desc_data
|
||||
/// addr_type can be either ADDR_TYPE_PUBLIC (default) or
|
||||
/// ADDR_TYPE_RANDOM_STATIC.
|
||||
///
|
||||
STATIC mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
mp_obj_t dev_addr = pos_args[1];
|
||||
|
||||
@@ -439,11 +439,11 @@ STATIC mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, m
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_connect_obj, 2, peripheral_connect);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_connect_obj, 2, peripheral_connect);
|
||||
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_peripheral_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_peripheral_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_withDelegate), MP_ROM_PTR(&ubluepy_peripheral_with_delegate_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setNotificationHandler), MP_ROM_PTR(&ubluepy_peripheral_set_notif_handler_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setConnectionHandler), MP_ROM_PTR(&ubluepy_peripheral_set_conn_handler_obj) },
|
||||
@@ -480,7 +480,7 @@ STATIC const mp_rom_map_elem_t ubluepy_peripheral_locals_dict_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_peripheral_locals_dict, ubluepy_peripheral_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_peripheral_locals_dict, ubluepy_peripheral_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_peripheral_type,
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
#include "ble_drv.h"
|
||||
|
||||
STATIC void ubluepy_scan_entry_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void ubluepy_scan_entry_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
ubluepy_scan_entry_obj_t * self = (ubluepy_scan_entry_obj_t *)o;
|
||||
(void)self;
|
||||
mp_printf(print, "ScanEntry");
|
||||
@@ -46,34 +46,34 @@ STATIC void ubluepy_scan_entry_print(const mp_print_t *print, mp_obj_t o, mp_pri
|
||||
/// \method addr()
|
||||
/// Return address as text string.
|
||||
///
|
||||
STATIC mp_obj_t scan_entry_get_addr(mp_obj_t self_in) {
|
||||
static mp_obj_t scan_entry_get_addr(mp_obj_t self_in) {
|
||||
ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return self->addr;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_obj, scan_entry_get_addr);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_obj, scan_entry_get_addr);
|
||||
|
||||
/// \method addr_type()
|
||||
/// Return address type value.
|
||||
///
|
||||
STATIC mp_obj_t scan_entry_get_addr_type(mp_obj_t self_in) {
|
||||
static mp_obj_t scan_entry_get_addr_type(mp_obj_t self_in) {
|
||||
ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return mp_obj_new_int(self->addr_type);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_type_obj, scan_entry_get_addr_type);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_type_obj, scan_entry_get_addr_type);
|
||||
|
||||
/// \method rssi()
|
||||
/// Return RSSI value.
|
||||
///
|
||||
STATIC mp_obj_t scan_entry_get_rssi(mp_obj_t self_in) {
|
||||
static mp_obj_t scan_entry_get_rssi(mp_obj_t self_in) {
|
||||
ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return mp_obj_new_int(self->rssi);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_rssi_obj, scan_entry_get_rssi);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_rssi_obj, scan_entry_get_rssi);
|
||||
|
||||
/// \method getScanData()
|
||||
/// Return list of the scan data tuples (ad_type, description, value)
|
||||
///
|
||||
STATIC mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) {
|
||||
static mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) {
|
||||
ubluepy_scan_entry_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
mp_obj_t retval_list = mp_obj_new_list(0, NULL);
|
||||
@@ -125,16 +125,16 @@ STATIC mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) {
|
||||
|
||||
return retval_list;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_scan_entry_get_scan_data_obj, scan_entry_get_scan_data);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_scan_entry_get_scan_data_obj, scan_entry_get_scan_data);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_scan_entry_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_scan_entry_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_addr), MP_ROM_PTR(&bluepy_scan_entry_get_addr_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_addr_type), MP_ROM_PTR(&bluepy_scan_entry_get_addr_type_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bluepy_scan_entry_get_rssi_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getScanData), MP_ROM_PTR(&ubluepy_scan_entry_get_scan_data_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_scan_entry_locals_dict, ubluepy_scan_entry_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_scan_entry_locals_dict, ubluepy_scan_entry_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_scan_entry_type,
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "ble_drv.h"
|
||||
#include "mphalport.h"
|
||||
|
||||
STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_data_t * data) {
|
||||
static void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_data_t * data) {
|
||||
ubluepy_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
ubluepy_scan_entry_obj_t * item = mp_obj_malloc(ubluepy_scan_entry_obj_t, &ubluepy_scan_entry_type);
|
||||
@@ -62,13 +62,13 @@ STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_d
|
||||
ble_drv_scan_start(true);
|
||||
}
|
||||
|
||||
STATIC void ubluepy_scanner_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void ubluepy_scanner_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
ubluepy_scanner_obj_t * self = (ubluepy_scanner_obj_t *)o;
|
||||
(void)self;
|
||||
mp_printf(print, "Scanner");
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
|
||||
};
|
||||
@@ -86,7 +86,7 @@ STATIC mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
/// Scan for devices. Timeout is in milliseconds and will set the duration
|
||||
/// of the scanning.
|
||||
///
|
||||
STATIC mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) {
|
||||
static mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) {
|
||||
ubluepy_scanner_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t timeout = mp_obj_get_int(timeout_in);
|
||||
|
||||
@@ -105,13 +105,13 @@ STATIC mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) {
|
||||
|
||||
return self->adv_reports;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_scanner_scan_obj, scanner_scan);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_scanner_scan_obj, scanner_scan);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_scanner_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_scanner_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&ubluepy_scanner_scan_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_scanner_locals_dict, ubluepy_scanner_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_scanner_locals_dict, ubluepy_scanner_locals_dict_table);
|
||||
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
|
||||
@@ -33,13 +33,13 @@
|
||||
#include "modubluepy.h"
|
||||
#include "ble_drv.h"
|
||||
|
||||
STATIC void ubluepy_service_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void ubluepy_service_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
ubluepy_service_obj_t * self = (ubluepy_service_obj_t *)o;
|
||||
|
||||
mp_printf(print, "Service(handle: 0x" HEX2_FMT ")", self->handle);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
|
||||
enum { ARG_NEW_UUID, ARG_NEW_TYPE };
|
||||
|
||||
@@ -86,7 +86,7 @@ STATIC mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
/// \method addCharacteristic(Characteristic)
|
||||
/// Add Characteristic to the Service.
|
||||
///
|
||||
STATIC mp_obj_t service_add_characteristic(mp_obj_t self_in, mp_obj_t characteristic) {
|
||||
static mp_obj_t service_add_characteristic(mp_obj_t self_in, mp_obj_t characteristic) {
|
||||
ubluepy_service_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
ubluepy_characteristic_obj_t * p_char = MP_OBJ_TO_PTR(characteristic);
|
||||
|
||||
@@ -103,22 +103,22 @@ STATIC mp_obj_t service_add_characteristic(mp_obj_t self_in, mp_obj_t characteri
|
||||
// return mp_obj_new_bool(retval);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_add_char_obj, service_add_characteristic);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_add_char_obj, service_add_characteristic);
|
||||
|
||||
/// \method getCharacteristics()
|
||||
/// Return list with all characteristics registered in the Service.
|
||||
///
|
||||
STATIC mp_obj_t service_get_chars(mp_obj_t self_in) {
|
||||
static mp_obj_t service_get_chars(mp_obj_t self_in) {
|
||||
ubluepy_service_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
return self->char_list;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_service_get_chars_obj, service_get_chars);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_service_get_chars_obj, service_get_chars);
|
||||
|
||||
/// \method getCharacteristic(UUID)
|
||||
/// Return Characteristic with the given UUID.
|
||||
///
|
||||
STATIC mp_obj_t service_get_characteristic(mp_obj_t self_in, mp_obj_t uuid) {
|
||||
static mp_obj_t service_get_characteristic(mp_obj_t self_in, mp_obj_t uuid) {
|
||||
ubluepy_service_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
ubluepy_uuid_obj_t * p_uuid = MP_OBJ_TO_PTR(uuid);
|
||||
|
||||
@@ -145,18 +145,18 @@ STATIC mp_obj_t service_get_characteristic(mp_obj_t self_in, mp_obj_t uuid) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_get_char_obj, service_get_characteristic);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_get_char_obj, service_get_characteristic);
|
||||
|
||||
/// \method uuid()
|
||||
/// Get UUID instance of the Service.
|
||||
///
|
||||
STATIC mp_obj_t service_uuid(mp_obj_t self_in) {
|
||||
static mp_obj_t service_uuid(mp_obj_t self_in) {
|
||||
ubluepy_service_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
return MP_OBJ_FROM_PTR(self->p_uuid);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_service_get_uuid_obj, service_uuid);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_service_get_uuid_obj, service_uuid);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_service_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_service_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_getCharacteristic), MP_ROM_PTR(&ubluepy_service_get_char_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_addCharacteristic), MP_ROM_PTR(&ubluepy_service_add_char_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getCharacteristics), MP_ROM_PTR(&ubluepy_service_get_chars_obj) },
|
||||
@@ -169,7 +169,7 @@ STATIC const mp_rom_map_elem_t ubluepy_service_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_SECONDARY), MP_ROM_INT(UBLUEPY_SERVICE_SECONDARY) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_service_locals_dict, ubluepy_service_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_service_locals_dict, ubluepy_service_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_service_type,
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "modubluepy.h"
|
||||
#include "ble_drv.h"
|
||||
|
||||
STATIC void ubluepy_uuid_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
static void ubluepy_uuid_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
ubluepy_uuid_obj_t * self = (ubluepy_uuid_obj_t *)o;
|
||||
if (self->type == UBLUEPY_UUID_16_BIT) {
|
||||
mp_printf(print, "UUID(uuid: 0x" HEX2_FMT HEX2_FMT ")",
|
||||
@@ -45,7 +45,7 @@ STATIC void ubluepy_uuid_print(const mp_print_t *print, mp_obj_t o, mp_print_kin
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
|
||||
enum { ARG_NEW_UUID };
|
||||
|
||||
@@ -140,7 +140,7 @@ STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
/// \method binVal()
|
||||
/// Get binary value of the 16 or 128 bit UUID. Returned as bytearray type.
|
||||
///
|
||||
STATIC mp_obj_t uuid_bin_val(mp_obj_t self_in) {
|
||||
static mp_obj_t uuid_bin_val(mp_obj_t self_in) {
|
||||
ubluepy_uuid_obj_t * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// TODO: Extend the uint16 byte value to 16 byte if 128-bit,
|
||||
@@ -148,9 +148,9 @@ STATIC mp_obj_t uuid_bin_val(mp_obj_t self_in) {
|
||||
// the uint16_t field of the UUID.
|
||||
return MP_OBJ_NEW_SMALL_INT(self->value[0] | self->value[1] << 8);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_uuid_bin_val_obj, uuid_bin_val);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_uuid_bin_val_obj, uuid_bin_val);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ubluepy_uuid_locals_dict_table[] = {
|
||||
static const mp_rom_map_elem_t ubluepy_uuid_locals_dict_table[] = {
|
||||
#if 0
|
||||
{ MP_ROM_QSTR(MP_QSTR_getCommonName), MP_ROM_PTR(&ubluepy_uuid_get_common_name_obj) },
|
||||
#endif
|
||||
@@ -158,7 +158,7 @@ STATIC const mp_rom_map_elem_t ubluepy_uuid_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_binVal), MP_ROM_PTR(&ubluepy_uuid_bin_val_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ubluepy_uuid_locals_dict, ubluepy_uuid_locals_dict_table);
|
||||
static MP_DEFINE_CONST_DICT(ubluepy_uuid_locals_dict, ubluepy_uuid_locals_dict_table);
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ubluepy_uuid_type,
|
||||
|
||||
@@ -86,7 +86,7 @@ const nrfx_rtc_config_t rtc_config_time_ticks = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC void rtc_irq_time(nrfx_rtc_int_type_t event) {
|
||||
static void rtc_irq_time(nrfx_rtc_int_type_t event) {
|
||||
// irq handler for overflow
|
||||
if (event == NRFX_RTC_INT_OVERFLOW) {
|
||||
rtc_overflows += 1;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "py/mphal.h"
|
||||
#include "pin.h"
|
||||
|
||||
STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pin_named_pins_obj_t *self = self_in;
|
||||
mp_printf(print, "<Pin.%q>", self->name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user