From ea45877ca52c1f3d8e5f0e8547ffdcb982090ff9 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 12 Mar 2019 14:39:46 -0700 Subject: Accept x and y kwargs into Group for initial position. --- shared-bindings/displayio/Group.c | 10 +++++++--- shared-bindings/displayio/Group.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 7b79f3229..3365d5d36 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -41,19 +41,23 @@ //| //| Manage a group of sprites and groups and how they are inter-related. //| -//| .. class:: Group(*, max_size=4, scale=1) +//| .. class:: Group(*, max_size=4, scale=1, x=0, y=0) //| //| Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2 //| leads to a layer's pixel being 2x2 pixels when in the group. //| //| :param int max_size: The maximum group size. //| :param int scale: Scale of layer pixels in one dimension. +//| :param int x: Initial x position within the parent. +//| :param int y: Initial y position within the parent. //| STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_max_size, ARG_scale }; + enum { ARG_max_size, ARG_scale, ARG_x, ARG_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_max_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 4} }, { MP_QSTR_scale, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} }, + { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, + { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -70,7 +74,7 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg displayio_group_t *self = m_new_obj(displayio_group_t); self->base.type = &displayio_group_type; - common_hal_displayio_group_construct(self, max_size, scale); + common_hal_displayio_group_construct(self, max_size, scale, args[ARG_x].u_int, args[ARG_y].u_int); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/displayio/Group.h b/shared-bindings/displayio/Group.h index d326dbf4d..fa3c32964 100644 --- a/shared-bindings/displayio/Group.h +++ b/shared-bindings/displayio/Group.h @@ -32,7 +32,7 @@ extern const mp_obj_type_t displayio_group_type; -void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale); +void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self); void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scale); mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self); -- cgit v1.2.3 From 224e9b10092c7142857cafb7df712843906401fd Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 12 Mar 2019 15:56:03 -0700 Subject: Standardize TileGrid to x and y properties over position This brings it inline with Group. Also fixes #1613 This also includes a number of fixes for where a method is called through a subclass. We now correctly get the native object. Fixes #1567 Lastly, this adds subscript support to TileGrid for changing tile indices. Similar to Bitmap, it accepts ints or 2-tuples. --- shared-bindings/displayio/Group.c | 10 +-- shared-bindings/displayio/TileGrid.c | 161 +++++++++++++++++++++++++---------- shared-bindings/displayio/TileGrid.h | 17 ++-- shared-module/displayio/TileGrid.c | 73 ++++++++++------ shared-module/terminalio/Terminal.c | 10 +-- 5 files changed, 188 insertions(+), 83 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 3365d5d36..c7a72891a 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -172,7 +172,7 @@ const mp_obj_property_t displayio_group_y_obj = { //| Append a layer to the group. It will be drawn above other layers. //| STATIC mp_obj_t displayio_group_obj_append(mp_obj_t self_in, mp_obj_t layer) { - displayio_group_t *self = MP_OBJ_TO_PTR(self_in); + displayio_group_t *self = native_group(self_in); common_hal_displayio_group_insert(self, common_hal_displayio_group_get_len(self), layer); return mp_const_none; } @@ -183,7 +183,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_append_obj, displayio_group_obj_append //| Insert a layer into the group. //| STATIC mp_obj_t displayio_group_obj_insert(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t layer) { - displayio_group_t *self = MP_OBJ_TO_PTR(self_in); + displayio_group_t *self = native_group(self_in); size_t index = mp_get_index(&displayio_group_type, common_hal_displayio_group_get_len(self), index_obj, false); common_hal_displayio_group_insert(self, index, layer); return mp_const_none; @@ -202,7 +202,7 @@ STATIC mp_obj_t displayio_group_obj_pop(size_t n_args, const mp_obj_t *pos_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - displayio_group_t *self = MP_OBJ_TO_PTR(pos_args[0]); + displayio_group_t *self = native_group(pos_args[0]); size_t index = mp_get_index(&displayio_group_type, common_hal_displayio_group_get_len(self), @@ -217,7 +217,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(displayio_group_pop_obj, 1, displayio_group_obj_pop); //| Returns the number of layers in a Group //| STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { - displayio_group_t *self = MP_OBJ_TO_PTR(self_in); + displayio_group_t *self = native_group(self_in); uint16_t len = common_hal_displayio_group_get_len(self); switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len != 0); @@ -251,7 +251,7 @@ STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { //| del group[0] //| STATIC mp_obj_t group_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value) { - displayio_group_t *self = MP_OBJ_TO_PTR(self_in); + displayio_group_t *self = native_group(self_in); if (MP_OBJ_IS_TYPE(index_obj, &mp_type_slice)) { mp_raise_NotImplementedError(translate("Slices not supported")); diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index eeacd1918..a45feaec4 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -39,17 +39,6 @@ #include "shared-bindings/displayio/Shape.h" #include "supervisor/shared/translate.h" -static void unpack_position(mp_obj_t position_obj, int16_t* x, int16_t* y) { - // TODO(tannewt): Support any value sequence such as bytearray or bytes. - mp_obj_tuple_t *position = MP_OBJ_TO_PTR(position_obj); - if (MP_OBJ_IS_TYPE(position_obj, &mp_type_tuple) && position->len == 2) { - *x = mp_obj_get_int(position->items[0]); - *y = mp_obj_get_int(position->items[1]); - } else if (position != mp_const_none) { - mp_raise_TypeError(translate("position must be 2-tuple")); - } -} - //| .. currentmodule:: displayio //| //| :class:`TileGrid` -- A grid of tiles sourced out of one bitmap @@ -60,7 +49,7 @@ static void unpack_position(mp_obj_t position_obj, int16_t* x, int16_t* y) { //| //| A single tile grid is also known as a Sprite. //| -//| .. class:: TileGrid(bitmap, *, pixel_shader, position, width=1, height=1, tile_width=None, tile_height=None, default_tile=0) +//| .. class:: TileGrid(bitmap, *, pixel_shader, width=1, height=1, tile_width=None, tile_height=None, default_tile=0, x=0, y=0) //| //| Create a TileGrid object. The bitmap is source for 2d pixels. The pixel_shader is used to //| convert the value and its location to a display native pixel color. This may be a simple color @@ -70,24 +59,26 @@ static void unpack_position(mp_obj_t position_obj, int16_t* x, int16_t* y) { //| //| :param displayio.Bitmap bitmap: The bitmap storing one or more tiles. //| :param displayio.Palette pixel_shader: The pixel shader that produces colors from values -//| :param tuple position: Upper left corner of the grid //| :param int width: Width of the grid in tiles. //| :param int height: Height of the grid in tiles. //| :param int tile_width: Width of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap's dimensions. //| :param int tile_height: Height of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap's dimensions. //| :param in default_tile: Default tile index to show. +//| :param int x: Initial x position of the left edge within the parent. +//| :param int y: Initial y position of the top edge within the parent. //| STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_bitmap, ARG_pixel_shader, ARG_position, ARG_width, ARG_height, ARG_tile_width, ARG_tile_height, ARG_default_tile }; + enum { ARG_bitmap, ARG_pixel_shader, ARG_width, ARG_height, ARG_tile_width, ARG_tile_height, ARG_default_tile, ARG_x, ARG_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, - { MP_QSTR_position, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, { MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} }, { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} }, { MP_QSTR_tile_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_tile_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_default_tile, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, + { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, + { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -129,10 +120,8 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_ mp_raise_ValueError(translate("Tile height must exactly divide bitmap height")); } - int16_t x = 0; - int16_t y = 0; - mp_obj_t position_obj = args[ARG_position].u_obj; - unpack_position(position_obj, &x, &y); + int16_t x = args[ARG_x].u_int; + int16_t y = args[ARG_y].u_int; displayio_tilegrid_t *self = m_new_obj(displayio_tilegrid_t); self->base.type = &displayio_tilegrid_type; @@ -142,41 +131,61 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_ return MP_OBJ_FROM_PTR(self); } -//| .. attribute:: position +// Helper to ensure we have the native super class instead of a subclass. +static displayio_tilegrid_t* native_tilegrid(mp_obj_t tilegrid_obj) { + mp_obj_t native_tilegrid = mp_instance_cast_to_native_base(tilegrid_obj, &displayio_tilegrid_type); + return MP_OBJ_TO_PTR(native_tilegrid); +} + +//| .. attribute:: x //| -//| The position of the top-left corner of the tilegrid. +//| X position of the left edge in the parent. //| -STATIC mp_obj_t displayio_tilegrid_obj_get_position(mp_obj_t self_in) { - displayio_tilegrid_t *self = MP_OBJ_TO_PTR(self_in); - int16_t x; - int16_t y; - common_hal_displayio_tilegrid_get_position(self, &x, &y); +STATIC mp_obj_t displayio_tilegrid_obj_get_x(mp_obj_t self_in) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_tilegrid_get_x(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_x_obj, displayio_tilegrid_obj_get_x); - mp_obj_t coords[2]; - coords[0] = mp_obj_new_int(x); - coords[1] = mp_obj_new_int(y); +STATIC mp_obj_t displayio_tilegrid_obj_set_x(mp_obj_t self_in, mp_obj_t x_obj) { + displayio_tilegrid_t *self = native_tilegrid(self_in); - return mp_obj_new_tuple(2, coords); + mp_int_t x = mp_obj_get_int(x_obj); + common_hal_displayio_tilegrid_set_x(self, x); + return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_position_obj, displayio_tilegrid_obj_get_position); +MP_DEFINE_CONST_FUN_OBJ_2(displayio_tilegrid_set_x_obj, displayio_tilegrid_obj_set_x); -STATIC mp_obj_t displayio_tilegrid_obj_set_position(mp_obj_t self_in, mp_obj_t value) { - displayio_tilegrid_t *self = MP_OBJ_TO_PTR(self_in); +const mp_obj_property_t displayio_tilegrid_x_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_tilegrid_get_x_obj, + (mp_obj_t)&displayio_tilegrid_set_x_obj, + (mp_obj_t)&mp_const_none_obj}, +}; - int16_t x = 0; - int16_t y = 0; - unpack_position(value, &x, &y); +//| .. attribute:: y +//| +//| Y position of the top edge in the parent. +//| +STATIC mp_obj_t displayio_tilegrid_obj_get_y(mp_obj_t self_in) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_tilegrid_get_y(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_y_obj, displayio_tilegrid_obj_get_y); - common_hal_displayio_tilegrid_set_position(self, x, y); +STATIC mp_obj_t displayio_tilegrid_obj_set_y(mp_obj_t self_in, mp_obj_t y_obj) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + mp_int_t y = mp_obj_get_int(y_obj); + common_hal_displayio_tilegrid_set_y(self, y); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(displayio_tilegrid_set_position_obj, displayio_tilegrid_obj_set_position); +MP_DEFINE_CONST_FUN_OBJ_2(displayio_tilegrid_set_y_obj, displayio_tilegrid_obj_set_y); -const mp_obj_property_t displayio_tilegrid_position_obj = { +const mp_obj_property_t displayio_tilegrid_y_obj = { .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&displayio_tilegrid_get_position_obj, - (mp_obj_t)&displayio_tilegrid_set_position_obj, + .proxy = {(mp_obj_t)&displayio_tilegrid_get_y_obj, + (mp_obj_t)&displayio_tilegrid_set_y_obj, (mp_obj_t)&mp_const_none_obj}, }; @@ -185,13 +194,13 @@ const mp_obj_property_t displayio_tilegrid_position_obj = { //| The pixel shader of the tilegrid. //| STATIC mp_obj_t displayio_tilegrid_obj_get_pixel_shader(mp_obj_t self_in) { - displayio_tilegrid_t *self = MP_OBJ_TO_PTR(self_in); + displayio_tilegrid_t *self = native_tilegrid(self_in); return common_hal_displayio_tilegrid_get_pixel_shader(self); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_pixel_shader_obj, displayio_tilegrid_obj_get_pixel_shader); STATIC mp_obj_t displayio_tilegrid_obj_set_pixel_shader(mp_obj_t self_in, mp_obj_t pixel_shader) { - displayio_tilegrid_t *self = MP_OBJ_TO_PTR(self_in); + displayio_tilegrid_t *self = native_tilegrid(self_in); if (!MP_OBJ_IS_TYPE(pixel_shader, &displayio_palette_type) && !MP_OBJ_IS_TYPE(pixel_shader, &displayio_colorconverter_type)) { mp_raise_TypeError(translate("pixel_shader must be displayio.Palette or displayio.ColorConverter")); } @@ -209,9 +218,72 @@ const mp_obj_property_t displayio_tilegrid_pixel_shader_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| .. method:: __getitem__(index) +//| +//| Returns the tile index at the given index. The index can either be an x,y tuple or an int equal +//| to ``y * width + x``. +//| +//| This allows you to:: +//| +//| print(grid[0]) +//| +//| .. method:: __setitem__(index, tile_index) +//| +//| Sets the tile index at the given index. The index can either be an x,y tuple or an int equal +//| to ``y * width + x``. +//| +//| This allows you to:: +//| +//| grid[0] = 10 +//| +//| or:: +//| +//| grid[0,0] = 10 +//| +STATIC mp_obj_t tilegrid_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value_obj) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + + + if (MP_OBJ_IS_TYPE(index_obj, &mp_type_slice)) { + mp_raise_NotImplementedError(translate("Slices not supported")); + } else { + uint16_t x = 0; + uint16_t y = 0; + if (MP_OBJ_IS_SMALL_INT(index_obj)) { + mp_int_t i = MP_OBJ_SMALL_INT_VALUE(index_obj); + uint16_t width = common_hal_displayio_tilegrid_get_width(self); + x = i % width; + y = i / width; + } else { + mp_obj_t* items; + mp_obj_get_array_fixed_n(index_obj, 2, &items); + x = mp_obj_get_int(items[0]); + y = mp_obj_get_int(items[1]); + if (x >= common_hal_displayio_tilegrid_get_width(self) || y >= common_hal_displayio_tilegrid_get_height(self)) { + mp_raise_IndexError(translate("tile index out of bounds")); + } + } + + if (value_obj == MP_OBJ_SENTINEL) { + // load + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_tilegrid_get_tile(self, x, y)); + } else if (value_obj == mp_const_none) { + return MP_OBJ_NULL; // op not supported + } else { + mp_int_t value = mp_obj_get_int(value_obj); + if (value < 0 || value > 255) { + mp_raise_ValueError(translate("Tile indices must be 0 - 255")); + } + common_hal_displayio_tilegrid_set_tile(self, x, y, value); + } + } + return mp_const_none; +} + STATIC const mp_rom_map_elem_t displayio_tilegrid_locals_dict_table[] = { // Properties - { MP_ROM_QSTR(MP_QSTR_position), MP_ROM_PTR(&displayio_tilegrid_position_obj) }, + { MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&displayio_tilegrid_x_obj) }, + { MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&displayio_tilegrid_y_obj) }, { MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&displayio_tilegrid_pixel_shader_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_tilegrid_locals_dict, displayio_tilegrid_locals_dict_table); @@ -220,5 +292,6 @@ const mp_obj_type_t displayio_tilegrid_type = { { &mp_type_type }, .name = MP_QSTR_TileGrid, .make_new = displayio_tilegrid_make_new, + .subscr = tilegrid_subscr, .locals_dict = (mp_obj_dict_t*)&displayio_tilegrid_locals_dict, }; diff --git a/shared-bindings/displayio/TileGrid.h b/shared-bindings/displayio/TileGrid.h index 2260db413..15a71b53b 100644 --- a/shared-bindings/displayio/TileGrid.h +++ b/shared-bindings/displayio/TileGrid.h @@ -35,13 +35,20 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_ uint16_t bitmap_width_in_tiles, mp_obj_t pixel_shader, uint16_t width, uint16_t height, uint16_t tile_width, uint16_t tile_height, uint16_t x, uint16_t y, uint8_t default_tile); -void common_hal_displayio_tilegrid_get_position(displayio_tilegrid_t *self, int16_t* x, int16_t* y); -void common_hal_displayio_tilegrid_set_position(displayio_tilegrid_t *self, int16_t x, int16_t y); - +mp_int_t common_hal_displayio_tilegrid_get_x(displayio_tilegrid_t *self); +void common_hal_displayio_tilegrid_set_x(displayio_tilegrid_t *self, mp_int_t x); +mp_int_t common_hal_displayio_tilegrid_get_y(displayio_tilegrid_t *self); +void common_hal_displayio_tilegrid_set_y(displayio_tilegrid_t *self, mp_int_t y); mp_obj_t common_hal_displayio_tilegrid_get_pixel_shader(displayio_tilegrid_t *self); void common_hal_displayio_tilegrid_set_pixel_shader(displayio_tilegrid_t *self, mp_obj_t pixel_shader); -void common_hal_displayio_textgrid_set_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y, uint8_t tile_index); -void common_hal_displayio_textgrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y); +uint16_t common_hal_displayio_tilegrid_get_width(displayio_tilegrid_t *self); +uint16_t common_hal_displayio_tilegrid_get_height(displayio_tilegrid_t *self); + +uint8_t common_hal_displayio_tilegrid_get_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y); +void common_hal_displayio_tilegrid_set_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y, uint8_t tile_index); + +// Private API for scrolling the TileGrid. +void common_hal_displayio_tilegrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_TILEGRID_H diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index c2aa9b144..bbbb11924 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -66,14 +66,20 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_ self->y = y; } -void common_hal_displayio_tilegrid_get_position(displayio_tilegrid_t *self, int16_t* x, int16_t* y) { - *x = self->x; - *y = self->y; -} -void common_hal_displayio_tilegrid_set_position(displayio_tilegrid_t *self, int16_t x, int16_t y) { - self->needs_refresh = self->x != x || self->y != y; +mp_int_t common_hal_displayio_tilegrid_get_x(displayio_tilegrid_t *self) { + return self->x; +} +void common_hal_displayio_tilegrid_set_x(displayio_tilegrid_t *self, mp_int_t x) { + self->needs_refresh = self->x != x; self->x = x; +} +mp_int_t common_hal_displayio_tilegrid_get_y(displayio_tilegrid_t *self) { + return self->y; +} + +void common_hal_displayio_tilegrid_set_y(displayio_tilegrid_t *self, mp_int_t y) { + self->needs_refresh = self->y != y; self->y = y; } @@ -86,6 +92,43 @@ void common_hal_displayio_tilegrid_set_pixel_shader(displayio_tilegrid_t *self, self->needs_refresh = true; } + +uint16_t common_hal_displayio_tilegrid_get_width(displayio_tilegrid_t *self) { + return self->width_in_tiles; +} + +uint16_t common_hal_displayio_tilegrid_get_height(displayio_tilegrid_t *self) { + return self->height_in_tiles; +} + +uint8_t common_hal_displayio_tilegrid_get_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y) { + uint8_t* tiles = self->tiles; + if (self->inline_tiles) { + tiles = (uint8_t*) &self->tiles; + } + if (tiles == NULL) { + return 0; + } + return tiles[y * self->width_in_tiles + x]; +} + +void common_hal_displayio_tilegrid_set_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y, uint8_t tile_index) { + uint8_t* tiles = self->tiles; + if (self->inline_tiles) { + tiles = (uint8_t*) &self->tiles; + } + if (tiles == NULL) { + return; + } + tiles[y * self->width_in_tiles + x] = tile_index; + self->needs_refresh = true; +} + + +void common_hal_displayio_tilegrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y) { + self->top_left_x = x; + self->top_left_y = y; +} bool displayio_tilegrid_get_pixel(displayio_tilegrid_t *self, int16_t x, int16_t y, uint16_t* pixel) { x -= self->x; y -= self->y; @@ -126,24 +169,6 @@ bool displayio_tilegrid_get_pixel(displayio_tilegrid_t *self, int16_t x, int16_t return false; } -void common_hal_displayio_textgrid_set_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y, uint8_t tile_index) { - uint8_t* tiles = self->tiles; - if (self->inline_tiles) { - tiles = (uint8_t*) &self->tiles; - } - if (tiles == NULL) { - return; - } - tiles[y * self->width_in_tiles + x] = tile_index; - self->needs_refresh = true; -} - - -void common_hal_displayio_textgrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y) { - self->top_left_x = x; - self->top_left_y = y; -} - bool displayio_tilegrid_needs_refresh(displayio_tilegrid_t *self) { return self->needs_refresh || displayio_palette_needs_refresh(self->pixel_shader); } diff --git a/shared-module/terminalio/Terminal.c b/shared-module/terminalio/Terminal.c index 85bbee293..07c13d639 100644 --- a/shared-module/terminalio/Terminal.c +++ b/shared-module/terminalio/Terminal.c @@ -48,7 +48,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con if (c < 128) { if (c >= 0x20 && c <= 0x7e) { uint8_t tile_index = displayio_builtinfont_get_glyph_index(self->font, c); - common_hal_displayio_textgrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, tile_index); + common_hal_displayio_tilegrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, tile_index); self->cursor_x++; } else if (c == '\r') { self->cursor_x = 0; @@ -64,7 +64,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con if (i[1] == 'K') { // Clear the rest of the line. for (uint16_t j = self->cursor_x; j < self->tilegrid->width_in_tiles; j++) { - common_hal_displayio_textgrid_set_tile(self->tilegrid, j, self->cursor_y, 0); + common_hal_displayio_tilegrid_set_tile(self->tilegrid, j, self->cursor_y, 0); } i += 2; } else { @@ -94,7 +94,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con } else { uint8_t tile_index = displayio_builtinfont_get_glyph_index(self->font, c); if (tile_index != 0xff) { - common_hal_displayio_textgrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, tile_index); + common_hal_displayio_tilegrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, tile_index); self->cursor_x++; } @@ -109,10 +109,10 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con if (self->cursor_y != start_y) { // clear the new row for (uint16_t j = 0; j < self->tilegrid->width_in_tiles; j++) { - common_hal_displayio_textgrid_set_tile(self->tilegrid, j, self->cursor_y, 0); + common_hal_displayio_tilegrid_set_tile(self->tilegrid, j, self->cursor_y, 0); start_y = self->cursor_y; } - common_hal_displayio_textgrid_set_top_left(self->tilegrid, 0, (start_y + self->tilegrid->height_in_tiles + 1) % self->tilegrid->height_in_tiles); + common_hal_displayio_tilegrid_set_top_left(self->tilegrid, 0, (start_y + self->tilegrid->height_in_tiles + 1) % self->tilegrid->height_in_tiles); } } return i - data; -- cgit v1.2.3 From afbf59019eec003ed79ee4467d0f3f76c00c68d2 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 12 Mar 2019 16:20:12 -0700 Subject: Update displayio docs to add detail to display bus comments Fixes #1599 --- shared-bindings/displayio/FourWire.c | 9 +++++++-- shared-bindings/displayio/ParallelBus.c | 14 ++++++++++---- shared-bindings/displayio/__init__.c | 5 +++-- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c index 70cd42747..8ffe54be0 100644 --- a/shared-bindings/displayio/FourWire.c +++ b/shared-bindings/displayio/FourWire.c @@ -46,14 +46,19 @@ //| Manage updating a display over SPI four wire protocol in the background while Python code runs. //| It doesn't handle display initialization. //| -//| .. class:: FourWire(spi_bus, *, command, chip_select, reset) +//| .. class:: FourWire(spi_bus, *, command, chip_select, reset=None) //| //| Create a FourWire object associated with the given pins. //| +//| The SPI bus and pins are then in use by the display until `displayio.release_displays()` is +//| called even after a reload. (It does this so CircuitPython can use the display after your code +//| is done.) So, the first time you initialize a display bus in code.py you should call +//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run. +//| //| :param busio.SPI spi_bus: The SPI bus that make up the clock and data lines //| :param microcontroller.Pin command: Data or command pin //| :param microcontroller.Pin chip_select: Chip select pin -//| :param microcontroller.Pin reset: Reset pin +//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used //| STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset }; diff --git a/shared-bindings/displayio/ParallelBus.c b/shared-bindings/displayio/ParallelBus.c index 6a499ed06..00a96d230 100644 --- a/shared-bindings/displayio/ParallelBus.c +++ b/shared-bindings/displayio/ParallelBus.c @@ -39,18 +39,24 @@ //| .. currentmodule:: displayio //| -//| :class:`ParallelBus` -- Manage updating a display over SPI four wire protocol +//| :class:`ParallelBus` -- Manage updating a display over 8-bit parallel bus //| ============================================================================== //| -//| Manage updating a display over SPI four wire protocol in the background while Python code runs. -//| It doesn't handle display initialization. +//| Manage updating a display over 8-bit parallel bus in the background while Python code runs. This +//| protocol may be refered to as 8080-I Series Parallel Interface in datasheets. It doesn't handle +//| display initialization. //| //| .. class:: ParallelBus(*, data0, command, chip_select, write, read, reset) //| //| Create a ParallelBus object associated with the given pins. The bus is inferred from data0 //| by implying the next 7 additional pins on a given GPIO port. //| -//| :param microcontroller.Pin: The first data pin. The rest are implied +//| The parallel bus and pins are then in use by the display until `displayio.release_displays()` +//| is called even after a reload. (It does this so CircuitPython can use the display after your +//| code is done.) So, the first time you initialize a display bus in code.py you should call +//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run. +//| +//| :param microcontroller.Pin data0: The first data pin. The rest are implied //| :param microcontroller.Pin command: Data or command pin //| :param microcontroller.Pin chip_select: Chip select pin //| :param microcontroller.Pin write: Write pin diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 1ee755014..177bd5fff 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -71,8 +71,6 @@ //| Shape //| TileGrid //| -//| All libraries change hardware state but are never deinit -//| //| .. method:: release_displays() @@ -81,6 +79,9 @@ //| release the builtin display on boards that have one. You will need to reinitialize it yourself //| afterwards. //| +//| Use this once in your code.py if you initialize a display. Place it right before the +//| initialization so the display is active as long as possible. +//| STATIC mp_obj_t displayio_release_displays(void) { common_hal_displayio_release_displays(); return mp_const_none; -- cgit v1.2.3 From 946790bfb53d69492f76b097aa07b1b45287631c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 12 Mar 2019 17:06:21 -0700 Subject: Add better PewPew error messages and update translations --- locale/ID.po | 32 ++++++++++++++++++++++++++------ locale/circuitpython.pot | 34 +++++++++++++++++++++++++++------- locale/de_DE.po | 32 ++++++++++++++++++++++++++------ locale/en_US.po | 32 ++++++++++++++++++++++++++------ locale/en_x_pirate.po | 32 ++++++++++++++++++++++++++------ locale/es.po | 35 +++++++++++++++++++++++++++++------ locale/fil.po | 35 +++++++++++++++++++++++++++++------ locale/fr.po | 37 ++++++++++++++++++++++++++++++------- locale/it_IT.po | 35 +++++++++++++++++++++++++++++------ locale/pt_BR.po | 32 ++++++++++++++++++++++++++------ shared-bindings/_pew/PewPew.c | 9 ++++----- shared-module/_pew/PewPew.c | 2 +- 12 files changed, 279 insertions(+), 68 deletions(-) (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 8961872a0..f975ad08b 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c #, fuzzy msgid "" msgstr "" @@ -262,6 +261,7 @@ msgstr "Semua timer untuk pin ini sedang digunakan" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "Semua timer sedang digunakan" @@ -473,6 +473,10 @@ msgstr "" msgid "Clock unit in use" msgstr "Clock unit sedang digunakan" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -771,6 +775,10 @@ msgid "" "mpy-update for more info." msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "" @@ -1137,6 +1145,10 @@ msgstr "sistem file (filesystem) bersifat Read-only" msgid "Right channel unsupported" msgstr "Channel Kanan tidak didukung" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "Berjalan di mode aman(safe mode)! Auto-reload tidak aktif.\n" @@ -1177,7 +1189,7 @@ msgid "Slice and value different lengths." msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1244,6 +1256,10 @@ msgstr "" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1541,6 +1557,10 @@ msgstr "" msgid "buffers must be the same length" msgstr "buffers harus mempunyai panjang yang sama" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "" @@ -2461,10 +2481,6 @@ msgstr "" msgid "popitem(): dictionary is empty" msgstr "" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "" @@ -2633,6 +2649,10 @@ msgstr "sintaksis error pada pendeskripsi uctypes" msgid "threshold must be in the range 0-65536" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 36975f988..bbdb06287 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -3,13 +3,12 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-12 11:17-0700\n" +"POT-Creation-Date: 2019-03-12 17:20-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -260,6 +259,7 @@ msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "" @@ -463,6 +463,10 @@ msgstr "" msgid "Clock unit in use" msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -746,6 +750,10 @@ msgid "" "mpy-update for more info." msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "" @@ -1108,6 +1116,10 @@ msgstr "" msgid "Right channel unsupported" msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "" @@ -1147,7 +1159,7 @@ msgid "Slice and value different lengths." msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1211,6 +1223,10 @@ msgstr "" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1495,6 +1511,10 @@ msgstr "" msgid "buffers must be the same length" msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "" @@ -2413,10 +2433,6 @@ msgstr "" msgid "popitem(): dictionary is empty" msgstr "" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "" @@ -2585,6 +2601,10 @@ msgstr "" msgid "threshold must be in the range 0-65536" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 1a73ec7a2..add0cc71e 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c msgid "" msgstr "" "Project-Id-Version: \n" @@ -262,6 +261,7 @@ msgstr "Alle timer für diesen Pin werden bereits benutzt" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "Alle timer werden benutzt" @@ -467,6 +467,10 @@ msgstr "Clock stretch zu lang" msgid "Clock unit in use" msgstr "Clock unit wird benutzt" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" @@ -753,6 +757,10 @@ msgstr "" "Inkompatible mpy-Datei. Bitte aktualisieren Sie alle mpy-Dateien. Siehe " "http://adafru.it/mpy-update für weitere Informationen." +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "Eingabe-/Ausgabefehler" @@ -1129,6 +1137,10 @@ msgstr "Schreibgeschützte Objekt" msgid "Right channel unsupported" msgstr "Rechter Kanal wird nicht unterstützt" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "Sicherheitsmodus aktiv! Automatisches Neuladen ist deaktiviert.\n" @@ -1168,7 +1180,7 @@ msgid "Slice and value different lengths." msgstr "Slice und Wert (value) haben unterschiedliche Längen." #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Slices werden nicht unterstützt" @@ -1244,6 +1256,10 @@ msgstr "" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1540,6 +1556,10 @@ msgstr "Der Puffer ist zu klein" msgid "buffers must be the same length" msgstr "Buffer müssen gleich lang sein" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "" @@ -2468,10 +2488,6 @@ msgstr "pop von einer leeren Liste" msgid "popitem(): dictionary is empty" msgstr "popitem(): dictionary ist leer" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "pow() drittes Argument darf nicht 0 sein" @@ -2643,6 +2659,10 @@ msgstr "Syntaxfehler in uctypes Deskriptor" msgid "threshold must be in the range 0-65536" msgstr "threshold muss im Intervall 0-65536 liegen" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "" diff --git a/locale/en_US.po b/locale/en_US.po index 52d4b73e8..2e1dbd0f0 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c msgid "" msgstr "" "Project-Id-Version: \n" @@ -260,6 +259,7 @@ msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "" @@ -463,6 +463,10 @@ msgstr "" msgid "Clock unit in use" msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -746,6 +750,10 @@ msgid "" "mpy-update for more info." msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "" @@ -1108,6 +1116,10 @@ msgstr "" msgid "Right channel unsupported" msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "" @@ -1147,7 +1159,7 @@ msgid "Slice and value different lengths." msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1211,6 +1223,10 @@ msgstr "" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1495,6 +1511,10 @@ msgstr "" msgid "buffers must be the same length" msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "" @@ -2413,10 +2433,6 @@ msgstr "" msgid "popitem(): dictionary is empty" msgstr "" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "" @@ -2585,6 +2601,10 @@ msgstr "" msgid "threshold must be in the range 0-65536" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 6597d98bd..97d819bcd 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c msgid "" msgstr "" "Project-Id-Version: \n" @@ -262,6 +261,7 @@ msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "" @@ -467,6 +467,10 @@ msgstr "" msgid "Clock unit in use" msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -750,6 +754,10 @@ msgid "" "mpy-update for more info." msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "" @@ -1112,6 +1120,10 @@ msgstr "" msgid "Right channel unsupported" msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "Runnin' in safe mode! Auto-reload be off.\n" @@ -1151,7 +1163,7 @@ msgid "Slice and value different lengths." msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1215,6 +1227,10 @@ msgstr "" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1499,6 +1515,10 @@ msgstr "" msgid "buffers must be the same length" msgstr "yer buffers must be of the same length" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "" @@ -2417,10 +2437,6 @@ msgstr "" msgid "popitem(): dictionary is empty" msgstr "" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "" @@ -2589,6 +2605,10 @@ msgstr "" msgid "threshold must be in the range 0-65536" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "" diff --git a/locale/es.po b/locale/es.po index a6749413d..adf786085 100644 --- a/locale/es.po +++ b/locale/es.po @@ -4,7 +4,6 @@ # Carlos Diaz , 2018. # Juan Biondi , 2018. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c msgid "" msgstr "" "Project-Id-Version: \n" @@ -267,6 +266,7 @@ msgstr "Todos los timers para este pin están siendo utilizados" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "Todos los timers en uso" @@ -474,6 +474,10 @@ msgstr "" msgid "Clock unit in use" msgstr "Clock unit está siendo utilizado" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" @@ -778,6 +782,10 @@ msgstr "" "Archivo .mpy incompatible. Actualice todos los archivos .mpy. Consulte " "http://adafru.it/mpy-update para más información" +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "error Input/output" @@ -1153,6 +1161,10 @@ msgstr "Solo-lectura" msgid "Right channel unsupported" msgstr "Canal derecho no soportado" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "Ejecutando en modo seguro! La auto-recarga esta deshabilitada.\n" @@ -1192,7 +1204,7 @@ msgid "Slice and value different lengths." msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1263,6 +1275,10 @@ msgstr "El signo del sample no iguala al del mixer" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1558,6 +1574,10 @@ msgstr "buffer demasiado pequeño" msgid "buffers must be the same length" msgstr "los buffers deben de tener la misma longitud" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "codigo byte no implementado" @@ -2493,10 +2513,6 @@ msgstr "pop desde una lista vacía" msgid "popitem(): dictionary is empty" msgstr "popitem(): diccionario vacío" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "posición debe ser 2-tuple" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "el 3er argumento de pow() no puede ser 0" @@ -2669,6 +2685,10 @@ msgstr "error de sintaxis en el descriptor uctypes" msgid "threshold must be in the range 0-65536" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "" @@ -2877,3 +2897,6 @@ msgstr "paso cero" #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Solo color verdadero (24 bpp o superior) BMP admitido %x" + +#~ msgid "position must be 2-tuple" +#~ msgstr "posición debe ser 2-tuple" diff --git a/locale/fil.po b/locale/fil.po index 2d9ce796b..c45f62b75 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c msgid "" msgstr "" "Project-Id-Version: \n" @@ -264,6 +263,7 @@ msgstr "Lahat ng timers para sa pin na ito ay ginagamit" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "Lahat ng timer ginagamit" @@ -471,6 +471,10 @@ msgstr "Masyadong mahaba ang Clock stretch" msgid "Clock unit in use" msgstr "Clock unit ginagamit" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" @@ -776,6 +780,10 @@ msgstr "" ".mpy file hindi compatible. Maaring i-update lahat ng .mpy files. See http://" "adafru.it/mpy-update for more info." +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "May mali sa Input/Output" @@ -1152,6 +1160,10 @@ msgstr "Basahin-lamang" msgid "Right channel unsupported" msgstr "Hindi supportado ang kanang channel" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "Tumatakbo sa safe mode! Awtomatikong pag re-reload ay OFF.\n" @@ -1191,7 +1203,7 @@ msgid "Slice and value different lengths." msgstr "Slice at value iba't ibang haba." #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Hindi suportado ang Slices" @@ -1265,6 +1277,10 @@ msgstr "Ang signedness ng sample hindi tugma sa mixer" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1561,6 +1577,10 @@ msgstr "masyadong maliit ang buffer" msgid "buffers must be the same length" msgstr "ang buffers ay dapat parehas sa haba" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "byte code hindi pa implemented" @@ -2499,10 +2519,6 @@ msgstr "pop galing sa walang laman na list" msgid "popitem(): dictionary is empty" msgstr "popitem(): dictionary ay walang laman" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "position ay dapat 2-tuple" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "pow() 3rd argument ay hindi maaring 0" @@ -2675,6 +2691,10 @@ msgstr "may pagkakamali sa sintaks sa uctypes descriptor" msgid "threshold must be in the range 0-65536" msgstr "ang threshold ay dapat sa range 0-65536" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "time.struct_time() kumukuha ng 9-sequence" @@ -2883,3 +2903,6 @@ msgstr "zero step" #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Dapat true color (24 bpp o mas mataas) BMP lamang ang supportado %x" + +#~ msgid "position must be 2-tuple" +#~ msgstr "position ay dapat 2-tuple" diff --git a/locale/fr.po b/locale/fr.po index eeab87b65..7f8acb4cd 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # Pierrick Couturier , 2018. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c msgid "" msgstr "" "Project-Id-Version: 0.1\n" @@ -264,6 +263,7 @@ msgstr "Tous les timers pour cette broche sont utilisés" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "Tous les timers sont utilisés" @@ -473,6 +473,10 @@ msgstr "Période de l'horloge trop longue" msgid "Clock unit in use" msgstr "Horloge en cours d'utilisation" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" @@ -775,6 +779,10 @@ msgstr "" "Fichier .mpy incompatible. Merci de mettre à jour tous les .mpy. Voirhttp://" "adafru.it/mpy-update pour plus d'informations." +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "Erreur d'entrée/sortie" @@ -1159,6 +1167,10 @@ msgstr "Lecture seule" msgid "Right channel unsupported" msgstr "Canal droit non supporté" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "Mode sans-échec. Auto-rechargement désactivé.\n" @@ -1199,7 +1211,7 @@ msgid "Slice and value different lengths." msgstr "Slice et valeur de tailles différentes" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Slices non supportées" @@ -1276,6 +1288,10 @@ msgstr "Le signe de l'échantillon ne correspond pas au mixer" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1573,6 +1589,10 @@ msgstr "tampon trop petit" msgid "buffers must be the same length" msgstr "les tampons doivent être de la même longueur" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "bytecode non implémenté" @@ -2519,11 +2539,6 @@ msgstr "pop d'une liste vide" msgid "popitem(): dictionary is empty" msgstr "popitem(): dictionnaire vide" -#: shared-bindings/displayio/TileGrid.c -#, fuzzy -msgid "position must be 2-tuple" -msgstr "position doit être un 2-tuple" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "le 3e argument de pow() ne peut être 0" @@ -2697,6 +2712,10 @@ msgstr "erreur de syntaxe dans le descripteur d'uctypes" msgid "threshold must be in the range 0-65536" msgstr "le seuil doit être dans la gamme 0-65536" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "time.struct_time() prend une séquence de longueur 9" @@ -2907,3 +2926,7 @@ msgstr "'step' nul" #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Seul les BMP 24bits ou plus sont supportés %x" + +#, fuzzy +#~ msgid "position must be 2-tuple" +#~ msgstr "position doit être un 2-tuple" diff --git a/locale/it_IT.po b/locale/it_IT.po index 22bc8ed4b..fd00b9198 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # Enrico Paganin , 2018 # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c #, fuzzy msgid "" msgstr "" @@ -263,6 +262,7 @@ msgstr "Tutti i timer per questo pin sono in uso" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "Tutti i timer utilizzati" @@ -472,6 +472,10 @@ msgstr "" msgid "Clock unit in use" msgstr "Unità di clock in uso" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" @@ -775,6 +779,10 @@ msgstr "" "File .mpy incompatibile. Aggiorna tutti i file .mpy. Vedi http://adafru.it/" "mpy-update per più informazioni." +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "Errore input/output" @@ -1155,6 +1163,10 @@ msgstr "Sola lettura" msgid "Right channel unsupported" msgstr "Canale destro non supportato" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "Modalità sicura in esecuzione! Auto-reload disattivato.\n" @@ -1196,7 +1208,7 @@ msgid "Slice and value different lengths." msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Slice non supportate" @@ -1263,6 +1275,10 @@ msgstr "" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1555,6 +1571,10 @@ msgstr "buffer troppo piccolo" msgid "buffers must be the same length" msgstr "i buffer devono essere della stessa lunghezza" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "byte code non implementato" @@ -2495,10 +2515,6 @@ msgstr "pop da una lista vuota" msgid "popitem(): dictionary is empty" msgstr "popitem(): il dizionario è vuoto" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "position deve essere una 2-tuple" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "il terzo argomento di pow() non può essere 0" @@ -2671,6 +2687,10 @@ msgstr "errore di sintassi nel descrittore uctypes" msgid "threshold must be in the range 0-65536" msgstr "la soglia deve essere nell'intervallo 0-65536" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "" @@ -2879,3 +2899,6 @@ msgstr "zero step" #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Solo BMP true color (24 bpp o superiore) sono supportati %x" + +#~ msgid "position must be 2-tuple" +#~ msgstr "position deve essere una 2-tuple" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 77e1beff6..aaf17f54b 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -3,7 +3,6 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: shared-bindings/_pew/PewPew.c shared-module/_pew/PewPew.c #, fuzzy msgid "" msgstr "" @@ -263,6 +262,7 @@ msgstr "Todos os temporizadores para este pino estão em uso" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c +#: shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "Todos os temporizadores em uso" @@ -468,6 +468,10 @@ msgstr "Clock se estendeu por tempo demais" msgid "Clock unit in use" msgstr "Unidade de Clock em uso" +#: shared-bindings/_pew/PewPew.c +msgid "Column entry must be digitalio.DigitalInOut" +msgstr "" + #: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" @@ -766,6 +770,10 @@ msgid "" "mpy-update for more info." msgstr "" +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" +msgstr "" + #: py/moduerrno.c msgid "Input/output error" msgstr "" @@ -1136,6 +1144,10 @@ msgstr "Somente leitura" msgid "Right channel unsupported" msgstr "Canal direito não suportado" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" +msgstr "" + #: main.c msgid "Running in safe mode! Auto-reload is off.\n" msgstr "Rodando em modo seguro! Atualização automática está desligada.\n" @@ -1175,7 +1187,7 @@ msgid "Slice and value different lengths." msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1239,6 +1251,10 @@ msgstr "" msgid "Tile height must exactly divide bitmap height" msgstr "" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" +msgstr "" + #: shared-bindings/displayio/TileGrid.c msgid "Tile width must exactly divide bitmap width" msgstr "" @@ -1527,6 +1543,10 @@ msgstr "" msgid "buffers must be the same length" msgstr "buffers devem ser o mesmo tamanho" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" +msgstr "" + #: py/vm.c msgid "byte code not implemented" msgstr "" @@ -2447,10 +2467,6 @@ msgstr "" msgid "popitem(): dictionary is empty" msgstr "" -#: shared-bindings/displayio/TileGrid.c -msgid "position must be 2-tuple" -msgstr "" - #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" msgstr "" @@ -2621,6 +2637,10 @@ msgstr "" msgid "threshold must be in the range 0-65536" msgstr "Limite deve estar no alcance de 0-65536" +#: shared-bindings/displayio/TileGrid.c +msgid "tile index out of bounds" +msgstr "" + #: shared-bindings/time/__init__.c msgid "time.struct_time() takes a 9-sequence" msgstr "" diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 50647488c..d7ae0116d 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -88,12 +88,12 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, mp_obj_get_array(args[ARG_cols].u_obj, &cols_size, &cols); if (bufinfo.len != rows_size * cols_size) { - mp_raise_ValueError(translate("")); + mp_raise_ValueError(translate("Incorrect buffer size")); } for (size_t i = 0; i < rows_size; ++i) { if (!MP_OBJ_IS_TYPE(rows[i], &digitalio_digitalinout_type)) { - mp_raise_TypeError(translate("")); + mp_raise_TypeError(translate("Row entry must be digitalio.DigitalInOut")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(rows[i]); raise_error_if_deinited( @@ -102,7 +102,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, for (size_t i = 0; i < cols_size; ++i) { if (!MP_OBJ_IS_TYPE(cols[i], &digitalio_digitalinout_type)) { - mp_raise_TypeError(translate("")); + mp_raise_TypeError(translate("Column entry must be digitalio.DigitalInOut")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(cols[i]); raise_error_if_deinited( @@ -111,7 +111,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, if (!MP_OBJ_IS_TYPE(args[ARG_buttons].u_obj, &digitalio_digitalinout_type)) { - mp_raise_TypeError(translate("")); + mp_raise_TypeError(translate("buttons must be digitalio.DigitalInOut")); } digitalio_digitalinout_obj_t *buttons = MP_OBJ_TO_PTR( args[ARG_buttons].u_obj); @@ -148,4 +148,3 @@ const mp_obj_type_t pewpew_type = { .make_new = pewpew_make_new, .locals_dict = (mp_obj_dict_t*)&pewpew_locals_dict, }; - diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index 7ff4e8c7a..568dc6425 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -76,7 +76,7 @@ void pew_init() { // Find a spare timer. uint8_t index = find_free_timer(); if (index == 0xff) { - mp_raise_RuntimeError(translate("")); + mp_raise_RuntimeError(translate("All timers in use")); } Tc *tc = tc_insts[index]; -- cgit v1.2.3 From 97140e6a62770bf60c0cca9967960bbc038e8991 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 12 Mar 2019 21:28:30 -0400 Subject: wrong arg type for PWMOut variable_frequency --- ports/atmel-samd/common-hal/pulseio/PWMOut.c | 2 ++ shared-bindings/pulseio/PWMOut.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pulseio/PWMOut.c index dd85e8c02..6dcace21f 100644 --- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PWMOut.c @@ -102,6 +102,8 @@ void pwmout_reset(void) { } tcc_channels[i] = mask; tccs[i]->CTRLA.bit.SWRST = 1; + while (tccs[i]->CTRLA.bit.SWRST == 1) { + } } Tc *tcs[TC_INST_NUM] = TC_INSTS; for (int i = 0; i < TC_INST_NUM; i++) { diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c index bba5fe883..37939a07a 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pulseio/PWMOut.c @@ -103,7 +103,7 @@ STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args uint16_t duty_cycle = parsed_args[ARG_duty_cycle].u_int; uint32_t frequency = parsed_args[ARG_frequency].u_int; - bool variable_frequency = parsed_args[ARG_variable_frequency].u_int; + bool variable_frequency = parsed_args[ARG_variable_frequency].u_bool; // create PWM object from the given pin pulseio_pwmout_obj_t *self = m_new_obj(pulseio_pwmout_obj_t); -- cgit v1.2.3 From 5e2fec714cfbff8692d8af4ec8f774738b822ce1 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 19 Mar 2019 16:22:09 -0700 Subject: Move Glyph and BuiltinFont into fontio It was confusing in displayio. Fixes #1662 --- py/circuitpy_defns.mk | 7 +- py/circuitpy_mpconfig.h | 6 +- shared-bindings/displayio/BuiltinFont.c | 110 -------------------------------- shared-bindings/displayio/BuiltinFont.h | 38 ----------- shared-bindings/displayio/Glyph.c | 75 ---------------------- shared-bindings/displayio/Glyph.h | 34 ---------- shared-bindings/displayio/__init__.c | 4 -- shared-bindings/fontio/BuiltinFont.c | 110 ++++++++++++++++++++++++++++++++ shared-bindings/fontio/BuiltinFont.h | 38 +++++++++++ shared-bindings/fontio/Glyph.c | 75 ++++++++++++++++++++++ shared-bindings/fontio/Glyph.h | 34 ++++++++++ shared-bindings/fontio/__init__.c | 65 +++++++++++++++++++ shared-bindings/fontio/__init__.h | 31 +++++++++ shared-bindings/terminalio/Terminal.c | 6 +- shared-bindings/terminalio/Terminal.h | 2 +- shared-module/displayio/BuiltinFont.c | 79 ----------------------- shared-module/displayio/BuiltinFont.h | 47 -------------- shared-module/fontio/BuiltinFont.c | 79 +++++++++++++++++++++++ shared-module/fontio/BuiltinFont.h | 47 ++++++++++++++ shared-module/fontio/__init__.c | 27 ++++++++ shared-module/terminalio/Terminal.c | 9 ++- shared-module/terminalio/Terminal.h | 4 +- supervisor/shared/display.h | 4 +- tools/gen_display_resources.py | 4 +- 24 files changed, 529 insertions(+), 406 deletions(-) delete mode 100644 shared-bindings/displayio/BuiltinFont.c delete mode 100644 shared-bindings/displayio/BuiltinFont.h delete mode 100644 shared-bindings/displayio/Glyph.c delete mode 100644 shared-bindings/displayio/Glyph.h create mode 100644 shared-bindings/fontio/BuiltinFont.c create mode 100644 shared-bindings/fontio/BuiltinFont.h create mode 100644 shared-bindings/fontio/Glyph.c create mode 100644 shared-bindings/fontio/Glyph.h create mode 100644 shared-bindings/fontio/__init__.c create mode 100644 shared-bindings/fontio/__init__.h delete mode 100644 shared-module/displayio/BuiltinFont.c delete mode 100644 shared-module/displayio/BuiltinFont.h create mode 100644 shared-module/fontio/BuiltinFont.c create mode 100644 shared-module/fontio/BuiltinFont.h create mode 100644 shared-module/fontio/__init__.c (limited to 'shared-bindings') diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 09d0a93e2..7a369817a 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -124,7 +124,7 @@ ifeq ($(CIRCUITPY_DIGITALIO),1) SRC_PATTERNS += digitalio/% endif ifeq ($(CIRCUITPY_DISPLAYIO),1) -SRC_PATTERNS += displayio/% terminalio/% +SRC_PATTERNS += displayio/% terminalio/% fontio/% endif ifeq ($(CIRCUITPY_FREQUENCYIO),1) SRC_PATTERNS += frequencyio/% @@ -268,7 +268,7 @@ $(filter $(SRC_PATTERNS), \ digitalio/Direction.c \ digitalio/DriveMode.c \ digitalio/Pull.c \ - displayio/Glyph.c \ + fontio/Glyph.c \ microcontroller/RunMode.c \ math/__init__.c \ supervisor/__init__.c \ @@ -304,7 +304,6 @@ $(filter $(SRC_PATTERNS), \ bitbangio/__init__.c \ busio/OneWire.c \ displayio/Bitmap.c \ - displayio/BuiltinFont.c \ displayio/ColorConverter.c \ displayio/Display.c \ displayio/FourWire.c \ @@ -314,6 +313,8 @@ $(filter $(SRC_PATTERNS), \ displayio/Shape.c \ displayio/TileGrid.c \ displayio/__init__.c \ + fontio/BuiltinFont.c \ + fontio/__init__.c \ gamepad/GamePad.c \ gamepad/__init__.c \ os/__init__.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 00f3c7b3f..ba4e92aac 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -271,12 +271,15 @@ extern const struct _mp_obj_module_t digitalio_module; #if CIRCUITPY_DISPLAYIO extern const struct _mp_obj_module_t displayio_module; +extern const struct _mp_obj_module_t fontio_module; extern const struct _mp_obj_module_t terminalio_module; #define DISPLAYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_displayio), (mp_obj_t)&displayio_module }, +#define FONTIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_fontio), (mp_obj_t)&fontio_module }, #define TERMINALIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_terminalio), (mp_obj_t)&terminalio_module }, #define CIRCUITPY_DISPLAY_LIMIT (3) #else #define DISPLAYIO_MODULE +#define FONTIO_MODULE #define TERMINALIO_MODULE #define CIRCUITPY_DISPLAY_LIMIT (0) #endif @@ -523,8 +526,9 @@ extern const struct _mp_obj_module_t pew_module; BOARD_MODULE \ BUSIO_MODULE \ DIGITALIO_MODULE \ - TERMINALIO_MODULE \ DISPLAYIO_MODULE \ + FONTIO_MODULE \ + TERMINALIO_MODULE \ ERRNO_MODULE \ FREQUENCYIO_MODULE \ GAMEPAD_MODULE \ diff --git a/shared-bindings/displayio/BuiltinFont.c b/shared-bindings/displayio/BuiltinFont.c deleted file mode 100644 index 55d38458e..000000000 --- a/shared-bindings/displayio/BuiltinFont.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-bindings/displayio/BuiltinFont.h" - -#include - -#include "lib/utils/context_manager_helpers.h" -#include "py/binary.h" -#include "py/objproperty.h" -#include "py/runtime.h" -#include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" - -//| .. currentmodule:: displayio -//| -//| :class:`BuiltinFont` -- A font built into CircuitPython -//| ========================================================================================= -//| -//| A font built into CircuitPython. -//| -//| .. class:: BuiltinFont() -//| -//| Creation not supported. Available fonts are defined when CircuitPython is built. See the -//| `Adafruit_CircuitPython_Bitmap_Font `_ -//| library for dynamically loaded fonts. -//| - -//| .. attribute:: bitmap -//| -//| Bitmap containing all font glyphs starting with ASCII and followed by unicode. Use -//| `get_glyph` in most cases. This is useful for use with `displayio.TileGrid` and -//| `terminalio.Terminal`. -//| -STATIC mp_obj_t displayio_builtinfont_obj_get_bitmap(mp_obj_t self_in) { - displayio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_displayio_builtinfont_get_bitmap(self); -} -MP_DEFINE_CONST_FUN_OBJ_1(displayio_builtinfont_get_bitmap_obj, displayio_builtinfont_obj_get_bitmap); - -const mp_obj_property_t displayio_builtinfont_bitmap_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&displayio_builtinfont_get_bitmap_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| .. method:: get_bounding_box() -//| -//| Returns the maximum bounds of all glyphs in the font in a tuple of two values: width, height. -//| -STATIC mp_obj_t displayio_builtinfont_obj_get_bounding_box(mp_obj_t self_in) { - displayio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in); - - return common_hal_displayio_builtinfont_get_bounding_box(self); -} -MP_DEFINE_CONST_FUN_OBJ_1(displayio_builtinfont_get_bounding_box_obj, displayio_builtinfont_obj_get_bounding_box); - - -//| .. method:: get_glyph(codepoint) -//| -//| Returns a `displayio.Glyph` for the given codepoint or None if no glyph is available. -//| -STATIC mp_obj_t displayio_builtinfont_obj_get_glyph(mp_obj_t self_in, mp_obj_t codepoint_obj) { - displayio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in); - - mp_int_t codepoint; - if (!mp_obj_get_int_maybe(codepoint_obj, &codepoint)) { - mp_raise_ValueError_varg(translate("%q should be an int"), MP_QSTR_codepoint); - } - return common_hal_displayio_builtinfont_get_glyph(self, codepoint); -} -MP_DEFINE_CONST_FUN_OBJ_2(displayio_builtinfont_get_glyph_obj, displayio_builtinfont_obj_get_glyph); - -STATIC const mp_rom_map_elem_t displayio_builtinfont_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&displayio_builtinfont_bitmap_obj) }, - { MP_ROM_QSTR(MP_QSTR_get_bounding_box), MP_ROM_PTR(&displayio_builtinfont_get_bounding_box_obj) }, - { MP_ROM_QSTR(MP_QSTR_get_glyph), MP_ROM_PTR(&displayio_builtinfont_get_glyph_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(displayio_builtinfont_locals_dict, displayio_builtinfont_locals_dict_table); - -const mp_obj_type_t displayio_builtinfont_type = { - { &mp_type_type }, - .name = MP_QSTR_BuiltinFont, - .locals_dict = (mp_obj_dict_t*)&displayio_builtinfont_locals_dict, -}; diff --git a/shared-bindings/displayio/BuiltinFont.h b/shared-bindings/displayio/BuiltinFont.h deleted file mode 100644 index 766013158..000000000 --- a/shared-bindings/displayio/BuiltinFont.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BUILTINFONT_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BUILTINFONT_H - -#include "shared-module/displayio/BuiltinFont.h" - -extern const mp_obj_type_t displayio_builtinfont_type; - -mp_obj_t common_hal_displayio_builtinfont_get_bitmap(const displayio_builtinfont_t *self); -mp_obj_t common_hal_displayio_builtinfont_get_bounding_box(const displayio_builtinfont_t *self); -mp_obj_t common_hal_displayio_builtinfont_get_glyph(const displayio_builtinfont_t *self, mp_uint_t codepoint); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BUILTINFONT_H diff --git a/shared-bindings/displayio/Glyph.c b/shared-bindings/displayio/Glyph.c deleted file mode 100644 index 1a4a75522..000000000 --- a/shared-bindings/displayio/Glyph.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-bindings/displayio/Glyph.h" - -#include - -//| .. currentmodule:: displayio -//| -//| :class:`Glyph` -- Storage of glyph info -//| ========================================================================== -//| -//| .. class:: Glyph(bitmap, tile_index, width, height, dx, dy, shift_x, shift_y) -//| -//| Named tuple used to capture a single glyph and its attributes. -//| -//| :param displayio.Bitmap bitmap: the bitmap including the glyph -//| :param int tile_index: the tile index within the bitmap -//| :param int width: the width of the glyph's bitmap -//| :param int height: the height of the glyph's bitmap -//| :param int dx: x adjustment to the bitmap's position -//| :param int dy: y adjustment to the bitmap's position -//| :param int shift_x: the x difference to the next glyph -//| :param int shift_y: the y difference to the next glyph -//| -const mp_obj_namedtuple_type_t displayio_glyph_type = { - .base = { - .base = { - .type = &mp_type_type - }, - .name = MP_QSTR_Glyph, - .print = namedtuple_print, - .make_new = namedtuple_make_new, - .unary_op = mp_obj_tuple_unary_op, - .binary_op = mp_obj_tuple_binary_op, - .attr = namedtuple_attr, - .subscr = mp_obj_tuple_subscr, - .getiter = mp_obj_tuple_getiter, - .parent = &mp_type_tuple, - }, - .n_fields = 8, - .fields = { - MP_QSTR_bitmap, - MP_QSTR_tile_index, - MP_QSTR_width, - MP_QSTR_height, - MP_QSTR_dx, - MP_QSTR_dy, - MP_QSTR_shift_x, - MP_QSTR_shift_y - }, -}; diff --git a/shared-bindings/displayio/Glyph.h b/shared-bindings/displayio/Glyph.h deleted file mode 100644 index d26a4b9e4..000000000 --- a/shared-bindings/displayio/Glyph.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GLYPH_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GLYPH_H - -#include "py/objnamedtuple.h" - -extern const mp_obj_namedtuple_type_t displayio_glyph_type; - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GLYPH_H diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 177bd5fff..893bc6290 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -31,11 +31,9 @@ #include "shared-bindings/displayio/__init__.h" #include "shared-bindings/displayio/Bitmap.h" -#include "shared-bindings/displayio/BuiltinFont.h" #include "shared-bindings/displayio/ColorConverter.h" #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/FourWire.h" -#include "shared-bindings/displayio/Glyph.h" #include "shared-bindings/displayio/Group.h" #include "shared-bindings/displayio/OnDiskBitmap.h" #include "shared-bindings/displayio/Palette.h" @@ -91,10 +89,8 @@ MP_DEFINE_CONST_FUN_OBJ_0(displayio_release_displays_obj, displayio_release_disp STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_displayio) }, { MP_ROM_QSTR(MP_QSTR_Bitmap), MP_ROM_PTR(&displayio_bitmap_type) }, - { MP_ROM_QSTR(MP_QSTR_BuiltinFont), MP_ROM_PTR(&displayio_builtinfont_type) }, { MP_ROM_QSTR(MP_QSTR_ColorConverter), MP_ROM_PTR(&displayio_colorconverter_type) }, { MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&displayio_display_type) }, - { MP_ROM_QSTR(MP_QSTR_Glyph), MP_ROM_PTR(&displayio_glyph_type) }, { MP_ROM_QSTR(MP_QSTR_Group), MP_ROM_PTR(&displayio_group_type) }, { MP_ROM_QSTR(MP_QSTR_OnDiskBitmap), MP_ROM_PTR(&displayio_ondiskbitmap_type) }, { MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) }, diff --git a/shared-bindings/fontio/BuiltinFont.c b/shared-bindings/fontio/BuiltinFont.c new file mode 100644 index 000000000..74bc4d29e --- /dev/null +++ b/shared-bindings/fontio/BuiltinFont.c @@ -0,0 +1,110 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/fontio/BuiltinFont.h" + +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/binary.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: fontio +//| +//| :class:`BuiltinFont` -- A font built into CircuitPython +//| ========================================================================================= +//| +//| A font built into CircuitPython. +//| +//| .. class:: BuiltinFont() +//| +//| Creation not supported. Available fonts are defined when CircuitPython is built. See the +//| `Adafruit_CircuitPython_Bitmap_Font `_ +//| library for dynamically loaded fonts. +//| + +//| .. attribute:: bitmap +//| +//| Bitmap containing all font glyphs starting with ASCII and followed by unicode. Use +//| `get_glyph` in most cases. This is useful for use with `displayio.TileGrid` and +//| `terminalio.Terminal`. +//| +STATIC mp_obj_t fontio_builtinfont_obj_get_bitmap(mp_obj_t self_in) { + fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in); + return common_hal_fontio_builtinfont_get_bitmap(self); +} +MP_DEFINE_CONST_FUN_OBJ_1(fontio_builtinfont_get_bitmap_obj, fontio_builtinfont_obj_get_bitmap); + +const mp_obj_property_t fontio_builtinfont_bitmap_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&fontio_builtinfont_get_bitmap_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| .. method:: get_bounding_box() +//| +//| Returns the maximum bounds of all glyphs in the font in a tuple of two values: width, height. +//| +STATIC mp_obj_t fontio_builtinfont_obj_get_bounding_box(mp_obj_t self_in) { + fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in); + + return common_hal_fontio_builtinfont_get_bounding_box(self); +} +MP_DEFINE_CONST_FUN_OBJ_1(fontio_builtinfont_get_bounding_box_obj, fontio_builtinfont_obj_get_bounding_box); + + +//| .. method:: get_glyph(codepoint) +//| +//| Returns a `fontio.Glyph` for the given codepoint or None if no glyph is available. +//| +STATIC mp_obj_t fontio_builtinfont_obj_get_glyph(mp_obj_t self_in, mp_obj_t codepoint_obj) { + fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in); + + mp_int_t codepoint; + if (!mp_obj_get_int_maybe(codepoint_obj, &codepoint)) { + mp_raise_ValueError_varg(translate("%q should be an int"), MP_QSTR_codepoint); + } + return common_hal_fontio_builtinfont_get_glyph(self, codepoint); +} +MP_DEFINE_CONST_FUN_OBJ_2(fontio_builtinfont_get_glyph_obj, fontio_builtinfont_obj_get_glyph); + +STATIC const mp_rom_map_elem_t fontio_builtinfont_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&fontio_builtinfont_bitmap_obj) }, + { MP_ROM_QSTR(MP_QSTR_get_bounding_box), MP_ROM_PTR(&fontio_builtinfont_get_bounding_box_obj) }, + { MP_ROM_QSTR(MP_QSTR_get_glyph), MP_ROM_PTR(&fontio_builtinfont_get_glyph_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(fontio_builtinfont_locals_dict, fontio_builtinfont_locals_dict_table); + +const mp_obj_type_t fontio_builtinfont_type = { + { &mp_type_type }, + .name = MP_QSTR_BuiltinFont, + .locals_dict = (mp_obj_dict_t*)&fontio_builtinfont_locals_dict, +}; diff --git a/shared-bindings/fontio/BuiltinFont.h b/shared-bindings/fontio/BuiltinFont.h new file mode 100644 index 000000000..e87445e6b --- /dev/null +++ b/shared-bindings/fontio/BuiltinFont.h @@ -0,0 +1,38 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_BUILTINFONT_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_BUILTINFONT_H + +#include "shared-module/fontio/BuiltinFont.h" + +extern const mp_obj_type_t fontio_builtinfont_type; + +mp_obj_t common_hal_fontio_builtinfont_get_bitmap(const fontio_builtinfont_t *self); +mp_obj_t common_hal_fontio_builtinfont_get_bounding_box(const fontio_builtinfont_t *self); +mp_obj_t common_hal_fontio_builtinfont_get_glyph(const fontio_builtinfont_t *self, mp_uint_t codepoint); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_BUILTINFONT_H diff --git a/shared-bindings/fontio/Glyph.c b/shared-bindings/fontio/Glyph.c new file mode 100644 index 000000000..80298fd16 --- /dev/null +++ b/shared-bindings/fontio/Glyph.c @@ -0,0 +1,75 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/fontio/Glyph.h" + +#include + +//| .. currentmodule:: fontio +//| +//| :class:`Glyph` -- Storage of glyph info +//| ========================================================================== +//| +//| .. class:: Glyph(bitmap, tile_index, width, height, dx, dy, shift_x, shift_y) +//| +//| Named tuple used to capture a single glyph and its attributes. +//| +//| :param fontio.Bitmap bitmap: the bitmap including the glyph +//| :param int tile_index: the tile index within the bitmap +//| :param int width: the width of the glyph's bitmap +//| :param int height: the height of the glyph's bitmap +//| :param int dx: x adjustment to the bitmap's position +//| :param int dy: y adjustment to the bitmap's position +//| :param int shift_x: the x difference to the next glyph +//| :param int shift_y: the y difference to the next glyph +//| +const mp_obj_namedtuple_type_t fontio_glyph_type = { + .base = { + .base = { + .type = &mp_type_type + }, + .name = MP_QSTR_Glyph, + .print = namedtuple_print, + .make_new = namedtuple_make_new, + .unary_op = mp_obj_tuple_unary_op, + .binary_op = mp_obj_tuple_binary_op, + .attr = namedtuple_attr, + .subscr = mp_obj_tuple_subscr, + .getiter = mp_obj_tuple_getiter, + .parent = &mp_type_tuple, + }, + .n_fields = 8, + .fields = { + MP_QSTR_bitmap, + MP_QSTR_tile_index, + MP_QSTR_width, + MP_QSTR_height, + MP_QSTR_dx, + MP_QSTR_dy, + MP_QSTR_shift_x, + MP_QSTR_shift_y + }, +}; diff --git a/shared-bindings/fontio/Glyph.h b/shared-bindings/fontio/Glyph.h new file mode 100644 index 000000000..c58d812dd --- /dev/null +++ b/shared-bindings/fontio/Glyph.h @@ -0,0 +1,34 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_GLYPH_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_GLYPH_H + +#include "py/objnamedtuple.h" + +extern const mp_obj_namedtuple_type_t fontio_glyph_type; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO_GLYPH_H diff --git a/shared-bindings/fontio/__init__.c b/shared-bindings/fontio/__init__.c new file mode 100644 index 000000000..cd0f5ab0f --- /dev/null +++ b/shared-bindings/fontio/__init__.c @@ -0,0 +1,65 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/fontio/__init__.h" +#include "shared-bindings/fontio/BuiltinFont.h" +#include "shared-bindings/fontio/Glyph.h" + +//| :mod:`fontio` --- Core font related data structures +//| ========================================================================= +//| +//| .. module:: fontio +//| :synopsis: Core font related data structures +//| :platform: SAMD21, SAMD51, nRF52 +//| +//| The `fontio` module contains classes to store font related information. +//| +//| Libraries +//| +//| .. toctree:: +//| :maxdepth: 3 +//| +//| BuiltinFont +//| Glyph +//| + +STATIC const mp_rom_map_elem_t fontio_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_fontio) }, + { MP_ROM_QSTR(MP_QSTR_BuiltinFont), MP_ROM_PTR(&fontio_builtinfont_type) }, + { MP_ROM_QSTR(MP_QSTR_Glyph), MP_ROM_PTR(&fontio_glyph_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(fontio_module_globals, fontio_module_globals_table); + +const mp_obj_module_t fontio_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&fontio_module_globals, +}; diff --git a/shared-bindings/fontio/__init__.h b/shared-bindings/fontio/__init__.h new file mode 100644 index 000000000..209919777 --- /dev/null +++ b/shared-bindings/fontio/__init__.h @@ -0,0 +1,31 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO___INIT___H + + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_FONTIO___INIT___H diff --git a/shared-bindings/terminalio/Terminal.c b/shared-bindings/terminalio/Terminal.c index e3822d858..f0dc150c0 100644 --- a/shared-bindings/terminalio/Terminal.c +++ b/shared-bindings/terminalio/Terminal.c @@ -34,7 +34,7 @@ #include "py/objstr.h" #include "py/runtime.h" #include "py/stream.h" -#include "shared-bindings/displayio/BuiltinFont.h" +#include "shared-bindings/fontio/BuiltinFont.h" #include "supervisor/shared/translate.h" @@ -64,8 +64,8 @@ STATIC mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n } mp_obj_t font = args[ARG_font].u_obj; - if (!MP_OBJ_IS_TYPE(font, &displayio_builtinfont_type)) { - mp_raise_TypeError_varg(translate("Expected a %q"), displayio_builtinfont_type.name); + if (!MP_OBJ_IS_TYPE(font, &fontio_builtinfont_type)) { + mp_raise_TypeError_varg(translate("Expected a %q"), fontio_builtinfont_type.name); } terminalio_terminal_obj_t *self = m_new_obj(terminalio_terminal_obj_t); self->base.type = &terminalio_terminal_type; diff --git a/shared-bindings/terminalio/Terminal.h b/shared-bindings/terminalio/Terminal.h index a5dadac89..7ae0bf1b0 100644 --- a/shared-bindings/terminalio/Terminal.h +++ b/shared-bindings/terminalio/Terminal.h @@ -34,7 +34,7 @@ extern const mp_obj_type_t terminalio_terminal_type; extern void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, - displayio_tilegrid_t* tilegrid, const displayio_builtinfont_t* font); + displayio_tilegrid_t* tilegrid, const fontio_builtinfont_t* font); // Write characters. len is in characters NOT bytes! extern size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, diff --git a/shared-module/displayio/BuiltinFont.c b/shared-module/displayio/BuiltinFont.c deleted file mode 100644 index ee69b423c..000000000 --- a/shared-module/displayio/BuiltinFont.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-bindings/displayio/BuiltinFont.h" - - -#include "shared-bindings/displayio/Glyph.h" - -#include "py/objnamedtuple.h" - -mp_obj_t common_hal_displayio_builtinfont_get_bitmap(const displayio_builtinfont_t *self) { - return MP_OBJ_FROM_PTR(self->bitmap); -} - -mp_obj_t common_hal_displayio_builtinfont_get_bounding_box(const displayio_builtinfont_t *self) { - mp_obj_t *items = m_new(mp_obj_t, 2); - items[0] = MP_OBJ_NEW_SMALL_INT(self->width); - items[1] = MP_OBJ_NEW_SMALL_INT(self->height); - return mp_obj_new_tuple(2, items); -} - -uint8_t displayio_builtinfont_get_glyph_index(const displayio_builtinfont_t *self, mp_uint_t codepoint) { - if (codepoint >= 0x20 && codepoint <= 0x7e) { - return codepoint - 0x20; - } - // Do a linear search of the mapping for unicode. - const byte* j = self->unicode_characters; - uint8_t k = 0; - while (j < self->unicode_characters + self->unicode_characters_len) { - unichar potential_c = utf8_get_char(j); - j = utf8_next_char(j); - if (codepoint == potential_c) { - return 0x7f - 0x20 + k; - } - k++; - } - return 0xff; -} - -mp_obj_t common_hal_displayio_builtinfont_get_glyph(const displayio_builtinfont_t *self, mp_uint_t codepoint) { - uint8_t glyph_index = displayio_builtinfont_get_glyph_index(self, codepoint); - if (glyph_index == 0xff) { - return mp_const_none; - } - mp_obj_t field_values[8] = { - MP_OBJ_FROM_PTR(self->bitmap), - MP_OBJ_NEW_SMALL_INT(glyph_index), - MP_OBJ_NEW_SMALL_INT(self->width), - MP_OBJ_NEW_SMALL_INT(self->height), - MP_OBJ_NEW_SMALL_INT(0), - MP_OBJ_NEW_SMALL_INT(0), - MP_OBJ_NEW_SMALL_INT(self->width), - MP_OBJ_NEW_SMALL_INT(0) - }; - return namedtuple_make_new((const mp_obj_type_t*) &displayio_glyph_type, 8, field_values, NULL); -} diff --git a/shared-module/displayio/BuiltinFont.h b/shared-module/displayio/BuiltinFont.h deleted file mode 100644 index ac69ef9da..000000000 --- a/shared-module/displayio/BuiltinFont.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_BUILTINFONT_H -#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_BUILTINFONT_H - -#include -#include - -#include "py/obj.h" -#include "shared-bindings/displayio/Bitmap.h" - -typedef struct { - mp_obj_base_t base; - const displayio_bitmap_t* bitmap; - uint8_t width; - uint8_t height; - const byte* unicode_characters; - uint16_t unicode_characters_len; -} displayio_builtinfont_t; - -uint8_t displayio_builtinfont_get_glyph_index(const displayio_builtinfont_t *self, mp_uint_t codepoint); - -#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_BUILTINFONT_H diff --git a/shared-module/fontio/BuiltinFont.c b/shared-module/fontio/BuiltinFont.c new file mode 100644 index 000000000..58820d524 --- /dev/null +++ b/shared-module/fontio/BuiltinFont.c @@ -0,0 +1,79 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/fontio/BuiltinFont.h" + + +#include "shared-bindings/fontio/Glyph.h" + +#include "py/objnamedtuple.h" + +mp_obj_t common_hal_fontio_builtinfont_get_bitmap(const fontio_builtinfont_t *self) { + return MP_OBJ_FROM_PTR(self->bitmap); +} + +mp_obj_t common_hal_fontio_builtinfont_get_bounding_box(const fontio_builtinfont_t *self) { + mp_obj_t *items = m_new(mp_obj_t, 2); + items[0] = MP_OBJ_NEW_SMALL_INT(self->width); + items[1] = MP_OBJ_NEW_SMALL_INT(self->height); + return mp_obj_new_tuple(2, items); +} + +uint8_t fontio_builtinfont_get_glyph_index(const fontio_builtinfont_t *self, mp_uint_t codepoint) { + if (codepoint >= 0x20 && codepoint <= 0x7e) { + return codepoint - 0x20; + } + // Do a linear search of the mapping for unicode. + const byte* j = self->unicode_characters; + uint8_t k = 0; + while (j < self->unicode_characters + self->unicode_characters_len) { + unichar potential_c = utf8_get_char(j); + j = utf8_next_char(j); + if (codepoint == potential_c) { + return 0x7f - 0x20 + k; + } + k++; + } + return 0xff; +} + +mp_obj_t common_hal_fontio_builtinfont_get_glyph(const fontio_builtinfont_t *self, mp_uint_t codepoint) { + uint8_t glyph_index = fontio_builtinfont_get_glyph_index(self, codepoint); + if (glyph_index == 0xff) { + return mp_const_none; + } + mp_obj_t field_values[8] = { + MP_OBJ_FROM_PTR(self->bitmap), + MP_OBJ_NEW_SMALL_INT(glyph_index), + MP_OBJ_NEW_SMALL_INT(self->width), + MP_OBJ_NEW_SMALL_INT(self->height), + MP_OBJ_NEW_SMALL_INT(0), + MP_OBJ_NEW_SMALL_INT(0), + MP_OBJ_NEW_SMALL_INT(self->width), + MP_OBJ_NEW_SMALL_INT(0) + }; + return namedtuple_make_new((const mp_obj_type_t*) &fontio_glyph_type, 8, field_values, NULL); +} diff --git a/shared-module/fontio/BuiltinFont.h b/shared-module/fontio/BuiltinFont.h new file mode 100644 index 000000000..30b4ade8c --- /dev/null +++ b/shared-module/fontio/BuiltinFont.h @@ -0,0 +1,47 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_FONTIO_BUILTINFONT_H +#define MICROPY_INCLUDED_SHARED_MODULE_FONTIO_BUILTINFONT_H + +#include +#include + +#include "py/obj.h" +#include "shared-bindings/displayio/Bitmap.h" + +typedef struct { + mp_obj_base_t base; + const displayio_bitmap_t* bitmap; + uint8_t width; + uint8_t height; + const byte* unicode_characters; + uint16_t unicode_characters_len; +} fontio_builtinfont_t; + +uint8_t fontio_builtinfont_get_glyph_index(const fontio_builtinfont_t *self, mp_uint_t codepoint); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_FONTIO_BUILTINFONT_H diff --git a/shared-module/fontio/__init__.c b/shared-module/fontio/__init__.c new file mode 100644 index 000000000..674343c53 --- /dev/null +++ b/shared-module/fontio/__init__.c @@ -0,0 +1,27 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// Nothing now. diff --git a/shared-module/terminalio/Terminal.c b/shared-module/terminalio/Terminal.c index 07c13d639..7adf9d032 100644 --- a/shared-module/terminalio/Terminal.c +++ b/shared-module/terminalio/Terminal.c @@ -26,11 +26,10 @@ #include "shared-module/terminalio/Terminal.h" -#include "shared-module/displayio/__init__.h" -#include "shared-module/displayio/BuiltinFont.h" +#include "shared-module/fontio/BuiltinFont.h" #include "shared-bindings/displayio/TileGrid.h" -void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t* tilegrid, const displayio_builtinfont_t* font) { +void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t* tilegrid, const fontio_builtinfont_t* font) { self->cursor_x = 0; self->cursor_y = 0; self->font = font; @@ -47,7 +46,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con // Always handle ASCII. if (c < 128) { if (c >= 0x20 && c <= 0x7e) { - uint8_t tile_index = displayio_builtinfont_get_glyph_index(self->font, c); + uint8_t tile_index = fontio_builtinfont_get_glyph_index(self->font, c); common_hal_displayio_tilegrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, tile_index); self->cursor_x++; } else if (c == '\r') { @@ -92,7 +91,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con } } } else { - uint8_t tile_index = displayio_builtinfont_get_glyph_index(self->font, c); + uint8_t tile_index = fontio_builtinfont_get_glyph_index(self->font, c); if (tile_index != 0xff) { common_hal_displayio_tilegrid_set_tile(self->tilegrid, self->cursor_x, self->cursor_y, tile_index); self->cursor_x++; diff --git a/shared-module/terminalio/Terminal.h b/shared-module/terminalio/Terminal.h index 145b42f3f..c31392cc4 100644 --- a/shared-module/terminalio/Terminal.h +++ b/shared-module/terminalio/Terminal.h @@ -31,12 +31,12 @@ #include #include "py/obj.h" -#include "shared-module/displayio/BuiltinFont.h" +#include "shared-module/fontio/BuiltinFont.h" #include "shared-module/displayio/TileGrid.h" typedef struct { mp_obj_base_t base; - const displayio_builtinfont_t* font; + const fontio_builtinfont_t* font; uint16_t cursor_x; uint16_t cursor_y; displayio_tilegrid_t* tilegrid; diff --git a/supervisor/shared/display.h b/supervisor/shared/display.h index cb321e85e..d5faa7777 100644 --- a/supervisor/shared/display.h +++ b/supervisor/shared/display.h @@ -27,9 +27,9 @@ #ifndef MICROPY_INCLUDED_SUPERVISOR_SHARED_DISPLAY_H #define MICROPY_INCLUDED_SUPERVISOR_SHARED_DISPLAY_H -#include "shared-bindings/displayio/BuiltinFont.h" #include "shared-bindings/displayio/Bitmap.h" #include "shared-bindings/displayio/TileGrid.h" +#include "shared-bindings/fontio/BuiltinFont.h" #include "shared-bindings/terminalio/Terminal.h" // These are autogenerated resources. @@ -37,7 +37,7 @@ // This is fixed so it doesn't need to be in RAM. extern const displayio_bitmap_t supervisor_terminal_font_bitmap; -extern const displayio_builtinfont_t supervisor_terminal_font; +extern const fontio_builtinfont_t supervisor_terminal_font; // These will change so they must live in RAM. extern displayio_tilegrid_t supervisor_terminal_text_grid; diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py index 22f19d84e..82676ef07 100644 --- a/tools/gen_display_resources.py +++ b/tools/gen_display_resources.py @@ -165,8 +165,8 @@ const displayio_bitmap_t supervisor_terminal_font_bitmap = {{ c_file.write("""\ -const displayio_builtinfont_t supervisor_terminal_font = {{ - .base = {{.type = &displayio_builtinfont_type }}, +const fontio_builtinfont_t supervisor_terminal_font = {{ + .base = {{.type = &fontio_builtinfont_type }}, .bitmap = &supervisor_terminal_font_bitmap, .width = {}, .height = {}, -- cgit v1.2.3 From 4b0afc855d6b7784fe7a31a694a66f0c1e7cb0e5 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 19 Mar 2019 18:37:41 -0700 Subject: Fix up sphinx --- shared-bindings/displayio/__init__.c | 2 -- shared-bindings/terminalio/Terminal.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 893bc6290..44b1e0b07 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -57,11 +57,9 @@ //| :maxdepth: 3 //| //| Bitmap -//| BuiltinFont //| ColorConverter //| Display //| FourWire -//| Glyph //| Group //| OnDiskBitmap //| Palette diff --git a/shared-bindings/terminalio/Terminal.c b/shared-bindings/terminalio/Terminal.c index f0dc150c0..cdde672d3 100644 --- a/shared-bindings/terminalio/Terminal.c +++ b/shared-bindings/terminalio/Terminal.c @@ -46,7 +46,7 @@ //| .. class:: Terminal(tilegrid, font) //| //| Terminal manages tile indices and cursor position based on VT100 commands. The font should be -//| a `displayio.BuiltinFont` and the TileGrid's bitmap should match the font's bitmap. +//| a `fontio.BuiltinFont` and the TileGrid's bitmap should match the font's bitmap. //| STATIC mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { -- cgit v1.2.3 From e23bad3a3af2c334573d6233508cf2fd3b111b66 Mon Sep 17 00:00:00 2001 From: Joshua Coats Date: Sat, 23 Mar 2019 10:49:43 -0700 Subject: shared-bindings/socket: add socket_recv_into --- shared-bindings/socket/__init__.c | 53 +++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c index 29d47de56..c59724efc 100644 --- a/shared-bindings/socket/__init__.c +++ b/shared-bindings/socket/__init__.c @@ -240,6 +240,52 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); + +// helper function for socket_recv and socket_recv_into to handle common operations of both +STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_int_t len) { + int _errno; + mp_int_t ret = sock->nic_type->recv(sock, buf, len, &_errno); + if (ret == -1) { + mp_raise_OSError(_errno); + } + return len; +} + + +//| .. method:: recv_into(buffer[, bufsize]) +//| +//| Reads some bytes from the connected remote address, writing +//| into the provided buffer. If bufsize <= len(buffer) is given, +//| a maximum of bufsize bytes will be read into the buffer. If no +//| valid value is given for bufsize, the default is the length of +//| the given buffer. +//| +//| Suits sockets of type SOCK_STREAM +//| Returns an int of number of bytes read. +//| +//| :param bytearray buffer: buffer to receive into +//| :param int bufsize: optionally, a maximum number of bytes to read. + +STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) { + mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); + if (self->nic == MP_OBJ_NULL) { + // not connected + mp_raise_OSError(MP_ENOTCONN); + } + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); + mp_int_t len; + if (n_args == 3) { + len = mp_obj_get_int(args[2]); + } + if (n_args == 2 || (size_t) len > bufinfo.len) { + len = bufinfo.len; + } + mp_int_t ret = _socket_recv_into(self, (byte*)bufinfo.buf, len); + return mp_obj_new_int_from_uint(ret); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_into_obj, 2, 3, socket_recv_into); + //| .. method:: recv(bufsize) //| //| Reads some bytes from the connected remote address. @@ -257,11 +303,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { mp_int_t len = mp_obj_get_int(len_in); vstr_t vstr; vstr_init_len(&vstr, len); - int _errno; - mp_int_t ret = self->nic_type->recv(self, (byte*)vstr.buf, len, &_errno); - if (ret == -1) { - mp_raise_OSError(_errno); - } + mp_int_t ret = _socket_recv_into(self, (byte*)vstr.buf, len); if (ret == 0) { return mp_const_empty_bytes; } @@ -436,6 +478,7 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&socket_recv_obj) }, { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socket_sendto_obj) }, { MP_ROM_QSTR(MP_QSTR_recvfrom), MP_ROM_PTR(&socket_recvfrom_obj) }, + { MP_ROM_QSTR(MP_QSTR_recv_into), MP_ROM_PTR(&socket_recv_into_obj) }, { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socket_setsockopt_obj) }, { MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&socket_settimeout_obj) }, { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) }, -- cgit v1.2.3 From fadb5a102426182f1412adbbe9d57268882f8b5f Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sat, 23 Mar 2019 18:34:42 -0700 Subject: Added option to toggle cs in displayio init sequence --- shared-bindings/displayio/Display.c | 8 +++++--- shared-bindings/displayio/Display.h | 2 +- shared-bindings/displayio/FourWire.h | 2 ++ shared-module/displayio/Display.c | 8 +++++++- shared-module/displayio/Display.h | 3 +++ shared-module/displayio/FourWire.c | 5 +++++ 6 files changed, 23 insertions(+), 5 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 1f46330e8..3f5eef34a 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -50,7 +50,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, init_cs_toggle=False) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -93,7 +93,7 @@ //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_init_cs_toggle }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -108,6 +108,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + { MP_QSTR_init_cs_toggle, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -146,7 +147,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, args[ARG_write_ram_command].u_int, args[ARG_set_vertical_scroll].u_int, - bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin)); + bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin), + args[ARG_init_cs_toggle].u_bool); return self; } diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 7d6444a2d..407afe1c3 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -40,7 +40,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, - uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin); + uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle); int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self); diff --git a/shared-bindings/displayio/FourWire.h b/shared-bindings/displayio/FourWire.h index b8b00372c..a7fda2638 100644 --- a/shared-bindings/displayio/FourWire.h +++ b/shared-bindings/displayio/FourWire.h @@ -47,4 +47,6 @@ void common_hal_displayio_fourwire_send(mp_obj_t self, bool command, uint8_t *da void common_hal_displayio_fourwire_end_transaction(mp_obj_t self); +void common_hal_displayio_fourwire_set_cs(mp_obj_t self, bool high); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_FOURWIRE_H diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 0e76a868f..f82d94799 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, - const mcu_pin_obj_t* backlight_pin) { + const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle) { self->color_depth = color_depth; self->set_column_command = set_column_command; self->set_row_command = set_row_command; @@ -54,6 +54,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->colstart = colstart; self->rowstart = rowstart; self->auto_brightness = false; + self->init_cs_toggle = init_cs_toggle; if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) { self->begin_transaction = common_hal_displayio_parallelbus_begin_transaction; @@ -63,6 +64,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->begin_transaction = common_hal_displayio_fourwire_begin_transaction; self->send = common_hal_displayio_fourwire_send; self->end_transaction = common_hal_displayio_fourwire_end_transaction; + self->set_cs = common_hal_displayio_fourwire_set_cs; } else { mp_raise_ValueError(translate("Unsupported display bus type")); } @@ -82,6 +84,10 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, uint8_t *data = cmd + 2; self->send(self->bus, true, cmd, 1); self->send(self->bus, false, data, data_size); + if (self->init_cs_toggle && self->set_cs != NULL) { + self->set_cs(self->bus, true); + self->set_cs(self->bus, false); + } uint16_t delay_length_ms = 10; if (delay) { data_size++; diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 04da68b63..250f44031 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -34,6 +34,7 @@ typedef bool (*display_bus_begin_transaction)(mp_obj_t bus); typedef void (*display_bus_send)(mp_obj_t bus, bool command, uint8_t *data, uint32_t data_length); typedef void (*display_bus_end_transaction)(mp_obj_t bus); +typedef void (*display_bus_set_cs)(mp_obj_t bus, bool high); typedef struct { mp_obj_base_t base; @@ -49,9 +50,11 @@ typedef struct { uint64_t last_refresh; int16_t colstart; int16_t rowstart; + bool init_cs_toggle; display_bus_begin_transaction begin_transaction; display_bus_send send; display_bus_end_transaction end_transaction; + display_bus_set_cs set_cs; union { digitalio_digitalinout_obj_t backlight_inout; pulseio_pwmout_obj_t backlight_pwm; diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c index 9da5c0701..ae1fde7ca 100644 --- a/shared-module/displayio/FourWire.c +++ b/shared-module/displayio/FourWire.c @@ -87,3 +87,8 @@ void common_hal_displayio_fourwire_end_transaction(mp_obj_t obj) { common_hal_digitalio_digitalinout_set_value(&self->chip_select, true); common_hal_busio_spi_unlock(self->bus); } + +void common_hal_displayio_fourwire_set_cs(mp_obj_t obj, bool high) { + displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj); + common_hal_digitalio_digitalinout_set_value(&self->chip_select, high); +} -- cgit v1.2.3 From 2bb63cbeb351a93fba1f15d201d01fc608b42c53 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sat, 23 Mar 2019 18:53:04 -0700 Subject: Added new parameter description in displayio RTD comment --- shared-bindings/displayio/Display.c | 1 + 1 file changed, 1 insertion(+) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 3f5eef34a..7f98ea8c0 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -91,6 +91,7 @@ //| :param int write_ram_command: Command used to write pixels values into the update region //| :param int set_vertical_scroll: Command used to set the first row to show //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight +//| :param bool init_cs_toggle: Toggle the Chip Select between each initialization command. //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_init_cs_toggle }; -- cgit v1.2.3 From 0c33f7fdb4bd92ba2475671fee0ad2ae841eb5ba Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sat, 23 Mar 2019 20:23:23 -0700 Subject: Enable CS toggle for displayio by default --- ports/atmel-samd/boards/hallowing_m0_express/board.c | 2 +- ports/atmel-samd/boards/pybadge/board.c | 2 +- ports/atmel-samd/boards/pyportal/board.c | 2 +- shared-bindings/displayio/Display.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 64d74aad0..4f073e270 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -94,7 +94,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, - false); + true); common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 2c60015da..ce8c42a43 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -100,7 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, - false); + true); common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 1395daaae..3a306b0b4 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -91,7 +91,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PB31, - false); + true); common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 7f98ea8c0..8fed5129f 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -109,7 +109,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, - { MP_QSTR_init_cs_toggle, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_init_cs_toggle, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); -- cgit v1.2.3 From d9de1b99263bcc906af35a78ac81a11fff9483ca Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sun, 24 Mar 2019 08:23:46 -0700 Subject: Updated RTD comment to reflect new param defaulting True --- shared-bindings/displayio/Display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 8fed5129f..9cefb9532 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -50,7 +50,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, init_cs_toggle=False) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, init_cs_toggle=True) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -91,7 +91,7 @@ //| :param int write_ram_command: Command used to write pixels values into the update region //| :param int set_vertical_scroll: Command used to set the first row to show //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight -//| :param bool init_cs_toggle: Toggle the Chip Select between each initialization command. +//| :param bool init_cs_toggle: Toggle the Chip Select between each initialization command //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_init_cs_toggle }; -- cgit v1.2.3 From cc6fb4595ede6e27ae03edc8af782496e87698bb Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Mon, 25 Mar 2019 01:41:52 +0100 Subject: Reuse existing error message in busio.i2c Remove a period from the error message, so that the same message as in SPI and other places in I2C can be re-used. --- shared-bindings/busio/I2C.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index e792d2575..e17a72b48 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -114,7 +114,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_i2c___exit___obj, 4, 4, busio_i static void check_lock(busio_i2c_obj_t *self) { asm(""); if (!common_hal_busio_i2c_has_lock(self)) { - mp_raise_RuntimeError(translate("Function requires lock.")); + mp_raise_RuntimeError(translate("Function requires lock")); } } -- cgit v1.2.3 From c3329e224ddf352131568a5dd914943bc5194d4d Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sun, 24 Mar 2019 23:59:28 -0700 Subject: Added Single Byte Boundaries option for certain displays --- .../atmel-samd/boards/hallowing_m0_express/board.c | 3 ++- ports/atmel-samd/boards/pybadge/board.c | 3 ++- ports/atmel-samd/boards/pyportal/board.c | 4 +++- shared-bindings/displayio/Display.c | 11 +++++---- shared-bindings/displayio/Display.h | 3 ++- shared-module/displayio/Display.c | 26 +++++++++++++++------- shared-module/displayio/Display.h | 1 + 7 files changed, 35 insertions(+), 16 deletions(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 4f073e270..aa4f96d15 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -94,7 +94,8 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, - true); + true, // init_cs_toggle + false); // single_byte_bounds common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index ce8c42a43..0c55e41e2 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -100,7 +100,8 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, - true); + true, // init_cs_toggle + false); // single_byte_bounds common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 3a306b0b4..14a4dadbe 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -91,7 +91,9 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PB31, - true); + true, // init_cs_toggle + false); // single_byte_bounds + common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 8fed5129f..af2c27149 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -50,7 +50,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, init_cs_toggle=False) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, init_cs_toggle=True, single_byte_bounds=False) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -91,10 +91,11 @@ //| :param int write_ram_command: Command used to write pixels values into the update region //| :param int set_vertical_scroll: Command used to set the first row to show //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight -//| :param bool init_cs_toggle: Toggle the Chip Select between each initialization command. +//| :param bool init_cs_toggle: Toggle the Chip Select between each initialization command +//| :param bool single_byte_bounds: Display column and row commands use single bytes //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_init_cs_toggle }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_init_cs_toggle, ARG_single_byte_bounds }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -110,6 +111,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, { MP_QSTR_init_cs_toggle, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, + { MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -149,7 +151,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a args[ARG_write_ram_command].u_int, args[ARG_set_vertical_scroll].u_int, bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin), - args[ARG_init_cs_toggle].u_bool); + args[ARG_init_cs_toggle].u_bool, + args[ARG_single_byte_bounds].u_bool); return self; } diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 407afe1c3..617686445 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -40,7 +40,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, - uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle); + uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle, + bool single_byte_bounds); int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 8ebe4b543..3936f3b17 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, - const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle) { + const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle, bool single_byte_bounds) { self->color_depth = color_depth; self->set_column_command = set_column_command; self->set_row_command = set_row_command; @@ -55,6 +55,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->rowstart = rowstart; self->auto_brightness = false; self->init_cs_toggle = init_cs_toggle; + self->single_byte_bounds = single_byte_bounds; if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) { self->begin_transaction = common_hal_displayio_parallelbus_begin_transaction; @@ -218,16 +219,25 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) { } void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - // TODO(tannewt): Handle displays with single byte bounds. uint16_t data[2]; self->send(self->bus, true, &self->set_column_command, 1); - data[0] = __builtin_bswap16(x0 + self->colstart); - data[1] = __builtin_bswap16(x1 - 1 + self->colstart); - self->send(self->bus, false, (uint8_t*) data, 4); + if (self->single_byte_bounds) { + data[0] = __builtin_bswap16((x0 + self->colstart) << 8 | (x1 - 1 + self->colstart) && 0xFF); + self->send(self->bus, false, (uint8_t*) data, 2); + } else { + data[0] = __builtin_bswap16(x0 + self->colstart); + data[1] = __builtin_bswap16(x1 - 1 + self->colstart); + self->send(self->bus, false, (uint8_t*) data, 4); + } self->send(self->bus, true, &self->set_row_command, 1); - data[0] = __builtin_bswap16(y0 + self->rowstart); - data[1] = __builtin_bswap16(y1 - 1 + self->rowstart); - self->send(self->bus, false, (uint8_t*) data, 4); + if (self->single_byte_bounds) { + data[0] = __builtin_bswap16((y0 + self->rowstart) << 8 | (y1 - 1 + self->rowstart) && 0xFF); + self->send(self->bus, false, (uint8_t*) data, 2); + } else { + data[0] = __builtin_bswap16(y0 + self->rowstart); + data[1] = __builtin_bswap16(y1 - 1 + self->rowstart); + self->send(self->bus, false, (uint8_t*) data, 4); + } self->send(self->bus, true, &self->write_ram_command, 1); } diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 250f44031..18118bc72 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -51,6 +51,7 @@ typedef struct { int16_t colstart; int16_t rowstart; bool init_cs_toggle; + bool single_byte_bounds; display_bus_begin_transaction begin_transaction; display_bus_send send; display_bus_end_transaction end_transaction; -- cgit v1.2.3 From 81fe8060d76d54a20701e6944dd29cdfab9fed4f Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 20 Mar 2019 19:29:20 +0100 Subject: Properly calculate BPP for displayio.Bitmap Fix #1669 --- locale/ID.po | 12 ++++++------ locale/circuitpython.pot | 12 ++++++------ locale/de_DE.po | 16 ++++++++++------ locale/en_US.po | 12 ++++++------ locale/en_x_pirate.po | 12 ++++++------ locale/es.po | 15 +++++++++------ locale/fil.po | 15 +++++++++------ locale/fr.po | 15 +++++++++------ locale/it_IT.po | 12 ++++++------ locale/pt_BR.po | 12 ++++++------ shared-bindings/displayio/Bitmap.c | 16 ++++++++++++---- 11 files changed, 85 insertions(+), 64 deletions(-) (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 694b2964f..1df86a7d2 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -762,14 +762,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 tidak mendukung pull up" @@ -2838,6 +2834,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() gagal" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 735459a47..645b2e4ad 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -737,14 +737,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "" @@ -2789,6 +2785,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 21fe860eb..87e965914 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -742,14 +742,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 unterstützt pull up nicht" @@ -2851,6 +2847,10 @@ msgstr "nicht unterstützter Typ für Operator" msgid "unsupported types for %q: '%s', '%s'" msgstr "nicht unterstützte Typen für %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() fehlgeschlagen" @@ -2889,5 +2889,9 @@ msgstr "" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Kann den Attributwert nicht lesen. Status: 0x%04x" +#~ msgid "Function requires lock." +#~ msgstr "" +#~ "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" + #~ msgid "Only Windows format, uncompressed BMP supported %d" #~ msgstr "Nur unkomprimiertes Windows-Format (BMP) unterstützt %d" diff --git a/locale/en_US.po b/locale/en_US.po index 2f29498b9..da189c661 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -737,14 +737,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "" @@ -2789,6 +2785,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 0bcef8066..f9bb0f0ff 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -741,14 +741,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "" @@ -2793,6 +2789,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "" diff --git a/locale/es.po b/locale/es.po index efae8c368..9f71ac160 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -767,14 +767,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "La función requiere lock" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "La función requiere lock" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 no soporta pull up." @@ -2874,6 +2870,10 @@ msgstr "tipo de operador no soportado" msgid "unsupported types for %q: '%s', '%s'" msgstr "tipos no soportados para %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() ha fallado" @@ -2916,6 +2916,9 @@ msgstr "paso cero" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "No se puede leer el valor del atributo. status 0x%02x" +#~ msgid "Function requires lock." +#~ msgstr "La función requiere lock" + #~ msgid "Only Windows format, uncompressed BMP supported %d" #~ msgstr "Solo formato Windows, BMP sin comprimir soportado %d" diff --git a/locale/fil.po b/locale/fil.po index 42a1c9e26..230a09597 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -765,14 +765,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Function nangangailangan ng lock" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "Kailangan ng lock ang function." - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "Walang pull down support ang GPI016." @@ -2880,6 +2876,10 @@ msgstr "hindi sinusuportahang type para sa operator" msgid "unsupported types for %q: '%s', '%s'" msgstr "hindi sinusuportahang type para sa %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "nabigo ang wifi_set_ip_info()" @@ -2922,6 +2922,9 @@ msgstr "zero step" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Hindi mabasa ang value ng attribute, status: 0x%08lX" +#~ msgid "Function requires lock." +#~ msgstr "Kailangan ng lock ang function." + #~ msgid "Only Windows format, uncompressed BMP supported %d" #~ msgstr "Tanging Windows format, uncompressed BMP lamang ang supportado %d" diff --git a/locale/fr.po b/locale/fr.po index 1710a5ae9..f9c007825 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -764,14 +764,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "La fonction nécessite un verrou" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "La fonction nécessite un verrou." - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "le GPIO16 ne supporte pas le tirage (pull-up)" @@ -2902,6 +2898,10 @@ msgstr "type non supporté pour l'opérateur" msgid "unsupported types for %q: '%s', '%s'" msgstr "type non supporté pour %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() a échoué" @@ -2945,6 +2945,9 @@ msgstr "'step' nul" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Impossible de lire la valeur de l'attribut. status: 0x%08lX" +#~ msgid "Function requires lock." +#~ msgstr "La fonction nécessite un verrou." + #~ msgid "Only Windows format, uncompressed BMP supported %d" #~ msgstr "Seul les BMP non-compressé au format Windows sont supportés %d" diff --git a/locale/it_IT.po b/locale/it_IT.po index 758307ff3..693f8a03c 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -764,14 +764,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 non supporta pull-up" @@ -2876,6 +2872,10 @@ msgstr "tipo non supportato per l'operando" msgid "unsupported types for %q: '%s', '%s'" msgstr "tipi non supportati per %q: '%s', '%s'" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() faillito" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 5d00b4e03..587ed00ba 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 14:08+0100\n" +"POT-Creation-Date: 2019-03-25 19:40+0100\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -757,14 +757,10 @@ msgid "Frequency captured is above capability. Capture Paused." msgstr "" #: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" -#: shared-bindings/busio/I2C.c -msgid "Function requires lock." -msgstr "" - #: ports/esp8266/common-hal/digitalio/DigitalInOut.c msgid "GPIO16 does not support pull up." msgstr "GPIO16 não suporta pull up." @@ -2826,6 +2822,10 @@ msgstr "" msgid "unsupported types for %q: '%s', '%s'" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" +msgstr "" + #: ports/esp8266/modnetwork.c msgid "wifi_set_ip_info() failed" msgstr "wifi_set_ip_info() falhou" diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 3612b8d63..91c17f2d1 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -58,14 +58,22 @@ STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_ar uint32_t width = mp_obj_get_int(pos_args[0]); uint32_t height = mp_obj_get_int(pos_args[1]); uint32_t value_count = mp_obj_get_int(pos_args[2]); - uint32_t power_of_two = 1; - while (value_count > (1U << power_of_two)) { - power_of_two <<= 1; + uint32_t bits = 1; + + if (value_count == 0) { + mp_raise_ValueError(translate("value_count must be > 0")); + } + while ((value_count - 1) >> bits) { + if (bits < 8) { + bits <<= 1; + } else { + bits += 8; + } } displayio_bitmap_t *self = m_new_obj(displayio_bitmap_t); self->base.type = &displayio_bitmap_type; - common_hal_displayio_bitmap_construct(self, width, height, power_of_two); + common_hal_displayio_bitmap_construct(self, width, height, bits); return MP_OBJ_FROM_PTR(self); } -- cgit v1.2.3 From d553df95b0e597d4c275f33061b71d2d3168ece9 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Mon, 25 Mar 2019 21:09:15 +0100 Subject: Reuse "Not connected" message in bleio --- shared-bindings/bleio/CharacteristicBuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index 66d164954..c368de361 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -144,7 +144,7 @@ STATIC mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t r raise_error_if_deinited(common_hal_bleio_characteristic_buffer_deinited(self)); raise_error_if_not_connected(self); if (!common_hal_bleio_characteristic_buffer_connected(self)) { - mp_raise_ValueError(translate("Not connected.")); + mp_raise_ValueError(translate("Not connected")); } mp_uint_t ret; if (request == MP_IOCTL_POLL) { -- cgit v1.2.3 From b2ad16f5c84cd4dc853114e5fc526ab1827580a4 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 26 Mar 2019 18:34:07 -0700 Subject: Removed parameter so CS is always toggled --- ports/atmel-samd/boards/hallowing_m0_express/board.c | 3 +-- ports/atmel-samd/boards/pybadge/board.c | 3 +-- ports/atmel-samd/boards/pyportal/board.c | 3 +-- shared-bindings/displayio/Display.c | 6 ++---- shared-bindings/displayio/Display.h | 2 +- shared-module/displayio/Display.c | 5 ++--- shared-module/displayio/Display.h | 1 - 7 files changed, 8 insertions(+), 15 deletions(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 4f073e270..23b119413 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -93,8 +93,7 @@ void board_init(void) { 0x37, // set vertical scroll command display_init_sequence, sizeof(display_init_sequence), - &pin_PA00, - true); + &pin_PA00); common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index ce8c42a43..0881d8f45 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -99,8 +99,7 @@ void board_init(void) { 0x37, // set vertical scroll command display_init_sequence, sizeof(display_init_sequence), - &pin_PA00, - true); + &pin_PA00); common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 3a306b0b4..d2c328850 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -90,8 +90,7 @@ void board_init(void) { 0x37, // Set vertical scroll command display_init_sequence, sizeof(display_init_sequence), - &pin_PB31, - true); + &pin_PB31); common_hal_displayio_display_set_auto_brightness(display, true); } diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 9cefb9532..ddca9ffd8 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -94,7 +94,7 @@ //| :param bool init_cs_toggle: Toggle the Chip Select between each initialization command //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_init_cs_toggle }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -109,7 +109,6 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, - { MP_QSTR_init_cs_toggle, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -148,8 +147,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, args[ARG_write_ram_command].u_int, args[ARG_set_vertical_scroll].u_int, - bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin), - args[ARG_init_cs_toggle].u_bool); + bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin)); return self; } diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 407afe1c3..7d6444a2d 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -40,7 +40,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, - uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle); + uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin); int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index bbc23b7b0..c693d3c90 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, - const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle) { + const mcu_pin_obj_t* backlight_pin) { self->color_depth = color_depth; self->set_column_command = set_column_command; self->set_row_command = set_row_command; @@ -54,7 +54,6 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->colstart = colstart; self->rowstart = rowstart; self->auto_brightness = false; - self->init_cs_toggle = init_cs_toggle; if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) { self->begin_transaction = common_hal_displayio_parallelbus_begin_transaction; @@ -83,7 +82,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, bool delay = (data_size & DELAY) != 0; data_size &= ~DELAY; uint8_t *data = cmd + 2; - if (self->init_cs_toggle && self->set_cs != NULL) { + if (self->set_cs != NULL) { self->set_cs(self->bus, true); common_hal_time_delay_ms(1); self->set_cs(self->bus, false); diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 250f44031..70308daa2 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -50,7 +50,6 @@ typedef struct { uint64_t last_refresh; int16_t colstart; int16_t rowstart; - bool init_cs_toggle; display_bus_begin_transaction begin_transaction; display_bus_send send; display_bus_end_transaction end_transaction; -- cgit v1.2.3 From 2f7b338a4b87bc04166b021c48eca1fd5732e16a Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 26 Mar 2019 18:56:25 -0700 Subject: Comment Cleanup --- shared-bindings/displayio/Display.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index ddca9ffd8..1f46330e8 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -50,7 +50,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, init_cs_toggle=True) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -91,7 +91,6 @@ //| :param int write_ram_command: Command used to write pixels values into the update region //| :param int set_vertical_scroll: Command used to set the first row to show //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight -//| :param bool init_cs_toggle: Toggle the Chip Select between each initialization command //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin }; -- cgit v1.2.3 From b09d2c3c625340476aad6f8ce7be1f6426ff2594 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Thu, 7 Feb 2019 23:50:14 +1100 Subject: enable NRFX RTC adafruit/circuitpython#1046 --- ports/nrf/Makefile | 1 + ports/nrf/common-hal/rtc/RTC.c | 28 ++++++++++++++++++++++++---- ports/nrf/nrfx_config.h | 3 +++ shared-bindings/rtc/RTC.c | 2 ++ 4 files changed, 30 insertions(+), 4 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 3681ac49e..3cb4b52aa 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -140,6 +140,7 @@ SRC_NRFX = $(addprefix nrfx/,\ drivers/src/nrfx_twim.c \ drivers/src/nrfx_uarte.c \ drivers/src/nrfx_gpiote.c \ + drivers/src/nrfx_rtc.c \ ) ifdef EXTERNAL_FLASH_DEVICES diff --git a/ports/nrf/common-hal/rtc/RTC.c b/ports/nrf/common-hal/rtc/RTC.c index 7690b3bd3..85cdb4c37 100644 --- a/ports/nrf/common-hal/rtc/RTC.c +++ b/ports/nrf/common-hal/rtc/RTC.c @@ -33,24 +33,44 @@ #include "supervisor/shared/translate.h" #include "nrfx_rtc.h" +#include "nrf_clock.h" -static uint32_t _rtc_seconds = 0; +#define RTC_CLOCK_HZ (8) -void rtc_handler(nrfx_rtc_int_type_t int_type) { +static uint32_t rtc_offset = 0; + +const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(0); +const nrfx_rtc_config_t rtc_config = { + .prescaler = RTC_FREQ_TO_PRESCALER(RTC_CLOCK_HZ), + .reliable = 0, + .tick_latency = 0, + .interrupt_priority = 6 +}; + +void rtc_handler(nrfx_rtc_int_type_t int_type) { + // do nothing } void rtc_init(void) { + if (!nrf_clock_lf_is_running()) { + nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART); + } + nrfx_rtc_counter_clear(&rtc_instance); + nrfx_rtc_init(&rtc_instance, &rtc_config, rtc_handler); + nrfx_rtc_enable(&rtc_instance); } void common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - timeutils_seconds_since_2000_to_struct_time(_rtc_seconds, tm); + uint32_t t = rtc_offset + (nrfx_rtc_counter_get(&rtc_instance) / RTC_CLOCK_HZ ); + timeutils_seconds_since_2000_to_struct_time(t, tm); } void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - _rtc_seconds = timeutils_seconds_since_2000( + rtc_offset = timeutils_seconds_since_2000( tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec ); + nrfx_rtc_counter_clear(&rtc_instance); } // A positive value speeds up the clock by removing clock cycles. diff --git a/ports/nrf/nrfx_config.h b/ports/nrf/nrfx_config.h index 57a2727aa..b8a0a7f60 100644 --- a/ports/nrf/nrfx_config.h +++ b/ports/nrf/nrfx_config.h @@ -70,6 +70,9 @@ #define NRFX_PWM3_ENABLED 0 #endif +#define NRFX_RTC_ENABLED 1 +#define NRFX_RTC0_ENABLED 1 + // TIMERS #define NRFX_TIMER_ENABLED 1 // Don't enable TIMER0: it's used by the SoftDevice. diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index 474d4a399..97265d601 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -36,6 +36,7 @@ #include "shared-bindings/time/__init__.h" #include "supervisor/shared/translate.h" +/* void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) { mp_raise_NotImplementedError(translate("RTC is not supported on this board")); } @@ -51,6 +52,7 @@ int MP_WEAK common_hal_rtc_get_calibration(void) { void MP_WEAK common_hal_rtc_set_calibration(int calibration) { mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); } +*/ const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; -- cgit v1.2.3 From ff6395fa4eaf531abdf68719663895f4f2bf1870 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Tue, 12 Feb 2019 13:09:39 +1100 Subject: workaround for problem with adafruit/circuitpython#1046 the __weak linking works fine so long as these functions are not identical. I have not yet worked out why. --- shared-bindings/rtc/RTC.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index 97265d601..7c85f328c 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -36,13 +36,12 @@ #include "shared-bindings/time/__init__.h" #include "supervisor/shared/translate.h" -/* void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError(translate("RTC is not supported on this board")); + mp_raise_NotImplementedError(translate("RTC get is not supported on this board")); } void MP_WEAK common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError(translate("RTC is not supported on this board")); + mp_raise_NotImplementedError(translate("RTC set is not supported on this board")); } int MP_WEAK common_hal_rtc_get_calibration(void) { @@ -52,7 +51,7 @@ int MP_WEAK common_hal_rtc_get_calibration(void) { void MP_WEAK common_hal_rtc_set_calibration(int calibration) { mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); } -*/ + const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; -- cgit v1.2.3 From 93684737eb9a85aca1972ed53f5ec908c51e2401 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Sat, 2 Mar 2019 22:19:47 +1100 Subject: Fix up messages & wild stab at translations for adafruit/circuitpython#1046 The mysterious MP_WEAK linking bug still exists, thus the new message for 'set'. --- locale/ID.po | 3 + locale/circuitpython.pot | 2606 +++++--------------------------------------- locale/de_DE.po | 5 +- locale/en_US.po | 5 +- locale/en_x_pirate.po | 2642 ++++++--------------------------------------- locale/es.po | 5 +- locale/fil.po | 5 +- locale/fr.po | 3 + locale/it_IT.po | 5 +- locale/pt_BR.po | 5 +- shared-bindings/rtc/RTC.c | 2 +- 11 files changed, 614 insertions(+), 4672 deletions(-) (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 1df86a7d2..63b121bcd 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -1136,6 +1136,9 @@ msgstr "" msgid "RTC is not supported on this board" msgstr "" +msgid "RTC set is not supported on this board" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 645b2e4ad..c6bd8f4b1 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 19:40+0100\n" +"POT-Creation-Date: 2019-03-28 09:50+1100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -23,37 +23,16 @@ msgid "" "Code done running. Waiting for reload.\n" msgstr "" -#: py/obj.c -msgid " File \"%q\"" -msgstr "" - -#: py/obj.c -msgid " File \"%q\", line %d" -msgstr "" - #: main.c msgid " output:\n" msgstr "" -#: py/objstr.c -#, c-format -msgid "%%c requires int or char" -msgstr "" - #: shared-bindings/microcontroller/Pin.c msgid "%q in use" msgstr "" -#: py/obj.c -msgid "%q index out of range" -msgstr "" - -#: py/obj.c -msgid "%q indices must be integers, not %s" -msgstr "" - -#: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c #: shared-bindings/bleio/CharacteristicBuffer.c +#: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c msgid "%q must be >= 1" msgstr "" @@ -61,166 +40,10 @@ msgstr "" msgid "%q should be an int" msgstr "" -#: py/objnamedtuple.c py/bc.c -msgid "%q() takes %d positional arguments but %d were given" -msgstr "" - -#: py/argcheck.c -msgid "'%q' argument required" -msgstr "" - -#: py/emitinlinextensa.c py/emitinlinethumb.c -#, c-format -msgid "'%s' expects a label" -msgstr "" - -#: py/emitinlinextensa.c py/emitinlinethumb.c -#, c-format -msgid "'%s' expects a register" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects a special register" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects an FPU register" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects an address of the form [a, b]" -msgstr "" - -#: py/emitinlinextensa.c py/emitinlinethumb.c -#, c-format -msgid "'%s' expects an integer" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects at most r%d" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects {r0, r1, ...}" -msgstr "" - -#: py/emitinlinextensa.c -#, c-format -msgid "'%s' integer %d is not within range %d..%d" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' integer 0x%x does not fit in mask 0x%x" -msgstr "" - -#: py/obj.c -#, c-format -msgid "'%s' object does not support item assignment" -msgstr "" - -#: py/obj.c -#, c-format -msgid "'%s' object does not support item deletion" -msgstr "" - -#: py/runtime.c -msgid "'%s' object has no attribute '%q'" -msgstr "" - -#: py/runtime.c -#, c-format -msgid "'%s' object is not an iterator" -msgstr "" - -#: py/objtype.c py/runtime.c -#, c-format -msgid "'%s' object is not callable" -msgstr "" - -#: py/runtime.c -#, c-format -msgid "'%s' object is not iterable" -msgstr "" - -#: py/obj.c -#, c-format -msgid "'%s' object is not subscriptable" -msgstr "" - -#: py/objstr.c -msgid "'=' alignment not allowed in string format specifier" -msgstr "" - #: shared-module/struct/__init__.c msgid "'S' and 'O' are not supported format types" msgstr "" -#: py/compile.c -msgid "'align' requires 1 argument" -msgstr "" - -#: py/compile.c -msgid "'await' outside function" -msgstr "" - -#: py/compile.c -msgid "'break' outside loop" -msgstr "" - -#: py/compile.c -msgid "'continue' outside loop" -msgstr "" - -#: py/compile.c -msgid "'data' requires at least 2 arguments" -msgstr "" - -#: py/compile.c -msgid "'data' requires integer arguments" -msgstr "" - -#: py/compile.c -msgid "'label' requires 1 argument" -msgstr "" - -#: py/compile.c -msgid "'return' outside function" -msgstr "" - -#: py/compile.c -msgid "'yield' outside function" -msgstr "" - -#: py/compile.c -msgid "*x must be assignment target" -msgstr "" - -#: py/obj.c -msgid ", in %q\n" -msgstr "" - -#: py/objcomplex.c -msgid "0.0 to a complex power" -msgstr "" - -#: py/modbuiltins.c -msgid "3-arg pow() not supported" -msgstr "" - -#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c -msgid "A hardware interrupt channel is already in use" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "AP required" -msgstr "" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address is not %d bytes long or is in wrong format" @@ -231,54 +54,14 @@ msgstr "" msgid "Address must be %d bytes long" msgstr "" -#: ports/nrf/common-hal/busio/I2C.c -msgid "All I2C peripherals are in use" -msgstr "" - -#: ports/nrf/common-hal/busio/SPI.c -msgid "All SPI peripherals are in use" -msgstr "" - -#: ports/nrf/common-hal/busio/UART.c -msgid "All UART peripherals are in use" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "All event channels in use" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c -msgid "All sync event channels in use" -msgstr "" - #: shared-bindings/pulseio/PWMOut.c msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -#: ports/atmel-samd/common-hal/pulseio/PulseOut.c -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -#: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c -#: shared-module/_pew/PewPew.c +#: shared-bindings/pulseio/PWMOut.c shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "" -#: ports/nrf/common-hal/analogio/AnalogOut.c -msgid "AnalogOut functionality not supported" -msgstr "" - -#: shared-bindings/analogio/AnalogOut.c -msgid "AnalogOut is only 16 bits. Value must be less than 65536." -msgstr "" - -#: ports/atmel-samd/common-hal/analogio/AnalogOut.c -msgid "AnalogOut not supported on given pin" -msgstr "" - -#: ports/atmel-samd/common-hal/pulseio/PulseOut.c -msgid "Another send is already active" -msgstr "" - #: shared-bindings/pulseio/PulseOut.c msgid "Array must contain halfwords (type 'H')" msgstr "" @@ -301,18 +84,6 @@ msgid "" "disable.\n" msgstr "" -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -msgid "Bit clock and word select must share a clock unit" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "Bit depth must be multiple of 8." -msgstr "" - -#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c -msgid "Both pins must support hardware interrupts" -msgstr "" - #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -330,12 +101,6 @@ msgstr "" msgid "Buffer must be at least length 1" msgstr "" -#: ports/atmel-samd/common-hal/displayio/ParallelBus.c -#: ports/nrf/common-hal/displayio/ParallelBus.c -#, c-format -msgid "Bus pin %d is already in use" -msgstr "" - #: shared-bindings/bleio/UUID.c msgid "Byte buffer must be 16 bytes." msgstr "" @@ -344,15 +109,6 @@ msgstr "" msgid "Bytes must be between 0 and 255." msgstr "" -#: ports/esp8266/esp_mphal.c -msgid "C-level assert" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -#, c-format -msgid "Can not use dotstar with %s" -msgstr "" - #: shared-bindings/bleio/Device.c msgid "Can't add services in Central mode" msgstr "" @@ -369,72 +125,26 @@ msgstr "" msgid "Can't connect in Peripheral mode" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "Cannot connect to AP" -msgstr "" - #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "Cannot disconnect from AP" -msgstr "" - -#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c -#: ports/nrf/common-hal/digitalio/DigitalInOut.c -msgid "Cannot get pull while in output mode" -msgstr "" - -#: ports/nrf/common-hal/microcontroller/Processor.c -msgid "Cannot get temperature" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Cannot output both channels on the same pin" -msgstr "" - #: shared-module/bitbangio/SPI.c msgid "Cannot read without MISO pin." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "Cannot record to a file" -msgstr "" - #: shared-module/storage/__init__.c msgid "Cannot remount '/' when USB is active." msgstr "" -#: ports/atmel-samd/common-hal/microcontroller/__init__.c -#: ports/esp8266/common-hal/microcontroller/__init__.c -msgid "Cannot reset into bootloader because no bootloader is present." -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "Cannot set STA config" -msgstr "" - #: shared-bindings/digitalio/DigitalInOut.c msgid "Cannot set value when direction is input." msgstr "" -#: py/objslice.c -msgid "Cannot subclass slice" -msgstr "" - #: shared-module/bitbangio/SPI.c msgid "Cannot transfer without MOSI and MISO pins." msgstr "" -#: extmod/moductypes.c -msgid "Cannot unambiguously get sizeof scalar" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "Cannot update i/f status" -msgstr "" - #: shared-module/bitbangio/SPI.c msgid "Cannot write without MOSI pin." msgstr "" @@ -443,10 +153,6 @@ msgstr "" msgid "Characteristic UUID doesn't match Service UUID" msgstr "" -#: ports/nrf/common-hal/bleio/Service.c -msgid "Characteristic already in use by another Service." -msgstr "" - #: shared-bindings/bleio/CharacteristicBuffer.c msgid "CharacteristicBuffer writing not provided" msgstr "" @@ -459,27 +165,14 @@ msgstr "" msgid "Clock stretch too long" msgstr "" -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -msgid "Clock unit in use" -msgstr "" - #: shared-bindings/_pew/PewPew.c msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Command must be an int between 0 and 255" msgstr "" -#: ports/nrf/common-hal/bleio/UUID.c -#, c-format -msgid "Could not decode ble_uuid, err 0x%04x" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/UART.c -msgid "Could not initialize UART" -msgstr "" - #: shared-module/audioio/Mixer.c shared-module/audioio/WaveFile.c msgid "Couldn't allocate first buffer" msgstr "" @@ -492,67 +185,21 @@ msgstr "" msgid "Crash into the HardFault_Handler.\n" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "DAC already in use" -msgstr "" - -#: ports/atmel-samd/common-hal/displayio/ParallelBus.c -#: ports/nrf/common-hal/displayio/ParallelBus.c -msgid "Data 0 pin must be byte aligned" -msgstr "" - #: shared-module/audioio/WaveFile.c msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -#: ports/nrf/common-hal/bleio/Peripheral.c -msgid "Data too large for advertisement packet" -msgstr "" - -#: ports/nrf/common-hal/bleio/Device.c -msgid "Data too large for the advertisement packet" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "Destination capacity is smaller than destination_length." -msgstr "" - #: shared-bindings/displayio/Display.c msgid "Display rotation must be in 90 degree increments" msgstr "" -#: ports/unix/modffi.c -msgid "Don't know how to pass object to native function" -msgstr "" - #: shared-bindings/digitalio/DigitalInOut.c msgid "Drive mode not used when direction is input." msgstr "" -#: ports/esp8266/common-hal/microcontroller/__init__.c -msgid "ESP8226 does not support safe mode." -msgstr "" - -#: ports/esp8266/common-hal/digitalio/DigitalInOut.c -msgid "ESP8266 does not support pull down." -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -msgid "EXTINT channel already in use" -msgstr "" - -#: ports/unix/modffi.c -msgid "Error in ffi_prep_cif" -msgstr "" - -#: extmod/modure.c -msgid "Error in regex" -msgstr "" - -#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c -#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c +#: shared-bindings/microcontroller/Pin.c +#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -560,8 +207,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Characteristic.c +#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c msgid "Expected a UUID" msgstr "" @@ -570,440 +217,117 @@ msgstr "" msgid "Expected tuple of length %d, got %d" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to acquire mutex" +#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c +msgid "Function requires lock" msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c -#, c-format -msgid "Failed to acquire mutex, err 0x%04x" +#: shared-module/displayio/Group.c +msgid "Group full" msgstr "" -#: ports/nrf/common-hal/bleio/Service.c -#, c-format -msgid "Failed to add characteristic, err 0x%04x" +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to add service" +#: shared-module/displayio/OnDiskBitmap.c +msgid "Invalid BMP file" msgstr "" -#: ports/nrf/common-hal/bleio/Peripheral.c -#, c-format -msgid "Failed to add service, err 0x%04x" +#: shared-bindings/pulseio/PWMOut.c +msgid "Invalid PWM frequency" msgstr "" -#: ports/atmel-samd/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c -msgid "Failed to allocate RX buffer" +#: shared-bindings/digitalio/DigitalInOut.c +msgid "Invalid direction." msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -#: ports/nrf/common-hal/pulseio/PulseIn.c -#: ports/esp8266/common-hal/pulseio/PulseIn.c -#, c-format -msgid "Failed to allocate RX buffer of %d bytes" +#: shared-module/audioio/WaveFile.c +msgid "Invalid file" msgstr "" -#: ports/nrf/common-hal/bleio/Adapter.c -msgid "Failed to change softdevice state" +#: shared-module/audioio/WaveFile.c +msgid "Invalid format chunk size" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to connect:" +#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +msgid "Invalid number of bits" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to continue scanning" +#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +msgid "Invalid phase" msgstr "" -#: ports/nrf/common-hal/bleio/Scanner.c -#, c-format -msgid "Failed to continue scanning, err 0x%04x" +#: shared-bindings/pulseio/PWMOut.c +msgid "Invalid pin" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to create mutex" +#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +msgid "Invalid polarity" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to discover services" +#: shared-bindings/microcontroller/__init__.c +msgid "Invalid run mode." msgstr "" -#: ports/nrf/common-hal/bleio/Adapter.c -msgid "Failed to get local address" +#: shared-module/audioio/WaveFile.c +msgid "Invalid wave file" msgstr "" -#: ports/nrf/common-hal/bleio/Adapter.c -msgid "Failed to get softdevice state" +#: shared-module/displayio/Group.c +msgid "Layer must be a Group or TileGrid subclass." msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to notify or indicate attribute value, err 0x%04x" +#: supervisor/shared/safe_mode.c +msgid "" +"Looks like our core CircuitPython code crashed hard. Whoops!\n" +"Please file an issue at https://github.com/adafruit/circuitpython/issues\n" +" with the contents of your CIRCUITPY drive and this message:\n" msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to read CCCD value, err 0x%04x" +#: shared-module/bitbangio/SPI.c +msgid "MISO pin init failed." msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to read attribute value, err 0x%04x" +#: shared-module/bitbangio/SPI.c +msgid "MOSI pin init failed." msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c +#: shared-module/displayio/Shape.c #, c-format -msgid "Failed to read gatts value, err 0x%04x" +msgid "Maximum x value when mirrored is %d" msgstr "" -#: ports/nrf/common-hal/bleio/UUID.c -#, c-format -msgid "Failed to register Vendor-Specific UUID, err 0x%04x" +#: supervisor/shared/safe_mode.c +msgid "MicroPython NLR jump failed. Likely memory corruption.\n" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to release mutex" +#: supervisor/shared/safe_mode.c +msgid "MicroPython fatal error.\n" msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c -#, c-format -msgid "Failed to release mutex, err 0x%04x" +#: shared-bindings/displayio/Display.c +msgid "Must be a Group subclass." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to start advertising" +#: supervisor/shared/board_busses.c +msgid "No default I2C bus" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -#: ports/nrf/common-hal/bleio/Peripheral.c -#, c-format -msgid "Failed to start advertising, err 0x%04x" +#: supervisor/shared/board_busses.c +msgid "No default SPI bus" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to start scanning" +#: supervisor/shared/board_busses.c +msgid "No default UART bus" msgstr "" -#: ports/nrf/common-hal/bleio/Scanner.c -#, c-format -msgid "Failed to start scanning, err 0x%04x" +#: shared-bindings/os/__init__.c +msgid "No hardware random available" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to stop advertising" -msgstr "" - -#: ports/nrf/common-hal/bleio/Broadcaster.c -#: ports/nrf/common-hal/bleio/Peripheral.c -#, c-format -msgid "Failed to stop advertising, err 0x%04x" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to write attribute value, err 0x%04x" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to write gatts value, err 0x%04x" -msgstr "" - -#: py/moduerrno.c -msgid "File exists" -msgstr "" - -#: ports/nrf/supervisor/internal_flash.c -msgid "Flash erase failed" -msgstr "" - -#: ports/nrf/supervisor/internal_flash.c -#, c-format -msgid "Flash erase failed to start, err 0x%04x" -msgstr "" - -#: ports/nrf/supervisor/internal_flash.c -msgid "Flash write failed" -msgstr "" - -#: ports/nrf/supervisor/internal_flash.c -#, c-format -msgid "Flash write failed to start, err 0x%04x" -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -msgid "Frequency captured is above capability. Capture Paused." -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c -msgid "Function requires lock" -msgstr "" - -#: ports/esp8266/common-hal/digitalio/DigitalInOut.c -msgid "GPIO16 does not support pull up." -msgstr "" - -#: shared-module/displayio/Group.c -msgid "Group full" -msgstr "" - -#: ports/unix/file.c extmod/vfs_posix_file.c py/objstringio.c -msgid "I/O operation on closed file" -msgstr "" - -#: extmod/machine_i2c.c -msgid "I2C operation not supported" -msgstr "" - -#: py/persistentcode.c -msgid "" -"Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/" -"mpy-update for more info." -msgstr "" - -#: shared-bindings/_pew/PewPew.c -msgid "Incorrect buffer size" -msgstr "" - -#: py/moduerrno.c -msgid "Input/output error" -msgstr "" - -#: shared-module/displayio/OnDiskBitmap.c -msgid "Invalid BMP file" -msgstr "" - -#: ports/atmel-samd/common-hal/pulseio/PWMOut.c -#: ports/nrf/common-hal/pulseio/PWMOut.c shared-bindings/pulseio/PWMOut.c -msgid "Invalid PWM frequency" -msgstr "" - -#: py/moduerrno.c -msgid "Invalid argument" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -msgid "Invalid bit clock pin" -msgstr "" - -#: ports/nrf/common-hal/busio/UART.c -msgid "Invalid buffer size" -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -msgid "Invalid capture period. Valid range: 1 - 500" -msgstr "" - -#: shared-bindings/audioio/Mixer.c -msgid "Invalid channel count" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Invalid clock pin" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Invalid data pin" -msgstr "" - -#: shared-bindings/digitalio/DigitalInOut.c -msgid "Invalid direction." -msgstr "" - -#: shared-module/audioio/WaveFile.c -msgid "Invalid file" -msgstr "" - -#: shared-module/audioio/WaveFile.c -msgid "Invalid format chunk size" -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c -msgid "Invalid number of bits" -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c -msgid "Invalid phase" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -#: ports/atmel-samd/common-hal/touchio/TouchIn.c -#: shared-bindings/pulseio/PWMOut.c -msgid "Invalid pin" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Invalid pin for left channel" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Invalid pin for right channel" -msgstr "" - -#: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/atmel-samd/common-hal/busio/UART.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c -msgid "Invalid pins" -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c -msgid "Invalid polarity" -msgstr "" - -#: shared-bindings/microcontroller/__init__.c -msgid "Invalid run mode." -msgstr "" - -#: shared-bindings/audioio/Mixer.c -msgid "Invalid voice count" -msgstr "" - -#: shared-module/audioio/WaveFile.c -msgid "Invalid wave file" -msgstr "" - -#: py/compile.c -msgid "LHS of keyword arg must be an id" -msgstr "" - -#: shared-module/displayio/Group.c -msgid "Layer must be a Group or TileGrid subclass." -msgstr "" - -#: py/objslice.c -msgid "Length must be an int" -msgstr "" - -#: py/objslice.c -msgid "Length must be non-negative" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"Looks like our core CircuitPython code crashed hard. Whoops!\n" -"Please file an issue at https://github.com/adafruit/circuitpython/issues\n" -" with the contents of your CIRCUITPY drive and this message:\n" -msgstr "" - -#: shared-module/bitbangio/SPI.c -msgid "MISO pin init failed." -msgstr "" - -#: shared-module/bitbangio/SPI.c -msgid "MOSI pin init failed." -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PWMOut.c -#, c-format -msgid "Maximum PWM frequency is %dhz." -msgstr "" - -#: shared-module/displayio/Shape.c -#, c-format -msgid "Maximum x value when mirrored is %d" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption.\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error.\n" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "Microphone startup delay must be in range 0.0 to 1.0" -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PWMOut.c -msgid "Minimum PWM frequency is 1hz." -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PWMOut.c -#, c-format -msgid "Multiple PWM frequencies not supported. PWM already set to %dhz." -msgstr "" - -#: shared-bindings/displayio/Display.c -msgid "Must be a Group subclass." -msgstr "" - -#: ports/atmel-samd/common-hal/analogio/AnalogOut.c -msgid "No DAC on chip" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "No DMA channel found" -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PulseIn.c -msgid "No PulseIn support for %q" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c -msgid "No RX pin" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c -msgid "No TX pin" -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -msgid "No available clocks" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "" - -#: ports/atmel-samd/common-hal/touchio/TouchIn.c -msgid "No free GCLKs" -msgstr "" - -#: shared-bindings/os/__init__.c -msgid "No hardware random available" -msgstr "" - -#: ports/esp8266/common-hal/analogio/AnalogOut.c -msgid "No hardware support for analog out." -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -msgid "No hardware support on pin" -msgstr "" - -#: py/moduerrno.c -msgid "No space left on device" -msgstr "" - -#: py/moduerrno.c -msgid "No such file/directory" -msgstr "" - -#: shared-bindings/bleio/CharacteristicBuffer.c -msgid "Not connected" -msgstr "" - -#: shared-bindings/bleio/CharacteristicBuffer.c -msgid "Not connected." -msgstr "" - -#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audioio/AudioOut.c -msgid "Not playing" +#: shared-bindings/bleio/CharacteristicBuffer.c +msgid "Not connected" msgstr "" #: shared-bindings/util.c @@ -1011,14 +335,6 @@ msgid "" "Object has been deinitialized and can no longer be used. Create a new object." msgstr "" -#: ports/nrf/common-hal/busio/UART.c -msgid "Odd parity is not supported" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Only 8 or 16 bit mono with " -msgstr "" - #: shared-module/displayio/OnDiskBitmap.c #, c-format msgid "" @@ -1032,1777 +348,403 @@ msgstr "" #: shared-module/displayio/OnDiskBitmap.c #, c-format msgid "" -"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " -"given" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "Only slices with step=1 (aka None) are supported" -msgstr "" - -#: ports/esp8266/common-hal/busio/UART.c -msgid "Only tx supported on UART1 (GPIO2)." -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "Oversample must be multiple of 8." -msgstr "" - -#: shared-bindings/pulseio/PWMOut.c -msgid "" -"PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)" -msgstr "" - -#: shared-bindings/pulseio/PWMOut.c -msgid "" -"PWM frequency not writable when variable_frequency is False on construction." -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PWMOut.c ports/esp8266/machine_pwm.c -#, c-format -msgid "PWM not supported on pin %d" -msgstr "" - -#: py/moduerrno.c -msgid "Permission denied" -msgstr "" - -#: ports/esp8266/common-hal/analogio/AnalogIn.c -msgid "Pin %q does not have ADC capabilities" -msgstr "" - -#: ports/atmel-samd/common-hal/analogio/AnalogIn.c -#: ports/nrf/common-hal/analogio/AnalogIn.c -msgid "Pin does not have ADC capabilities" -msgstr "" - -#: ports/esp8266/machine_pin.c -msgid "Pin(16) doesn't support pull" -msgstr "" - -#: ports/esp8266/common-hal/busio/SPI.c -msgid "Pins not valid for SPI" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "Pixel beyond bounds of buffer" -msgstr "" - -#: py/builtinhelp.c -msgid "Plus any modules on the filesystem\n" -msgstr "" - -#: main.c -msgid "Press any key to enter the REPL. Use CTRL-D to reload." -msgstr "" - -#: shared-bindings/digitalio/DigitalInOut.c -msgid "Pull not used when direction is output." -msgstr "" - -#: shared-bindings/rtc/RTC.c -msgid "RTC calibration is not supported on this board" -msgstr "" - -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c -msgid "RTC is not supported on this board" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "Range out of bounds" -msgstr "" - -#: shared-bindings/pulseio/PulseIn.c -msgid "Read-only" -msgstr "" - -#: extmod/vfs_fat.c py/moduerrno.c -msgid "Read-only filesystem" -msgstr "" - -#: shared-module/displayio/Bitmap.c -msgid "Read-only object" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Right channel unsupported" -msgstr "" - -#: shared-bindings/_pew/PewPew.c -msgid "Row entry must be digitalio.DigitalInOut" -msgstr "" - -#: main.c -msgid "Running in safe mode! Auto-reload is off.\n" -msgstr "" - -#: main.c -msgid "Running in safe mode! Not running saved code.\n" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/I2C.c -msgid "SDA or SCL needs a pull up" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "STA must be active" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "STA required" -msgstr "" - -#: shared-bindings/audioio/Mixer.c -msgid "Sample rate must be positive" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -#, c-format -msgid "Sample rate too high. It must be less than %d" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Serializer in use" -msgstr "" - -#: shared-bindings/nvm/ByteArray.c -msgid "Slice and value different lengths." -msgstr "" - -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c -msgid "Slices not supported" -msgstr "" - -#: ports/nrf/common-hal/bleio/Adapter.c -#, c-format -msgid "Soft device assert, id: 0x%08lX, pc: 0x%08lX" -msgstr "" - -#: extmod/modure.c -msgid "Splitting with sub-captures" -msgstr "" - -#: shared-bindings/supervisor/__init__.c -msgid "Stack size must be at least 256" -msgstr "" - -#: shared-bindings/multiterminal/__init__.c -msgid "Stream missing readinto() or write() method." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"The CircuitPython heap was corrupted because the stack was too small.\n" -"Please increase stack size limits and press reset (after ejecting " -"CIRCUITPY).\n" -"If you didn't change the stack, then file an issue here with the contents of " -"your CIRCUITPY drive:\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"The microcontroller's power dipped. Please make sure your power supply " -"provides\n" -"enough power for the whole circuit and press reset (after ejecting " -"CIRCUITPY).\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"The reset button was pressed while booting CircuitPython. Press again to " -"exit safe mode.\n" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "The sample's signedness does not match the mixer's" -msgstr "" - -#: shared-bindings/displayio/TileGrid.c -msgid "Tile height must exactly divide bitmap height" -msgstr "" - -#: shared-bindings/displayio/TileGrid.c -msgid "Tile indices must be 0 - 255" -msgstr "" - -#: shared-bindings/displayio/TileGrid.c -msgid "Tile width must exactly divide bitmap width" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "To exit, please reset the board without " -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -msgid "Too many channels in sample." -msgstr "" - -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c -msgid "Too many display busses" -msgstr "" - -#: shared-bindings/displayio/Display.c -msgid "Too many displays" -msgstr "" - -#: py/obj.c -msgid "Traceback (most recent call last):\n" -msgstr "" - -#: shared-bindings/time/__init__.c -msgid "Tuple or struct_time argument required" -msgstr "" - -#: ports/esp8266/machine_uart.c -#, c-format -msgid "UART(%d) does not exist" -msgstr "" - -#: ports/esp8266/machine_uart.c -msgid "UART(1) can't read" -msgstr "" - -#: shared-module/usb_hid/Device.c -msgid "USB Busy" -msgstr "" - -#: shared-module/usb_hid/Device.c -msgid "USB Error" -msgstr "" - -#: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "" - -#: shared-bindings/bleio/UUID.c -msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" -msgstr "" - -#: shared-bindings/bleio/UUID.c -msgid "UUID value is not str, int or byte buffer" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Unable to allocate buffers for signed conversion" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Unable to find free GCLK" -msgstr "" - -#: py/parse.c -msgid "Unable to init parser" -msgstr "" - -#: shared-module/displayio/OnDiskBitmap.c -msgid "Unable to read color palette data" -msgstr "" - -#: ports/esp8266/common-hal/storage/__init__.c -msgid "Unable to remount filesystem" -msgstr "" - -#: shared-bindings/nvm/ByteArray.c -msgid "Unable to write to nvm." -msgstr "" - -#: ports/nrf/common-hal/bleio/UUID.c -msgid "Unexpected nrfx uuid type" -msgstr "" - -#: ports/unix/modffi.c -msgid "Unknown type" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -#, c-format -msgid "Unmatched number of items on RHS (expected %d, got %d)." -msgstr "" - -#: ports/atmel-samd/common-hal/busio/I2C.c -msgid "Unsupported baudrate" -msgstr "" - -#: shared-module/displayio/Display.c -msgid "Unsupported display bus type" -msgstr "" - -#: shared-module/audioio/WaveFile.c -msgid "Unsupported format" -msgstr "" - -#: py/moduerrno.c -msgid "Unsupported operation" -msgstr "" - -#: shared-bindings/digitalio/DigitalInOut.c -msgid "Unsupported pull value." -msgstr "" - -#: ports/esp8266/common-hal/storage/__init__.c -msgid "Use esptool to erase flash and re-upload Python instead" -msgstr "" - -#: py/emitnative.c -msgid "Viper functions don't currently support more than 4 arguments" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "Voice index too high" -msgstr "" - -#: main.c -msgid "WARNING: Your code filename has two extensions\n" -msgstr "" - -#: py/builtinhelp.c -#, c-format -msgid "" -"Welcome to Adafruit CircuitPython %s!\n" -"\n" -"Please visit learn.adafruit.com/category/circuitpython for project guides.\n" -"\n" -"To list built-in modules please do `help(\"modules\")`.\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"You are running in safe mode which means something unanticipated happened.\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "You requested starting safe mode by " -msgstr "" - -#: ports/unix/modusocket.c -#, c-format -msgid "[addrinfo error %d]" -msgstr "" - -#: py/objtype.c -msgid "__init__() should return None" -msgstr "" - -#: py/objtype.c -#, c-format -msgid "__init__() should return None, not '%s'" -msgstr "" - -#: py/objobject.c -msgid "__new__ arg must be a user-type" -msgstr "" - -#: extmod/modubinascii.c extmod/moduhashlib.c -msgid "a bytes-like object is required" -msgstr "" - -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "" - -#: ports/unix/modmachine.c extmod/machine_mem.c -#, c-format -msgid "address %08x is not aligned to %d bytes" -msgstr "" - -#: shared-bindings/i2cslave/I2CSlave.c -msgid "address out of bounds" -msgstr "" - -#: shared-bindings/i2cslave/I2CSlave.c -msgid "addresses is empty" -msgstr "" - -#: py/modbuiltins.c -msgid "arg is an empty sequence" -msgstr "" - -#: py/runtime.c -msgid "argument has wrong type" -msgstr "" - -#: py/argcheck.c -msgid "argument num/types mismatch" -msgstr "" - -#: py/runtime.c -msgid "argument should be a '%q' not a '%q'" -msgstr "" - -#: shared-bindings/nvm/ByteArray.c py/objarray.c -msgid "array/bytes required on right side" -msgstr "" - -#: py/objstr.c -msgid "attributes not supported yet" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c -msgid "bad GATT role" -msgstr "" - -#: py/builtinevex.c -msgid "bad compile mode" -msgstr "" - -#: py/objstr.c -msgid "bad conversion specifier" -msgstr "" - -#: py/objstr.c -msgid "bad format string" -msgstr "" - -#: py/binary.c -msgid "bad typecode" -msgstr "" - -#: py/emitnative.c -msgid "binary op %q not implemented" -msgstr "" - -#: shared-bindings/busio/UART.c -msgid "bits must be 7, 8 or 9" -msgstr "" - -#: extmod/machine_spi.c -msgid "bits must be 8" -msgstr "" - -#: shared-bindings/audioio/Mixer.c -msgid "bits_per_sample must be 8 or 16" -msgstr "" - -#: py/emitinlinethumb.c -msgid "branch not in range" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -#, c-format -msgid "buf is too small. need %d bytes" -msgstr "" - -#: shared-bindings/audioio/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - -#: shared-module/struct/__init__.c -msgid "buffer size must match format" -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c -msgid "buffer slices must be of equal length" -msgstr "" - -#: ports/esp8266/machine_rtc.c -msgid "buffer too long" -msgstr "" - -#: shared-bindings/struct/__init__.c shared-module/struct/__init__.c -#: py/modstruct.c -msgid "buffer too small" -msgstr "" - -#: extmod/machine_spi.c -msgid "buffers must be the same length" -msgstr "" - -#: shared-bindings/_pew/PewPew.c -msgid "buttons must be digitalio.DigitalInOut" -msgstr "" - -#: py/vm.c -msgid "byte code not implemented" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -#, c-format -msgid "byteorder is not an instance of ByteOrder (got a %s)" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/UART.c -msgid "bytes > 8 bits not supported" -msgstr "" - -#: py/objstr.c -msgid "bytes value out of range" -msgstr "" - -#: ports/atmel-samd/bindings/samd/Clock.c -msgid "calibration is out of range" -msgstr "" - -#: ports/atmel-samd/bindings/samd/Clock.c -msgid "calibration is read only" -msgstr "" - -#: ports/atmel-samd/common-hal/rtc/RTC.c -msgid "calibration value out of range +/-127" -msgstr "" - -#: py/emitinlinethumb.c -msgid "can only have up to 4 parameters to Thumb assembly" -msgstr "" - -#: py/emitinlinextensa.c -msgid "can only have up to 4 parameters to Xtensa assembly" -msgstr "" - -#: py/persistentcode.c -msgid "can only save bytecode" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can query only one param" -msgstr "" - -#: py/objtype.c -msgid "can't add special method to already-subclassed class" -msgstr "" - -#: py/compile.c -msgid "can't assign to expression" -msgstr "" - -#: py/obj.c -#, c-format -msgid "can't convert %s to complex" -msgstr "" - -#: py/obj.c -#, c-format -msgid "can't convert %s to float" -msgstr "" - -#: py/obj.c -#, c-format -msgid "can't convert %s to int" -msgstr "" - -#: py/objstr.c -msgid "can't convert '%q' object to %q implicitly" -msgstr "" - -#: py/objint.c -msgid "can't convert NaN to int" -msgstr "" - -#: shared-bindings/i2cslave/I2CSlave.c -msgid "can't convert address to int" -msgstr "" - -#: py/objint.c -msgid "can't convert inf to int" -msgstr "" - -#: py/obj.c -msgid "can't convert to complex" -msgstr "" - -#: py/obj.c -msgid "can't convert to float" -msgstr "" - -#: py/obj.c -msgid "can't convert to int" -msgstr "" - -#: py/objstr.c -msgid "can't convert to str implicitly" -msgstr "" - -#: py/compile.c -msgid "can't declare nonlocal in outer code" -msgstr "" - -#: py/compile.c -msgid "can't delete expression" -msgstr "" - -#: py/emitnative.c -msgid "can't do binary op between '%q' and '%q'" -msgstr "" - -#: py/objcomplex.c -msgid "can't do truncated division of a complex number" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can't get AP config" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can't get STA config" -msgstr "" - -#: py/compile.c -msgid "can't have multiple **x" -msgstr "" - -#: py/compile.c -msgid "can't have multiple *x" -msgstr "" - -#: py/emitnative.c -msgid "can't implicitly convert '%q' to 'bool'" -msgstr "" - -#: py/emitnative.c -msgid "can't load from '%q'" -msgstr "" - -#: py/emitnative.c -msgid "can't load with '%q' index" -msgstr "" - -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - -#: py/objgenerator.c -msgid "can't send non-None value to a just-started generator" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can't set AP config" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can't set STA config" -msgstr "" - -#: py/objnamedtuple.c -msgid "can't set attribute" -msgstr "" - -#: py/emitnative.c -msgid "can't store '%q'" -msgstr "" - -#: py/emitnative.c -msgid "can't store to '%q'" -msgstr "" - -#: py/emitnative.c -msgid "can't store with '%q' index" -msgstr "" - -#: py/objstr.c -msgid "" -"can't switch from automatic field numbering to manual field specification" -msgstr "" - -#: py/objstr.c -msgid "" -"can't switch from manual field specification to automatic field numbering" -msgstr "" - -#: py/objtype.c -msgid "cannot create '%q' instances" -msgstr "" - -#: py/objtype.c -msgid "cannot create instance" -msgstr "" - -#: py/runtime.c -msgid "cannot import name %q" -msgstr "" - -#: py/builtinimport.c -msgid "cannot perform relative import" -msgstr "" - -#: py/emitnative.c -msgid "casting" -msgstr "" - -#: shared-bindings/bleio/Service.c -msgid "characteristics includes an object that is not a Characteristic" -msgstr "" - -#: shared-bindings/_stage/Text.c -msgid "chars buffer too small" -msgstr "" - -#: py/modbuiltins.c -msgid "chr() arg not in range(0x110000)" -msgstr "" - -#: py/modbuiltins.c -msgid "chr() arg not in range(256)" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "color buffer must be a buffer or int" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "color buffer must be a bytearray or array of type 'b' or 'B'" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "color must be between 0x000000 and 0xffffff" -msgstr "" - -#: shared-bindings/displayio/ColorConverter.c -msgid "color should be an int" -msgstr "" - -#: py/objcomplex.c -msgid "complex division by zero" -msgstr "" - -#: py/parsenum.c py/objfloat.c -msgid "complex values not supported" -msgstr "" - -#: extmod/moduzlib.c -msgid "compression header" -msgstr "" - -#: py/parse.c -msgid "constant must be an integer" -msgstr "" - -#: py/emitnative.c -msgid "conversion to object" -msgstr "" - -#: py/parsenum.c -msgid "decimal numbers not supported" -msgstr "" - -#: py/compile.c -msgid "default 'except' must be last" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "" -"destination buffer must be a bytearray or array of type 'B' for bit_depth = 8" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "destination buffer must be an array of type 'H' for bit_depth = 16" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "destination_length must be an int >= 0" -msgstr "" - -#: py/objdict.c -msgid "dict update sequence has wrong length" -msgstr "" - -#: shared-bindings/math/__init__.c py/runtime.c py/modmath.c py/objint_mpz.c -#: py/objint_longlong.c py/objfloat.c -msgid "division by zero" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "either pos or kw args are allowed" -msgstr "" - -#: py/objdeque.c -msgid "empty" -msgstr "" - -#: extmod/modutimeq.c extmod/moduheapq.c -msgid "empty heap" -msgstr "" - -#: py/objstr.c -msgid "empty separator" -msgstr "" - -#: shared-bindings/random/__init__.c -msgid "empty sequence" -msgstr "" - -#: py/objstr.c -msgid "end of format while looking for conversion specifier" -msgstr "" - -#: shared-bindings/displayio/Shape.c -msgid "end_x should be an int" -msgstr "" - -#: ports/nrf/common-hal/busio/UART.c -#, c-format -msgid "error = 0x%08lX" -msgstr "" - -#: py/runtime.c -msgid "exceptions must derive from BaseException" -msgstr "" - -#: py/objstr.c -msgid "expected ':' after format specifier" -msgstr "" - -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "" - -#: py/obj.c -msgid "expected tuple/list" -msgstr "" - -#: py/modthread.c -msgid "expecting a dict for keyword args" -msgstr "" - -#: ports/esp8266/machine_pin.c -msgid "expecting a pin" -msgstr "" - -#: py/compile.c -msgid "expecting an assembler instruction" -msgstr "" - -#: py/compile.c -msgid "expecting just a value for set" -msgstr "" - -#: py/compile.c -msgid "expecting key:value for dict" -msgstr "" - -#: py/argcheck.c -msgid "extra keyword arguments given" -msgstr "" - -#: py/argcheck.c -msgid "extra positional arguments given" -msgstr "" - -#: ports/unix/modffi.c -msgid "ffi_prep_closure_loc" -msgstr "" - -#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c -msgid "file must be a file opened in byte mode" -msgstr "" - -#: shared-bindings/storage/__init__.c -msgid "filesystem must provide mount method" -msgstr "" - -#: py/objtype.c -msgid "first argument to super() must be type" -msgstr "" - -#: extmod/machine_spi.c -msgid "firstbit must be MSB" -msgstr "" - -#: ports/esp8266/modesp.c -msgid "flash location must be below 1MByte" -msgstr "" - -#: py/objint.c -msgid "float too big" -msgstr "" - -#: shared-bindings/_stage/Text.c -msgid "font must be 2048 bytes long" -msgstr "" - -#: py/objstr.c -msgid "format requires a dict" -msgstr "" - -#: ports/esp8266/modmachine.c -msgid "frequency can only be either 80Mhz or 160MHz" -msgstr "" - -#: py/objdeque.c -msgid "full" -msgstr "" - -#: py/argcheck.c -msgid "function does not take keyword arguments" -msgstr "" - -#: py/argcheck.c -#, c-format -msgid "function expected at most %d arguments, got %d" -msgstr "" - -#: py/objnamedtuple.c py/bc.c -msgid "function got multiple values for argument '%q'" -msgstr "" - -#: py/argcheck.c -#, c-format -msgid "function missing %d required positional arguments" -msgstr "" - -#: py/bc.c -msgid "function missing keyword-only argument" -msgstr "" - -#: py/bc.c -msgid "function missing required keyword argument '%q'" -msgstr "" - -#: py/bc.c -#, c-format -msgid "function missing required positional argument #%d" -msgstr "" - -#: py/argcheck.c py/objnamedtuple.c py/bc.c -#, c-format -msgid "function takes %d positional arguments but %d were given" -msgstr "" - -#: shared-bindings/time/__init__.c -msgid "function takes exactly 9 arguments" -msgstr "" - -#: py/objgenerator.c -msgid "generator already executing" -msgstr "" - -#: py/objgenerator.c -msgid "generator ignored GeneratorExit" -msgstr "" - -#: shared-bindings/_stage/Layer.c -msgid "graphic must be 2048 bytes long" -msgstr "" - -#: extmod/moduheapq.c -msgid "heap must be a list" -msgstr "" - -#: py/compile.c -msgid "identifier redefined as global" -msgstr "" - -#: py/compile.c -msgid "identifier redefined as nonlocal" -msgstr "" - -#: ports/esp8266/machine_hspi.c -msgid "impossible baudrate" -msgstr "" - -#: py/objstr.c -msgid "incomplete format" -msgstr "" - -#: py/objstr.c -msgid "incomplete format key" -msgstr "" - -#: extmod/modubinascii.c -msgid "incorrect padding" -msgstr "" - -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -#: ports/nrf/common-hal/pulseio/PulseIn.c -#: ports/esp8266/common-hal/pulseio/PulseIn.c py/obj.c -msgid "index out of range" -msgstr "" - -#: py/obj.c -msgid "indices must be integers" -msgstr "" - -#: py/compile.c -msgid "inline assembler must be a function" -msgstr "" - -#: py/parsenum.c -msgid "int() arg 2 must be >= 2 and <= 36" -msgstr "" - -#: py/objstr.c -msgid "integer required" -msgstr "" - -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "" - -#: extmod/machine_i2c.c -msgid "invalid I2C peripheral" -msgstr "" - -#: extmod/machine_spi.c -msgid "invalid SPI peripheral" -msgstr "" - -#: ports/esp8266/machine_rtc.c -msgid "invalid alarm" -msgstr "" - -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "invalid buffer length" -msgstr "" - -#: extmod/modussl_axtls.c -msgid "invalid cert" -msgstr "" - -#: ports/esp8266/common-hal/busio/UART.c ports/esp8266/machine_uart.c -msgid "invalid data bits" -msgstr "" - -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "" - -#: extmod/modframebuf.c -msgid "invalid format" -msgstr "" - -#: py/objstr.c -msgid "invalid format specifier" -msgstr "" - -#: extmod/modussl_axtls.c -msgid "invalid key" -msgstr "" - -#: py/compile.c -msgid "invalid micropython decorator" -msgstr "" - -#: ports/esp8266/machine_pin.c -msgid "invalid pin" -msgstr "" - -#: shared-bindings/random/__init__.c -msgid "invalid step" -msgstr "" - -#: ports/esp8266/common-hal/busio/UART.c ports/esp8266/machine_uart.c -msgid "invalid stop bits" -msgstr "" - -#: py/compile.c py/parse.c -msgid "invalid syntax" -msgstr "" - -#: py/parsenum.c -msgid "invalid syntax for integer" -msgstr "" - -#: py/parsenum.c -#, c-format -msgid "invalid syntax for integer with base %d" -msgstr "" - -#: py/parsenum.c -msgid "invalid syntax for number" -msgstr "" - -#: py/objtype.c -msgid "issubclass() arg 1 must be a class" -msgstr "" - -#: py/objtype.c -msgid "issubclass() arg 2 must be a class or a tuple of classes" -msgstr "" - -#: py/objstr.c -msgid "join expects a list of str/bytes objects consistent with self object" -msgstr "" - -#: py/argcheck.c -msgid "keyword argument(s) not yet implemented - use normal args instead" -msgstr "" - -#: py/bc.c -msgid "keywords must be strings" -msgstr "" - -#: py/emitinlinextensa.c py/emitinlinethumb.c -msgid "label '%q' not defined" -msgstr "" - -#: py/compile.c -msgid "label redefined" -msgstr "" - -#: ports/esp8266/modesp.c -msgid "len must be multiple of 4" -msgstr "" - -#: py/stream.c -msgid "length argument not allowed for this type" -msgstr "" - -#: py/objarray.c -msgid "lhs and rhs should be compatible" -msgstr "" - -#: py/emitnative.c -msgid "local '%q' has type '%q' but source is '%q'" -msgstr "" - -#: py/emitnative.c -msgid "local '%q' used before type known" -msgstr "" - -#: py/vm.c -msgid "local variable referenced before assignment" -msgstr "" - -#: py/objint.c -msgid "long int not supported in this build" -msgstr "" - -#: shared-bindings/_stage/Layer.c -msgid "map buffer too small" -msgstr "" - -#: shared-bindings/math/__init__.c py/modmath.c -msgid "math domain error" -msgstr "" - -#: py/runtime.c -msgid "maximum recursion depth exceeded" -msgstr "" - -#: py/runtime.c -#, c-format -msgid "memory allocation failed, allocating %u bytes" -msgstr "" - -#: ports/esp8266/modesp.c -#, c-format -msgid "memory allocation failed, allocating %u bytes for native code" -msgstr "" - -#: py/runtime.c -msgid "memory allocation failed, heap is locked" -msgstr "" - -#: py/builtinimport.c -msgid "module not found" -msgstr "" - -#: py/compile.c -msgid "multiple *x in assignment" -msgstr "" - -#: py/objtype.c -msgid "multiple bases have instance lay-out conflict" -msgstr "" - -#: py/objtype.c -msgid "multiple inheritance not supported" -msgstr "" - -#: py/emitnative.c -msgid "must raise an object" -msgstr "" - -#: extmod/machine_spi.c -msgid "must specify all of sck/mosi/miso" -msgstr "" - -#: py/modbuiltins.c -msgid "must use keyword argument for key function" -msgstr "" - -#: py/runtime.c -msgid "name '%q' is not defined" -msgstr "" - -#: shared-bindings/bleio/Peripheral.c -msgid "name must be a string" -msgstr "" - -#: py/runtime.c -msgid "name not defined" -msgstr "" - -#: py/compile.c -msgid "name reused for argument" -msgstr "" - -#: py/emitnative.c -msgid "native yield" -msgstr "" - -#: py/runtime.c -#, c-format -msgid "need more than %d values to unpack" -msgstr "" - -#: py/runtime.c py/objint_mpz.c py/objint_longlong.c -msgid "negative power with no float support" -msgstr "" - -#: py/runtime.c py/objint_mpz.c -msgid "negative shift count" -msgstr "" - -#: py/vm.c -msgid "no active exception to reraise" -msgstr "" - -#: shared-bindings/socket/__init__.c shared-module/network/__init__.c -msgid "no available NIC" -msgstr "" - -#: py/compile.c -msgid "no binding for nonlocal found" -msgstr "" - -#: py/builtinimport.c -msgid "no module named '%q'" -msgstr "" - -#: shared-bindings/_pixelbuf/__init__.c py/runtime.c -msgid "no such attribute" -msgstr "" - -#: py/compile.c -msgid "non-default argument follows default argument" -msgstr "" - -#: extmod/modubinascii.c -msgid "non-hex digit found" -msgstr "" - -#: py/compile.c -msgid "non-keyword arg after */**" -msgstr "" - -#: py/compile.c -msgid "non-keyword arg after keyword arg" -msgstr "" - -#: shared-bindings/bleio/UUID.c -msgid "not a 128-bit UUID" -msgstr "" - -#: ports/esp8266/machine_adc.c -#, c-format -msgid "not a valid ADC Channel: %d" -msgstr "" - -#: py/objstr.c -msgid "not all arguments converted during string formatting" -msgstr "" - -#: py/objstr.c -msgid "not enough arguments for format string" -msgstr "" - -#: py/obj.c -#, c-format -msgid "object '%s' is not a tuple or list" -msgstr "" - -#: py/obj.c -msgid "object does not support item assignment" -msgstr "" - -#: py/obj.c -msgid "object does not support item deletion" -msgstr "" - -#: py/obj.c -msgid "object has no len" -msgstr "" - -#: py/obj.c -msgid "object is not subscriptable" -msgstr "" - -#: py/runtime.c -msgid "object not an iterator" -msgstr "" - -#: py/objtype.c py/runtime.c -msgid "object not callable" -msgstr "" - -#: py/sequence.c -msgid "object not in sequence" -msgstr "" - -#: py/runtime.c -msgid "object not iterable" -msgstr "" - -#: py/obj.c -#, c-format -msgid "object of type '%s' has no len()" -msgstr "" - -#: py/obj.c -msgid "object with buffer protocol required" -msgstr "" - -#: extmod/modubinascii.c -msgid "odd-length string" -msgstr "" - -#: py/objstrunicode.c py/objstr.c -msgid "offset out of bounds" -msgstr "" - -#: shared-bindings/nvm/ByteArray.c py/objarray.c py/objtuple.c -#: py/objstrunicode.c py/objstr.c -msgid "only slices with step=1 (aka None) are supported" -msgstr "" - -#: py/modbuiltins.c -msgid "ord expects a character" -msgstr "" - -#: py/modbuiltins.c -#, c-format -msgid "ord() expected a character, but string of length %d found" -msgstr "" - -#: py/objint_mpz.c -msgid "overflow converting long int to machine word" -msgstr "" - -#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c -msgid "palette must be 32 bytes long" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "palette_index should be an int" -msgstr "" - -#: py/compile.c -msgid "parameter annotation must be an identifier" -msgstr "" - -#: py/emitinlinextensa.c -msgid "parameters must be registers in sequence a2 to a5" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" -#: py/emitinlinethumb.c -msgid "parameters must be registers in sequence r0 to r3" +#: shared-bindings/pulseio/PWMOut.c +msgid "" +"PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)" msgstr "" -#: ports/esp8266/machine_pin.c -msgid "pin does not have IRQ capabilities" +#: shared-bindings/pulseio/PWMOut.c +msgid "" +"PWM frequency not writable when variable_frequency is False on construction." msgstr "" -#: shared-bindings/displayio/Bitmap.c -msgid "pixel coordinates out of bounds" +#: main.c +msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" -#: shared-bindings/displayio/Bitmap.c -msgid "pixel value requires too many bits" +#: shared-bindings/digitalio/DigitalInOut.c +msgid "Pull not used when direction is output." msgstr "" -#: shared-bindings/displayio/TileGrid.c -msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter" +#: shared-bindings/rtc/RTC.c +msgid "RTC calibration is not supported on this board" msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -#: ports/nrf/common-hal/pulseio/PulseIn.c -#: ports/esp8266/common-hal/pulseio/PulseIn.c -msgid "pop from an empty PulseIn" +#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +msgid "RTC is not supported on this board" msgstr "" -#: py/objset.c -msgid "pop from an empty set" +#: shared-bindings/rtc/RTC.c +msgid "RTC set is not supported on this board" msgstr "" -#: py/objlist.c -msgid "pop from empty list" +#: shared-bindings/pulseio/PulseIn.c +msgid "Read-only" msgstr "" -#: py/objdict.c -msgid "popitem(): dictionary is empty" +#: shared-module/displayio/Bitmap.c +msgid "Read-only object" msgstr "" -#: py/objint_mpz.c -msgid "pow() 3rd argument cannot be 0" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" msgstr "" -#: py/objint_mpz.c -msgid "pow() with 3 arguments requires integers" +#: main.c +msgid "Running in safe mode! Auto-reload is off.\n" msgstr "" -#: extmod/modutimeq.c -msgid "queue overflow" +#: main.c +msgid "Running in safe mode! Not running saved code.\n" msgstr "" -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "rawbuf is not the same size as buf" +#: shared-bindings/nvm/ByteArray.c +msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/_pixelbuf/__init__.c -msgid "readonly attribute" +#: shared-bindings/displayio/Group.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +msgid "Slices not supported" msgstr "" -#: py/builtinimport.c -msgid "relative import" +#: shared-bindings/supervisor/__init__.c +msgid "Stack size must be at least 256" msgstr "" -#: py/obj.c -#, c-format -msgid "requested length %d but object has length %d" +#: shared-bindings/multiterminal/__init__.c +msgid "Stream missing readinto() or write() method." msgstr "" -#: py/compile.c -msgid "return annotation must be an identifier" +#: supervisor/shared/safe_mode.c +msgid "" +"The CircuitPython heap was corrupted because the stack was too small.\n" +"Please increase stack size limits and press reset (after ejecting " +"CIRCUITPY).\n" +"If you didn't change the stack, then file an issue here with the contents of " +"your CIRCUITPY drive:\n" msgstr "" -#: py/emitnative.c -msgid "return expected '%q' but got '%q'" +#: supervisor/shared/safe_mode.c +msgid "" +"The microcontroller's power dipped. Please make sure your power supply " +"provides\n" +"enough power for the whole circuit and press reset (after ejecting " +"CIRCUITPY).\n" msgstr "" -#: shared-module/displayio/Bitmap.c -msgid "row must be packed and word aligned" +#: supervisor/shared/safe_mode.c +msgid "" +"The reset button was pressed while booting CircuitPython. Press again to " +"exit safe mode.\n" msgstr "" -#: py/objstr.c -msgid "rsplit(None,n)" +#: shared-module/audioio/Mixer.c +msgid "The sample's bits_per_sample does not match the mixer's" msgstr "" -#: shared-bindings/audioio/RawSample.c -msgid "" -"sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or " -"'B'" +#: shared-module/audioio/Mixer.c +msgid "The sample's channel count does not match the mixer's" msgstr "" -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "sampling rate out of range" +#: shared-module/audioio/Mixer.c +msgid "The sample's sample rate does not match the mixer's" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "scan failed" +#: shared-module/audioio/Mixer.c +msgid "The sample's signedness does not match the mixer's" msgstr "" -#: py/modmicropython.c -msgid "schedule stack full" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile height must exactly divide bitmap height" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c -msgid "script compilation not supported" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" msgstr "" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile width must exactly divide bitmap width" msgstr "" -#: py/objstr.c -msgid "sign not allowed in string format specifier" +#: supervisor/shared/safe_mode.c +msgid "To exit, please reset the board without " msgstr "" -#: py/objstr.c -msgid "sign not allowed with integer format specifier 'c'" +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c +msgid "Too many display busses" msgstr "" -#: py/objstr.c -msgid "single '}' encountered in format string" +#: shared-bindings/displayio/Display.c +msgid "Too many displays" msgstr "" #: shared-bindings/time/__init__.c -msgid "sleep length must be non-negative" -msgstr "" - -#: py/objslice.c py/sequence.c -msgid "slice step cannot be zero" +msgid "Tuple or struct_time argument required" msgstr "" -#: py/sequence.c py/objint.c -msgid "small int overflow" +#: shared-module/usb_hid/Device.c +msgid "USB Busy" msgstr "" -#: main.c -msgid "soft reboot\n" +#: shared-module/usb_hid/Device.c +msgid "USB Error" msgstr "" -#: py/objstr.c -msgid "start/end indices" +#: shared-bindings/bleio/UUID.c +msgid "UUID integer value not in range 0 to 0xffff" msgstr "" -#: shared-bindings/displayio/Shape.c -msgid "start_x should be an int" +#: shared-bindings/bleio/UUID.c +msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" msgstr "" -#: shared-bindings/random/__init__.c -msgid "step must be non-zero" +#: shared-bindings/bleio/UUID.c +msgid "UUID value is not str, int or byte buffer" msgstr "" -#: shared-bindings/busio/UART.c -msgid "stop must be 1 or 2" +#: shared-module/displayio/OnDiskBitmap.c +msgid "Unable to read color palette data" msgstr "" -#: shared-bindings/random/__init__.c -msgid "stop not reachable from start" +#: shared-bindings/nvm/ByteArray.c +msgid "Unable to write to nvm." msgstr "" -#: py/stream.c -msgid "stream operation not supported" +#: shared-module/displayio/Display.c +msgid "Unsupported display bus type" msgstr "" -#: py/objstrunicode.c -msgid "string index out of range" +#: shared-module/audioio/WaveFile.c +msgid "Unsupported format" msgstr "" -#: py/objstrunicode.c -#, c-format -msgid "string indices must be integers, not %s" +#: shared-bindings/digitalio/DigitalInOut.c +msgid "Unsupported pull value." msgstr "" -#: py/stream.c -msgid "string not supported; use bytes or bytearray" +#: shared-module/audioio/Mixer.c +msgid "Voice index too high" msgstr "" -#: extmod/moductypes.c -msgid "struct: cannot index" +#: main.c +msgid "WARNING: Your code filename has two extensions\n" msgstr "" -#: extmod/moductypes.c -msgid "struct: index out of range" +#: supervisor/shared/safe_mode.c +msgid "" +"You are running in safe mode which means something unanticipated happened.\n" msgstr "" -#: extmod/moductypes.c -msgid "struct: no fields" +#: supervisor/shared/safe_mode.c +msgid "You requested starting safe mode by " msgstr "" -#: py/objstr.c -msgid "substring not found" +#: shared-bindings/i2cslave/I2CSlave.c +msgid "address out of bounds" msgstr "" -#: py/compile.c -msgid "super() can't find self" +#: shared-bindings/i2cslave/I2CSlave.c +msgid "addresses is empty" msgstr "" -#: extmod/modujson.c -msgid "syntax error in JSON" +#: shared-bindings/nvm/ByteArray.c +msgid "array/bytes required on right side" msgstr "" -#: extmod/moductypes.c -msgid "syntax error in uctypes descriptor" +#: shared-bindings/busio/UART.c +msgid "bits must be 7, 8 or 9" msgstr "" -#: shared-bindings/touchio/TouchIn.c -msgid "threshold must be in the range 0-65536" +#: shared-module/struct/__init__.c +msgid "buffer size must match format" msgstr "" -#: shared-bindings/displayio/TileGrid.c -msgid "tile index out of bounds" +#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +msgid "buffer slices must be of equal length" msgstr "" -#: shared-bindings/time/__init__.c -msgid "time.struct_time() takes a 9-sequence" +#: shared-bindings/struct/__init__.c shared-module/struct/__init__.c +msgid "buffer too small" msgstr "" -#: shared-bindings/time/__init__.c -msgid "time.struct_time() takes exactly 1 argument" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/busio/UART.c -msgid "timeout >100 (units are now seconds, not msecs)" +#: shared-bindings/i2cslave/I2CSlave.c +msgid "can't convert address to int" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c -msgid "timeout must be >= 0.0" +#: shared-bindings/bleio/Service.c +msgid "characteristics includes an object that is not a Characteristic" msgstr "" -#: shared-bindings/time/__init__.c -msgid "timestamp out of range for platform time_t" +#: shared-bindings/displayio/Palette.c +msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" +#: shared-bindings/displayio/Palette.c +msgid "color buffer must be a buffer or int" msgstr "" -#: shared-module/struct/__init__.c -msgid "too many arguments provided with the given format" +#: shared-bindings/displayio/Palette.c +msgid "color buffer must be a bytearray or array of type 'b' or 'B'" msgstr "" -#: py/runtime.c -#, c-format -msgid "too many values to unpack (expected %d)" +#: shared-bindings/displayio/Palette.c +msgid "color must be between 0x000000 and 0xffffff" msgstr "" -#: py/objstr.c -msgid "tuple index out of range" +#: shared-bindings/displayio/ColorConverter.c +msgid "color should be an int" msgstr "" -#: py/obj.c -msgid "tuple/list has wrong length" +#: shared-bindings/math/__init__.c +msgid "division by zero" msgstr "" -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "tuple/list required on RHS" +#: shared-bindings/random/__init__.c +msgid "empty sequence" msgstr "" -#: ports/atmel-samd/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c -msgid "tx and rx cannot both be None" +#: shared-bindings/displayio/Shape.c +msgid "end_x should be an int" msgstr "" -#: py/objtype.c -msgid "type '%q' is not an acceptable base type" +#: shared-bindings/gamepad/GamePad.c +msgid "expected a DigitalInOut" msgstr "" -#: py/objtype.c -msgid "type is not an acceptable base type" +#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +msgid "file must be a file opened in byte mode" msgstr "" -#: py/runtime.c -msgid "type object '%q' has no attribute '%q'" +#: shared-bindings/storage/__init__.c +msgid "filesystem must provide mount method" msgstr "" -#: py/objtype.c -msgid "type takes 1 or 3 arguments" +#: shared-bindings/time/__init__.c +msgid "function takes exactly 9 arguments" msgstr "" -#: py/objint_longlong.c -msgid "ulonglong too large" +#: shared-bindings/random/__init__.c +msgid "invalid step" msgstr "" -#: py/emitnative.c -msgid "unary op %q not implemented" +#: shared-bindings/math/__init__.c +msgid "math domain error" msgstr "" -#: py/parse.c -msgid "unexpected indent" +#: shared-bindings/bleio/Peripheral.c +msgid "name must be a string" msgstr "" -#: py/bc.c -msgid "unexpected keyword argument" +#: shared-bindings/socket/__init__.c shared-module/network/__init__.c +msgid "no available NIC" msgstr "" -#: py/objnamedtuple.c py/bc.c -msgid "unexpected keyword argument '%q'" +#: shared-bindings/bleio/UUID.c +msgid "not a 128-bit UUID" msgstr "" -#: py/lexer.c -msgid "unicode name escapes" +#: shared-bindings/nvm/ByteArray.c +msgid "only slices with step=1 (aka None) are supported" msgstr "" -#: py/parse.c -msgid "unindent does not match any outer indentation level" +#: shared-bindings/displayio/Palette.c +msgid "palette_index should be an int" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "unknown config param" +#: shared-bindings/displayio/Bitmap.c +msgid "pixel coordinates out of bounds" msgstr "" -#: py/objstr.c -#, c-format -msgid "unknown conversion specifier %c" +#: shared-bindings/displayio/Bitmap.c +msgid "pixel value requires too many bits" msgstr "" -#: py/objstr.c -#, c-format -msgid "unknown format code '%c' for object of type '%s'" +#: shared-bindings/displayio/TileGrid.c +msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter" msgstr "" -#: py/objstr.c -#, c-format -msgid "unknown format code '%c' for object of type 'float'" +#: shared-module/displayio/Bitmap.c +msgid "row must be packed and word aligned" msgstr "" -#: py/objstr.c -#, c-format -msgid "unknown format code '%c' for object of type 'str'" +#: shared-bindings/bleio/Peripheral.c +msgid "services includes an object that is not a Service" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "unknown status param" +#: shared-bindings/time/__init__.c +msgid "sleep length must be non-negative" msgstr "" -#: py/compile.c -msgid "unknown type" +#: main.c +msgid "soft reboot\n" msgstr "" -#: py/emitnative.c -msgid "unknown type '%q'" +#: shared-bindings/displayio/Shape.c +msgid "start_x should be an int" msgstr "" -#: py/objstr.c -msgid "unmatched '{' in format" +#: shared-bindings/random/__init__.c +msgid "step must be non-zero" msgstr "" -#: py/objtype.c py/runtime.c -msgid "unreadable attribute" +#: shared-bindings/busio/UART.c +msgid "stop must be 1 or 2" msgstr "" -#: py/emitinlinethumb.c -#, c-format -msgid "unsupported Thumb instruction '%s' with %d arguments" +#: shared-bindings/random/__init__.c +msgid "stop not reachable from start" msgstr "" -#: py/emitinlinextensa.c -#, c-format -msgid "unsupported Xtensa instruction '%s' with %d arguments" +#: shared-bindings/touchio/TouchIn.c +msgid "threshold must be in the range 0-65536" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "tile index out of bounds" msgstr "" -#: py/objstr.c -#, c-format -msgid "unsupported format character '%c' (0x%x) at index %d" +#: shared-bindings/time/__init__.c +msgid "time.struct_time() takes a 9-sequence" msgstr "" -#: py/runtime.c -msgid "unsupported type for %q: '%s'" +#: shared-bindings/time/__init__.c +msgid "time.struct_time() takes exactly 1 argument" msgstr "" -#: py/runtime.c -msgid "unsupported type for operator" +#: shared-bindings/busio/UART.c +msgid "timeout >100 (units are now seconds, not msecs)" msgstr "" -#: py/runtime.c -msgid "unsupported types for %q: '%s', '%s'" +#: shared-bindings/bleio/CharacteristicBuffer.c +msgid "timeout must be >= 0.0" msgstr "" -#: shared-bindings/displayio/Bitmap.c -msgid "value_count must be > 0" +#: shared-bindings/time/__init__.c +msgid "timestamp out of range for platform time_t" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "wifi_set_ip_info() failed" +#: shared-bindings/gamepad/GamePad.c +msgid "too many arguments" msgstr "" -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "write_args must be a list, tuple, or None" +#: shared-module/struct/__init__.c +msgid "too many arguments provided with the given format" msgstr "" -#: py/objstr.c -msgid "wrong number of arguments" +#: shared-bindings/displayio/TileGrid.c +msgid "unsupported bitmap type" msgstr "" -#: py/runtime.c -msgid "wrong number of values to unpack" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" msgstr "" #: shared-module/displayio/Shape.c @@ -2816,7 +758,3 @@ msgstr "" #: shared-module/displayio/Shape.c msgid "y value out of bounds" msgstr "" - -#: py/objrange.c -msgid "zero step" -msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 87e965914..175efaf80 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 19:40+0100\n" +"POT-Creation-Date: 2019-03-02 22:09+1100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -1129,6 +1129,9 @@ msgstr "Die RTC-Kalibrierung wird auf diesem Board nicht unterstützt" msgid "RTC is not supported on this board" msgstr "Eine RTC wird auf diesem Board nicht unterstützt" +msgid "RTC set is not supported on this board" +msgstr "Die RTC-Änderung wird auf diesem Board nicht unterstützt" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" diff --git a/locale/en_US.po b/locale/en_US.po index da189c661..14e202d05 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 19:40+0100\n" +"POT-Creation-Date: 2019-03-02 22:09+1100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -1108,6 +1108,9 @@ msgstr "" msgid "RTC is not supported on this board" msgstr "" +msgid "RTC set is not supported on this board" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index f9bb0f0ff..bf6c925e6 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 19:40+0100\n" +"POT-Creation-Date: 2019-03-28 09:50+1100\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -25,37 +25,16 @@ msgstr "" "\n" "Captin's orders are complete. Holdin' fast fer reload.\n" -#: py/obj.c -msgid " File \"%q\"" -msgstr "" - -#: py/obj.c -msgid " File \"%q\", line %d" -msgstr "" - #: main.c msgid " output:\n" msgstr "" -#: py/objstr.c -#, c-format -msgid "%%c requires int or char" -msgstr "" - #: shared-bindings/microcontroller/Pin.c msgid "%q in use" msgstr "" -#: py/obj.c -msgid "%q index out of range" -msgstr "" - -#: py/obj.c -msgid "%q indices must be integers, not %s" -msgstr "" - -#: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c #: shared-bindings/bleio/CharacteristicBuffer.c +#: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c msgid "%q must be >= 1" msgstr "" @@ -63,166 +42,10 @@ msgstr "" msgid "%q should be an int" msgstr "" -#: py/objnamedtuple.c py/bc.c -msgid "%q() takes %d positional arguments but %d were given" -msgstr "" - -#: py/argcheck.c -msgid "'%q' argument required" -msgstr "" - -#: py/emitinlinextensa.c py/emitinlinethumb.c -#, c-format -msgid "'%s' expects a label" -msgstr "" - -#: py/emitinlinextensa.c py/emitinlinethumb.c -#, c-format -msgid "'%s' expects a register" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects a special register" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects an FPU register" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects an address of the form [a, b]" -msgstr "" - -#: py/emitinlinextensa.c py/emitinlinethumb.c -#, c-format -msgid "'%s' expects an integer" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects at most r%d" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' expects {r0, r1, ...}" -msgstr "" - -#: py/emitinlinextensa.c -#, c-format -msgid "'%s' integer %d is not within range %d..%d" -msgstr "" - -#: py/emitinlinethumb.c -#, c-format -msgid "'%s' integer 0x%x does not fit in mask 0x%x" -msgstr "" - -#: py/obj.c -#, c-format -msgid "'%s' object does not support item assignment" -msgstr "" - -#: py/obj.c -#, c-format -msgid "'%s' object does not support item deletion" -msgstr "" - -#: py/runtime.c -msgid "'%s' object has no attribute '%q'" -msgstr "" - -#: py/runtime.c -#, c-format -msgid "'%s' object is not an iterator" -msgstr "" - -#: py/objtype.c py/runtime.c -#, c-format -msgid "'%s' object is not callable" -msgstr "" - -#: py/runtime.c -#, c-format -msgid "'%s' object is not iterable" -msgstr "" - -#: py/obj.c -#, c-format -msgid "'%s' object is not subscriptable" -msgstr "" - -#: py/objstr.c -msgid "'=' alignment not allowed in string format specifier" -msgstr "" - #: shared-module/struct/__init__.c msgid "'S' and 'O' are not supported format types" msgstr "" -#: py/compile.c -msgid "'align' requires 1 argument" -msgstr "" - -#: py/compile.c -msgid "'await' outside function" -msgstr "" - -#: py/compile.c -msgid "'break' outside loop" -msgstr "" - -#: py/compile.c -msgid "'continue' outside loop" -msgstr "" - -#: py/compile.c -msgid "'data' requires at least 2 arguments" -msgstr "" - -#: py/compile.c -msgid "'data' requires integer arguments" -msgstr "" - -#: py/compile.c -msgid "'label' requires 1 argument" -msgstr "" - -#: py/compile.c -msgid "'return' outside function" -msgstr "" - -#: py/compile.c -msgid "'yield' outside function" -msgstr "" - -#: py/compile.c -msgid "*x must be assignment target" -msgstr "" - -#: py/obj.c -msgid ", in %q\n" -msgstr "" - -#: py/objcomplex.c -msgid "0.0 to a complex power" -msgstr "" - -#: py/modbuiltins.c -msgid "3-arg pow() not supported" -msgstr "" - -#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c -msgid "A hardware interrupt channel is already in use" -msgstr "Avast! A hardware interrupt channel be used already" - -#: ports/esp8266/modnetwork.c -msgid "AP required" -msgstr "" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address is not %d bytes long or is in wrong format" @@ -233,54 +56,14 @@ msgstr "" msgid "Address must be %d bytes long" msgstr "" -#: ports/nrf/common-hal/busio/I2C.c -msgid "All I2C peripherals are in use" -msgstr "" - -#: ports/nrf/common-hal/busio/SPI.c -msgid "All SPI peripherals are in use" -msgstr "" - -#: ports/nrf/common-hal/busio/UART.c -msgid "All UART peripherals are in use" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "All event channels in use" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c -msgid "All sync event channels in use" -msgstr "" - #: shared-bindings/pulseio/PWMOut.c msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -#: ports/atmel-samd/common-hal/pulseio/PulseOut.c -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -#: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c -#: shared-module/_pew/PewPew.c +#: shared-bindings/pulseio/PWMOut.c shared-module/_pew/PewPew.c msgid "All timers in use" msgstr "" -#: ports/nrf/common-hal/analogio/AnalogOut.c -msgid "AnalogOut functionality not supported" -msgstr "" - -#: shared-bindings/analogio/AnalogOut.c -msgid "AnalogOut is only 16 bits. Value must be less than 65536." -msgstr "" - -#: ports/atmel-samd/common-hal/analogio/AnalogOut.c -msgid "AnalogOut not supported on given pin" -msgstr "" - -#: ports/atmel-samd/common-hal/pulseio/PulseOut.c -msgid "Another send is already active" -msgstr "Belay that! thar be another active send" - #: shared-bindings/pulseio/PulseOut.c msgid "Array must contain halfwords (type 'H')" msgstr "" @@ -305,18 +88,6 @@ msgstr "" "Auto-reload be on. Put yer files on USB to weigh anchor, er' bring'er about " "t' the REPL t' scuttle.\n" -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -msgid "Bit clock and word select must share a clock unit" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "Bit depth must be multiple of 8." -msgstr "" - -#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c -msgid "Both pins must support hardware interrupts" -msgstr "" - #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -334,12 +105,6 @@ msgstr "" msgid "Buffer must be at least length 1" msgstr "" -#: ports/atmel-samd/common-hal/displayio/ParallelBus.c -#: ports/nrf/common-hal/displayio/ParallelBus.c -#, c-format -msgid "Bus pin %d is already in use" -msgstr "Belay that! Bus pin %d already be in use" - #: shared-bindings/bleio/UUID.c msgid "Byte buffer must be 16 bytes." msgstr "" @@ -348,15 +113,6 @@ msgstr "" msgid "Bytes must be between 0 and 255." msgstr "" -#: ports/esp8266/esp_mphal.c -msgid "C-level assert" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -#, c-format -msgid "Can not use dotstar with %s" -msgstr "" - #: shared-bindings/bleio/Device.c msgid "Can't add services in Central mode" msgstr "" @@ -373,72 +129,26 @@ msgstr "" msgid "Can't connect in Peripheral mode" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "Cannot connect to AP" -msgstr "" - #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "Cannot disconnect from AP" -msgstr "" - -#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c -#: ports/nrf/common-hal/digitalio/DigitalInOut.c -msgid "Cannot get pull while in output mode" -msgstr "" - -#: ports/nrf/common-hal/microcontroller/Processor.c -msgid "Cannot get temperature" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Cannot output both channels on the same pin" -msgstr "" - #: shared-module/bitbangio/SPI.c msgid "Cannot read without MISO pin." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "Cannot record to a file" -msgstr "" - #: shared-module/storage/__init__.c msgid "Cannot remount '/' when USB is active." msgstr "" -#: ports/atmel-samd/common-hal/microcontroller/__init__.c -#: ports/esp8266/common-hal/microcontroller/__init__.c -msgid "Cannot reset into bootloader because no bootloader is present." -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "Cannot set STA config" -msgstr "" - #: shared-bindings/digitalio/DigitalInOut.c msgid "Cannot set value when direction is input." msgstr "" -#: py/objslice.c -msgid "Cannot subclass slice" -msgstr "" - #: shared-module/bitbangio/SPI.c msgid "Cannot transfer without MOSI and MISO pins." msgstr "" -#: extmod/moductypes.c -msgid "Cannot unambiguously get sizeof scalar" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "Cannot update i/f status" -msgstr "" - #: shared-module/bitbangio/SPI.c msgid "Cannot write without MOSI pin." msgstr "" @@ -447,10 +157,6 @@ msgstr "" msgid "Characteristic UUID doesn't match Service UUID" msgstr "" -#: ports/nrf/common-hal/bleio/Service.c -msgid "Characteristic already in use by another Service." -msgstr "" - #: shared-bindings/bleio/CharacteristicBuffer.c msgid "CharacteristicBuffer writing not provided" msgstr "" @@ -463,27 +169,14 @@ msgstr "" msgid "Clock stretch too long" msgstr "" -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -msgid "Clock unit in use" -msgstr "" - #: shared-bindings/_pew/PewPew.c msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Command must be an int between 0 and 255" msgstr "" -#: ports/nrf/common-hal/bleio/UUID.c -#, c-format -msgid "Could not decode ble_uuid, err 0x%04x" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/UART.c -msgid "Could not initialize UART" -msgstr "" - #: shared-module/audioio/Mixer.c shared-module/audioio/WaveFile.c msgid "Couldn't allocate first buffer" msgstr "" @@ -496,67 +189,21 @@ msgstr "" msgid "Crash into the HardFault_Handler.\n" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "DAC already in use" -msgstr "" - -#: ports/atmel-samd/common-hal/displayio/ParallelBus.c -#: ports/nrf/common-hal/displayio/ParallelBus.c -msgid "Data 0 pin must be byte aligned" -msgstr "" - #: shared-module/audioio/WaveFile.c msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -#: ports/nrf/common-hal/bleio/Peripheral.c -msgid "Data too large for advertisement packet" -msgstr "" - -#: ports/nrf/common-hal/bleio/Device.c -msgid "Data too large for the advertisement packet" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "Destination capacity is smaller than destination_length." -msgstr "" - #: shared-bindings/displayio/Display.c msgid "Display rotation must be in 90 degree increments" msgstr "" -#: ports/unix/modffi.c -msgid "Don't know how to pass object to native function" -msgstr "" - #: shared-bindings/digitalio/DigitalInOut.c msgid "Drive mode not used when direction is input." msgstr "" -#: ports/esp8266/common-hal/microcontroller/__init__.c -msgid "ESP8226 does not support safe mode." -msgstr "" - -#: ports/esp8266/common-hal/digitalio/DigitalInOut.c -msgid "ESP8266 does not support pull down." -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -msgid "EXTINT channel already in use" -msgstr "Avast! EXTINT channel already in use" - -#: ports/unix/modffi.c -msgid "Error in ffi_prep_cif" -msgstr "" - -#: extmod/modure.c -msgid "Error in regex" -msgstr "" - -#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c -#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c +#: shared-bindings/microcontroller/Pin.c +#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -564,8 +211,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Characteristic.c +#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c msgid "Expected a UUID" msgstr "" @@ -574,456 +221,125 @@ msgstr "" msgid "Expected tuple of length %d, got %d" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to acquire mutex" +#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c +msgid "Function requires lock" msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c -#, c-format -msgid "Failed to acquire mutex, err 0x%04x" +#: shared-module/displayio/Group.c +msgid "Group full" msgstr "" -#: ports/nrf/common-hal/bleio/Service.c -#, c-format -msgid "Failed to add characteristic, err 0x%04x" +#: shared-bindings/_pew/PewPew.c +msgid "Incorrect buffer size" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to add service" +#: shared-module/displayio/OnDiskBitmap.c +msgid "Invalid BMP file" msgstr "" -#: ports/nrf/common-hal/bleio/Peripheral.c -#, c-format -msgid "Failed to add service, err 0x%04x" +#: shared-bindings/pulseio/PWMOut.c +msgid "Invalid PWM frequency" msgstr "" -#: ports/atmel-samd/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c -msgid "Failed to allocate RX buffer" +#: shared-bindings/digitalio/DigitalInOut.c +msgid "Invalid direction." msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -#: ports/nrf/common-hal/pulseio/PulseIn.c -#: ports/esp8266/common-hal/pulseio/PulseIn.c -#, c-format -msgid "Failed to allocate RX buffer of %d bytes" +#: shared-module/audioio/WaveFile.c +msgid "Invalid file" msgstr "" -#: ports/nrf/common-hal/bleio/Adapter.c -msgid "Failed to change softdevice state" +#: shared-module/audioio/WaveFile.c +msgid "Invalid format chunk size" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to connect:" +#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +msgid "Invalid number of bits" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to continue scanning" +#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +msgid "Invalid phase" msgstr "" -#: ports/nrf/common-hal/bleio/Scanner.c -#, c-format -msgid "Failed to continue scanning, err 0x%04x" +#: shared-bindings/pulseio/PWMOut.c +msgid "Invalid pin" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to create mutex" +#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +msgid "Invalid polarity" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to discover services" +#: shared-bindings/microcontroller/__init__.c +msgid "Invalid run mode." msgstr "" -#: ports/nrf/common-hal/bleio/Adapter.c -msgid "Failed to get local address" +#: shared-module/audioio/WaveFile.c +msgid "Invalid wave file" msgstr "" -#: ports/nrf/common-hal/bleio/Adapter.c -msgid "Failed to get softdevice state" +#: shared-module/displayio/Group.c +msgid "Layer must be a Group or TileGrid subclass." msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to notify or indicate attribute value, err 0x%04x" +#: supervisor/shared/safe_mode.c +msgid "" +"Looks like our core CircuitPython code crashed hard. Whoops!\n" +"Please file an issue at https://github.com/adafruit/circuitpython/issues\n" +" with the contents of your CIRCUITPY drive and this message:\n" msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to read CCCD value, err 0x%04x" +#: shared-module/bitbangio/SPI.c +msgid "MISO pin init failed." msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to read attribute value, err 0x%04x" +#: shared-module/bitbangio/SPI.c +msgid "MOSI pin init failed." msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c +#: shared-module/displayio/Shape.c #, c-format -msgid "Failed to read gatts value, err 0x%04x" +msgid "Maximum x value when mirrored is %d" msgstr "" -#: ports/nrf/common-hal/bleio/UUID.c -#, c-format -msgid "Failed to register Vendor-Specific UUID, err 0x%04x" +#: supervisor/shared/safe_mode.c +msgid "MicroPython NLR jump failed. Likely memory corruption.\n" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to release mutex" +#: supervisor/shared/safe_mode.c +msgid "MicroPython fatal error.\n" msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c -#, c-format -msgid "Failed to release mutex, err 0x%04x" +#: shared-bindings/displayio/Display.c +msgid "Must be a Group subclass." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to start advertising" +#: supervisor/shared/board_busses.c +msgid "No default I2C bus" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -#: ports/nrf/common-hal/bleio/Peripheral.c -#, c-format -msgid "Failed to start advertising, err 0x%04x" +#: supervisor/shared/board_busses.c +msgid "No default SPI bus" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to start scanning" +#: supervisor/shared/board_busses.c +msgid "No default UART bus" msgstr "" -#: ports/nrf/common-hal/bleio/Scanner.c -#, c-format -msgid "Failed to start scanning, err 0x%04x" +#: shared-bindings/os/__init__.c +msgid "No hardware random available" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c -msgid "Failed to stop advertising" +#: shared-bindings/bleio/CharacteristicBuffer.c +msgid "Not connected" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -#: ports/nrf/common-hal/bleio/Peripheral.c -#, c-format -msgid "Failed to stop advertising, err 0x%04x" +#: shared-bindings/util.c +msgid "" +"Object has been deinitialized and can no longer be used. Create a new object." msgstr "" -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to write attribute value, err 0x%04x" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c -#, c-format -msgid "Failed to write gatts value, err 0x%04x" -msgstr "" - -#: py/moduerrno.c -msgid "File exists" -msgstr "" - -#: ports/nrf/supervisor/internal_flash.c -msgid "Flash erase failed" -msgstr "" - -#: ports/nrf/supervisor/internal_flash.c -#, c-format -msgid "Flash erase failed to start, err 0x%04x" -msgstr "" - -#: ports/nrf/supervisor/internal_flash.c -msgid "Flash write failed" -msgstr "" - -#: ports/nrf/supervisor/internal_flash.c -#, c-format -msgid "Flash write failed to start, err 0x%04x" -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -msgid "Frequency captured is above capability. Capture Paused." -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c -msgid "Function requires lock" -msgstr "" - -#: ports/esp8266/common-hal/digitalio/DigitalInOut.c -msgid "GPIO16 does not support pull up." -msgstr "" - -#: shared-module/displayio/Group.c -msgid "Group full" -msgstr "" - -#: ports/unix/file.c extmod/vfs_posix_file.c py/objstringio.c -msgid "I/O operation on closed file" -msgstr "" - -#: extmod/machine_i2c.c -msgid "I2C operation not supported" -msgstr "" - -#: py/persistentcode.c -msgid "" -"Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/" -"mpy-update for more info." -msgstr "" - -#: shared-bindings/_pew/PewPew.c -msgid "Incorrect buffer size" -msgstr "" - -#: py/moduerrno.c -msgid "Input/output error" -msgstr "" - -#: shared-module/displayio/OnDiskBitmap.c -msgid "Invalid BMP file" -msgstr "" - -#: ports/atmel-samd/common-hal/pulseio/PWMOut.c -#: ports/nrf/common-hal/pulseio/PWMOut.c shared-bindings/pulseio/PWMOut.c -msgid "Invalid PWM frequency" -msgstr "" - -#: py/moduerrno.c -msgid "Invalid argument" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -msgid "Invalid bit clock pin" -msgstr "" - -#: ports/nrf/common-hal/busio/UART.c -msgid "Invalid buffer size" -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -msgid "Invalid capture period. Valid range: 1 - 500" -msgstr "" - -#: shared-bindings/audioio/Mixer.c -msgid "Invalid channel count" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Invalid clock pin" -msgstr "Avast! Clock pin be invalid" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Invalid data pin" -msgstr "" - -#: shared-bindings/digitalio/DigitalInOut.c -msgid "Invalid direction." -msgstr "" - -#: shared-module/audioio/WaveFile.c -msgid "Invalid file" -msgstr "" - -#: shared-module/audioio/WaveFile.c -msgid "Invalid format chunk size" -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c -msgid "Invalid number of bits" -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c -msgid "Invalid phase" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -#: ports/atmel-samd/common-hal/touchio/TouchIn.c -#: shared-bindings/pulseio/PWMOut.c -msgid "Invalid pin" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Invalid pin for left channel" -msgstr "Belay that! Invalid pin for port-side channel" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Invalid pin for right channel" -msgstr "Belay that! Invalid pin for starboard-side channel" - -#: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/atmel-samd/common-hal/busio/UART.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c -msgid "Invalid pins" -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c -msgid "Invalid polarity" -msgstr "" - -#: shared-bindings/microcontroller/__init__.c -msgid "Invalid run mode." -msgstr "" - -#: shared-bindings/audioio/Mixer.c -msgid "Invalid voice count" -msgstr "" - -#: shared-module/audioio/WaveFile.c -msgid "Invalid wave file" -msgstr "" - -#: py/compile.c -msgid "LHS of keyword arg must be an id" -msgstr "" - -#: shared-module/displayio/Group.c -msgid "Layer must be a Group or TileGrid subclass." -msgstr "" - -#: py/objslice.c -msgid "Length must be an int" -msgstr "" - -#: py/objslice.c -msgid "Length must be non-negative" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"Looks like our core CircuitPython code crashed hard. Whoops!\n" -"Please file an issue at https://github.com/adafruit/circuitpython/issues\n" -" with the contents of your CIRCUITPY drive and this message:\n" -msgstr "" - -#: shared-module/bitbangio/SPI.c -msgid "MISO pin init failed." -msgstr "" - -#: shared-module/bitbangio/SPI.c -msgid "MOSI pin init failed." -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PWMOut.c -#, c-format -msgid "Maximum PWM frequency is %dhz." -msgstr "" - -#: shared-module/displayio/Shape.c -#, c-format -msgid "Maximum x value when mirrored is %d" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption.\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error.\n" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "Microphone startup delay must be in range 0.0 to 1.0" -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PWMOut.c -msgid "Minimum PWM frequency is 1hz." -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PWMOut.c -#, c-format -msgid "Multiple PWM frequencies not supported. PWM already set to %dhz." -msgstr "" - -#: shared-bindings/displayio/Display.c -msgid "Must be a Group subclass." -msgstr "" - -#: ports/atmel-samd/common-hal/analogio/AnalogOut.c -msgid "No DAC on chip" -msgstr "Shiver me timbers! There be no DAC on this chip" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "No DMA channel found" -msgstr "" - -#: ports/esp8266/common-hal/pulseio/PulseIn.c -msgid "No PulseIn support for %q" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c -msgid "No RX pin" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c -msgid "No TX pin" -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -msgid "No available clocks" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "" - -#: ports/atmel-samd/common-hal/touchio/TouchIn.c -msgid "No free GCLKs" -msgstr "" - -#: shared-bindings/os/__init__.c -msgid "No hardware random available" -msgstr "" - -#: ports/esp8266/common-hal/analogio/AnalogOut.c -msgid "No hardware support for analog out." -msgstr "" - -#: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -msgid "No hardware support on pin" -msgstr "" - -#: py/moduerrno.c -msgid "No space left on device" -msgstr "" - -#: py/moduerrno.c -msgid "No such file/directory" -msgstr "" - -#: shared-bindings/bleio/CharacteristicBuffer.c -msgid "Not connected" -msgstr "" - -#: shared-bindings/bleio/CharacteristicBuffer.c -msgid "Not connected." -msgstr "" - -#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audioio/AudioOut.c -msgid "Not playing" -msgstr "" - -#: shared-bindings/util.c -msgid "" -"Object has been deinitialized and can no longer be used. Create a new object." -msgstr "" - -#: ports/nrf/common-hal/busio/UART.c -msgid "Odd parity is not supported" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Only 8 or 16 bit mono with " -msgstr "" - -#: shared-module/displayio/OnDiskBitmap.c +#: shared-module/displayio/OnDiskBitmap.c #, c-format msgid "" "Only Windows format, uncompressed BMP supported: given header size is %d" @@ -1040,18 +356,6 @@ msgid "" "given" msgstr "" -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "Only slices with step=1 (aka None) are supported" -msgstr "" - -#: ports/esp8266/common-hal/busio/UART.c -msgid "Only tx supported on UART1 (GPIO2)." -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "Oversample must be multiple of 8." -msgstr "" - #: shared-bindings/pulseio/PWMOut.c msgid "" "PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)" @@ -1062,1751 +366,389 @@ msgid "" "PWM frequency not writable when variable_frequency is False on construction." msgstr "" -#: ports/esp8266/common-hal/pulseio/PWMOut.c ports/esp8266/machine_pwm.c -#, c-format -msgid "PWM not supported on pin %d" -msgstr "" - -#: py/moduerrno.c -msgid "Permission denied" -msgstr "" - -#: ports/esp8266/common-hal/analogio/AnalogIn.c -msgid "Pin %q does not have ADC capabilities" -msgstr "" - -#: ports/atmel-samd/common-hal/analogio/AnalogIn.c -#: ports/nrf/common-hal/analogio/AnalogIn.c -msgid "Pin does not have ADC capabilities" -msgstr "Belay that! Th' Pin be not ADC capable" - -#: ports/esp8266/machine_pin.c -msgid "Pin(16) doesn't support pull" -msgstr "" - -#: ports/esp8266/common-hal/busio/SPI.c -msgid "Pins not valid for SPI" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "Pixel beyond bounds of buffer" -msgstr "" - -#: py/builtinhelp.c -msgid "Plus any modules on the filesystem\n" -msgstr "" - #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" -#: shared-bindings/digitalio/DigitalInOut.c -msgid "Pull not used when direction is output." -msgstr "" - -#: shared-bindings/rtc/RTC.c -msgid "RTC calibration is not supported on this board" -msgstr "" - -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c -msgid "RTC is not supported on this board" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "Range out of bounds" -msgstr "" - -#: shared-bindings/pulseio/PulseIn.c -msgid "Read-only" -msgstr "" - -#: extmod/vfs_fat.c py/moduerrno.c -msgid "Read-only filesystem" -msgstr "" - -#: shared-module/displayio/Bitmap.c -msgid "Read-only object" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Right channel unsupported" -msgstr "" - -#: shared-bindings/_pew/PewPew.c -msgid "Row entry must be digitalio.DigitalInOut" -msgstr "" - -#: main.c -msgid "Running in safe mode! Auto-reload is off.\n" -msgstr "Runnin' in safe mode! Auto-reload be off.\n" - -#: main.c -msgid "Running in safe mode! Not running saved code.\n" -msgstr "Runnin' in safe mode! Nay runnin' saved code.\n" - -#: ports/atmel-samd/common-hal/busio/I2C.c -msgid "SDA or SCL needs a pull up" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "STA must be active" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "STA required" -msgstr "" - -#: shared-bindings/audioio/Mixer.c -msgid "Sample rate must be positive" -msgstr "" - -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -#, c-format -msgid "Sample rate too high. It must be less than %d" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Serializer in use" -msgstr "" - -#: shared-bindings/nvm/ByteArray.c -msgid "Slice and value different lengths." -msgstr "" - -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c -msgid "Slices not supported" -msgstr "" - -#: ports/nrf/common-hal/bleio/Adapter.c -#, c-format -msgid "Soft device assert, id: 0x%08lX, pc: 0x%08lX" -msgstr "" - -#: extmod/modure.c -msgid "Splitting with sub-captures" -msgstr "" - -#: shared-bindings/supervisor/__init__.c -msgid "Stack size must be at least 256" -msgstr "" - -#: shared-bindings/multiterminal/__init__.c -msgid "Stream missing readinto() or write() method." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"The CircuitPython heap was corrupted because the stack was too small.\n" -"Please increase stack size limits and press reset (after ejecting " -"CIRCUITPY).\n" -"If you didn't change the stack, then file an issue here with the contents of " -"your CIRCUITPY drive:\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"The microcontroller's power dipped. Please make sure your power supply " -"provides\n" -"enough power for the whole circuit and press reset (after ejecting " -"CIRCUITPY).\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"The reset button was pressed while booting CircuitPython. Press again to " -"exit safe mode.\n" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "The sample's signedness does not match the mixer's" -msgstr "" - -#: shared-bindings/displayio/TileGrid.c -msgid "Tile height must exactly divide bitmap height" -msgstr "" - -#: shared-bindings/displayio/TileGrid.c -msgid "Tile indices must be 0 - 255" -msgstr "" - -#: shared-bindings/displayio/TileGrid.c -msgid "Tile width must exactly divide bitmap width" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "To exit, please reset the board without " -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -msgid "Too many channels in sample." -msgstr "" - -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c -msgid "Too many display busses" -msgstr "" - -#: shared-bindings/displayio/Display.c -msgid "Too many displays" -msgstr "" - -#: py/obj.c -msgid "Traceback (most recent call last):\n" -msgstr "" - -#: shared-bindings/time/__init__.c -msgid "Tuple or struct_time argument required" -msgstr "" - -#: ports/esp8266/machine_uart.c -#, c-format -msgid "UART(%d) does not exist" -msgstr "" - -#: ports/esp8266/machine_uart.c -msgid "UART(1) can't read" -msgstr "" - -#: shared-module/usb_hid/Device.c -msgid "USB Busy" -msgstr "" - -#: shared-module/usb_hid/Device.c -msgid "USB Error" -msgstr "" - -#: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "" - -#: shared-bindings/bleio/UUID.c -msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" -msgstr "" - -#: shared-bindings/bleio/UUID.c -msgid "UUID value is not str, int or byte buffer" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audioio/AudioOut.c -msgid "Unable to allocate buffers for signed conversion" -msgstr "" - -#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "Unable to find free GCLK" -msgstr "Arr! No free GCLK be in sight" - -#: py/parse.c -msgid "Unable to init parser" -msgstr "" - -#: shared-module/displayio/OnDiskBitmap.c -msgid "Unable to read color palette data" -msgstr "" - -#: ports/esp8266/common-hal/storage/__init__.c -msgid "Unable to remount filesystem" -msgstr "" - -#: shared-bindings/nvm/ByteArray.c -msgid "Unable to write to nvm." -msgstr "" - -#: ports/nrf/common-hal/bleio/UUID.c -msgid "Unexpected nrfx uuid type" -msgstr "" - -#: ports/unix/modffi.c -msgid "Unknown type" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -#, c-format -msgid "Unmatched number of items on RHS (expected %d, got %d)." -msgstr "" - -#: ports/atmel-samd/common-hal/busio/I2C.c -msgid "Unsupported baudrate" -msgstr "" - -#: shared-module/displayio/Display.c -msgid "Unsupported display bus type" -msgstr "" - -#: shared-module/audioio/WaveFile.c -msgid "Unsupported format" -msgstr "" - -#: py/moduerrno.c -msgid "Unsupported operation" -msgstr "" - -#: shared-bindings/digitalio/DigitalInOut.c -msgid "Unsupported pull value." -msgstr "" - -#: ports/esp8266/common-hal/storage/__init__.c -msgid "Use esptool to erase flash and re-upload Python instead" -msgstr "" - -#: py/emitnative.c -msgid "Viper functions don't currently support more than 4 arguments" -msgstr "" - -#: shared-module/audioio/Mixer.c -msgid "Voice index too high" -msgstr "" - -#: main.c -msgid "WARNING: Your code filename has two extensions\n" -msgstr "Blimey! Yer code filename has two extensions\n" - -#: py/builtinhelp.c -#, c-format -msgid "" -"Welcome to Adafruit CircuitPython %s!\n" -"\n" -"Please visit learn.adafruit.com/category/circuitpython for project guides.\n" -"\n" -"To list built-in modules please do `help(\"modules\")`.\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "" -"You are running in safe mode which means something unanticipated happened.\n" -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "You requested starting safe mode by " -msgstr "" - -#: ports/unix/modusocket.c -#, c-format -msgid "[addrinfo error %d]" -msgstr "" - -#: py/objtype.c -msgid "__init__() should return None" -msgstr "" - -#: py/objtype.c -#, c-format -msgid "__init__() should return None, not '%s'" -msgstr "" - -#: py/objobject.c -msgid "__new__ arg must be a user-type" -msgstr "" - -#: extmod/modubinascii.c extmod/moduhashlib.c -msgid "a bytes-like object is required" -msgstr "" - -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "" - -#: ports/unix/modmachine.c extmod/machine_mem.c -#, c-format -msgid "address %08x is not aligned to %d bytes" -msgstr "" - -#: shared-bindings/i2cslave/I2CSlave.c -msgid "address out of bounds" -msgstr "" - -#: shared-bindings/i2cslave/I2CSlave.c -msgid "addresses is empty" -msgstr "" - -#: py/modbuiltins.c -msgid "arg is an empty sequence" -msgstr "" - -#: py/runtime.c -msgid "argument has wrong type" -msgstr "" - -#: py/argcheck.c -msgid "argument num/types mismatch" -msgstr "" - -#: py/runtime.c -msgid "argument should be a '%q' not a '%q'" -msgstr "" - -#: shared-bindings/nvm/ByteArray.c py/objarray.c -msgid "array/bytes required on right side" -msgstr "" - -#: py/objstr.c -msgid "attributes not supported yet" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c -msgid "bad GATT role" -msgstr "" - -#: py/builtinevex.c -msgid "bad compile mode" -msgstr "" - -#: py/objstr.c -msgid "bad conversion specifier" -msgstr "" - -#: py/objstr.c -msgid "bad format string" -msgstr "" - -#: py/binary.c -msgid "bad typecode" -msgstr "" - -#: py/emitnative.c -msgid "binary op %q not implemented" -msgstr "" - -#: shared-bindings/busio/UART.c -msgid "bits must be 7, 8 or 9" -msgstr "" - -#: extmod/machine_spi.c -msgid "bits must be 8" -msgstr "pieces must be of 8" - -#: shared-bindings/audioio/Mixer.c -msgid "bits_per_sample must be 8 or 16" -msgstr "" - -#: py/emitinlinethumb.c -msgid "branch not in range" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -#, c-format -msgid "buf is too small. need %d bytes" -msgstr "" - -#: shared-bindings/audioio/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - -#: shared-module/struct/__init__.c -msgid "buffer size must match format" -msgstr "" - -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c -msgid "buffer slices must be of equal length" -msgstr "" - -#: ports/esp8266/machine_rtc.c -msgid "buffer too long" -msgstr "" - -#: shared-bindings/struct/__init__.c shared-module/struct/__init__.c -#: py/modstruct.c -msgid "buffer too small" -msgstr "" - -#: extmod/machine_spi.c -msgid "buffers must be the same length" -msgstr "yer buffers must be of the same length" - -#: shared-bindings/_pew/PewPew.c -msgid "buttons must be digitalio.DigitalInOut" -msgstr "" - -#: py/vm.c -msgid "byte code not implemented" -msgstr "" - -#: shared-bindings/_pixelbuf/PixelBuf.c -#, c-format -msgid "byteorder is not an instance of ByteOrder (got a %s)" -msgstr "" - -#: ports/atmel-samd/common-hal/busio/UART.c -msgid "bytes > 8 bits not supported" -msgstr "" - -#: py/objstr.c -msgid "bytes value out of range" -msgstr "" - -#: ports/atmel-samd/bindings/samd/Clock.c -msgid "calibration is out of range" -msgstr "" - -#: ports/atmel-samd/bindings/samd/Clock.c -msgid "calibration is read only" -msgstr "" - -#: ports/atmel-samd/common-hal/rtc/RTC.c -msgid "calibration value out of range +/-127" -msgstr "" - -#: py/emitinlinethumb.c -msgid "can only have up to 4 parameters to Thumb assembly" -msgstr "" - -#: py/emitinlinextensa.c -msgid "can only have up to 4 parameters to Xtensa assembly" -msgstr "" - -#: py/persistentcode.c -msgid "can only save bytecode" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can query only one param" -msgstr "" - -#: py/objtype.c -msgid "can't add special method to already-subclassed class" -msgstr "" - -#: py/compile.c -msgid "can't assign to expression" -msgstr "" - -#: py/obj.c -#, c-format -msgid "can't convert %s to complex" -msgstr "" - -#: py/obj.c -#, c-format -msgid "can't convert %s to float" -msgstr "" - -#: py/obj.c -#, c-format -msgid "can't convert %s to int" -msgstr "" - -#: py/objstr.c -msgid "can't convert '%q' object to %q implicitly" -msgstr "" - -#: py/objint.c -msgid "can't convert NaN to int" -msgstr "" - -#: shared-bindings/i2cslave/I2CSlave.c -msgid "can't convert address to int" -msgstr "" - -#: py/objint.c -msgid "can't convert inf to int" -msgstr "" - -#: py/obj.c -msgid "can't convert to complex" -msgstr "" - -#: py/obj.c -msgid "can't convert to float" -msgstr "" - -#: py/obj.c -msgid "can't convert to int" -msgstr "" - -#: py/objstr.c -msgid "can't convert to str implicitly" -msgstr "" - -#: py/compile.c -msgid "can't declare nonlocal in outer code" -msgstr "" - -#: py/compile.c -msgid "can't delete expression" -msgstr "" - -#: py/emitnative.c -msgid "can't do binary op between '%q' and '%q'" -msgstr "" - -#: py/objcomplex.c -msgid "can't do truncated division of a complex number" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can't get AP config" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can't get STA config" -msgstr "" - -#: py/compile.c -msgid "can't have multiple **x" -msgstr "" - -#: py/compile.c -msgid "can't have multiple *x" -msgstr "" - -#: py/emitnative.c -msgid "can't implicitly convert '%q' to 'bool'" -msgstr "" - -#: py/emitnative.c -msgid "can't load from '%q'" -msgstr "" - -#: py/emitnative.c -msgid "can't load with '%q' index" -msgstr "" - -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - -#: py/objgenerator.c -msgid "can't send non-None value to a just-started generator" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can't set AP config" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "can't set STA config" -msgstr "" - -#: py/objnamedtuple.c -msgid "can't set attribute" -msgstr "" - -#: py/emitnative.c -msgid "can't store '%q'" -msgstr "" - -#: py/emitnative.c -msgid "can't store to '%q'" -msgstr "" - -#: py/emitnative.c -msgid "can't store with '%q' index" -msgstr "" - -#: py/objstr.c -msgid "" -"can't switch from automatic field numbering to manual field specification" -msgstr "" - -#: py/objstr.c -msgid "" -"can't switch from manual field specification to automatic field numbering" -msgstr "" - -#: py/objtype.c -msgid "cannot create '%q' instances" -msgstr "" - -#: py/objtype.c -msgid "cannot create instance" -msgstr "" - -#: py/runtime.c -msgid "cannot import name %q" -msgstr "" - -#: py/builtinimport.c -msgid "cannot perform relative import" -msgstr "" - -#: py/emitnative.c -msgid "casting" -msgstr "" - -#: shared-bindings/bleio/Service.c -msgid "characteristics includes an object that is not a Characteristic" -msgstr "" - -#: shared-bindings/_stage/Text.c -msgid "chars buffer too small" -msgstr "" - -#: py/modbuiltins.c -msgid "chr() arg not in range(0x110000)" -msgstr "" - -#: py/modbuiltins.c -msgid "chr() arg not in range(256)" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "color buffer must be a buffer or int" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "color buffer must be a bytearray or array of type 'b' or 'B'" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "color must be between 0x000000 and 0xffffff" -msgstr "" - -#: shared-bindings/displayio/ColorConverter.c -msgid "color should be an int" -msgstr "" - -#: py/objcomplex.c -msgid "complex division by zero" -msgstr "" - -#: py/parsenum.c py/objfloat.c -msgid "complex values not supported" -msgstr "" - -#: extmod/moduzlib.c -msgid "compression header" -msgstr "" - -#: py/parse.c -msgid "constant must be an integer" -msgstr "" - -#: py/emitnative.c -msgid "conversion to object" -msgstr "" - -#: py/parsenum.c -msgid "decimal numbers not supported" -msgstr "" - -#: py/compile.c -msgid "default 'except' must be last" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "" -"destination buffer must be a bytearray or array of type 'B' for bit_depth = 8" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "destination buffer must be an array of type 'H' for bit_depth = 16" -msgstr "" - -#: shared-bindings/audiobusio/PDMIn.c -msgid "destination_length must be an int >= 0" -msgstr "" - -#: py/objdict.c -msgid "dict update sequence has wrong length" -msgstr "" - -#: shared-bindings/math/__init__.c py/runtime.c py/modmath.c py/objint_mpz.c -#: py/objint_longlong.c py/objfloat.c -msgid "division by zero" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "either pos or kw args are allowed" -msgstr "" - -#: py/objdeque.c -msgid "empty" -msgstr "" - -#: extmod/modutimeq.c extmod/moduheapq.c -msgid "empty heap" -msgstr "" - -#: py/objstr.c -msgid "empty separator" -msgstr "" - -#: shared-bindings/random/__init__.c -msgid "empty sequence" -msgstr "" - -#: py/objstr.c -msgid "end of format while looking for conversion specifier" -msgstr "" - -#: shared-bindings/displayio/Shape.c -msgid "end_x should be an int" -msgstr "" - -#: ports/nrf/common-hal/busio/UART.c -#, c-format -msgid "error = 0x%08lX" -msgstr "" - -#: py/runtime.c -msgid "exceptions must derive from BaseException" -msgstr "" - -#: py/objstr.c -msgid "expected ':' after format specifier" -msgstr "" - -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "" - -#: py/obj.c -msgid "expected tuple/list" -msgstr "" - -#: py/modthread.c -msgid "expecting a dict for keyword args" -msgstr "" - -#: ports/esp8266/machine_pin.c -msgid "expecting a pin" -msgstr "" - -#: py/compile.c -msgid "expecting an assembler instruction" -msgstr "" - -#: py/compile.c -msgid "expecting just a value for set" -msgstr "" - -#: py/compile.c -msgid "expecting key:value for dict" -msgstr "" - -#: py/argcheck.c -msgid "extra keyword arguments given" -msgstr "" - -#: py/argcheck.c -msgid "extra positional arguments given" -msgstr "" - -#: ports/unix/modffi.c -msgid "ffi_prep_closure_loc" -msgstr "" - -#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c -msgid "file must be a file opened in byte mode" -msgstr "" - -#: shared-bindings/storage/__init__.c -msgid "filesystem must provide mount method" -msgstr "" - -#: py/objtype.c -msgid "first argument to super() must be type" -msgstr "" - -#: extmod/machine_spi.c -msgid "firstbit must be MSB" -msgstr "" - -#: ports/esp8266/modesp.c -msgid "flash location must be below 1MByte" -msgstr "" - -#: py/objint.c -msgid "float too big" -msgstr "" - -#: shared-bindings/_stage/Text.c -msgid "font must be 2048 bytes long" -msgstr "" - -#: py/objstr.c -msgid "format requires a dict" -msgstr "" - -#: ports/esp8266/modmachine.c -msgid "frequency can only be either 80Mhz or 160MHz" -msgstr "" - -#: py/objdeque.c -msgid "full" -msgstr "" - -#: py/argcheck.c -msgid "function does not take keyword arguments" -msgstr "" - -#: py/argcheck.c -#, c-format -msgid "function expected at most %d arguments, got %d" -msgstr "" - -#: py/objnamedtuple.c py/bc.c -msgid "function got multiple values for argument '%q'" -msgstr "" - -#: py/argcheck.c -#, c-format -msgid "function missing %d required positional arguments" -msgstr "" - -#: py/bc.c -msgid "function missing keyword-only argument" -msgstr "" - -#: py/bc.c -msgid "function missing required keyword argument '%q'" -msgstr "" - -#: py/bc.c -#, c-format -msgid "function missing required positional argument #%d" -msgstr "" - -#: py/argcheck.c py/objnamedtuple.c py/bc.c -#, c-format -msgid "function takes %d positional arguments but %d were given" -msgstr "" - -#: shared-bindings/time/__init__.c -msgid "function takes exactly 9 arguments" -msgstr "" - -#: py/objgenerator.c -msgid "generator already executing" -msgstr "" - -#: py/objgenerator.c -msgid "generator ignored GeneratorExit" -msgstr "" - -#: shared-bindings/_stage/Layer.c -msgid "graphic must be 2048 bytes long" -msgstr "" - -#: extmod/moduheapq.c -msgid "heap must be a list" -msgstr "" - -#: py/compile.c -msgid "identifier redefined as global" -msgstr "" - -#: py/compile.c -msgid "identifier redefined as nonlocal" -msgstr "" - -#: ports/esp8266/machine_hspi.c -msgid "impossible baudrate" -msgstr "" - -#: py/objstr.c -msgid "incomplete format" -msgstr "" - -#: py/objstr.c -msgid "incomplete format key" -msgstr "" - -#: extmod/modubinascii.c -msgid "incorrect padding" -msgstr "" - -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -#: ports/nrf/common-hal/pulseio/PulseIn.c -#: ports/esp8266/common-hal/pulseio/PulseIn.c py/obj.c -msgid "index out of range" -msgstr "" - -#: py/obj.c -msgid "indices must be integers" -msgstr "" - -#: py/compile.c -msgid "inline assembler must be a function" -msgstr "" - -#: py/parsenum.c -msgid "int() arg 2 must be >= 2 and <= 36" -msgstr "" - -#: py/objstr.c -msgid "integer required" -msgstr "" - -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "" - -#: extmod/machine_i2c.c -msgid "invalid I2C peripheral" -msgstr "Belay that! I2C peripheral be invalid" - -#: extmod/machine_spi.c -msgid "invalid SPI peripheral" -msgstr "Arr! SPI peripheral be invalid" - -#: ports/esp8266/machine_rtc.c -msgid "invalid alarm" -msgstr "" - -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "" - -#: ports/esp8266/modnetwork.c -msgid "invalid buffer length" -msgstr "" - -#: extmod/modussl_axtls.c -msgid "invalid cert" -msgstr "" - -#: ports/esp8266/common-hal/busio/UART.c ports/esp8266/machine_uart.c -msgid "invalid data bits" -msgstr "" - -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "" - -#: extmod/modframebuf.c -msgid "invalid format" -msgstr "" - -#: py/objstr.c -msgid "invalid format specifier" -msgstr "" - -#: extmod/modussl_axtls.c -msgid "invalid key" -msgstr "" - -#: py/compile.c -msgid "invalid micropython decorator" -msgstr "" - -#: ports/esp8266/machine_pin.c -msgid "invalid pin" -msgstr "" - -#: shared-bindings/random/__init__.c -msgid "invalid step" -msgstr "" - -#: ports/esp8266/common-hal/busio/UART.c ports/esp8266/machine_uart.c -msgid "invalid stop bits" -msgstr "" - -#: py/compile.c py/parse.c -msgid "invalid syntax" -msgstr "" - -#: py/parsenum.c -msgid "invalid syntax for integer" -msgstr "" - -#: py/parsenum.c -#, c-format -msgid "invalid syntax for integer with base %d" -msgstr "" - -#: py/parsenum.c -msgid "invalid syntax for number" -msgstr "" - -#: py/objtype.c -msgid "issubclass() arg 1 must be a class" -msgstr "" - -#: py/objtype.c -msgid "issubclass() arg 2 must be a class or a tuple of classes" -msgstr "" - -#: py/objstr.c -msgid "join expects a list of str/bytes objects consistent with self object" -msgstr "" - -#: py/argcheck.c -msgid "keyword argument(s) not yet implemented - use normal args instead" -msgstr "" - -#: py/bc.c -msgid "keywords must be strings" -msgstr "" - -#: py/emitinlinextensa.c py/emitinlinethumb.c -msgid "label '%q' not defined" -msgstr "" - -#: py/compile.c -msgid "label redefined" -msgstr "" - -#: ports/esp8266/modesp.c -msgid "len must be multiple of 4" -msgstr "" - -#: py/stream.c -msgid "length argument not allowed for this type" -msgstr "" - -#: py/objarray.c -msgid "lhs and rhs should be compatible" -msgstr "" - -#: py/emitnative.c -msgid "local '%q' has type '%q' but source is '%q'" -msgstr "" - -#: py/emitnative.c -msgid "local '%q' used before type known" -msgstr "" - -#: py/vm.c -msgid "local variable referenced before assignment" -msgstr "" - -#: py/objint.c -msgid "long int not supported in this build" -msgstr "" - -#: shared-bindings/_stage/Layer.c -msgid "map buffer too small" -msgstr "" - -#: shared-bindings/math/__init__.c py/modmath.c -msgid "math domain error" -msgstr "" - -#: py/runtime.c -msgid "maximum recursion depth exceeded" -msgstr "" - -#: py/runtime.c -#, c-format -msgid "memory allocation failed, allocating %u bytes" -msgstr "" - -#: ports/esp8266/modesp.c -#, c-format -msgid "memory allocation failed, allocating %u bytes for native code" -msgstr "" - -#: py/runtime.c -msgid "memory allocation failed, heap is locked" -msgstr "" - -#: py/builtinimport.c -msgid "module not found" -msgstr "" - -#: py/compile.c -msgid "multiple *x in assignment" -msgstr "" - -#: py/objtype.c -msgid "multiple bases have instance lay-out conflict" -msgstr "" - -#: py/objtype.c -msgid "multiple inheritance not supported" -msgstr "" - -#: py/emitnative.c -msgid "must raise an object" -msgstr "" - -#: extmod/machine_spi.c -msgid "must specify all of sck/mosi/miso" -msgstr "" - -#: py/modbuiltins.c -msgid "must use keyword argument for key function" -msgstr "" - -#: py/runtime.c -msgid "name '%q' is not defined" -msgstr "" - -#: shared-bindings/bleio/Peripheral.c -msgid "name must be a string" -msgstr "" - -#: py/runtime.c -msgid "name not defined" -msgstr "" - -#: py/compile.c -msgid "name reused for argument" -msgstr "" - -#: py/emitnative.c -msgid "native yield" -msgstr "" - -#: py/runtime.c -#, c-format -msgid "need more than %d values to unpack" -msgstr "" - -#: py/runtime.c py/objint_mpz.c py/objint_longlong.c -msgid "negative power with no float support" -msgstr "" - -#: py/runtime.c py/objint_mpz.c -msgid "negative shift count" -msgstr "" - -#: py/vm.c -msgid "no active exception to reraise" -msgstr "" - -#: shared-bindings/socket/__init__.c shared-module/network/__init__.c -msgid "no available NIC" -msgstr "" - -#: py/compile.c -msgid "no binding for nonlocal found" -msgstr "" - -#: py/builtinimport.c -msgid "no module named '%q'" -msgstr "" - -#: shared-bindings/_pixelbuf/__init__.c py/runtime.c -msgid "no such attribute" -msgstr "" - -#: py/compile.c -msgid "non-default argument follows default argument" -msgstr "" - -#: extmod/modubinascii.c -msgid "non-hex digit found" -msgstr "" - -#: py/compile.c -msgid "non-keyword arg after */**" -msgstr "" - -#: py/compile.c -msgid "non-keyword arg after keyword arg" -msgstr "" - -#: shared-bindings/bleio/UUID.c -msgid "not a 128-bit UUID" -msgstr "" - -#: ports/esp8266/machine_adc.c -#, c-format -msgid "not a valid ADC Channel: %d" -msgstr "" - -#: py/objstr.c -msgid "not all arguments converted during string formatting" -msgstr "" - -#: py/objstr.c -msgid "not enough arguments for format string" -msgstr "" - -#: py/obj.c -#, c-format -msgid "object '%s' is not a tuple or list" -msgstr "" - -#: py/obj.c -msgid "object does not support item assignment" -msgstr "" - -#: py/obj.c -msgid "object does not support item deletion" -msgstr "" - -#: py/obj.c -msgid "object has no len" -msgstr "" - -#: py/obj.c -msgid "object is not subscriptable" -msgstr "" - -#: py/runtime.c -msgid "object not an iterator" -msgstr "" - -#: py/objtype.c py/runtime.c -msgid "object not callable" -msgstr "" - -#: py/sequence.c -msgid "object not in sequence" -msgstr "" - -#: py/runtime.c -msgid "object not iterable" -msgstr "" - -#: py/obj.c -#, c-format -msgid "object of type '%s' has no len()" -msgstr "" - -#: py/obj.c -msgid "object with buffer protocol required" -msgstr "" - -#: extmod/modubinascii.c -msgid "odd-length string" -msgstr "" - -#: py/objstrunicode.c py/objstr.c -msgid "offset out of bounds" -msgstr "" - -#: shared-bindings/nvm/ByteArray.c py/objarray.c py/objtuple.c -#: py/objstrunicode.c py/objstr.c -msgid "only slices with step=1 (aka None) are supported" -msgstr "" - -#: py/modbuiltins.c -msgid "ord expects a character" -msgstr "" - -#: py/modbuiltins.c -#, c-format -msgid "ord() expected a character, but string of length %d found" -msgstr "" - -#: py/objint_mpz.c -msgid "overflow converting long int to machine word" -msgstr "" - -#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c -msgid "palette must be 32 bytes long" -msgstr "" - -#: shared-bindings/displayio/Palette.c -msgid "palette_index should be an int" -msgstr "" - -#: py/compile.c -msgid "parameter annotation must be an identifier" -msgstr "" - -#: py/emitinlinextensa.c -msgid "parameters must be registers in sequence a2 to a5" -msgstr "" - -#: py/emitinlinethumb.c -msgid "parameters must be registers in sequence r0 to r3" -msgstr "" - -#: ports/esp8266/machine_pin.c -msgid "pin does not have IRQ capabilities" -msgstr "" - -#: shared-bindings/displayio/Bitmap.c -msgid "pixel coordinates out of bounds" -msgstr "" - -#: shared-bindings/displayio/Bitmap.c -msgid "pixel value requires too many bits" -msgstr "" - -#: shared-bindings/displayio/TileGrid.c -msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter" -msgstr "" - -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c -#: ports/nrf/common-hal/pulseio/PulseIn.c -#: ports/esp8266/common-hal/pulseio/PulseIn.c -msgid "pop from an empty PulseIn" +#: shared-bindings/digitalio/DigitalInOut.c +msgid "Pull not used when direction is output." msgstr "" -#: py/objset.c -msgid "pop from an empty set" +#: shared-bindings/rtc/RTC.c +msgid "RTC calibration is not supported on this board" msgstr "" -#: py/objlist.c -msgid "pop from empty list" +#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +msgid "RTC is not supported on this board" msgstr "" -#: py/objdict.c -msgid "popitem(): dictionary is empty" +#: shared-bindings/rtc/RTC.c +msgid "RTC set is not supported on this board" msgstr "" -#: py/objint_mpz.c -msgid "pow() 3rd argument cannot be 0" +#: shared-bindings/pulseio/PulseIn.c +msgid "Read-only" msgstr "" -#: py/objint_mpz.c -msgid "pow() with 3 arguments requires integers" +#: shared-module/displayio/Bitmap.c +msgid "Read-only object" msgstr "" -#: extmod/modutimeq.c -msgid "queue overflow" +#: shared-bindings/_pew/PewPew.c +msgid "Row entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "rawbuf is not the same size as buf" -msgstr "" +#: main.c +msgid "Running in safe mode! Auto-reload is off.\n" +msgstr "Runnin' in safe mode! Auto-reload be off.\n" -#: shared-bindings/_pixelbuf/__init__.c -msgid "readonly attribute" -msgstr "" +#: main.c +msgid "Running in safe mode! Not running saved code.\n" +msgstr "Runnin' in safe mode! Nay runnin' saved code.\n" -#: py/builtinimport.c -msgid "relative import" +#: shared-bindings/nvm/ByteArray.c +msgid "Slice and value different lengths." msgstr "" -#: py/obj.c -#, c-format -msgid "requested length %d but object has length %d" +#: shared-bindings/displayio/Group.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +msgid "Slices not supported" msgstr "" -#: py/compile.c -msgid "return annotation must be an identifier" +#: shared-bindings/supervisor/__init__.c +msgid "Stack size must be at least 256" msgstr "" -#: py/emitnative.c -msgid "return expected '%q' but got '%q'" +#: shared-bindings/multiterminal/__init__.c +msgid "Stream missing readinto() or write() method." msgstr "" -#: shared-module/displayio/Bitmap.c -msgid "row must be packed and word aligned" +#: supervisor/shared/safe_mode.c +msgid "" +"The CircuitPython heap was corrupted because the stack was too small.\n" +"Please increase stack size limits and press reset (after ejecting " +"CIRCUITPY).\n" +"If you didn't change the stack, then file an issue here with the contents of " +"your CIRCUITPY drive:\n" msgstr "" -#: py/objstr.c -msgid "rsplit(None,n)" +#: supervisor/shared/safe_mode.c +msgid "" +"The microcontroller's power dipped. Please make sure your power supply " +"provides\n" +"enough power for the whole circuit and press reset (after ejecting " +"CIRCUITPY).\n" msgstr "" -#: shared-bindings/audioio/RawSample.c +#: supervisor/shared/safe_mode.c msgid "" -"sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or " -"'B'" +"The reset button was pressed while booting CircuitPython. Press again to " +"exit safe mode.\n" msgstr "" -#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c -msgid "sampling rate out of range" +#: shared-module/audioio/Mixer.c +msgid "The sample's bits_per_sample does not match the mixer's" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "scan failed" +#: shared-module/audioio/Mixer.c +msgid "The sample's channel count does not match the mixer's" msgstr "" -#: py/modmicropython.c -msgid "schedule stack full" +#: shared-module/audioio/Mixer.c +msgid "The sample's sample rate does not match the mixer's" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c -msgid "script compilation not supported" +#: shared-module/audioio/Mixer.c +msgid "The sample's signedness does not match the mixer's" msgstr "" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile height must exactly divide bitmap height" msgstr "" -#: py/objstr.c -msgid "sign not allowed in string format specifier" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile indices must be 0 - 255" msgstr "" -#: py/objstr.c -msgid "sign not allowed with integer format specifier 'c'" +#: shared-bindings/displayio/TileGrid.c +msgid "Tile width must exactly divide bitmap width" msgstr "" -#: py/objstr.c -msgid "single '}' encountered in format string" +#: supervisor/shared/safe_mode.c +msgid "To exit, please reset the board without " msgstr "" -#: shared-bindings/time/__init__.c -msgid "sleep length must be non-negative" +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c +msgid "Too many display busses" msgstr "" -#: py/objslice.c py/sequence.c -msgid "slice step cannot be zero" +#: shared-bindings/displayio/Display.c +msgid "Too many displays" msgstr "" -#: py/sequence.c py/objint.c -msgid "small int overflow" +#: shared-bindings/time/__init__.c +msgid "Tuple or struct_time argument required" msgstr "" -#: main.c -msgid "soft reboot\n" +#: shared-module/usb_hid/Device.c +msgid "USB Busy" msgstr "" -#: py/objstr.c -msgid "start/end indices" +#: shared-module/usb_hid/Device.c +msgid "USB Error" msgstr "" -#: shared-bindings/displayio/Shape.c -msgid "start_x should be an int" +#: shared-bindings/bleio/UUID.c +msgid "UUID integer value not in range 0 to 0xffff" msgstr "" -#: shared-bindings/random/__init__.c -msgid "step must be non-zero" +#: shared-bindings/bleio/UUID.c +msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" msgstr "" -#: shared-bindings/busio/UART.c -msgid "stop must be 1 or 2" +#: shared-bindings/bleio/UUID.c +msgid "UUID value is not str, int or byte buffer" msgstr "" -#: shared-bindings/random/__init__.c -msgid "stop not reachable from start" +#: shared-module/displayio/OnDiskBitmap.c +msgid "Unable to read color palette data" msgstr "" -#: py/stream.c -msgid "stream operation not supported" +#: shared-bindings/nvm/ByteArray.c +msgid "Unable to write to nvm." msgstr "" -#: py/objstrunicode.c -msgid "string index out of range" +#: shared-module/displayio/Display.c +msgid "Unsupported display bus type" msgstr "" -#: py/objstrunicode.c -#, c-format -msgid "string indices must be integers, not %s" +#: shared-module/audioio/WaveFile.c +msgid "Unsupported format" msgstr "" -#: py/stream.c -msgid "string not supported; use bytes or bytearray" +#: shared-bindings/digitalio/DigitalInOut.c +msgid "Unsupported pull value." msgstr "" -#: extmod/moductypes.c -msgid "struct: cannot index" +#: shared-module/audioio/Mixer.c +msgid "Voice index too high" msgstr "" -#: extmod/moductypes.c -msgid "struct: index out of range" +#: main.c +msgid "WARNING: Your code filename has two extensions\n" +msgstr "Blimey! Yer code filename has two extensions\n" + +#: supervisor/shared/safe_mode.c +msgid "" +"You are running in safe mode which means something unanticipated happened.\n" msgstr "" -#: extmod/moductypes.c -msgid "struct: no fields" +#: supervisor/shared/safe_mode.c +msgid "You requested starting safe mode by " msgstr "" -#: py/objstr.c -msgid "substring not found" +#: shared-bindings/i2cslave/I2CSlave.c +msgid "address out of bounds" msgstr "" -#: py/compile.c -msgid "super() can't find self" +#: shared-bindings/i2cslave/I2CSlave.c +msgid "addresses is empty" msgstr "" -#: extmod/modujson.c -msgid "syntax error in JSON" +#: shared-bindings/nvm/ByteArray.c +msgid "array/bytes required on right side" msgstr "" -#: extmod/moductypes.c -msgid "syntax error in uctypes descriptor" +#: shared-bindings/busio/UART.c +msgid "bits must be 7, 8 or 9" msgstr "" -#: shared-bindings/touchio/TouchIn.c -msgid "threshold must be in the range 0-65536" +#: shared-module/struct/__init__.c +msgid "buffer size must match format" msgstr "" -#: shared-bindings/displayio/TileGrid.c -msgid "tile index out of bounds" +#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +msgid "buffer slices must be of equal length" msgstr "" -#: shared-bindings/time/__init__.c -msgid "time.struct_time() takes a 9-sequence" +#: shared-bindings/struct/__init__.c shared-module/struct/__init__.c +msgid "buffer too small" msgstr "" -#: shared-bindings/time/__init__.c -msgid "time.struct_time() takes exactly 1 argument" +#: shared-bindings/_pew/PewPew.c +msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/busio/UART.c -msgid "timeout >100 (units are now seconds, not msecs)" +#: shared-bindings/i2cslave/I2CSlave.c +msgid "can't convert address to int" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c -msgid "timeout must be >= 0.0" +#: shared-bindings/bleio/Service.c +msgid "characteristics includes an object that is not a Characteristic" msgstr "" -#: shared-bindings/time/__init__.c -msgid "timestamp out of range for platform time_t" +#: shared-bindings/displayio/Palette.c +msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" +#: shared-bindings/displayio/Palette.c +msgid "color buffer must be a buffer or int" msgstr "" -#: shared-module/struct/__init__.c -msgid "too many arguments provided with the given format" +#: shared-bindings/displayio/Palette.c +msgid "color buffer must be a bytearray or array of type 'b' or 'B'" msgstr "" -#: py/runtime.c -#, c-format -msgid "too many values to unpack (expected %d)" +#: shared-bindings/displayio/Palette.c +msgid "color must be between 0x000000 and 0xffffff" msgstr "" -#: py/objstr.c -msgid "tuple index out of range" +#: shared-bindings/displayio/ColorConverter.c +msgid "color should be an int" msgstr "" -#: py/obj.c -msgid "tuple/list has wrong length" +#: shared-bindings/math/__init__.c +msgid "division by zero" msgstr "" -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "tuple/list required on RHS" +#: shared-bindings/random/__init__.c +msgid "empty sequence" msgstr "" -#: ports/atmel-samd/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c -msgid "tx and rx cannot both be None" +#: shared-bindings/displayio/Shape.c +msgid "end_x should be an int" msgstr "" -#: py/objtype.c -msgid "type '%q' is not an acceptable base type" +#: shared-bindings/gamepad/GamePad.c +msgid "expected a DigitalInOut" msgstr "" -#: py/objtype.c -msgid "type is not an acceptable base type" +#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +msgid "file must be a file opened in byte mode" msgstr "" -#: py/runtime.c -msgid "type object '%q' has no attribute '%q'" +#: shared-bindings/storage/__init__.c +msgid "filesystem must provide mount method" msgstr "" -#: py/objtype.c -msgid "type takes 1 or 3 arguments" +#: shared-bindings/time/__init__.c +msgid "function takes exactly 9 arguments" msgstr "" -#: py/objint_longlong.c -msgid "ulonglong too large" +#: shared-bindings/random/__init__.c +msgid "invalid step" msgstr "" -#: py/emitnative.c -msgid "unary op %q not implemented" +#: shared-bindings/math/__init__.c +msgid "math domain error" msgstr "" -#: py/parse.c -msgid "unexpected indent" +#: shared-bindings/bleio/Peripheral.c +msgid "name must be a string" msgstr "" -#: py/bc.c -msgid "unexpected keyword argument" +#: shared-bindings/socket/__init__.c shared-module/network/__init__.c +msgid "no available NIC" msgstr "" -#: py/objnamedtuple.c py/bc.c -msgid "unexpected keyword argument '%q'" +#: shared-bindings/bleio/UUID.c +msgid "not a 128-bit UUID" msgstr "" -#: py/lexer.c -msgid "unicode name escapes" +#: shared-bindings/nvm/ByteArray.c +msgid "only slices with step=1 (aka None) are supported" msgstr "" -#: py/parse.c -msgid "unindent does not match any outer indentation level" +#: shared-bindings/displayio/Palette.c +msgid "palette_index should be an int" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "unknown config param" +#: shared-bindings/displayio/Bitmap.c +msgid "pixel coordinates out of bounds" msgstr "" -#: py/objstr.c -#, c-format -msgid "unknown conversion specifier %c" +#: shared-bindings/displayio/Bitmap.c +msgid "pixel value requires too many bits" msgstr "" -#: py/objstr.c -#, c-format -msgid "unknown format code '%c' for object of type '%s'" +#: shared-bindings/displayio/TileGrid.c +msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter" msgstr "" -#: py/objstr.c -#, c-format -msgid "unknown format code '%c' for object of type 'float'" +#: shared-module/displayio/Bitmap.c +msgid "row must be packed and word aligned" msgstr "" -#: py/objstr.c -#, c-format -msgid "unknown format code '%c' for object of type 'str'" +#: shared-bindings/bleio/Peripheral.c +msgid "services includes an object that is not a Service" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "unknown status param" +#: shared-bindings/time/__init__.c +msgid "sleep length must be non-negative" msgstr "" -#: py/compile.c -msgid "unknown type" +#: main.c +msgid "soft reboot\n" msgstr "" -#: py/emitnative.c -msgid "unknown type '%q'" +#: shared-bindings/displayio/Shape.c +msgid "start_x should be an int" msgstr "" -#: py/objstr.c -msgid "unmatched '{' in format" +#: shared-bindings/random/__init__.c +msgid "step must be non-zero" msgstr "" -#: py/objtype.c py/runtime.c -msgid "unreadable attribute" +#: shared-bindings/busio/UART.c +msgid "stop must be 1 or 2" msgstr "" -#: py/emitinlinethumb.c -#, c-format -msgid "unsupported Thumb instruction '%s' with %d arguments" +#: shared-bindings/random/__init__.c +msgid "stop not reachable from start" msgstr "" -#: py/emitinlinextensa.c -#, c-format -msgid "unsupported Xtensa instruction '%s' with %d arguments" +#: shared-bindings/touchio/TouchIn.c +msgid "threshold must be in the range 0-65536" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "tile index out of bounds" msgstr "" -#: py/objstr.c -#, c-format -msgid "unsupported format character '%c' (0x%x) at index %d" +#: shared-bindings/time/__init__.c +msgid "time.struct_time() takes a 9-sequence" msgstr "" -#: py/runtime.c -msgid "unsupported type for %q: '%s'" +#: shared-bindings/time/__init__.c +msgid "time.struct_time() takes exactly 1 argument" msgstr "" -#: py/runtime.c -msgid "unsupported type for operator" +#: shared-bindings/busio/UART.c +msgid "timeout >100 (units are now seconds, not msecs)" msgstr "" -#: py/runtime.c -msgid "unsupported types for %q: '%s', '%s'" +#: shared-bindings/bleio/CharacteristicBuffer.c +msgid "timeout must be >= 0.0" msgstr "" -#: shared-bindings/displayio/Bitmap.c -msgid "value_count must be > 0" +#: shared-bindings/time/__init__.c +msgid "timestamp out of range for platform time_t" msgstr "" -#: ports/esp8266/modnetwork.c -msgid "wifi_set_ip_info() failed" +#: shared-bindings/gamepad/GamePad.c +msgid "too many arguments" msgstr "" -#: shared-bindings/_pixelbuf/PixelBuf.c -msgid "write_args must be a list, tuple, or None" +#: shared-module/struct/__init__.c +msgid "too many arguments provided with the given format" msgstr "" -#: py/objstr.c -msgid "wrong number of arguments" +#: shared-bindings/displayio/TileGrid.c +msgid "unsupported bitmap type" msgstr "" -#: py/runtime.c -msgid "wrong number of values to unpack" +#: shared-bindings/displayio/Bitmap.c +msgid "value_count must be > 0" msgstr "" #: shared-module/displayio/Shape.c @@ -2821,9 +763,8 @@ msgstr "" msgid "y value out of bounds" msgstr "" -#: py/objrange.c -msgid "zero step" -msgstr "" +#~ msgid "A hardware interrupt channel is already in use" +#~ msgstr "Avast! A hardware interrupt channel be used already" #~ msgid "All event channels " #~ msgstr "Avast! All th' event channels " @@ -2831,8 +772,47 @@ msgstr "" #~ msgid "All timers " #~ msgstr "Heave-to! All th' timers be used" +#~ msgid "Another send is already active" +#~ msgstr "Belay that! thar be another active send" + +#~ msgid "Bus pin %d is already in use" +#~ msgstr "Belay that! Bus pin %d already be in use" + #~ msgid "Clock unit " #~ msgstr "Blimey! Clock unit " #~ msgid "DAC already " #~ msgstr "Blimey! DAC already under sail" + +#~ msgid "EXTINT channel already in use" +#~ msgstr "Avast! EXTINT channel already in use" + +#~ msgid "Invalid clock pin" +#~ msgstr "Avast! Clock pin be invalid" + +#~ msgid "Invalid pin for left channel" +#~ msgstr "Belay that! Invalid pin for port-side channel" + +#~ msgid "Invalid pin for right channel" +#~ msgstr "Belay that! Invalid pin for starboard-side channel" + +#~ msgid "No DAC on chip" +#~ msgstr "Shiver me timbers! There be no DAC on this chip" + +#~ msgid "Pin does not have ADC capabilities" +#~ msgstr "Belay that! Th' Pin be not ADC capable" + +#~ msgid "Unable to find free GCLK" +#~ msgstr "Arr! No free GCLK be in sight" + +#~ msgid "bits must be 8" +#~ msgstr "pieces must be of 8" + +#~ msgid "buffers must be the same length" +#~ msgstr "yer buffers must be of the same length" + +#~ msgid "invalid I2C peripheral" +#~ msgstr "Belay that! I2C peripheral be invalid" + +#~ msgid "invalid SPI peripheral" +#~ msgstr "Arr! SPI peripheral be invalid" diff --git a/locale/es.po b/locale/es.po index 9f71ac160..6b5351fcb 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 19:40+0100\n" +"POT-Creation-Date: 2019-03-02 22:09+1100\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -1151,6 +1151,9 @@ msgstr "Calibración de RTC no es soportada en esta placa" msgid "RTC is not supported on this board" msgstr "RTC no soportado en esta placa" +msgid "RTC set is not supported on this board" +msgstr "El cambio de RTC no soportado en esta placa" + #: shared-bindings/_pixelbuf/PixelBuf.c #, fuzzy msgid "Range out of bounds" diff --git a/locale/fil.po b/locale/fil.po index 230a09597..c3a1f613f 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 19:40+0100\n" +"POT-Creation-Date: 2019-03-02 22:09+1100\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -1150,6 +1150,9 @@ msgstr "RTC calibration ay hindi supportado ng board na ito" msgid "RTC is not supported on this board" msgstr "Hindi supportado ang RTC sa board na ito" +msgid "RTC set is not supported on this board" +msgstr "Hindi sinusuportahan ang pagbabago ng RTC sa board na ito" + #: shared-bindings/_pixelbuf/PixelBuf.c #, fuzzy msgid "Range out of bounds" diff --git a/locale/fr.po b/locale/fr.po index f9c007825..7918f0f71 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -1157,6 +1157,9 @@ msgstr "calibration de la RTC non supportée sur cette carte" msgid "RTC is not supported on this board" msgstr "RTC non supportée sur cette carte" +msgid "RTC set is not supported on this board" +msgstr "Le changement de RTC non supportée sur cette carte" + #: shared-bindings/_pixelbuf/PixelBuf.c #, fuzzy msgid "Range out of bounds" diff --git a/locale/it_IT.po b/locale/it_IT.po index 693f8a03c..cd0da30f1 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 19:40+0100\n" +"POT-Creation-Date: 2019-03-02 22:09+1100\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -1153,6 +1153,9 @@ msgstr "calibrazione RTC non supportata su questa scheda" msgid "RTC is not supported on this board" msgstr "RTC non supportato su questa scheda" +msgid "RTC set is not supported on this board" +msgstr "La modifica RTC non è supportata su questa scheda" + #: shared-bindings/_pixelbuf/PixelBuf.c #, fuzzy msgid "Range out of bounds" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 587ed00ba..1cd3fac2a 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-25 19:40+0100\n" +"POT-Creation-Date: 2019-03-02 22:09+1100\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -1135,6 +1135,9 @@ msgstr "A calibração RTC não é suportada nesta placa" msgid "RTC is not supported on this board" msgstr "O RTC não é suportado nesta placa" +msgid "RTC set is not supported on this board" +msgstr "A mudança de RTC não é suportada nesta placa" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index 7c85f328c..d9153781e 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -37,7 +37,7 @@ #include "supervisor/shared/translate.h" void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError(translate("RTC get is not supported on this board")); + mp_raise_NotImplementedError(translate("RTC is not supported on this board")); } void MP_WEAK common_hal_rtc_set_time(timeutils_struct_time_t *tm) { -- cgit v1.2.3 From f3ec0514cdfc818c57274cd80025f582ad562f22 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 27 Mar 2019 20:11:32 -0700 Subject: Simplified into fourwire only --- shared-bindings/displayio/FourWire.h | 2 -- shared-module/displayio/Display.c | 7 ------- shared-module/displayio/Display.h | 2 -- shared-module/displayio/FourWire.c | 11 ++++++----- 4 files changed, 6 insertions(+), 16 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/FourWire.h b/shared-bindings/displayio/FourWire.h index a7fda2638..b8b00372c 100644 --- a/shared-bindings/displayio/FourWire.h +++ b/shared-bindings/displayio/FourWire.h @@ -47,6 +47,4 @@ void common_hal_displayio_fourwire_send(mp_obj_t self, bool command, uint8_t *da void common_hal_displayio_fourwire_end_transaction(mp_obj_t self); -void common_hal_displayio_fourwire_set_cs(mp_obj_t self, bool high); - #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_FOURWIRE_H diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index c693d3c90..0e76a868f 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -59,12 +59,10 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->begin_transaction = common_hal_displayio_parallelbus_begin_transaction; self->send = common_hal_displayio_parallelbus_send; self->end_transaction = common_hal_displayio_parallelbus_end_transaction; - self->set_cs = NULL; } else if (MP_OBJ_IS_TYPE(bus, &displayio_fourwire_type)) { self->begin_transaction = common_hal_displayio_fourwire_begin_transaction; self->send = common_hal_displayio_fourwire_send; self->end_transaction = common_hal_displayio_fourwire_end_transaction; - self->set_cs = common_hal_displayio_fourwire_set_cs; } else { mp_raise_ValueError(translate("Unsupported display bus type")); } @@ -82,11 +80,6 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, bool delay = (data_size & DELAY) != 0; data_size &= ~DELAY; uint8_t *data = cmd + 2; - if (self->set_cs != NULL) { - self->set_cs(self->bus, true); - common_hal_time_delay_ms(1); - self->set_cs(self->bus, false); - } self->send(self->bus, true, cmd, 1); self->send(self->bus, false, data, data_size); uint16_t delay_length_ms = 10; diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 70308daa2..04da68b63 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -34,7 +34,6 @@ typedef bool (*display_bus_begin_transaction)(mp_obj_t bus); typedef void (*display_bus_send)(mp_obj_t bus, bool command, uint8_t *data, uint32_t data_length); typedef void (*display_bus_end_transaction)(mp_obj_t bus); -typedef void (*display_bus_set_cs)(mp_obj_t bus, bool high); typedef struct { mp_obj_base_t base; @@ -53,7 +52,6 @@ typedef struct { display_bus_begin_transaction begin_transaction; display_bus_send send; display_bus_end_transaction end_transaction; - display_bus_set_cs set_cs; union { digitalio_digitalinout_obj_t backlight_inout; pulseio_pwmout_obj_t backlight_pwm; diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c index ae1fde7ca..043f68e26 100644 --- a/shared-module/displayio/FourWire.c +++ b/shared-module/displayio/FourWire.c @@ -30,6 +30,7 @@ #include "shared-bindings/busio/SPI.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/time/__init__.h" #include "tick.h" @@ -78,6 +79,11 @@ bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t obj) { void common_hal_displayio_fourwire_send(mp_obj_t obj, bool command, uint8_t *data, uint32_t data_length) { displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj); + if (command) { + common_hal_digitalio_digitalinout_set_value(&self->chip_select, true); + common_hal_time_delay_ms(1); + common_hal_digitalio_digitalinout_set_value(&self->chip_select, false); + } common_hal_digitalio_digitalinout_set_value(&self->command, !command); common_hal_busio_spi_write(self->bus, data, data_length); } @@ -87,8 +93,3 @@ void common_hal_displayio_fourwire_end_transaction(mp_obj_t obj) { common_hal_digitalio_digitalinout_set_value(&self->chip_select, true); common_hal_busio_spi_unlock(self->bus); } - -void common_hal_displayio_fourwire_set_cs(mp_obj_t obj, bool high) { - displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj); - common_hal_digitalio_digitalinout_set_value(&self->chip_select, high); -} -- cgit v1.2.3 From 0653bca3239e9e00ad744523188f181b315d479f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 29 Mar 2019 16:41:29 -0400 Subject: Revert "Circuitpython nickzoic 1046 nrf rtc" --- locale/ID.po | 76 +++++++++++++++++----------------- locale/circuitpython.pot | 76 +++++++++++++++++----------------- locale/de_DE.po | 76 +++++++++++++++++----------------- locale/en_US.po | 76 +++++++++++++++++----------------- locale/en_x_pirate.po | 76 +++++++++++++++++----------------- locale/es.po | 76 +++++++++++++++++----------------- locale/fil.po | 76 +++++++++++++++++----------------- locale/fr.po | 76 +++++++++++++++++----------------- locale/it_IT.po | 76 +++++++++++++++++----------------- locale/pt_BR.po | 76 +++++++++++++++++----------------- ports/nrf/Makefile | 1 - ports/nrf/common-hal/rtc/RTC.c | 81 ------------------------------------- ports/nrf/common-hal/rtc/RTC.h | 32 --------------- ports/nrf/common-hal/rtc/__init__.c | 0 ports/nrf/mpconfigport.h | 1 + ports/nrf/mpconfigport.mk | 4 +- ports/nrf/nrfx_config.h | 3 -- ports/nrf/supervisor/port.c | 5 --- shared-bindings/rtc/RTC.c | 3 +- 19 files changed, 364 insertions(+), 526 deletions(-) delete mode 100644 ports/nrf/common-hal/rtc/RTC.c delete mode 100644 ports/nrf/common-hal/rtc/RTC.h delete mode 100644 ports/nrf/common-hal/rtc/__init__.c (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 727849516..36023152c 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -52,8 +52,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "buffers harus mempunyai panjang yang sama" @@ -70,12 +70,12 @@ msgstr "%q() mengambil posisi argumen %d tapi %d yang diberikan" msgid "'%q' argument required" msgstr "'%q' argumen dibutuhkan" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' mengharapkan sebuah register" @@ -95,7 +95,7 @@ msgstr "'%s' mengharapkan sebuah FPU register" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' mengharapkan sebuah alamat dengan bentuk [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' mengharapkan integer" @@ -253,9 +253,9 @@ msgstr "Semua channel event yang disinkronisasi sedang digunakan" msgid "All timers for this pin are in use" msgstr "Semua timer untuk pin ini sedang digunakan" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -326,7 +326,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "" @@ -366,7 +366,7 @@ msgstr "" msgid "Can't connect in Peripheral mode" msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "" @@ -452,7 +452,7 @@ msgstr "Clock unit sedang digunakan" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -490,8 +490,8 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Tidak bisa menyesuaikan data ke dalam paket advertisment" @@ -522,8 +522,8 @@ msgstr "Channel EXTINT sedang digunakan" msgid "Error in regex" msgstr "Error pada regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -532,8 +532,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "" @@ -657,8 +657,8 @@ msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" msgid "Failed to start advertising" msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" @@ -678,8 +678,8 @@ msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" msgid "Failed to stop advertising" msgstr "Gagal untuk memberhentikan advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Gagal untuk memberhentikan advertisement, status: 0x%08lX" @@ -720,8 +720,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -801,16 +801,16 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "Pin tidak valid" @@ -824,14 +824,14 @@ msgid "Invalid pin for right channel" msgstr "Pin untuk channel kanan tidak valid" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Pin-pin tidak valid" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "" @@ -1041,14 +1041,10 @@ msgstr "" msgid "RTC calibration is not supported on this board" msgstr "" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" @@ -1105,8 +1101,8 @@ msgstr "Serializer sedang digunakan" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "" @@ -1189,7 +1185,7 @@ msgstr "Untuk keluar, silahkan reset board tanpa " msgid "Too many channels in sample." msgstr "Terlalu banyak channel dalam sampel" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1429,7 +1425,7 @@ msgstr "" msgid "buffer size must match format" msgstr "buffers harus mempunyai panjang yang sama" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "" @@ -1713,7 +1709,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "" @@ -1722,7 +1718,7 @@ msgstr "" msgid "empty" msgstr "" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "heap kosong" @@ -1787,7 +1783,7 @@ msgstr "argumen keyword ekstra telah diberikan" msgid "extra positional arguments given" msgstr "argumen posisi ekstra telah diberikan" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1960,7 +1956,7 @@ msgstr "micropython decorator tidak valid" msgid "invalid step" msgstr "" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "syntax tidak valid" @@ -1997,7 +1993,7 @@ msgstr "argumen keyword belum diimplementasi - gunakan args normal" msgid "keywords must be strings" msgstr "keyword harus berupa string" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2104,11 +2100,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2215,7 +2211,7 @@ msgstr "panjang data string memiliki keganjilan (odd-length)" msgid "offset out of bounds" msgstr "modul tidak ditemukan" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2369,7 +2365,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 2d82ec3ed..37b158902 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -52,8 +52,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "" @@ -69,12 +69,12 @@ msgstr "" msgid "'%q' argument required" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "" @@ -94,7 +94,7 @@ msgstr "" msgid "'%s' expects an address of the form [a, b]" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "" @@ -251,9 +251,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -322,7 +322,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "" @@ -361,7 +361,7 @@ msgstr "" msgid "Can't connect in Peripheral mode" msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "" @@ -442,7 +442,7 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -480,8 +480,8 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c msgid "Data too large for advertisement packet" msgstr "" @@ -510,8 +510,8 @@ msgstr "" msgid "Error in regex" msgstr "" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -520,8 +520,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "" @@ -634,8 +634,8 @@ msgstr "" msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" @@ -653,8 +653,8 @@ msgstr "" msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "" @@ -695,8 +695,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -776,16 +776,16 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "" @@ -799,14 +799,14 @@ msgid "Invalid pin for right channel" msgstr "" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "" @@ -1013,14 +1013,10 @@ msgstr "" msgid "RTC calibration is not supported on this board" msgstr "" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" @@ -1075,8 +1071,8 @@ msgstr "" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "" @@ -1156,7 +1152,7 @@ msgstr "" msgid "Too many channels in sample." msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1385,7 +1381,7 @@ msgstr "" msgid "buffer size must match format" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "" @@ -1669,7 +1665,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "" @@ -1678,7 +1674,7 @@ msgstr "" msgid "empty" msgstr "" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "" @@ -1743,7 +1739,7 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1916,7 +1912,7 @@ msgstr "" msgid "invalid step" msgstr "" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "" @@ -1953,7 +1949,7 @@ msgstr "" msgid "keywords must be strings" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2059,11 +2055,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2169,7 +2165,7 @@ msgstr "" msgid "offset out of bounds" msgstr "" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2323,7 +2319,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index eaf34f1be..26b519d4d 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -54,8 +54,8 @@ msgstr "Der Index %q befindet sich außerhalb der Reihung" msgid "%q indices must be integers, not %s" msgstr "%q Indizes müssen ganze Zahlen sein, nicht %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "%q muss >= 1 sein" @@ -71,12 +71,12 @@ msgstr "%q() nimmt %d Argumente ohne Keyword an, aber es wurden %d angegeben" msgid "'%q' argument required" msgstr "'%q' Argument erforderlich" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' erwartet ein Label" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' erwartet ein Register" @@ -96,7 +96,7 @@ msgstr "'%s' erwartet ein FPU-Register" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' erwartet eine Adresse in der Form [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' erwartet ein Integer" @@ -253,9 +253,9 @@ msgstr "Alle sync event Kanäle werden benutzt" msgid "All timers for this pin are in use" msgstr "Alle timer für diesen Pin werden bereits benutzt" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -326,7 +326,7 @@ msgstr "Die Helligkeit ist nicht einstellbar" msgid "Buffer incorrect size. Should be %d bytes." msgstr "Der Puffergröße ist inkorrekt. Sie sollte %d bytes haben." -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "Der Puffer muss eine Mindestenslänge von 1 haben" @@ -365,7 +365,7 @@ msgstr "Im Central mode kann name nicht geändert werden" msgid "Can't connect in Peripheral mode" msgstr "Im Peripheral mode kann keine Verbindung hergestellt werden" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "Kann Werte nicht löschen" @@ -446,7 +446,7 @@ msgstr "Clock unit wird benutzt" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Command must be an int between 0 and 255" msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" @@ -484,8 +484,8 @@ msgstr "Data 0 pin muss am Byte ausgerichtet sein" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c msgid "Data too large for advertisement packet" msgstr "Zu vielen Daten für das advertisement packet" @@ -514,8 +514,8 @@ msgstr "EXTINT Kanal ist schon in Benutzung" msgid "Error in regex" msgstr "Fehler in regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Erwartet ein(e) %q" @@ -524,8 +524,8 @@ msgstr "Erwartet ein(e) %q" msgid "Expected a Characteristic" msgstr "Characteristic wird erwartet" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "Eine UUID wird erwartet" @@ -638,8 +638,8 @@ msgstr "Mutex konnte nicht freigegeben werden. Status: 0x%04x" msgid "Failed to start advertising" msgstr "Kann advertisement nicht starten" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Kann advertisement nicht starten. Status: 0x%04x" @@ -657,8 +657,8 @@ msgstr "Der Scanvorgang kann nicht gestartet werden. Status: 0x%04x" msgid "Failed to stop advertising" msgstr "Kann advertisement nicht stoppen" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Kann advertisement nicht stoppen. Status: 0x%04x" @@ -699,8 +699,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" @@ -782,16 +782,16 @@ msgstr "Ungültige Datei" msgid "Invalid format chunk size" msgstr "Ungültige format chunk size" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "Ungültige Anzahl von Bits" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "Ungültige Phase" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "Ungültiger Pin" @@ -805,14 +805,14 @@ msgid "Invalid pin for right channel" msgstr "Ungültiger Pin für rechten Kanal" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Ungültige Pins" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "Ungültige Polarität" @@ -1031,14 +1031,10 @@ msgstr "Pull wird nicht verwendet, wenn die Richtung output ist." msgid "RTC calibration is not supported on this board" msgstr "Die RTC-Kalibrierung wird auf diesem Board nicht unterstützt" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "Eine RTC wird auf diesem Board nicht unterstützt" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" @@ -1093,8 +1089,8 @@ msgstr "Serializer wird benutzt" msgid "Slice and value different lengths." msgstr "Slice und Wert (value) haben unterschiedliche Längen." -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "Slices werden nicht unterstützt" @@ -1186,7 +1182,7 @@ msgstr "Zum beenden, resette bitte das board ohne " msgid "Too many channels in sample." msgstr "Zu viele Kanäle im sample" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1426,7 +1422,7 @@ msgstr "Puffer muss ein bytes-artiges Objekt sein" msgid "buffer size must match format" msgstr "Die Puffergröße muss zum Format passen" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "Puffersegmente müssen gleich lang sein" @@ -1710,7 +1706,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "Division durch Null" @@ -1719,7 +1715,7 @@ msgstr "Division durch Null" msgid "empty" msgstr "leer" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "leerer heap" @@ -1784,7 +1780,7 @@ msgstr "Es wurden zusätzliche Keyword-Argumente angegeben" msgid "extra positional arguments given" msgstr "Es wurden zusätzliche Argumente ohne Keyword angegeben" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "Die Datei muss eine im Byte-Modus geöffnete Datei sein" @@ -1958,7 +1954,7 @@ msgstr "ungültiger micropython decorator" msgid "invalid step" msgstr "ungültiger Schritt (step)" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "ungültige Syntax" @@ -1999,7 +1995,7 @@ msgstr "" msgid "keywords must be strings" msgstr "Schlüsselwörter müssen Zeichenfolgen sein" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "Label '%q' nicht definiert" @@ -2107,11 +2103,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2217,7 +2213,7 @@ msgstr "String mit ungerader Länge" msgid "offset out of bounds" msgstr "offset außerhalb der Grenzen" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2375,7 +2371,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "small int Überlauf" diff --git a/locale/en_US.po b/locale/en_US.po index b4a3e739d..b16d22b3b 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -52,8 +52,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "" @@ -69,12 +69,12 @@ msgstr "" msgid "'%q' argument required" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "" @@ -94,7 +94,7 @@ msgstr "" msgid "'%s' expects an address of the form [a, b]" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "" @@ -251,9 +251,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -322,7 +322,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "" @@ -361,7 +361,7 @@ msgstr "" msgid "Can't connect in Peripheral mode" msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "" @@ -442,7 +442,7 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -480,8 +480,8 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c msgid "Data too large for advertisement packet" msgstr "" @@ -510,8 +510,8 @@ msgstr "" msgid "Error in regex" msgstr "" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -520,8 +520,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "" @@ -634,8 +634,8 @@ msgstr "" msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" @@ -653,8 +653,8 @@ msgstr "" msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "" @@ -695,8 +695,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -776,16 +776,16 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "" @@ -799,14 +799,14 @@ msgid "Invalid pin for right channel" msgstr "" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "" @@ -1013,14 +1013,10 @@ msgstr "" msgid "RTC calibration is not supported on this board" msgstr "" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" @@ -1075,8 +1071,8 @@ msgstr "" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "" @@ -1156,7 +1152,7 @@ msgstr "" msgid "Too many channels in sample." msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1385,7 +1381,7 @@ msgstr "" msgid "buffer size must match format" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "" @@ -1669,7 +1665,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "" @@ -1678,7 +1674,7 @@ msgstr "" msgid "empty" msgstr "" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "" @@ -1743,7 +1739,7 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1916,7 +1912,7 @@ msgstr "" msgid "invalid step" msgstr "" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "" @@ -1953,7 +1949,7 @@ msgstr "" msgid "keywords must be strings" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2059,11 +2055,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2169,7 +2165,7 @@ msgstr "" msgid "offset out of bounds" msgstr "" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2323,7 +2319,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 70e883d7d..5c1d74722 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -54,8 +54,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "" @@ -71,12 +71,12 @@ msgstr "" msgid "'%q' argument required" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "" @@ -96,7 +96,7 @@ msgstr "" msgid "'%s' expects an address of the form [a, b]" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "" @@ -253,9 +253,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -326,7 +326,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "" @@ -365,7 +365,7 @@ msgstr "" msgid "Can't connect in Peripheral mode" msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "" @@ -446,7 +446,7 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -484,8 +484,8 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c msgid "Data too large for advertisement packet" msgstr "" @@ -514,8 +514,8 @@ msgstr "Avast! EXTINT channel already in use" msgid "Error in regex" msgstr "" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -524,8 +524,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "" @@ -638,8 +638,8 @@ msgstr "" msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" @@ -657,8 +657,8 @@ msgstr "" msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "" @@ -699,8 +699,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -780,16 +780,16 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "" @@ -803,14 +803,14 @@ msgid "Invalid pin for right channel" msgstr "Belay that! Invalid pin for starboard-side channel" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "" @@ -1017,14 +1017,10 @@ msgstr "" msgid "RTC calibration is not supported on this board" msgstr "" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" @@ -1079,8 +1075,8 @@ msgstr "" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "" @@ -1160,7 +1156,7 @@ msgstr "" msgid "Too many channels in sample." msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1389,7 +1385,7 @@ msgstr "" msgid "buffer size must match format" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "" @@ -1673,7 +1669,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "" @@ -1682,7 +1678,7 @@ msgstr "" msgid "empty" msgstr "" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "" @@ -1747,7 +1743,7 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1920,7 +1916,7 @@ msgstr "" msgid "invalid step" msgstr "" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "" @@ -1957,7 +1953,7 @@ msgstr "" msgid "keywords must be strings" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2063,11 +2059,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2173,7 +2169,7 @@ msgstr "" msgid "offset out of bounds" msgstr "" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2327,7 +2323,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" diff --git a/locale/es.po b/locale/es.po index 7cac184c9..078525e20 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -55,8 +55,8 @@ msgstr "%q indice fuera de rango" msgid "%q indices must be integers, not %s" msgstr "%q indices deben ser enteros, no %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "%q debe ser >= 1" @@ -74,12 +74,12 @@ msgstr "%q() toma %d argumentos posicionales pero %d fueron dados" msgid "'%q' argument required" msgstr "argumento '%q' requerido" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' espera una etiqueta" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' espera un registro" @@ -99,7 +99,7 @@ msgstr "'%s' espera un registro de FPU" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' espera una dirección de forma [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' espera un entero" @@ -260,9 +260,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "Todos los timers para este pin están siendo utilizados" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -333,7 +333,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "Tamaño de buffer incorrecto. Debe ser de %d bytes." -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "Buffer debe ser de longitud 1 como minimo" @@ -373,7 +373,7 @@ msgstr "No se puede cambiar el nombre en modo Central" msgid "Can't connect in Peripheral mode" msgstr "No se puede conectar en modo Peripheral" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "No se puede eliminar valores" @@ -455,7 +455,7 @@ msgstr "Clock unit está siendo utilizado" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Bytes debe estar entre 0 y 255." @@ -495,8 +495,8 @@ msgstr "graphic debe ser 2048 bytes de largo" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Los datos no caben en el paquete de anuncio." @@ -527,8 +527,8 @@ msgstr "El canal EXTINT ya está siendo utilizado" msgid "Error in regex" msgstr "Error en regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Se espera un %q" @@ -538,8 +538,8 @@ msgstr "Se espera un %q" msgid "Expected a Characteristic" msgstr "No se puede agregar la Característica." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Se espera un %q" @@ -664,8 +664,8 @@ msgstr "No se puede liberar el mutex, status: 0x%08lX" msgid "Failed to start advertising" msgstr "No se puede inicar el anuncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "No se puede inicar el anuncio. status: 0x%02x" @@ -685,8 +685,8 @@ msgstr "No se puede iniciar el escaneo. status: 0x%02x" msgid "Failed to stop advertising" msgstr "No se puede detener el anuncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "No se puede detener el anuncio. status: 0x%02x" @@ -727,8 +727,8 @@ msgstr "Falló el iniciar la escritura de flash, err 0x%04x" msgid "Frequency captured is above capability. Capture Paused." msgstr "Frecuencia capturada por encima de la capacidad. Captura en pausa." +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "La función requiere lock" @@ -810,16 +810,16 @@ msgstr "Archivo inválido" msgid "Invalid format chunk size" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "Numero inválido de bits" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "Fase inválida" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "Pin inválido" @@ -833,14 +833,14 @@ msgid "Invalid pin for right channel" msgstr "Pin inválido para canal derecho" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "pines inválidos" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "Polaridad inválida" @@ -1061,14 +1061,10 @@ msgstr "Pull no se usa cuando la dirección es output." msgid "RTC calibration is not supported on this board" msgstr "Calibración de RTC no es soportada en esta placa" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "RTC no soportado en esta placa" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c #, fuzzy msgid "Range out of bounds" @@ -1125,8 +1121,8 @@ msgstr "Serializer está siendo utilizado" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "" @@ -1213,7 +1209,7 @@ msgstr "Para salir, por favor reinicia la tarjeta sin " msgid "Too many channels in sample." msgstr "Demasiados canales en sample." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1453,7 +1449,7 @@ msgstr "buffer debe de ser un objeto bytes-like" msgid "buffer size must match format" msgstr "los buffers deben de tener la misma longitud" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "" @@ -1744,7 +1740,7 @@ msgstr "destination_length debe ser un int >= 0" msgid "dict update sequence has wrong length" msgstr "la secuencia de actualizacion del dict tiene una longitud incorrecta" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "división por cero" @@ -1753,7 +1749,7 @@ msgstr "división por cero" msgid "empty" msgstr "vacío" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "heap vacío" @@ -1819,7 +1815,7 @@ msgstr "argumento(s) por palabra clave adicionales fueron dados" msgid "extra positional arguments given" msgstr "argumento posicional adicional dado" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "el archivo deberia ser una archivo abierto en modo byte" @@ -1992,7 +1988,7 @@ msgstr "decorador de micropython inválido" msgid "invalid step" msgstr "" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "sintaxis inválida" @@ -2032,7 +2028,7 @@ msgstr "" msgid "keywords must be strings" msgstr "palabras clave deben ser strings" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "etiqueta '%q' no definida" @@ -2139,11 +2135,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "necesita más de %d valores para descomprimir" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "potencia negativa sin float support" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "cuenta negativa de turnos" @@ -2253,7 +2249,7 @@ msgstr "string de longitud impar" msgid "offset out of bounds" msgstr "address fuera de límites" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "solo se admiten segmentos con step=1 (alias None)" @@ -2411,7 +2407,7 @@ msgstr "la longitud de sleep no puede ser negativa" msgid "slice step cannot be zero" msgstr "slice step no puede ser cero" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "pequeño int desbordamiento" diff --git a/locale/fil.po b/locale/fil.po index a4ee118a5..c0aaf93bb 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -52,8 +52,8 @@ msgstr "%q indeks wala sa sakop" msgid "%q indices must be integers, not %s" msgstr "%q indeks ay dapat integers, hindi %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "aarehas na haba dapat ang buffer slices" @@ -72,12 +72,12 @@ msgstr "" msgid "'%q' argument required" msgstr "'%q' argument kailangan" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' umaasa ng label" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "Inaasahan ng '%s' ang isang rehistro" @@ -97,7 +97,7 @@ msgstr "Inaasahan ng '%s' ang isang FPU register" msgid "'%s' expects an address of the form [a, b]" msgstr "Inaasahan ng '%s' ang isang address sa [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "Inaasahan ng '%s' ang isang integer" @@ -255,9 +255,9 @@ msgstr "Lahat ng sync event channels ay ginagamit" msgid "All timers for this pin are in use" msgstr "Lahat ng timers para sa pin na ito ay ginagamit" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -328,7 +328,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "Mali ang size ng buffer. Dapat %d bytes." -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "Buffer dapat ay hindi baba sa 1 na haba" @@ -368,7 +368,7 @@ msgstr "Hindi mapalitan ang pangalan sa Central mode" msgid "Can't connect in Peripheral mode" msgstr "Hindi maconnect sa Peripheral mode" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "Hindi mabura ang values" @@ -450,7 +450,7 @@ msgstr "Clock unit ginagamit" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Sa gitna ng 0 o 255 dapat ang bytes." @@ -490,8 +490,8 @@ msgstr "graphic ay dapat 2048 bytes ang haba" msgid "Data chunk must follow fmt chunk" msgstr "Dapat sunurin ng Data chunk ang fmt chunk" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Hindi makasya ang data sa loob ng advertisement packet" @@ -523,8 +523,8 @@ msgstr "Ginagamit na ang EXTINT channel" msgid "Error in regex" msgstr "May pagkakamali sa REGEX" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Umasa ng %q" @@ -534,8 +534,8 @@ msgstr "Umasa ng %q" msgid "Expected a Characteristic" msgstr "Hindi mabasa and Characteristic." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Umasa ng %q" @@ -660,8 +660,8 @@ msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" msgid "Failed to start advertising" msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" @@ -681,8 +681,8 @@ msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" msgid "Failed to stop advertising" msgstr "Hindi mahinto ang advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Hindi mahinto ang advertisement, status: 0x%08lX" @@ -723,8 +723,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Function nangangailangan ng lock" @@ -806,16 +806,16 @@ msgstr "Mali ang file" msgid "Invalid format chunk size" msgstr "Mali ang format ng chunk size" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "Mali ang bilang ng bits" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "Mali ang phase" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "Mali ang pin" @@ -829,14 +829,14 @@ msgid "Invalid pin for right channel" msgstr "Mali ang pin para sa kanang channel" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Mali ang pins" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "Mali ang polarity" @@ -1054,14 +1054,10 @@ msgstr "Pull hindi ginagamit kapag ang direksyon ay output." msgid "RTC calibration is not supported on this board" msgstr "RTC calibration ay hindi supportado ng board na ito" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "Hindi supportado ang RTC sa board na ito" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c #, fuzzy msgid "Range out of bounds" @@ -1118,8 +1114,8 @@ msgstr "Serializer ginagamit" msgid "Slice and value different lengths." msgstr "Slice at value iba't ibang haba." -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "Hindi suportado ang Slices" @@ -1209,7 +1205,7 @@ msgstr "Para lumabas, paki-reset ang board na wala ang " msgid "Too many channels in sample." msgstr "Sobra ang channels sa sample." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1449,7 +1445,7 @@ msgstr "buffer ay dapat bytes-like object" msgid "buffer size must match format" msgstr "aarehas na haba dapat ang buffer slices" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "aarehas na haba dapat ang buffer slices" @@ -1743,7 +1739,7 @@ msgstr "ang destination_length ay dapat na isang int >= 0" msgid "dict update sequence has wrong length" msgstr "may mali sa haba ng dict update sequence" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "dibisyon ng zero" @@ -1752,7 +1748,7 @@ msgstr "dibisyon ng zero" msgid "empty" msgstr "walang laman" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "walang laman ang heap" @@ -1818,7 +1814,7 @@ msgstr "dagdag na keyword argument na ibinigay" msgid "extra positional arguments given" msgstr "dagdag na positional argument na ibinigay" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "file ay dapat buksan sa byte mode" @@ -1992,7 +1988,7 @@ msgstr "mali ang micropython decorator" msgid "invalid step" msgstr "mali ang step" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "mali ang sintaks" @@ -2033,7 +2029,7 @@ msgstr "" msgid "keywords must be strings" msgstr "ang keywords dapat strings" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "label '%d' kailangan na i-define" @@ -2140,11 +2136,11 @@ msgstr "native yield" msgid "need more than %d values to unpack" msgstr "kailangan ng higit sa %d na halaga upang i-unpack" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "negatibong power na walang float support" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "negative shift count" @@ -2251,7 +2247,7 @@ msgstr "odd-length string" msgid "offset out of bounds" msgstr "wala sa sakop ang address" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "ang mga slices lamang na may hakbang = 1 (aka None) ang sinusuportahan" @@ -2409,7 +2405,7 @@ msgstr "sleep length ay dapat hindi negatibo" msgid "slice step cannot be zero" msgstr "slice step ay hindi puedeng 0" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "small int overflow" diff --git a/locale/fr.po b/locale/fr.po index 917f10ea4..f117b3e30 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -51,8 +51,8 @@ msgstr "index %q hors gamme" msgid "%q indices must be integers, not %s" msgstr "les indices %q doivent être des entiers, pas %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "les slices de tampon doivent être de longueurs égales" @@ -70,12 +70,12 @@ msgstr "%q() prend %d arguments mais %d ont été donnés" msgid "'%q' argument required" msgstr "'%q' argument requis" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' attend un label" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' attend un registre" @@ -95,7 +95,7 @@ msgstr "'%s' attend un registre FPU" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' attend une adresse de la forme [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' attend un entier" @@ -255,9 +255,9 @@ msgstr "Tous les canaux d'événements de synchro sont utilisés" msgid "All timers for this pin are in use" msgstr "Tous les timers pour cette broche sont utilisés" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -329,7 +329,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "Tampon de taille incorrect. Devrait être de %d octets." -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "Le tampon doit être de longueur au moins 1" @@ -369,7 +369,7 @@ msgstr "Modification du nom impossible en mode Central" msgid "Can't connect in Peripheral mode" msgstr "Impossible de se connecter en mode Peripheral" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "Impossible de supprimer les valeurs" @@ -452,7 +452,7 @@ msgstr "Horloge en cours d'utilisation" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Les octets 'bytes' doivent être entre 0 et 255" @@ -492,8 +492,8 @@ msgstr "le graphic doit être long de 2048 octets" msgid "Data chunk must follow fmt chunk" msgstr "Un bloc de données doit suivre un bloc de format" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c msgid "Data too large for advertisement packet" msgstr "" @@ -522,8 +522,8 @@ msgstr "Canal EXTINT déjà utilisé" msgid "Error in regex" msgstr "Erreur dans l'expression régulière" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Attendu : %q" @@ -533,8 +533,8 @@ msgstr "Attendu : %q" msgid "Expected a Characteristic" msgstr "Impossible d'ajouter la Characteristic." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Attendu : %q" @@ -659,8 +659,8 @@ msgstr "Impossible de libérer mutex, status: 0x%08lX" msgid "Failed to start advertising" msgstr "Echec de l'ajout de service, statut: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Impossible de commencer à scanner, statut: 0x%0xlX" @@ -680,8 +680,8 @@ msgstr "Impossible de commencer à scanner, statut: 0x%0xlX" msgid "Failed to stop advertising" msgstr "Echec de l'ajout de service, statut: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Echec de l'ajout de service, statut: 0x%08lX" @@ -722,8 +722,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "La fonction nécessite un verrou" @@ -808,16 +808,16 @@ msgstr "Fichier invalide" msgid "Invalid format chunk size" msgstr "Taille de bloc de formatage invalide" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "Nombre de bits invalide" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "Phase invalide" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "Broche invalide" @@ -831,14 +831,14 @@ msgid "Invalid pin for right channel" msgstr "Broche invalide pour le canal droit" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Broches invalides" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "Polarité invalide" @@ -1061,14 +1061,10 @@ msgstr "Le tirage 'pull' n'est pas utilisé quand la direction est 'output'." msgid "RTC calibration is not supported on this board" msgstr "calibration de la RTC non supportée sur cette carte" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "RTC non supportée sur cette carte" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c #, fuzzy msgid "Range out of bounds" @@ -1126,8 +1122,8 @@ msgstr "Sérialiseur en cours d'utilisation" msgid "Slice and value different lengths." msgstr "Slice et valeur de tailles différentes" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "Slices non supportées" @@ -1220,7 +1216,7 @@ msgstr "Pour quitter, redémarrez la carte SVP sans " msgid "Too many channels in sample." msgstr "Trop de canaux dans l'échantillon." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1461,7 +1457,7 @@ msgstr "le tampon doit être un objet bytes-like" msgid "buffer size must match format" msgstr "les slices de tampon doivent être de longueurs égales" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "les slices de tampon doivent être de longueurs égales" @@ -1760,7 +1756,7 @@ msgstr "destination_length doit être un entier >= 0" msgid "dict update sequence has wrong length" msgstr "la séquence de mise à jour de dict a une mauvaise longueur" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "division par zéro" @@ -1769,7 +1765,7 @@ msgstr "division par zéro" msgid "empty" msgstr "vide" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "'heap' vide" @@ -1835,7 +1831,7 @@ msgstr "argument nommé donné en plus" msgid "extra positional arguments given" msgstr "argument positionnel donné en plus" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "le fichier doit être un fichier ouvert en mode 'byte'" @@ -2008,7 +2004,7 @@ msgstr "décorateur micropython invalide" msgid "invalid step" msgstr "pas invalide" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "syntaxe invalide" @@ -2047,7 +2043,7 @@ msgstr "" msgid "keywords must be strings" msgstr "les noms doivent être des chaînes de caractère" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "label '%q' non supporté" @@ -2154,11 +2150,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "nécessite plus de %d valeur à dégrouper" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "puissance négative sans support des nombres flottants" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "compte de décalage négatif" @@ -2268,7 +2264,7 @@ msgstr "chaîne de longueur impaire" msgid "offset out of bounds" msgstr "adresse hors limites" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "seuls les slices avec 'step=1' (cad None) sont supportées" @@ -2429,7 +2425,7 @@ msgstr "la longueur de sleep ne doit pas être négative" msgid "slice step cannot be zero" msgstr "le pas 'step' de slice ne peut être zéro" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "dépassement de capacité d'un entier court" diff --git a/locale/it_IT.po b/locale/it_IT.po index 28f872b92..c443d600a 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -52,8 +52,8 @@ msgstr "indice %q fuori intervallo" msgid "%q indices must be integers, not %s" msgstr "gli indici %q devono essere interi, non %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "slice del buffer devono essere della stessa lunghezza" @@ -71,12 +71,12 @@ msgstr "%q() prende %d argomenti posizionali ma ne sono stati forniti %d" msgid "'%q' argument required" msgstr "'%q' argomento richiesto" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' aspetta una etichetta" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' aspetta un registro" @@ -96,7 +96,7 @@ msgstr "'%s' aspetta un registro" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' aspetta un registro" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' aspetta un intero" @@ -254,9 +254,9 @@ msgstr "Tutti i canali di eventi sincronizzati in uso" msgid "All timers for this pin are in use" msgstr "Tutti i timer per questo pin sono in uso" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -328,7 +328,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "Buffer di lunghezza non valida. Dovrebbe essere di %d bytes." -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "Il buffer deve essere lungo almeno 1" @@ -368,7 +368,7 @@ msgstr "" msgid "Can't connect in Peripheral mode" msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "Impossibile cancellare valori" @@ -451,7 +451,7 @@ msgstr "Unità di clock in uso" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "I byte devono essere compresi tra 0 e 255" @@ -491,8 +491,8 @@ msgstr "graphic deve essere lunga 2048 byte" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Impossibile inserire dati nel pacchetto di advertisement." @@ -523,8 +523,8 @@ msgstr "Canale EXTINT già in uso" msgid "Error in regex" msgstr "Errore nella regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Atteso un %q" @@ -534,8 +534,8 @@ msgstr "Atteso un %q" msgid "Expected a Characteristic" msgstr "Non è possibile aggiungere Characteristic." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Atteso un %q" @@ -659,8 +659,8 @@ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" msgid "Failed to start advertising" msgstr "Impossibile avviare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Impossibile avviare advertisement. status: 0x%02x" @@ -680,8 +680,8 @@ msgstr "Impossible iniziare la scansione. status: 0x%02x" msgid "Failed to stop advertising" msgstr "Impossibile fermare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Impossibile fermare advertisement. status: 0x%02x" @@ -722,8 +722,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -807,16 +807,16 @@ msgstr "File non valido" msgid "Invalid format chunk size" msgstr "" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "Numero di bit non valido" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "Fase non valida" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "Pin non valido" @@ -830,14 +830,14 @@ msgid "Invalid pin for right channel" msgstr "Pin non valido per il canale destro" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Pin non validi" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "Polarità non valida" @@ -1058,14 +1058,10 @@ msgstr "" msgid "RTC calibration is not supported on this board" msgstr "calibrazione RTC non supportata su questa scheda" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "RTC non supportato su questa scheda" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c #, fuzzy msgid "Range out of bounds" @@ -1124,8 +1120,8 @@ msgstr "Serializer in uso" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "Slice non supportate" @@ -1208,7 +1204,7 @@ msgstr "Per uscire resettare la scheda senza " msgid "Too many channels in sample." msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1445,7 +1441,7 @@ msgstr "" msgid "buffer size must match format" msgstr "slice del buffer devono essere della stessa lunghezza" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "slice del buffer devono essere della stessa lunghezza" @@ -1735,7 +1731,7 @@ msgstr "destination_length deve essere un int >= 0" msgid "dict update sequence has wrong length" msgstr "sequanza di aggiornamento del dizionario ha la lunghezza errata" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "divisione per zero" @@ -1744,7 +1740,7 @@ msgstr "divisione per zero" msgid "empty" msgstr "vuoto" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "heap vuoto" @@ -1810,7 +1806,7 @@ msgstr "argomento nominato aggiuntivo fornito" msgid "extra positional arguments given" msgstr "argomenti posizonali extra dati" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1984,7 +1980,7 @@ msgstr "decoratore non valido in micropython" msgid "invalid step" msgstr "step non valida" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "sintassi non valida" @@ -2026,7 +2022,7 @@ msgstr "" msgid "keywords must be strings" msgstr "argomenti nominati devono essere stringhe" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "etichetta '%q' non definita" @@ -2133,11 +2129,11 @@ msgstr "yield nativo" msgid "need more than %d values to unpack" msgstr "necessari più di %d valori da scompattare" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "potenza negativa senza supporto per float" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2247,7 +2243,7 @@ msgstr "stringa di lunghezza dispari" msgid "offset out of bounds" msgstr "indirizzo fuori limite" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "solo slice con step=1 (aka None) sono supportate" @@ -2407,7 +2403,7 @@ msgstr "la lunghezza di sleed deve essere non negativa" msgid "slice step cannot be zero" msgstr "la step della slice non può essere zero" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "small int overflow" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 91bf15db5..546d9e73f 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-03-28 14:48+1100\n" +"POT-Creation-Date: 2019-03-27 16:28-0400\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -52,8 +52,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Shape.c shared-bindings/displayio/Group.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "buffers devem ser o mesmo tamanho" @@ -71,12 +71,12 @@ msgstr "" msgid "'%q' argument required" msgstr "'%q' argumento(s) requerido(s)" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "" @@ -96,7 +96,7 @@ msgstr "" msgid "'%s' expects an address of the form [a, b]" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "" @@ -254,9 +254,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "Todos os temporizadores para este pino estão em uso" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -325,7 +325,7 @@ msgstr "" msgid "Buffer incorrect size. Should be %d bytes." msgstr "Buffer de tamanho incorreto. Deve ser %d bytes." -#: shared-bindings/bitbangio/I2C.c shared-bindings/busio/I2C.c +#: shared-bindings/busio/I2C.c shared-bindings/bitbangio/I2C.c msgid "Buffer must be at least length 1" msgstr "" @@ -365,7 +365,7 @@ msgstr "" msgid "Can't connect in Peripheral mode" msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c msgid "Cannot delete values" msgstr "Não é possível excluir valores" @@ -447,7 +447,7 @@ msgstr "Unidade de Clock em uso" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Os bytes devem estar entre 0 e 255." @@ -486,8 +486,8 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "Pedaço de dados deve seguir o pedaço de cortes" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Não é possível ajustar dados no pacote de anúncios." @@ -518,8 +518,8 @@ msgstr "Canal EXTINT em uso" msgid "Error in regex" msgstr "Erro no regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/microcontroller/Pin.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Esperado um" @@ -529,8 +529,8 @@ msgstr "Esperado um" msgid "Expected a Characteristic" msgstr "Não é possível adicionar Característica." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Service.c -#: shared-bindings/bleio/Descriptor.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Esperado um" @@ -652,8 +652,8 @@ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" msgid "Failed to start advertising" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" @@ -673,8 +673,8 @@ msgstr "Não é possível iniciar o anúncio. status: 0x%02x" msgid "Failed to stop advertising" msgstr "Não pode parar propaganda. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c +#: ports/nrf/common-hal/bleio/Broadcaster.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Não pode parar propaganda. status: 0x%02x" @@ -715,8 +715,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" +#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c #: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -798,16 +798,16 @@ msgstr "Arquivo inválido" msgid "Invalid format chunk size" msgstr "Tamanho do pedaço de formato inválido" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid number of bits" msgstr "Número inválido de bits" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid phase" msgstr "Fase Inválida" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: shared-bindings/pulseio/PWMOut.c msgid "Invalid pin" msgstr "Pino inválido" @@ -821,14 +821,14 @@ msgid "Invalid pin for right channel" msgstr "Pino inválido para canal direito" #: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c #: ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Pinos inválidos" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "Invalid polarity" msgstr "" @@ -1040,14 +1040,10 @@ msgstr "" msgid "RTC calibration is not supported on this board" msgstr "A calibração RTC não é suportada nesta placa" -#: shared-bindings/rtc/RTC.c shared-bindings/time/__init__.c +#: shared-bindings/time/__init__.c shared-bindings/rtc/RTC.c msgid "RTC is not supported on this board" msgstr "O RTC não é suportado nesta placa" -#: shared-bindings/rtc/RTC.c -msgid "RTC set is not supported on this board" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "Range out of bounds" msgstr "" @@ -1103,8 +1099,8 @@ msgstr "Serializer em uso" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c -#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/pulseio/PulseIn.c shared-bindings/displayio/Bitmap.c +#: shared-bindings/displayio/TileGrid.c shared-bindings/displayio/Group.c msgid "Slices not supported" msgstr "" @@ -1184,7 +1180,7 @@ msgstr "Para sair, por favor, reinicie a placa sem " msgid "Too many channels in sample." msgstr "Muitos canais na amostra." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/ParallelBus.c shared-bindings/displayio/FourWire.c msgid "Too many display busses" msgstr "" @@ -1417,7 +1413,7 @@ msgstr "" msgid "buffer size must match format" msgstr "buffers devem ser o mesmo tamanho" -#: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c +#: shared-bindings/busio/SPI.c shared-bindings/bitbangio/SPI.c msgid "buffer slices must be of equal length" msgstr "" @@ -1701,7 +1697,7 @@ msgstr "destination_length deve ser um int >= 0" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/objfloat.c py/runtime.c py/modmath.c py/objint_longlong.c py/objint_mpz.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "divisão por zero" @@ -1710,7 +1706,7 @@ msgstr "divisão por zero" msgid "empty" msgstr "vazio" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "heap vazia" @@ -1776,7 +1772,7 @@ msgstr "argumentos extras de palavras-chave passados" msgid "extra positional arguments given" msgstr "argumentos extra posicionais passados" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1949,7 +1945,7 @@ msgstr "" msgid "invalid step" msgstr "passo inválido" -#: py/compile.c py/parse.c +#: py/parse.c py/compile.c msgid "invalid syntax" msgstr "" @@ -1986,7 +1982,7 @@ msgstr "" msgid "keywords must be strings" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2093,11 +2089,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "precisa de mais de %d valores para desempacotar" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_longlong.c py/objint_mpz.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2203,7 +2199,7 @@ msgstr "" msgid "offset out of bounds" msgstr "" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objstr.c py/objarray.c py/objstrunicode.c py/objtuple.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2358,7 +2354,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 3cb4b52aa..3681ac49e 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -140,7 +140,6 @@ SRC_NRFX = $(addprefix nrfx/,\ drivers/src/nrfx_twim.c \ drivers/src/nrfx_uarte.c \ drivers/src/nrfx_gpiote.c \ - drivers/src/nrfx_rtc.c \ ) ifdef EXTERNAL_FLASH_DEVICES diff --git a/ports/nrf/common-hal/rtc/RTC.c b/ports/nrf/common-hal/rtc/RTC.c deleted file mode 100644 index d807d7b03..000000000 --- a/ports/nrf/common-hal/rtc/RTC.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Nick Moore for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "py/obj.h" -#include "py/runtime.h" -#include "lib/timeutils/timeutils.h" -#include "shared-bindings/rtc/__init__.h" -#include "supervisor/shared/translate.h" - -#include "nrfx_rtc.h" -#include "nrf_clock.h" - -// We clock the RTC very slowly (8Hz) so that it won't overflow often. -// But the counter is only 24 bits, so overflow is about every 24 days ... -// For testing, set this to 32768 and it'll overflow every few minutes - -#define RTC_CLOCK_HZ (8) - -volatile static uint32_t rtc_offset = 0; - -const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(0); - -const nrfx_rtc_config_t rtc_config = { - .prescaler = RTC_FREQ_TO_PRESCALER(RTC_CLOCK_HZ), - .reliable = 0, - .tick_latency = 0, - .interrupt_priority = 6 -}; - -void rtc_handler(nrfx_rtc_int_type_t int_type) { - if (int_type == NRFX_RTC_INT_OVERFLOW) { - rtc_offset += (1L<<24) / RTC_CLOCK_HZ; - } -} - -void rtc_init(void) { - if (!nrf_clock_lf_is_running()) { - nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART); - } - nrfx_rtc_counter_clear(&rtc_instance); - nrfx_rtc_init(&rtc_instance, &rtc_config, rtc_handler); - nrfx_rtc_enable(&rtc_instance); - nrfx_rtc_overflow_enable(&rtc_instance, 1); -} - -void common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - uint32_t t = rtc_offset + (nrfx_rtc_counter_get(&rtc_instance) / RTC_CLOCK_HZ ); - timeutils_seconds_since_2000_to_struct_time(t, tm); -} - -void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - rtc_offset = timeutils_seconds_since_2000( - tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec - ); - nrfx_rtc_counter_clear(&rtc_instance); -} diff --git a/ports/nrf/common-hal/rtc/RTC.h b/ports/nrf/common-hal/rtc/RTC.h deleted file mode 100644 index 5374fa2c8..000000000 --- a/ports/nrf/common-hal/rtc/RTC.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Noralf Trønnes - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_RTC_RTC_H -#define MICROPY_INCLUDED_NRF_COMMON_HAL_RTC_RTC_H - -extern void rtc_init(void); - -#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_RTC_RTC_H diff --git a/ports/nrf/common-hal/rtc/__init__.c b/ports/nrf/common-hal/rtc/__init__.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 5ed521e85..1b2d8ea12 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -57,4 +57,5 @@ CIRCUITPY_COMMON_ROOT_POINTERS \ ble_drv_evt_handler_entry_t* ble_drv_evt_handler_entries; \ + #endif // NRF5_MPCONFIGPORT_H__ diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index fdeb1bbbe..badfb6735 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -22,8 +22,8 @@ CIRCUITPY_I2CSLAVE = 0 # nvm not yet implemented CIRCUITPY_NVM = 0 -# enable RTC -CIRCUITPY_RTC = 1 +# rtc not yet implemented +CIRCUITPY_RTC = 0 # frequencyio not yet implemented CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/nrf/nrfx_config.h b/ports/nrf/nrfx_config.h index b8a0a7f60..57a2727aa 100644 --- a/ports/nrf/nrfx_config.h +++ b/ports/nrf/nrfx_config.h @@ -70,9 +70,6 @@ #define NRFX_PWM3_ENABLED 0 #endif -#define NRFX_RTC_ENABLED 1 -#define NRFX_RTC0_ENABLED 1 - // TIMERS #define NRFX_TIMER_ENABLED 1 // Don't enable TIMER0: it's used by the SoftDevice. diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 3d20e94ae..fd077a46a 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -45,11 +45,8 @@ #include "common-hal/pulseio/PWMOut.h" #include "common-hal/pulseio/PulseOut.h" #include "common-hal/pulseio/PulseIn.h" -#include "common-hal/rtc/RTC.h" #include "tick.h" -#include "shared-bindings/rtc/__init__.h" - static void power_warning_handler(void) { reset_into_safe_mode(BROWNOUT); } @@ -74,7 +71,6 @@ safe_mode_t port_init(void) { // Configure millisecond timer initialization. tick_init(); - rtc_init(); // Will do usb_init() if chip supports USB. board_init(); @@ -94,7 +90,6 @@ void reset_port(void) { pulseout_reset(); pulsein_reset(); timers_reset(); - rtc_reset(); bleio_reset(); diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index d9153781e..474d4a399 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -41,7 +41,7 @@ void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) { } void MP_WEAK common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError(translate("RTC set is not supported on this board")); + mp_raise_NotImplementedError(translate("RTC is not supported on this board")); } int MP_WEAK common_hal_rtc_get_calibration(void) { @@ -52,7 +52,6 @@ void MP_WEAK common_hal_rtc_set_calibration(int calibration) { mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); } - const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; //| .. currentmodule:: rtc -- cgit v1.2.3 From f846fa109ea20e74983fba7b7662f2bae9cc8fea Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Thu, 7 Feb 2019 23:50:14 +1100 Subject: enable NRFX RTC adafruit/circuitpython#1046 --- ports/nrf/Makefile | 1 + ports/nrf/common-hal/rtc/RTC.c | 28 ++++++++++++++++++++++++---- ports/nrf/nrfx_config.h | 3 +++ shared-bindings/rtc/RTC.c | 2 ++ 4 files changed, 30 insertions(+), 4 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 3681ac49e..3cb4b52aa 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -140,6 +140,7 @@ SRC_NRFX = $(addprefix nrfx/,\ drivers/src/nrfx_twim.c \ drivers/src/nrfx_uarte.c \ drivers/src/nrfx_gpiote.c \ + drivers/src/nrfx_rtc.c \ ) ifdef EXTERNAL_FLASH_DEVICES diff --git a/ports/nrf/common-hal/rtc/RTC.c b/ports/nrf/common-hal/rtc/RTC.c index 7690b3bd3..85cdb4c37 100644 --- a/ports/nrf/common-hal/rtc/RTC.c +++ b/ports/nrf/common-hal/rtc/RTC.c @@ -33,24 +33,44 @@ #include "supervisor/shared/translate.h" #include "nrfx_rtc.h" +#include "nrf_clock.h" -static uint32_t _rtc_seconds = 0; +#define RTC_CLOCK_HZ (8) -void rtc_handler(nrfx_rtc_int_type_t int_type) { +static uint32_t rtc_offset = 0; + +const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(0); +const nrfx_rtc_config_t rtc_config = { + .prescaler = RTC_FREQ_TO_PRESCALER(RTC_CLOCK_HZ), + .reliable = 0, + .tick_latency = 0, + .interrupt_priority = 6 +}; + +void rtc_handler(nrfx_rtc_int_type_t int_type) { + // do nothing } void rtc_init(void) { + if (!nrf_clock_lf_is_running()) { + nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART); + } + nrfx_rtc_counter_clear(&rtc_instance); + nrfx_rtc_init(&rtc_instance, &rtc_config, rtc_handler); + nrfx_rtc_enable(&rtc_instance); } void common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - timeutils_seconds_since_2000_to_struct_time(_rtc_seconds, tm); + uint32_t t = rtc_offset + (nrfx_rtc_counter_get(&rtc_instance) / RTC_CLOCK_HZ ); + timeutils_seconds_since_2000_to_struct_time(t, tm); } void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - _rtc_seconds = timeutils_seconds_since_2000( + rtc_offset = timeutils_seconds_since_2000( tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec ); + nrfx_rtc_counter_clear(&rtc_instance); } // A positive value speeds up the clock by removing clock cycles. diff --git a/ports/nrf/nrfx_config.h b/ports/nrf/nrfx_config.h index 57a2727aa..b8a0a7f60 100644 --- a/ports/nrf/nrfx_config.h +++ b/ports/nrf/nrfx_config.h @@ -70,6 +70,9 @@ #define NRFX_PWM3_ENABLED 0 #endif +#define NRFX_RTC_ENABLED 1 +#define NRFX_RTC0_ENABLED 1 + // TIMERS #define NRFX_TIMER_ENABLED 1 // Don't enable TIMER0: it's used by the SoftDevice. diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index 474d4a399..97265d601 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -36,6 +36,7 @@ #include "shared-bindings/time/__init__.h" #include "supervisor/shared/translate.h" +/* void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) { mp_raise_NotImplementedError(translate("RTC is not supported on this board")); } @@ -51,6 +52,7 @@ int MP_WEAK common_hal_rtc_get_calibration(void) { void MP_WEAK common_hal_rtc_set_calibration(int calibration) { mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); } +*/ const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; -- cgit v1.2.3 From 781d301bb6da7386bb735fc23637e4127b080072 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Tue, 2 Apr 2019 13:23:55 +1100 Subject: Remove unnecessary MP_WEAK declarations --- ports/nrf/common-hal/rtc/RTC.c | 9 +++++++++ ports/nrf/common-hal/rtc/RTC.h | 1 + ports/nrf/supervisor/port.c | 6 ++++++ shared-bindings/rtc/RTC.c | 18 ------------------ 4 files changed, 16 insertions(+), 18 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/rtc/RTC.c b/ports/nrf/common-hal/rtc/RTC.c index 25c1003ed..57138350c 100644 --- a/ports/nrf/common-hal/rtc/RTC.c +++ b/ports/nrf/common-hal/rtc/RTC.c @@ -79,3 +79,12 @@ void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { ); nrfx_rtc_counter_clear(&rtc_instance); } + +int common_hal_rtc_get_calibration(void) { + return 0; +} + +void common_hal_rtc_set_calibration(int calibration) { + mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); +} + diff --git a/ports/nrf/common-hal/rtc/RTC.h b/ports/nrf/common-hal/rtc/RTC.h index 5374fa2c8..0207c8338 100644 --- a/ports/nrf/common-hal/rtc/RTC.h +++ b/ports/nrf/common-hal/rtc/RTC.h @@ -28,5 +28,6 @@ #define MICROPY_INCLUDED_NRF_COMMON_HAL_RTC_RTC_H extern void rtc_init(void); +extern void rtc_reset(void); #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_RTC_RTC_H diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 3d20e94ae..85ecd6afe 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -74,7 +74,10 @@ safe_mode_t port_init(void) { // Configure millisecond timer initialization. tick_init(); + + #if CIRCUITPY_RTC rtc_init(); + #endif // Will do usb_init() if chip supports USB. board_init(); @@ -94,7 +97,10 @@ void reset_port(void) { pulseout_reset(); pulsein_reset(); timers_reset(); + + #if CIRCUITPY_RTC rtc_reset(); + #endif bleio_reset(); diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index 97265d601..17dccdb03 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -36,24 +36,6 @@ #include "shared-bindings/time/__init__.h" #include "supervisor/shared/translate.h" -/* -void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError(translate("RTC is not supported on this board")); -} - -void MP_WEAK common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - mp_raise_NotImplementedError(translate("RTC is not supported on this board")); -} - -int MP_WEAK common_hal_rtc_get_calibration(void) { - return 0; -} - -void MP_WEAK common_hal_rtc_set_calibration(int calibration) { - mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); -} -*/ - const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; //| .. currentmodule:: rtc -- cgit v1.2.3 From 8f1fc6c07d37609fd354ddd707ecd147df6d7384 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 4 Apr 2019 23:15:00 -0700 Subject: Added option to easily treat SPI parameter data as commands --- shared-bindings/displayio/Display.c | 9 ++++++--- shared-bindings/displayio/Display.h | 3 ++- shared-module/displayio/Display.c | 24 +++++++++++++++++------- shared-module/displayio/Display.h | 1 + 4 files changed, 26 insertions(+), 11 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 885a4f3c4..f36fd3d07 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -50,7 +50,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, single_byte_bounds=False) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, single_byte_bounds=False, data_as_commands=False) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -92,9 +92,10 @@ //| :param int set_vertical_scroll: Command used to set the first row to show //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight //| :param bool single_byte_bounds: Display column and row commands use single bytes +//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this. //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_single_byte_bounds }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_single_byte_bounds, ARG_data_as_commands }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -110,6 +111,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, { MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_data_as_commands, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -149,7 +151,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a args[ARG_write_ram_command].u_int, args[ARG_set_vertical_scroll].u_int, bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin), - args[ARG_single_byte_bounds].u_bool); + args[ARG_single_byte_bounds].u_bool, + args[ARG_data_as_commands].u_bool); return self; } diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index d35569f6c..3b855195d 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -40,7 +40,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, - uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds); + uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds, + bool data_as_commands); int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index eccb2d0ef..34202aa45 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, - const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds) { + const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds, bool data_as_commands) { self->color_depth = color_depth; self->set_column_command = set_column_command; self->set_row_command = set_row_command; @@ -54,6 +54,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->colstart = colstart; self->rowstart = rowstart; self->auto_brightness = false; + self->data_as_commands = data_as_commands; self->single_byte_bounds = single_byte_bounds; if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) { @@ -82,7 +83,13 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, data_size &= ~DELAY; uint8_t *data = cmd + 2; self->send(self->bus, true, cmd, 1); - self->send(self->bus, false, data, data_size); + if (self->data_as_commands) { + for (uint32_t j=0; j < data_size; j++) { + self->send(self->bus, true, data + j, 1); + } + } else { + self->send(self->bus, false, data, data_size); + } uint16_t delay_length_ms = 10; if (delay) { data_size++; @@ -214,30 +221,33 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) { void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { self->send(self->bus, true, &self->set_column_command, 1); + bool isCommand = self->data_as_commands; if (self->single_byte_bounds) { uint8_t data[2]; data[0] = x0 + self->colstart; data[1] = x1 - 1 + self->colstart; - self->send(self->bus, false, (uint8_t*) data, 2); + self->send(self->bus, isCommand, (uint8_t*) data, 2); } else { uint16_t data[2]; data[0] = __builtin_bswap16(x0 + self->colstart); data[1] = __builtin_bswap16(x1 - 1 + self->colstart); - self->send(self->bus, false, (uint8_t*) data, 4); + self->send(self->bus, isCommand, (uint8_t*) data, 4); } self->send(self->bus, true, &self->set_row_command, 1); if (self->single_byte_bounds) { uint8_t data[2]; data[0] = y0 + self->rowstart; data[1] = y1 - 1 + self->rowstart; - self->send(self->bus, false, (uint8_t*) data, 2); + self->send(self->bus, isCommand, (uint8_t*) data, 2); } else { uint16_t data[2]; data[0] = __builtin_bswap16(y0 + self->rowstart); data[1] = __builtin_bswap16(y1 - 1 + self->rowstart); - self->send(self->bus, false, (uint8_t*) data, 4); + self->send(self->bus, isCommand, (uint8_t*) data, 4); + } + if (!self->data_as_commands) { + self->send(self->bus, true, &self->write_ram_command, 1); } - self->send(self->bus, true, &self->write_ram_command, 1); } bool displayio_display_frame_queued(displayio_display_obj_t* self) { diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 4ccae37bf..52f98a252 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -50,6 +50,7 @@ typedef struct { int16_t colstart; int16_t rowstart; bool single_byte_bounds; + bool data_as_commands; display_bus_begin_transaction begin_transaction; display_bus_send send; display_bus_end_transaction end_transaction; -- cgit v1.2.3 From 04a4e8a38dcbbce97a46b1980d9d505d095a2404 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 5 Apr 2019 13:10:47 -0700 Subject: Always check TileGrid's x, y When using an int index you could end up writing past the end of TileGrid's memory. Fixes #1747 --- shared-bindings/displayio/TileGrid.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index a45feaec4..7c2c0d4cc 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -259,9 +259,10 @@ STATIC mp_obj_t tilegrid_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t v mp_obj_get_array_fixed_n(index_obj, 2, &items); x = mp_obj_get_int(items[0]); y = mp_obj_get_int(items[1]); - if (x >= common_hal_displayio_tilegrid_get_width(self) || y >= common_hal_displayio_tilegrid_get_height(self)) { - mp_raise_IndexError(translate("tile index out of bounds")); - } + } + if (x >= common_hal_displayio_tilegrid_get_width(self) || + y >= common_hal_displayio_tilegrid_get_height(self)) { + mp_raise_IndexError(translate("tile index out of bounds")); } if (value_obj == MP_OBJ_SENTINEL) { -- cgit v1.2.3 From 7686f93ef456aa46f538da3159d0e12cae9fa737 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 5 Apr 2019 19:06:37 -0700 Subject: Fix crash when getting board.SPI outside the VM If one of the default pins was already in use it would crash. The internal API has been refined to allow us to get the value without causing an init of the singleton. Fixes #1753 --- .../atmel-samd/boards/hallowing_m0_express/board.c | 2 +- .../atmel-samd/common-hal/digitalio/DigitalInOut.c | 5 +++ shared-bindings/digitalio/DigitalInOut.h | 1 + shared-module/displayio/__init__.c | 2 +- supervisor/shared/board_busses.c | 45 +++++++++++++++------- supervisor/shared/board_busses.h | 3 +- supervisor/shared/external_flash/spi_flash.c | 4 ++ supervisor/shared/safe_mode.c | 3 +- 8 files changed, 48 insertions(+), 17 deletions(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index ababaef35..78c772323 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -72,7 +72,7 @@ void board_init(void) { displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, - board_spi(), + common_hal_board_create_spi(), &pin_PA28, // Command or data &pin_PA01, // Chip select &pin_PA27); // Reset diff --git a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c index 9537d6179..e167cbb69 100644 --- a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c +++ b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c @@ -49,6 +49,11 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct( return DIGITALINOUT_OK; } +void common_hal_digitalio_digitalinout_never_reset( + digitalio_digitalinout_obj_t *self) { + never_reset_pin_number(self->pin->number); +} + bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t* self) { return self->pin == mp_const_none; } diff --git a/shared-bindings/digitalio/DigitalInOut.h b/shared-bindings/digitalio/DigitalInOut.h index 2aaa31b7f..037979098 100644 --- a/shared-bindings/digitalio/DigitalInOut.h +++ b/shared-bindings/digitalio/DigitalInOut.h @@ -52,5 +52,6 @@ void common_hal_digitalio_digitalinout_set_drive_mode(digitalio_digitalinout_obj digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitalio_digitalinout_obj_t* self); void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t* self, digitalio_pull_t pull); digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t* self); +void common_hal_digitalio_digitalinout_never_reset(digitalio_digitalinout_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DIGITALINOUT_H diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index ced5b0fef..49c85f277 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -190,7 +190,7 @@ void reset_displays(void) { if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) || ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { busio_spi_obj_t* original_spi = fourwire->bus; - if (original_spi == board_spi()) { + if (original_spi == common_hal_board_get_spi()) { continue; } memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); diff --git a/supervisor/shared/board_busses.c b/supervisor/shared/board_busses.c index d77c4f331..b2d04207d 100644 --- a/supervisor/shared/board_busses.c +++ b/supervisor/shared/board_busses.c @@ -71,23 +71,42 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); STATIC busio_spi_obj_t spi_obj; STATIC mp_obj_t spi_singleton = NULL; -mp_obj_t board_spi(void) { - if (spi_singleton == NULL) { - busio_spi_obj_t *self = &spi_obj; - self->base.type = &busio_spi_type; - assert_pin_free(DEFAULT_SPI_BUS_SCK); - assert_pin_free(DEFAULT_SPI_BUS_MOSI); - assert_pin_free(DEFAULT_SPI_BUS_MISO); - const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK); - const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI); - const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO); - common_hal_busio_spi_construct(self, clock, mosi, miso); - spi_singleton = (mp_obj_t)self; +// TODO(tannewt): Move this to shared-bindings/board/__init__.c and corresponding shared-module. +mp_obj_t common_hal_board_get_spi(void) { + return spi_singleton; +} + +mp_obj_t common_hal_board_create_spi(void) { + if (spi_singleton != NULL) { + return spi_singleton; + } + busio_spi_obj_t *self = &spi_obj; + self->base.type = &busio_spi_type; + if (!common_hal_mcu_pin_is_free(DEFAULT_SPI_BUS_SCK) || + !common_hal_mcu_pin_is_free(DEFAULT_SPI_BUS_MOSI) || + !common_hal_mcu_pin_is_free(DEFAULT_SPI_BUS_MISO)) { + return NULL; } + const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK); + const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI); + const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO); + common_hal_busio_spi_construct(self, clock, mosi, miso); + spi_singleton = (mp_obj_t)self; return spi_singleton; } -#else + mp_obj_t board_spi(void) { + mp_obj_t singleton = common_hal_board_get_spi(); + if (singleton != NULL) { + return singleton; + } + assert_pin_free(DEFAULT_SPI_BUS_SCK); + assert_pin_free(DEFAULT_SPI_BUS_MOSI); + assert_pin_free(DEFAULT_SPI_BUS_MISO); + return common_hal_board_create_spi(); +} +#else +mp_obj_t common_hal_board_spi(void) { mp_raise_NotImplementedError(translate("No default SPI bus")); return NULL; } diff --git a/supervisor/shared/board_busses.h b/supervisor/shared/board_busses.h index 0ccb3ba6a..bdb3884f6 100644 --- a/supervisor/shared/board_busses.h +++ b/supervisor/shared/board_busses.h @@ -29,7 +29,8 @@ #include "py/obj.h" -mp_obj_t board_i2c(void); +mp_obj_t common_hal_board_get_spi(void); +mp_obj_t common_hal_board_create_spi(void); MP_DECLARE_CONST_FUN_OBJ_0(board_i2c_obj); mp_obj_t board_spi(void); diff --git a/supervisor/shared/external_flash/spi_flash.c b/supervisor/shared/external_flash/spi_flash.c index ec7101bc9..12888f2d3 100644 --- a/supervisor/shared/external_flash/spi_flash.c +++ b/supervisor/shared/external_flash/spi_flash.c @@ -132,11 +132,15 @@ bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length) } void spi_flash_init(void) { + cs_pin.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&cs_pin, SPI_FLASH_CS_PIN); + // Set CS high (disabled). common_hal_digitalio_digitalinout_switch_to_output(&cs_pin, true, DRIVE_MODE_PUSH_PULL); + common_hal_digitalio_digitalinout_never_reset(&cs_pin); + spi.base.type = &busio_spi_type; common_hal_busio_spi_construct(&spi, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN); common_hal_busio_spi_never_reset(&spi); } diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index 3bb75b897..7182bbcca 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -77,7 +77,8 @@ safe_mode_t wait_for_safe_mode_reset(void) { return NO_SAFE_MODE; } -void reset_into_safe_mode(safe_mode_t reason) { +// Inline this so it's easy to break on it from GDB. +void __attribute__((noinline,)) reset_into_safe_mode(safe_mode_t reason) { if (current_safe_mode > BROWNOUT && reason > BROWNOUT) { while (true) { // This very bad because it means running in safe mode didn't save us. Only ignore brownout -- cgit v1.2.3 From 4b3cb7b6db688e7701b603eea4d380145155567c Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sat, 6 Apr 2019 14:25:08 +0200 Subject: Expose displayio.Display.bus With the bus exposed, we can send custom commands to the display, to leverage advanced features specific to the display, which are not exposed by default. --- shared-bindings/displayio/Display.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index f36fd3d07..c4f65704f 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -295,6 +295,25 @@ const mp_obj_property_t displayio_display_height_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| .. attribute:: bus +//| +//| The bus being used by the display +//| +//| +STATIC mp_obj_t displayio_display_obj_get_bus(mp_obj_t self_in) { + displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + return self->bus; +} +MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_bus_obj, displayio_display_obj_get_bus); + +const mp_obj_property_t displayio_display_bus_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_display_get_bus_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + + STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_display_show_obj) }, { MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_display_refresh_soon_obj) }, @@ -305,6 +324,7 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) }, + { MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_display_bus_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table); -- cgit v1.2.3 From 8323721232f52fcb216a4fa32e5572d5f4369c6c Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sat, 6 Apr 2019 15:08:31 +0200 Subject: Stop hard-coding SPI frequency in FourWire Instead remember and use the frequency, polarity and phase that was set when the bus was first created. --- ports/atmel-samd/boards/hallowing_m0_express/board.c | 5 ++++- ports/atmel-samd/common-hal/busio/SPI.c | 10 ++++++++++ ports/nrf/common-hal/busio/SPI.c | 10 ++++++++++ shared-bindings/busio/SPI.h | 6 ++++++ shared-module/displayio/FourWire.c | 7 +++++-- shared-module/displayio/FourWire.h | 3 +++ 6 files changed, 38 insertions(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index ababaef35..599413a0d 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -29,6 +29,7 @@ #include "shared-bindings/displayio/FourWire.h" #include "shared-module/displayio/__init__.h" #include "shared-module/displayio/mipi_constants.h" +#include "shared-bindings/busio/SPI.h" #include "tick.h" @@ -71,8 +72,10 @@ uint8_t display_init_sequence[] = { void board_init(void) { displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; + busio_spi_obj_t *spi = board_spi(); + common_hal_busio_spi_configure(spi, 12000000, 0, 0, 8); common_hal_displayio_fourwire_construct(bus, - board_spi(), + spi, &pin_PA28, // Command or data &pin_PA01, // Chip select &pin_PA27); // Reset diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index ca58e3fd5..644b9a87b 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -361,3 +361,13 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uin uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self) { return samd_peripherals_spi_baud_reg_value_to_baudrate(hri_sercomspi_read_BAUD_reg(self->spi_desc.dev.prvt)); } + +uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) { + void * hw = self->spi_desc.dev.prvt; + return hri_sercomspi_get_CTRLA_CPHA_bit(hw); +} + +uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) { + void * hw = self->spi_desc.dev.prvt; + return hri_sercomspi_get_CTRLA_CPOL_bit(hw); +} diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 19bd4d1ba..d358dbba4 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -327,3 +327,13 @@ uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self) { return 0; } } + +uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) { + // XXX(deshipu) implement + return 0; +} + +uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) { + // XXX(deshipu) implement + return 0; +} diff --git a/shared-bindings/busio/SPI.h b/shared-bindings/busio/SPI.h index 2d12b8b76..b7b0715d1 100644 --- a/shared-bindings/busio/SPI.h +++ b/shared-bindings/busio/SPI.h @@ -61,6 +61,12 @@ extern bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_o // Return actual SPI bus frequency. uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self); +// Return SPI bus phase. +uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self); + +// Return SPI bus polarity. +uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self); + // This is used by the supervisor to claim SPI devices indefinitely. extern void common_hal_busio_spi_never_reset(busio_spi_obj_t *self); diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c index 043f68e26..c87d2be95 100644 --- a/shared-module/displayio/FourWire.c +++ b/shared-module/displayio/FourWire.c @@ -40,6 +40,9 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self, self->bus = spi; common_hal_busio_spi_never_reset(self->bus); + self->frequency = common_hal_busio_spi_get_frequency(spi); + self->polarity = common_hal_busio_spi_get_polarity(spi); + self->phase = common_hal_busio_spi_get_phase(spi); common_hal_digitalio_digitalinout_construct(&self->command, command); common_hal_digitalio_digitalinout_switch_to_output(&self->command, true, DRIVE_MODE_PUSH_PULL); @@ -71,8 +74,8 @@ bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t obj) { if (!common_hal_busio_spi_try_lock(self->bus)) { return false; } - // TODO(tannewt): Stop hardcoding SPI frequency, polarity and phase. - common_hal_busio_spi_configure(self->bus, 12000000, 0, 0, 8); + common_hal_busio_spi_configure(self->bus, self->frequency, self->polarity, + self->phase, 8); common_hal_digitalio_digitalinout_set_value(&self->chip_select, false); return true; } diff --git a/shared-module/displayio/FourWire.h b/shared-module/displayio/FourWire.h index 234bcf794..743139e62 100644 --- a/shared-module/displayio/FourWire.h +++ b/shared-module/displayio/FourWire.h @@ -38,6 +38,9 @@ typedef struct { digitalio_digitalinout_obj_t command; digitalio_digitalinout_obj_t chip_select; digitalio_digitalinout_obj_t reset; + uint32_t frequency; + uint8_t polarity; + uint8_t phase; } displayio_fourwire_obj_t; #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H -- cgit v1.2.3 From 0f003ac5b8312fafb120e86e05eefd2431014d8c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 8 Apr 2019 16:58:50 -0700 Subject: Reorganize board busses into shared-bindings and shared-module. --- locale/ID.po | 16 +- locale/circuitpython.pot | 14 +- locale/de_DE.po | 16 +- locale/en_US.po | 14 +- locale/en_x_pirate.po | 14 +- locale/es.po | 16 +- locale/fil.po | 16 +- locale/fr.po | 16 +- locale/it_IT.po | 16 +- locale/pl.po | 16 +- locale/pt_BR.po | 16 +- main.c | 5 +- ports/atmel-samd/boards/arduino_mkr1300/pins.c | 2 - ports/atmel-samd/boards/arduino_mkrzero/pins.c | 2 - ports/atmel-samd/boards/arduino_zero/pins.c | 2 - ports/atmel-samd/boards/catwan_usbstick/pins.c | 2 - .../boards/circuitplayground_express/pins.c | 2 - .../circuitplayground_express_crickit/pins.c | 2 - ports/atmel-samd/boards/cp32-m4/pins.c | 2 - ports/atmel-samd/boards/datalore_ip_m4/pins.c | 2 - .../atmel-samd/boards/feather_m0_adalogger/pins.c | 2 - ports/atmel-samd/boards/feather_m0_basic/pins.c | 2 - ports/atmel-samd/boards/feather_m0_express/pins.c | 2 - .../boards/feather_m0_express_crickit/pins.c | 2 - ports/atmel-samd/boards/feather_m0_rfm69/pins.c | 2 - ports/atmel-samd/boards/feather_m0_rfm9x/pins.c | 2 - .../atmel-samd/boards/feather_m0_supersized/pins.c | 2 - ports/atmel-samd/boards/feather_m4_express/pins.c | 2 - .../boards/feather_radiofruit_zigbee/pins.c | 2 - ports/atmel-samd/boards/gemma_m0/pins.c | 2 - .../boards/grandcentral_m4_express/pins.c | 2 - .../atmel-samd/boards/hallowing_m0_express/pins.c | 1 - .../atmel-samd/boards/itsybitsy_m0_express/pins.c | 2 - .../atmel-samd/boards/itsybitsy_m4_express/pins.c | 2 - ports/atmel-samd/boards/meowmeow/pins.c | 2 - ports/atmel-samd/boards/metro_m0_express/pins.c | 2 - .../atmel-samd/boards/metro_m4_airlift_lite/pins.c | 2 - ports/atmel-samd/boards/metro_m4_express/pins.c | 2 - ports/atmel-samd/boards/mini_sam_m4/pins.c | 2 - ports/atmel-samd/boards/pewpew10/pins.c | 2 - ports/atmel-samd/boards/pirkey_m0/pins.c | 2 - ports/atmel-samd/boards/pybadge/board.c | 9 +- ports/atmel-samd/boards/pybadge/pins.c | 1 - ports/atmel-samd/boards/pyportal/board.c | 1 - ports/atmel-samd/boards/pyportal/pins.c | 1 - ports/atmel-samd/boards/sam32/pins.c | 2 - ports/atmel-samd/boards/sparkfun_lumidrive/pins.c | 2 - .../boards/sparkfun_redboard_turbo/pins.c | 2 - ports/atmel-samd/boards/sparkfun_samd21_dev/pins.c | 2 - .../atmel-samd/boards/sparkfun_samd21_mini/pins.c | 2 - ports/atmel-samd/boards/trellis_m4_express/pins.c | 2 - ports/atmel-samd/boards/trinket_m0/pins.c | 2 - ports/atmel-samd/boards/trinket_m0_haxpress/pins.c | 2 - ports/atmel-samd/boards/uchip/pins.c | 2 - ports/atmel-samd/boards/ugame10/pins.c | 2 - ports/nrf/boards/feather_nrf52840_express/pins.c | 2 - ports/nrf/boards/makerdiary_nrf52840_mdk/pins.c | 2 - .../makerdiary_nrf52840_mdk_usb_dongle/pins.c | 2 - ports/nrf/boards/particle_argon/pins.c | 2 - ports/nrf/boards/particle_boron/pins.c | 2 - ports/nrf/boards/particle_xenon/pins.c | 2 - ports/nrf/boards/pca10056/pins.c | 2 - ports/nrf/boards/pca10059/pins.c | 2 - ports/nrf/boards/sparkfun_nrf52840_mini/pins.c | 2 - py/circuitpy_defns.mk | 1 + py/circuitpy_mpconfig.h | 23 +++ py/gc.c | 32 ++++ py/gc.h | 4 + py/mpstate.h | 2 + shared-bindings/board/__init__.c | 75 ++++++++++ shared-bindings/board/__init__.h | 12 ++ shared-bindings/displayio/FourWire.h | 1 - shared-module/board/__init__.c | 115 ++++++++++++++ shared-module/board/__init__.h | 32 ++++ shared-module/displayio/FourWire.c | 2 + shared-module/displayio/__init__.c | 4 + supervisor/shared/board_busses.c | 165 --------------------- supervisor/shared/board_busses.h | 44 ------ supervisor/shared/safe_mode.c | 3 +- supervisor/supervisor.mk | 1 - 80 files changed, 352 insertions(+), 446 deletions(-) create mode 100644 shared-module/board/__init__.c create mode 100644 shared-module/board/__init__.h delete mode 100644 supervisor/shared/board_busses.c delete mode 100644 supervisor/shared/board_busses.h (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 8460f7876..2e01bfe9a 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -924,17 +924,9 @@ msgstr "Tidak ada pin TX" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "Tidak ada standar bus I2C" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "Tidak ada standar bus SPI" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "Tidak ada standar bus UART" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" +msgstr "Tidak ada standar bus %q" #: ports/atmel-samd/common-hal/touchio/TouchIn.c msgid "No free GCLKs" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 8516b5e5d..e38aa7727 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -899,16 +899,8 @@ msgstr "" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" msgstr "" #: ports/atmel-samd/common-hal/touchio/TouchIn.c diff --git a/locale/de_DE.po b/locale/de_DE.po index acfc8ad4d..ae76bc76c 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -912,17 +912,9 @@ msgstr "Kein TX Pin" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "Kein Standard I2C Bus" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "Kein Standard SPI Bus" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "Kein Standard UART Bus" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" +msgstr "Kein Standard %q Bus" #: ports/atmel-samd/common-hal/touchio/TouchIn.c msgid "No free GCLKs" diff --git a/locale/en_US.po b/locale/en_US.po index 1f422aeee..fb62ea2b0 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -899,16 +899,8 @@ msgstr "" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" msgstr "" #: ports/atmel-samd/common-hal/touchio/TouchIn.c diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index e0bfa9f91..24af776c0 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -903,16 +903,8 @@ msgstr "" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" msgstr "" #: ports/atmel-samd/common-hal/touchio/TouchIn.c diff --git a/locale/es.po b/locale/es.po index be6426749..661c591d3 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -937,17 +937,9 @@ msgstr "Sin pin TX" msgid "No available clocks" msgstr "Relojes no disponibles" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "Sin bus I2C por defecto" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "Sin bus SPI por defecto" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "Sin bus UART por defecto" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" +msgstr "Sin bus %q por defecto" #: ports/atmel-samd/common-hal/touchio/TouchIn.c msgid "No free GCLKs" diff --git a/locale/fil.po b/locale/fil.po index dd838cb66..7873ec685 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -933,17 +933,9 @@ msgstr "Walang TX pin" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "Walang default na I2C bus" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "Walang default SPI bus" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "Walang default UART bus" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" +msgstr "Walang default na %q bus" #: ports/atmel-samd/common-hal/touchio/TouchIn.c msgid "No free GCLKs" diff --git a/locale/fr.po b/locale/fr.po index 9733a0103..9c723333d 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -936,17 +936,9 @@ msgstr "Pas de broche TX" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "Pas de bus I2C par défaut" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "Pas de bus SPI par défaut" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "Pas de bus UART par défaut" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" +msgstr "Pas de bus %q par défaut" #: ports/atmel-samd/common-hal/touchio/TouchIn.c msgid "No free GCLKs" diff --git a/locale/it_IT.po b/locale/it_IT.po index 04ee36063..c14b3698b 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -932,17 +932,9 @@ msgstr "Nessun pin TX" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "Nessun bus I2C predefinito" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "Nessun bus SPI predefinito" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "Nessun bus UART predefinito" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" +msgstr "Nessun bus %q predefinito" #: ports/atmel-samd/common-hal/touchio/TouchIn.c msgid "No free GCLKs" diff --git a/locale/pl.po b/locale/pl.po index d845dc260..1b861fff0 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -909,17 +909,9 @@ msgstr "Brak nóżki TX" msgid "No available clocks" msgstr "Brak dostępnych zegarów" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "Nie ma domyślnej magistrali I2C" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "Nie ma domyślnej magistrali SPI" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "Nie ma domyślnej magistrali UART" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" +msgstr "Nie ma domyślnej magistrali %q" #: ports/atmel-samd/common-hal/touchio/TouchIn.c msgid "No free GCLKs" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 992576486..4685e9c82 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-04 13:37-0700\n" +"POT-Creation-Date: 2019-04-08 16:48-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -922,17 +922,9 @@ msgstr "Nenhum pino TX" msgid "No available clocks" msgstr "" -#: supervisor/shared/board_busses.c -msgid "No default I2C bus" -msgstr "Nenhum barramento I2C padrão" - -#: supervisor/shared/board_busses.c -msgid "No default SPI bus" -msgstr "Nenhum barramento SPI padrão" - -#: supervisor/shared/board_busses.c -msgid "No default UART bus" -msgstr "Nenhum barramento UART padrão" +#: shared-bindings/board/__init__.c +msgid "No default %q bus" +msgstr "Nenhum barramento %q padrão" #: ports/atmel-samd/common-hal/touchio/TouchIn.c msgid "No free GCLKs" diff --git a/main.c b/main.c index 77498d7de..dc47a70de 100755 --- a/main.c +++ b/main.c @@ -50,7 +50,6 @@ #include "supervisor/port.h" #include "supervisor/filesystem.h" #include "supervisor/shared/autoreload.h" -#include "supervisor/shared/board_busses.h" #include "supervisor/shared/translate.h" #include "supervisor/shared/rgb_led_status.h" #include "supervisor/shared/safe_mode.h" @@ -62,6 +61,10 @@ #include "shared-module/network/__init__.h" #endif +#if CIRCUITPY_BOARD +#include "shared-module/board/__init__.h" +#endif + void do_str(const char *src, mp_parse_input_kind_t input_kind) { mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); if (lex == NULL) { diff --git a/ports/atmel-samd/boards/arduino_mkr1300/pins.c b/ports/atmel-samd/boards/arduino_mkr1300/pins.c index a5a058ace..7a73e89bf 100644 --- a/ports/atmel-samd/boards/arduino_mkr1300/pins.c +++ b/ports/atmel-samd/boards/arduino_mkr1300/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB02) }, diff --git a/ports/atmel-samd/boards/arduino_mkrzero/pins.c b/ports/atmel-samd/boards/arduino_mkrzero/pins.c index 654c0d6da..2494076ab 100644 --- a/ports/atmel-samd/boards/arduino_mkrzero/pins.c +++ b/ports/atmel-samd/boards/arduino_mkrzero/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB02) }, diff --git a/ports/atmel-samd/boards/arduino_zero/pins.c b/ports/atmel-samd/boards/arduino_zero/pins.c index f9403bb9a..7ebcc9a6e 100644 --- a/ports/atmel-samd/boards/arduino_zero/pins.c +++ b/ports/atmel-samd/boards/arduino_zero/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/catwan_usbstick/pins.c b/ports/atmel-samd/boards/catwan_usbstick/pins.c index 87ee84c0b..346bd9c10 100644 --- a/ports/atmel-samd/boards/catwan_usbstick/pins.c +++ b/ports/atmel-samd/boards/catwan_usbstick/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA30) }, { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA31) }, diff --git a/ports/atmel-samd/boards/circuitplayground_express/pins.c b/ports/atmel-samd/boards/circuitplayground_express/pins.c index 70743366e..6fc46bd21 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/pins.c +++ b/ports/atmel-samd/boards/circuitplayground_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA02) }, diff --git a/ports/atmel-samd/boards/circuitplayground_express_crickit/pins.c b/ports/atmel-samd/boards/circuitplayground_express_crickit/pins.c index 70743366e..6fc46bd21 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_crickit/pins.c +++ b/ports/atmel-samd/boards/circuitplayground_express_crickit/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA02) }, diff --git a/ports/atmel-samd/boards/cp32-m4/pins.c b/ports/atmel-samd/boards/cp32-m4/pins.c index 9da67dfb4..bbad6f75f 100644 --- a/ports/atmel-samd/boards/cp32-m4/pins.c +++ b/ports/atmel-samd/boards/cp32-m4/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from // microcontroller.pin. diff --git a/ports/atmel-samd/boards/datalore_ip_m4/pins.c b/ports/atmel-samd/boards/datalore_ip_m4/pins.c index 63ae319a2..4eb26dd21 100644 --- a/ports/atmel-samd/boards/datalore_ip_m4/pins.c +++ b/ports/atmel-samd/boards/datalore_ip_m4/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from // microcontroller.pin. diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/pins.c b/ports/atmel-samd/boards/feather_m0_adalogger/pins.c index d99e62c95..63d134952 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/pins.c +++ b/ports/atmel-samd/boards/feather_m0_adalogger/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/feather_m0_basic/pins.c b/ports/atmel-samd/boards/feather_m0_basic/pins.c index f9b6db63b..f15ec2e9d 100644 --- a/ports/atmel-samd/boards/feather_m0_basic/pins.c +++ b/ports/atmel-samd/boards/feather_m0_basic/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/feather_m0_express/pins.c b/ports/atmel-samd/boards/feather_m0_express/pins.c index 1eaa98a58..3c4effbe3 100644 --- a/ports/atmel-samd/boards/feather_m0_express/pins.c +++ b/ports/atmel-samd/boards/feather_m0_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/feather_m0_express_crickit/pins.c b/ports/atmel-samd/boards/feather_m0_express_crickit/pins.c index 1eaa98a58..3c4effbe3 100644 --- a/ports/atmel-samd/boards/feather_m0_express_crickit/pins.c +++ b/ports/atmel-samd/boards/feather_m0_express_crickit/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/feather_m0_rfm69/pins.c b/ports/atmel-samd/boards/feather_m0_rfm69/pins.c index ba59cb69b..178f945ad 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm69/pins.c +++ b/ports/atmel-samd/boards/feather_m0_rfm69/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/feather_m0_rfm9x/pins.c b/ports/atmel-samd/boards/feather_m0_rfm9x/pins.c index 29a01d405..977cb9fdf 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm9x/pins.c +++ b/ports/atmel-samd/boards/feather_m0_rfm9x/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/feather_m0_supersized/pins.c b/ports/atmel-samd/boards/feather_m0_supersized/pins.c index 1eaa98a58..3c4effbe3 100644 --- a/ports/atmel-samd/boards/feather_m0_supersized/pins.c +++ b/ports/atmel-samd/boards/feather_m0_supersized/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/feather_m4_express/pins.c b/ports/atmel-samd/boards/feather_m4_express/pins.c index cec9fe37f..d9496ecfc 100644 --- a/ports/atmel-samd/boards/feather_m4_express/pins.c +++ b/ports/atmel-samd/boards/feather_m4_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, diff --git a/ports/atmel-samd/boards/feather_radiofruit_zigbee/pins.c b/ports/atmel-samd/boards/feather_radiofruit_zigbee/pins.c index 211596f78..713397878 100755 --- a/ports/atmel-samd/boards/feather_radiofruit_zigbee/pins.c +++ b/ports/atmel-samd/boards/feather_radiofruit_zigbee/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PB02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB03) }, diff --git a/ports/atmel-samd/boards/gemma_m0/pins.c b/ports/atmel-samd/boards/gemma_m0/pins.c index b24b45838..9aecd5d84 100644 --- a/ports/atmel-samd/boards/gemma_m0/pins.c +++ b/ports/atmel-samd/boards/gemma_m0/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, // pad 1 { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA05) }, diff --git a/ports/atmel-samd/boards/grandcentral_m4_express/pins.c b/ports/atmel-samd/boards/grandcentral_m4_express/pins.c index 26d0e71a0..6b09c62bf 100644 --- a/ports/atmel-samd/boards/grandcentral_m4_express/pins.c +++ b/ports/atmel-samd/boards/grandcentral_m4_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from // microcontroller.pin. diff --git a/ports/atmel-samd/boards/hallowing_m0_express/pins.c b/ports/atmel-samd/boards/hallowing_m0_express/pins.c index 3db1b1752..3e670a676 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/pins.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/pins.c @@ -1,7 +1,6 @@ #include "shared-bindings/board/__init__.h" #include "boards/board.h" -#include "supervisor/shared/board_busses.h" #include "shared-module/displayio/__init__.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { diff --git a/ports/atmel-samd/boards/itsybitsy_m0_express/pins.c b/ports/atmel-samd/boards/itsybitsy_m0_express/pins.c index 912fba4ed..1b0e5d09e 100644 --- a/ports/atmel-samd/boards/itsybitsy_m0_express/pins.c +++ b/ports/atmel-samd/boards/itsybitsy_m0_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, diff --git a/ports/atmel-samd/boards/itsybitsy_m4_express/pins.c b/ports/atmel-samd/boards/itsybitsy_m4_express/pins.c index ed91c88ee..8cd2f44f8 100644 --- a/ports/atmel-samd/boards/itsybitsy_m4_express/pins.c +++ b/ports/atmel-samd/boards/itsybitsy_m4_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from // microcontroller.pin. diff --git a/ports/atmel-samd/boards/meowmeow/pins.c b/ports/atmel-samd/boards/meowmeow/pins.c index 089baad32..41d122d87 100644 --- a/ports/atmel-samd/boards/meowmeow/pins.c +++ b/ports/atmel-samd/boards/meowmeow/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA03) }, diff --git a/ports/atmel-samd/boards/metro_m0_express/pins.c b/ports/atmel-samd/boards/metro_m0_express/pins.c index 0707a3581..c11fac5ce 100644 --- a/ports/atmel-samd/boards/metro_m0_express/pins.c +++ b/ports/atmel-samd/boards/metro_m0_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/metro_m4_airlift_lite/pins.c b/ports/atmel-samd/boards/metro_m4_airlift_lite/pins.c index 4b72c42f0..4e90870c4 100644 --- a/ports/atmel-samd/boards/metro_m4_airlift_lite/pins.c +++ b/ports/atmel-samd/boards/metro_m4_airlift_lite/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from // microcontroller.pin. diff --git a/ports/atmel-samd/boards/metro_m4_express/pins.c b/ports/atmel-samd/boards/metro_m4_express/pins.c index 63ae319a2..4eb26dd21 100644 --- a/ports/atmel-samd/boards/metro_m4_express/pins.c +++ b/ports/atmel-samd/boards/metro_m4_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from // microcontroller.pin. diff --git a/ports/atmel-samd/boards/mini_sam_m4/pins.c b/ports/atmel-samd/boards/mini_sam_m4/pins.c index f78fe1bc8..b1d8d5325 100644 --- a/ports/atmel-samd/boards/mini_sam_m4/pins.c +++ b/ports/atmel-samd/boards/mini_sam_m4/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from // microcontroller.pin. diff --git a/ports/atmel-samd/boards/pewpew10/pins.c b/ports/atmel-samd/boards/pewpew10/pins.c index e2552dc32..9e5b9d98e 100644 --- a/ports/atmel-samd/boards/pewpew10/pins.c +++ b/ports/atmel-samd/boards/pewpew10/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { // Pins for internal use. { MP_ROM_QSTR(MP_QSTR__R1), MP_ROM_PTR(&pin_PA05) }, diff --git a/ports/atmel-samd/boards/pirkey_m0/pins.c b/ports/atmel-samd/boards/pirkey_m0/pins.c index a6dbcefe3..e1f43c83c 100644 --- a/ports/atmel-samd/boards/pirkey_m0/pins.c +++ b/ports/atmel-samd/boards/pirkey_m0/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_REMOTEIN), MP_ROM_PTR(&pin_PA28) }, diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 867fb9fa4..f234db8ca 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -69,16 +69,15 @@ uint8_t display_init_sequence[] = { 0x29, 0 | DELAY, 100, // _DISPON }; -STATIC busio_spi_obj_t display_spi_obj; - void board_init(void) { - common_hal_busio_spi_construct(&display_spi_obj, &pin_PB13, &pin_PB12, NULL); - common_hal_busio_spi_never_reset(&display_spi_obj); + busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, NULL); + common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, - &display_spi_obj, + spi, &pin_PB05, // TFT_DC Command or data &pin_PB07, // TFT_CS Chip select &pin_PA01); // TFT_RST Reset diff --git a/ports/atmel-samd/boards/pybadge/pins.c b/ports/atmel-samd/boards/pybadge/pins.c index 41ab634c9..2134cf8c7 100644 --- a/ports/atmel-samd/boards/pybadge/pins.c +++ b/ports/atmel-samd/boards/pybadge/pins.c @@ -1,7 +1,6 @@ #include "shared-bindings/board/__init__.h" #include "boards/board.h" -#include "supervisor/shared/board_busses.h" #include "shared-module/displayio/__init__.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index d0a602066..222e11144 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -25,7 +25,6 @@ */ #include "boards/board.h" -#include "supervisor/shared/board_busses.h" #include "mpconfigboard.h" #include "hal/include/hal_gpio.h" diff --git a/ports/atmel-samd/boards/pyportal/pins.c b/ports/atmel-samd/boards/pyportal/pins.c index 4a41ee913..14699a209 100644 --- a/ports/atmel-samd/boards/pyportal/pins.c +++ b/ports/atmel-samd/boards/pyportal/pins.c @@ -2,7 +2,6 @@ #include "boards/board.h" #include "shared-module/displayio/__init__.h" -#include "supervisor/shared/board_busses.h" // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from diff --git a/ports/atmel-samd/boards/sam32/pins.c b/ports/atmel-samd/boards/sam32/pins.c index b2e0a3f2b..f32057d75 100644 --- a/ports/atmel-samd/boards/sam32/pins.c +++ b/ports/atmel-samd/boards/sam32/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PB08) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB09) }, diff --git a/ports/atmel-samd/boards/sparkfun_lumidrive/pins.c b/ports/atmel-samd/boards/sparkfun_lumidrive/pins.c index 232c89e38..f2faa901d 100755 --- a/ports/atmel-samd/boards/sparkfun_lumidrive/pins.c +++ b/ports/atmel-samd/boards/sparkfun_lumidrive/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) }, diff --git a/ports/atmel-samd/boards/sparkfun_redboard_turbo/pins.c b/ports/atmel-samd/boards/sparkfun_redboard_turbo/pins.c index 223e20359..485589fca 100755 --- a/ports/atmel-samd/boards/sparkfun_redboard_turbo/pins.c +++ b/ports/atmel-samd/boards/sparkfun_redboard_turbo/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, diff --git a/ports/atmel-samd/boards/sparkfun_samd21_dev/pins.c b/ports/atmel-samd/boards/sparkfun_samd21_dev/pins.c index 9eab132c3..039100956 100644 --- a/ports/atmel-samd/boards/sparkfun_samd21_dev/pins.c +++ b/ports/atmel-samd/boards/sparkfun_samd21_dev/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { // Analog pins diff --git a/ports/atmel-samd/boards/sparkfun_samd21_mini/pins.c b/ports/atmel-samd/boards/sparkfun_samd21_mini/pins.c index 42cd3736b..a90b0b5a3 100644 --- a/ports/atmel-samd/boards/sparkfun_samd21_mini/pins.c +++ b/ports/atmel-samd/boards/sparkfun_samd21_mini/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { // Analog pins diff --git a/ports/atmel-samd/boards/trellis_m4_express/pins.c b/ports/atmel-samd/boards/trellis_m4_express/pins.c index a9f204318..4a0fa3ca2 100644 --- a/ports/atmel-samd/boards/trellis_m4_express/pins.c +++ b/ports/atmel-samd/boards/trellis_m4_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from // microcontroller.pin. diff --git a/ports/atmel-samd/boards/trinket_m0/pins.c b/ports/atmel-samd/boards/trinket_m0/pins.c index b3637bd5b..372601e62 100644 --- a/ports/atmel-samd/boards/trinket_m0/pins.c +++ b/ports/atmel-samd/boards/trinket_m0/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA08) }, { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA08) }, diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/pins.c b/ports/atmel-samd/boards/trinket_m0_haxpress/pins.c index b3637bd5b..372601e62 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/pins.c +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA08) }, { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA08) }, diff --git a/ports/atmel-samd/boards/uchip/pins.c b/ports/atmel-samd/boards/uchip/pins.c index 7476c60ad..65b1c79cc 100644 --- a/ports/atmel-samd/boards/uchip/pins.c +++ b/ports/atmel-samd/boards/uchip/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA06) }, { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA08) }, diff --git a/ports/atmel-samd/boards/ugame10/pins.c b/ports/atmel-samd/boards/ugame10/pins.c index 71db52752..904ac224b 100644 --- a/ports/atmel-samd/boards/ugame10/pins.c +++ b/ports/atmel-samd/boards/ugame10/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_O), MP_ROM_PTR(&pin_PA01) }, diff --git a/ports/nrf/boards/feather_nrf52840_express/pins.c b/ports/nrf/boards/feather_nrf52840_express/pins.c index c6f643761..ec2689ab4 100644 --- a/ports/nrf/boards/feather_nrf52840_express/pins.c +++ b/ports/nrf/boards/feather_nrf52840_express/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_05) }, diff --git a/ports/nrf/boards/makerdiary_nrf52840_mdk/pins.c b/ports/nrf/boards/makerdiary_nrf52840_mdk/pins.c index 2d24e8597..5284c2484 100644 --- a/ports/nrf/boards/makerdiary_nrf52840_mdk/pins.c +++ b/ports/nrf/boards/makerdiary_nrf52840_mdk/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_AIN0), MP_ROM_PTR(&pin_P0_02) }, { MP_ROM_QSTR(MP_QSTR_AIN1), MP_ROM_PTR(&pin_P0_03) }, diff --git a/ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/pins.c b/ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/pins.c index 10490c8cb..006b24768 100644 --- a/ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/pins.c +++ b/ports/nrf/boards/makerdiary_nrf52840_mdk_usb_dongle/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_AIN0), MP_ROM_PTR(&pin_P0_02) }, { MP_ROM_QSTR(MP_QSTR_AIN1), MP_ROM_PTR(&pin_P0_03) }, diff --git a/ports/nrf/boards/particle_argon/pins.c b/ports/nrf/boards/particle_argon/pins.c index 10d547f91..9fab9e6b6 100644 --- a/ports/nrf/boards/particle_argon/pins.c +++ b/ports/nrf/boards/particle_argon/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_03) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_04) }, diff --git a/ports/nrf/boards/particle_boron/pins.c b/ports/nrf/boards/particle_boron/pins.c index 0b827a85a..4d6f3e7de 100644 --- a/ports/nrf/boards/particle_boron/pins.c +++ b/ports/nrf/boards/particle_boron/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_03) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_04) }, diff --git a/ports/nrf/boards/particle_xenon/pins.c b/ports/nrf/boards/particle_xenon/pins.c index 644face61..a50c8b641 100644 --- a/ports/nrf/boards/particle_xenon/pins.c +++ b/ports/nrf/boards/particle_xenon/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_03) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_04) }, diff --git a/ports/nrf/boards/pca10056/pins.c b/ports/nrf/boards/pca10056/pins.c index 510b6100e..e00bc8a11 100644 --- a/ports/nrf/boards/pca10056/pins.c +++ b/ports/nrf/boards/pca10056/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, diff --git a/ports/nrf/boards/pca10059/pins.c b/ports/nrf/boards/pca10059/pins.c index c43d3a9eb..932b925d1 100644 --- a/ports/nrf/boards/pca10059/pins.c +++ b/ports/nrf/boards/pca10059/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, diff --git a/ports/nrf/boards/sparkfun_nrf52840_mini/pins.c b/ports/nrf/boards/sparkfun_nrf52840_mini/pins.c index f826ac771..e7b61db58 100644 --- a/ports/nrf/boards/sparkfun_nrf52840_mini/pins.c +++ b/ports/nrf/boards/sparkfun_nrf52840_mini/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P1_15) }, // D1/TX { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P0_17) }, // D0/RX diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 7a369817a..342c0ab0c 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -302,6 +302,7 @@ $(filter $(SRC_PATTERNS), \ bitbangio/OneWire.c \ bitbangio/SPI.c \ bitbangio/__init__.c \ + board/__init__.c \ busio/OneWire.c \ displayio/Bitmap.c \ displayio/ColorConverter.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 6da3ae910..441dd5bad 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -252,8 +252,29 @@ extern const struct _mp_obj_module_t bleio_module; #if CIRCUITPY_BOARD #define BOARD_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, extern const struct _mp_obj_module_t board_module; + +#define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL)) +#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI)) +#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX)) + +#if BOARD_I2C +#define BOARD_I2C_ROOT_POINTER mp_obj_t shared_i2c_bus; +#else +#define BOARD_I2C_ROOT_POINTER +#endif + +// SPI is always allocated off the heap. + +#if BOARD_UART +#define BOARD_UART_ROOT_POINTER mp_obj_t shared_uart_bus; +#else +#define BOARD_UART_ROOT_POINTER +#endif + #else #define BOARD_MODULE +#define BOARD_I2C_ROOT_POINTER +#define BOARD_UART_ROOT_POINTER #endif #if CIRCUITPY_BUSIO @@ -586,6 +607,8 @@ extern const struct _mp_obj_module_t ustack_module; mp_obj_t gamepad_singleton; \ mp_obj_t pew_singleton; \ mp_obj_t terminal_tilegrid_tiles; \ + BOARD_I2C_ROOT_POINTER \ + BOARD_UART_ROOT_POINTER \ FLASH_ROOT_POINTERS \ NETWORK_ROOT_POINTERS \ diff --git a/py/gc.c b/py/gc.c index 81e609730..246df1503 100755 --- a/py/gc.c +++ b/py/gc.c @@ -176,6 +176,8 @@ void gc_init(void *start, void *end) { mp_thread_mutex_init(&MP_STATE_MEM(gc_mutex)); #endif + MP_STATE_MEM(permanent_pointers) = NULL; + DEBUG_printf("GC layout:\n"); DEBUG_printf(" alloc table at %p, length " UINT_FMT " bytes, " UINT_FMT " blocks\n", MP_STATE_MEM(gc_alloc_table_start), MP_STATE_MEM(gc_alloc_table_byte_len), MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB); #if MICROPY_ENABLE_FINALISER @@ -359,6 +361,10 @@ void gc_collect_start(void) { size_t root_end = offsetof(mp_state_ctx_t, vm.qstr_last_chunk); gc_collect_root(ptrs + root_start / sizeof(void*), (root_end - root_start) / sizeof(void*)); + if (MP_STATE_MEM(permanent_pointers) != NULL) { + gc_collect_root(MP_STATE_MEM(permanent_pointers), BYTES_PER_BLOCK / sizeof(void*)); + } + #if MICROPY_ENABLE_PYSTACK // Trace root pointers from the Python stack. ptrs = (void**)(void*)MP_STATE_THREAD(pystack_start); @@ -938,6 +944,32 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) { } #endif // Alternative gc_realloc impl +bool gc_never_free(void *ptr) { + // Pointers are stored in a linked list where each block is BYTES_PER_BLOCK long and the first + // pointer is the next block of pointers. + void ** current_reference_block = MP_STATE_MEM(permanent_pointers); + while (current_reference_block != NULL) { + for (size_t i = 1; i < BYTES_PER_BLOCK / sizeof(void*); i++) { + if (current_reference_block[i] == NULL) { + current_reference_block[i] = ptr; + return true; + } + } + current_reference_block = current_reference_block[0]; + } + void** next_block = gc_alloc(BYTES_PER_BLOCK, false, true); + if (next_block == NULL) { + return false; + } + if (MP_STATE_MEM(permanent_pointers) == NULL) { + MP_STATE_MEM(permanent_pointers) = next_block; + } else { + current_reference_block[0] = next_block; + } + next_block[1] = ptr; + return true; +} + void gc_dump_info(void) { gc_info_t info; gc_info(&info); diff --git a/py/gc.h b/py/gc.h index c05e006b4..757a2a6e0 100644 --- a/py/gc.h +++ b/py/gc.h @@ -57,6 +57,10 @@ bool gc_has_finaliser(const void *ptr); void *gc_make_long_lived(void *old_ptr); void *gc_realloc(void *ptr, size_t n_bytes, bool allow_move); +// Prevents a pointer from ever being freed because it establishes a permanent reference to it. Use +// very sparingly because it can leak memory. +bool gc_never_free(void *ptr); + typedef struct _gc_info_t { size_t total; size_t used; diff --git a/py/mpstate.h b/py/mpstate.h index eef8696d3..a3d7e5dcc 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -103,6 +103,8 @@ typedef struct _mp_state_mem_t { // This is a global mutex used to make the GC thread-safe. mp_thread_mutex_t gc_mutex; #endif + + void** permanent_pointers; } mp_state_mem_t; // This structure hold runtime and VM information. It includes a section diff --git a/shared-bindings/board/__init__.c b/shared-bindings/board/__init__.c index 06c2f218f..1092d40a0 100644 --- a/shared-bindings/board/__init__.c +++ b/shared-bindings/board/__init__.c @@ -37,6 +37,81 @@ //| //| Common container for board base pin names. These will vary from board to //| board so don't expect portability when using this module. +//| +//| .. warning:: The board module varies by board. The APIs documented here may or may not be +//| available on a specific board. + +//| .. method:: I2C() +//| +//| Returns the `busio.I2C` object for the board designated SDA and SCL pins. It is a singleton. +//| + +#if BOARD_I2C +mp_obj_t board_i2c(void) { + mp_obj_t singleton = common_hal_board_get_i2c(); + if (singleton != NULL) { + return singleton; + } + assert_pin_free(DEFAULT_I2C_BUS_SDA); + assert_pin_free(DEFAULT_I2C_BUS_SCL); + return common_hal_board_create_i2c(); +} +#else +mp_obj_t board_i2c(void) { + mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_I2C); + return NULL; +} +#endif +MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); + + +//| .. method:: SPI() +//| +//| Returns the `busio.SPI` object for the board designated SCK, MOSI and MISO pins. It is a +//| singleton. +//| +#if BOARD_SPI +mp_obj_t board_spi(void) { + mp_obj_t singleton = common_hal_board_get_spi(); + if (singleton != NULL) { + return singleton; + } + assert_pin_free(DEFAULT_SPI_BUS_SCK); + assert_pin_free(DEFAULT_SPI_BUS_MOSI); + assert_pin_free(DEFAULT_SPI_BUS_MISO); + return common_hal_board_create_spi(); +} +#else +mp_obj_t board_spi(void) { + mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_SPI); + return NULL; +} +#endif +MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi); + +//| .. method:: UART() +//| +//| Returns the `busio.UART` object for the board designated TX and RX pins. It is a singleton. +//| +#if BOARD_UART +mp_obj_t board_uart(void) { + mp_obj_t singleton = common_hal_board_get_uart(); + if (singleton != NULL) { + return singleton; + } + + assert_pin_free(DEFAULT_UART_BUS_RX); + assert_pin_free(DEFAULT_UART_BUS_TX); + + return common_hal_board_create_uart(); +} +#else +mp_obj_t board_uart(void) { + mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_SPI); + return NULL; +} +#endif +MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart); const mp_obj_module_t board_module = { .base = { &mp_type_module }, diff --git a/shared-bindings/board/__init__.h b/shared-bindings/board/__init__.h index 2730e5f51..a9b652ba8 100644 --- a/shared-bindings/board/__init__.h +++ b/shared-bindings/board/__init__.h @@ -33,4 +33,16 @@ extern const mp_obj_dict_t board_module_globals; +mp_obj_t common_hal_board_get_i2c(void); +mp_obj_t common_hal_board_create_i2c(void); +MP_DECLARE_CONST_FUN_OBJ_0(board_i2c_obj); + +mp_obj_t common_hal_board_get_spi(void); +mp_obj_t common_hal_board_create_spi(void); +MP_DECLARE_CONST_FUN_OBJ_0(board_spi_obj); + +mp_obj_t common_hal_board_get_uart(void); +mp_obj_t common_hal_board_create_uart(void); +MP_DECLARE_CONST_FUN_OBJ_0(board_uart_obj); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BOARD___INIT___H diff --git a/shared-bindings/displayio/FourWire.h b/shared-bindings/displayio/FourWire.h index b8b00372c..b65b1b5b7 100644 --- a/shared-bindings/displayio/FourWire.h +++ b/shared-bindings/displayio/FourWire.h @@ -31,7 +31,6 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-module/displayio/Group.h" -#include "supervisor/shared/board_busses.h" extern const mp_obj_type_t displayio_fourwire_type; diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c new file mode 100644 index 000000000..65252dd0a --- /dev/null +++ b/shared-module/board/__init__.c @@ -0,0 +1,115 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/busio/I2C.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/busio/UART.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "supervisor/shared/translate.h" +#include "mpconfigboard.h" +#include "py/runtime.h" + +#ifdef CIRCUITPY_DISPLAYIO +#include "shared-module/displayio/__init__.h" +#endif + +mp_obj_t common_hal_board_get_i2c(void) { + return MP_STATE_VM(shared_i2c_bus); +} + +mp_obj_t common_hal_board_create_i2c(void) { + busio_i2c_obj_t *self = m_new_ll_obj(busio_i2c_obj_t); + self->base.type = &busio_i2c_type; + + common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0); + MP_STATE_VM(shared_i2c_bus) = MP_OBJ_FROM_PTR(self); + return MP_STATE_VM(shared_i2c_bus); +} + +// Statically allocate the SPI object so it can live past the end of the heap and into the next VM. +// That way it can be used by built-in FourWire displays and be accessible through board.SPI(). +STATIC busio_spi_obj_t spi_obj; +STATIC mp_obj_t spi_singleton = NULL; + +// TODO(tannewt): Move this to shared-bindings/board/__init__.c and corresponding shared-module. +mp_obj_t common_hal_board_get_spi(void) { + return spi_singleton; +} + +mp_obj_t common_hal_board_create_spi(void) { + if (spi_singleton != NULL) { + return spi_singleton; + } + busio_spi_obj_t *self = &spi_obj; + self->base.type = &busio_spi_type; + + const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK); + const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI); + const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO); + common_hal_busio_spi_construct(self, clock, mosi, miso); + spi_singleton = (mp_obj_t)self; + return spi_singleton; +} + +mp_obj_t common_hal_board_get_uart(void) { + return MP_STATE_VM(shared_uart_bus); +} + +mp_obj_t common_hal_board_create_uart(void) { + busio_uart_obj_t *self = m_new_ll_obj(busio_uart_obj_t); + self->base.type = &busio_uart_type; + + const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX); + const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX); + + common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64); + MP_STATE_VM(shared_uart_bus) = MP_OBJ_FROM_PTR(self); + return MP_STATE_VM(shared_uart_bus); +} + +void reset_board_busses(void) { +#if BOARD_I2C + MP_STATE_VM(shared_i2c_bus) = NULL; +#endif +#if BOARD_SPI + bool display_using_spi = false; + #ifdef CIRCUITPY_DISPLAYIO + for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { + if (displays[i].fourwire_bus.bus == spi_singleton) { + display_using_spi = true; + break; + } + } + #endif + if (!display_using_spi) { + spi_singleton = NULL; + } +#endif +#if BOARD_UART + MP_STATE_VM(shared_uart_bus) = NULL; +#endif +} diff --git a/shared-module/board/__init__.h b/shared-module/board/__init__.h new file mode 100644 index 000000000..f7eecd417 --- /dev/null +++ b/shared-module/board/__init__.h @@ -0,0 +1,32 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H +#define MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H + +void reset_board_busses(void); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c index 043f68e26..2ca685f17 100644 --- a/shared-module/displayio/FourWire.c +++ b/shared-module/displayio/FourWire.c @@ -28,6 +28,7 @@ #include +#include "py/gc.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/time/__init__.h" @@ -40,6 +41,7 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self, self->bus = spi; common_hal_busio_spi_never_reset(self->bus); + gc_never_free(self->bus); common_hal_digitalio_digitalinout_construct(&self->command, command); common_hal_digitalio_digitalinout_switch_to_output(&self->command, true, DRIVE_MODE_PUSH_PULL); diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 49c85f277..c1f5a6810 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -5,6 +5,7 @@ #include "lib/utils/interrupt_char.h" #include "py/reload.h" #include "py/runtime.h" +#include "shared-bindings/board/__init__.h" #include "shared-bindings/displayio/Bitmap.h" #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/Group.h" @@ -190,6 +191,9 @@ void reset_displays(void) { if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) || ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { busio_spi_obj_t* original_spi = fourwire->bus; + // We don't need to move original_spi if it is the board.SPI object because it is + // statically allocated already. (Doing so would also make it impossible to reference in + // a subsequent VM run.) if (original_spi == common_hal_board_get_spi()) { continue; } diff --git a/supervisor/shared/board_busses.c b/supervisor/shared/board_busses.c deleted file mode 100644 index b2d04207d..000000000 --- a/supervisor/shared/board_busses.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-bindings/busio/I2C.h" -#include "shared-bindings/busio/SPI.h" -#include "shared-bindings/busio/UART.h" - -#include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" -#include "mpconfigboard.h" -#include "py/runtime.h" - -#ifdef CIRCUITPY_DISPLAYIO -#include "shared-module/displayio/__init__.h" -#endif - -#define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL)) -#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI)) -#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX)) - -#if BOARD_I2C -STATIC mp_obj_t i2c_singleton = NULL; - -mp_obj_t board_i2c(void) { - - if (i2c_singleton == NULL) { - busio_i2c_obj_t *self = m_new_ll_obj(busio_i2c_obj_t); - self->base.type = &busio_i2c_type; - - assert_pin_free(DEFAULT_I2C_BUS_SDA); - assert_pin_free(DEFAULT_I2C_BUS_SCL); - common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0); - i2c_singleton = (mp_obj_t)self; - } - return i2c_singleton; -} -#else -mp_obj_t board_i2c(void) { - mp_raise_NotImplementedError(translate("No default I2C bus")); - return NULL; -} -#endif -MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); - -#if BOARD_SPI -// Statically allocate the SPI object so it can live past the end of the heap and into the next VM. -// That way it can be used by built-in FourWire displays and be accessible through board.SPI(). -STATIC busio_spi_obj_t spi_obj; -STATIC mp_obj_t spi_singleton = NULL; - -// TODO(tannewt): Move this to shared-bindings/board/__init__.c and corresponding shared-module. -mp_obj_t common_hal_board_get_spi(void) { - return spi_singleton; -} - -mp_obj_t common_hal_board_create_spi(void) { - if (spi_singleton != NULL) { - return spi_singleton; - } - busio_spi_obj_t *self = &spi_obj; - self->base.type = &busio_spi_type; - if (!common_hal_mcu_pin_is_free(DEFAULT_SPI_BUS_SCK) || - !common_hal_mcu_pin_is_free(DEFAULT_SPI_BUS_MOSI) || - !common_hal_mcu_pin_is_free(DEFAULT_SPI_BUS_MISO)) { - return NULL; - } - const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK); - const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI); - const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO); - common_hal_busio_spi_construct(self, clock, mosi, miso); - spi_singleton = (mp_obj_t)self; - return spi_singleton; -} - -mp_obj_t board_spi(void) { - mp_obj_t singleton = common_hal_board_get_spi(); - if (singleton != NULL) { - return singleton; - } - assert_pin_free(DEFAULT_SPI_BUS_SCK); - assert_pin_free(DEFAULT_SPI_BUS_MOSI); - assert_pin_free(DEFAULT_SPI_BUS_MISO); - return common_hal_board_create_spi(); -} -#else -mp_obj_t common_hal_board_spi(void) { - mp_raise_NotImplementedError(translate("No default SPI bus")); - return NULL; -} -#endif -MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi); - -#if BOARD_UART -STATIC mp_obj_t uart_singleton = NULL; - -mp_obj_t board_uart(void) { - if (uart_singleton == NULL) { - busio_uart_obj_t *self = m_new_ll_obj(busio_uart_obj_t); - self->base.type = &busio_uart_type; - - assert_pin_free(DEFAULT_UART_BUS_RX); - assert_pin_free(DEFAULT_UART_BUS_TX); - - const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX); - const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX); - - common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64); - uart_singleton = (mp_obj_t)self; - } - return uart_singleton; -} -#else -mp_obj_t board_uart(void) { - mp_raise_NotImplementedError(translate("No default UART bus")); - return NULL; -} -#endif -MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart); - - -void reset_board_busses(void) { -#if BOARD_I2C - i2c_singleton = NULL; -#endif -#if BOARD_SPI - bool display_using_spi = false; - #ifdef CIRCUITPY_DISPLAYIO - for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - if (displays[i].fourwire_bus.bus == spi_singleton) { - display_using_spi = true; - break; - } - } - #endif - if (!display_using_spi) { - spi_singleton = NULL; - } -#endif -#if BOARD_UART - uart_singleton = NULL; -#endif -} diff --git a/supervisor/shared/board_busses.h b/supervisor/shared/board_busses.h deleted file mode 100644 index bdb3884f6..000000000 --- a/supervisor/shared/board_busses.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SUPERVISOR_SHARED_BOARD_BUSSES_H -#define MICROPY_INCLUDED_SUPERVISOR_SHARED_BOARD_BUSSES_H - -#include "py/obj.h" - -mp_obj_t common_hal_board_get_spi(void); -mp_obj_t common_hal_board_create_spi(void); -MP_DECLARE_CONST_FUN_OBJ_0(board_i2c_obj); - -mp_obj_t board_spi(void); -MP_DECLARE_CONST_FUN_OBJ_0(board_spi_obj); - -mp_obj_t board_uart(void); -MP_DECLARE_CONST_FUN_OBJ_0(board_uart_obj); - -void reset_board_busses(void); - -#endif // MICROPY_INCLUDED_SUPERVISOR_SHARED_BOARD_BUSSES_H diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index 7182bbcca..f965bc48a 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -27,7 +27,6 @@ #include "supervisor/shared/safe_mode.h" #include "mphalport.h" -// #include "py/mpconfig.h" #include "shared-bindings/digitalio/DigitalInOut.h" @@ -77,7 +76,7 @@ safe_mode_t wait_for_safe_mode_reset(void) { return NO_SAFE_MODE; } -// Inline this so it's easy to break on it from GDB. +// Don't inline this so it's easy to break on it from GDB. void __attribute__((noinline,)) reset_into_safe_mode(safe_mode_t reason) { if (current_safe_mode > BROWNOUT && reason > BROWNOUT) { while (true) { diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 6815fba57..95cffc098 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -2,7 +2,6 @@ SRC_SUPERVISOR = \ main.c \ supervisor/port.c \ supervisor/shared/autoreload.c \ - supervisor/shared/board_busses.c \ supervisor/shared/display.c \ supervisor/shared/filesystem.c \ supervisor/shared/flash.c \ -- cgit v1.2.3 From 72992070c5137ce44969555828673ba7ccd69f08 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 9 Apr 2019 11:36:10 -0700 Subject: Fix boards with no shared busses. --- py/runtime.c | 8 ++++++++ py/runtime.h | 1 + shared-bindings/board/__init__.c | 1 + shared-module/board/__init__.c | 7 +++++++ shared-module/displayio/__init__.c | 14 ++++++++------ 5 files changed, 25 insertions(+), 6 deletions(-) (limited to 'shared-bindings') diff --git a/py/runtime.c b/py/runtime.c index 060748f1b..1e0100337 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1590,6 +1590,14 @@ NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg) { mp_raise_msg(&mp_type_NotImplementedError, msg); } +NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...) { + va_list argptr; + va_start(argptr,fmt); + mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_NotImplementedError, fmt, argptr); + va_end(argptr); + nlr_raise(exception); +} + #if MICROPY_STACK_CHECK || MICROPY_ENABLE_PYSTACK NORETURN void mp_raise_recursion_depth(void) { mp_raise_RuntimeError(translate("maximum recursion depth exceeded")); diff --git a/py/runtime.h b/py/runtime.h index e52d3232e..2577c9dd5 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -162,6 +162,7 @@ NORETURN void mp_raise_OSError(int errno_); NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg); NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg); +NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_recursion_depth(void); #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG diff --git a/shared-bindings/board/__init__.c b/shared-bindings/board/__init__.c index 1092d40a0..82a0cab67 100644 --- a/shared-bindings/board/__init__.c +++ b/shared-bindings/board/__init__.c @@ -25,6 +25,7 @@ */ #include "py/obj.h" +#include "py/runtime.h" #include "shared-bindings/board/__init__.h" diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 3647e2654..ac4de2fe5 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -37,6 +37,7 @@ #include "shared-module/displayio/__init__.h" #endif +#if BOARD_I2C mp_obj_t common_hal_board_get_i2c(void) { return MP_STATE_VM(shared_i2c_bus); } @@ -49,7 +50,10 @@ mp_obj_t common_hal_board_create_i2c(void) { MP_STATE_VM(shared_i2c_bus) = MP_OBJ_FROM_PTR(self); return MP_STATE_VM(shared_i2c_bus); } +#endif + +#if BOARD_SPI // Statically allocate the SPI object so it can live past the end of the heap and into the next VM. // That way it can be used by built-in FourWire displays and be accessible through board.SPI(). STATIC busio_spi_obj_t spi_obj; @@ -73,7 +77,9 @@ mp_obj_t common_hal_board_create_spi(void) { spi_singleton = (mp_obj_t)self; return spi_singleton; } +#endif +#if BOARD_UART mp_obj_t common_hal_board_get_uart(void) { return MP_STATE_VM(shared_uart_bus); } @@ -89,6 +95,7 @@ mp_obj_t common_hal_board_create_uart(void) { MP_STATE_VM(shared_uart_bus) = MP_OBJ_FROM_PTR(self); return MP_STATE_VM(shared_uart_bus); } +#endif void reset_board_busses(void) { #if BOARD_I2C diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index c1f5a6810..156640440 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -191,12 +191,14 @@ void reset_displays(void) { if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) || ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { busio_spi_obj_t* original_spi = fourwire->bus; - // We don't need to move original_spi if it is the board.SPI object because it is - // statically allocated already. (Doing so would also make it impossible to reference in - // a subsequent VM run.) - if (original_spi == common_hal_board_get_spi()) { - continue; - } + #if BOARD_SPI + // We don't need to move original_spi if it is the board.SPI object because it is + // statically allocated already. (Doing so would also make it impossible to reference in + // a subsequent VM run.) + if (original_spi == common_hal_board_get_spi()) { + continue; + } + #endif memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); fourwire->bus = &fourwire->inline_bus; // Check for other displays that use the same spi bus and swap them too. -- cgit v1.2.3 From 5028f87b0988775d37c59ac2f65035468936bb0c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 5 Apr 2019 13:03:03 -0700 Subject: Tweak pybadge and fix display bugs * Update pybadge pins and flash for rev D * TileGrid now validates the type of the pixel_shader. * Display actually handles incoming subclass objects. * MicroPython will inspect native parents to see if special accessors are used. --- locale/ID.po | 2 +- locale/circuitpython.pot | 2 +- locale/de_DE.po | 4 +-- locale/en_US.po | 2 +- locale/en_x_pirate.po | 2 +- locale/es.po | 4 +-- locale/fil.po | 4 +-- locale/fr.po | 4 +-- locale/it_IT.po | 4 +-- locale/pl.po | 4 +-- locale/pt_BR.po | 2 +- ports/atmel-samd/boards/pybadge/board.c | 2 +- ports/atmel-samd/boards/pybadge/mpconfigboard.mk | 2 +- py/objtype.c | 36 +++++++++++++++--------- shared-bindings/displayio/Display.c | 26 ++++++++++------- shared-bindings/displayio/TileGrid.c | 9 ++++-- 16 files changed, 64 insertions(+), 45 deletions(-) (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 2e01bfe9a..949eddc4b 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -2575,7 +2575,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index e38aa7727..3416ef0f3 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -2528,7 +2528,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/locale/de_DE.po b/locale/de_DE.po index ae76bc76c..8bb5ce370 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -2584,8 +2584,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "Nicht unterstützter Bitmap-Typ" +msgid "unsupported %q type" +msgstr "Nicht unterstützter %q-Typ" #: py/objstr.c #, c-format diff --git a/locale/en_US.po b/locale/en_US.po index fb62ea2b0..79f4ab06d 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -2528,7 +2528,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 24af776c0..db068589b 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -2532,7 +2532,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/locale/es.po b/locale/es.po index 661c591d3..0592af242 100644 --- a/locale/es.po +++ b/locale/es.po @@ -2614,8 +2614,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "instrucción Xtensa '%s' con %d argumentos no soportada" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "tipo de bitmap no soportado" +msgid "unsupported %q type" +msgstr "tipo de %q no soportado" #: py/objstr.c #, c-format diff --git a/locale/fil.po b/locale/fil.po index 7873ec685..b34e7bb1b 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -2616,8 +2616,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "hindi sinusuportahan ang instruction ng Xtensa '%s' sa %d argumento" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "Hindi supportadong tipo ng bitmap" +msgid "unsupported %q type" +msgstr "Hindi supportadong tipo ng %q" #: py/objstr.c #, c-format diff --git a/locale/fr.po b/locale/fr.po index 9c723333d..df3af424e 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -2638,8 +2638,8 @@ msgstr "instruction Xtensa '%s' non supportée avec %d arguments" #: shared-bindings/displayio/TileGrid.c #, fuzzy -msgid "unsupported bitmap type" -msgstr "type de bitmap non supporté" +msgid "unsupported %q type" +msgstr "type de %q non supporté" #: py/objstr.c #, c-format diff --git a/locale/it_IT.po b/locale/it_IT.po index c14b3698b..7714530f6 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -2614,8 +2614,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "istruzione '%s' Xtensa non supportata con %d argomenti" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "tipo di bitmap non supportato" +msgid "unsupported %q type" +msgstr "tipo di %q non supportato" #: py/objstr.c #, c-format diff --git a/locale/pl.po b/locale/pl.po index 1b861fff0..888103fd3 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -2561,8 +2561,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "niewspierana instrukcja Xtensa '%s' z %d argumentami" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "niewspierany typ bitmapy" +msgid "unsupported %q type" +msgstr "niewspierany typ %q" #: py/objstr.c #, c-format diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 4685e9c82..047b654b4 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -2565,7 +2565,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index f234db8ca..ba18a2896 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -71,7 +71,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, NULL); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/pybadge/mpconfigboard.mk b/ports/atmel-samd/boards/pybadge/mpconfigboard.mk index 8ab759865..8828c17b2 100644 --- a/ports/atmel-samd/boards/pybadge/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pybadge/mpconfigboard.mk @@ -6,7 +6,7 @@ USB_MANUFACTURER = "Adafruit Industries LLC" QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICE_COUNT = 1 -EXTERNAL_FLASH_DEVICES = GD25Q64C +EXTERNAL_FLASH_DEVICES = GD25Q16C LONGINT_IMPL = MPZ # No I2S on SAMD51G diff --git a/py/objtype.c b/py/objtype.c index f205c224e..4dec478e9 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -964,6 +964,18 @@ STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) { #endif return false; } + +STATIC bool map_has_special_accessors(const mp_map_t *map) { + for (size_t i = 0; i < map->alloc; i++) { + if (MP_MAP_SLOT_IS_FILLED(map, i)) { + const mp_map_elem_t *elem = &map->table[i]; + if (check_for_special_accessors(elem->key, elem->value)) { + return true; + } + } + } + return false; +} #endif STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { @@ -1158,20 +1170,6 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) o->locals_dict = make_dict_long_lived(locals_dict, 10); - #if ENABLE_SPECIAL_ACCESSORS - // Check if the class has any special accessor methods - if (!(o->flags & TYPE_FLAG_HAS_SPECIAL_ACCESSORS)) { - for (size_t i = 0; i < o->locals_dict->map.alloc; i++) { - if (MP_MAP_SLOT_IS_FILLED(&o->locals_dict->map, i)) { - const mp_map_elem_t *elem = &o->locals_dict->map.table[i]; - if (check_for_special_accessors(elem->key, elem->value)) { - o->flags |= TYPE_FLAG_HAS_SPECIAL_ACCESSORS; - break; - } - } - } - } - #endif const mp_obj_type_t *native_base; size_t num_native_bases = instance_count_native_bases(o, &native_base); @@ -1180,6 +1178,16 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) } mp_map_t *locals_map = &o->locals_dict->map; + #if ENABLE_SPECIAL_ACCESSORS + // Check if the class has any special accessor methods + if (!(o->flags & TYPE_FLAG_HAS_SPECIAL_ACCESSORS) && + (map_has_special_accessors(locals_map) || + (num_native_bases == 1 && + map_has_special_accessors(&native_base->locals_dict->map)))) { + o->flags |= TYPE_FLAG_HAS_SPECIAL_ACCESSORS; + } + #endif + mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(MP_QSTR___new__), MP_MAP_LOOKUP); if (elem != NULL) { // __new__ slot exists; check if it is a function diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index c4f65704f..17f275bc0 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -157,13 +157,19 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a return self; } +// Helper to ensure we have the native super class instead of a subclass. +static displayio_display_obj_t* native_display(mp_obj_t display_obj) { + mp_obj_t native_display = mp_instance_cast_to_native_base(display_obj, &displayio_display_type); + return MP_OBJ_TO_PTR(native_display); +} + //| .. method:: show(group) //| //| Switches to displaying the given group of layers. When group is None, the default //| CircuitPython terminal will be shown. //| STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); displayio_group_t* group = NULL; if (group_in != mp_const_none) { mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type); @@ -183,7 +189,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show //| Queues up a display refresh that happens in the background. //| STATIC mp_obj_t displayio_display_obj_refresh_soon(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); common_hal_displayio_display_refresh_soon(self); return mp_const_none; } @@ -195,7 +201,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_refresh_soon_obj, displayio_display_ //| behind the rendered frames. In that case, this will return immediately with the wait count. //| STATIC mp_obj_t displayio_display_obj_wait_for_frame(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_wait_for_frame(self)); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_wait_for_frame_obj, displayio_display_obj_wait_for_frame); @@ -207,7 +213,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_wait_for_frame_obj, displayio_displa //| effect. To control the brightness, auto_brightness must be false. //| STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); mp_float_t brightness = common_hal_displayio_display_get_brightness(self); if (brightness < 0) { mp_raise_RuntimeError(translate("Brightness not adjustable")); @@ -217,7 +223,7 @@ STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_brightness_obj, displayio_display_obj_get_brightness); STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); bool ok = common_hal_displayio_display_set_brightness(self, mp_obj_get_float(brightness)); if (!ok) { mp_raise_RuntimeError(translate("Brightness not adjustable")); @@ -238,13 +244,13 @@ const mp_obj_property_t displayio_display_brightness_obj = { //| True when the display brightness is auto adjusted. //| STATIC mp_obj_t displayio_display_obj_get_auto_brightness(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return mp_obj_new_bool(common_hal_displayio_display_get_auto_brightness(self)); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_auto_brightness_obj, displayio_display_obj_get_auto_brightness); STATIC mp_obj_t displayio_display_obj_set_auto_brightness(mp_obj_t self_in, mp_obj_t auto_brightness) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); common_hal_displayio_display_set_auto_brightness(self, mp_obj_is_true(auto_brightness)); @@ -265,7 +271,7 @@ const mp_obj_property_t displayio_display_auto_brightness_obj = { //| //| STATIC mp_obj_t displayio_display_obj_get_width(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_width(self)); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_width_obj, displayio_display_obj_get_width); @@ -283,7 +289,7 @@ const mp_obj_property_t displayio_display_width_obj = { //| //| STATIC mp_obj_t displayio_display_obj_get_height(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_height(self)); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_height_obj, displayio_display_obj_get_height); @@ -301,7 +307,7 @@ const mp_obj_property_t displayio_display_height_obj = { //| //| STATIC mp_obj_t displayio_display_obj_get_bus(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return self->bus; } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_bus_obj, displayio_display_obj_get_bus); diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 7c2c0d4cc..2b41eb8fd 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -103,7 +103,12 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_ bitmap_width = bmp->width; bitmap_height = bmp->height; } else { - mp_raise_TypeError(translate("unsupported bitmap type")); + mp_raise_TypeError_varg(translate("unsupported %q type"), MP_QSTR_bitmap); + } + mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj; + if (!MP_OBJ_IS_TYPE(pixel_shader, &displayio_colorconverter_type) && + !MP_OBJ_IS_TYPE(pixel_shader, &displayio_palette_type)) { + mp_raise_TypeError_varg(translate("unsupported %q type"), MP_QSTR_pixel_shader); } uint16_t tile_width = args[ARG_tile_width].u_int; if (tile_width == 0) { @@ -126,7 +131,7 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_ displayio_tilegrid_t *self = m_new_obj(displayio_tilegrid_t); self->base.type = &displayio_tilegrid_type; common_hal_displayio_tilegrid_construct(self, native, bitmap_width / tile_width, - args[ARG_pixel_shader].u_obj, args[ARG_width].u_int, args[ARG_height].u_int, + pixel_shader, args[ARG_width].u_int, args[ARG_height].u_int, tile_width, tile_height, x, y, args[ARG_default_tile].u_int); return MP_OBJ_FROM_PTR(self); } -- cgit v1.2.3 From c0c809ad4b26490c586abf5e995699cc335e09b3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 9 Apr 2019 22:52:53 -0400 Subject: Fix version skew for bast_pro_mini build --- ports/atmel-samd/boards/bast_pro_mini_m0/pins.c | 2 -- shared-bindings/busio/UART.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/bast_pro_mini_m0/pins.c b/ports/atmel-samd/boards/bast_pro_mini_m0/pins.c index 9681fff50..3ed940e36 100644 --- a/ports/atmel-samd/boards/bast_pro_mini_m0/pins.c +++ b/ports/atmel-samd/boards/bast_pro_mini_m0/pins.c @@ -1,7 +1,5 @@ #include "shared-bindings/board/__init__.h" -#include "supervisor/shared/board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA04) }, diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index b40f3fa03..94ad1bd3e 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -57,7 +57,7 @@ //| :param int bits: the number of bits per byte, 7, 8 or 9. //| :param Parity parity: the parity used for error checking. //| :param int stop: the number of stop bits, 1 or 2. -//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters. Raises ``ValueError`` if timeout >100 seconds. +//| :param float timeout: the timeout in seconds to wait for the first character and between subsequent characters. Raises ``ValueError`` if timeout >100 seconds. //| :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.) //| //| *New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds. -- cgit v1.2.3 From c3136f4f32df28cc29596fc9ba76dcc0bfd533f0 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sat, 6 Apr 2019 14:02:18 +0200 Subject: Enable displayio for uGame10 board Also, make the _stage library work with the fourwire bus, to re-use the display. --- frozen/circuitpython-stage | 2 +- ports/atmel-samd/boards/ugame10/board.c | 73 ++++++++++++++++++++++++ ports/atmel-samd/boards/ugame10/mpconfigboard.h | 9 ++- ports/atmel-samd/boards/ugame10/mpconfigboard.mk | 7 ++- ports/atmel-samd/boards/ugame10/pins.c | 5 +- shared-bindings/_stage/__init__.c | 11 +++- 6 files changed, 95 insertions(+), 12 deletions(-) (limited to 'shared-bindings') diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index d8a9d8c1d..347b02095 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit d8a9d8c1d73041e4cc5669c5441f531ecba517fc +Subproject commit 347b02095449075d3e9bb1b7bac6d3a8a2151df2 diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index d7e856d61..cd67dabe3 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -26,7 +26,80 @@ #include "boards/board.h" +#include "shared-bindings/board/__init__.h" +#include "shared-bindings/displayio/FourWire.h" +#include "shared-module/displayio/__init__.h" +#include "shared-module/displayio/mipi_constants.h" +#include "shared-bindings/busio/SPI.h" + +#include "tick.h" + +displayio_fourwire_obj_t board_display_obj; + +#define DELAY 0x80 + +uint8_t display_init_sequence[] = { + 0x01, 0 | DELAY, 150, // SWRESET + 0x11, 0 | DELAY, 255, // SLPOUT + 0xb1, 3, 0x01, 0x2C, 0x2D, // _FRMCTR1 + 0xb2, 3, 0x01, 0x2C, 0x2D, // + 0xb3, 6, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, + 0xb4, 1, 0x07, // _INVCTR line inversion + 0xc0, 3, 0xa2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA + 0xc1, 1, 0xc5, // _PWCTR2 VGH=14.7V, VGL=-7.35V + 0xc2, 2, 0x0a, 0x00, // _PWCTR3 Opamp current small, Boost frequency + 0xc3, 2, 0x8a, 0x2a, + 0xc4, 2, 0x8a, 0xee, + 0xc5, 1, 0x0e, // _VMCTR1 VCOMH = 4V, VOML = -1.1V + 0x2a, 0, // _INVOFF + 0x36, 1, 0xa8, // _MADCTL bottom to top refresh + // 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie, + // fix on VTL + 0x3a, 1, 0x05, // COLMOD - 16bit color + 0xe0, 16, 0x02, 0x1c, 0x07, 0x12, // _GMCTRP1 Gamma + 0x37, 0x32, 0x29, 0x2d, + 0x29, 0x25, 0x2B, 0x39, + 0x00, 0x01, 0x03, 0x10, + 0xe1, 16, 0x03, 0x1d, 0x07, 0x06, // _GMCTRN1 + 0x2E, 0x2C, 0x29, 0x2D, + 0x2E, 0x2E, 0x37, 0x3F, + 0x00, 0x00, 0x02, 0x10, + 0x2a, 3, 0x02, 0x00, 0x81, // _CASET XSTART = 2, XEND = 129 + 0x2b, 3, 0x02, 0x00, 0x81, // _RASET XSTART = 2, XEND = 129 + 0x13, 0 | DELAY, 10, // _NORON + 0x29, 0 | DELAY, 100, // _DISPON +}; + void board_init(void) { + displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; + bus->base.type = &displayio_fourwire_type; + busio_spi_obj_t *spi = common_hal_board_create_spi(); + common_hal_busio_spi_configure(spi, 24000000, 0, 0, 8); + common_hal_displayio_fourwire_construct(bus, + spi, + &pin_PA09, // Command or data + &pin_PA08, // Chip select + NULL); // Reset + + displayio_display_obj_t* display = &displays[0].display; + display->base.type = &displayio_display_type; + common_hal_displayio_display_construct(display, + bus, + 128, // Width + 128, // Height + 3, // column start + 2, // row start + 0, // rotation + 16, // Color depth + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command + MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command + 0x37, // set vertical scroll command + display_init_sequence, + sizeof(display_init_sequence), + NULL, + false, // single_byte_bounds + false); // data as commands } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.h b/ports/atmel-samd/boards/ugame10/mpconfigboard.h index caa05bc1a..452633649 100644 --- a/ports/atmel-samd/boards/ugame10/mpconfigboard.h +++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.h @@ -7,7 +7,7 @@ #define SPI_FLASH_CS_PIN &pin_PA18 // These are pins not to reset. -#define MICROPY_PORT_A (0) +#define MICROPY_PORT_A (PORT_PA06 | PORT_PA07 | PORT_PA08 | PORT_PA09) #define MICROPY_PORT_B (0) #define MICROPY_PORT_C (0) @@ -19,10 +19,9 @@ #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) -#define EXTRA_BUILTIN_MODULES \ - { MP_OBJ_NEW_QSTR(MP_QSTR_audioio), (mp_obj_t)&audioio_module }, \ - { MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }, \ - { MP_OBJ_NEW_QSTR(MP_QSTR__stage), (mp_obj_t)&stage_module } +#define DEFAULT_SPI_BUS_SCK (&pin_PA07) +#define DEFAULT_SPI_BUS_MISO (&pin_PA11) +#define DEFAULT_SPI_BUS_MOSI (&pin_PA06) #define IGNORE_PIN_PB00 1 #define IGNORE_PIN_PB01 1 diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.mk b/ports/atmel-samd/boards/ugame10/mpconfigboard.mk index 0a727c8b1..4a0330d57 100644 --- a/ports/atmel-samd/boards/ugame10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.mk @@ -17,13 +17,16 @@ CIRCUITPY_MATH = 1 CIRCUITPY_AUDIOIO = 1 CIRCUITPY_ANALOGIO = 1 CIRCUITPY_GAMEPAD = 1 +CIRCUITPY_DISPLAYIO = 1 + CIRCUITPY_TOUCHIO = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 CIRCUITPY_USB_MIDI = 0 CIRCUITPY_USB_HID = 0 +CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_SMALL_BUILD = 1 +CIRCUITPY_AUDIOBUSIO = 0 +CIRCUITPY_PIXELBUF = 0 FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage diff --git a/ports/atmel-samd/boards/ugame10/pins.c b/ports/atmel-samd/boards/ugame10/pins.c index 904ac224b..4a03f8bb5 100644 --- a/ports/atmel-samd/boards/ugame10/pins.c +++ b/ports/atmel-samd/boards/ugame10/pins.c @@ -1,4 +1,5 @@ #include "shared-bindings/board/__init__.h" +#include "shared-module/displayio/__init__.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA00) }, @@ -23,8 +24,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_B), MP_ROM_PTR(&pin_PA14) }, { MP_ROM_QSTR(MP_QSTR_C), MP_ROM_PTR(&pin_PA15) }, { MP_ROM_QSTR(MP_QSTR_D), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)} }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 24a359664..95cbda846 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -28,6 +28,7 @@ #include "py/mperrno.h" #include "py/runtime.h" #include "shared-bindings/busio/SPI.h" +#include "shared-bindings/displayio/FourWire.h" #include "shared-module/_stage/__init__.h" #include "Layer.h" #include "Text.h" @@ -85,12 +86,18 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { uint16_t *buffer = bufinfo.buf; size_t buffer_size = bufinfo.len / 2; // 16-bit indexing - busio_spi_obj_t *spi = MP_OBJ_TO_PTR(args[6]); + displayio_fourwire_obj_t *bus = MP_OBJ_TO_PTR(args[6]); + while (!common_hal_displayio_fourwire_begin_transaction(bus)) { +#ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP ; +#endif + } if (!render_stage(x0, y0, x1, y1, layers, layers_size, - buffer, buffer_size, spi)) { + buffer, buffer_size, bus->bus)) { mp_raise_OSError(MP_EIO); } + common_hal_displayio_fourwire_end_transaction(bus); return mp_const_none; } -- cgit v1.2.3 From d39e7e7dd51aa55e92cfda3e05ea80ae1abe409d Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 12 Apr 2019 11:56:23 +0200 Subject: Use displayio.Display directly --- frozen/circuitpython-stage | 2 +- shared-bindings/_stage/__init__.c | 24 +++++++++++------------- shared-module/_stage/__init__.c | 14 ++++---------- shared-module/_stage/__init__.h | 6 +++--- supervisor/supervisor.mk | 2 +- 5 files changed, 20 insertions(+), 28 deletions(-) (limited to 'shared-bindings') diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index a7b3295ff..069fad835 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit a7b3295ff573ce03cd7111a6cf7bf9cfe1e4f657 +Subproject commit 069fad8357623f5ea2ff3c865a5b8ed54608afd7 diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 95cbda846..466098061 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -28,7 +28,7 @@ #include "py/mperrno.h" #include "py/runtime.h" #include "shared-bindings/busio/SPI.h" -#include "shared-bindings/displayio/FourWire.h" +#include "shared-bindings/displayio/Display.h" #include "shared-module/_stage/__init__.h" #include "Layer.h" #include "Text.h" @@ -50,7 +50,7 @@ //| Layer //| Text //| -//| .. function:: render(x0, y0, x1, y1, layers, buffer, spi) +//| .. function:: render(x0, y0, x1, y1, layers, buffer, display) //| //| Render and send to the display a fragment of the screen. //| @@ -60,11 +60,8 @@ //| :param int y1: Bottom edge of the fragment. //| :param list layers: A list of the :py:class:`~_stage.Layer` objects. //| :param bytearray buffer: A buffer to use for rendering. -//| :param ~busio.SPI spi: The SPI bus to use. +//| :param ~displayio.Display display: The display to use. //| -//| Note that this function only sends the raw pixel data. Setting up -//| the display for receiving it and handling the chip-select and -//| data-command pins has to be done outside of it. //| There are also no sanity checks, outside of the basic overflow //| checking. The caller is responsible for making the passed parameters //| valid. @@ -86,18 +83,19 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { uint16_t *buffer = bufinfo.buf; size_t buffer_size = bufinfo.len / 2; // 16-bit indexing - displayio_fourwire_obj_t *bus = MP_OBJ_TO_PTR(args[6]); + if (!MP_OBJ_IS_TYPE(args[6], &displayio_display_type)) { + mp_raise_TypeError(translate("expected displayio.Display")); + } + displayio_display_obj_t *display = MP_OBJ_TO_PTR(args[6]); - while (!common_hal_displayio_fourwire_begin_transaction(bus)) { + while (!displayio_display_begin_transaction(display)) { #ifdef MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_LOOP ; #endif } - if (!render_stage(x0, y0, x1, y1, layers, layers_size, - buffer, buffer_size, bus->bus)) { - mp_raise_OSError(MP_EIO); - } - common_hal_displayio_fourwire_end_transaction(bus); + displayio_display_set_region_to_update(display, x0, y0, x1, y1); + render_stage(x0, y0, x1, y1, layers, layers_size, buffer, buffer_size, display); + displayio_display_end_transaction(display); return mp_const_none; } diff --git a/shared-module/_stage/__init__.c b/shared-module/_stage/__init__.c index 86f5ee795..1af279e92 100644 --- a/shared-module/_stage/__init__.c +++ b/shared-module/_stage/__init__.c @@ -31,10 +31,10 @@ #include "shared-bindings/_stage/Text.h" -bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, +void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, mp_obj_t *layers, size_t layers_size, uint16_t *buffer, size_t buffer_size, - busio_spi_obj_t *spi) { + displayio_display_obj_t *display) { size_t index = 0; for (uint16_t y = y0; y < y1; ++y) { @@ -55,19 +55,13 @@ bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, index += 1; // The buffer is full, send it. if (index >= buffer_size) { - if (!common_hal_busio_spi_write(spi, - ((uint8_t*)buffer), buffer_size * 2)) { - return false; - } + display->send(display->bus, false, ((uint8_t*)buffer), buffer_size * 2); index = 0; } } } // Send the remaining data. if (index) { - if (!common_hal_busio_spi_write(spi, ((uint8_t*)buffer), index * 2)) { - return false; - } + display->send(display->bus, false, ((uint8_t*)buffer), index * 2); } - return true; } diff --git a/shared-module/_stage/__init__.h b/shared-module/_stage/__init__.h index d56a26940..d263302b4 100644 --- a/shared-module/_stage/__init__.h +++ b/shared-module/_stage/__init__.h @@ -27,16 +27,16 @@ #ifndef MICROPY_INCLUDED_SHARED_MODULE__STAGE_H #define MICROPY_INCLUDED_SHARED_MODULE__STAGE_H -#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/displayio/Display.h" #include #include #include "py/obj.h" #define TRANSPARENT (0x1ff8) -bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, +void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, mp_obj_t *layers, size_t layers_size, uint16_t *buffer, size_t buffer_size, - busio_spi_obj_t *spi); + displayio_display_obj_t *display); #endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 95cffc098..f94f19353 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -101,7 +101,7 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile --output_c_file $(BUILD)/autogen_usb_descriptor.c\ --output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h -CIRCUITPY_DISPLAY_FONT = "../../tools/Tecate-bitmap-fonts/bitmap/terminus-font-4.39/ter-u12n.bdf" +CIRCUITPY_DISPLAY_FONT ?= "../../tools/Tecate-bitmap-fonts/bitmap/terminus-font-4.39/ter-u12n.bdf" $(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD) $(STEPECHO) "GEN $@" -- cgit v1.2.3 From 6ff4e0ecb03f297d327c9c6fd3a52a7ad3a05c47 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 10 Apr 2019 20:42:21 +0200 Subject: Add GamePadShift for handling shift-register-based buttons --- shared-bindings/gamepad/GamePad.c | 68 ++++++++++++++++++++++++++++++++++---- shared-bindings/gamepad/GamePad.h | 1 + shared-bindings/gamepad/__init__.c | 1 + shared-module/gamepad/GamePad.c | 21 +++++++++++- shared-module/gamepad/GamePad.h | 9 ++++- shared-module/gamepad/__init__.c | 36 +++++++++++++++----- 6 files changed, 119 insertions(+), 17 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index 4458c972f..b211e229d 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -35,6 +35,15 @@ #include "supervisor/shared/translate.h" #include "GamePad.h" +digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) { + if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) { + mp_raise_TypeError(translate("expected a DigitalInOut")); + } + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj); + raise_error_if_deinited( + common_hal_digitalio_digitalinout_deinited(pin)); + return pin; +} //| .. currentmodule:: gamepad //| @@ -100,19 +109,52 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_TypeError(translate("too many arguments")); } for (size_t i = 0; i < n_args; ++i) { - if (!MP_OBJ_IS_TYPE(args[i], &digitalio_digitalinout_type)) { - mp_raise_TypeError(translate("expected a DigitalInOut")); - } - digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(args[i]); - raise_error_if_deinited( - common_hal_digitalio_digitalinout_deinited(pin)); + validate_pin(args[i]); + } + if (!MP_STATE_VM(gamepad_singleton)) { + gamepad_obj_t* gamepad_singleton = m_new_obj(gamepad_obj_t); + gamepad_singleton->base.type = &gamepad_type; + MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton); } + gamepad_init_pins(n_args, args); + return MP_OBJ_FROM_PTR(MP_STATE_VM(gamepad_singleton)); +} + + +//| .. class:: GamePadShift(data, clock, latch) +//| +//| Initializes button scanning routines. +//| +//| The ``data``, ``clock`` and ``latch`` parameters are ``DigitalInOut`` +//| objects connected to the shift register controlling the buttons. +//| +//| They button presses are accumulated, until the ``get_pressed`` method +//| is called, at which point the button state is cleared, and the new +//| button presses start to be recorded. +//| +STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, + const mp_obj_t *pos_args, mp_map_t *kw_args) { + + enum { ARG_data, ARG_clock, ARG_latch }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ}, + { MP_QSTR_latch, MP_ARG_REQUIRED | MP_ARG_OBJ}, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), + allowed_args, args); + + digitalio_digitalinout_obj_t *data_pin = validate_pin(args[ARG_data].u_obj); + digitalio_digitalinout_obj_t *clock_pin = validate_pin(args[ARG_clock].u_obj); + digitalio_digitalinout_obj_t *latch_pin = validate_pin(args[ARG_latch].u_obj); + if (!MP_STATE_VM(gamepad_singleton)) { gamepad_obj_t* gamepad_singleton = m_new_obj(gamepad_obj_t); gamepad_singleton->base.type = &gamepad_type; MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton); } - gamepad_init(n_args, args); + gamepad_init_shift(data_pin, clock_pin, latch_pin); return MP_OBJ_FROM_PTR(MP_STATE_VM(gamepad_singleton)); } @@ -158,3 +200,15 @@ const mp_obj_type_t gamepad_type = { .make_new = gamepad_make_new, .locals_dict = (mp_obj_dict_t*)&gamepad_locals_dict, }; + +STATIC const mp_rom_map_elem_t gamepadshift_locals_dict_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR_get_pressed), MP_ROM_PTR(&gamepad_get_pressed_obj)}, + { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gamepad_deinit_obj)}, +}; +STATIC MP_DEFINE_CONST_DICT(gamepadshift_locals_dict, gamepadshift_locals_dict_table); +const mp_obj_type_t gamepadshift_type = { + { &mp_type_type }, + .name = MP_QSTR_GamePadShift, + .make_new = gamepadshift_make_new, + .locals_dict = (mp_obj_dict_t*)&gamepadshift_locals_dict, +}; diff --git a/shared-bindings/gamepad/GamePad.h b/shared-bindings/gamepad/GamePad.h index 172c95ace..350331193 100644 --- a/shared-bindings/gamepad/GamePad.h +++ b/shared-bindings/gamepad/GamePad.h @@ -29,5 +29,6 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H extern const mp_obj_type_t gamepad_type; +extern const mp_obj_type_t gamepadshift_type; #endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H diff --git a/shared-bindings/gamepad/__init__.c b/shared-bindings/gamepad/__init__.c index 0c99d0d52..0775d6abf 100644 --- a/shared-bindings/gamepad/__init__.c +++ b/shared-bindings/gamepad/__init__.c @@ -44,6 +44,7 @@ STATIC const mp_rom_map_elem_t gamepad_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepad) }, { MP_OBJ_NEW_QSTR(MP_QSTR_GamePad), MP_ROM_PTR(&gamepad_type)}, + { MP_OBJ_NEW_QSTR(MP_QSTR_GamePadShift), MP_ROM_PTR(&gamepadshift_type)}, }; STATIC MP_DEFINE_CONST_DICT(gamepad_module_globals, gamepad_module_globals_table); diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c index 2c14fa02a..ed574db53 100644 --- a/shared-module/gamepad/GamePad.c +++ b/shared-module/gamepad/GamePad.c @@ -35,7 +35,7 @@ #include "shared-bindings/util.h" -void gamepad_init(size_t n_pins, const mp_obj_t* pins) { +void gamepad_init_pins(size_t n_pins, const mp_obj_t* pins) { gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); for (size_t i = 0; i < 8; ++i) { gamepad_singleton->pins[i] = NULL; @@ -57,4 +57,23 @@ void gamepad_init(size_t n_pins, const mp_obj_t* pins) { gamepad_singleton->pins[i] = pin; } gamepad_singleton->last = 0; + gamepad_singleton->kind = GAMEPAD_KIND_PINS; +} + +void gamepad_init_shift(digitalio_digitalinout_obj_t *data_pin, + digitalio_digitalinout_obj_t *clock_pin, + digitalio_digitalinout_obj_t *latch_pin) { + gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); + + common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); + gamepad_singleton->pins[0] = data_pin; + + common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, DRIVE_MODE_PUSH_PULL); + gamepad_singleton->pins[1] = clock_pin; + + common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 1, DRIVE_MODE_PUSH_PULL); + gamepad_singleton->pins[2] = latch_pin; + + gamepad_singleton->last = 0; + gamepad_singleton->kind = GAMEPAD_KIND_PINS; } diff --git a/shared-module/gamepad/GamePad.h b/shared-module/gamepad/GamePad.h index 9fd5c9626..9bc5a711c 100644 --- a/shared-module/gamepad/GamePad.h +++ b/shared-module/gamepad/GamePad.h @@ -37,8 +37,15 @@ typedef struct { volatile uint8_t last; volatile uint8_t pressed; uint8_t pulls; + uint8_t kind; } gamepad_obj_t; -void gamepad_init(size_t n_pins, const mp_obj_t* pins); +#define GAMEPAD_KIND_PINS 0 +#define GAMEPAD_KIND_SHIFT 1 + +void gamepad_init_pins(size_t n_pins, const mp_obj_t* pins); +void gamepad_init_shift(digitalio_digitalinout_obj_t *data_pin, + digitalio_digitalinout_obj_t *clock_pin, + digitalio_digitalinout_obj_t *latch_pin); #endif // MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index 8414ddfbe..c79ee30ba 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -40,17 +40,37 @@ void gamepad_tick(void) { } uint8_t gamepad_current = 0; uint8_t bit = 1; - for (int i = 0; i < 8; ++i) { - digitalio_digitalinout_obj_t* pin = gamepad_singleton->pins[i]; - if (!pin) { - break; + switch (gamepad_singleton->kind) { + case GAMEPAD_KIND_PINS: + for (int i = 0; i < 8; ++i) { + digitalio_digitalinout_obj_t* pin = gamepad_singleton->pins[i]; + if (!pin) { + break; + } + if (common_hal_digitalio_digitalinout_get_value(pin)) { + gamepad_current |= bit; + } + bit <<= 1; } - if (common_hal_digitalio_digitalinout_get_value(pin)) { - gamepad_current |= bit; + gamepad_current ^= gamepad_singleton->pulls; + break; + case GAMEPAD_KIND_SHIFT: + bit = 1; + digitalio_digitalinout_obj_t* data_pin = gamepad_singleton->pins[0]; + digitalio_digitalinout_obj_t* clock_pin = gamepad_singleton->pins[1]; + digitalio_digitalinout_obj_t* latch_pin = gamepad_singleton->pins[2]; + common_hal_digitalio_digitalinout_set_value(latch_pin, 0); + for (int i = 0; i < 8; ++i) { + common_hal_digitalio_digitalinout_set_value(clock_pin, 1); + if (common_hal_digitalio_digitalinout_get_value(data_pin)) { + gamepad_current |= bit; + } + bit <<= 1; + common_hal_digitalio_digitalinout_set_value(clock_pin, 0); } - bit <<= 1; + common_hal_digitalio_digitalinout_set_value(latch_pin, 1); + break; } - gamepad_current ^= gamepad_singleton->pulls; gamepad_singleton->pressed |= gamepad_singleton->last & gamepad_current; gamepad_singleton->last = gamepad_current; } -- cgit v1.2.3 From a7925930fa95143c5336fe6d661691605eae41dd Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 10 Apr 2019 22:44:50 +0200 Subject: Read one bit per system clock tick in GamePadShift --- shared-bindings/gamepad/GamePad.c | 2 +- shared-module/gamepad/GamePad.c | 2 - shared-module/gamepad/GamePad.h | 1 - shared-module/gamepad/__init__.c | 81 +++++++++++++++++++++++++-------------- 4 files changed, 53 insertions(+), 33 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index b211e229d..c475185e7 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -151,7 +151,7 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, if (!MP_STATE_VM(gamepad_singleton)) { gamepad_obj_t* gamepad_singleton = m_new_obj(gamepad_obj_t); - gamepad_singleton->base.type = &gamepad_type; + gamepad_singleton->base.type = &gamepadshift_type; MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton); } gamepad_init_shift(data_pin, clock_pin, latch_pin); diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c index ed574db53..4fea7fe4b 100644 --- a/shared-module/gamepad/GamePad.c +++ b/shared-module/gamepad/GamePad.c @@ -56,7 +56,6 @@ void gamepad_init_pins(size_t n_pins, const mp_obj_t* pins) { } gamepad_singleton->pins[i] = pin; } - gamepad_singleton->last = 0; gamepad_singleton->kind = GAMEPAD_KIND_PINS; } @@ -74,6 +73,5 @@ void gamepad_init_shift(digitalio_digitalinout_obj_t *data_pin, common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 1, DRIVE_MODE_PUSH_PULL); gamepad_singleton->pins[2] = latch_pin; - gamepad_singleton->last = 0; gamepad_singleton->kind = GAMEPAD_KIND_PINS; } diff --git a/shared-module/gamepad/GamePad.h b/shared-module/gamepad/GamePad.h index 9bc5a711c..8ba597a37 100644 --- a/shared-module/gamepad/GamePad.h +++ b/shared-module/gamepad/GamePad.h @@ -34,7 +34,6 @@ typedef struct { mp_obj_base_t base; digitalio_digitalinout_obj_t* pins[8]; - volatile uint8_t last; volatile uint8_t pressed; uint8_t pulls; uint8_t kind; diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index c79ee30ba..6f9b80bec 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -33,46 +33,69 @@ #include "shared-bindings/digitalio/DigitalInOut.h" +void pressed_pins(gamepad_obj_t *self) { + static uint8_t last = 0; + uint8_t current = 0; + uint8_t bit = 1; + for (int i = 0; i < 8; ++i) { + digitalio_digitalinout_obj_t* pin = self->pins[i]; + if (!pin) { + break; + } + if (common_hal_digitalio_digitalinout_get_value(pin)) { + current |= bit; + } + bit <<= 1; + } + current ^= self->pulls; + self->pressed |= last & current; + last = current; +} + + +void pressed_shift(gamepad_obj_t *self) { + static volatile uint8_t i = 8; + static volatile uint8_t clock = 0; + digitalio_digitalinout_obj_t* data_pin = self->pins[0]; + digitalio_digitalinout_obj_t* clock_pin = self->pins[1]; + digitalio_digitalinout_obj_t* latch_pin = self->pins[2]; + + if (clock == 0) { + common_hal_digitalio_digitalinout_set_value(clock_pin, 1); + clock = 1; + return; + } + + if (i == 8) { + common_hal_digitalio_digitalinout_set_value(latch_pin, 0); + i = 9; + } else if (i == 9) { + common_hal_digitalio_digitalinout_set_value(latch_pin, 1); + i = 0; + } else { + if (common_hal_digitalio_digitalinout_get_value(data_pin)) { + self->pressed |= (1 << i); + } + i += 1; + } + common_hal_digitalio_digitalinout_set_value(clock_pin, 0); + clock = 0; +} + + void gamepad_tick(void) { gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); if (!gamepad_singleton) { return; } - uint8_t gamepad_current = 0; - uint8_t bit = 1; switch (gamepad_singleton->kind) { case GAMEPAD_KIND_PINS: - for (int i = 0; i < 8; ++i) { - digitalio_digitalinout_obj_t* pin = gamepad_singleton->pins[i]; - if (!pin) { - break; - } - if (common_hal_digitalio_digitalinout_get_value(pin)) { - gamepad_current |= bit; - } - bit <<= 1; - } - gamepad_current ^= gamepad_singleton->pulls; + pressed_pins(gamepad_singleton); break; case GAMEPAD_KIND_SHIFT: - bit = 1; - digitalio_digitalinout_obj_t* data_pin = gamepad_singleton->pins[0]; - digitalio_digitalinout_obj_t* clock_pin = gamepad_singleton->pins[1]; - digitalio_digitalinout_obj_t* latch_pin = gamepad_singleton->pins[2]; - common_hal_digitalio_digitalinout_set_value(latch_pin, 0); - for (int i = 0; i < 8; ++i) { - common_hal_digitalio_digitalinout_set_value(clock_pin, 1); - if (common_hal_digitalio_digitalinout_get_value(data_pin)) { - gamepad_current |= bit; - } - bit <<= 1; - common_hal_digitalio_digitalinout_set_value(clock_pin, 0); - } - common_hal_digitalio_digitalinout_set_value(latch_pin, 1); + pressed_shift(gamepad_singleton); break; } - gamepad_singleton->pressed |= gamepad_singleton->last & gamepad_current; - gamepad_singleton->last = gamepad_current; } void gamepad_reset(void) { -- cgit v1.2.3 From 7e89beeb3101ddb7fc1d3f35d492943ffb287ec2 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Thu, 11 Apr 2019 11:22:46 +0200 Subject: Optimize the size of code for gamepad --- locale/ID.po | 74 +++++++++++++++++-------------------- locale/circuitpython.pot | 74 +++++++++++++++++-------------------- locale/de_DE.po | 77 +++++++++++++++++++-------------------- locale/en_US.po | 74 +++++++++++++++++-------------------- locale/en_x_pirate.po | 74 +++++++++++++++++-------------------- locale/es.po | 77 +++++++++++++++++++-------------------- locale/fil.po | 77 +++++++++++++++++++-------------------- locale/fr.po | 77 +++++++++++++++++++-------------------- locale/it_IT.po | 77 +++++++++++++++++++-------------------- locale/pl.po | 77 +++++++++++++++++++-------------------- locale/pt_BR.po | 77 +++++++++++++++++++-------------------- shared-bindings/gamepad/GamePad.c | 4 +- shared-module/gamepad/__init__.c | 68 ++++++++++++++-------------------- 13 files changed, 424 insertions(+), 483 deletions(-) (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 949eddc4b..d8d82709b 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -52,8 +52,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "buffers harus mempunyai panjang yang sama" @@ -62,7 +62,7 @@ msgstr "buffers harus mempunyai panjang yang sama" msgid "%q should be an int" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "%q() mengambil posisi argumen %d tapi %d yang diberikan" @@ -70,12 +70,12 @@ msgstr "%q() mengambil posisi argumen %d tapi %d yang diberikan" msgid "'%q' argument required" msgstr "'%q' argumen dibutuhkan" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' mengharapkan sebuah register" @@ -95,7 +95,7 @@ msgstr "'%s' mengharapkan sebuah FPU register" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' mengharapkan sebuah alamat dengan bentuk [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' mengharapkan integer" @@ -245,7 +245,7 @@ msgstr "Semua perangkat I2C sedang digunakan" msgid "All event channels in use" msgstr "Semua channel event sedang digunakan" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Semua channel event yang disinkronisasi sedang digunakan" @@ -253,9 +253,9 @@ msgstr "Semua channel event yang disinkronisasi sedang digunakan" msgid "All timers for this pin are in use" msgstr "Semua timer untuk pin ini sedang digunakan" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -522,9 +522,8 @@ msgstr "Channel EXTINT sedang digunakan" msgid "Error in regex" msgstr "Error pada regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "" @@ -532,8 +531,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "" @@ -720,8 +719,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -827,11 +826,10 @@ msgstr "Pin untuk channel kiri tidak valid" msgid "Invalid pin for right channel" msgstr "Pin untuk channel kanan tidak valid" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Pin-pin tidak valid" @@ -1093,8 +1091,8 @@ msgstr "Serializer sedang digunakan" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1347,7 +1345,7 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "argumen num/types tidak cocok" @@ -1660,7 +1658,7 @@ msgstr "" msgid "complex division by zero" msgstr "" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "" @@ -1701,7 +1699,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "" @@ -1710,7 +1708,7 @@ msgstr "" msgid "empty" msgstr "" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "heap kosong" @@ -1775,7 +1773,7 @@ msgstr "argumen keyword ekstra telah diberikan" msgid "extra positional arguments given" msgstr "argumen posisi ekstra telah diberikan" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1816,7 +1814,7 @@ msgstr "fungsi tidak dapat mengambil argumen keyword" msgid "function expected at most %d arguments, got %d" msgstr "fungsi diharapkan setidaknya %d argumen, hanya mendapatkan %d" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "fungsi mendapatkan nilai ganda untuk argumen '%q'" @@ -1838,7 +1836,7 @@ msgstr "fungsi kehilangan argumen keyword '%q' yang dibutuhkan" msgid "function missing required positional argument #%d" msgstr "fungsi kehilangan argumen posisi #%d yang dibutuhkan" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "fungsi mengambil posisi argumen %d tapi %d yang diberikan" @@ -1985,7 +1983,7 @@ msgstr "argumen keyword belum diimplementasi - gunakan args normal" msgid "keywords must be strings" msgstr "keyword harus berupa string" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2092,11 +2090,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2198,12 +2196,12 @@ msgstr "" msgid "odd-length string" msgstr "panjang data string memiliki keganjilan (odd-length)" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c #, fuzzy msgid "offset out of bounds" msgstr "modul tidak ditemukan" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2221,7 +2219,7 @@ msgstr "" msgid "overflow converting long int to machine word" msgstr "" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "" @@ -2353,7 +2351,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" @@ -2455,10 +2453,6 @@ msgstr "bits harus memilki nilai 8" msgid "timestamp out of range for platform time_t" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "" @@ -2516,7 +2510,7 @@ msgstr "" msgid "unexpected keyword argument" msgstr "argumen keyword tidak diharapkan" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "keyword argumen '%q' tidak diharapkan" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 3416ef0f3..729dea742 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -52,8 +52,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "" @@ -61,7 +61,7 @@ msgstr "" msgid "%q should be an int" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "" @@ -69,12 +69,12 @@ msgstr "" msgid "'%q' argument required" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "" @@ -94,7 +94,7 @@ msgstr "" msgid "'%s' expects an address of the form [a, b]" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "" @@ -243,7 +243,7 @@ msgstr "" msgid "All event channels in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -251,9 +251,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -510,9 +510,8 @@ msgstr "" msgid "Error in regex" msgstr "" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "" @@ -520,8 +519,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "" @@ -695,8 +694,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -802,11 +801,10 @@ msgstr "" msgid "Invalid pin for right channel" msgstr "" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "" @@ -1063,8 +1061,8 @@ msgstr "" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1304,7 +1302,7 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "" @@ -1616,7 +1614,7 @@ msgstr "" msgid "complex division by zero" msgstr "" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "" @@ -1657,7 +1655,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "" @@ -1666,7 +1664,7 @@ msgstr "" msgid "empty" msgstr "" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "" @@ -1731,7 +1729,7 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1772,7 +1770,7 @@ msgstr "" msgid "function expected at most %d arguments, got %d" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "" @@ -1794,7 +1792,7 @@ msgstr "" msgid "function missing required positional argument #%d" msgstr "" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "" @@ -1941,7 +1939,7 @@ msgstr "" msgid "keywords must be strings" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2047,11 +2045,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2153,11 +2151,11 @@ msgstr "" msgid "odd-length string" msgstr "" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c msgid "offset out of bounds" msgstr "" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2175,7 +2173,7 @@ msgstr "" msgid "overflow converting long int to machine word" msgstr "" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "" @@ -2307,7 +2305,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" @@ -2408,10 +2406,6 @@ msgstr "" msgid "timestamp out of range for platform time_t" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "" @@ -2469,7 +2463,7 @@ msgstr "" msgid "unexpected keyword argument" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 8bb5ce370..0130005be 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -54,8 +54,8 @@ msgstr "Der Index %q befindet sich außerhalb der Reihung" msgid "%q indices must be integers, not %s" msgstr "%q Indizes müssen ganze Zahlen sein, nicht %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "%q muss >= 1 sein" @@ -63,7 +63,7 @@ msgstr "%q muss >= 1 sein" msgid "%q should be an int" msgstr "%q sollte ein int sein" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "%q() nimmt %d Argumente ohne Keyword an, aber es wurden %d angegeben" @@ -71,12 +71,12 @@ msgstr "%q() nimmt %d Argumente ohne Keyword an, aber es wurden %d angegeben" msgid "'%q' argument required" msgstr "'%q' Argument erforderlich" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' erwartet ein Label" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' erwartet ein Register" @@ -96,7 +96,7 @@ msgstr "'%s' erwartet ein FPU-Register" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' erwartet eine Adresse in der Form [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' erwartet ein Integer" @@ -245,7 +245,7 @@ msgstr "Alle UART-Peripheriegeräte sind in Benutzung" msgid "All event channels in use" msgstr "Alle event Kanäle werden benutzt" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Alle sync event Kanäle werden benutzt" @@ -253,9 +253,9 @@ msgstr "Alle sync event Kanäle werden benutzt" msgid "All timers for this pin are in use" msgstr "Alle timer für diesen Pin werden bereits benutzt" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -514,9 +514,8 @@ msgstr "EXTINT Kanal ist schon in Benutzung" msgid "Error in regex" msgstr "Fehler in regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "Erwartet ein(e) %q" @@ -524,8 +523,8 @@ msgstr "Erwartet ein(e) %q" msgid "Expected a Characteristic" msgstr "Characteristic wird erwartet" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "Eine UUID wird erwartet" @@ -699,8 +698,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" @@ -808,11 +807,10 @@ msgstr "Ungültiger Pin für linken Kanal" msgid "Invalid pin for right channel" msgstr "Ungültiger Pin für rechten Kanal" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Ungültige Pins" @@ -1080,8 +1078,8 @@ msgstr "Serializer wird benutzt" msgid "Slice and value different lengths." msgstr "Slice und Wert (value) haben unterschiedliche Längen." -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Slices werden nicht unterstützt" @@ -1344,7 +1342,7 @@ msgstr "arg ist eine leere Sequenz" msgid "argument has wrong type" msgstr "Argument hat falschen Typ" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "Anzahl/Type der Argumente passen nicht" @@ -1656,7 +1654,7 @@ msgstr "" msgid "complex division by zero" msgstr "" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "" @@ -1697,7 +1695,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "Division durch Null" @@ -1706,7 +1704,7 @@ msgstr "Division durch Null" msgid "empty" msgstr "leer" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "leerer heap" @@ -1771,7 +1769,7 @@ msgstr "Es wurden zusätzliche Keyword-Argumente angegeben" msgid "extra positional arguments given" msgstr "Es wurden zusätzliche Argumente ohne Keyword angegeben" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "Die Datei muss eine im Byte-Modus geöffnete Datei sein" @@ -1812,7 +1810,7 @@ msgstr "Funktion akzeptiert keine Keyword-Argumente" msgid "function expected at most %d arguments, got %d" msgstr "Funktion erwartet maximal %d Argumente, aber hat %d erhalten" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "Funktion hat mehrere Werte für Argument '%q'" @@ -1834,7 +1832,7 @@ msgstr "Funktion vermisst benötigtes Keyword-Argumente '%q'" msgid "function missing required positional argument #%d" msgstr "Funktion vermisst benötigtes Argumente ohne Keyword #%d" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "" @@ -1986,7 +1984,7 @@ msgstr "" msgid "keywords must be strings" msgstr "Schlüsselwörter müssen Zeichenfolgen sein" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "Label '%q' nicht definiert" @@ -2094,11 +2092,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2200,11 +2198,11 @@ msgstr "Objekt mit Pufferprotokoll (buffer protocol) erforderlich" msgid "odd-length string" msgstr "String mit ungerader Länge" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c msgid "offset out of bounds" msgstr "offset außerhalb der Grenzen" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2224,7 +2222,7 @@ msgstr "" msgid "overflow converting long int to machine word" msgstr "" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "" @@ -2358,7 +2356,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "small int Überlauf" @@ -2460,10 +2458,6 @@ msgstr "timeout muss >= 0.0 sein" msgid "timestamp out of range for platform time_t" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "zu viele Argumente" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "" @@ -2523,7 +2517,7 @@ msgstr "" msgid "unexpected keyword argument" msgstr "unerwartetes Keyword-Argument" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "unerwartetes Keyword-Argument '%q'" @@ -2794,6 +2788,9 @@ msgstr "" #~ msgid "scan failed" #~ msgstr "Scan fehlgeschlagen" +#~ msgid "too many arguments" +#~ msgstr "zu viele Argumente" + #~ msgid "unknown status param" #~ msgstr "Unbekannter Statusparameter" diff --git a/locale/en_US.po b/locale/en_US.po index 79f4ab06d..99097a027 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -52,8 +52,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "" @@ -61,7 +61,7 @@ msgstr "" msgid "%q should be an int" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "" @@ -69,12 +69,12 @@ msgstr "" msgid "'%q' argument required" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "" @@ -94,7 +94,7 @@ msgstr "" msgid "'%s' expects an address of the form [a, b]" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "" @@ -243,7 +243,7 @@ msgstr "" msgid "All event channels in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -251,9 +251,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -510,9 +510,8 @@ msgstr "" msgid "Error in regex" msgstr "" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "" @@ -520,8 +519,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "" @@ -695,8 +694,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -802,11 +801,10 @@ msgstr "" msgid "Invalid pin for right channel" msgstr "" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "" @@ -1063,8 +1061,8 @@ msgstr "" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1304,7 +1302,7 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "" @@ -1616,7 +1614,7 @@ msgstr "" msgid "complex division by zero" msgstr "" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "" @@ -1657,7 +1655,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "" @@ -1666,7 +1664,7 @@ msgstr "" msgid "empty" msgstr "" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "" @@ -1731,7 +1729,7 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1772,7 +1770,7 @@ msgstr "" msgid "function expected at most %d arguments, got %d" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "" @@ -1794,7 +1792,7 @@ msgstr "" msgid "function missing required positional argument #%d" msgstr "" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "" @@ -1941,7 +1939,7 @@ msgstr "" msgid "keywords must be strings" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2047,11 +2045,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2153,11 +2151,11 @@ msgstr "" msgid "odd-length string" msgstr "" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c msgid "offset out of bounds" msgstr "" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2175,7 +2173,7 @@ msgstr "" msgid "overflow converting long int to machine word" msgstr "" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "" @@ -2307,7 +2305,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" @@ -2408,10 +2406,6 @@ msgstr "" msgid "timestamp out of range for platform time_t" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "" @@ -2469,7 +2463,7 @@ msgstr "" msgid "unexpected keyword argument" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index db068589b..1f81d3e3c 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -54,8 +54,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "" @@ -63,7 +63,7 @@ msgstr "" msgid "%q should be an int" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "" @@ -71,12 +71,12 @@ msgstr "" msgid "'%q' argument required" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "" @@ -96,7 +96,7 @@ msgstr "" msgid "'%s' expects an address of the form [a, b]" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "" @@ -245,7 +245,7 @@ msgstr "" msgid "All event channels in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -253,9 +253,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -514,9 +514,8 @@ msgstr "Avast! EXTINT channel already in use" msgid "Error in regex" msgstr "" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "" @@ -524,8 +523,8 @@ msgstr "" msgid "Expected a Characteristic" msgstr "" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "" @@ -699,8 +698,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -806,11 +805,10 @@ msgstr "Belay that! Invalid pin for port-side channel" msgid "Invalid pin for right channel" msgstr "Belay that! Invalid pin for starboard-side channel" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "" @@ -1067,8 +1065,8 @@ msgstr "" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1308,7 +1306,7 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "" @@ -1620,7 +1618,7 @@ msgstr "" msgid "complex division by zero" msgstr "" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "" @@ -1661,7 +1659,7 @@ msgstr "" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "" @@ -1670,7 +1668,7 @@ msgstr "" msgid "empty" msgstr "" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "" @@ -1735,7 +1733,7 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1776,7 +1774,7 @@ msgstr "" msgid "function expected at most %d arguments, got %d" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "" @@ -1798,7 +1796,7 @@ msgstr "" msgid "function missing required positional argument #%d" msgstr "" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "" @@ -1945,7 +1943,7 @@ msgstr "" msgid "keywords must be strings" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2051,11 +2049,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2157,11 +2155,11 @@ msgstr "" msgid "odd-length string" msgstr "" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c msgid "offset out of bounds" msgstr "" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2179,7 +2177,7 @@ msgstr "" msgid "overflow converting long int to machine word" msgstr "" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "" @@ -2311,7 +2309,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" @@ -2412,10 +2410,6 @@ msgstr "" msgid "timestamp out of range for platform time_t" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "" @@ -2473,7 +2467,7 @@ msgstr "" msgid "unexpected keyword argument" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "" diff --git a/locale/es.po b/locale/es.po index 0592af242..6b1563a1f 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -55,8 +55,8 @@ msgstr "%q indice fuera de rango" msgid "%q indices must be integers, not %s" msgstr "%q indices deben ser enteros, no %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "%q debe ser >= 1" @@ -66,7 +66,7 @@ msgstr "%q debe ser >= 1" msgid "%q should be an int" msgstr "%q deberia ser un int" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "%q() toma %d argumentos posicionales pero %d fueron dados" @@ -74,12 +74,12 @@ msgstr "%q() toma %d argumentos posicionales pero %d fueron dados" msgid "'%q' argument required" msgstr "argumento '%q' requerido" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' espera una etiqueta" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' espera un registro" @@ -99,7 +99,7 @@ msgstr "'%s' espera un registro de FPU" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' espera una dirección de forma [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' espera un entero" @@ -250,7 +250,7 @@ msgstr "Todos los timers están siendo usados" msgid "All event channels in use" msgstr "Todos los canales de eventos en uso" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" "Todos los canales de eventos de sincronización(sync event channels) están " @@ -260,9 +260,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "Todos los timers para este pin están siendo utilizados" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -527,9 +527,8 @@ msgstr "El canal EXTINT ya está siendo utilizado" msgid "Error in regex" msgstr "Error en regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "Se espera un %q" @@ -538,8 +537,8 @@ msgstr "Se espera un %q" msgid "Expected a Characteristic" msgstr "No se puede agregar la Característica." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Se espera un %q" @@ -727,8 +726,8 @@ msgstr "Falló el iniciar la escritura de flash, err 0x%04x" msgid "Frequency captured is above capability. Capture Paused." msgstr "Frecuencia capturada por encima de la capacidad. Captura en pausa." -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "La función requiere lock" @@ -836,11 +835,10 @@ msgstr "Pin inválido para canal izquierdo" msgid "Invalid pin for right channel" msgstr "Pin inválido para canal derecho" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "pines inválidos" @@ -1109,8 +1107,8 @@ msgstr "Serializer está siendo utilizado" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1367,7 +1365,7 @@ msgstr "argumento es una secuencia vacía" msgid "argument has wrong type" msgstr "el argumento tiene un tipo erroneo" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "argumento número/tipos no coinciden" @@ -1685,7 +1683,7 @@ msgstr "color deberia ser un int" msgid "complex division by zero" msgstr "división compleja por cero" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "valores complejos no soportados" @@ -1728,7 +1726,7 @@ msgstr "destination_length debe ser un int >= 0" msgid "dict update sequence has wrong length" msgstr "la secuencia de actualizacion del dict tiene una longitud incorrecta" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "división por cero" @@ -1737,7 +1735,7 @@ msgstr "división por cero" msgid "empty" msgstr "vacío" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "heap vacío" @@ -1803,7 +1801,7 @@ msgstr "argumento(s) por palabra clave adicionales fueron dados" msgid "extra positional arguments given" msgstr "argumento posicional adicional dado" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "el archivo deberia ser una archivo abierto en modo byte" @@ -1844,7 +1842,7 @@ msgstr "la función no tiene argumentos por palabra clave" msgid "function expected at most %d arguments, got %d" msgstr "la función esperaba minimo %d argumentos, tiene %d" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "la función tiene múltiples valores para el argumento '%q'" @@ -1866,7 +1864,7 @@ msgstr "la función requiere del argumento por palabra clave '%q'" msgid "function missing required positional argument #%d" msgstr "la función requiere del argumento posicional #%d" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "la función toma %d argumentos posicionales pero le fueron dados %d" @@ -2016,7 +2014,7 @@ msgstr "" msgid "keywords must be strings" msgstr "palabras clave deben ser strings" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "etiqueta '%q' no definida" @@ -2123,11 +2121,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "necesita más de %d valores para descomprimir" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "potencia negativa sin float support" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "cuenta negativa de turnos" @@ -2232,12 +2230,12 @@ msgstr "objeto con protocolo de buffer requerido" msgid "odd-length string" msgstr "string de longitud impar" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c #, fuzzy msgid "offset out of bounds" msgstr "address fuera de límites" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "solo se admiten segmentos con step=1 (alias None)" @@ -2255,7 +2253,7 @@ msgstr "ord() espera un carácter, pero encontró un string de longitud %d" msgid "overflow converting long int to machine word" msgstr "desbordamiento convirtiendo long int a palabra de máquina" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "palette debe ser 32 bytes de largo" @@ -2391,7 +2389,7 @@ msgstr "la longitud de sleep no puede ser negativa" msgid "slice step cannot be zero" msgstr "slice step no puede ser cero" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "pequeño int desbordamiento" @@ -2494,10 +2492,6 @@ msgstr "bits debe ser 8" msgid "timestamp out of range for platform time_t" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "muchos argumentos" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "demasiados argumentos provistos con el formato dado" @@ -2555,7 +2549,7 @@ msgstr "sangría inesperada" msgid "unexpected keyword argument" msgstr "argumento por palabra clave inesperado" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "argumento por palabra clave inesperado '%q'" @@ -2847,6 +2841,9 @@ msgstr "paso cero" #~ msgid "scan failed" #~ msgstr "scan ha fallado" +#~ msgid "too many arguments" +#~ msgstr "muchos argumentos" + #~ msgid "unknown config param" #~ msgstr "parámetro config desconocido" diff --git a/locale/fil.po b/locale/fil.po index b34e7bb1b..2d420ca65 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -52,8 +52,8 @@ msgstr "%q indeks wala sa sakop" msgid "%q indices must be integers, not %s" msgstr "%q indeks ay dapat integers, hindi %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "aarehas na haba dapat ang buffer slices" @@ -63,7 +63,7 @@ msgstr "aarehas na haba dapat ang buffer slices" msgid "%q should be an int" msgstr "y ay dapat int" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "" "Ang %q() ay kumukuha ng %d positional arguments pero %d lang ang binigay" @@ -72,12 +72,12 @@ msgstr "" msgid "'%q' argument required" msgstr "'%q' argument kailangan" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' umaasa ng label" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "Inaasahan ng '%s' ang isang rehistro" @@ -97,7 +97,7 @@ msgstr "Inaasahan ng '%s' ang isang FPU register" msgid "'%s' expects an address of the form [a, b]" msgstr "Inaasahan ng '%s' ang isang address sa [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "Inaasahan ng '%s' ang isang integer" @@ -247,7 +247,7 @@ msgstr "Lahat ng I2C peripherals ginagamit" msgid "All event channels in use" msgstr "Lahat ng event channels ginagamit" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Lahat ng sync event channels ay ginagamit" @@ -255,9 +255,9 @@ msgstr "Lahat ng sync event channels ay ginagamit" msgid "All timers for this pin are in use" msgstr "Lahat ng timers para sa pin na ito ay ginagamit" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -523,9 +523,8 @@ msgstr "Ginagamit na ang EXTINT channel" msgid "Error in regex" msgstr "May pagkakamali sa REGEX" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "Umasa ng %q" @@ -534,8 +533,8 @@ msgstr "Umasa ng %q" msgid "Expected a Characteristic" msgstr "Hindi mabasa and Characteristic." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Umasa ng %q" @@ -723,8 +722,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Function nangangailangan ng lock" @@ -832,11 +831,10 @@ msgstr "Mali ang pin para sa kaliwang channel" msgid "Invalid pin for right channel" msgstr "Mali ang pin para sa kanang channel" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Mali ang pins" @@ -1106,8 +1104,8 @@ msgstr "Serializer ginagamit" msgid "Slice and value different lengths." msgstr "Slice at value iba't ibang haba." -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Hindi suportado ang Slices" @@ -1367,7 +1365,7 @@ msgstr "arg ay walang laman na sequence" msgid "argument has wrong type" msgstr "may maling type ang argument" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "hindi tugma ang argument num/types" @@ -1686,7 +1684,7 @@ msgstr "color ay dapat na int" msgid "complex division by zero" msgstr "kumplikadong dibisyon sa pamamagitan ng zero" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "kumplikadong values hindi sinusuportahan" @@ -1731,7 +1729,7 @@ msgstr "ang destination_length ay dapat na isang int >= 0" msgid "dict update sequence has wrong length" msgstr "may mali sa haba ng dict update sequence" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "dibisyon ng zero" @@ -1740,7 +1738,7 @@ msgstr "dibisyon ng zero" msgid "empty" msgstr "walang laman" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "walang laman ang heap" @@ -1806,7 +1804,7 @@ msgstr "dagdag na keyword argument na ibinigay" msgid "extra positional arguments given" msgstr "dagdag na positional argument na ibinigay" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "file ay dapat buksan sa byte mode" @@ -1847,7 +1845,7 @@ msgstr "ang function ay hindi kumukuha ng mga argumento ng keyword" msgid "function expected at most %d arguments, got %d" msgstr "function na inaasahang %d ang argumento, ngunit %d ang nakuha" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "ang function ay nakakuha ng maraming values para sa argument '%q'" @@ -1869,7 +1867,7 @@ msgstr "function nangangailangan ng keyword argument '%q'" msgid "function missing required positional argument #%d" msgstr "function nangangailangan ng positional argument #%d" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "" @@ -2021,7 +2019,7 @@ msgstr "" msgid "keywords must be strings" msgstr "ang keywords dapat strings" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "label '%d' kailangan na i-define" @@ -2128,11 +2126,11 @@ msgstr "native yield" msgid "need more than %d values to unpack" msgstr "kailangan ng higit sa %d na halaga upang i-unpack" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "negatibong power na walang float support" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "negative shift count" @@ -2234,12 +2232,12 @@ msgstr "object na may buffer protocol kinakailangan" msgid "odd-length string" msgstr "odd-length string" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c #, fuzzy msgid "offset out of bounds" msgstr "wala sa sakop ang address" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "ang mga slices lamang na may hakbang = 1 (aka None) ang sinusuportahan" @@ -2257,7 +2255,7 @@ msgstr "ord() umaasa ng character pero string ng %d haba ang nakita" msgid "overflow converting long int to machine word" msgstr "overflow nagcoconvert ng long int sa machine word" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "ang palette ay dapat 32 bytes ang haba" @@ -2393,7 +2391,7 @@ msgstr "sleep length ay dapat hindi negatibo" msgid "slice step cannot be zero" msgstr "slice step ay hindi puedeng 0" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "small int overflow" @@ -2496,10 +2494,6 @@ msgstr "bits ay dapat walo (8)" msgid "timestamp out of range for platform time_t" msgstr "wala sa sakop ng timestamp ang platform time_t" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "masyadong maraming argumento" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "masyadong maraming mga argumento na ibinigay sa ibinigay na format" @@ -2557,7 +2551,7 @@ msgstr "hindi inaasahang indent" msgid "unexpected keyword argument" msgstr "hindi inaasahang argumento ng keyword" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "hindi inaasahang argumento ng keyword na '%q'" @@ -2853,6 +2847,9 @@ msgstr "zero step" #~ msgid "scan failed" #~ msgstr "nabigo ang pag-scan" +#~ msgid "too many arguments" +#~ msgstr "masyadong maraming argumento" + #~ msgid "unknown config param" #~ msgstr "hindi alam na config param" diff --git a/locale/fr.po b/locale/fr.po index df3af424e..c304b8fe5 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -51,8 +51,8 @@ msgstr "index %q hors gamme" msgid "%q indices must be integers, not %s" msgstr "les indices %q doivent être des entiers, pas %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "les slices de tampon doivent être de longueurs égales" @@ -62,7 +62,7 @@ msgstr "les slices de tampon doivent être de longueurs égales" msgid "%q should be an int" msgstr "y doit être un entier (int)" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "%q() prend %d arguments mais %d ont été donnés" @@ -70,12 +70,12 @@ msgstr "%q() prend %d arguments mais %d ont été donnés" msgid "'%q' argument required" msgstr "'%q' argument requis" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' attend un label" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' attend un registre" @@ -95,7 +95,7 @@ msgstr "'%s' attend un registre FPU" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' attend une adresse de la forme [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' attend un entier" @@ -247,7 +247,7 @@ msgstr "Tous les périphériques I2C sont utilisés" msgid "All event channels in use" msgstr "Tous les canaux d'événements sont utilisés" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Tous les canaux d'événements de synchro sont utilisés" @@ -255,9 +255,9 @@ msgstr "Tous les canaux d'événements de synchro sont utilisés" msgid "All timers for this pin are in use" msgstr "Tous les timers pour cette broche sont utilisés" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -522,9 +522,8 @@ msgstr "Canal EXTINT déjà utilisé" msgid "Error in regex" msgstr "Erreur dans l'expression régulière" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "Attendu : %q" @@ -533,8 +532,8 @@ msgstr "Attendu : %q" msgid "Expected a Characteristic" msgstr "Impossible d'ajouter la Characteristic." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Attendu : %q" @@ -722,8 +721,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "La fonction nécessite un verrou" @@ -834,11 +833,10 @@ msgstr "Broche invalide pour le canal gauche" msgid "Invalid pin for right channel" msgstr "Broche invalide pour le canal droit" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Broches invalides" @@ -1114,8 +1112,8 @@ msgstr "Sérialiseur en cours d'utilisation" msgid "Slice and value different lengths." msgstr "Slice et valeur de tailles différentes" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Slices non supportées" @@ -1377,7 +1375,7 @@ msgstr "l'argument est une séquence vide" msgid "argument has wrong type" msgstr "l'argument est d'un mauvais type" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "argument num/types ne correspond pas" @@ -1705,7 +1703,7 @@ msgstr "la couleur doit être un entier (int)" msgid "complex division by zero" msgstr "division complexe par zéro" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "valeurs complexes non supportées" @@ -1748,7 +1746,7 @@ msgstr "destination_length doit être un entier >= 0" msgid "dict update sequence has wrong length" msgstr "la séquence de mise à jour de dict a une mauvaise longueur" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "division par zéro" @@ -1757,7 +1755,7 @@ msgstr "division par zéro" msgid "empty" msgstr "vide" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "'heap' vide" @@ -1823,7 +1821,7 @@ msgstr "argument nommé donné en plus" msgid "extra positional arguments given" msgstr "argument positionnel donné en plus" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "le fichier doit être un fichier ouvert en mode 'byte'" @@ -1864,7 +1862,7 @@ msgstr "la fonction ne prend pas d'arguments nommés" msgid "function expected at most %d arguments, got %d" msgstr "la fonction attendait au plus %d arguments, reçu %d" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "la fonction a reçu plusieurs valeurs pour l'argument '%q'" @@ -1886,7 +1884,7 @@ msgstr "il manque l'argument nommé obligatoire '%q'" msgid "function missing required positional argument #%d" msgstr "il manque l'argument obligatoire #%d" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "la fonction prend %d argument(s) mais %d ont été donné(s)" @@ -2035,7 +2033,7 @@ msgstr "" msgid "keywords must be strings" msgstr "les noms doivent être des chaînes de caractère" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "label '%q' non supporté" @@ -2142,11 +2140,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "nécessite plus de %d valeur à dégrouper" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "puissance négative sans support des nombres flottants" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "compte de décalage négatif" @@ -2251,12 +2249,12 @@ msgstr "un objet avec un protocol de tampon est nécessaire" msgid "odd-length string" msgstr "chaîne de longueur impaire" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c #, fuzzy msgid "offset out of bounds" msgstr "adresse hors limites" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "seuls les slices avec 'step=1' (cad None) sont supportées" @@ -2274,7 +2272,7 @@ msgstr "ord() attend un caractère mais une chaîne de longueur %d a été trouv msgid "overflow converting long int to machine word" msgstr "dépassement de capacité en convertissant un entier long en mot machine" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "la palette doit être longue de 32 octets" @@ -2413,7 +2411,7 @@ msgstr "la longueur de sleep ne doit pas être négative" msgid "slice step cannot be zero" msgstr "le pas 'step' de slice ne peut être zéro" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "dépassement de capacité d'un entier court" @@ -2517,10 +2515,6 @@ msgstr "les bits doivent être 8" msgid "timestamp out of range for platform time_t" msgstr "timestamp hors gamme pour time_t de la plateforme" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "trop d'arguments" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "trop d'arguments fournis avec ce format" @@ -2578,7 +2572,7 @@ msgstr "indentation inattendue" msgid "unexpected keyword argument" msgstr "argument nommé imprévu" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "argument nommé '%q' imprévu" @@ -2864,6 +2858,9 @@ msgstr "'step' nul" #~ msgid "scan failed" #~ msgstr "échec du scan" +#~ msgid "too many arguments" +#~ msgstr "trop d'arguments" + #~ msgid "unknown config param" #~ msgstr "paramètre de config. inconnu" diff --git a/locale/it_IT.po b/locale/it_IT.po index 7714530f6..baebe7260 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -52,8 +52,8 @@ msgstr "indice %q fuori intervallo" msgid "%q indices must be integers, not %s" msgstr "gli indici %q devono essere interi, non %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "slice del buffer devono essere della stessa lunghezza" @@ -63,7 +63,7 @@ msgstr "slice del buffer devono essere della stessa lunghezza" msgid "%q should be an int" msgstr "y dovrebbe essere un int" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "%q() prende %d argomenti posizionali ma ne sono stati forniti %d" @@ -71,12 +71,12 @@ msgstr "%q() prende %d argomenti posizionali ma ne sono stati forniti %d" msgid "'%q' argument required" msgstr "'%q' argomento richiesto" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' aspetta una etichetta" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' aspetta un registro" @@ -96,7 +96,7 @@ msgstr "'%s' aspetta un registro" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' aspetta un registro" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' aspetta un intero" @@ -246,7 +246,7 @@ msgstr "Tutte le periferiche I2C sono in uso" msgid "All event channels in use" msgstr "Tutti i canali eventi utilizati" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Tutti i canali di eventi sincronizzati in uso" @@ -254,9 +254,9 @@ msgstr "Tutti i canali di eventi sincronizzati in uso" msgid "All timers for this pin are in use" msgstr "Tutti i timer per questo pin sono in uso" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -523,9 +523,8 @@ msgstr "Canale EXTINT già in uso" msgid "Error in regex" msgstr "Errore nella regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "Atteso un %q" @@ -534,8 +533,8 @@ msgstr "Atteso un %q" msgid "Expected a Characteristic" msgstr "Non è possibile aggiungere Characteristic." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Atteso un %q" @@ -722,8 +721,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -833,11 +832,10 @@ msgstr "Pin non valido per il canale sinistro" msgid "Invalid pin for right channel" msgstr "Pin non valido per il canale destro" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Pin non validi" @@ -1112,8 +1110,8 @@ msgstr "Serializer in uso" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Slice non supportate" @@ -1361,7 +1359,7 @@ msgstr "l'argomento è una sequenza vuota" msgid "argument has wrong type" msgstr "il tipo dell'argomento è errato" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "discrepanza di numero/tipo di argomenti" @@ -1679,7 +1677,7 @@ msgstr "il colore deve essere un int" msgid "complex division by zero" msgstr "complex divisione per zero" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "valori complessi non supportai" @@ -1723,7 +1721,7 @@ msgstr "destination_length deve essere un int >= 0" msgid "dict update sequence has wrong length" msgstr "sequanza di aggiornamento del dizionario ha la lunghezza errata" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "divisione per zero" @@ -1732,7 +1730,7 @@ msgstr "divisione per zero" msgid "empty" msgstr "vuoto" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "heap vuoto" @@ -1798,7 +1796,7 @@ msgstr "argomento nominato aggiuntivo fornito" msgid "extra positional arguments given" msgstr "argomenti posizonali extra dati" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1839,7 +1837,7 @@ msgstr "la funzione non prende argomenti nominati" msgid "function expected at most %d arguments, got %d" msgstr "la funzione prevede al massimo %d argmoneti, ma ne ha ricevuti %d" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "la funzione ha ricevuto valori multipli per l'argomento '%q'" @@ -1861,7 +1859,7 @@ msgstr "argomento nominato '%q' mancante alla funzione" msgid "function missing required positional argument #%d" msgstr "mancante il #%d argomento posizonale obbligatorio della funzione" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "" @@ -2014,7 +2012,7 @@ msgstr "" msgid "keywords must be strings" msgstr "argomenti nominati devono essere stringhe" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "etichetta '%q' non definita" @@ -2121,11 +2119,11 @@ msgstr "yield nativo" msgid "need more than %d values to unpack" msgstr "necessari più di %d valori da scompattare" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "potenza negativa senza supporto per float" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2230,12 +2228,12 @@ msgstr "" msgid "odd-length string" msgstr "stringa di lunghezza dispari" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c #, fuzzy msgid "offset out of bounds" msgstr "indirizzo fuori limite" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "solo slice con step=1 (aka None) sono supportate" @@ -2254,7 +2252,7 @@ msgstr "" msgid "overflow converting long int to machine word" msgstr "overflow convertendo long int in parola" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "la palette deve essere lunga 32 byte" @@ -2391,7 +2389,7 @@ msgstr "la lunghezza di sleed deve essere non negativa" msgid "slice step cannot be zero" msgstr "la step della slice non può essere zero" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "small int overflow" @@ -2494,10 +2492,6 @@ msgstr "i bit devono essere 8" msgid "timestamp out of range for platform time_t" msgstr "timestamp è fuori intervallo per il time_t della piattaforma" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "troppi argomenti" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "troppi argomenti forniti con il formato specificato" @@ -2555,7 +2549,7 @@ msgstr "indentazione inaspettata" msgid "unexpected keyword argument" msgstr "argomento nominato inaspettato" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "argomento nominato '%q' inaspettato" @@ -2845,6 +2839,9 @@ msgstr "zero step" #~ msgid "scan failed" #~ msgstr "scansione fallita" +#~ msgid "too many arguments" +#~ msgstr "troppi argomenti" + #~ msgid "unknown config param" #~ msgstr "parametro di configurazione sconosciuto" diff --git a/locale/pl.po b/locale/pl.po index 888103fd3..94f21d1ff 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -53,8 +53,8 @@ msgstr "%q poza zakresem" msgid "%q indices must be integers, not %s" msgstr "%q indeks musi być liczbą całkowitą, a nie %s" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c msgid "%q must be >= 1" msgstr "%q musi być >= 1" @@ -62,7 +62,7 @@ msgstr "%q musi być >= 1" msgid "%q should be an int" msgstr "%q powinno być typu int" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "%q() bierze %d argumentów pozycyjnych, lecz podano %d" @@ -70,12 +70,12 @@ msgstr "%q() bierze %d argumentów pozycyjnych, lecz podano %d" msgid "'%q' argument required" msgstr "'%q' wymaga argumentu" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "'%s' oczekuje etykiety" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "'%s' oczekuje rejestru" @@ -95,7 +95,7 @@ msgstr "'%s' oczekuje rejestru FPU" msgid "'%s' expects an address of the form [a, b]" msgstr "'%s' oczekuje adresu w postaci [a, b]" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "'%s' oczekuje liczby całkowitej" @@ -244,7 +244,7 @@ msgstr "Wszystkie peryferia UART są w użyciu" msgid "All event channels in use" msgstr "Wszystkie kanały zdarzeń są w użyciu" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Wszystkie kanały zdarzeń synchronizacji są w użyciu" @@ -252,9 +252,9 @@ msgstr "Wszystkie kanały zdarzeń synchronizacji są w użyciu" msgid "All timers for this pin are in use" msgstr "Wszystkie " -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -513,9 +513,8 @@ msgstr "Kanał EXTINT jest już w użyciu" msgid "Error in regex" msgstr "Błąd w regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "Oczekiwano %q" @@ -523,8 +522,8 @@ msgstr "Oczekiwano %q" msgid "Expected a Characteristic" msgstr "Oczekiwano charakterystyki" -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c msgid "Expected a UUID" msgstr "Oczekiwano UUID" @@ -698,8 +697,8 @@ msgstr "Nie udało się rozpocząć zapisu do pamięci flash, błąd 0x%04x" msgid "Frequency captured is above capability. Capture Paused." msgstr "Uzyskana częstotliwość jest poza możliwościami. Spauzowano." -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "Funkcja wymaga blokady" @@ -807,11 +806,10 @@ msgstr "Niewłaściwa nóżka dla lewego kanału" msgid "Invalid pin for right channel" msgstr "Niewłaściwa nóżka dla prawego kanału" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Niewłaściwe nóżki" @@ -1077,8 +1075,8 @@ msgstr "Serializator w użyciu" msgid "Slice and value different lengths." msgstr "Fragment i wartość są różnych długości." -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "Fragmenty nieobsługiwane" @@ -1334,7 +1332,7 @@ msgstr "arg jest puste" msgid "argument has wrong type" msgstr "argument ma zły typ" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "niezgodna liczba lub typ argumentów" @@ -1646,7 +1644,7 @@ msgstr "kolor powinien być liczbą całkowitą" msgid "complex division by zero" msgstr "zespolone dzielenie przez zero" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "wartości zespolone nieobsługiwane" @@ -1688,7 +1686,7 @@ msgstr "destination_length musi być nieujemną liczbą całkowitą" msgid "dict update sequence has wrong length" msgstr "sekwencja ma złą długość" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "dzielenie przez zero" @@ -1697,7 +1695,7 @@ msgstr "dzielenie przez zero" msgid "empty" msgstr "puste" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "pusta sterta" @@ -1762,7 +1760,7 @@ msgstr "nadmiarowe argumenty" msgid "extra positional arguments given" msgstr "nadmiarowe argumenty pozycyjne" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "file musi być plikiem otwartym w trybie bajtowym" @@ -1803,7 +1801,7 @@ msgstr "funkcja nie bierze argumentów nazwanych" msgid "function expected at most %d arguments, got %d" msgstr "funkcja oczekuje najwyżej %d argumentów, jest %d" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "funkcja dostała wiele wartości dla argumentu '%q'" @@ -1825,7 +1823,7 @@ msgstr "brak wymaganego argumentu nazwanego '%q' funkcji" msgid "function missing required positional argument #%d" msgstr "brak wymaganego argumentu pozycyjnego #%d funkcji" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "funkcja wymaga %d argumentów pozycyjnych, ale jest %d" @@ -1972,7 +1970,7 @@ msgstr "argumenty nazwane nieobsługiwane - proszę użyć zwykłych argumentów msgid "keywords must be strings" msgstr "słowa kluczowe muszą być łańcuchami" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "etykieta '%q' niezdefiniowana" @@ -2078,11 +2076,11 @@ msgstr "natywny yield" msgid "need more than %d values to unpack" msgstr "potrzeba więcej niż %d do rozpakowania" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "ujemna potęga, ale brak obsługi liczb zmiennoprzecinkowych" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "ujemne przesunięcie" @@ -2184,11 +2182,11 @@ msgstr "wymagany obiekt z protokołem buforu" msgid "odd-length string" msgstr "łańcuch o nieparzystej długości" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c msgid "offset out of bounds" msgstr "offset poza zakresem" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "tylko fragmenty ze step=1 (lub None) są wspierane" @@ -2206,7 +2204,7 @@ msgstr "ord() oczekuje znaku, a jest łańcuch od długości %d" msgid "overflow converting long int to machine word" msgstr "przepełnienie przy konwersji long in to słowa maszynowego" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "paleta musi mieć 32 bajty długości" @@ -2340,7 +2338,7 @@ msgstr "okres snu musi być nieujemny" msgid "slice step cannot be zero" msgstr "krok fragmentu nie może być zerowy" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "przepełnienie small int" @@ -2441,10 +2439,6 @@ msgstr "timeout musi być >= 0.0" msgid "timestamp out of range for platform time_t" msgstr "timestamp poza zakresem dla time_t na tej platformie" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "zbyt wiele argumentów" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "zbyt wiele argumentów podanych dla tego formatu" @@ -2502,7 +2496,7 @@ msgstr "nieoczekiwane wcięcie" msgid "unexpected keyword argument" msgstr "nieoczekiwany argument nazwany" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "nieoczekiwany argument nazwany '%q'" @@ -2621,3 +2615,6 @@ msgstr "zerowy krok" #~ msgid "row must be packed and word aligned" #~ msgstr "row musi być upakowana i wyrównana do słowa" + +#~ msgid "too many arguments" +#~ msgstr "zbyt wiele argumentów" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 047b654b4..156c18931 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 16:48-0700\n" +"POT-Creation-Date: 2019-04-11 11:22+0200\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -52,8 +52,8 @@ msgstr "" msgid "%q indices must be integers, not %s" msgstr "" -#: shared-bindings/bleio/CharacteristicBuffer.c #: shared-bindings/displayio/Group.c shared-bindings/displayio/Shape.c +#: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "%q must be >= 1" msgstr "buffers devem ser o mesmo tamanho" @@ -63,7 +63,7 @@ msgstr "buffers devem ser o mesmo tamanho" msgid "%q should be an int" msgstr "y deve ser um int" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "%q() takes %d positional arguments but %d were given" msgstr "" @@ -71,12 +71,12 @@ msgstr "" msgid "'%q' argument required" msgstr "'%q' argumento(s) requerido(s)" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a label" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects a register" msgstr "" @@ -96,7 +96,7 @@ msgstr "" msgid "'%s' expects an address of the form [a, b]" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c #, c-format msgid "'%s' expects an integer" msgstr "" @@ -246,7 +246,7 @@ msgstr "Todos os periféricos I2C estão em uso" msgid "All event channels in use" msgstr "Todos os canais de eventos em uso" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -254,9 +254,9 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "Todos os temporizadores para este pino estão em uso" -#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/nrf/common-hal/pulseio/PulseOut.c shared-bindings/pulseio/PWMOut.c #: shared-module/_pew/PewPew.c msgid "All timers in use" @@ -518,9 +518,8 @@ msgstr "Canal EXTINT em uso" msgid "Error in regex" msgstr "Erro no regex" -#: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c -#: shared-bindings/terminalio/Terminal.c +#: shared-bindings/pulseio/PulseOut.c shared-bindings/neopixel_write/__init__.c +#: shared-bindings/terminalio/Terminal.c shared-bindings/microcontroller/Pin.c msgid "Expected a %q" msgstr "Esperado um" @@ -529,8 +528,8 @@ msgstr "Esperado um" msgid "Expected a Characteristic" msgstr "Não é possível adicionar Característica." -#: shared-bindings/bleio/Characteristic.c shared-bindings/bleio/Descriptor.c -#: shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Descriptor.c shared-bindings/bleio/Service.c +#: shared-bindings/bleio/Characteristic.c #, fuzzy msgid "Expected a UUID" msgstr "Esperado um" @@ -715,8 +714,8 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: shared-bindings/bitbangio/I2C.c shared-bindings/bitbangio/SPI.c -#: shared-bindings/busio/I2C.c shared-bindings/busio/SPI.c +#: shared-bindings/bitbangio/SPI.c shared-bindings/bitbangio/I2C.c +#: shared-bindings/busio/SPI.c shared-bindings/busio/I2C.c msgid "Function requires lock" msgstr "" @@ -824,11 +823,10 @@ msgstr "Pino inválido para canal esquerdo" msgid "Invalid pin for right channel" msgstr "Pino inválido para canal direito" -#: ports/atmel-samd/common-hal/busio/I2C.c -#: ports/atmel-samd/common-hal/busio/SPI.c -#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/i2cslave/I2CSlave.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/busio/SPI.c +#: ports/atmel-samd/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "Invalid pins" msgstr "Pinos inválidos" @@ -1091,8 +1089,8 @@ msgstr "Serializer em uso" msgid "Slice and value different lengths." msgstr "" -#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c -#: shared-bindings/displayio/TileGrid.c shared-bindings/pulseio/PulseIn.c +#: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/TileGrid.c +#: shared-bindings/displayio/Group.c shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" msgstr "" @@ -1333,7 +1331,7 @@ msgstr "" msgid "argument has wrong type" msgstr "argumento tem tipo errado" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "" @@ -1648,7 +1646,7 @@ msgstr "cor deve ser um int" msgid "complex division by zero" msgstr "" -#: py/objfloat.c py/parsenum.c +#: py/parsenum.c py/objfloat.c msgid "complex values not supported" msgstr "" @@ -1689,7 +1687,7 @@ msgstr "destination_length deve ser um int >= 0" msgid "dict update sequence has wrong length" msgstr "" -#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/modmath.c py/objint_mpz.c py/objint_longlong.c py/objfloat.c #: shared-bindings/math/__init__.c msgid "division by zero" msgstr "divisão por zero" @@ -1698,7 +1696,7 @@ msgstr "divisão por zero" msgid "empty" msgstr "vazio" -#: extmod/moduheapq.c extmod/modutimeq.c +#: extmod/modutimeq.c extmod/moduheapq.c msgid "empty heap" msgstr "heap vazia" @@ -1764,7 +1762,7 @@ msgstr "argumentos extras de palavras-chave passados" msgid "extra positional arguments given" msgstr "argumentos extra posicionais passados" -#: shared-bindings/audioio/WaveFile.c shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/audioio/WaveFile.c msgid "file must be a file opened in byte mode" msgstr "" @@ -1805,7 +1803,7 @@ msgstr "função não aceita argumentos de palavras-chave" msgid "function expected at most %d arguments, got %d" msgstr "função esperada na maioria dos %d argumentos, obteve %d" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "function got multiple values for argument '%q'" msgstr "" @@ -1827,7 +1825,7 @@ msgstr "" msgid "function missing required positional argument #%d" msgstr "" -#: py/argcheck.c py/bc.c py/objnamedtuple.c +#: py/argcheck.c py/objnamedtuple.c py/bc.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "função leva %d argumentos posicionais, mas apenas %d foram passadas" @@ -1974,7 +1972,7 @@ msgstr "" msgid "keywords must be strings" msgstr "" -#: py/emitinlinethumb.c py/emitinlinextensa.c +#: py/emitinlinextensa.c py/emitinlinethumb.c msgid "label '%q' not defined" msgstr "" @@ -2081,11 +2079,11 @@ msgstr "" msgid "need more than %d values to unpack" msgstr "precisa de mais de %d valores para desempacotar" -#: py/objint_longlong.c py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c py/objint_longlong.c msgid "negative power with no float support" msgstr "" -#: py/objint_mpz.c py/runtime.c +#: py/runtime.c py/objint_mpz.c msgid "negative shift count" msgstr "" @@ -2187,11 +2185,11 @@ msgstr "" msgid "odd-length string" msgstr "" -#: py/objstr.c py/objstrunicode.c +#: py/objstrunicode.c py/objstr.c msgid "offset out of bounds" msgstr "" -#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c +#: py/objarray.c py/objtuple.c py/objstrunicode.c py/objstr.c #: shared-bindings/nvm/ByteArray.c msgid "only slices with step=1 (aka None) are supported" msgstr "" @@ -2209,7 +2207,7 @@ msgstr "" msgid "overflow converting long int to machine word" msgstr "" -#: shared-bindings/_stage/Layer.c shared-bindings/_stage/Text.c +#: shared-bindings/_stage/Text.c shared-bindings/_stage/Layer.c msgid "palette must be 32 bytes long" msgstr "" @@ -2342,7 +2340,7 @@ msgstr "" msgid "slice step cannot be zero" msgstr "" -#: py/objint.c py/sequence.c +#: py/sequence.c py/objint.c msgid "small int overflow" msgstr "" @@ -2445,10 +2443,6 @@ msgstr "bits devem ser 8" msgid "timestamp out of range for platform time_t" msgstr "timestamp fora do intervalo para a plataforma time_t" -#: shared-bindings/gamepad/GamePad.c -msgid "too many arguments" -msgstr "muitos argumentos" - #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" msgstr "Muitos argumentos fornecidos com o formato dado" @@ -2506,7 +2500,7 @@ msgstr "" msgid "unexpected keyword argument" msgstr "" -#: py/bc.c py/objnamedtuple.c +#: py/objnamedtuple.c py/bc.c msgid "unexpected keyword argument '%q'" msgstr "" @@ -2785,6 +2779,9 @@ msgstr "passo zero" #~ msgid "scan failed" #~ msgstr "varredura falhou" +#~ msgid "too many arguments" +#~ msgstr "muitos argumentos" + #~ msgid "unknown config param" #~ msgstr "parâmetro configuração desconhecido" diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index c475185e7..04819f57b 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -35,7 +35,7 @@ #include "supervisor/shared/translate.h" #include "GamePad.h" -digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) { +STATIC digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) { if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) { mp_raise_TypeError(translate("expected a DigitalInOut")); } @@ -106,7 +106,7 @@ digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) { STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { if (n_args > 8) { - mp_raise_TypeError(translate("too many arguments")); + mp_raise_TypeError(translate("argument num/types mismatch")); } for (size_t i = 0; i < n_args; ++i) { validate_pin(args[i]); diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index 1d9b25cee..24c299f86 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -33,58 +33,44 @@ #include "shared-bindings/digitalio/DigitalInOut.h" -STATIC uint8_t pressed_pins(gamepad_obj_t *self) { - uint8_t current = 0; - uint8_t bit = 1; - for (int i = 0; i < 8; ++i) { - digitalio_digitalinout_obj_t* pin = self->pins[i]; - if (!pin) { - break; - } - if (common_hal_digitalio_digitalinout_get_value(pin)) { - current |= bit; - } - bit <<= 1; - } - current ^= self->pulls; - return current; -} - - -STATIC uint8_t pressed_shift(gamepad_obj_t *self) { - uint8_t current = 0; - uint8_t bit = 1; - digitalio_digitalinout_obj_t* data_pin = self->pins[0]; - digitalio_digitalinout_obj_t* clock_pin = self->pins[1]; - digitalio_digitalinout_obj_t* latch_pin = self->pins[2]; - - common_hal_digitalio_digitalinout_set_value(latch_pin, 1); - for (int i = 0; i < 8; ++i) { - common_hal_digitalio_digitalinout_set_value(clock_pin, 0); - if (common_hal_digitalio_digitalinout_get_value(data_pin)) { - current |= bit; - } - bit <<= 1; - common_hal_digitalio_digitalinout_set_value(clock_pin, 1); - } - common_hal_digitalio_digitalinout_set_value(latch_pin, 0); - return current; -} - - void gamepad_tick(void) { static uint8_t last = 0; uint8_t current = 0; + uint8_t bit = 1; gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); if (!gamepad_singleton) { return; } switch (gamepad_singleton->kind) { case GAMEPAD_KIND_PINS: - current = pressed_pins(gamepad_singleton); + for (int i = 0; i < 8; ++i) { + digitalio_digitalinout_obj_t* pin = gamepad_singleton->pins[i]; + if (!pin) { + break; + } + if (common_hal_digitalio_digitalinout_get_value(pin)) { + current |= bit; + } + bit <<= 1; + } + current ^= gamepad_singleton->pulls; break; case GAMEPAD_KIND_SHIFT: - current = pressed_shift(gamepad_singleton); + bit = 1; // we need a statement after a label + digitalio_digitalinout_obj_t* data_pin = gamepad_singleton->pins[0]; + digitalio_digitalinout_obj_t* clock_pin = gamepad_singleton->pins[1]; + digitalio_digitalinout_obj_t* latch_pin = gamepad_singleton->pins[2]; + + common_hal_digitalio_digitalinout_set_value(latch_pin, 1); + for (int i = 0; i < 8; ++i) { + common_hal_digitalio_digitalinout_set_value(clock_pin, 0); + if (common_hal_digitalio_digitalinout_get_value(data_pin)) { + current |= bit; + } + bit <<= 1; + common_hal_digitalio_digitalinout_set_value(clock_pin, 1); + } + common_hal_digitalio_digitalinout_set_value(latch_pin, 0); break; } gamepad_singleton->pressed |= last & current; -- cgit v1.2.3 From ae60968563ff844189ef17fcb8ba3ec9bb7b54f9 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Thu, 11 Apr 2019 12:05:49 +0200 Subject: More refactoring --- locale/ID.po | 6 +-- locale/circuitpython.pot | 6 +-- locale/de_DE.po | 9 ++--- locale/en_US.po | 6 +-- locale/en_x_pirate.po | 6 +-- locale/es.po | 9 ++--- locale/fil.po | 9 ++--- locale/fr.po | 9 ++--- locale/it_IT.po | 9 ++--- locale/pl.po | 9 ++--- locale/pt_BR.po | 6 +-- shared-bindings/gamepad/GamePad.c | 50 +++++++++++++++++++------ shared-module/gamepad/GamePad.c | 77 --------------------------------------- shared-module/gamepad/GamePad.h | 9 ----- shared-module/gamepad/__init__.c | 22 ++++++----- 15 files changed, 80 insertions(+), 162 deletions(-) (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index d8d82709b..58a737300 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1741,10 +1741,6 @@ msgstr "" msgid "expected ':' after format specifier" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "" - #: py/obj.c msgid "expected tuple/list" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 729dea742..316e51dc7 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1697,10 +1697,6 @@ msgstr "" msgid "expected ':' after format specifier" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "" - #: py/obj.c msgid "expected tuple/list" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 0130005be..c685c7de9 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -1737,10 +1737,6 @@ msgstr "Exceptions müssen von BaseException abgeleitet sein" msgid "expected ':' after format specifier" msgstr "erwarte ':' nach format specifier" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "erwarte DigitalInOut" - #: py/obj.c msgid "expected tuple/list" msgstr "erwarte tuple/list" @@ -2742,6 +2738,9 @@ msgstr "" #~ msgid "buffer too long" #~ msgstr "Buffer zu lang" +#~ msgid "expected a DigitalInOut" +#~ msgstr "erwarte DigitalInOut" + #~ msgid "expecting a pin" #~ msgstr "Ein Pin wird erwartet" diff --git a/locale/en_US.po b/locale/en_US.po index 99097a027..be5d21573 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -1697,10 +1697,6 @@ msgstr "" msgid "expected ':' after format specifier" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "" - #: py/obj.c msgid "expected tuple/list" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 1f81d3e3c..de9cd9095 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -1701,10 +1701,6 @@ msgstr "" msgid "expected ':' after format specifier" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "" - #: py/obj.c msgid "expected tuple/list" msgstr "" diff --git a/locale/es.po b/locale/es.po index 6b1563a1f..48e2420a0 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -1769,10 +1769,6 @@ msgstr "las excepciones deben derivar de BaseException" msgid "expected ':' after format specifier" msgstr "se espera ':' despues de un especificaro de tipo format" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "se espera un DigitalInOut" - #: py/obj.c msgid "expected tuple/list" msgstr "tupla/lista esperada" @@ -2789,6 +2785,9 @@ msgstr "paso cero" #~ msgid "either pos or kw args are allowed" #~ msgstr "ya sea pos o kw args son permitidos" +#~ msgid "expected a DigitalInOut" +#~ msgstr "se espera un DigitalInOut" + #~ msgid "expecting a pin" #~ msgstr "esperando un pin" diff --git a/locale/fil.po b/locale/fil.po index 2d420ca65..7a5bf9c7a 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -1772,10 +1772,6 @@ msgstr "ang mga exceptions ay dapat makuha mula sa BaseException" msgid "expected ':' after format specifier" msgstr "umaasa ng ':' pagkatapos ng format specifier" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "umasa ng DigitalInOut" - #: py/obj.c msgid "expected tuple/list" msgstr "umaasa ng tuple/list" @@ -2795,6 +2791,9 @@ msgstr "zero step" #~ msgid "either pos or kw args are allowed" #~ msgstr "pos o kw args ang pinahihintulutan" +#~ msgid "expected a DigitalInOut" +#~ msgstr "umasa ng DigitalInOut" + #~ msgid "expecting a pin" #~ msgstr "umaasa ng isang pin" diff --git a/locale/fr.po b/locale/fr.po index c304b8fe5..61f0b7b7f 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -1789,10 +1789,6 @@ msgstr "les exceptions doivent dériver de BaseException" msgid "expected ':' after format specifier" msgstr "':' attendu après la spécification de format" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "objet DigitalInOut attendu" - #: py/obj.c msgid "expected tuple/list" msgstr "un tuple ou une liste est attendu" @@ -2811,6 +2807,9 @@ msgstr "'step' nul" #~ msgid "either pos or kw args are allowed" #~ msgstr "soit 'pos', soit 'kw' est permis en argument" +#~ msgid "expected a DigitalInOut" +#~ msgstr "objet DigitalInOut attendu" + #~ msgid "expecting a pin" #~ msgstr "une broche (Pin) est attendue" diff --git a/locale/it_IT.po b/locale/it_IT.po index baebe7260..62dd420ce 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -1764,10 +1764,6 @@ msgstr "le eccezioni devono derivare da BaseException" msgid "expected ':' after format specifier" msgstr "':' atteso dopo lo specificatore di formato" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "DigitalInOut atteso" - #: py/obj.c msgid "expected tuple/list" msgstr "lista/tupla prevista" @@ -2787,6 +2783,9 @@ msgstr "zero step" #~ msgid "either pos or kw args are allowed" #~ msgstr "sono permesse solo gli argomenti pos o kw" +#~ msgid "expected a DigitalInOut" +#~ msgstr "DigitalInOut atteso" + #~ msgid "expecting a pin" #~ msgstr "pin atteso" diff --git a/locale/pl.po b/locale/pl.po index 94f21d1ff..7aab60d97 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -1728,10 +1728,6 @@ msgstr "wyjątki muszą dziedziczyć po BaseException" msgid "expected ':' after format specifier" msgstr "oczekiwano ':' po specyfikacji formatu" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "oczekiwano DigitalInOut" - #: py/obj.c msgid "expected tuple/list" msgstr "oczekiwano krotki/listy" @@ -2613,6 +2609,9 @@ msgstr "zerowy krok" #~ msgid "RTC set is not supported on this board" #~ msgstr "Ustawianie RTC nie jest obsługiwane na tej płytce" +#~ msgid "expected a DigitalInOut" +#~ msgstr "oczekiwano DigitalInOut" + #~ msgid "row must be packed and word aligned" #~ msgstr "row musi być upakowana i wyrównana do słowa" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 156c18931..d3a6d4e05 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-11 11:22+0200\n" +"POT-Creation-Date: 2019-04-11 11:44+0200\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -1730,10 +1730,6 @@ msgstr "" msgid "expected ':' after format specifier" msgstr "" -#: shared-bindings/gamepad/GamePad.c -msgid "expected a DigitalInOut" -msgstr "" - #: py/obj.c msgid "expected tuple/list" msgstr "" diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index 04819f57b..30fdac002 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -37,7 +37,7 @@ STATIC digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) { if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) { - mp_raise_TypeError(translate("expected a DigitalInOut")); + mp_raise_TypeError(translate("argument num/types mismatch")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj); raise_error_if_deinited( @@ -105,18 +105,37 @@ STATIC digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) { //| STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - if (n_args > 8) { + if (n_args > 8 || n_args == 0) { mp_raise_TypeError(translate("argument num/types mismatch")); } for (size_t i = 0; i < n_args; ++i) { validate_pin(args[i]); } - if (!MP_STATE_VM(gamepad_singleton)) { - gamepad_obj_t* gamepad_singleton = m_new_obj(gamepad_obj_t); - gamepad_singleton->base.type = &gamepad_type; + gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); + if (!gamepad_singleton) { + gamepad_singleton = m_new_obj(gamepad_obj_t); + gamepad_singleton->base.type = &gamepadshift_type; MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton); } - gamepad_init_pins(n_args, args); + for (size_t i = 0; i < 8; ++i) { + gamepad_singleton->pins[i] = NULL; + } + gamepad_singleton->pulls = 0; + for (size_t i = 0; i < n_args; ++i) { + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(args[i]); + if (common_hal_digitalio_digitalinout_get_direction(pin) != + DIRECTION_INPUT) { + common_hal_digitalio_digitalinout_switch_to_input(pin, PULL_UP); + } + digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(pin); + if (pull == PULL_NONE) { + common_hal_digitalio_digitalinout_set_pull(pin, PULL_UP); + } + if (pull != PULL_DOWN) { + gamepad_singleton->pulls |= 1 << i; + } + gamepad_singleton->pins[i] = pin; + } return MP_OBJ_FROM_PTR(MP_STATE_VM(gamepad_singleton)); } @@ -149,12 +168,21 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, digitalio_digitalinout_obj_t *clock_pin = validate_pin(args[ARG_clock].u_obj); digitalio_digitalinout_obj_t *latch_pin = validate_pin(args[ARG_latch].u_obj); - if (!MP_STATE_VM(gamepad_singleton)) { - gamepad_obj_t* gamepad_singleton = m_new_obj(gamepad_obj_t); + gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); + if (!gamepad_singleton) { + gamepad_singleton = m_new_obj(gamepad_obj_t); gamepad_singleton->base.type = &gamepadshift_type; MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton); } - gamepad_init_shift(data_pin, clock_pin, latch_pin); + gamepad_singleton->pins[0] = NULL; + common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); + gamepad_singleton->pins[1] = data_pin; + common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, + DRIVE_MODE_PUSH_PULL); + gamepad_singleton->pins[2] = clock_pin; + common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1, + DRIVE_MODE_PUSH_PULL); + gamepad_singleton->pins[3] = latch_pin; return MP_OBJ_FROM_PTR(MP_STATE_VM(gamepad_singleton)); } @@ -171,9 +199,9 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, //| STATIC mp_obj_t gamepad_get_pressed(mp_obj_t self_in) { gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); - mp_obj_t gamepad = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed); + mp_obj_t pressed = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed); gamepad_singleton->pressed = 0; - return gamepad; + return pressed; } MP_DEFINE_CONST_FUN_OBJ_1(gamepad_get_pressed_obj, gamepad_get_pressed); diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c index 18a7c4d7b..e69de29bb 100644 --- a/shared-module/gamepad/GamePad.c +++ b/shared-module/gamepad/GamePad.c @@ -1,77 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "py/mpstate.h" -#include "__init__.h" -#include "GamePad.h" - -#include "shared-bindings/digitalio/Pull.h" -#include "shared-bindings/digitalio/DigitalInOut.h" -#include "shared-bindings/util.h" - - -void gamepad_init_pins(size_t n_pins, const mp_obj_t* pins) { - gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); - for (size_t i = 0; i < 8; ++i) { - gamepad_singleton->pins[i] = NULL; - } - gamepad_singleton->pulls = 0; - for (size_t i = 0; i < n_pins; ++i) { - digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(pins[i]); - digitalio_direction_t direction = common_hal_digitalio_digitalinout_get_direction(pin); - if (direction != DIRECTION_INPUT) { - common_hal_digitalio_digitalinout_switch_to_input(pin, PULL_UP); - } - digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(pin); - if (pull == PULL_NONE) { - common_hal_digitalio_digitalinout_set_pull(pin, PULL_UP); - } - if (pull != PULL_DOWN) { - gamepad_singleton->pulls |= 1 << i; - } - gamepad_singleton->pins[i] = pin; - } - gamepad_singleton->kind = GAMEPAD_KIND_PINS; -} - -void gamepad_init_shift(digitalio_digitalinout_obj_t *data_pin, - digitalio_digitalinout_obj_t *clock_pin, - digitalio_digitalinout_obj_t *latch_pin) { - gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); - - common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); - gamepad_singleton->pins[0] = data_pin; - - common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, DRIVE_MODE_PUSH_PULL); - gamepad_singleton->pins[1] = clock_pin; - - common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1, DRIVE_MODE_PUSH_PULL); - gamepad_singleton->pins[2] = latch_pin; - - gamepad_singleton->kind = GAMEPAD_KIND_SHIFT; -} diff --git a/shared-module/gamepad/GamePad.h b/shared-module/gamepad/GamePad.h index 8ba597a37..746bba567 100644 --- a/shared-module/gamepad/GamePad.h +++ b/shared-module/gamepad/GamePad.h @@ -36,15 +36,6 @@ typedef struct { digitalio_digitalinout_obj_t* pins[8]; volatile uint8_t pressed; uint8_t pulls; - uint8_t kind; } gamepad_obj_t; -#define GAMEPAD_KIND_PINS 0 -#define GAMEPAD_KIND_SHIFT 1 - -void gamepad_init_pins(size_t n_pins, const mp_obj_t* pins); -void gamepad_init_shift(digitalio_digitalinout_obj_t *data_pin, - digitalio_digitalinout_obj_t *clock_pin, - digitalio_digitalinout_obj_t *latch_pin); - #endif // MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index 24c299f86..ccfbfae56 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -37,12 +37,16 @@ void gamepad_tick(void) { static uint8_t last = 0; uint8_t current = 0; uint8_t bit = 1; + digitalio_digitalinout_obj_t* data_pin; + digitalio_digitalinout_obj_t* clock_pin; + digitalio_digitalinout_obj_t* latch_pin; + gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); if (!gamepad_singleton) { return; } - switch (gamepad_singleton->kind) { - case GAMEPAD_KIND_PINS: + if (gamepad_singleton->pins[0]) { + // buttons connected directly to pins for (int i = 0; i < 8; ++i) { digitalio_digitalinout_obj_t* pin = gamepad_singleton->pins[i]; if (!pin) { @@ -54,12 +58,11 @@ void gamepad_tick(void) { bit <<= 1; } current ^= gamepad_singleton->pulls; - break; - case GAMEPAD_KIND_SHIFT: - bit = 1; // we need a statement after a label - digitalio_digitalinout_obj_t* data_pin = gamepad_singleton->pins[0]; - digitalio_digitalinout_obj_t* clock_pin = gamepad_singleton->pins[1]; - digitalio_digitalinout_obj_t* latch_pin = gamepad_singleton->pins[2]; + } else { + // buttons connected to a shift register + data_pin = gamepad_singleton->pins[1]; + clock_pin = gamepad_singleton->pins[2]; + latch_pin = gamepad_singleton->pins[3]; common_hal_digitalio_digitalinout_set_value(latch_pin, 1); for (int i = 0; i < 8; ++i) { @@ -67,11 +70,10 @@ void gamepad_tick(void) { if (common_hal_digitalio_digitalinout_get_value(data_pin)) { current |= bit; } - bit <<= 1; common_hal_digitalio_digitalinout_set_value(clock_pin, 1); + bit <<= 1; } common_hal_digitalio_digitalinout_set_value(latch_pin, 0); - break; } gamepad_singleton->pressed |= last & current; last = current; -- cgit v1.2.3 From 049e80993d8e7a4514e66d5745536a1b38480852 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Thu, 11 Apr 2019 16:08:26 +0200 Subject: Sync gampad_singleton with the long lived copy --- shared-bindings/gamepad/GamePad.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index 30fdac002..f189437a1 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -114,8 +114,9 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); if (!gamepad_singleton) { gamepad_singleton = m_new_obj(gamepad_obj_t); - gamepad_singleton->base.type = &gamepadshift_type; - MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton); + gamepad_singleton->base.type = &gamepad_type; + gamepad_singleton = gc_make_long_lived(gamepad_singleton); + MP_STATE_VM(gamepad_singleton) = gamepad_singleton; } for (size_t i = 0; i < 8; ++i) { gamepad_singleton->pins[i] = NULL; @@ -172,7 +173,8 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, if (!gamepad_singleton) { gamepad_singleton = m_new_obj(gamepad_obj_t); gamepad_singleton->base.type = &gamepadshift_type; - MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton); + gamepad_singleton = gc_make_long_lived(gamepad_singleton); + MP_STATE_VM(gamepad_singleton) = gamepad_singleton; } gamepad_singleton->pins[0] = NULL; common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); -- cgit v1.2.3 From 4dc286fa14e381f7ac2ca4dda1f006fac5bc0356 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 12 Apr 2019 20:38:51 +0200 Subject: Reorganize the gamepad code --- py/circuitpy_defns.mk | 1 + shared-bindings/gamepad/GamePad.c | 99 ++------------------------- shared-bindings/gamepad/GamePad.h | 1 - shared-bindings/gamepad/GamePadShift.c | 118 +++++++++++++++++++++++++++++++++ shared-bindings/gamepad/GamePadShift.h | 33 +++++++++ shared-bindings/gamepad/__init__.c | 15 +++++ shared-bindings/gamepad/__init__.h | 33 +++++++++ shared-module/gamepad/GamePad.c | 51 ++++++++++++++ shared-module/gamepad/GamePad.h | 4 ++ shared-module/gamepad/GamePadShift.c | 43 ++++++++++++ shared-module/gamepad/GamePadShift.h | 48 ++++++++++++++ shared-module/gamepad/__init__.c | 36 +++++----- 12 files changed, 370 insertions(+), 112 deletions(-) create mode 100644 shared-bindings/gamepad/GamePadShift.c create mode 100644 shared-bindings/gamepad/GamePadShift.h create mode 100644 shared-bindings/gamepad/__init__.h create mode 100644 shared-module/gamepad/GamePadShift.c create mode 100644 shared-module/gamepad/GamePadShift.h (limited to 'shared-bindings') diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 342c0ab0c..41c73430f 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -317,6 +317,7 @@ $(filter $(SRC_PATTERNS), \ fontio/BuiltinFont.c \ fontio/__init__.c \ gamepad/GamePad.c \ + gamepad/GamePadShift.c \ gamepad/__init__.c \ os/__init__.c \ random/__init__.c \ diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index f189437a1..8b88471ee 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -31,19 +31,10 @@ #include "shared-module/gamepad/__init__.h" #include "shared-module/gamepad/GamePad.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "shared-bindings/util.h" #include "supervisor/shared/translate.h" #include "GamePad.h" +#include "__init__.h" -STATIC digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) { - if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) { - mp_raise_TypeError(translate("argument num/types mismatch")); - } - digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj); - raise_error_if_deinited( - common_hal_digitalio_digitalinout_deinited(pin)); - return pin; -} //| .. currentmodule:: gamepad //| @@ -109,86 +100,20 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_TypeError(translate("argument num/types mismatch")); } for (size_t i = 0; i < n_args; ++i) { - validate_pin(args[i]); + pin_io(args[i]); } gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); - if (!gamepad_singleton) { + if (!gamepad_singleton || + !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(gamepad_singleton), &gamepad_type)) { gamepad_singleton = m_new_obj(gamepad_obj_t); gamepad_singleton->base.type = &gamepad_type; gamepad_singleton = gc_make_long_lived(gamepad_singleton); MP_STATE_VM(gamepad_singleton) = gamepad_singleton; } - for (size_t i = 0; i < 8; ++i) { - gamepad_singleton->pins[i] = NULL; - } - gamepad_singleton->pulls = 0; - for (size_t i = 0; i < n_args; ++i) { - digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(args[i]); - if (common_hal_digitalio_digitalinout_get_direction(pin) != - DIRECTION_INPUT) { - common_hal_digitalio_digitalinout_switch_to_input(pin, PULL_UP); - } - digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(pin); - if (pull == PULL_NONE) { - common_hal_digitalio_digitalinout_set_pull(pin, PULL_UP); - } - if (pull != PULL_DOWN) { - gamepad_singleton->pulls |= 1 << i; - } - gamepad_singleton->pins[i] = pin; - } - return MP_OBJ_FROM_PTR(MP_STATE_VM(gamepad_singleton)); -} - - -//| .. class:: GamePadShift(data, clock, latch) -//| -//| Initializes button scanning routines. -//| -//| The ``data``, ``clock`` and ``latch`` parameters are ``DigitalInOut`` -//| objects connected to the shift register controlling the buttons. -//| -//| They button presses are accumulated, until the ``get_pressed`` method -//| is called, at which point the button state is cleared, and the new -//| button presses start to be recorded. -//| -STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *pos_args, mp_map_t *kw_args) { - - enum { ARG_data, ARG_clock, ARG_latch }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ}, - { MP_QSTR_latch, MP_ARG_REQUIRED | MP_ARG_OBJ}, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), - allowed_args, args); - - digitalio_digitalinout_obj_t *data_pin = validate_pin(args[ARG_data].u_obj); - digitalio_digitalinout_obj_t *clock_pin = validate_pin(args[ARG_clock].u_obj); - digitalio_digitalinout_obj_t *latch_pin = validate_pin(args[ARG_latch].u_obj); - - gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); - if (!gamepad_singleton) { - gamepad_singleton = m_new_obj(gamepad_obj_t); - gamepad_singleton->base.type = &gamepadshift_type; - gamepad_singleton = gc_make_long_lived(gamepad_singleton); - MP_STATE_VM(gamepad_singleton) = gamepad_singleton; - } - gamepad_singleton->pins[0] = NULL; - common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); - gamepad_singleton->pins[1] = data_pin; - common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, - DRIVE_MODE_PUSH_PULL); - gamepad_singleton->pins[2] = clock_pin; - common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1, - DRIVE_MODE_PUSH_PULL); - gamepad_singleton->pins[3] = latch_pin; - return MP_OBJ_FROM_PTR(MP_STATE_VM(gamepad_singleton)); + gamepad_init(gamepad_singleton, args, n_args); + return MP_OBJ_FROM_PTR(gamepad_singleton); } - //| .. method:: get_pressed() //| //| Get the status of buttons pressed since the last call and clear it. @@ -230,15 +155,3 @@ const mp_obj_type_t gamepad_type = { .make_new = gamepad_make_new, .locals_dict = (mp_obj_dict_t*)&gamepad_locals_dict, }; - -STATIC const mp_rom_map_elem_t gamepadshift_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_get_pressed), MP_ROM_PTR(&gamepad_get_pressed_obj)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gamepad_deinit_obj)}, -}; -STATIC MP_DEFINE_CONST_DICT(gamepadshift_locals_dict, gamepadshift_locals_dict_table); -const mp_obj_type_t gamepadshift_type = { - { &mp_type_type }, - .name = MP_QSTR_GamePadShift, - .make_new = gamepadshift_make_new, - .locals_dict = (mp_obj_dict_t*)&gamepadshift_locals_dict, -}; diff --git a/shared-bindings/gamepad/GamePad.h b/shared-bindings/gamepad/GamePad.h index 350331193..172c95ace 100644 --- a/shared-bindings/gamepad/GamePad.h +++ b/shared-bindings/gamepad/GamePad.h @@ -29,6 +29,5 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H extern const mp_obj_type_t gamepad_type; -extern const mp_obj_type_t gamepadshift_type; #endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H diff --git a/shared-bindings/gamepad/GamePadShift.c b/shared-bindings/gamepad/GamePadShift.c new file mode 100644 index 000000000..07dd1b48e --- /dev/null +++ b/shared-bindings/gamepad/GamePadShift.c @@ -0,0 +1,118 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "py/gc.h" +#include "py/mpstate.h" +#include "shared-module/gamepad/__init__.h" +#include "shared-module/gamepad/GamePadShift.h" +#include "supervisor/shared/translate.h" +#include "GamePadShift.h" +#include "__init__.h" + + +//| .. class:: GamePadShift(data, clock, latch) +//| +//| Initializes button scanning routines. +//| +//| The ``data``, ``clock`` and ``latch`` parameters are ``DigitalInOut`` +//| objects connected to the shift register controlling the buttons. +//| +//| They button presses are accumulated, until the ``get_pressed`` method +//| is called, at which point the button state is cleared, and the new +//| button presses start to be recorded. +//| +STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, + const mp_obj_t *pos_args, mp_map_t *kw_args) { + + enum { ARG_data, ARG_clock, ARG_latch }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ}, + { MP_QSTR_latch, MP_ARG_REQUIRED | MP_ARG_OBJ}, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), + allowed_args, args); + + digitalio_digitalinout_obj_t *data_pin = pin_io(args[ARG_data].u_obj); + digitalio_digitalinout_obj_t *clock_pin = pin_io(args[ARG_clock].u_obj); + digitalio_digitalinout_obj_t *latch_pin = pin_io(args[ARG_latch].u_obj); + + gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); + if (!gamepad_singleton || + !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(gamepad_singleton), + &gamepadshift_type)) { + gamepad_singleton = m_new_obj(gamepadshift_obj_t); + gamepad_singleton->base.type = &gamepadshift_type; + gamepad_singleton = gc_make_long_lived(gamepad_singleton); + MP_STATE_VM(gamepad_singleton) = gamepad_singleton; + } + gamepadshift_init(gamepad_singleton, data_pin, clock_pin, latch_pin); + return MP_OBJ_FROM_PTR(gamepad_singleton); +} + +//| .. method:: get_pressed() +//| +//| Get the status of buttons pressed since the last call and clear it. +//| +//| Returns an 8-bit number, with bits that correspond to buttons, +//| which have been pressed (or held down) since the last call to this +//| function set to 1, and the remaining bits set to 0. Then it clears +//| the button state, so that new button presses (or buttons that are +//| held down) can be recorded for the next call. +//| +STATIC mp_obj_t gamepadshift_get_pressed(mp_obj_t self_in) { + gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); + mp_obj_t pressed = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed); + gamepad_singleton->pressed = 0; + return pressed; +} +MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_get_pressed_obj, gamepadshift_get_pressed); + +//| .. method:: deinit() +//| +//| Disable button scanning. +//| +STATIC mp_obj_t gamepadshift_deinit(mp_obj_t self_in) { + gamepad_reset(); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_deinit_obj, gamepadshift_deinit); + + +STATIC const mp_rom_map_elem_t gamepadshift_locals_dict_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR_get_pressed), MP_ROM_PTR(&gamepadshift_get_pressed_obj)}, + { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gamepadshift_deinit_obj)}, +}; +STATIC MP_DEFINE_CONST_DICT(gamepadshift_locals_dict, gamepadshift_locals_dict_table); +const mp_obj_type_t gamepadshift_type = { + { &mp_type_type }, + .name = MP_QSTR_GamePadShift, + .make_new = gamepadshift_make_new, + .locals_dict = (mp_obj_dict_t*)&gamepadshift_locals_dict, +}; diff --git a/shared-bindings/gamepad/GamePadShift.h b/shared-bindings/gamepad/GamePadShift.h new file mode 100644 index 000000000..68c8de876 --- /dev/null +++ b/shared-bindings/gamepad/GamePadShift.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPADSHIFT_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPADSHIFT_H + +extern const mp_obj_type_t gamepadshift_type; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPADSHIFT_H diff --git a/shared-bindings/gamepad/__init__.c b/shared-bindings/gamepad/__init__.c index 0775d6abf..ecbcc793e 100644 --- a/shared-bindings/gamepad/__init__.c +++ b/shared-bindings/gamepad/__init__.c @@ -27,6 +27,21 @@ #include "py/runtime.h" #include "py/mphal.h" #include "GamePad.h" +#include "GamePadShift.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/util.h" + + +// Helper for validating digitalio.DigitalInOut arguments +digitalio_digitalinout_obj_t *pin_io(mp_obj_t obj) { + if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) { + mp_raise_TypeError(translate("argument num/types mismatch")); + } + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj); + raise_error_if_deinited( + common_hal_digitalio_digitalinout_deinited(pin)); + return pin; +} //| :mod:`gamepad` --- Button handling diff --git a/shared-bindings/gamepad/__init__.h b/shared-bindings/gamepad/__init__.h new file mode 100644 index 000000000..12e38edc4 --- /dev/null +++ b/shared-bindings/gamepad/__init__.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H + +digitalio_digitalinout_obj_t *pin_io(mp_obj_t obj); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c index e69de29bb..23addb397 100644 --- a/shared-module/gamepad/GamePad.c +++ b/shared-module/gamepad/GamePad.c @@ -0,0 +1,51 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "GamePad.h" + +void gamepad_init(gamepad_obj_t *gamepad, + const mp_obj_t pins[], size_t n_pins) { + for (size_t i = 0; i < 8; ++i) { + gamepad->pins[i] = NULL; + } + gamepad->pulls = 0; + for (size_t i = 0; i < n_pins; ++i) { + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(pins[i]); + if (common_hal_digitalio_digitalinout_get_direction(pin) != + DIRECTION_INPUT) { + common_hal_digitalio_digitalinout_switch_to_input(pin, PULL_UP); + } + digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(pin); + if (pull == PULL_NONE) { + common_hal_digitalio_digitalinout_set_pull(pin, PULL_UP); + } + if (pull != PULL_DOWN) { + gamepad->pulls |= 1 << i; + } + gamepad->pins[i] = pin; + } +} diff --git a/shared-module/gamepad/GamePad.h b/shared-module/gamepad/GamePad.h index 746bba567..dc8a7e87a 100644 --- a/shared-module/gamepad/GamePad.h +++ b/shared-module/gamepad/GamePad.h @@ -38,4 +38,8 @@ typedef struct { uint8_t pulls; } gamepad_obj_t; + +void gamepad_init(gamepad_obj_t *gamepad, + const mp_obj_t pins[], size_t n_pins); + #endif // MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H diff --git a/shared-module/gamepad/GamePadShift.c b/shared-module/gamepad/GamePadShift.c new file mode 100644 index 000000000..12083a86a --- /dev/null +++ b/shared-module/gamepad/GamePadShift.c @@ -0,0 +1,43 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "GamePadShift.h" + + +void gamepadshift_init(gamepadshift_obj_t *gamepadshift, + digitalio_digitalinout_obj_t *data_pin, + digitalio_digitalinout_obj_t *clock_pin, + digitalio_digitalinout_obj_t *latch_pin) { + common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); + gamepadshift->data_pin = data_pin; + common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, + DRIVE_MODE_PUSH_PULL); + gamepadshift->clock_pin = clock_pin; + common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1, + DRIVE_MODE_PUSH_PULL); + gamepadshift->latch_pin = latch_pin; +} diff --git a/shared-module/gamepad/GamePadShift.h b/shared-module/gamepad/GamePadShift.h new file mode 100644 index 000000000..05235f318 --- /dev/null +++ b/shared-module/gamepad/GamePadShift.h @@ -0,0 +1,48 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_GAMEPAD_GAMEPADSHIFT_H +#define MICROPY_INCLUDED_GAMEPAD_GAMEPADSHIFT_H + +#include + +#include "shared-bindings/digitalio/DigitalInOut.h" + +typedef struct { + mp_obj_base_t base; + digitalio_digitalinout_obj_t* data_pin; + digitalio_digitalinout_obj_t* clock_pin; + digitalio_digitalinout_obj_t* latch_pin; + volatile uint8_t pressed; +} gamepadshift_obj_t; + + +void gamepadshift_init(gamepadshift_obj_t *gamepadshift, + digitalio_digitalinout_obj_t *data_pin, + digitalio_digitalinout_obj_t *clock_pin, + digitalio_digitalinout_obj_t *latch_pin); + +#endif // MICROPY_INCLUDED_GAMEPAD_GAMEPADSHIFT_H diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index ccfbfae56..f92042d4b 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -29,6 +29,9 @@ #include "py/mpstate.h" #include "__init__.h" #include "GamePad.h" +#include "GamePadShift.h" +#include "shared-bindings/gamepad/GamePad.h" +#include "shared-bindings/gamepad/GamePadShift.h" #include "shared-bindings/digitalio/DigitalInOut.h" @@ -37,18 +40,16 @@ void gamepad_tick(void) { static uint8_t last = 0; uint8_t current = 0; uint8_t bit = 1; - digitalio_digitalinout_obj_t* data_pin; - digitalio_digitalinout_obj_t* clock_pin; - digitalio_digitalinout_obj_t* latch_pin; - gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); - if (!gamepad_singleton) { + void* singleton = MP_STATE_VM(gamepad_singleton); + if (!singleton) { return; } - if (gamepad_singleton->pins[0]) { + if (MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepad_type)) { // buttons connected directly to pins + gamepad_obj_t *self = singleton; for (int i = 0; i < 8; ++i) { - digitalio_digitalinout_obj_t* pin = gamepad_singleton->pins[i]; + digitalio_digitalinout_obj_t* pin = self->pins[i]; if (!pin) { break; } @@ -57,25 +58,24 @@ void gamepad_tick(void) { } bit <<= 1; } - current ^= gamepad_singleton->pulls; - } else { + current ^= self->pulls; + self->pressed |= last & current; + } else if (MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepadshift_type)) { // buttons connected to a shift register - data_pin = gamepad_singleton->pins[1]; - clock_pin = gamepad_singleton->pins[2]; - latch_pin = gamepad_singleton->pins[3]; + gamepadshift_obj_t *self = singleton; - common_hal_digitalio_digitalinout_set_value(latch_pin, 1); + common_hal_digitalio_digitalinout_set_value(self->latch_pin, 1); for (int i = 0; i < 8; ++i) { - common_hal_digitalio_digitalinout_set_value(clock_pin, 0); - if (common_hal_digitalio_digitalinout_get_value(data_pin)) { + common_hal_digitalio_digitalinout_set_value(self->clock_pin, 0); + if (common_hal_digitalio_digitalinout_get_value(self->data_pin)) { current |= bit; } - common_hal_digitalio_digitalinout_set_value(clock_pin, 1); + common_hal_digitalio_digitalinout_set_value(self->clock_pin, 1); bit <<= 1; } - common_hal_digitalio_digitalinout_set_value(latch_pin, 0); + common_hal_digitalio_digitalinout_set_value(self->latch_pin, 0); + self->pressed |= last & current; } - gamepad_singleton->pressed |= last & current; last = current; } -- cgit v1.2.3 From 7aab3e8c9394ad8f07d101b426d13ec59c36c01c Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 12 Apr 2019 21:31:06 +0200 Subject: Re-use an error message in _stage --- shared-bindings/_stage/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 466098061..dc9dbef65 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -84,7 +84,7 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { size_t buffer_size = bufinfo.len / 2; // 16-bit indexing if (!MP_OBJ_IS_TYPE(args[6], &displayio_display_type)) { - mp_raise_TypeError(translate("expected displayio.Display")); + mp_raise_TypeError(translate("argument num/types mismatch")); } displayio_display_obj_t *display = MP_OBJ_TO_PTR(args[6]); -- cgit v1.2.3 From 016efb5c68c3ca8d97f109146946db2ae96e8759 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 12 Apr 2019 22:00:03 +0200 Subject: Add GamePadShift to docs --- shared-bindings/gamepad/__init__.c | 1 + 1 file changed, 1 insertion(+) (limited to 'shared-bindings') diff --git a/shared-bindings/gamepad/__init__.c b/shared-bindings/gamepad/__init__.c index ecbcc793e..0806a142e 100644 --- a/shared-bindings/gamepad/__init__.c +++ b/shared-bindings/gamepad/__init__.c @@ -55,6 +55,7 @@ digitalio_digitalinout_obj_t *pin_io(mp_obj_t obj) { //| :maxdepth: 3 //| //| GamePad +//| GamePadShift //| STATIC const mp_rom_map_elem_t gamepad_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepad) }, -- cgit v1.2.3 From c0a553e90fdd61c77803de7b63507f6a2e2b5fa0 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 12 Apr 2019 22:52:19 +0200 Subject: Add title to docs --- shared-bindings/gamepad/GamePadShift.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/gamepad/GamePadShift.c b/shared-bindings/gamepad/GamePadShift.c index 07dd1b48e..c24a9162a 100644 --- a/shared-bindings/gamepad/GamePadShift.c +++ b/shared-bindings/gamepad/GamePadShift.c @@ -34,7 +34,11 @@ #include "GamePadShift.h" #include "__init__.h" - +//| .. currentmodule:: gamepad +//| +//| :class:`GamePadShift` -- Scan buttons for presses +//| ================================================= +//| //| .. class:: GamePadShift(data, clock, latch) //| //| Initializes button scanning routines. -- cgit v1.2.3 From c927e6b938ff35fe0f42180d1dc0f9d58f8e571c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 15 Apr 2019 15:40:06 -0700 Subject: Split GamePadShift from GamePad to save space on most boards. --- ports/atmel-samd/boards/pybadge/mpconfigboard.mk | 2 + py/circuitpy_defns.mk | 7 +- py/circuitpy_mpconfig.h | 8 ++ py/circuitpy_mpconfig.mk | 5 + shared-bindings/gamepad/GamePad.c | 6 +- shared-bindings/gamepad/GamePad.h | 5 + shared-bindings/gamepad/GamePadShift.c | 122 ---------------------- shared-bindings/gamepad/GamePadShift.h | 33 ------ shared-bindings/gamepad/__init__.c | 8 +- shared-bindings/gamepad/__init__.h | 4 +- shared-bindings/gamepadshift/GamePadShift.c | 125 +++++++++++++++++++++++ shared-bindings/gamepadshift/GamePadShift.h | 42 ++++++++ shared-bindings/gamepadshift/__init__.c | 54 ++++++++++ shared-bindings/gamepadshift/__init__.h | 31 ++++++ shared-module/gamepad/GamePad.c | 9 +- shared-module/gamepad/GamePad.h | 5 +- shared-module/gamepad/GamePadShift.c | 43 -------- shared-module/gamepad/GamePadShift.h | 48 --------- shared-module/gamepad/__init__.c | 33 +++--- shared-module/gamepadshift/GamePadShift.c | 64 ++++++++++++ shared-module/gamepadshift/GamePadShift.h | 45 ++++++++ shared-module/gamepadshift/__init__.c | 27 +++++ 22 files changed, 442 insertions(+), 284 deletions(-) delete mode 100644 shared-bindings/gamepad/GamePadShift.c delete mode 100644 shared-bindings/gamepad/GamePadShift.h create mode 100644 shared-bindings/gamepadshift/GamePadShift.c create mode 100644 shared-bindings/gamepadshift/GamePadShift.h create mode 100644 shared-bindings/gamepadshift/__init__.c create mode 100644 shared-bindings/gamepadshift/__init__.h delete mode 100644 shared-module/gamepad/GamePadShift.c delete mode 100644 shared-module/gamepad/GamePadShift.h create mode 100644 shared-module/gamepadshift/GamePadShift.c create mode 100644 shared-module/gamepadshift/GamePadShift.h create mode 100644 shared-module/gamepadshift/__init__.c (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/pybadge/mpconfigboard.mk b/ports/atmel-samd/boards/pybadge/mpconfigboard.mk index 8828c17b2..63510b52a 100644 --- a/ports/atmel-samd/boards/pybadge/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pybadge/mpconfigboard.mk @@ -14,5 +14,7 @@ CIRCUITPY_AUDIOBUSIO = 0 # No touch on SAMD51 yet CIRCUITPY_TOUCHIO = 0 +CIRCUITPY_GAMEPADSHIFT = 1 + CHIP_VARIANT = SAMD51J19A CHIP_FAMILY = samd51 diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 41c73430f..be7ff0b11 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -131,6 +131,10 @@ SRC_PATTERNS += frequencyio/% endif ifeq ($(CIRCUITPY_GAMEPAD),1) SRC_PATTERNS += gamepad/% + # gamepadshift depends on gamepad + ifeq ($(CIRCUITPY_GAMEPADSHIFT),1) + SRC_PATTERNS += gamepadshift/% + endif endif ifeq ($(CIRCUITPY_I2CSLAVE),1) SRC_PATTERNS += i2cslave/% @@ -317,8 +321,9 @@ $(filter $(SRC_PATTERNS), \ fontio/BuiltinFont.c \ fontio/__init__.c \ gamepad/GamePad.c \ - gamepad/GamePadShift.c \ gamepad/__init__.c \ + gamepadshift/GamePadShift.c \ + gamepadshift/__init__.c \ os/__init__.c \ random/__init__.c \ socket/__init__.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 441dd5bad..3952b5e06 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -322,6 +322,13 @@ extern const struct _mp_obj_module_t gamepad_module; #define GAMEPAD_MODULE #endif +#if CIRCUITPY_GAMEPADSHIFT +extern const struct _mp_obj_module_t gamepadshift_module; +#define GAMEPADSHIFT_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_gamepadshift),(mp_obj_t)&gamepadshift_module }, +#else +#define GAMEPADSHIFT_MODULE +#endif + #if CIRCUITPY_I2CSLAVE extern const struct _mp_obj_module_t i2cslave_module; #define I2CSLAVE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_i2cslave), (mp_obj_t)&i2cslave_module }, @@ -554,6 +561,7 @@ extern const struct _mp_obj_module_t ustack_module; ERRNO_MODULE \ FREQUENCYIO_MODULE \ GAMEPAD_MODULE \ + GAMEPADSHIFT_MODULE \ I2CSLAVE_MODULE \ JSON_MODULE \ MATH_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 8ea72f0bf..b436929e0 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -102,6 +102,11 @@ CIRCUITPY_GAMEPAD = $(CIRCUITPY_FULL_BUILD) endif CFLAGS += -DCIRCUITPY_GAMEPAD=$(CIRCUITPY_GAMEPAD) +ifndef CIRCUITPY_GAMEPADSHIFT +CIRCUITPY_GAMEPADSHIFT = 0 +endif +CFLAGS += -DCIRCUITPY_GAMEPADSHIFT=$(CIRCUITPY_GAMEPADSHIFT) + ifndef CIRCUITPY_I2CSLAVE CIRCUITPY_I2CSLAVE = $(CIRCUITPY_FULL_BUILD) endif diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index 8b88471ee..c80aa7f7c 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -100,7 +100,7 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_TypeError(translate("argument num/types mismatch")); } for (size_t i = 0; i < n_args; ++i) { - pin_io(args[i]); + assert_digitalinout(args[i]); } gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); if (!gamepad_singleton || @@ -110,7 +110,7 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, gamepad_singleton = gc_make_long_lived(gamepad_singleton); MP_STATE_VM(gamepad_singleton) = gamepad_singleton; } - gamepad_init(gamepad_singleton, args, n_args); + common_hal_gamepad_gamepad_init(gamepad_singleton, args, n_args); return MP_OBJ_FROM_PTR(gamepad_singleton); } @@ -138,7 +138,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(gamepad_get_pressed_obj, gamepad_get_pressed); //| Disable button scanning. //| STATIC mp_obj_t gamepad_deinit(mp_obj_t self_in) { - gamepad_reset(); + common_hal_gamepad_gamepad_deinit(self_in); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(gamepad_deinit_obj, gamepad_deinit); diff --git a/shared-bindings/gamepad/GamePad.h b/shared-bindings/gamepad/GamePad.h index 172c95ace..3bbad4c97 100644 --- a/shared-bindings/gamepad/GamePad.h +++ b/shared-bindings/gamepad/GamePad.h @@ -28,6 +28,11 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H #define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H +#include "shared-module/gamepad/GamePad.h" + extern const mp_obj_type_t gamepad_type; +void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad, const mp_obj_t pins[], size_t n_pins); +void common_hal_gamepad_gamepad_deinit(gamepad_obj_t *gamepad); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H diff --git a/shared-bindings/gamepad/GamePadShift.c b/shared-bindings/gamepad/GamePadShift.c deleted file mode 100644 index c24a9162a..000000000 --- a/shared-bindings/gamepad/GamePadShift.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "py/obj.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "py/gc.h" -#include "py/mpstate.h" -#include "shared-module/gamepad/__init__.h" -#include "shared-module/gamepad/GamePadShift.h" -#include "supervisor/shared/translate.h" -#include "GamePadShift.h" -#include "__init__.h" - -//| .. currentmodule:: gamepad -//| -//| :class:`GamePadShift` -- Scan buttons for presses -//| ================================================= -//| -//| .. class:: GamePadShift(data, clock, latch) -//| -//| Initializes button scanning routines. -//| -//| The ``data``, ``clock`` and ``latch`` parameters are ``DigitalInOut`` -//| objects connected to the shift register controlling the buttons. -//| -//| They button presses are accumulated, until the ``get_pressed`` method -//| is called, at which point the button state is cleared, and the new -//| button presses start to be recorded. -//| -STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *pos_args, mp_map_t *kw_args) { - - enum { ARG_data, ARG_clock, ARG_latch }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ}, - { MP_QSTR_latch, MP_ARG_REQUIRED | MP_ARG_OBJ}, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), - allowed_args, args); - - digitalio_digitalinout_obj_t *data_pin = pin_io(args[ARG_data].u_obj); - digitalio_digitalinout_obj_t *clock_pin = pin_io(args[ARG_clock].u_obj); - digitalio_digitalinout_obj_t *latch_pin = pin_io(args[ARG_latch].u_obj); - - gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); - if (!gamepad_singleton || - !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(gamepad_singleton), - &gamepadshift_type)) { - gamepad_singleton = m_new_obj(gamepadshift_obj_t); - gamepad_singleton->base.type = &gamepadshift_type; - gamepad_singleton = gc_make_long_lived(gamepad_singleton); - MP_STATE_VM(gamepad_singleton) = gamepad_singleton; - } - gamepadshift_init(gamepad_singleton, data_pin, clock_pin, latch_pin); - return MP_OBJ_FROM_PTR(gamepad_singleton); -} - -//| .. method:: get_pressed() -//| -//| Get the status of buttons pressed since the last call and clear it. -//| -//| Returns an 8-bit number, with bits that correspond to buttons, -//| which have been pressed (or held down) since the last call to this -//| function set to 1, and the remaining bits set to 0. Then it clears -//| the button state, so that new button presses (or buttons that are -//| held down) can be recorded for the next call. -//| -STATIC mp_obj_t gamepadshift_get_pressed(mp_obj_t self_in) { - gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); - mp_obj_t pressed = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed); - gamepad_singleton->pressed = 0; - return pressed; -} -MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_get_pressed_obj, gamepadshift_get_pressed); - -//| .. method:: deinit() -//| -//| Disable button scanning. -//| -STATIC mp_obj_t gamepadshift_deinit(mp_obj_t self_in) { - gamepad_reset(); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_deinit_obj, gamepadshift_deinit); - - -STATIC const mp_rom_map_elem_t gamepadshift_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_get_pressed), MP_ROM_PTR(&gamepadshift_get_pressed_obj)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gamepadshift_deinit_obj)}, -}; -STATIC MP_DEFINE_CONST_DICT(gamepadshift_locals_dict, gamepadshift_locals_dict_table); -const mp_obj_type_t gamepadshift_type = { - { &mp_type_type }, - .name = MP_QSTR_GamePadShift, - .make_new = gamepadshift_make_new, - .locals_dict = (mp_obj_dict_t*)&gamepadshift_locals_dict, -}; diff --git a/shared-bindings/gamepad/GamePadShift.h b/shared-bindings/gamepad/GamePadShift.h deleted file mode 100644 index 68c8de876..000000000 --- a/shared-bindings/gamepad/GamePadShift.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPADSHIFT_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPADSHIFT_H - -extern const mp_obj_type_t gamepadshift_type; - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPADSHIFT_H diff --git a/shared-bindings/gamepad/__init__.c b/shared-bindings/gamepad/__init__.c index 0806a142e..e61f36cc2 100644 --- a/shared-bindings/gamepad/__init__.c +++ b/shared-bindings/gamepad/__init__.c @@ -26,14 +26,12 @@ #include "py/obj.h" #include "py/runtime.h" #include "py/mphal.h" -#include "GamePad.h" -#include "GamePadShift.h" -#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/gamepad/GamePad.h" #include "shared-bindings/util.h" // Helper for validating digitalio.DigitalInOut arguments -digitalio_digitalinout_obj_t *pin_io(mp_obj_t obj) { +digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj) { if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) { mp_raise_TypeError(translate("argument num/types mismatch")); } @@ -55,12 +53,10 @@ digitalio_digitalinout_obj_t *pin_io(mp_obj_t obj) { //| :maxdepth: 3 //| //| GamePad -//| GamePadShift //| STATIC const mp_rom_map_elem_t gamepad_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepad) }, { MP_OBJ_NEW_QSTR(MP_QSTR_GamePad), MP_ROM_PTR(&gamepad_type)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_GamePadShift), MP_ROM_PTR(&gamepadshift_type)}, }; STATIC MP_DEFINE_CONST_DICT(gamepad_module_globals, gamepad_module_globals_table); diff --git a/shared-bindings/gamepad/__init__.h b/shared-bindings/gamepad/__init__.h index 12e38edc4..40cf4e6de 100644 --- a/shared-bindings/gamepad/__init__.h +++ b/shared-bindings/gamepad/__init__.h @@ -28,6 +28,8 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H #define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H -digitalio_digitalinout_obj_t *pin_io(mp_obj_t obj); +#include "shared-bindings/digitalio/DigitalInOut.h" + +digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H diff --git a/shared-bindings/gamepadshift/GamePadShift.c b/shared-bindings/gamepadshift/GamePadShift.c new file mode 100644 index 000000000..94b71036f --- /dev/null +++ b/shared-bindings/gamepadshift/GamePadShift.c @@ -0,0 +1,125 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "py/gc.h" +#include "py/mpstate.h" +#include "shared-bindings/gamepad/__init__.h" +#include "shared-bindings/gamepadshift/GamePadShift.h" +#include "shared-bindings/gamepadshift/__init__.h" +#include "shared-module/gamepadshift/GamePadShift.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: gamepadshift +//| +//| :class:`GamePadShift` -- Scan buttons for presses through a shift register +//| =========================================================================== +//| +//| .. class:: GamePadShift(data, clock, latch) +//| +//| Initializes button scanning routines. +//| +//| The ``data``, ``clock`` and ``latch`` parameters are ``DigitalInOut`` +//| objects connected to the shift register controlling the buttons. +//| +//| They button presses are accumulated, until the ``get_pressed`` method +//| is called, at which point the button state is cleared, and the new +//| button presses start to be recorded. +//| +//| Only one gamepad (`gamepad.GamePad` or `gamepadshift.GamePadShift`) +//| may be used at a time. +//| +STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, + const mp_obj_t *pos_args, mp_map_t *kw_args) { + + enum { ARG_data, ARG_clock, ARG_latch }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ}, + { MP_QSTR_latch, MP_ARG_REQUIRED | MP_ARG_OBJ}, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), + allowed_args, args); + + digitalio_digitalinout_obj_t *data_pin = assert_digitalinout(args[ARG_data].u_obj); + digitalio_digitalinout_obj_t *clock_pin = assert_digitalinout(args[ARG_clock].u_obj); + digitalio_digitalinout_obj_t *latch_pin = assert_digitalinout(args[ARG_latch].u_obj); + + gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); + if (!gamepad_singleton || + !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(gamepad_singleton), + &gamepadshift_type)) { + gamepad_singleton = m_new_obj(gamepadshift_obj_t); + gamepad_singleton->base.type = &gamepadshift_type; + gamepad_singleton = gc_make_long_lived(gamepad_singleton); + MP_STATE_VM(gamepad_singleton) = gamepad_singleton; + } + common_hal_gamepadshift_gamepadshift_init(gamepad_singleton, data_pin, clock_pin, latch_pin); + return MP_OBJ_FROM_PTR(gamepad_singleton); +} + +//| .. method:: get_pressed() +//| +//| Get the status of buttons pressed since the last call and clear it. +//| +//| Returns an 8-bit number, with bits that correspond to buttons, +//| which have been pressed (or held down) since the last call to this +//| function set to 1, and the remaining bits set to 0. Then it clears +//| the button state, so that new button presses (or buttons that are +//| held down) can be recorded for the next call. +//| +STATIC mp_obj_t gamepadshift_get_pressed(mp_obj_t self_in) { + gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); + mp_obj_t pressed = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed); + gamepad_singleton->pressed = 0; + return pressed; +} +MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_get_pressed_obj, gamepadshift_get_pressed); + +//| .. method:: deinit() +//| +//| Disable button scanning. +//| +STATIC mp_obj_t gamepadshift_deinit(mp_obj_t self_in) { + common_hal_gamepadshift_gamepadshift_deinit(self_in); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_deinit_obj, gamepadshift_deinit); + + +STATIC const mp_rom_map_elem_t gamepadshift_locals_dict_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR_get_pressed), MP_ROM_PTR(&gamepadshift_get_pressed_obj)}, + { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gamepadshift_deinit_obj)}, +}; +STATIC MP_DEFINE_CONST_DICT(gamepadshift_locals_dict, gamepadshift_locals_dict_table); +const mp_obj_type_t gamepadshift_type = { + { &mp_type_type }, + .name = MP_QSTR_GamePadShift, + .make_new = gamepadshift_make_new, + .locals_dict = (mp_obj_dict_t*)&gamepadshift_locals_dict, +}; diff --git a/shared-bindings/gamepadshift/GamePadShift.h b/shared-bindings/gamepadshift/GamePadShift.h new file mode 100644 index 000000000..2668ec83f --- /dev/null +++ b/shared-bindings/gamepadshift/GamePadShift.h @@ -0,0 +1,42 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPADSHIFT_GAMEPADSHIFT_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPADSHIFT_GAMEPADSHIFT_H + +#include "shared-module/gamepadshift/GamePadShift.h" + +extern const mp_obj_type_t gamepadshift_type; + +void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift, + digitalio_digitalinout_obj_t *data_pin, + digitalio_digitalinout_obj_t *clock_pin, + digitalio_digitalinout_obj_t *latch_pin); + +void common_hal_gamepadshift_gamepadshift_deinit(gamepadshift_obj_t *gamepadshift); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPADSHIFT_GAMEPADSHIFT_H diff --git a/shared-bindings/gamepadshift/__init__.c b/shared-bindings/gamepadshift/__init__.c new file mode 100644 index 000000000..2d3667726 --- /dev/null +++ b/shared-bindings/gamepadshift/__init__.c @@ -0,0 +1,54 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "shared-bindings/gamepadshift/GamePadShift.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/util.h" + +//| :mod:`gamepadshift` --- Tracks button presses read through a shift register +//| =========================================================================== +//| +//| .. module:: gamepadshift +//| :synopsis: Tracks button presses read through a shift register +//| :platform: SAMD21, SAMD51 +//| +//| .. toctree:: +//| :maxdepth: 3 +//| +//| GamePadShift +//| +STATIC const mp_rom_map_elem_t gamepadshift_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepadshift) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_GamePadShift), MP_ROM_PTR(&gamepadshift_type)}, +}; +STATIC MP_DEFINE_CONST_DICT(gamepadshift_module_globals, gamepadshift_module_globals_table); + +const mp_obj_module_t gamepadshift_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&gamepadshift_module_globals, +}; diff --git a/shared-bindings/gamepadshift/__init__.h b/shared-bindings/gamepadshift/__init__.h new file mode 100644 index 000000000..4b4be756a --- /dev/null +++ b/shared-bindings/gamepadshift/__init__.h @@ -0,0 +1,31 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPADSHIFT___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPADSHIFT___INIT___H + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPADSHIFT___INIT___H diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c index 23addb397..b3e3fabf6 100644 --- a/shared-module/gamepad/GamePad.c +++ b/shared-module/gamepad/GamePad.c @@ -24,10 +24,11 @@ * THE SOFTWARE. */ +#include "py/mpstate.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "GamePad.h" +#include "shared-bindings/gamepad/GamePad.h" -void gamepad_init(gamepad_obj_t *gamepad, +void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad, const mp_obj_t pins[], size_t n_pins) { for (size_t i = 0; i < 8; ++i) { gamepad->pins[i] = NULL; @@ -49,3 +50,7 @@ void gamepad_init(gamepad_obj_t *gamepad, gamepad->pins[i] = pin; } } + +void common_hal_gamepad_gamepad_deinit(gamepad_obj_t *self) { + MP_STATE_VM(gamepad_singleton) = NULL; +} diff --git a/shared-module/gamepad/GamePad.h b/shared-module/gamepad/GamePad.h index dc8a7e87a..e8bfd9c6b 100644 --- a/shared-module/gamepad/GamePad.h +++ b/shared-module/gamepad/GamePad.h @@ -36,10 +36,7 @@ typedef struct { digitalio_digitalinout_obj_t* pins[8]; volatile uint8_t pressed; uint8_t pulls; + volatile uint8_t last; } gamepad_obj_t; - -void gamepad_init(gamepad_obj_t *gamepad, - const mp_obj_t pins[], size_t n_pins); - #endif // MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H diff --git a/shared-module/gamepad/GamePadShift.c b/shared-module/gamepad/GamePadShift.c deleted file mode 100644 index 12083a86a..000000000 --- a/shared-module/gamepad/GamePadShift.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-bindings/digitalio/DigitalInOut.h" -#include "GamePadShift.h" - - -void gamepadshift_init(gamepadshift_obj_t *gamepadshift, - digitalio_digitalinout_obj_t *data_pin, - digitalio_digitalinout_obj_t *clock_pin, - digitalio_digitalinout_obj_t *latch_pin) { - common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); - gamepadshift->data_pin = data_pin; - common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, - DRIVE_MODE_PUSH_PULL); - gamepadshift->clock_pin = clock_pin; - common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1, - DRIVE_MODE_PUSH_PULL); - gamepadshift->latch_pin = latch_pin; -} diff --git a/shared-module/gamepad/GamePadShift.h b/shared-module/gamepad/GamePadShift.h deleted file mode 100644 index 05235f318..000000000 --- a/shared-module/gamepad/GamePadShift.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_GAMEPAD_GAMEPADSHIFT_H -#define MICROPY_INCLUDED_GAMEPAD_GAMEPADSHIFT_H - -#include - -#include "shared-bindings/digitalio/DigitalInOut.h" - -typedef struct { - mp_obj_base_t base; - digitalio_digitalinout_obj_t* data_pin; - digitalio_digitalinout_obj_t* clock_pin; - digitalio_digitalinout_obj_t* latch_pin; - volatile uint8_t pressed; -} gamepadshift_obj_t; - - -void gamepadshift_init(gamepadshift_obj_t *gamepadshift, - digitalio_digitalinout_obj_t *data_pin, - digitalio_digitalinout_obj_t *clock_pin, - digitalio_digitalinout_obj_t *latch_pin); - -#endif // MICROPY_INCLUDED_GAMEPAD_GAMEPADSHIFT_H diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index f92042d4b..8a4f4eae9 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -27,17 +27,17 @@ #include #include "py/mpstate.h" -#include "__init__.h" -#include "GamePad.h" -#include "GamePadShift.h" +#include "shared-bindings/gamepad/__init__.h" #include "shared-bindings/gamepad/GamePad.h" -#include "shared-bindings/gamepad/GamePadShift.h" + +#if CIRCUITPY_GAMEPADSHIFT +#include "shared-bindings/gamepadshift/GamePadShift.h" +#endif #include "shared-bindings/digitalio/DigitalInOut.h" void gamepad_tick(void) { - static uint8_t last = 0; uint8_t current = 0; uint8_t bit = 1; @@ -59,24 +59,15 @@ void gamepad_tick(void) { bit <<= 1; } current ^= self->pulls; - self->pressed |= last & current; - } else if (MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepadshift_type)) { + self->pressed |= self->last & current; + self->last = current; + } + #if CIRCUITPY_GAMEPADSHIFT + else if (MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepadshift_type)) { // buttons connected to a shift register - gamepadshift_obj_t *self = singleton; - - common_hal_digitalio_digitalinout_set_value(self->latch_pin, 1); - for (int i = 0; i < 8; ++i) { - common_hal_digitalio_digitalinout_set_value(self->clock_pin, 0); - if (common_hal_digitalio_digitalinout_get_value(self->data_pin)) { - current |= bit; - } - common_hal_digitalio_digitalinout_set_value(self->clock_pin, 1); - bit <<= 1; - } - common_hal_digitalio_digitalinout_set_value(self->latch_pin, 0); - self->pressed |= last & current; + gamepadshift_tick(singleton); } - last = current; + #endif } void gamepad_reset(void) { diff --git a/shared-module/gamepadshift/GamePadShift.c b/shared-module/gamepadshift/GamePadShift.c new file mode 100644 index 000000000..1dadfb9b2 --- /dev/null +++ b/shared-module/gamepadshift/GamePadShift.c @@ -0,0 +1,64 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/mpstate.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-module/gamepadshift/GamePadShift.h" + +void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift, + digitalio_digitalinout_obj_t *data_pin, + digitalio_digitalinout_obj_t *clock_pin, + digitalio_digitalinout_obj_t *latch_pin) { + common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); + gamepadshift->data_pin = data_pin; + common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, + DRIVE_MODE_PUSH_PULL); + gamepadshift->clock_pin = clock_pin; + common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1, + DRIVE_MODE_PUSH_PULL); + gamepadshift->latch_pin = latch_pin; +} + +void common_hal_gamepadshift_gamepadshift_deinit(gamepadshift_obj_t *gamepadshift) { + MP_STATE_VM(gamepad_singleton) = NULL; +} + +void gamepadshift_tick(gamepadshift_obj_t *self) { + uint8_t current = 0; + uint8_t bit = 1; + common_hal_digitalio_digitalinout_set_value(self->latch_pin, 1); + for (int i = 0; i < 8; ++i) { + common_hal_digitalio_digitalinout_set_value(self->clock_pin, 0); + if (common_hal_digitalio_digitalinout_get_value(self->data_pin)) { + current |= bit; + } + common_hal_digitalio_digitalinout_set_value(self->clock_pin, 1); + bit <<= 1; + } + common_hal_digitalio_digitalinout_set_value(self->latch_pin, 0); + self->pressed |= self->last & current; + self->last = current; +} diff --git a/shared-module/gamepadshift/GamePadShift.h b/shared-module/gamepadshift/GamePadShift.h new file mode 100644 index 000000000..ccbf5ca06 --- /dev/null +++ b/shared-module/gamepadshift/GamePadShift.h @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_GAMEPADSHIFT_GAMEPADSHIFT_H +#define MICROPY_INCLUDED_GAMEPADSHIFT_GAMEPADSHIFT_H + +#include + +#include "shared-bindings/digitalio/DigitalInOut.h" + +typedef struct { + mp_obj_base_t base; + digitalio_digitalinout_obj_t* data_pin; + digitalio_digitalinout_obj_t* clock_pin; + digitalio_digitalinout_obj_t* latch_pin; + volatile uint8_t pressed; + volatile uint8_t last; +} gamepadshift_obj_t; + +void gamepadshift_tick(gamepadshift_obj_t *self); + +#endif // MICROPY_INCLUDED_GAMEPADSHIFT_GAMEPADSHIFT_H diff --git a/shared-module/gamepadshift/__init__.c b/shared-module/gamepadshift/__init__.c new file mode 100644 index 000000000..c3bb83e34 --- /dev/null +++ b/shared-module/gamepadshift/__init__.c @@ -0,0 +1,27 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// Nothing now. -- cgit v1.2.3 From 9c42a72275993aa8f921c6ee0ea8e79882711def Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Tue, 16 Apr 2019 14:32:27 +1000 Subject: Fix up single-byte access to nvm.ByteArray --- ports/nrf/common-hal/nvm/ByteArray.h | 2 -- shared-bindings/nvm/ByteArray.c | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/nvm/ByteArray.h b/ports/nrf/common-hal/nvm/ByteArray.h index e47a87b9e..a8d09dd43 100644 --- a/ports/nrf/common-hal/nvm/ByteArray.h +++ b/ports/nrf/common-hal/nvm/ByteArray.h @@ -31,8 +31,6 @@ typedef struct { mp_obj_base_t base; - uint32_t start_address; - uint32_t len; } nvm_bytearray_obj_t; #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_NVM_BYTEARRAY_H diff --git a/shared-bindings/nvm/ByteArray.c b/shared-bindings/nvm/ByteArray.c index 22cd838b1..31bedeacc 100644 --- a/shared-bindings/nvm/ByteArray.c +++ b/shared-bindings/nvm/ByteArray.c @@ -124,7 +124,8 @@ STATIC mp_obj_t nvm_bytearray_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj #endif } else { // Single index rather than slice. - size_t index = mp_get_index(self->base.type, self->len, index_in, false); + size_t index = mp_get_index(self->base.type, common_hal_nvm_bytearray_get_length(self), + index_in, false); if (value == MP_OBJ_SENTINEL) { // load uint8_t value_out; -- cgit v1.2.3 From 0e03a321e4c4fba6c5d700bfef830c6196aec106 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 16 Apr 2019 10:11:54 -0700 Subject: Fully split gamepadshift from gamepad --- ports/atmel-samd/supervisor/port.c | 6 +++++ py/circuitpy_defns.mk | 7 +++--- py/circuitpy_mpconfig.h | 12 +++++++--- shared-bindings/digitalio/DigitalInOut.c | 11 +++++++++ shared-bindings/digitalio/DigitalInOut.h | 1 + shared-bindings/gamepad/__init__.c | 13 ----------- shared-bindings/gamepad/__init__.h | 4 ---- shared-bindings/gamepadshift/GamePadShift.c | 12 +++++----- shared-bindings/gamepadshift/GamePadShift.h | 2 +- shared-module/gamepad/__init__.c | 10 --------- shared-module/gamepadshift/GamePadShift.c | 19 +--------------- shared-module/gamepadshift/GamePadShift.h | 2 -- shared-module/gamepadshift/__init__.c | 35 ++++++++++++++++++++++++++++- shared-module/gamepadshift/__init__.h | 33 +++++++++++++++++++++++++++ 14 files changed, 105 insertions(+), 62 deletions(-) create mode 100644 shared-module/gamepadshift/__init__.h (limited to 'shared-bindings') diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index f8d830d8b..4f53d30f9 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -71,6 +71,9 @@ #if CIRCUITPY_GAMEPAD #include "shared-module/gamepad/__init__.h" #endif +#if CIRCUITPY_GAMEPADSHIFT +#include "shared-module/gamepadshift/__init__.h" +#endif #include "shared-module/_pew/PewPew.h" extern volatile bool mp_msc_enabled; @@ -229,6 +232,9 @@ void reset_port(void) { #if CIRCUITPY_GAMEPAD gamepad_reset(); #endif +#if CIRCUITPY_GAMEPADSHIFT + gamepadshift_reset(); +#endif #if CIRCUITPY_PEW pew_reset(); #endif diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index be7ff0b11..1aca33901 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -131,10 +131,9 @@ SRC_PATTERNS += frequencyio/% endif ifeq ($(CIRCUITPY_GAMEPAD),1) SRC_PATTERNS += gamepad/% - # gamepadshift depends on gamepad - ifeq ($(CIRCUITPY_GAMEPADSHIFT),1) - SRC_PATTERNS += gamepadshift/% - endif +endif +ifeq ($(CIRCUITPY_GAMEPADSHIFT),1) +SRC_PATTERNS += gamepadshift/% endif ifeq ($(CIRCUITPY_I2CSLAVE),1) SRC_PATTERNS += i2cslave/% diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 3952b5e06..a101aa527 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -315,8 +315,6 @@ extern const struct _mp_obj_module_t frequencyio_module; #if CIRCUITPY_GAMEPAD extern const struct _mp_obj_module_t gamepad_module; -// Scan gamepad every 32ms -#define CIRCUITPY_GAMEPAD_TICKS 0x1f #define GAMEPAD_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }, #else #define GAMEPAD_MODULE @@ -329,6 +327,14 @@ extern const struct _mp_obj_module_t gamepadshift_module; #define GAMEPADSHIFT_MODULE #endif +#if CIRCUITPY_GAMEPAD || CIRCUITPY_GAMEPADSHIFT +// Scan gamepad every 32ms +#define CIRCUITPY_GAMEPAD_TICKS 0x1f +#define GAMEPAD_ROOT_POINTERS mp_obj_t gamepad_singleton; +#else +#define GAMEPAD_ROOT_POINTERS +#endif + #if CIRCUITPY_I2CSLAVE extern const struct _mp_obj_module_t i2cslave_module; #define I2CSLAVE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_i2cslave), (mp_obj_t)&i2cslave_module }, @@ -612,7 +618,7 @@ extern const struct _mp_obj_module_t ustack_module; const char *readline_hist[8]; \ vstr_t *repl_line; \ mp_obj_t rtc_time_source; \ - mp_obj_t gamepad_singleton; \ + GAMEPAD_ROOT_POINTERS \ mp_obj_t pew_singleton; \ mp_obj_t terminal_tilegrid_tiles; \ BOARD_I2C_ROOT_POINTER \ diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index 2fcbefe11..1ced15137 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -374,3 +374,14 @@ const mp_obj_type_t digitalio_digitalinout_type = { .make_new = digitalio_digitalinout_make_new, .locals_dict = (mp_obj_t)&digitalio_digitalinout_locals_dict, }; + +// Helper for validating digitalio.DigitalInOut arguments +digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj) { + if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) { + mp_raise_TypeError(translate("argument num/types mismatch")); + } + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj); + raise_error_if_deinited( + common_hal_digitalio_digitalinout_deinited(pin)); + return pin; +} diff --git a/shared-bindings/digitalio/DigitalInOut.h b/shared-bindings/digitalio/DigitalInOut.h index 037979098..eee0d5801 100644 --- a/shared-bindings/digitalio/DigitalInOut.h +++ b/shared-bindings/digitalio/DigitalInOut.h @@ -53,5 +53,6 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitali void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t* self, digitalio_pull_t pull); digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t* self); void common_hal_digitalio_digitalinout_never_reset(digitalio_digitalinout_obj_t *self); +digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DIGITALINOUT_H diff --git a/shared-bindings/gamepad/__init__.c b/shared-bindings/gamepad/__init__.c index e61f36cc2..cea0b4ee9 100644 --- a/shared-bindings/gamepad/__init__.c +++ b/shared-bindings/gamepad/__init__.c @@ -29,19 +29,6 @@ #include "shared-bindings/gamepad/GamePad.h" #include "shared-bindings/util.h" - -// Helper for validating digitalio.DigitalInOut arguments -digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj) { - if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) { - mp_raise_TypeError(translate("argument num/types mismatch")); - } - digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj); - raise_error_if_deinited( - common_hal_digitalio_digitalinout_deinited(pin)); - return pin; -} - - //| :mod:`gamepad` --- Button handling //| ================================== //| diff --git a/shared-bindings/gamepad/__init__.h b/shared-bindings/gamepad/__init__.h index 40cf4e6de..2ae5efb3a 100644 --- a/shared-bindings/gamepad/__init__.h +++ b/shared-bindings/gamepad/__init__.h @@ -28,8 +28,4 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H #define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H -#include "shared-bindings/digitalio/DigitalInOut.h" - -digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj); - #endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H diff --git a/shared-bindings/gamepadshift/GamePadShift.c b/shared-bindings/gamepadshift/GamePadShift.c index 94b71036f..de3813b08 100644 --- a/shared-bindings/gamepadshift/GamePadShift.c +++ b/shared-bindings/gamepadshift/GamePadShift.c @@ -39,11 +39,11 @@ //| :class:`GamePadShift` -- Scan buttons for presses through a shift register //| =========================================================================== //| -//| .. class:: GamePadShift(data, clock, latch) +//| .. class:: GamePadShift(clock, data, latch) //| //| Initializes button scanning routines. //| -//| The ``data``, ``clock`` and ``latch`` parameters are ``DigitalInOut`` +//| The ``clock``, ``data`` and ``latch`` parameters are ``DigitalInOut`` //| objects connected to the shift register controlling the buttons. //| //| They button presses are accumulated, until the ``get_pressed`` method @@ -56,18 +56,18 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_data, ARG_clock, ARG_latch }; + enum { ARG_clock, ARG_data, ARG_latch }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ}, + { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_latch, MP_ARG_REQUIRED | MP_ARG_OBJ}, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - digitalio_digitalinout_obj_t *data_pin = assert_digitalinout(args[ARG_data].u_obj); digitalio_digitalinout_obj_t *clock_pin = assert_digitalinout(args[ARG_clock].u_obj); + digitalio_digitalinout_obj_t *data_pin = assert_digitalinout(args[ARG_data].u_obj); digitalio_digitalinout_obj_t *latch_pin = assert_digitalinout(args[ARG_latch].u_obj); gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); @@ -79,7 +79,7 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, gamepad_singleton = gc_make_long_lived(gamepad_singleton); MP_STATE_VM(gamepad_singleton) = gamepad_singleton; } - common_hal_gamepadshift_gamepadshift_init(gamepad_singleton, data_pin, clock_pin, latch_pin); + common_hal_gamepadshift_gamepadshift_init(gamepad_singleton, clock_pin, data_pin, latch_pin); return MP_OBJ_FROM_PTR(gamepad_singleton); } diff --git a/shared-bindings/gamepadshift/GamePadShift.h b/shared-bindings/gamepadshift/GamePadShift.h index 2668ec83f..3e8ea9693 100644 --- a/shared-bindings/gamepadshift/GamePadShift.h +++ b/shared-bindings/gamepadshift/GamePadShift.h @@ -33,8 +33,8 @@ extern const mp_obj_type_t gamepadshift_type; void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift, - digitalio_digitalinout_obj_t *data_pin, digitalio_digitalinout_obj_t *clock_pin, + digitalio_digitalinout_obj_t *data_pin, digitalio_digitalinout_obj_t *latch_pin); void common_hal_gamepadshift_gamepadshift_deinit(gamepadshift_obj_t *gamepadshift); diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index 8a4f4eae9..46630fd32 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -30,10 +30,6 @@ #include "shared-bindings/gamepad/__init__.h" #include "shared-bindings/gamepad/GamePad.h" -#if CIRCUITPY_GAMEPADSHIFT -#include "shared-bindings/gamepadshift/GamePadShift.h" -#endif - #include "shared-bindings/digitalio/DigitalInOut.h" @@ -62,12 +58,6 @@ void gamepad_tick(void) { self->pressed |= self->last & current; self->last = current; } - #if CIRCUITPY_GAMEPADSHIFT - else if (MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepadshift_type)) { - // buttons connected to a shift register - gamepadshift_tick(singleton); - } - #endif } void gamepad_reset(void) { diff --git a/shared-module/gamepadshift/GamePadShift.c b/shared-module/gamepadshift/GamePadShift.c index 1dadfb9b2..f9303938f 100644 --- a/shared-module/gamepadshift/GamePadShift.c +++ b/shared-module/gamepadshift/GamePadShift.c @@ -29,8 +29,8 @@ #include "shared-module/gamepadshift/GamePadShift.h" void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift, - digitalio_digitalinout_obj_t *data_pin, digitalio_digitalinout_obj_t *clock_pin, + digitalio_digitalinout_obj_t *data_pin, digitalio_digitalinout_obj_t *latch_pin) { common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE); gamepadshift->data_pin = data_pin; @@ -45,20 +45,3 @@ void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift, void common_hal_gamepadshift_gamepadshift_deinit(gamepadshift_obj_t *gamepadshift) { MP_STATE_VM(gamepad_singleton) = NULL; } - -void gamepadshift_tick(gamepadshift_obj_t *self) { - uint8_t current = 0; - uint8_t bit = 1; - common_hal_digitalio_digitalinout_set_value(self->latch_pin, 1); - for (int i = 0; i < 8; ++i) { - common_hal_digitalio_digitalinout_set_value(self->clock_pin, 0); - if (common_hal_digitalio_digitalinout_get_value(self->data_pin)) { - current |= bit; - } - common_hal_digitalio_digitalinout_set_value(self->clock_pin, 1); - bit <<= 1; - } - common_hal_digitalio_digitalinout_set_value(self->latch_pin, 0); - self->pressed |= self->last & current; - self->last = current; -} diff --git a/shared-module/gamepadshift/GamePadShift.h b/shared-module/gamepadshift/GamePadShift.h index ccbf5ca06..b4b26b7a9 100644 --- a/shared-module/gamepadshift/GamePadShift.h +++ b/shared-module/gamepadshift/GamePadShift.h @@ -40,6 +40,4 @@ typedef struct { volatile uint8_t last; } gamepadshift_obj_t; -void gamepadshift_tick(gamepadshift_obj_t *self); - #endif // MICROPY_INCLUDED_GAMEPADSHIFT_GAMEPADSHIFT_H diff --git a/shared-module/gamepadshift/__init__.c b/shared-module/gamepadshift/__init__.c index c3bb83e34..728c2187e 100644 --- a/shared-module/gamepadshift/__init__.c +++ b/shared-module/gamepadshift/__init__.c @@ -24,4 +24,37 @@ * THE SOFTWARE. */ -// Nothing now. +#include "shared-module/gamepadshift/__init__.h" + +#include "py/mpstate.h" +#include "shared-bindings/gamepadshift/GamePadShift.h" + +void gamepadshift_tick(void) { + void* singleton = MP_STATE_VM(gamepad_singleton); + if (!singleton) { + return; + } + + if (MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepadshift_type)) { + // buttons connected to a shift register + gamepadshift_obj_t *self = MP_OBJ_TO_PTR(singleton); + uint8_t current = 0; + uint8_t bit = 1; + common_hal_digitalio_digitalinout_set_value(self->latch_pin, 1); + for (int i = 0; i < 8; ++i) { + common_hal_digitalio_digitalinout_set_value(self->clock_pin, 0); + if (common_hal_digitalio_digitalinout_get_value(self->data_pin)) { + current |= bit; + } + common_hal_digitalio_digitalinout_set_value(self->clock_pin, 1); + bit <<= 1; + } + common_hal_digitalio_digitalinout_set_value(self->latch_pin, 0); + self->pressed |= self->last & current; + self->last = current; + } +} + +void gamepadshift_reset(void) { + MP_STATE_VM(gamepad_singleton) = NULL; +} diff --git a/shared-module/gamepadshift/__init__.h b/shared-module/gamepadshift/__init__.h new file mode 100644 index 000000000..225db7336 --- /dev/null +++ b/shared-module/gamepadshift/__init__.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_GAMEPADSHIFT___INIT___H +#define MICROPY_INCLUDED_GAMEPADSHIFT___INIT___H + +void gamepadshift_tick(void); +void gamepadshift_reset(void); + +#endif // MICROPY_INCLUDED_GAMEPADSHIFT___INIT___H -- cgit v1.2.3 From 6132a05fd9e6fa51972f1445ee051e99b816527f Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 16 Apr 2019 10:19:07 -0700 Subject: Include cleanup and style tweaks --- py/circuitpy_mpconfig.h | 2 +- shared-bindings/gamepad/GamePad.c | 7 +++---- shared-bindings/gamepadshift/GamePadShift.c | 2 -- shared-module/gamepad/GamePad.h | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) (limited to 'shared-bindings') diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index a101aa527..f957886f4 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -567,7 +567,7 @@ extern const struct _mp_obj_module_t ustack_module; ERRNO_MODULE \ FREQUENCYIO_MODULE \ GAMEPAD_MODULE \ - GAMEPADSHIFT_MODULE \ + GAMEPADSHIFT_MODULE \ I2CSLAVE_MODULE \ JSON_MODULE \ MATH_MODULE \ diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index c80aa7f7c..c342cbbf9 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -23,17 +23,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "shared-bindings/gamepad/GamePad.h" + #include "py/obj.h" #include "py/runtime.h" #include "py/mphal.h" #include "py/gc.h" #include "py/mpstate.h" -#include "shared-module/gamepad/__init__.h" -#include "shared-module/gamepad/GamePad.h" +#include "shared-bindings/gamepad/__init__.h" #include "shared-bindings/digitalio/DigitalInOut.h" #include "supervisor/shared/translate.h" -#include "GamePad.h" -#include "__init__.h" //| .. currentmodule:: gamepad diff --git a/shared-bindings/gamepadshift/GamePadShift.c b/shared-bindings/gamepadshift/GamePadShift.c index de3813b08..d6f365388 100644 --- a/shared-bindings/gamepadshift/GamePadShift.c +++ b/shared-bindings/gamepadshift/GamePadShift.c @@ -28,10 +28,8 @@ #include "py/mphal.h" #include "py/gc.h" #include "py/mpstate.h" -#include "shared-bindings/gamepad/__init__.h" #include "shared-bindings/gamepadshift/GamePadShift.h" #include "shared-bindings/gamepadshift/__init__.h" -#include "shared-module/gamepadshift/GamePadShift.h" #include "supervisor/shared/translate.h" //| .. currentmodule:: gamepadshift diff --git a/shared-module/gamepad/GamePad.h b/shared-module/gamepad/GamePad.h index e8bfd9c6b..048fbcd2b 100644 --- a/shared-module/gamepad/GamePad.h +++ b/shared-module/gamepad/GamePad.h @@ -34,9 +34,9 @@ typedef struct { mp_obj_base_t base; digitalio_digitalinout_obj_t* pins[8]; + volatile uint8_t last; volatile uint8_t pressed; uint8_t pulls; - volatile uint8_t last; } gamepad_obj_t; #endif // MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H -- cgit v1.2.3 From e46bf7e7c6fc8939ec3a49c9656ca78e843142de Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 17 Apr 2019 11:18:30 +0200 Subject: Update GamePad docs to include pull-downs --- shared-bindings/gamepad/GamePad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index 4458c972f..f7506b6bd 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -78,7 +78,8 @@ //| Initializes button scanning routines. //| //| The ``b1``-``b8`` parameters are ``DigitalInOut`` objects, which -//| immediately get switched to input with a pull-up, and then scanned +//| immediately get switched to input with a pull-up, (unless they already +//| were set to pull-down, in which case they remain so), and then scanned //| regularly for button presses. The order is the same as the order of //| bits returned by the ``get_pressed`` function. You can re-initialize //| it with different keys, then the new object will replace the previous -- cgit v1.2.3 From 3a65ff970aa6628ab6f5eb05523777d298bdee0c Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 17 Apr 2019 10:27:08 +0200 Subject: Allow use of displayio.Display subclasses in _stage --- shared-bindings/_stage/__init__.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index dc9dbef65..03775b1de 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -83,10 +83,12 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { uint16_t *buffer = bufinfo.buf; size_t buffer_size = bufinfo.len / 2; // 16-bit indexing - if (!MP_OBJ_IS_TYPE(args[6], &displayio_display_type)) { + mp_obj_t native_display = mp_instance_cast_to_native_base(args[6], + &displayio_display_type); + if (!MP_OBJ_IS_TYPE(native_display, &displayio_display_type)) { mp_raise_TypeError(translate("argument num/types mismatch")); } - displayio_display_obj_t *display = MP_OBJ_TO_PTR(args[6]); + displayio_display_obj_t *display = MP_OBJ_TO_PTR(native_display); while (!displayio_display_begin_transaction(display)) { #ifdef MICROPY_VM_HOOK_LOOP -- cgit v1.2.3 From 4fc0f8b25c53d5eb05cd2b4e124c22d999fc506a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 18 Apr 2019 13:57:27 -0400 Subject: Turn off auto_brightness if brightness is set --- shared-bindings/displayio/Display.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 17f275bc0..071b9441f 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -209,8 +209,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_wait_for_frame_obj, displayio_displa //| .. attribute:: brightness //| //| The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When -//| `auto_brightness` is True this value will change automatically and setting it will have no -//| effect. To control the brightness, auto_brightness must be false. +//| `auto_brightness` is True, the value of `brightness` will change automatically. +//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False. //| STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) { displayio_display_obj_t *self = native_display(self_in); @@ -224,6 +224,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_brightness_obj, displayio_displa STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness) { displayio_display_obj_t *self = native_display(self_in); + common_hal_displayio_display_set_auto_brightness(self, false); bool ok = common_hal_displayio_display_set_brightness(self, mp_obj_get_float(brightness)); if (!ok) { mp_raise_RuntimeError(translate("Brightness not adjustable")); @@ -241,7 +242,10 @@ const mp_obj_property_t displayio_display_brightness_obj = { //| .. attribute:: auto_brightness //| -//| True when the display brightness is auto adjusted. +//| True when the display brightness is adjusted automatically, based on an ambient +//| light sensor or other method. Note that some displays may have this set to True by default, +//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False +//| if `brightness` is set manually. //| STATIC mp_obj_t displayio_display_obj_get_auto_brightness(mp_obj_t self_in) { displayio_display_obj_t *self = native_display(self_in); -- cgit v1.2.3 From 0113e0970eb7d4b753982692d33754d38694efb7 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 18 Apr 2019 15:59:16 -0400 Subject: add Display.__init__() args for brightness and auto_brightness --- .../atmel-samd/boards/hallowing_m0_express/board.c | 3 +- ports/atmel-samd/boards/pybadge/board.c | 3 +- ports/atmel-samd/boards/pyportal/board.c | 4 +-- ports/atmel-samd/boards/ugame10/board.c | 2 ++ shared-bindings/displayio/Display.c | 32 +++++++++++++++------- shared-bindings/displayio/Display.h | 5 ++-- shared-module/displayio/Display.c | 8 ++++-- 7 files changed, 39 insertions(+), 18 deletions(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 94775cd94..6e0328e95 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -98,9 +98,10 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, + 1.0f, // brightness (ignored) + true, // auto_brightness false, // single_byte_bounds false); // data_as_commands - common_hal_displayio_display_set_auto_brightness(display, true); } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 9d16ae12f..d559ba7fc 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -100,9 +100,10 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, + 1.0f, // brightness (ignored) + true, // auto_brightness false, // single_byte_bounds false); // data_as_commands - common_hal_displayio_display_set_auto_brightness(display, true); } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 222e11144..bb80c5b48 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -90,10 +90,10 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PB31, + 1.0f, // brightness (ignored) + true, // auto_brightness false, // single_byte_bounds false); // data_as_commands - - common_hal_displayio_display_set_auto_brightness(display, true); } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index a4f6bb175..38f63570a 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -98,6 +98,8 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), NULL, + 1.0f, // brightness + false, // auto_brightness false, // single_byte_bounds false); // data as commands } diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 071b9441f..52ab2ef31 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -50,7 +50,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, single_byte_bounds=False, data_as_commands=False) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -91,11 +91,13 @@ //| :param int write_ram_command: Command used to write pixels values into the update region //| :param int set_vertical_scroll: Command used to set the first row to show //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight +//| :param bool brightness: Initial display brightness. This value is ignored if auto_brightness is True. +//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism. //| :param bool single_byte_bounds: Display column and row commands use single bytes //| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this. //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_single_byte_bounds, ARG_data_as_commands }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -110,6 +112,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + { MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, + { MP_QSTR_auto_brightness, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_data_as_commands, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; @@ -128,6 +132,9 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a backlight_pin = MP_OBJ_TO_PTR(backlight_pin_obj); assert_pin_free(backlight_pin); } + + mp_float_t brightness = mp_obj_get_float(args[ARG_brightness].u_obj); + mp_int_t rotation = args[ARG_rotation].u_int; if (rotation % 90 != 0) { mp_raise_ValueError(translate("Display rotation must be in 90 degree increments")); @@ -145,14 +152,19 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a mp_raise_RuntimeError(translate("Too many displays")); } self->base.type = &displayio_display_type; - common_hal_displayio_display_construct(self, - display_bus, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation, - args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, - args[ARG_write_ram_command].u_int, - args[ARG_set_vertical_scroll].u_int, - bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin), - args[ARG_single_byte_bounds].u_bool, - args[ARG_data_as_commands].u_bool); + common_hal_displayio_display_construct( + self, + display_bus, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation, + args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, + args[ARG_write_ram_command].u_int, + args[ARG_set_vertical_scroll].u_int, + bufinfo.buf, bufinfo.len, + MP_OBJ_TO_PTR(backlight_pin), + brightness, + args[ARG_auto_brightness].u_bool, + args[ARG_single_byte_bounds].u_bool, + args[ARG_data_as_commands].u_bool + ); return self; } diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 3b855195d..3136ae88a 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -40,8 +40,9 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, - uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds, - bool data_as_commands); + uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, + mp_float_t brightness, bool auto_brightness, + bool single_byte_bounds, bool data_as_commands); int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 28df062f8..3b1613974 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -44,7 +44,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, - const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds, bool data_as_commands) { + const mcu_pin_obj_t* backlight_pin, mp_float_t brightness, bool auto_brightness, + bool single_byte_bounds, bool data_as_commands) { self->color_depth = color_depth; self->set_column_command = set_column_command; self->set_row_command = set_row_command; @@ -53,7 +54,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->current_group = NULL; self->colstart = colstart; self->rowstart = rowstart; - self->auto_brightness = false; + self->auto_brightness = auto_brightness; self->data_as_commands = data_as_commands; self->single_byte_bounds = single_byte_bounds; @@ -142,6 +143,9 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, } else { self->backlight_pwm.base.type = &pulseio_pwmout_type; common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm); + if (!self->auto_brightness) { + common_hal_displayio_display_set_brightness(self, brightness); + } } } } -- cgit v1.2.3 From 58d1d997013c717d5b6e17d53aa44eb5940c202a Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Tue, 16 Apr 2019 17:57:05 +1000 Subject: Fix socket.recv() buffer length from e23bad3a --- shared-bindings/socket/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c index c59724efc..8e34c3700 100644 --- a/shared-bindings/socket/__init__.c +++ b/shared-bindings/socket/__init__.c @@ -248,7 +248,7 @@ STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_ if (ret == -1) { mp_raise_OSError(_errno); } - return len; + return ret; } -- cgit v1.2.3 From baa9c02c8b1737bf31319b58d623ca970829af24 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Thu, 2 May 2019 15:42:10 +1000 Subject: Add a kw-only argument "dhcp" to wiznet5k object --- shared-bindings/wiznet/wiznet5k.c | 32 ++++++++++++++++++++++++-------- shared-module/wiznet/wiznet5k.c | 11 +++++------ shared-module/wiznet/wiznet5k.h | 6 +++--- 3 files changed, 32 insertions(+), 17 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index 6d43e8992..b8b7ea8a0 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -41,6 +41,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/digitalio/DriveMode.h" #include "shared-bindings/busio/SPI.h" +#include "shared-bindings/microcontroller/Pin.h" #include "shared-module/network/__init__.h" #include "shared-module/wiznet/wiznet5k.h" @@ -56,14 +57,27 @@ //| //| :param spi: spi bus to use //| :param cs: pin to use for Chip Select -//| :param rst: pin to sue for Reset +//| :param rst: pin to use for Reset //| -STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - // check arguments - mp_arg_check_num(n_args, kw_args, 3, 3, false); - - return wiznet5k_create(args[0], args[1], args[2]); +STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_spi, ARG_cs, ARG_rst, ARG_dhcp }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_spi, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_cs, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_rst, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_dhcp, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = true } }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + // XXX check type of ARG_spi? + // XXX should ARG_rst be optional? + assert_pin(args[ARG_cs].u_obj, false); + assert_pin(args[ARG_rst].u_obj, false); + + mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, args[ARG_cs].u_obj, args[ARG_rst].u_obj); + if (args[ARG_dhcp].u_bool) wiznet5k_start_dhcp(); + return ret; } //| .. attribute:: connected @@ -99,9 +113,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_dhcp_get_value_obj, wiznet5k_dhcp_get_ STATIC mp_obj_t wiznet5k_dhcp_set_value(mp_obj_t self_in, mp_obj_t value) { (void)self_in; if (mp_obj_is_true(value)) { - wiznet5k_start_dhcp(); + int ret = wiznet5k_start_dhcp(); + if (ret) mp_raise_OSError(ret); } else { - wiznet5k_stop_dhcp(); + int ret = wiznet5k_stop_dhcp(); + if (ret) mp_raise_OSError(ret); } return mp_const_none; } diff --git a/shared-module/wiznet/wiznet5k.c b/shared-module/wiznet/wiznet5k.c index 660df90b7..237f67887 100644 --- a/shared-module/wiznet/wiznet5k.c +++ b/shared-module/wiznet/wiznet5k.c @@ -328,27 +328,29 @@ void wiznet5k_socket_timer_tick(mod_network_socket_obj_t *socket) { } } -void wiznet5k_start_dhcp(void) { +int wiznet5k_start_dhcp(void) { // XXX this should throw an error if DHCP fails static DHCP_INIT_BUFFER_TYPE dhcp_buf[DHCP_INIT_BUFFER_SIZE]; if (wiznet5k_obj.dhcp_socket < 0) { // Set up the socket to listen on UDP 68 before calling DHCP_init wiznet5k_obj.dhcp_socket = get_available_socket(&wiznet5k_obj); - if (wiznet5k_obj.dhcp_socket < 0) return; + if (wiznet5k_obj.dhcp_socket < 0) return MP_EMFILE; WIZCHIP_EXPORT(socket)(wiznet5k_obj.dhcp_socket, MOD_NETWORK_SOCK_DGRAM, DHCP_CLIENT_PORT, 0); DHCP_init(wiznet5k_obj.dhcp_socket, dhcp_buf); } + return 0; } -void wiznet5k_stop_dhcp(void) { +int wiznet5k_stop_dhcp(void) { if (wiznet5k_obj.dhcp_socket >= 0) { DHCP_stop(); WIZCHIP_EXPORT(close)(wiznet5k_obj.dhcp_socket); wiznet5k_obj.socket_used &= ~(1 << wiznet5k_obj.dhcp_socket); wiznet5k_obj.dhcp_socket = -1; } + return 0; } bool wiznet5k_check_dhcp(void) { @@ -403,9 +405,6 @@ mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) { // seems we need a small delay after init mp_hal_delay_ms(250); - // dhcp is started by default - wiznet5k_start_dhcp(); - // register with network module network_module_register_nic(&wiznet5k_obj); diff --git a/shared-module/wiznet/wiznet5k.h b/shared-module/wiznet/wiznet5k.h index 09f83df66..2cfb17a20 100644 --- a/shared-module/wiznet/wiznet5k.h +++ b/shared-module/wiznet/wiznet5k.h @@ -39,7 +39,7 @@ typedef struct _wiznet5k_obj_t { digitalio_digitalinout_obj_t cs; digitalio_digitalinout_obj_t rst; uint8_t socket_used; - int8_t dhcp_socket; + int8_t dhcp_socket; // -1 for DHCP not in use } wiznet5k_obj_t; int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *out_ip); @@ -60,8 +60,8 @@ void wiznet5k_socket_timer_tick(mod_network_socket_obj_t *socket); mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in); mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in); -void wiznet5k_start_dhcp(void); -void wiznet5k_stop_dhcp(void); +int wiznet5k_start_dhcp(void); +int wiznet5k_stop_dhcp(void); bool wiznet5k_check_dhcp(void); extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k; -- cgit v1.2.3 From d97c81b0c999c77b64319e6eca4bcb346c2f9f29 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Thu, 2 May 2019 19:14:22 +1000 Subject: Update docs to include new 'dhcp' constructor parameter --- shared-bindings/wiznet/wiznet5k.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index b8b7ea8a0..826783771 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -51,13 +51,14 @@ //| :class:`WIZNET5K` -- wrapper for Wiznet 5500 Ethernet interface //| =============================================================== //| -//| .. class:: WIZNET5K(spi, cs, rst) +//| .. class:: WIZNET5K(spi, cs, rst, dhcp=True) //| //| Create a new WIZNET5500 interface using the specified pins //| -//| :param spi: spi bus to use -//| :param cs: pin to use for Chip Select -//| :param rst: pin to use for Reset +//| :param ~busio.SPI spi: spi bus to use +//| :param ~microcontroller.Pin cs: pin to use for Chip Select +//| :param ~microcontroller.Pin rst: pin to use for Reset +//| :param bool dhcp: boolean flag, whether to start DHCP automatically (default True) //| STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { -- cgit v1.2.3 From 264fc2b07041a55aaf607c1839914acf056b1513 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Tue, 7 May 2019 18:41:53 +1000 Subject: Make wiznet5k RST pin optional adafruit/circuitpython#1800 --- shared-bindings/wiznet/wiznet5k.c | 5 ++--- shared-module/wiznet/wiznet5k.c | 16 +++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index 826783771..b8382162f 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -66,15 +66,14 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, cons static const mp_arg_t allowed_args[] = { { MP_QSTR_spi, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_cs, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_rst, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_rst, MP_ARG_OBJ, { .u_obj = mp_const_none } }, { MP_QSTR_dhcp, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = true } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); // XXX check type of ARG_spi? - // XXX should ARG_rst be optional? assert_pin(args[ARG_cs].u_obj, false); - assert_pin(args[ARG_rst].u_obj, false); + assert_pin(args[ARG_rst].u_obj, true); // may be NULL mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, args[ARG_cs].u_obj, args[ARG_rst].u_obj); if (args[ARG_dhcp].u_bool) wiznet5k_start_dhcp(); diff --git a/shared-module/wiznet/wiznet5k.c b/shared-module/wiznet/wiznet5k.c index 237f67887..847a13484 100644 --- a/shared-module/wiznet/wiznet5k.c +++ b/shared-module/wiznet/wiznet5k.c @@ -364,8 +364,6 @@ mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) { wiznet5k_obj.base.type = (mp_obj_type_t*)&mod_network_nic_type_wiznet5k; wiznet5k_obj.cris_state = 0; wiznet5k_obj.spi = MP_OBJ_TO_PTR(spi_in); - common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.cs, cs_in); - common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in); wiznet5k_obj.socket_used = 0; wiznet5k_obj.dhcp_socket = -1; @@ -380,13 +378,17 @@ mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) { 8 // 8 BITS ); + common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.cs, cs_in); common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.cs, 1, DRIVE_MODE_PUSH_PULL); - common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.rst, 1, DRIVE_MODE_PUSH_PULL); - common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 0); - mp_hal_delay_us(10); // datasheet says 2us - common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 1); - mp_hal_delay_ms(160); // datasheet says 150ms + if (rst_in) { + common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in); + common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.rst, 1, DRIVE_MODE_PUSH_PULL); + common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 0); + mp_hal_delay_us(10); // datasheet says 2us + common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 1); + mp_hal_delay_ms(160); // datasheet says 150ms + } reg_wizchip_cris_cbfunc(wiz_cris_enter, wiz_cris_exit); reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect); -- cgit v1.2.3 From 832f07a6e94a35ec733be706ecdba9f80c8ff726 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Tue, 7 May 2019 21:48:44 +1000 Subject: Update docs for wiznet5k adafruit/circuitpython#1800 --- shared-bindings/wiznet/wiznet5k.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index b8382162f..c83a29fbc 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -57,8 +57,14 @@ //| //| :param ~busio.SPI spi: spi bus to use //| :param ~microcontroller.Pin cs: pin to use for Chip Select -//| :param ~microcontroller.Pin rst: pin to use for Reset -//| :param bool dhcp: boolean flag, whether to start DHCP automatically (default True) +//| :param ~microcontroller.Pin rst: pin to use for Reset (optional) +//| :param bool dhcp: boolean flag, whether to start DHCP automatically (optional, keyword only, default True) +//| +//| * The reset pin is optional: if supplied it is used to reset the +//| wiznet board before initialization. +//| * The SPI bus will be initialized appropriately by this library. +//| * At present, the WIZNET5K object is a singleton, so only one WizNet +//| interface is supported at a time. //| STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -82,7 +88,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, cons //| .. attribute:: connected //| -//| is this device physically connected? +//| (boolean, readonly) is this device physically connected? //| STATIC mp_obj_t wiznet5k_connected_get_value(mp_obj_t self_in) { @@ -100,7 +106,9 @@ const mp_obj_property_t wiznet5k_connected_obj = { //| .. attribute:: dhcp //| -//| is DHCP active on this device? (set to true to activate DHCP, false to turn it off) +//| (boolean, readwrite) is DHCP active on this device? +//| +//| * set to True to activate DHCP, False to turn it off //| STATIC mp_obj_t wiznet5k_dhcp_get_value(mp_obj_t self_in) { @@ -152,6 +160,7 @@ STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { return mp_obj_new_tuple(4, tuple); } else { // set + // XXX should this automatically stop DHCP here? mp_obj_t *items; mp_obj_get_array_fixed_n(args[1], 4, &items); netutils_parse_ipv4_addr(items[0], netinfo.ip, NETUTILS_BIG); -- cgit v1.2.3 From e00a702ce9df8109e15e5268ee3fb41df2902681 Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Fri, 10 May 2019 09:20:57 +1000 Subject: Stop DHCP when configuring IP address adafruit/circuitpython#1800 --- shared-bindings/wiznet/wiznet5k.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index c83a29fbc..c32f876f0 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -77,7 +77,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, cons }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - // XXX check type of ARG_spi? + // TODO check type of ARG_spi? assert_pin(args[ARG_cs].u_obj, false); assert_pin(args[ARG_rst].u_obj, true); // may be NULL @@ -144,6 +144,7 @@ const mp_obj_property_t wiznet5k_dhcp_obj = { //| (ip_address, subnet_mask, gateway_address, dns_server) //| //| Or can be called with the same tuple to set those parameters. +//| Setting ifconfig parameters turns DHCP off, if it was on. //| STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { @@ -160,7 +161,7 @@ STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { return mp_obj_new_tuple(4, tuple); } else { // set - // XXX should this automatically stop DHCP here? + wiznet5k_stop_dhcp(); mp_obj_t *items; mp_obj_get_array_fixed_n(args[1], 4, &items); netutils_parse_ipv4_addr(items[0], netinfo.ip, NETUTILS_BIG); -- cgit v1.2.3 From af0bba062275cd06577018e276ebe6c5ee0428ce Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Fri, 10 May 2019 13:55:45 +1000 Subject: reset wiznet at network deinitialize adafruit/circuitpython#1800 --- shared-bindings/wiznet/wiznet5k.c | 1 + shared-module/network/__init__.c | 5 +++++ shared-module/network/__init__.h | 1 + shared-module/wiznet/wiznet5k.c | 27 +++++++++++++++++++-------- shared-module/wiznet/wiznet5k.h | 1 + 5 files changed, 27 insertions(+), 8 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index c32f876f0..878095b2a 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -204,6 +204,7 @@ const mod_network_nic_type_t mod_network_nic_type_wiznet5k = { .settimeout = wiznet5k_socket_settimeout, .ioctl = wiznet5k_socket_ioctl, .timer_tick = wiznet5k_socket_timer_tick, + .deinit = wiznet5k_socket_deinit, }; #endif // MICROPY_PY_WIZNET5K diff --git a/shared-module/network/__init__.c b/shared-module/network/__init__.c index c5783758d..bf33fef7a 100644 --- a/shared-module/network/__init__.c +++ b/shared-module/network/__init__.c @@ -43,6 +43,11 @@ void network_module_init(void) { } void network_module_deinit(void) { + for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) { + mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i]; + mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic); + if (nic_type->deinit != NULL) nic_type->deinit(nic); + } mp_obj_list_set_len(&MP_STATE_PORT(mod_network_nic_list), 0); } diff --git a/shared-module/network/__init__.h b/shared-module/network/__init__.h index 00a3c3957..504065979 100644 --- a/shared-module/network/__init__.h +++ b/shared-module/network/__init__.h @@ -62,6 +62,7 @@ typedef struct _mod_network_nic_type_t { int (*settimeout)(struct _mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno); int (*ioctl)(struct _mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno); void (*timer_tick)(struct _mod_network_socket_obj_t *socket); + void (*deinit)(struct _mod_network_socket_obj_t *socket); } mod_network_nic_type_t; typedef struct _mod_network_socket_obj_t { diff --git a/shared-module/wiznet/wiznet5k.c b/shared-module/wiznet/wiznet5k.c index 847a13484..dbd483451 100644 --- a/shared-module/wiznet/wiznet5k.c +++ b/shared-module/wiznet/wiznet5k.c @@ -357,6 +357,23 @@ bool wiznet5k_check_dhcp(void) { return wiznet5k_obj.dhcp_socket >= 0; } +void wiznet5k_reset(void) { + if (wiznet5k_obj.rst.pin) { + // hardware reset if using RST pin + common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 0); + mp_hal_delay_us(10); // datasheet says 2us + common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 1); + mp_hal_delay_ms(150); // datasheet says 150ms + } else { + // otherwise, software reset + wizchip_sw_reset(); + } +} + +void wiznet5k_socket_deinit(mod_network_socket_obj_t *socket) { + wiznet5k_reset(); +} + /// Create and return a WIZNET5K object. mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) { @@ -381,14 +398,8 @@ mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) { common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.cs, cs_in); common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.cs, 1, DRIVE_MODE_PUSH_PULL); - if (rst_in) { - common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in); - common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.rst, 1, DRIVE_MODE_PUSH_PULL); - common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 0); - mp_hal_delay_us(10); // datasheet says 2us - common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 1); - mp_hal_delay_ms(160); // datasheet says 150ms - } + if (rst_in) common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in); + wiznet5k_reset(); reg_wizchip_cris_cbfunc(wiz_cris_enter, wiz_cris_exit); reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect); diff --git a/shared-module/wiznet/wiznet5k.h b/shared-module/wiznet/wiznet5k.h index 2cfb17a20..0154831c7 100644 --- a/shared-module/wiznet/wiznet5k.h +++ b/shared-module/wiznet/wiznet5k.h @@ -57,6 +57,7 @@ int wiznet5k_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno); int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno); void wiznet5k_socket_timer_tick(mod_network_socket_obj_t *socket); +void wiznet5k_socket_deinit(mod_network_socket_obj_t *socket); mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in); mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in); -- cgit v1.2.3 From 214dfed703e81770b3a74df09ce13d8f86fa7211 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Fri, 10 May 2019 16:41:13 -0500 Subject: Add documentation for Palette shared binding Add documentation for the palette subscript operator and how to use it. --- shared-bindings/displayio/Palette.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 799d42bef..55692eae1 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -66,7 +66,17 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a return MP_OBJ_FROM_PTR(self); } - +//| .. method:: __setitem__(index, value) +//| +//| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1 +//| +//| The color can be from 0x000000 to 0xFFFFFF, and can be an int or bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)) +//| +//| This allows you to:: +//| +//| palette[0] = 0xFFFFFF +//| palette[1] = 0xFF0000 +//| STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { if (value == MP_OBJ_NULL) { // delete item -- cgit v1.2.3 From ad211b23be17ed058ca686644d5e2323a005d0a4 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Fri, 10 May 2019 17:35:51 -0500 Subject: add documentation of transparency --- shared-bindings/displayio/Palette.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 55692eae1..90fd9bf52 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -68,14 +68,16 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a } //| .. method:: __setitem__(index, value) //| -//| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1 +//| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1. //| -//| The color can be from 0x000000 to 0xFFFFFF, and can be an int or bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)) +//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value), +//| or None to represent transparency. Value can be an int or bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)). //| //| This allows you to:: //| //| palette[0] = 0xFFFFFF //| palette[1] = 0xFF0000 +//| palette[2] = None # transparency //| STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { if (value == MP_OBJ_NULL) { -- cgit v1.2.3 From f29de5132562cd6e88661d150fa1ee3ab8b771e1 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 13 May 2019 17:31:30 -0700 Subject: Check native object in case of early access If a native displayio object is accessed before it's super().__init__() has been called, then a placeholder is given that will cause a crash if accessed. This is tricky to get right so we detect this case and raise a NotInplementedError instead of crashing. Fixes #1881 --- py/objtype.c | 10 ++++++++++ py/objtype.h | 2 ++ shared-bindings/_stage/__init__.c | 1 + shared-bindings/displayio/Display.c | 8 +++----- shared-bindings/displayio/Group.c | 7 ++++++- shared-bindings/displayio/Group.h | 1 + shared-bindings/displayio/TileGrid.c | 2 ++ shared-bindings/socket/__init__.c | 13 +++++++------ 8 files changed, 32 insertions(+), 12 deletions(-) (limited to 'shared-bindings') diff --git a/py/objtype.c b/py/objtype.c index 88e918827..5133d849f 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -117,6 +117,16 @@ mp_obj_instance_t *mp_obj_new_instance(const mp_obj_type_t *class, const mp_obj_ return o; } +// When instances are first created they have the base_init wrapper as their native parent's +// instance because make_new combines __new__ and __init__. This object is invalid for the native +// code so it must call this method to ensure that the given object has been __init__'d and is +// valid. +void mp_obj_assert_native_inited(mp_obj_t native_object) { + if (native_object == MP_OBJ_FROM_PTR(&native_base_init_wrapper_obj)) { + mp_raise_NotImplementedError(translate("Call super().__init__() before accessing native object.")); + } +} + // TODO // This implements depth-first left-to-right MRO, which is not compliant with Python3 MRO // http://python-history.blogspot.com/2010/06/method-resolution-order.html diff --git a/py/objtype.h b/py/objtype.h index 13613f01f..a32c87496 100644 --- a/py/objtype.h +++ b/py/objtype.h @@ -37,6 +37,8 @@ typedef struct _mp_obj_instance_t { // TODO maybe cache __getattr__ and __setattr__ for efficient lookup of them } mp_obj_instance_t; +void mp_obj_assert_native_inited(mp_obj_t native_object); + #if MICROPY_CPYTHON_COMPAT // this is needed for object.__new__ mp_obj_instance_t *mp_obj_new_instance(const mp_obj_type_t *cls, const mp_obj_type_t **native_base); diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 03775b1de..be8315efe 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -85,6 +85,7 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { mp_obj_t native_display = mp_instance_cast_to_native_base(args[6], &displayio_display_type); + mp_obj_assert_native_inited(native_display); if (!MP_OBJ_IS_TYPE(native_display, &displayio_display_type)) { mp_raise_TypeError(translate("argument num/types mismatch")); } diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 52ab2ef31..84302a175 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -31,6 +31,7 @@ #include "lib/utils/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" +#include "py/objtype.h" #include "py/runtime.h" #include "shared-bindings/displayio/Group.h" #include "shared-bindings/microcontroller/Pin.h" @@ -172,6 +173,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a // Helper to ensure we have the native super class instead of a subclass. static displayio_display_obj_t* native_display(mp_obj_t display_obj) { mp_obj_t native_display = mp_instance_cast_to_native_base(display_obj, &displayio_display_type); + mp_obj_assert_native_inited(native_display); return MP_OBJ_TO_PTR(native_display); } @@ -184,11 +186,7 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) displayio_display_obj_t *self = native_display(self_in); displayio_group_t* group = NULL; if (group_in != mp_const_none) { - mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type); - if (native_layer == MP_OBJ_NULL) { - mp_raise_ValueError(translate("Must be a Group subclass.")); - } - group = MP_OBJ_TO_PTR(native_layer); + group = MP_OBJ_TO_PTR(native_group(group_in)); } common_hal_displayio_display_show(self, group); diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index c7a72891a..bbf7190a3 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -31,6 +31,7 @@ #include "lib/utils/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" +#include "py/objtype.h" #include "py/runtime.h" #include "supervisor/shared/translate.h" @@ -80,8 +81,12 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg } // Helper to ensure we have the native super class instead of a subclass. -static displayio_group_t* native_group(mp_obj_t group_obj) { +displayio_group_t* native_group(mp_obj_t group_obj) { mp_obj_t native_group = mp_instance_cast_to_native_base(group_obj, &displayio_group_type); + if (native_group == MP_OBJ_NULL) { + mp_raise_ValueError_varg(translate("Must be a %q subclass."), MP_QSTR_Group); + } + mp_obj_assert_native_inited(native_group); return MP_OBJ_TO_PTR(native_group); } diff --git a/shared-bindings/displayio/Group.h b/shared-bindings/displayio/Group.h index fa3c32964..0570735cf 100644 --- a/shared-bindings/displayio/Group.h +++ b/shared-bindings/displayio/Group.h @@ -31,6 +31,7 @@ extern const mp_obj_type_t displayio_group_type; +displayio_group_t* native_group(mp_obj_t group_obj); void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self); diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 2b41eb8fd..6d18ac78f 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -31,6 +31,7 @@ #include "lib/utils/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" +#include "py/objtype.h" #include "py/runtime.h" #include "shared-bindings/displayio/Bitmap.h" #include "shared-bindings/displayio/ColorConverter.h" @@ -139,6 +140,7 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_ // Helper to ensure we have the native super class instead of a subclass. static displayio_tilegrid_t* native_tilegrid(mp_obj_t tilegrid_obj) { mp_obj_t native_tilegrid = mp_instance_cast_to_native_base(tilegrid_obj, &displayio_tilegrid_type); + mp_obj_assert_native_inited(native_tilegrid); return MP_OBJ_TO_PTR(native_tilegrid); } diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c index 8e34c3700..085d4e690 100644 --- a/shared-bindings/socket/__init__.c +++ b/shared-bindings/socket/__init__.c @@ -257,7 +257,7 @@ STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_ //| Reads some bytes from the connected remote address, writing //| into the provided buffer. If bufsize <= len(buffer) is given, //| a maximum of bufsize bytes will be read into the buffer. If no -//| valid value is given for bufsize, the default is the length of +//| valid value is given for bufsize, the default is the length of //| the given buffer. //| //| Suits sockets of type SOCK_STREAM @@ -274,13 +274,14 @@ STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) { } mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); - mp_int_t len; + mp_int_t len = bufinfo.len; if (n_args == 3) { - len = mp_obj_get_int(args[2]); - } - if (n_args == 2 || (size_t) len > bufinfo.len) { - len = bufinfo.len; + mp_int_t given_len = mp_obj_get_int(args[2]); + if (given_len < len) { + len = given_len; + } } + mp_int_t ret = _socket_recv_into(self, (byte*)bufinfo.buf, len); return mp_obj_new_int_from_uint(ret); } -- cgit v1.2.3 From 0b1c1c1d929352c9995bcb1e58e90309d89b9d38 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 14 May 2019 08:03:34 -0500 Subject: Update Palette.c Remove None, add in byte and bytearray examples --- shared-bindings/displayio/Palette.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 90fd9bf52..11c2f677c 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -70,14 +70,15 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a //| //| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1. //| -//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value), -//| or None to represent transparency. Value can be an int or bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)). +//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value). +//| Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), or bytearray. //| //| This allows you to:: //| -//| palette[0] = 0xFFFFFF -//| palette[1] = 0xFF0000 -//| palette[2] = None # transparency +//| palette[0] = 0xFFFFFF # set using an integer +//| palette[1] = b'\xff\xff\x00' # set using 3 bytes +//| palette[2] = b'\xff\xff\x00\x00' # set using 4 bytes +//| palette[3] = bytearray(b'\x00\x00\xFF') # set using a bytearay of 3 or 4 bytes //| STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { if (value == MP_OBJ_NULL) { -- cgit v1.2.3 From bf682d14b33a3bc6b1934391017bcfbcad782e41 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 14 May 2019 10:20:04 -0700 Subject: Remove native init check from stage. It isn't needed because the object is passed in, not self. To be passed in it must be inited. --- shared-bindings/_stage/__init__.c | 1 - 1 file changed, 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index be8315efe..03775b1de 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -85,7 +85,6 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { mp_obj_t native_display = mp_instance_cast_to_native_base(args[6], &displayio_display_type); - mp_obj_assert_native_inited(native_display); if (!MP_OBJ_IS_TYPE(native_display, &displayio_display_type)) { mp_raise_TypeError(translate("argument num/types mismatch")); } -- cgit v1.2.3 From b7b55e0c0a0187f4d248d9b52cd972af5d928336 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 14 May 2019 15:15:23 -0700 Subject: Make Group iterable via a generic native iterator. Fixes #1694 --- py/obj.c | 30 ++++++++++++++++++++++++++++++ py/obj.h | 4 ++++ shared-bindings/displayio/Group.c | 1 + 3 files changed, 35 insertions(+) (limited to 'shared-bindings') diff --git a/py/obj.c b/py/obj.c index fb59eec82..322a302f9 100644 --- a/py/obj.c +++ b/py/obj.c @@ -531,6 +531,36 @@ mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf) { return self; } +typedef struct { + mp_obj_base_t base; + mp_fun_1_t iternext; + mp_obj_t obj; + mp_int_t cur; +} mp_obj_generic_it_t; + +STATIC mp_obj_t generic_it_iternext(mp_obj_t self_in) { + mp_obj_generic_it_t *self = MP_OBJ_TO_PTR(self_in); + mp_obj_type_t *type = mp_obj_get_type(self->obj); + mp_obj_t current_length = type->unary_op(MP_UNARY_OP_LEN, self->obj); + if (self->cur < MP_OBJ_SMALL_INT_VALUE(current_length)) { + mp_obj_t o_out = type->subscr(self->obj, MP_OBJ_NEW_SMALL_INT(self->cur), MP_OBJ_SENTINEL); + self->cur += 1; + return o_out; + } else { + return MP_OBJ_STOP_ITERATION; + } +} + +mp_obj_t mp_obj_new_generic_iterator(mp_obj_t obj, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(mp_obj_generic_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_generic_it_t *o = (mp_obj_generic_it_t*)iter_buf; + o->base.type = &mp_type_polymorph_iter; + o->iternext = generic_it_iternext; + o->obj = obj; + o->cur = 0; + return MP_OBJ_FROM_PTR(o); +} + bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) { mp_obj_type_t *type = mp_obj_get_type(obj); if (type->buffer_p.get_buffer == NULL) { diff --git a/py/obj.h b/py/obj.h index ae2bff190..773043b59 100644 --- a/py/obj.h +++ b/py/obj.h @@ -819,6 +819,10 @@ mp_obj_t mp_identity(mp_obj_t self); MP_DECLARE_CONST_FUN_OBJ_1(mp_identity_obj); mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf); +// Generic iterator that uses unary op and subscr to iterate over a native type. It will be slower +// than a custom iterator but applies broadly. +mp_obj_t mp_obj_new_generic_iterator(mp_obj_t self, mp_obj_iter_buf_t *iter_buf); + // module typedef struct _mp_obj_module_t { mp_obj_base_t base; diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index bbf7190a3..46f67e3e8 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -291,5 +291,6 @@ const mp_obj_type_t displayio_group_type = { .make_new = displayio_group_make_new, .subscr = group_subscr, .unary_op = group_unary_op, + .getiter = mp_obj_new_generic_iterator, .locals_dict = (mp_obj_dict_t*)&displayio_group_locals_dict, }; -- cgit v1.2.3 From 5608e273a01d0c39d2f82c695eec860288afa4a8 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 15 May 2019 11:33:16 -0700 Subject: Add index and remove to Group. --- shared-bindings/displayio/Group.c | 31 +++++++++++++++++++++++++++++++ shared-bindings/displayio/Group.h | 1 + shared-module/displayio/Group.c | 10 ++++++++++ 3 files changed, 42 insertions(+) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 46f67e3e8..76719c580 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -195,6 +195,21 @@ STATIC mp_obj_t displayio_group_obj_insert(mp_obj_t self_in, mp_obj_t index_obj, } MP_DEFINE_CONST_FUN_OBJ_3(displayio_group_insert_obj, displayio_group_obj_insert); + +//| .. method:: index(layer) +//| +//| Returns the index of the first copy of layer. Raises ValueError if not found. +//| +STATIC mp_obj_t displayio_group_obj_index(mp_obj_t self_in, mp_obj_t layer) { + displayio_group_t *self = native_group(self_in); + mp_int_t index = common_hal_displayio_group_index(self, layer); + if (index < 0) { + mp_raise_ValueError(translate("object not in sequence")); + } + return MP_OBJ_NEW_SMALL_INT(index); +} +MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_index_obj, displayio_group_obj_index); + //| .. method:: pop(i=-1) //| //| Remove the ith item and return it. @@ -217,6 +232,20 @@ STATIC mp_obj_t displayio_group_obj_pop(size_t n_args, const mp_obj_t *pos_args, } MP_DEFINE_CONST_FUN_OBJ_KW(displayio_group_pop_obj, 1, displayio_group_obj_pop); + +//| .. method:: remove(layer) +//| +//| Remove the first copy of layer. Raises ValueError if it is not present. +//| +STATIC mp_obj_t displayio_group_obj_remove(mp_obj_t self_in, mp_obj_t layer) { + mp_obj_t index = displayio_group_obj_index(self_in, layer); + displayio_group_t *self = native_group(self_in); + + common_hal_displayio_group_pop(self, MP_OBJ_SMALL_INT_VALUE(index)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_remove_obj, displayio_group_obj_remove); + //| .. method:: __len__() //| //| Returns the number of layers in a Group @@ -281,7 +310,9 @@ STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&displayio_group_y_obj) }, { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&displayio_group_append_obj) }, { MP_ROM_QSTR(MP_QSTR_insert), MP_ROM_PTR(&displayio_group_insert_obj) }, + { MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&displayio_group_index_obj) }, { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&displayio_group_pop_obj) }, + { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&displayio_group_remove_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_group_locals_dict, displayio_group_locals_dict_table); diff --git a/shared-bindings/displayio/Group.h b/shared-bindings/displayio/Group.h index 0570735cf..dc9616f2e 100644 --- a/shared-bindings/displayio/Group.h +++ b/shared-bindings/displayio/Group.h @@ -44,6 +44,7 @@ void common_hal_displayio_group_append(displayio_group_t* self, mp_obj_t layer); void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp_obj_t layer); size_t common_hal_displayio_group_get_len(displayio_group_t* self); mp_obj_t common_hal_displayio_group_pop(displayio_group_t* self, size_t index); +mp_int_t common_hal_displayio_group_index(displayio_group_t* self, mp_obj_t layer); mp_obj_t common_hal_displayio_group_get(displayio_group_t* self, size_t index); void common_hal_displayio_group_set(displayio_group_t* self, size_t index, mp_obj_t layer); diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index 097edf33b..e2045a5da 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -95,6 +95,16 @@ mp_obj_t common_hal_displayio_group_pop(displayio_group_t* self, size_t index) { return item; } +mp_int_t common_hal_displayio_group_index(displayio_group_t* self, mp_obj_t layer) { + // Shift everything left. + for (size_t i = 0; i < self->size; i++) { + if (self->children[i].original == layer) { + return i; + } + } + return -1; +} + size_t common_hal_displayio_group_get_len(displayio_group_t* self) { return self->size; } -- cgit v1.2.3 From ee8119779e22c21fe7771a054e4cf6ee921b4352 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 17 May 2019 15:47:12 -0400 Subject: WIP --- shared-bindings/bleio/ScanEntry.c | 7 ++----- shared-bindings/bleio/Scanner.c | 23 ++++++++--------------- shared-bindings/bleio/Scanner.h | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index e6b955078..67e4a38c0 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -37,9 +37,6 @@ #include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/ScanEntry.h" -// Work-in-progress: orphaned for now. -//| :orphan: -//| //| .. currentmodule:: bleio //| //| :class:`ScanEntry` -- BLE scan response entry @@ -63,7 +60,7 @@ //| .. attribute:: name //| //| The name of the device. (read-only) -//| This attribute might be `None` if the data was missing from the advertisement packet. +//| Will be be `None` if the data was missing from the advertisement packet. //| //| .. attribute:: raw_data @@ -87,7 +84,7 @@ //| .. attribute:: tx_power_level //| //| The transmit power level of the device. (read-only) -//| This attribute might be `None` if the data was missing from the advertisement packet. +//| Will be `None` if the data was missing from the advertisement packet. //| static uint8_t find_data_item(mp_obj_array_t *data_in, uint8_t type, uint8_t **data_out) { uint16_t i = 0; diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index f5424f706..73b6e6a0b 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -32,9 +33,6 @@ #define DEFAULT_INTERVAL 100 #define DEFAULT_WINDOW 100 -// Work-in-progress: orphaned for now. -//| :orphan: -//| //| .. currentmodule:: bleio //| //| :class:`Scanner` -- scan for nearby BLE devices @@ -46,7 +44,7 @@ //| //| import bleio //| scanner = bleio.Scanner() -//| entries = scanner.scan(2500) +//| entries = scanner.scan(2.5) # Scan for 2.5 seconds //| print(entries) //| @@ -57,33 +55,28 @@ //| .. attribute:: interval //| -//| The interval (in ms) between the start of two consecutive scan windows. -//| Allowed values are between 10ms and 10.24 sec. +//| The interval (in seconds) between the start of two consecutive scan windows. +//| Allowed values are between 0.010 and 10.24 sec. //| //| .. attribute:: window //| -//| The duration (in ms) in which a single BLE channel is scanned. -//| Allowed values are between 10ms and 10.24 sec. +//| The duration (in seconds) in which a single BLE channel is scanned. +//| Allowed values are between 0.010 and 10.24 sec. //| //| .. method:: scan(timeout) //| //| Performs a BLE scan. //| -//| :param int timeout: the scan timeout in ms +//| :param float timeout: the scan timeout in seconds //| :returns: advertising packets found //| :rtype: list of :py:class:`bleio.ScanEntry` //| -STATIC void bleio_scanner_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - - mp_printf(print, "Scanner(interval: %d window: %d)", self->interval, self->window); -} - STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) { mp_arg_check_num(n_args, kw_args, 0, 0, false); + bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t); self->base.type = type; diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index 9bd071747..c72136389 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy -- cgit v1.2.3 From 3fad7de8db7f1f317ab6d00a00a82e406ec6fb33 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 16 May 2019 16:45:38 -0700 Subject: Rework the pixel computation to use areas This changes the displayio pixel computation from per-pixel to per-area. This is precursor work to updating portions of the screen (#1169). It should provide mild speedups because bounds checks are done once per area rather than once per pixel. Filling by area also allows TileGrid to maintain a row-associative fill pattern even when the display's refresh is orthogonal to it. --- ports/atmel-samd/Makefile | 1 - shared-bindings/displayio/Display.h | 1 + shared-module/displayio/Group.c | 32 +++-- shared-module/displayio/Group.h | 3 +- shared-module/displayio/TileGrid.c | 149 ++++++++++++++++++------ shared-module/displayio/TileGrid.h | 8 +- shared-module/displayio/__init__.c | 225 +++++++++++++++++++++++------------- shared-module/displayio/__init__.h | 6 +- shared-module/displayio/area.h | 57 +++++++++ supervisor/shared/display.c | 14 ++- tools/gen_display_resources.py | 10 +- 11 files changed, 353 insertions(+), 153 deletions(-) create mode 100644 shared-module/displayio/area.h (limited to 'shared-bindings') diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 9b110c1bb..3a8ad4acc 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -99,7 +99,6 @@ endif #Debugging/Optimization ifeq ($(DEBUG), 1) - # Turn on Python modules useful for debugging (e.g. uheap, ustack). CFLAGS += -ggdb # You may want to disable -flto if it interferes with debugging. CFLAGS += -flto diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 3136ae88a..6695da32b 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -53,6 +53,7 @@ void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self); bool displayio_display_begin_transaction(displayio_display_obj_t* self); void displayio_display_end_transaction(displayio_display_obj_t* self); +// The second point of the region is exclusive. void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); bool displayio_display_frame_queued(displayio_display_obj_t* self); diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index 40f112bf1..c9be47f9a 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -134,32 +134,28 @@ void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* self->scale = scale; } -bool displayio_group_get_pixel(displayio_group_t *self, int16_t x, int16_t y, uint16_t* pixel) { - x -= self->x; - y -= self->y; - // When we are scaled we need to substract all but one to ensure -scale to 0 divide down to -1. - // Normally -scale to scale both divide down to 0 because 0 is unsigned. - if (x < 0) { - x -= self->scale - 1; - } - if (y < 0) { - y -= self->scale - 1; - } - x /= self->scale; - y /= self->scale; +bool displayio_group_get_area(displayio_group_t *self, displayio_buffer_transform_t* transform, displayio_area_t* area, uint32_t* mask, uint32_t* buffer) { + displayio_area_shift(area, -self->x * transform->scale, -self->y * transform->scale); + transform->scale *= self->scale; + + bool full_coverage = false; for (int32_t i = self->size - 1; i >= 0 ; i--) { mp_obj_t layer = self->children[i].native; if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { - if (displayio_tilegrid_get_pixel(layer, x, y, pixel)) { - return true; + if (displayio_tilegrid_get_area(layer, transform, area, mask, buffer)) { + full_coverage = true; + break; } } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { - if (displayio_group_get_pixel(layer, x, y, pixel)) { - return true; + if (displayio_group_get_area(layer, transform, area, mask, buffer)) { + full_coverage = true; + break; } } } - return false; + transform->scale /= self->scale; + displayio_area_shift(area, self->x * transform->scale, self->y * transform->scale); + return full_coverage; } bool displayio_group_needs_refresh(displayio_group_t *self) { diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h index 7826b9e66..f8fe9be04 100644 --- a/shared-module/displayio/Group.h +++ b/shared-module/displayio/Group.h @@ -31,6 +31,7 @@ #include #include "py/obj.h" +#include "shared-module/displayio/area.h" typedef struct { mp_obj_t native; @@ -49,7 +50,7 @@ typedef struct { } displayio_group_t; void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); -bool displayio_group_get_pixel(displayio_group_t *group, int16_t x, int16_t y, uint16_t *pixel); +bool displayio_group_get_area(displayio_group_t *group, displayio_buffer_transform_t* transform, displayio_area_t* area, uint32_t* mask, uint32_t *buffer); bool displayio_group_needs_refresh(displayio_group_t *self); void displayio_group_finish_refresh(displayio_group_t *self); diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 3212dfe8b..6ffc65889 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -56,31 +56,40 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_ self->bitmap_width_in_tiles = bitmap_width_in_tiles; self->width_in_tiles = width; self->height_in_tiles = height; - self->total_width = width * tile_width; - self->total_height = height * tile_height; + self->area.x1 = x; + self->area.y1 = y; + // -1 because areas are inclusive + self->area.x2 = x + width * tile_width - 1; + self->area.y2 = y + height * tile_height - 1; self->tile_width = tile_width; self->tile_height = tile_height; self->bitmap = bitmap; self->pixel_shader = pixel_shader; - self->x = x; - self->y = y; } mp_int_t common_hal_displayio_tilegrid_get_x(displayio_tilegrid_t *self) { - return self->x; + return self->area.x1; } void common_hal_displayio_tilegrid_set_x(displayio_tilegrid_t *self, mp_int_t x) { - self->needs_refresh = self->x != x; - self->x = x; + if (self->area.x1 == x) { + return; + } + self->needs_refresh = true; + self->area.x2 += (self->area.x1 - x); + self->area.x1 = x; } mp_int_t common_hal_displayio_tilegrid_get_y(displayio_tilegrid_t *self) { - return self->y; + return self->area.y1; } void common_hal_displayio_tilegrid_set_y(displayio_tilegrid_t *self, mp_int_t y) { - self->needs_refresh = self->y != y; - self->y = y; + if (self->area.y1 == y) { + return; + } + self->needs_refresh = true; + self->area.y2 += (self->area.y1 - y); + self->area.y1 = y; } mp_obj_t common_hal_displayio_tilegrid_get_pixel_shader(displayio_tilegrid_t *self) { @@ -128,14 +137,11 @@ void common_hal_displayio_tilegrid_set_tile(displayio_tilegrid_t *self, uint16_t void common_hal_displayio_tilegrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y) { self->top_left_x = x; self->top_left_y = y; + self->needs_refresh = true; } -bool displayio_tilegrid_get_pixel(displayio_tilegrid_t *self, int16_t x, int16_t y, uint16_t* pixel) { - x -= self->x; - y -= self->y; - if (y < 0 || y >= self->total_height || x >= self->total_width || x < 0) { - return false; - } +bool displayio_tilegrid_get_area(displayio_tilegrid_t *self, displayio_buffer_transform_t* transform, displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { + // If no tiles are present we have no impact. uint8_t* tiles = self->tiles; if (self->inline_tiles) { tiles = (uint8_t*) &self->tiles; @@ -143,30 +149,103 @@ bool displayio_tilegrid_get_pixel(displayio_tilegrid_t *self, int16_t x, int16_t if (tiles == NULL) { return false; } - uint16_t tile_location = ((y / self->tile_height + self->top_left_y) % self->height_in_tiles) * self->width_in_tiles + (x / self->tile_width + self->top_left_x) % self->width_in_tiles; - uint8_t tile = tiles[tile_location]; - uint16_t tile_x = tile_x = (tile % self->bitmap_width_in_tiles) * self->tile_width + x % self->tile_width; - uint16_t tile_y = tile_y = (tile / self->bitmap_width_in_tiles) * self->tile_height + y % self->tile_height; - uint32_t value = 0; - if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_bitmap_type)) { - value = common_hal_displayio_bitmap_get_pixel(self->bitmap, tile_x, tile_y); - } else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_shape_type)) { - value = common_hal_displayio_shape_get_pixel(self->bitmap, tile_x, tile_y); - } else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_ondiskbitmap_type)) { - value = common_hal_displayio_ondiskbitmap_get_pixel(self->bitmap, tile_x, tile_y); + displayio_area_t overlap; + displayio_area_t scaled_area = { + .x1 = self->area.x1 * transform->scale, + .y1 = self->area.y1 * transform->scale, + .x2 = (self->area.x2 + 1) * transform->scale - 1, // Second point is inclusive. + .y2 = (self->area.y2 + 1) * transform->scale - 1 + }; + if (!displayio_area_compute_overlap(area, &scaled_area, &overlap)) { + return false; } - if (self->pixel_shader == mp_const_none) { - *pixel = value; - return true; - } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type) && displayio_palette_get_color(self->pixel_shader, value, pixel)) { - return true; - } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type) && common_hal_displayio_colorconverter_convert(self->pixel_shader, value, pixel)) { - return true; + int16_t x_stride = 1; + int16_t y_stride = displayio_area_width(area); + if (transform->transpose_xy) { + x_stride = displayio_area_height(area); + y_stride = 1; + } + uint16_t start = 0; + if (transform->mirror_x) { + start += (area->x2 - area->x1) * x_stride; + x_stride *= -1; + } + if (transform->mirror_y) { + start += (area->y2 - area->y1) * y_stride; + y_stride *= -1; } - return false; + bool full_coverage = displayio_area_equal(area, &overlap); + + // TODO(tannewt): Set full coverage to true if all pixels outside the overlap have already been + // set as well. + bool always_full_coverage = false; + + // TODO(tannewt): Check to see if the pixel_shader has any transparency. If it doesn't then we + // can either return full coverage or bulk update the mask. + int16_t y = overlap.y1 - scaled_area.y1; + if (y < 0) { + y = 0; + } + int16_t x_shift = area->x1 - scaled_area.x1; + int16_t y_shift = area->y1 - scaled_area.y1; + for (; y <= overlap.y2 - scaled_area.y1; y++) { + int16_t x = overlap.x1 - scaled_area.x1; + if (x < 0) { + x = 0; + } + int16_t row_start = start + (y - y_shift) * y_stride; + int16_t local_y = y / transform->scale; + for (; x <= overlap.x2 - scaled_area.x1; x++) { + // Compute the destination pixel in the buffer and mask based on the transformations. + uint16_t offset = row_start + (x - x_shift) * x_stride; + + // Check the mask first to see if the pixel has already been set. + if ((mask[offset / 32] & (1 << (offset % 32))) != 0) { + continue; + } + int16_t local_x = x / transform->scale; + uint16_t tile_location = ((local_y / self->tile_height + self->top_left_y) % self->height_in_tiles) * self->width_in_tiles + (local_x / self->tile_width + self->top_left_x) % self->width_in_tiles; + uint8_t tile = tiles[tile_location]; + uint16_t tile_x = (tile % self->bitmap_width_in_tiles) * self->tile_width + local_x % self->tile_width; + uint16_t tile_y = (tile / self->bitmap_width_in_tiles) * self->tile_height + local_y % self->tile_height; + + uint32_t value = 0; + // We always want to read bitmap pixels by row first and then transpose into the destination + // buffer because most bitmaps are row associated. + if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_bitmap_type)) { + value = common_hal_displayio_bitmap_get_pixel(self->bitmap, tile_x, tile_y); + } else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_shape_type)) { + value = common_hal_displayio_shape_get_pixel(self->bitmap, tile_x, tile_y); + } else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_ondiskbitmap_type)) { + value = common_hal_displayio_ondiskbitmap_get_pixel(self->bitmap, tile_x, tile_y); + } + + uint16_t* pixel = ((uint16_t*) buffer) + offset; + if (self->pixel_shader == mp_const_none) { + *pixel = value; + return true; + } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type)) { + if (!displayio_palette_get_color(self->pixel_shader, value, pixel)) { + // mark the pixel as transparent + full_coverage = false; + } else if (!always_full_coverage) { + mask[offset / 32] |= 1 << (offset % 32); + } + } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type)) { + if (!common_hal_displayio_colorconverter_convert(self->pixel_shader, value, pixel)) { + // mark the pixel as transparent + full_coverage = false; + } else if (!always_full_coverage) { + mask[offset / 32] |= 1 << (offset % 32); + } + } + } + } + + return full_coverage; } bool displayio_tilegrid_needs_refresh(displayio_tilegrid_t *self) { diff --git a/shared-module/displayio/TileGrid.h b/shared-module/displayio/TileGrid.h index 59645553d..6157dfbe8 100644 --- a/shared-module/displayio/TileGrid.h +++ b/shared-module/displayio/TileGrid.h @@ -31,18 +31,16 @@ #include #include "py/obj.h" +#include "shared-module/displayio/area.h" typedef struct { mp_obj_base_t base; mp_obj_t bitmap; mp_obj_t pixel_shader; - uint16_t x; - uint16_t y; + displayio_area_t area; uint16_t bitmap_width_in_tiles; uint16_t width_in_tiles; uint16_t height_in_tiles; - uint16_t total_width; - uint16_t total_height; uint16_t tile_width; uint16_t tile_height; uint16_t top_left_x; @@ -52,7 +50,7 @@ typedef struct { bool inline_tiles; } displayio_tilegrid_t; -bool displayio_tilegrid_get_pixel(displayio_tilegrid_t *self, int16_t x, int16_t y, uint16_t *pixel); +bool displayio_tilegrid_get_area(displayio_tilegrid_t *self, displayio_buffer_transform_t* transform, displayio_area_t* area, uint32_t* mask, uint32_t *buffer); bool displayio_tilegrid_needs_refresh(displayio_tilegrid_t *self); void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self); diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 156640440..e816fefda 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -10,6 +10,7 @@ #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/Group.h" #include "shared-bindings/displayio/Palette.h" +#include "shared-module/displayio/area.h" #include "supervisor/shared/autoreload.h" #include "supervisor/shared/display.h" #include "supervisor/memory.h" @@ -17,8 +18,8 @@ primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT]; -static inline void swap(uint16_t* a, uint16_t* b) { - uint16_t temp = *a; +static inline void swap(int16_t* a, int16_t* b) { + int16_t temp = *a; *a = *b; *b = temp; } @@ -56,102 +57,112 @@ void displayio_refresh_displays(void) { continue; } if (displayio_display_refresh_queued(display)) { - // We compute the pixels. r and c are row and column to match the display memory - // structure. x and y match location within the groups. - uint16_t c0 = 0; - uint16_t r0 = 0; - uint16_t c1 = display->width; - uint16_t r1 = display->height; - if (display->transpose_xy) { - swap(&c1, &r1); - } - if (!displayio_display_begin_transaction(display)) { // Can't acquire display bus; skip updating this display. Try next display. continue; } - displayio_display_set_region_to_update(display, c0, r0, c1, r1); displayio_display_end_transaction(display); - uint16_t x0 = 0; - uint16_t x1 = display->width - 1; - uint16_t startx = 0; - int8_t dx = 1; - if (display->mirror_x) { - dx = -1; - startx = x1; - } - uint16_t y0 = 0; - uint16_t y1 = display->height - 1; - uint16_t starty = 0; - int8_t dy = 1; - if (display->mirror_y) { - dy = -1; - starty = y1; - } - - bool transpose = false; + displayio_area_t whole_screen = { + .x1 = 0, + .y1 = 0, + .x2 = display->width - 1, + .y2 = display->height - 1 + }; if (display->transpose_xy) { - transpose = true; - int8_t temp_dx = dx; - dx = dy; - dy = temp_dx; - - swap(&starty, &startx); - swap(&x0, &y0); - swap(&x1, &y1); + swap(&whole_screen.x2, &whole_screen.y2); } - size_t index = 0; - uint16_t buffer_size = 256; + uint16_t buffer_size = 512; + + uint16_t subrectangles = 1; + uint16_t rows_per_buffer = displayio_area_height(&whole_screen); + if (displayio_area_size(&whole_screen) > buffer_size) { + rows_per_buffer = buffer_size / displayio_area_width(&whole_screen); + subrectangles = displayio_area_height(&whole_screen) / rows_per_buffer; + buffer_size = rows_per_buffer * displayio_area_width(&whole_screen); + } uint32_t buffer[buffer_size / 2]; - bool skip_this_display = false; - - for (uint16_t y = starty; y0 <= y && y <= y1; y += dy) { - for (uint16_t x = startx; x0 <= x && x <= x1; x += dx) { - uint16_t* pixel = &(((uint16_t*)buffer)[index]); - *pixel = 0; - - if (display->current_group != NULL) { - if (transpose) { - displayio_group_get_pixel(display->current_group, y, x, pixel); - } else { - displayio_group_get_pixel(display->current_group, x, y, pixel); - } - } - index += 1; - // The buffer is full, send it. - if (index >= buffer_size) { - if (!displayio_display_begin_transaction(display)) { - // Can't acquire display bus; skip the rest of the data. Try next display. - index = 0; - skip_this_display = true; - break; + for (uint16_t j = 0; j < subrectangles; j++) { + displayio_area_t subrectangle = { + .x1 = 0, + .y1 = rows_per_buffer * j, + .x2 = displayio_area_width(&whole_screen) - 1, + .y2 = rows_per_buffer * (j + 1) - 1 + }; + + displayio_display_begin_transaction(display); + displayio_display_set_region_to_update(display, subrectangle.x1, subrectangle.y1, + subrectangle.x2 + 1, subrectangle.y2 + 1); + displayio_display_end_transaction(display); + + // Handle display mirroring and transpose. + displayio_area_t transformed_subrectangle; + displayio_buffer_transform_t transform; + if (display->mirror_x) { + uint16_t width = displayio_area_width(&whole_screen); + transformed_subrectangle.x1 = width - subrectangle.x2 - 1; + transformed_subrectangle.x2 = width - subrectangle.x1 - 1; + } else { + transformed_subrectangle.x1 = subrectangle.x1; + transformed_subrectangle.x2 = subrectangle.x2; + } + if (display->mirror_y != display->transpose_xy) { + uint16_t height = displayio_area_height(&whole_screen); + transformed_subrectangle.y1 = height - subrectangle.y2 - 1; + transformed_subrectangle.y2 = height - subrectangle.y1 - 1; + } else { + transformed_subrectangle.y1 = subrectangle.y1; + transformed_subrectangle.y2 = subrectangle.y2; + } + transform.width = transformed_subrectangle.x2 - transformed_subrectangle.x1 + 1; + transform.height = transformed_subrectangle.y2 - transformed_subrectangle.y1 + 1; + if (display->transpose_xy) { + int16_t y1 = transformed_subrectangle.y1; + int16_t y2 = transformed_subrectangle.y2; + transformed_subrectangle.y1 = transformed_subrectangle.x1; + transformed_subrectangle.y2 = transformed_subrectangle.x2; + transformed_subrectangle.x1 = y1; + transformed_subrectangle.x2 = y2; + } + transform.transpose_xy = display->transpose_xy; + transform.mirror_x = display->mirror_x; + transform.mirror_y = display->mirror_y; + transform.scale = 1; + + uint32_t mask[(buffer_size / 32) + 1]; + for (uint16_t k = 0; k < (buffer_size / 32) + 1; k++) { + mask[k] = 0x00000000; + } + bool full_coverage = displayio_group_get_area(display->current_group, &transform, &transformed_subrectangle, mask, buffer); + if (!full_coverage) { + uint32_t index = 0; + uint32_t current_mask = 0; + for (int16_t y = subrectangle.y1; y <= subrectangle.y2; y++) { + for (int16_t x = subrectangle.x1; x <= subrectangle.x2; x++) { + if (index % 32 == 0) { + current_mask = mask[index / 32]; + } + if ((current_mask & (1 << (index % 32))) == 0) { + ((uint16_t*) buffer)[index] = 0x0000; + } + index++; } - displayio_display_send_pixels(display, buffer, buffer_size / 2); - displayio_display_end_transaction(display); - // TODO(tannewt): Make refresh displays faster so we don't starve other - // background tasks. - usb_background(); - index = 0; } } - } - if (skip_this_display) { - // Go on to next display. - continue; - } - // Send the remaining data. - if (index) { if (!displayio_display_begin_transaction(display)) { - // Can't get display bus. Skip the rest of the data. Try next display. - continue; + // Can't acquire display bus; skip the rest of the data. Try next display. + break; } - displayio_display_send_pixels(display, buffer, index * 2); + displayio_display_send_pixels(display, buffer, buffer_size / 2); + displayio_display_end_transaction(display); + + // TODO(tannewt): Make refresh displays faster so we don't starve other + // background tasks. + usb_background(); } - displayio_display_end_transaction(display); } displayio_display_finish_refresh(display); } @@ -220,3 +231,57 @@ void reset_displays(void) { } #endif } + +void displayio_area_shift(displayio_area_t* area, int16_t dx, int16_t dy) { + area->x1 += dx; + area->y1 += dy; + area->x2 += dx; + area->y2 += dy; +} + +bool displayio_area_compute_overlap(const displayio_area_t* a, + const displayio_area_t* b, + displayio_area_t* overlap) { + overlap->x1 = a->x1; + if (b->x1 > overlap->x1) { + overlap->x1 = b->x1; + } + overlap->x2 = a->x2; + if (b->x2 < overlap->x2) { + overlap->x2 = b->x2; + } + if (overlap->x1 > overlap->x2) { + return false; + } + overlap->y1 = a->y1; + if (b->y1 > overlap->y1) { + overlap->y1 = b->y1; + } + overlap->y2 = a->y2; + if (b->y2 < overlap->y2) { + overlap->y2 = b->y2; + } + if (overlap->y1 > overlap->y2) { + return false; + } + return true; +} + +uint16_t displayio_area_width(const displayio_area_t* area) { + return area->x2 - area->x1 + 1; +} + +uint16_t displayio_area_height(const displayio_area_t* area) { + return area->y2 - area->y1 + 1; +} + +uint32_t displayio_area_size(const displayio_area_t* area) { + return displayio_area_width(area) * displayio_area_height(area); +} + +bool displayio_area_equal(const displayio_area_t* a, const displayio_area_t* b) { + return a->x1 == b->x1 && + a->y1 == b->y1 && + a->x2 == b->x2 && + a->y2 == b->y2; +} diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h index 5b56ed55c..7ffc8eab2 100644 --- a/shared-module/displayio/__init__.h +++ b/shared-module/displayio/__init__.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H -#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H +#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO___INIT___H +#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO___INIT___H #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/FourWire.h" @@ -47,4 +47,4 @@ extern displayio_group_t circuitpython_splash; void displayio_refresh_displays(void); void reset_displays(void); -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H +#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO___INIT___H diff --git a/shared-module/displayio/area.h b/shared-module/displayio/area.h new file mode 100644 index 000000000..33e41f37d --- /dev/null +++ b/shared-module/displayio/area.h @@ -0,0 +1,57 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_AREA_H +#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_AREA_H + +// Implementations are in __init__.c + +typedef struct { + int16_t x1; + int16_t y1; + int16_t x2; // Second point is inclusive. + int16_t y2; +} displayio_area_t; + +typedef struct { + uint16_t width; + uint16_t height; + uint8_t scale; + bool mirror_x; + bool mirror_y; + bool transpose_xy; +} displayio_buffer_transform_t; + +void displayio_area_shift(displayio_area_t* area, int16_t dx, int16_t dy); +bool displayio_area_compute_overlap(const displayio_area_t* a, + const displayio_area_t* b, + displayio_area_t* overlap); +uint16_t displayio_area_width(const displayio_area_t* area); +uint16_t displayio_area_height(const displayio_area_t* area); +uint32_t displayio_area_size(const displayio_area_t* area); +bool displayio_area_equal(const displayio_area_t* a, const displayio_area_t* b); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_AREA_H diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 0b3fbe178..cfb9cc1d1 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -70,8 +70,8 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { grid->width_in_tiles = width_in_tiles; grid->height_in_tiles = height_in_tiles; - grid->total_width = width_in_tiles * grid->tile_width; - grid->total_height = height_in_tiles * grid->tile_height; + grid->area.x2 = grid->area.x1 + width_in_tiles * grid->tile_width - 1; + grid->area.y2 = grid->area.y1 + height_in_tiles * grid->tile_height - 1; grid->tiles = tiles; supervisor_terminal.cursor_x = 0; @@ -157,13 +157,15 @@ displayio_tilegrid_t blinka_sprite = { .base = {.type = &displayio_tilegrid_type }, .bitmap = &blinka_bitmap, .pixel_shader = &blinka_palette, - .x = 0, - .y = 0, + .area = { + .x1 = 0, + .y1 = 0, + .x2 = 16, + .y2 = 16 + }, .bitmap_width_in_tiles = 1, .width_in_tiles = 1, .height_in_tiles = 1, - .total_width = 16, - .total_height = 16, .tile_width = 16, .tile_height = 16, .top_left_x = 16, diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py index ebea9dccc..b1fd04831 100644 --- a/tools/gen_display_resources.py +++ b/tools/gen_display_resources.py @@ -120,13 +120,15 @@ displayio_tilegrid_t supervisor_terminal_text_grid = {{ .base = {{ .type = &displayio_tilegrid_type }}, .bitmap = (displayio_bitmap_t*) &supervisor_terminal_font_bitmap, .pixel_shader = &supervisor_terminal_color, - .x = 16, - .y = 0, + .area = {{ + .x1 = 16, + .y1 = 0, + .x2 = {1} + 16, + .y2 = {2}, + }}, .bitmap_width_in_tiles = {0}, .width_in_tiles = 1, .height_in_tiles = 1, - .total_width = {1}, - .total_height = {2}, .tile_width = {1}, .tile_height = {2}, .tiles = NULL, -- cgit v1.2.3 From 1639354e5fc886ee4b2064eaceedfd26ebbe1cd3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 23 May 2019 16:07:54 -0400 Subject: Scanner working, but not very first time --- ports/nrf/bluetooth/ble_drv.h | 5 +- ports/nrf/common-hal/bleio/Scanner.c | 26 ++----- shared-bindings/bleio/Scanner.c | 130 ++++++++++++++--------------------- shared-bindings/bleio/Scanner.h | 2 +- shared-bindings/bleio/__init__.c | 8 +-- 5 files changed, 61 insertions(+), 110 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/bluetooth/ble_drv.h b/ports/nrf/bluetooth/ble_drv.h index cdb4c9b03..133d77b48 100644 --- a/ports/nrf/bluetooth/ble_drv.h +++ b/ports/nrf/bluetooth/ble_drv.h @@ -30,10 +30,6 @@ #include "ble.h" -#if (BLUETOOTH_SD == 132) && (BLE_API_VERSION == 2) -#define NRF52 -#endif - #define MAX_TX_IN_PROGRESS 10 #ifndef BLE_GATT_ATT_MTU_DEFAULT @@ -43,6 +39,7 @@ #define BLE_CONN_CFG_TAG_CUSTOM 1 #define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION)) +#define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION)) // 0.625 msecs (625 usecs) #define ADV_INTERVAL_UNIT_FLOAT_SECS (0.000625) #define UNIT_0_625_MS (625) diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index d2e19b5f9..d4479515e 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -36,14 +36,12 @@ #include "shared-bindings/bleio/Scanner.h" #include "shared-module/bleio/ScanEntry.h" -#if (BLUETOOTH_SD == 140) static uint8_t m_scan_buffer_data[BLE_GAP_SCAN_BUFFER_MIN]; static ble_data_t m_scan_buffer = { m_scan_buffer_data, BLE_GAP_SCAN_BUFFER_MIN }; -#endif STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { bleio_scanner_obj_t *scanner = (bleio_scanner_obj_t*)scanner_in; @@ -61,48 +59,34 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { entry->address.type = report->peer_addr.addr_type; memcpy(entry->address.value, report->peer_addr.addr, BLEIO_ADDRESS_BYTES); -#if (BLUETOOTH_SD == 140) entry->data = mp_obj_new_bytearray(report->data.len, report->data.p_data); -#else - entry->data = mp_obj_new_bytearray(report->dlen, report->data); -#endif mp_obj_list_append(scanner->adv_reports, entry); -#if (BLUETOOTH_SD == 140) const uint32_t err_code = sd_ble_gap_scan_start(NULL, &m_scan_buffer); if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to continue scanning, err 0x%04x"), err_code); } -#endif } -void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_int_t timeout) { +void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { ble_drv_add_event_handler(on_ble_evt, self); ble_gap_scan_params_t scan_params = { - .interval = MSEC_TO_UNITS(self->interval, UNIT_0_625_MS), - .window = MSEC_TO_UNITS(self->window, UNIT_0_625_MS), -#if (BLUETOOTH_SD == 140) + .interval = SEC_TO_UNITS(interval, UNIT_0_625_MS), + .window = SEC_TO_UNITS(window, UNIT_0_625_MS), .scan_phys = BLE_GAP_PHY_1MBPS, -#endif }; common_hal_bleio_adapter_set_enabled(true); uint32_t err_code; -#if (BLUETOOTH_SD == 140) err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); -#else - err_code = sd_ble_gap_scan_start(&scan_params); -#endif if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to start scanning, err 0x%04x"), err_code); } - if (timeout > 0) { - mp_hal_delay_ms(timeout); - sd_ble_gap_scan_stop(); - } + mp_hal_delay_ms(timeout * 1000); + sd_ble_gap_scan_stop(); } diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 73b6e6a0b..5615ce103 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -30,8 +30,12 @@ #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/Scanner.h" -#define DEFAULT_INTERVAL 100 -#define DEFAULT_WINDOW 100 +#define INTERVAL_DEFAULT (0.1f) +#define INTERVAL_MIN (0.0025f) +#define INTERVAL_MIN_STRING "0.0025" +#define INTERVAL_MAX (40.959375f) +#define INTERVAL_MAX_STRING "40.959375" +#define WINDOW_DEFAULT (0.1f) //| .. currentmodule:: bleio //| @@ -45,109 +49,76 @@ //| import bleio //| scanner = bleio.Scanner() //| entries = scanner.scan(2.5) # Scan for 2.5 seconds -//| print(entries) //| //| .. class:: Scanner() //| //| Create a new Scanner object. //| +STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 0, 0, false); -//| .. attribute:: interval -//| -//| The interval (in seconds) between the start of two consecutive scan windows. -//| Allowed values are between 0.010 and 10.24 sec. -//| + bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t); + self->base.type = type; -//| .. attribute:: window -//| -//| The duration (in seconds) in which a single BLE channel is scanned. -//| Allowed values are between 0.010 and 10.24 sec. -//| + return MP_OBJ_FROM_PTR(self); +} -//| .. method:: scan(timeout) +//| .. method:: scan(timeout, \*, interval=0.1, window=0.1) //| //| Performs a BLE scan. //| //| :param float timeout: the scan timeout in seconds +//| :param float interval: the interval (in seconds) between the start of two consecutive scan windows +//| Must be in the range 0.0025 - 40.959375 seconds. +//| :param float window: the duration (in seconds) to scan a single BLE channel +//| `window` must be <= `interval`. //| :returns: advertising packets found //| :rtype: list of :py:class:`bleio.ScanEntry` //| -STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 0, 0, false); - - - bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t); - self->base.type = type; - - self->interval = DEFAULT_INTERVAL; - self->window = DEFAULT_WINDOW; - - return MP_OBJ_FROM_PTR(self); -} - -STATIC mp_obj_t bleio_scanner_get_interval(mp_obj_t self_in) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return mp_obj_new_int(self->interval); -} -MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanner_get_interval_obj, bleio_scanner_get_interval); - -static mp_obj_t bleio_scanner_set_interval(mp_obj_t self_in, mp_obj_t value) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - - self->interval = mp_obj_get_int(value); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_scanner_set_interval_obj, bleio_scanner_set_interval); - -const mp_obj_property_t bleio_scanner_interval_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_scanner_get_interval_obj, - (mp_obj_t)&bleio_scanner_set_interval_obj, - (mp_obj_t)&mp_const_none_obj }, -}; - -STATIC mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - const mp_int_t timeout = mp_obj_get_int(timeout_in); +STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_timeout, ARG_interval, ARG_window }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_timeout, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_interval, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_window, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_obj = MP_OBJ_NULL} }, + }; + + bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + const mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); + + if (args[ARG_interval].u_obj == MP_OBJ_NULL) { + args[ARG_interval].u_obj = mp_obj_new_float(INTERVAL_DEFAULT); + } + + if (args[ARG_window].u_obj == MP_OBJ_NULL) { + args[ARG_window].u_obj = mp_obj_new_float(WINDOW_DEFAULT); + } + + const mp_float_t interval = mp_obj_float_get(args[ARG_interval].u_obj); + if (interval < INTERVAL_MIN || interval > INTERVAL_MAX) { + mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), INTERVAL_MIN_STRING, INTERVAL_MAX_STRING); + } + + const mp_float_t window = mp_obj_float_get(args[ARG_window].u_obj); + if (window > interval) { + mp_raise_ValueError(translate("window must be <= interval")); + } self->adv_reports = mp_obj_new_list(0, NULL); - common_hal_bleio_scanner_scan(self, timeout); + common_hal_bleio_scanner_scan(self, timeout, interval, window); return self->adv_reports; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_scanner_scan_obj, scanner_scan); - -STATIC mp_obj_t bleio_scanner_get_window(mp_obj_t self_in) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return mp_obj_new_int(self->window); -} -MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanner_get_window_obj, bleio_scanner_get_window); - -static mp_obj_t bleio_scanner_set_window(mp_obj_t self_in, mp_obj_t value) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); - self->window = mp_obj_get_int(value); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_scanner_set_window_obj, bleio_scanner_set_window); - -const mp_obj_property_t bleio_scanner_window_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_scanner_get_window_obj, - (mp_obj_t)&bleio_scanner_set_window_obj, - (mp_obj_t)&mp_const_none_obj }, -}; STATIC const mp_rom_map_elem_t bleio_scanner_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_interval), MP_ROM_PTR(&bleio_scanner_interval_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&bleio_scanner_scan_obj) }, - { MP_ROM_QSTR(MP_QSTR_window), MP_ROM_PTR(&bleio_scanner_window_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bleio_scanner_locals_dict, bleio_scanner_locals_dict_table); @@ -155,7 +126,6 @@ STATIC MP_DEFINE_CONST_DICT(bleio_scanner_locals_dict, bleio_scanner_locals_dict const mp_obj_type_t bleio_scanner_type = { { &mp_type_type }, .name = MP_QSTR_Scanner, - .print = bleio_scanner_print, .make_new = bleio_scanner_make_new, .locals_dict = (mp_obj_dict_t*)&bleio_scanner_locals_dict }; diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index c72136389..54c09675b 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -33,7 +33,7 @@ extern const mp_obj_type_t bleio_scanner_type; -extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_int_t timeout); +void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 7348655ac..907d21101 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -64,8 +64,8 @@ // Descriptor // Device //| Peripheral -// ScanEntry -// Scanner +//| ScanEntry +//| Scanner //| Service //| UUID //| @@ -86,8 +86,8 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, { MP_ROM_QSTR(MP_QSTR_Peripheral), MP_ROM_PTR(&bleio_peripheral_type) }, // Hide work-in-progress. -// { MP_ROM_QSTR(MP_QSTR_ScanEntry), MP_ROM_PTR(&bleio_scanentry_type) }, -// { MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&bleio_scanner_type) }, + { MP_ROM_QSTR(MP_QSTR_ScanEntry), MP_ROM_PTR(&bleio_scanentry_type) }, + { MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&bleio_scanner_type) }, { MP_ROM_QSTR(MP_QSTR_Service), MP_ROM_PTR(&bleio_service_type) }, { MP_ROM_QSTR(MP_QSTR_UUID), MP_ROM_PTR(&bleio_uuid_type) }, -- cgit v1.2.3 From 6cec81bcb54fe69d179f6596d8dae96b6f3beea2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 23 May 2019 22:05:16 -0400 Subject: Need to enable ble before scanning --- ports/nrf/common-hal/bleio/Peripheral.c | 2 +- ports/nrf/common-hal/bleio/Scanner.c | 1 + shared-bindings/bleio/__init__.c | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 0a5a8069d..83191d487 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -288,7 +288,7 @@ STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self) { - common_hal_bleio_adapter_set_enabled(true); // TODO -- Do this somewhere else maybe bleio __init__ + common_hal_bleio_adapter_set_enabled(true); self->gatt_role = GATT_ROLE_SERVER; self->conn_handle = BLE_CONN_HANDLE_INVALID; diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index d4479515e..b76caaf21 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -70,6 +70,7 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { } void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { + common_hal_bleio_adapter_set_enabled(true); ble_drv_add_event_handler(on_ble_evt, self); ble_gap_scan_params_t scan_params = { diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 907d21101..03aef2ece 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -85,7 +85,6 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) }, // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, { MP_ROM_QSTR(MP_QSTR_Peripheral), MP_ROM_PTR(&bleio_peripheral_type) }, -// Hide work-in-progress. { MP_ROM_QSTR(MP_QSTR_ScanEntry), MP_ROM_PTR(&bleio_scanentry_type) }, { MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&bleio_scanner_type) }, { MP_ROM_QSTR(MP_QSTR_Service), MP_ROM_PTR(&bleio_service_type) }, -- cgit v1.2.3 From a9a222716722f3477ecaf27f07f7d4c66862818e Mon Sep 17 00:00:00 2001 From: Jason Pecor <14111408+jpecor@users.noreply.github.com> Date: Mon, 27 May 2019 14:08:19 -0500 Subject: Removed warning box regarding SAMD21 builds The support matrix shows that pulseio is supported for all SAMD21/SAMD51 variants. Removing warning to avoid confusion. --- shared-bindings/pulseio/__init__.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/pulseio/__init__.c b/shared-bindings/pulseio/__init__.c index 1114b604b..a3cec3dca 100644 --- a/shared-bindings/pulseio/__init__.c +++ b/shared-bindings/pulseio/__init__.c @@ -54,10 +54,6 @@ //| PWMOut //| -//| .. warning:: This module is not available in some SAMD21 builds. See the -//| :ref:`module-support-matrix` for more info. -//| - //| All classes change hardware state and should be deinitialized when they //| are no longer needed if the program continues after use. To do so, either //| call :py:meth:`!deinit` or use a context manager. See -- cgit v1.2.3 From cfe24b85322a029758c3376eed2726657397bf33 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 30 May 2019 19:01:27 -0700 Subject: Improve rST consistency for rst2pyi use --- shared-bindings/_pixelbuf/PixelBuf.c | 42 +++++++++++++++------------- shared-bindings/_pixelbuf/__init__.c | 38 ++++++++++++------------- shared-bindings/audiobusio/PDMIn.c | 2 +- shared-bindings/audioio/WaveFile.c | 4 +-- shared-bindings/bitbangio/I2C.c | 18 ++++++------ shared-bindings/bitbangio/SPI.c | 22 +++++++-------- shared-bindings/bleio/AddressType.c | 2 +- shared-bindings/bleio/CharacteristicBuffer.c | 2 +- shared-bindings/bleio/UUID.c | 18 ++++++++---- shared-bindings/board/__init__.c | 6 ++-- shared-bindings/busio/I2C.c | 22 +++++++-------- shared-bindings/busio/SPI.c | 26 ++++++++--------- shared-bindings/busio/UART.c | 4 +-- shared-bindings/displayio/TileGrid.c | 2 +- shared-bindings/displayio/__init__.c | 2 +- shared-bindings/help.c | 2 +- shared-bindings/microcontroller/Pin.c | 2 +- shared-bindings/microcontroller/RunMode.c | 14 +++++++--- shared-bindings/microcontroller/__init__.c | 16 ++++++----- shared-bindings/neopixel_write/__init__.c | 4 +-- shared-bindings/network/__init__.c | 2 +- shared-bindings/pulseio/PWMOut.c | 2 +- shared-bindings/pulseio/PulseIn.c | 2 +- shared-bindings/socket/__init__.c | 2 +- shared-bindings/storage/__init__.c | 6 ++-- shared-bindings/struct/__init__.c | 8 +++--- shared-bindings/time/__init__.c | 33 +++++++++++----------- shared-bindings/uheap/__init__.c | 2 +- shared-bindings/ustack/__init__.c | 6 ++-- shared-bindings/wiznet/wiznet5k.c | 2 +- 30 files changed, 165 insertions(+), 148 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/_pixelbuf/PixelBuf.c b/shared-bindings/_pixelbuf/PixelBuf.c index 7c2766aa3..420720e62 100644 --- a/shared-bindings/_pixelbuf/PixelBuf.c +++ b/shared-bindings/_pixelbuf/PixelBuf.c @@ -51,7 +51,7 @@ extern const int32_t colorwheel(float pos); //| //| :class:`~_pixelbuf.PixelBuf` implements an RGB[W] bytearray abstraction. //| -//| .. class:: PixelBuf(size, buf, byteorder=BGR, bpp=3) +//| .. class:: PixelBuf(size, buf, byteorder=BGR, brightness=0, rawbuf=None, offset=0, dotstar=False, auto_write=False, write_function=None, write_args=None) //| //| Create a PixelBuf object of the specified size, byteorder, and bits per pixel. //| @@ -66,14 +66,14 @@ extern const int32_t colorwheel(float pos); //| //| :param ~int size: Number of pixelsx //| :param ~bytearray buf: Bytearray to store pixel data in -//| :param ~_pixelbuf.ByteOrder byteorder: Byte order constant from `_pixelbuf` (also sets the bpp) +//| :param ~_pixelbuf.ByteOrder byteorder: Byte order constant from `_pixelbuf` //| :param ~float brightness: Brightness (0 to 1.0, default 1.0) //| :param ~bytearray rawbuf: Bytearray to store raw pixel colors in //| :param ~int offset: Offset from start of buffer (default 0) //| :param ~bool dotstar: Dotstar mode (default False) //| :param ~bool auto_write: Whether to automatically write pixels (Default False) //| :param ~callable write_function: (optional) Callable to use to send pixels -//| :param ~list write_args: (optional) Tuple or list of args to pass to ``write_function``. The +//| :param ~list write_args: (optional) Tuple or list of args to pass to ``write_function``. The //| PixelBuf instance is appended after these args. //| STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -95,7 +95,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - if (mp_obj_is_subclass_fast(args[ARG_byteorder].u_obj, &pixelbuf_byteorder_type)) + if (mp_obj_is_subclass_fast(args[ARG_byteorder].u_obj, &pixelbuf_byteorder_type)) mp_raise_TypeError_varg(translate("byteorder is not an instance of ByteOrder (got a %s)"), mp_obj_get_type_str(args[ARG_byteorder].u_obj)); pixelbuf_byteorder_obj_t *byteorder = (args[ARG_byteorder].u_obj == mp_const_none) ? MP_OBJ_FROM_PTR(&byteorder_BGR) : args[ARG_byteorder].u_obj; @@ -122,7 +122,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a if (!MP_OBJ_IS_TYPE(args[ARG_write_args].u_obj, &mp_type_list) && !MP_OBJ_IS_TYPE(args[ARG_write_args].u_obj, &mp_type_tuple) && - args[ARG_write_args].u_obj != mp_const_none) + args[ARG_write_args].u_obj != mp_const_none) { mp_raise_ValueError(translate("write_args must be a list, tuple, or None")); } @@ -186,8 +186,8 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a else if (self->brightness > 1) self->brightness = 1; } - - if (self->dotstar_mode) { + + if (self->dotstar_mode) { // Initialize the buffer with the dotstar start bytes. // Header and end must be setup by caller for (uint i = 0; i < self->pixels * 4; i += 4) { @@ -197,7 +197,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a } } } - + return MP_OBJ_FROM_PTR(self); } @@ -227,7 +227,7 @@ const mp_obj_property_t pixelbuf_pixelbuf_bpp_obj = { //| setting this value causes a recomputation of the values in buf. //| If only a buf was provided, then the brightness only applies to //| future pixel changes. -//| In DotStar mode +//| In DotStar mode //| STATIC mp_obj_t pixelbuf_pixelbuf_obj_get_brightness(mp_obj_t self_in) { mp_check_self(MP_OBJ_IS_TYPE(self_in, &pixelbuf_pixelbuf_type)); @@ -266,7 +266,7 @@ void pixelbuf_recalculate_brightness(pixelbuf_pixelbuf_obj_t *self) { // Compensate for shifted buffer (bpp=3 dotstar) for (uint i = 0; i < self->bytes; i++) { // Don't adjust per-pixel luminance bytes in dotstar mode - if (!self->dotstar_mode || (i % 4 != 0)) + if (!self->dotstar_mode || (i % 4 != 0)) buf[i] = rawbuf[i] * self->brightness; } } @@ -367,11 +367,13 @@ void call_write_function(pixelbuf_pixelbuf_obj_t *self) { } } - - -//| .. method:: [] +//| .. method:: __getitem__(index) +//| +//| Returns the pixel value at the given index. //| -//| Get or set pixels. Supports individual pixels and slices. +//| .. method:: __setitem__(index, value) +//| +//| Sets the pixel value at the given index. //| STATIC mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { mp_check_self(MP_OBJ_IS_TYPE(self_in, &pixelbuf_pixelbuf_type)); @@ -380,7 +382,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp // delete item // slice deletion return MP_OBJ_NULL; // op not supported - } + } pixelbuf_pixelbuf_obj_t *self = MP_OBJ_TO_PTR(self_in); if (0) { @@ -390,7 +392,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp if (!mp_seq_get_fast_slice_indexes(self->bytes, index_in, &slice)) mp_raise_NotImplementedError(translate("Only slices with step=1 (aka None) are supported")); - if ((slice.stop * self->pixel_step) > self->bytes) + if ((slice.stop * self->pixel_step) > self->bytes) mp_raise_IndexError(translate("Range out of bounds")); if (value == MP_OBJ_SENTINEL) { // Get @@ -422,8 +424,8 @@ STATIC mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp for (size_t i = slice.start; i < slice.stop; i++) { mp_obj_t *item = src_objs[i-slice.start]; if (MP_OBJ_IS_TYPE(value, &mp_type_list) || MP_OBJ_IS_TYPE(value, &mp_type_tuple) || MP_OBJ_IS_INT(value)) { - pixelbuf_set_pixel(self->buf + (i * self->pixel_step), - self->two_buffers ? self->rawbuf + (i * self->pixel_step) : NULL, + pixelbuf_set_pixel(self->buf + (i * self->pixel_step), + self->two_buffers ? self->rawbuf + (i * self->pixel_step) : NULL, self->brightness, item, &self->byteorder, self->dotstar_mode); } } @@ -438,14 +440,14 @@ STATIC mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp } else { // Single index rather than slice. size_t index = mp_get_index(self->base.type, self->pixels, index_in, false); size_t offset = (index * self->pixel_step); - if (offset > self->bytes) + if (offset > self->bytes) mp_raise_IndexError(translate("Pixel beyond bounds of buffer")); if (value == MP_OBJ_SENTINEL) { // Get uint8_t *pixelstart = (uint8_t *)(self->two_buffers ? self->rawbuf : self->buf) + offset; return pixelbuf_get_pixel(pixelstart, &self->byteorder, self->dotstar_mode); } else { // Store - pixelbuf_set_pixel(self->buf + offset, self->two_buffers ? self->rawbuf + offset : NULL, + pixelbuf_set_pixel(self->buf + offset, self->two_buffers ? self->rawbuf + offset : NULL, self->brightness, value, &self->byteorder, self->dotstar_mode); if (self->auto_write) call_write_function(self); diff --git a/shared-bindings/_pixelbuf/__init__.c b/shared-bindings/_pixelbuf/__init__.c index 31defc7fb..48b9f1cef 100644 --- a/shared-bindings/_pixelbuf/__init__.c +++ b/shared-bindings/_pixelbuf/__init__.c @@ -53,7 +53,7 @@ //| //| PixelBuf -//| .. class:: ByteOrder +//| .. class:: ByteOrder() //| //| Classes representing byteorders for circuitpython @@ -169,34 +169,34 @@ const int32_t colorwheel(float pos) { /// RGB -//| .. class:: RGB +//| .. data:: RGB //| //| * **order** Red, Green, Blue //| * **bpp** 3 PIXELBUF_BYTEORDER(RGB, 3, 0, 1, 2, 3, false, false) -//| .. class:: RBG +//| .. data:: RBG //| //| * **order** Red, Blue, Green //| * **bpp** 3 PIXELBUF_BYTEORDER(RBG, 3, 0, 2, 1, 3, false, false) -//| .. class:: GRB +//| .. data:: GRB //| //| * **order** Green, Red, Blue //| * **bpp** 3 //| //| Commonly used by NeoPixel. PIXELBUF_BYTEORDER(GRB, 3, 1, 0, 2, 3, false, false) -//| .. class:: GBR +//| .. data:: GBR //| //| * **order** Green, Blue, Red //| * **bpp** 3 PIXELBUF_BYTEORDER(GBR, 3, 1, 2, 0, 3, false, false) -//| .. class:: BRG +//| .. data:: BRG //| //| * **order** Blue, Red, Green //| * **bpp** 3 PIXELBUF_BYTEORDER(BRG, 3, 2, 0, 1, 3, false, false) -//| .. class:: BGR +//| .. data:: BGR //| //| * **order** Blue, Green, Red //| * **bpp** 3 @@ -205,19 +205,19 @@ PIXELBUF_BYTEORDER(BRG, 3, 2, 0, 1, 3, false, false) PIXELBUF_BYTEORDER(BGR, 3, 2, 1, 0, 3, false, false) // RGBW -//| .. class:: RGBW +//| .. data:: RGBW //| //| * **order** Red, Green, Blue, White //| * **bpp** 4 //| * **has_white** True PIXELBUF_BYTEORDER(RGBW, 4, 0, 1, 2, 3, true, false) -//| .. class:: RBGW +//| .. data:: RBGW //| //| * **order** Red, Blue, Green, White //| * **bpp** 4 //| * **has_white** True PIXELBUF_BYTEORDER(RBGW, 4, 0, 2, 1, 3, true, false) -//| .. class:: GRBW +//| .. data:: GRBW //| //| * **order** Green, Red, Blue, White //| * **bpp** 4 @@ -225,19 +225,19 @@ PIXELBUF_BYTEORDER(RBGW, 4, 0, 2, 1, 3, true, false) //| //| Commonly used by RGBW NeoPixels. PIXELBUF_BYTEORDER(GRBW, 4, 1, 0, 2, 3, true, false) -//| .. class:: GBRW +//| .. data:: GBRW //| //| * **order** Green, Blue, Red, White //| * **bpp** 4 //| * **has_white** True PIXELBUF_BYTEORDER(GBRW, 4, 1, 2, 0, 3, true, false) -//| .. class:: BRGW +//| .. data:: BRGW //| //| * **order** Blue, Red, Green, White //| * **bpp** 4 //| * **has_white** True PIXELBUF_BYTEORDER(BRGW, 4, 2, 0, 1, 3, true, false) -//| .. class:: BGRW +//| .. data:: BGRW //| //| * **order** Blue, Green, Red, White //| * **bpp** 4 @@ -248,37 +248,37 @@ PIXELBUF_BYTEORDER(BGRW, 4, 2, 1, 0, 3, true, false) // Luminosity chosen because the luminosity of a Dotstar at full bright // burns the eyes like looking at the Sun. // https://www.thesaurus.com/browse/luminosity?s=t -//| .. class:: LRGB +//| .. data:: LRGB //| //| * **order** *Luminosity*, Red, Green, Blue //| * **bpp** 4 //| * **has_luminosity** True PIXELBUF_BYTEORDER(LRGB, 4, 1, 2, 3, 0, false, true) -//| .. class:: LRBG +//| .. data:: LRBG //| //| * **order** *Luminosity*, Red, Blue, Green //| * **bpp** 4 //| * **has_luminosity** True PIXELBUF_BYTEORDER(LRBG, 4, 1, 3, 2, 0, false, true) -//| .. class:: LGRB +//| .. data:: LGRB //| //| * **order** *Luminosity*, Green, Red, Blue //| * **bpp** 4 //| * **has_luminosity** True PIXELBUF_BYTEORDER(LGRB, 4, 2, 1, 3, 0, false, true) -//| .. class:: LGBR +//| .. data:: LGBR //| //| * **order** *Luminosity*, Green, Blue, Red //| * **bpp** 4 //| * **has_luminosity** True PIXELBUF_BYTEORDER(LGBR, 4, 2, 3, 1, 0, false, true) -//| .. class:: LBRG +//| .. data:: LBRG //| //| * **order** *Luminosity*, Blue, Red, Green //| * **bpp** 4 //| * **has_luminosity** True PIXELBUF_BYTEORDER(LBRG, 4, 3, 1, 2, 0, false, true) -//| .. class:: LBGR +//| .. data:: LBGR //| //| * **order** *Luminosity*, Blue, Green, Red //| * **bpp** 4 diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index 5dca3fa59..0f19e2587 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -43,7 +43,7 @@ //| //| PDMIn can be used to record an input audio signal on a given set of pins. //| -//| .. class:: PDMIn(clock_pin, data_pin, \*, sample_rate=16000, bit_depth=8, mono=True, oversample=64, startup_delay=0.11) +//| .. class:: PDMIn(clock_pin, data_pin, *, sample_rate=16000, bit_depth=8, mono=True, oversample=64, startup_delay=0.11) //| //| Create a PDMIn object associated with the given pins. This allows you to //| record audio signals from the given pins. Individual ports may put further diff --git a/shared-bindings/audioio/WaveFile.c b/shared-bindings/audioio/WaveFile.c index cddeef769..a4e37231a 100644 --- a/shared-bindings/audioio/WaveFile.c +++ b/shared-bindings/audioio/WaveFile.c @@ -41,11 +41,11 @@ //| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must //| be 8 bit unsigned or 16 bit signed. //| -//| .. class:: WaveFile(filename) +//| .. class:: WaveFile(file) //| //| Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`. //| -//| :param bytes-like file: Already opened wave file +//| :param typing.BinaryIO file: Already opened wave file //| //| Playing a wave file from flash:: //| diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index 374268e3d..a74f08b0b 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -42,7 +42,7 @@ //| :class:`I2C` --- Two wire serial protocol //| ------------------------------------------ //| -//| .. class:: I2C(scl, sda, \*, frequency=400000) +//| .. class:: I2C(scl, sda, *, frequency=400000, timeout) //| //| I2C is a two-wire protocol for communicating between devices. At the //| physical level it consists of 2 wires: SCL and SDA, the clock and data @@ -75,7 +75,7 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, return (mp_obj_t)self; } -//| .. method:: I2C.deinit() +//| .. method:: deinit() //| //| Releases control of the underlying hardware so other classes can use it. //| @@ -86,13 +86,13 @@ STATIC mp_obj_t bitbangio_i2c_obj_deinit(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_deinit_obj, bitbangio_i2c_obj_deinit); -//| .. method:: I2C.__enter__() +//| .. method:: __enter__() //| //| No-op used in Context Managers. //| // Provided by context manager helper. -//| .. method:: I2C.__exit__() +//| .. method:: __exit__() //| //| Automatically deinitializes the hardware on context exit. See //| :ref:`lifetime-and-contextmanagers` for more info. @@ -110,7 +110,7 @@ static void check_lock(bitbangio_i2c_obj_t *self) { } } -//| .. method:: I2C.scan() +//| .. method:: scan() //| //| Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of //| those that respond. A device responds if it pulls the SDA line low after @@ -132,7 +132,7 @@ STATIC mp_obj_t bitbangio_i2c_scan(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_scan_obj, bitbangio_i2c_scan); -//| .. method:: I2C.try_lock() +//| .. method:: try_lock() //| //| Attempts to grab the I2C lock. Returns True on success. //| @@ -143,7 +143,7 @@ STATIC mp_obj_t bitbangio_i2c_obj_try_lock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_try_lock_obj, bitbangio_i2c_obj_try_lock); -//| .. method:: I2C.unlock() +//| .. method:: unlock() //| //| Releases the I2C lock. //| @@ -155,7 +155,7 @@ STATIC mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_i2c_obj_unlock); -//| .. method:: I2C.readfrom_into(address, buffer, \*, start=0, end=len(buffer)) +//| .. method:: readfrom_into(address, buffer, *, start=0, end=None) //| //| Read into ``buffer`` from the slave specified by ``address``. //| The number of bytes read will be the length of ``buffer``. @@ -203,7 +203,7 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a } MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 3, bitbangio_i2c_readfrom_into); -//| .. method:: I2C.writeto(address, buffer, \*, start=0, end=len(buffer), stop=True) +//| .. method:: writeto(address, buffer, *, start=0, end=None, stop=True) //| //| Write the bytes from ``buffer`` to the slave specified by ``address``. //| Transmits a stop bit if ``stop`` is set. diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 974ec99e2..9d00264cd 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -84,7 +84,7 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, return (mp_obj_t)self; } -//| .. method:: SPI.deinit() +//| .. method:: deinit() //| //| Turn off the SPI bus. //| @@ -95,13 +95,13 @@ STATIC mp_obj_t bitbangio_spi_obj_deinit(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_deinit_obj, bitbangio_spi_obj_deinit); -//| .. method:: SPI.__enter__() +//| .. method:: __enter__() //| //| No-op used by Context Managers. //| // Provided by context manager helper. -//| .. method:: SPI.__exit__() +//| .. method:: __exit__() //| //| Automatically deinitializes the hardware when exiting a context. See //| :ref:`lifetime-and-contextmanagers` for more info. @@ -120,7 +120,7 @@ static void check_lock(bitbangio_spi_obj_t *self) { } } -//| .. method:: SPI.configure(\*, baudrate=100000, polarity=0, phase=0, bits=8) +//| .. method:: configure(*, baudrate=100000, polarity=0, phase=0, bits=8) //| //| Configures the SPI bus. Only valid when locked. //| @@ -162,7 +162,7 @@ STATIC mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args, } MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_configure_obj, 1, bitbangio_spi_configure); -//| .. method:: SPI.try_lock() +//| .. method:: try_lock() //| //| Attempts to grab the SPI lock. Returns True on success. //| @@ -176,7 +176,7 @@ STATIC mp_obj_t bitbangio_spi_obj_try_lock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_try_lock_obj, bitbangio_spi_obj_try_lock); -//| .. method:: SPI.unlock() +//| .. method:: unlock() //| //| Releases the SPI lock. //| @@ -188,7 +188,7 @@ STATIC mp_obj_t bitbangio_spi_obj_unlock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_unlock_obj, bitbangio_spi_obj_unlock); -//| .. method:: SPI.write(buf) +//| .. method:: write(buf) //| //| Write the data contained in ``buf``. Requires the SPI being locked. //| If the buffer is empty, nothing happens. @@ -212,7 +212,7 @@ STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) { MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_spi_write_obj, bitbangio_spi_write); -//| .. method:: SPI.readinto(buf) +//| .. method:: readinto(buf) //| //| Read into the buffer specified by ``buf`` while writing zeroes. //| Requires the SPI being locked. @@ -236,7 +236,7 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_readinto_obj, 2, 2, bitbangio_spi_readinto); -//| .. method:: SPI.write_readinto(buffer_out, buffer_in, \*, out_start=0, out_end=len(buffer_out), in_start=0, in_end=len(buffer_in)) +//| .. method:: write_readinto(buffer_out, buffer_in, *, out_start=0, out_end=None, in_start=0, in_end=None) //| //| Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``. //| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]`` @@ -246,9 +246,9 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_readinto_obj, 2, 2, bitbangio_ //| :param bytearray buffer_out: Write out the data in this buffer //| :param bytearray buffer_in: Read data into this buffer //| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]`` -//| :param int out_end: End of the slice; this index is not included +//| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)`` //| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]`` -//| :param int in_end: End of the slice; this index is not included +//| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)`` //| STATIC mp_obj_t bitbangio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_buffer_out, ARG_buffer_in, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end }; diff --git a/shared-bindings/bleio/AddressType.c b/shared-bindings/bleio/AddressType.c index cf2151c94..7edf3c170 100644 --- a/shared-bindings/bleio/AddressType.c +++ b/shared-bindings/bleio/AddressType.c @@ -31,7 +31,7 @@ //| :class:`AddressType` -- defines the type of a BLE address //| ============================================================= //| -//| .. class:: bleio.AddressType +//| .. class:: AddressType() //| //| Enum-like class to define the type of a BLE address, see also `bleio.Address`. //| diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index c368de361..3604aeedb 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -47,7 +47,7 @@ STATIC void raise_error_if_not_connected(bleio_characteristic_buffer_obj_t *self //| //| Accumulates a Characteristic's incoming values in a FIFO buffer. //| -//| .. class:: CharacteristicBuffer(Characteristic, *, timeout=1, buffer_size=64) +//| .. class:: CharacteristicBuffer(characteristic, *, timeout=1, buffer_size=64) //| //| Create a new Characteristic object identified by the specified UUID. //| diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index c6ad9e626..fa2472b48 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -47,9 +47,10 @@ //| The value can be one of: //| //| - an `int` value in range 0 to 0xFFFF (Bluetooth SIG 16-bit UUID) -//| - a buffer object (bytearray, bytes) of 16 bytes in little-endian order (128-bit UUID) +//| - a buffer object (bytearray, bytes) of 16 bytes in little-endian order (128-bit UUID) //| -//| :param int/buffer value: The uuid value to encapsulate +//| :param value: The uuid value to encapsulate +//| :type value: int or typing.ByteString //| STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_check_num(n_args, kw_args, 1, 1, false); @@ -124,6 +125,8 @@ STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, co //| //| The 16-bit part of the UUID. (read-only) //| +//| :type: int +//| STATIC mp_obj_t bleio_uuid_get_uuid16(mp_obj_t self_in) { bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_uuid_get_uuid16(self)); @@ -140,9 +143,11 @@ const mp_obj_property_t bleio_uuid_uuid16_obj = { //| .. attribute:: uuid128 //| -//| The 128-bit value of the UUID, returned as bytes. +//| The 128-bit value of the UUID //| Raises AttributeError if this is a 16-bit UUID. (read-only) //| +//| :type: bytes +//| STATIC mp_obj_t bleio_uuid_get_uuid128(mp_obj_t self_in) { bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -164,9 +169,10 @@ const mp_obj_property_t bleio_uuid_uuid128_obj = { //| .. attribute:: size //| -//| Returns 128 if this UUID represents a 128-bit vendor-specific UUID. -//| Returns 16 if this UUID represents a 16-bit Bluetooth SIG assigned UUID. (read-only) -//| 32-bit UUIDs are not currently supported. +//| 128 if this UUID represents a 128-bit vendor-specific UUID. 16 if this UUID represents a +//| 16-bit Bluetooth SIG assigned UUID. (read-only) 32-bit UUIDs are not currently supported. +//| +//| :type: int //| STATIC mp_obj_t bleio_uuid_get_size(mp_obj_t self_in) { bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/board/__init__.c b/shared-bindings/board/__init__.c index 82a0cab67..b4cc8cb12 100644 --- a/shared-bindings/board/__init__.c +++ b/shared-bindings/board/__init__.c @@ -42,7 +42,7 @@ //| .. warning:: The board module varies by board. The APIs documented here may or may not be //| available on a specific board. -//| .. method:: I2C() +//| .. function:: I2C() //| //| Returns the `busio.I2C` object for the board designated SDA and SCL pins. It is a singleton. //| @@ -66,7 +66,7 @@ mp_obj_t board_i2c(void) { MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); -//| .. method:: SPI() +//| .. function:: SPI() //| //| Returns the `busio.SPI` object for the board designated SCK, MOSI and MISO pins. It is a //| singleton. @@ -90,7 +90,7 @@ mp_obj_t board_spi(void) { #endif MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi); -//| .. method:: UART() +//| .. function:: UART() //| //| Returns the `busio.UART` object for the board designated TX and RX pins. It is a singleton. //| diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index e17a72b48..1c50c07b0 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -41,7 +41,7 @@ //| :class:`I2C` --- Two wire serial protocol //| ------------------------------------------ //| -//| .. class:: I2C(scl, sda, \*, frequency=400000) +//| .. class:: I2C(scl, sda, *, frequency=400000, timeout=255) //| //| I2C is a two-wire protocol for communicating between devices. At the //| physical level it consists of 2 wires: SCL and SDA, the clock and data @@ -82,7 +82,7 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, con return (mp_obj_t)self; } -//| .. method:: I2C.deinit() +//| .. method:: deinit() //| //| Releases control of the underlying hardware so other classes can use it. //| @@ -93,13 +93,13 @@ STATIC mp_obj_t busio_i2c_obj_deinit(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_deinit_obj, busio_i2c_obj_deinit); -//| .. method:: I2C.__enter__() +//| .. method:: __enter__() //| //| No-op used in Context Managers. //| // Provided by context manager helper. -//| .. method:: I2C.__exit__() +//| .. method:: __exit__() //| //| Automatically deinitializes the hardware on context exit. See //| :ref:`lifetime-and-contextmanagers` for more info. @@ -118,7 +118,7 @@ static void check_lock(busio_i2c_obj_t *self) { } } -//| .. method:: I2C.scan() +//| .. method:: scan() //| //| Scan all I2C addresses between 0x08 and 0x77 inclusive and return a //| list of those that respond. @@ -142,7 +142,7 @@ STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_scan_obj, busio_i2c_scan); -//| .. method:: I2C.try_lock() +//| .. method:: try_lock() //| //| Attempts to grab the I2C lock. Returns True on success. //| @@ -156,7 +156,7 @@ STATIC mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock); -//| .. method:: I2C.unlock() +//| .. method:: unlock() //| //| Releases the I2C lock. //| @@ -168,7 +168,7 @@ STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock); -//| .. method:: I2C.readfrom_into(address, buffer, \*, start=0, end=len(buffer)) +//| .. method:: readfrom_into(address, buffer, *, start=0, end=None) //| //| Read into ``buffer`` from the slave specified by ``address``. //| The number of bytes read will be the length of ``buffer``. @@ -181,7 +181,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock); //| :param int address: 7-bit device address //| :param bytearray buffer: buffer to write into //| :param int start: Index to start writing at -//| :param int end: Index to write up to but not include +//| :param int end: Index to write up to but not include. Defaults to ``len(buffer)`` //| STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_address, ARG_buffer, ARG_start, ARG_end }; @@ -216,7 +216,7 @@ STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, } MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 3, busio_i2c_readfrom_into); -//| .. method:: I2C.writeto(address, buffer, \*, start=0, end=len(buffer), stop=True) +//| .. method:: writeto(address, buffer, *, start=0, end=None, stop=True) //| //| Write the bytes from ``buffer`` to the slave specified by ``address``. //| Transmits a stop bit if ``stop`` is set. @@ -231,7 +231,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 3, busio_i2c_readfrom_in //| :param int address: 7-bit device address //| :param bytearray buffer: buffer containing the bytes to write //| :param int start: Index to start writing from -//| :param int end: Index to read up to but not include +//| :param int end: Index to read up to but not include. Defaults to ``len(buffer)`` //| :param bool stop: If true, output an I2C stop condition after the //| buffer is written //| diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index f690eea18..bd788365e 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -95,7 +95,7 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con return (mp_obj_t)self; } -//| .. method:: SPI.deinit() +//| .. method:: deinit() //| //| Turn off the SPI bus. //| @@ -106,13 +106,13 @@ STATIC mp_obj_t busio_spi_obj_deinit(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_deinit_obj, busio_spi_obj_deinit); -//| .. method:: SPI.__enter__() +//| .. method:: __enter__() //| //| No-op used by Context Managers. //| // Provided by context manager helper. -//| .. method:: SPI.__exit__() +//| .. method:: __exit__() //| //| Automatically deinitializes the hardware when exiting a context. See //| :ref:`lifetime-and-contextmanagers` for more info. @@ -131,7 +131,7 @@ static void check_lock(busio_spi_obj_t *self) { } } -//| .. method:: SPI.configure(\*, baudrate=100000, polarity=0, phase=0, bits=8) +//| .. method:: configure(*, baudrate=100000, polarity=0, phase=0, bits=8) //| //| Configures the SPI bus. The SPI object must be locked. //| @@ -188,7 +188,7 @@ STATIC mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_ } MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_configure_obj, 1, busio_spi_configure); -//| .. method:: SPI.try_lock() +//| .. method:: try_lock() //| //| Attempts to grab the SPI lock. Returns True on success. //| @@ -202,7 +202,7 @@ STATIC mp_obj_t busio_spi_obj_try_lock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_try_lock_obj, busio_spi_obj_try_lock); -//| .. method:: SPI.unlock() +//| .. method:: unlock() //| //| Releases the SPI lock. //| @@ -214,14 +214,14 @@ STATIC mp_obj_t busio_spi_obj_unlock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_unlock_obj, busio_spi_obj_unlock); -//| .. method:: SPI.write(buffer, \*, start=0, end=len(buffer)) +//| .. method:: write(buffer, *, start=0, end=None) //| //| Write the data contained in ``buffer``. The SPI object must be locked. //| If the buffer is empty, nothing happens. //| //| :param bytearray buffer: Write out the data in this buffer //| :param int start: Start of the slice of ``buffer`` to write out: ``buffer[start:end]`` -//| :param int end: End of the slice; this index is not included +//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)`` //| STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_buffer, ARG_start, ARG_end }; @@ -255,7 +255,7 @@ STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_obj, 2, busio_spi_write); -//| .. method:: SPI.readinto(buffer, \*, start=0, end=len(buffer), write_value=0) +//| .. method:: readinto(buffer, *, start=0, end=None, write_value=0) //| //| Read into ``buffer`` while writing ``write_value`` for each byte read. //| The SPI object must be locked. @@ -263,7 +263,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_obj, 2, busio_spi_write); //| //| :param bytearray buffer: Read data into this buffer //| :param int start: Start of the slice of ``buffer`` to read into: ``buffer[start:end]`` -//| :param int end: End of the slice; this index is not included +//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)`` //| :param int write_value: Value to write while reading. (Usually ignored.) //| STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -298,7 +298,7 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m } MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 2, busio_spi_readinto); -//| .. method:: SPI.write_readinto(buffer_out, buffer_in, \*, out_start=0, out_end=len(buffer_out), in_start=0, in_end=len(buffer_in)) +//| .. method:: write_readinto(buffer_out, buffer_in, *, out_start=0, out_end=None, in_start=0, in_end=None) //| //| Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``. //| The SPI object must be locked. @@ -309,9 +309,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 2, busio_spi_readinto); //| :param bytearray buffer_out: Write out the data in this buffer //| :param bytearray buffer_in: Read data into this buffer //| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]`` -//| :param int out_end: End of the slice; this index is not included +//| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)`` //| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]`` -//| :param int in_end: End of the slice; this index is not included +//| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)`` //| STATIC mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_buffer_out, ARG_buffer_in, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end }; diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index 94ad1bd3e..eeffb62ef 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -46,7 +46,7 @@ //| ================================================= //| //| -//| .. class:: UART(tx, rx, \*, baudrate=9600, bits=8, parity=None, stop=1, timeout=1, receiver_buffer_size=64) +//| .. class:: UART(tx, rx, *, baudrate=9600, bits=8, parity=None, stop=1, timeout=1, receiver_buffer_size=64) //| //| A common bidirectional serial protocol that uses an an agreed upon speed //| rather than a shared clock line. @@ -292,7 +292,7 @@ STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_obj_reset_input_buffer); -//| .. class:: busio.UART.Parity +//| .. class:: busio.UART.Parity() //| //| Enum-like class to define the parity used to verify correct data transfer. //| diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 6d18ac78f..10bed4c77 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -64,7 +64,7 @@ //| :param int height: Height of the grid in tiles. //| :param int tile_width: Width of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap's dimensions. //| :param int tile_height: Height of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap's dimensions. -//| :param in default_tile: Default tile index to show. +//| :param int default_tile: Default tile index to show. //| :param int x: Initial x position of the left edge within the parent. //| :param int y: Initial y position of the top edge within the parent. //| diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 44b1e0b07..9dc17103b 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -69,7 +69,7 @@ //| -//| .. method:: release_displays() +//| .. function:: release_displays() //| //| Releases any actively used displays so their busses and pins can be used again. This will also //| release the builtin display on boards that have one. You will need to reinitialize it yourself diff --git a/shared-bindings/help.c b/shared-bindings/help.c index e0770ff3c..4e7c3a78b 100644 --- a/shared-bindings/help.c +++ b/shared-bindings/help.c @@ -27,7 +27,7 @@ //| :func:`help` - Built-in method to provide helpful information //| ============================================================== //| -//| .. method:: help(object=None) +//| .. function:: help(object=None) //| //| Prints a help method about the given object. When ``object`` is none, //| prints general port information. diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index e79663107..3635f0afb 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -40,7 +40,7 @@ //| //| Identifies an IO pin on the microcontroller. //| -//| .. class:: Pin +//| .. class:: Pin() //| //| Identifies an IO pin on the microcontroller. They are fixed by the //| hardware so they cannot be constructed on demand. Instead, use diff --git a/shared-bindings/microcontroller/RunMode.c b/shared-bindings/microcontroller/RunMode.c index 7c3f84fca..913242ad2 100644 --- a/shared-bindings/microcontroller/RunMode.c +++ b/shared-bindings/microcontroller/RunMode.c @@ -31,24 +31,30 @@ //| :class:`RunMode` -- run state of the microcontroller //| ============================================================= //| -//| .. class:: microcontroller.RunMode +//| .. class:: RunMode() //| //| Enum-like class to define the run mode of the microcontroller and //| CircuitPython. //| -//| .. data:: NORMAL +//| .. attribute:: NORMAL //| //| Run CircuitPython as normal. //| -//| .. data:: SAFE_MODE +//| :type microcontroller.RunMode: +//| +//| .. attribute:: SAFE_MODE //| //| Run CircuitPython in safe mode. User code will not be run and the //| file system will be writeable over USB. //| -//| .. data:: BOOTLOADER +//| :type microcontroller.RunMode: +//| +//| .. attribute:: BOOTLOADER //| //| Run the bootloader. //| +//| :type microcontroller.RunMode: +//| const mp_obj_type_t mcu_runmode_type; const mcu_runmode_obj_t mcu_runmode_normal_obj = { diff --git a/shared-bindings/microcontroller/__init__.c b/shared-bindings/microcontroller/__init__.c index da8d0bd94..090c4564d 100644 --- a/shared-bindings/microcontroller/__init__.c +++ b/shared-bindings/microcontroller/__init__.c @@ -62,14 +62,14 @@ //| RunMode //| -//| .. attribute:: cpu +//| .. data:: cpu //| //| CPU information and control, such as ``cpu.temperature`` and ``cpu.frequency`` //| (clock frequency). //| This object is the sole instance of `microcontroller.Processor`. //| -//| .. method:: delay_us(delay) +//| .. function:: delay_us(delay) //| //| Dedicated delay method used for very short delays. **Do not** do long delays //| because this stops all other functions from completing. Think of this as an empty @@ -87,7 +87,7 @@ STATIC mp_obj_t mcu_delay_us(mp_obj_t delay_obj) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mcu_delay_us_obj, mcu_delay_us); -//| .. method:: disable_interrupts() +//| .. function:: disable_interrupts() //| //| Disable all interrupts. Be very careful, this can stall everything. //| @@ -97,7 +97,7 @@ STATIC mp_obj_t mcu_disable_interrupts(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_disable_interrupts_obj, mcu_disable_interrupts); -//| .. method:: enable_interrupts() +//| .. function:: enable_interrupts() //| //| Enable the interrupts that were enabled at the last disable. //| @@ -107,7 +107,7 @@ STATIC mp_obj_t mcu_enable_interrupts(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_enable_interrupts_obj, mcu_enable_interrupts); -//| .. method:: on_next_reset(run_mode) +//| .. function:: on_next_reset(run_mode) //| //| Configure the run mode used the next time the microcontroller is reset but //| not powered down. @@ -132,7 +132,7 @@ STATIC mp_obj_t mcu_on_next_reset(mp_obj_t run_mode_obj) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mcu_on_next_reset_obj, mcu_on_next_reset); -//| .. method:: reset() +//| .. function:: reset() //| //| Reset the microcontroller. After reset, the microcontroller will enter the //| run mode last set by `on_next_reset`. @@ -148,11 +148,13 @@ STATIC mp_obj_t mcu_reset(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_reset_obj, mcu_reset); -//| .. attribute:: nvm +//| .. data:: nvm //| //| Available non-volatile memory. //| This object is the sole instance of `nvm.ByteArray` when available or ``None`` otherwise. //| +//| :type: nvm.ByteArray or None +//| //| :mod:`microcontroller.pin` --- Microcontroller pin names //| -------------------------------------------------------- diff --git a/shared-bindings/neopixel_write/__init__.c b/shared-bindings/neopixel_write/__init__.c index 05d6fd97a..1ee66337b 100644 --- a/shared-bindings/neopixel_write/__init__.c +++ b/shared-bindings/neopixel_write/__init__.c @@ -55,11 +55,11 @@ //| pixel_off = bytearray([0, 0, 0]) //| neopixel_write.neopixel_write(pin, pixel_off) //| -//| .. method:: neopixel_write.neopixel_write(digitalinout, buf) +//| .. function:: neopixel_write(digitalinout, buf) //| //| Write buf out on the given DigitalInOut. //| -//| :param ~digitalio.DigitalInOut gpio: the DigitalInOut to output with +//| :param ~digitalio.DigitalInOut digitalinout: the DigitalInOut to output with //| :param bytearray buf: The bytes to clock out. No assumption is made about color order //| STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) { diff --git a/shared-bindings/network/__init__.c b/shared-bindings/network/__init__.c index 1067ea549..01763a73c 100644 --- a/shared-bindings/network/__init__.c +++ b/shared-bindings/network/__init__.c @@ -49,7 +49,7 @@ //| It is used by the 'socket' module to look up a suitable //| NIC when a socket is created. //| -//| .. function:: route +//| .. function:: route() //| //| Returns a list of all configured NICs. //| diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c index 37939a07a..a7a90fb0d 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pulseio/PWMOut.c @@ -42,7 +42,7 @@ //| //| PWMOut can be used to output a PWM signal on a given pin. //| -//| .. class:: PWMOut(pin, \*, duty_cycle=0, frequency=500, variable_frequency=False) +//| .. class:: PWMOut(pin, *, duty_cycle=0, frequency=500, variable_frequency=False) //| //| Create a PWM object associated with the given pin. This allows you to //| write PWM signals out on the given pin. Frequency is fixed after init diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index 426ac4384..9f37c65c9 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -45,7 +45,7 @@ //| The pulsed signal consists of timed active and idle periods. Unlike PWM, //| there is no set duration for active and idle pairs. //| -//| .. class:: PulseIn(pin, maxlen=2, \*, idle_state=False) +//| .. class:: PulseIn(pin, maxlen=2, *, idle_state=False) //| //| Create a PulseIn object associated with the given pin. The object acts as //| a read-only sequence of pulse lengths with a given max length. When it is diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c index 085d4e690..6d04a9893 100644 --- a/shared-bindings/socket/__init__.c +++ b/shared-bindings/socket/__init__.c @@ -51,7 +51,7 @@ STATIC const mp_obj_type_t socket_type; //| .. currentmodule:: socket //| -//| .. class:: socket(family, type, proto, ...) +//| .. class:: socket(family, type, proto) //| //| Create a new socket //| diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 4db3a9fec..ba439b951 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -48,7 +48,7 @@ //| directly. //| -//| .. function:: mount(filesystem, mount_path, \*, readonly=False) +//| .. function:: mount(filesystem, mount_path, *, readonly=False) //| //| Mounts the given filesystem object at the given path. //| @@ -183,7 +183,7 @@ STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { //| this property can only be set when the device is writable by the //| microcontroller. //| - //| .. method:: mkfs + //| .. method:: mkfs() //| //| Format the block device, deleting any data that may have been there //| @@ -216,7 +216,7 @@ STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { //| //| Don't call this directly, call `storage.mount`. //| - //| .. method:: umount + //| .. method:: umount() //| //| Don't call this directly, call `storage.umount`. //| diff --git a/shared-bindings/struct/__init__.c b/shared-bindings/struct/__init__.c index 9240a15bb..ea14b3763 100644 --- a/shared-bindings/struct/__init__.c +++ b/shared-bindings/struct/__init__.c @@ -67,9 +67,9 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { } MP_DEFINE_CONST_FUN_OBJ_1(struct_calcsize_obj, struct_calcsize); -//| .. function:: pack(fmt, v1, v2, ...) +//| .. function:: pack(fmt, *values) //| -//| Pack the values v1, v2, ... according to the format string fmt. +//| Pack the values according to the format string fmt. //| The return value is a bytes object encoding the values. //| @@ -85,9 +85,9 @@ STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack); -//| .. function:: pack_into(fmt, buffer, offset, v1, v2, ...) +//| .. function:: pack_into(fmt, buffer, offset, *values) //| -//| Pack the values v1, v2, ... according to the format string fmt into a buffer +//| Pack the values according to the format string fmt into a buffer //| starting at offset. offset may be negative to count from the end of buffer. //| diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c index 3babe2db4..70c01c2d8 100644 --- a/shared-bindings/time/__init__.c +++ b/shared-bindings/time/__init__.c @@ -47,7 +47,7 @@ //| written in MicroPython will work in CPython but not necessarily the other //| way around. //| -//| .. method:: monotonic() +//| .. function:: monotonic() //| //| Returns an always increasing value of time with an unknown reference //| point. Only use it to compare against other values from `monotonic`. @@ -62,7 +62,7 @@ STATIC mp_obj_t time_monotonic(void) { } MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_obj, time_monotonic); -//| .. method:: sleep(seconds) +//| .. function:: sleep(seconds) //| //| Sleep for a given number of seconds. //| @@ -95,19 +95,20 @@ mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp return namedtuple_make_new(type, 9, tuple->items, NULL); } -//| .. class:: struct_time((tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)) +//| .. class:: struct_time(time_tuple) //| //| Structure used to capture a date and time. Note that it takes a tuple! //| -//| :param int tm_year: the year, 2017 for example -//| :param int tm_mon: the month, range [1, 12] -//| :param int tm_mday: the day of the month, range [1, 31] -//| :param int tm_hour: the hour, range [0, 23] -//| :param int tm_min: the minute, range [0, 59] -//| :param int tm_sec: the second, range [0, 61] -//| :param int tm_wday: the day of the week, range [0, 6], Monday is 0 -//| :param int tm_yday: the day of the year, range [1, 366], -1 indicates not known -//| :param int tm_isdst: 1 when in daylight savings, 0 when not, -1 if unknown. +//| :param Tuple[tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst] time_tuple: Tuple of time info. +//| * the year, 2017 for example +//| * the month, range [1, 12] +//| * the day of the month, range [1, 31] +//| * the hour, range [0, 23] +//| * the minute, range [0, 59] +//| * the second, range [0, 61] +//| * the day of the week, range [0, 6], Monday is 0 +//| * the day of the year, range [1, 366], -1 indicates not known +//| * 1 when in daylight savings, 0 when not, -1 if unknown. //| const mp_obj_namedtuple_type_t struct_time_type_obj = { .base = { @@ -190,7 +191,7 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) { mp_raise_RuntimeError(translate("RTC is not supported on this board")); } -//| .. method:: time() +//| .. function:: time() //| //| Return the current time in seconds since since Jan 1, 1970. //| @@ -206,7 +207,7 @@ STATIC mp_obj_t time_time(void) { } MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); -//| .. method:: monotonic_ns() +//| .. function:: monotonic_ns() //| //| Return the time of the specified clock clk_id in nanoseconds. //| @@ -219,7 +220,7 @@ STATIC mp_obj_t time_monotonic_ns(void) { } MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_ns_obj, time_monotonic_ns); -//| .. method:: localtime([secs]) +//| .. function:: localtime([secs]) //| //| Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in //| local time. If secs is not provided or None, the current time as returned @@ -245,7 +246,7 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); -//| .. method:: mktime(t) +//| .. function:: mktime(t) //| //| This is the inverse function of localtime(). Its argument is the //| struct_time or full 9-tuple (since the dst flag is needed; use -1 as the diff --git a/shared-bindings/uheap/__init__.c b/shared-bindings/uheap/__init__.c index df18237ac..0d699cd28 100644 --- a/shared-bindings/uheap/__init__.c +++ b/shared-bindings/uheap/__init__.c @@ -38,7 +38,7 @@ //| :synopsis: Heap size analysis //| -//| .. method:: info(object) +//| .. function:: info(object) //| //| Prints memory debugging info for the given object and returns the //| estimated size. diff --git a/shared-bindings/ustack/__init__.c b/shared-bindings/ustack/__init__.c index c4391c132..08b772e41 100644 --- a/shared-bindings/ustack/__init__.c +++ b/shared-bindings/ustack/__init__.c @@ -39,7 +39,7 @@ //| #if MICROPY_MAX_STACK_USAGE -//| .. method:: max_stack_usage() +//| .. function:: max_stack_usage() //| //| Return the maximum excursion of the stack so far. //| @@ -50,7 +50,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(max_stack_usage_obj, max_stack_usage); #endif // MICROPY_MAX_STACK_USAGE -//| .. method:: stack_size() +//| .. function:: stack_size() //| //| Return the size of the entire stack. //| Same as in micropython.mem_info(), but returns a value instead @@ -61,7 +61,7 @@ STATIC mp_obj_t stack_size(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(stack_size_obj, stack_size); -//| .. method:: stack_usage() +//| .. function:: stack_usage() //| //| Return how much stack is currently in use. //| Same as micropython.stack_use(); duplicated here for convenience. diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c index 878095b2a..ac89cc691 100644 --- a/shared-bindings/wiznet/wiznet5k.c +++ b/shared-bindings/wiznet/wiznet5k.c @@ -138,7 +138,7 @@ const mp_obj_property_t wiznet5k_dhcp_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| .. method:: ifconfig(...) +//| .. method:: ifconfig(params=None) //| //| Called without parameters, returns a tuple of //| (ip_address, subnet_mask, gateway_address, dns_server) -- cgit v1.2.3 From 12f1d9d30cf6e8c73db2eac5512c332cfde3031f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 31 May 2019 18:03:05 -0400 Subject: fix advertisement length check; add Service.secondary attribute --- ports/nrf/common-hal/bleio/Peripheral.c | 2 +- shared-bindings/bleio/Service.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 83191d487..4aff75c9b 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -52,7 +52,7 @@ static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; STATIC void check_data_fit(size_t pos, size_t data_len) { - if (pos + data_len >= BLE_GAP_ADV_SET_DATA_SIZE_MAX) { + if (pos + data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX) { mp_raise_ValueError(translate("Data too large for advertisement packet")); } } diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index c3be26260..d9bc4021f 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -118,6 +118,24 @@ const mp_obj_property_t bleio_service_characteristics_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| .. attribute:: secondary +//| +//| True if this is a secondary service. (read-only) +//| +STATIC mp_obj_t bleio_service_get_secondary(mp_obj_t self_in) { + bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_bool(self->is_secondary); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_secondary_obj, bleio_service_get_secondary); + +const mp_obj_property_t bleio_service_secondary_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_service_get_secondary_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| .. attribute:: uuid //| //| The UUID of this service. (read-only) @@ -138,6 +156,7 @@ const mp_obj_property_t bleio_service_uuid_obj = { STATIC const mp_rom_map_elem_t bleio_service_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_characteristics), MP_ROM_PTR(&bleio_service_characteristics_obj) }, + { MP_ROM_QSTR(MP_QSTR_secondary), MP_ROM_PTR(&bleio_service_secondary_obj) }, { MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_service_uuid_obj) }, }; -- cgit v1.2.3 From 63ac37946df041519ffa822fde292f3be6d1840c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 2 Jun 2019 23:21:30 -0400 Subject: 1. Remove advertising data construction in C: it's all done in Python now 2. Add scan response capability to advertising. --- ports/nrf/common-hal/bleio/Broadcaster.c | 2 +- ports/nrf/common-hal/bleio/Peripheral.c | 143 ++++--------------------------- ports/nrf/common-hal/bleio/Peripheral.h | 7 +- shared-bindings/bleio/Broadcaster.c | 2 +- shared-bindings/bleio/Peripheral.c | 26 ++++-- shared-bindings/bleio/Peripheral.h | 2 +- 6 files changed, 39 insertions(+), 143 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Broadcaster.c b/ports/nrf/common-hal/bleio/Broadcaster.c index a70209a7f..a9e2a04c3 100644 --- a/ports/nrf/common-hal/bleio/Broadcaster.c +++ b/ports/nrf/common-hal/bleio/Broadcaster.c @@ -39,7 +39,7 @@ static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; void common_hal_bleio_broadcaster_construct(bleio_broadcaster_obj_t *self, mp_float_t interval) { - common_hal_bleio_adapter_set_enabled(true); // TODO -- Do this somewhere else maybe bleio __init__ + common_hal_bleio_adapter_set_enabled(true); const mp_float_t min = BLE_GAP_ADV_INTERVAL_MIN * ADV_INTERVAL_UNIT_FLOAT_SECS; const mp_float_t max = BLE_GAP_ADV_INTERVAL_MAX * ADV_INTERVAL_UNIT_FLOAT_SECS; diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 4aff75c9b..ad28523ae 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -51,63 +51,15 @@ static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; -STATIC void check_data_fit(size_t pos, size_t data_len) { - if (pos + data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX) { +STATIC void check_data_fit(size_t data_len) { + if (data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX) { mp_raise_ValueError(translate("Data too large for advertisement packet")); } } -STATIC uint32_t add_services_to_advertisement(bleio_peripheral_obj_t *self, size_t* adv_data_pos_p, size_t uuid_len) { - uint32_t uuids_total_size = 0; - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); - uint32_t err_code = NRF_SUCCESS; - - check_data_fit(*adv_data_pos_p, 1 + 1); - - // Remember where length byte is; fill in later when we know the size. - const size_t length_pos = *adv_data_pos_p; - (*adv_data_pos_p)++; - - self->adv_data[(*adv_data_pos_p)++] = (uuid_len == 16) - ? BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE - : BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE; - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - uint8_t encoded_size = 0; - - // Skip services of the wrong length and secondary services. - if (common_hal_bleio_uuid_get_size(service->uuid) != uuid_len || service->is_secondary) { - continue; - } - - ble_uuid_t uuid; - bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); - - err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &(self->adv_data[*adv_data_pos_p])); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - check_data_fit(*adv_data_pos_p, encoded_size); - uuids_total_size += encoded_size; - (*adv_data_pos_p) += encoded_size; - } - - self->adv_data[length_pos] = 1 + uuids_total_size; // 1 for the field type. - return err_code; -} - - - -// if raw_data is a zero-length buffer, generate an advertising packet that advertises the -// services passed in when this Peripheral was created. -// If raw_data contains some bytes, use those bytes as the advertising packet. -// TODO: Generate the advertising packet in Python, not here. -STATIC uint32_t set_advertisement_data(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *raw_data) { +STATIC uint32_t start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { common_hal_bleio_adapter_set_enabled(true); - size_t adv_data_pos = 0; uint32_t err_code; GET_STR_DATA_LEN(self->name, name_data, name_len); @@ -115,86 +67,18 @@ STATIC uint32_t set_advertisement_data(bleio_peripheral_obj_t *self, bool connec ble_gap_conn_sec_mode_t sec_mode; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - // We'll add the name after everything else, shortening it if necessary. err_code = sd_ble_gap_device_name_set(&sec_mode, name_data, name_len); if (err_code != NRF_SUCCESS) { return err_code; } } - if (raw_data->len != 0) { - // User-supplied advertising packet. - check_data_fit(adv_data_pos, raw_data->len); - memcpy(&(self->adv_data[adv_data_pos]), raw_data->buf, raw_data->len); - adv_data_pos += raw_data->len; - } else { - // Build up advertising packet. - check_data_fit(adv_data_pos, 1 + 1 + 1); - self->adv_data[adv_data_pos++] = 2; - self->adv_data[adv_data_pos++] = BLE_GAP_AD_TYPE_FLAGS; - self->adv_data[adv_data_pos++] = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; - - // The 16-bit ids and 128-bit ids are grouped together by length, so find it whether we have - // 16 and/or 128-bit service UUIDs. - - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); - if (service_list->len > 0) { - bool has_128bit_services = false; - bool has_16bit_services = false; - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - - if (service->is_secondary) { - continue; - } - - switch (common_hal_bleio_uuid_get_size(service->uuid)) { - case 16: - has_16bit_services = true; - break; - case 128: - has_128bit_services = true; - break; - } - } - - // Add 16-bit service UUID's in a group, then 128-bit service UUID's. - - if (has_16bit_services) { - err_code = add_services_to_advertisement(self, &adv_data_pos, 16); - if (err_code != NRF_SUCCESS) { - return err_code; - } - } - - if (has_128bit_services) { - err_code = add_services_to_advertisement(self, &adv_data_pos, 128); - if (err_code != NRF_SUCCESS) { - return err_code; - } - } - } + check_data_fit(advertising_data_bufinfo->len); + memcpy(self->advertising_data, advertising_data_bufinfo->buf, advertising_data_bufinfo->len); + + check_data_fit(scan_response_data_bufinfo->len); + memcpy(self->scan_response_data, scan_response_data_bufinfo->buf, scan_response_data_bufinfo->len); - // Always include TX power. - check_data_fit(adv_data_pos, 1 + 1 + 1); - self->adv_data[adv_data_pos++] = 1 + 1; - self->adv_data[adv_data_pos++] = BLE_GAP_AD_TYPE_TX_POWER_LEVEL; - self->adv_data[adv_data_pos++] = 0; // TODO - allow power level to be set later. - - // We need room for at least a one-character name. - check_data_fit(adv_data_pos, 1 + 1 + 1); - - // How big a name can we fit? - size_t bytes_left = BLE_GAP_ADV_SET_DATA_SIZE_MAX - adv_data_pos - 1 - 1; - size_t partial_name_len = MIN(bytes_left, name_len); - self->adv_data[adv_data_pos++] = 1 + partial_name_len; - self->adv_data[adv_data_pos++] = (partial_name_len == name_len) - ? BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME - : BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME; - memcpy(&(self->adv_data[adv_data_pos]), name_data, partial_name_len); - adv_data_pos += partial_name_len; - } // end of advertising packet construction static ble_gap_adv_params_t m_adv_params = { .interval = MSEC_TO_UNITS(1000, UNIT_0_625_MS), @@ -211,8 +95,10 @@ STATIC uint32_t set_advertisement_data(bleio_peripheral_obj_t *self, bool connec common_hal_bleio_peripheral_stop_advertising(self); const ble_gap_adv_data_t ble_gap_adv_data = { - .adv_data.p_data = self->adv_data, - .adv_data.len = adv_data_pos, + .adv_data.p_data = self->advertising_data, + .adv_data.len = advertising_data_bufinfo->len, + .scan_rsp_data.p_data = scan_response_data_bufinfo-> len > 0 ? self->scan_response_data : NULL, + .scan_rsp_data.len = scan_response_data_bufinfo->len, }; err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); @@ -322,12 +208,13 @@ bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self) { return self->conn_handle != BLE_CONN_HANDLE_INVALID; } -void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *raw_data) { +void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { if (connectable) { ble_drv_add_event_handler(peripheral_on_ble_evt, self); } - const uint32_t err_code = set_advertisement_data(self, connectable, raw_data); + const uint32_t err_code = start_advertising(self, connectable, + advertising_data_bufinfo, scan_response_data_bufinfo); if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to start advertising, err 0x%04x"), err_code); } diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index b255fe9f4..bf1931dda 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -43,10 +43,11 @@ typedef struct { mp_obj_t service_list; mp_obj_t notif_handler; mp_obj_t conn_handler; - // The advertising data buffer is held by us, not by the SD, so we must - // maintain it and not change it. If we need to change its contents during advertising, + // The advertising data and scan response buffers are held by us, not by the SD, so we must + // maintain them and not change it. If we need to change the contents during advertising, // there are tricks to get the SD to notice (see DevZone - TBS). - uint8_t adv_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; + uint8_t advertising_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; + uint8_t scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; } bleio_peripheral_obj_t; diff --git a/shared-bindings/bleio/Broadcaster.c b/shared-bindings/bleio/Broadcaster.c index 209e66490..294f1a83a 100644 --- a/shared-bindings/bleio/Broadcaster.c +++ b/shared-bindings/bleio/Broadcaster.c @@ -82,7 +82,7 @@ STATIC mp_obj_t bleio_broadcaster_make_new(const mp_obj_type_t *type, size_t n_a //| //| Start advertising using the given data packet. //| -//| :param buf data: advertising data packet, starting with advertising data flags (0x01) +//| :param buf data: advertising data packet //| STATIC mp_obj_t bleio_broadcaster_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_broadcaster_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 340485f35..960b3723c 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -68,7 +68,8 @@ static const char default_name[] = "CIRCUITPY"; //| //| # Create a peripheral and start it up. //| periph = bleio.Peripheral([service]) -//| periph.start_advertising() +//| adv = ServerAdvertisement(periph) +//| periph.start_advertising(adv.advertising_data_bytes, adv.scan_response_bytes) //| //| while not periph.connected: //| # Wait for connection. @@ -181,33 +182,40 @@ const mp_obj_property_t bleio_peripheral_name_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| .. method:: start_advertising(*, connectable=True, data=None) +//| .. method:: start_advertising(data, *, scan_response=None, connectable=True) //| //| Starts advertising the peripheral. The peripheral's name and //| services are included in the advertisement packets. //| +//| :param buf data: advertising data packet bytes +//| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed. //| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral. -//| :param buf data: If `None`, advertise the services passed to this Peripheral when it was created. -//| If not `None`, then send the bytes in ``data`` as the advertising packet. +//| //| STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_connectable, ARG_data }; + enum { ARG_data, ARG_scan_response, ARG_connectable }; static const mp_arg_t allowed_args[] = { + { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_scan_response, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_connectable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, - { MP_QSTR_data, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_buffer_info_t bufinfo = { 0 }; + mp_buffer_info_t data_bufinfo; + mp_get_buffer_raise(args[ARG_data].u_obj, &data_bufinfo, MP_BUFFER_READ); + + // Pass an empty buffer if scan_response not provided. + mp_buffer_info_t scan_response_bufinfo = { 0 }; if (args[ARG_data].u_obj != mp_const_none) { - mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(args[ARG_scan_response].u_obj, &scan_response_bufinfo, MP_BUFFER_READ); } - common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, &bufinfo); + common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, + &data_bufinfo, &scan_response_bufinfo); return mp_const_none; } diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index 02a5c1ef8..c09c60088 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -34,7 +34,7 @@ extern const mp_obj_type_t bleio_peripheral_type; extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self); extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self); -extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, mp_buffer_info_t *raw_data); +extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_PERIPHERAL_H -- cgit v1.2.3 From 613e12f99fd101a2c6b4b738da398a270aede538 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 3 Jun 2019 20:40:05 -0400 Subject: Replace Broadcaster with enhanced Peripheral --- ports/nrf/common-hal/bleio/Broadcaster.c | 98 ---------------------- ports/nrf/common-hal/bleio/Peripheral.c | 117 +++++++++++++------------- ports/nrf/common-hal/bleio/Peripheral.h | 1 + py/circuitpy_defns.mk | 2 - shared-bindings/bleio/AdvertisementData.c | 90 -------------------- shared-bindings/bleio/Broadcaster.c | 132 ------------------------------ shared-bindings/bleio/Broadcaster.h | 38 --------- shared-bindings/bleio/Device.c | 1 - shared-bindings/bleio/Device.h | 1 - shared-bindings/bleio/Peripheral.c | 46 ++++++++--- shared-bindings/bleio/Peripheral.h | 2 +- shared-bindings/bleio/__init__.c | 5 -- shared-module/bleio/AdvertisementData.h | 7 -- 13 files changed, 90 insertions(+), 450 deletions(-) delete mode 100644 ports/nrf/common-hal/bleio/Broadcaster.c delete mode 100644 shared-bindings/bleio/AdvertisementData.c delete mode 100644 shared-bindings/bleio/Broadcaster.c delete mode 100644 shared-bindings/bleio/Broadcaster.h (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Broadcaster.c b/ports/nrf/common-hal/bleio/Broadcaster.c deleted file mode 100644 index a9e2a04c3..000000000 --- a/ports/nrf/common-hal/bleio/Broadcaster.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Dan Halbert for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "ble.h" -#include "ble_drv.h" -#include "ble_hci.h" -#include "nrf_soc.h" -#include "py/runtime.h" - -#include "common-hal/bleio/Broadcaster.h" -#include "shared-bindings/bleio/Adapter.h" -#include "shared-bindings/bleio/Broadcaster.h" - -static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; - -void common_hal_bleio_broadcaster_construct(bleio_broadcaster_obj_t *self, mp_float_t interval) { - common_hal_bleio_adapter_set_enabled(true); - const mp_float_t min = BLE_GAP_ADV_INTERVAL_MIN * ADV_INTERVAL_UNIT_FLOAT_SECS; - const mp_float_t max = BLE_GAP_ADV_INTERVAL_MAX * ADV_INTERVAL_UNIT_FLOAT_SECS; - - if (interval < min || interval > max) { - // Would like to print range using the constants above, but vargs would convert to double. - mp_raise_ValueError(translate("interval not in range 0.0020 to 10.24")); - } - self->interval = interval; -} - - -void common_hal_bleio_broadcaster_start_advertising(bleio_broadcaster_obj_t *self, mp_buffer_info_t *data) { - uint32_t err_code; - - if (data->len >= BLE_GAP_ADV_SET_DATA_SIZE_MAX) { - mp_raise_ValueError(translate("Data too large for advertisement packet")); - } - memcpy(self->adv_data, data->buf, data->len); - - ble_gap_adv_params_t m_adv_params = { - .interval = (uint32_t) (self->interval / ADV_INTERVAL_UNIT_FLOAT_SECS), - .properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED, - .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, - .filter_policy = BLE_GAP_ADV_FP_ANY, - .primary_phy = BLE_GAP_PHY_1MBPS, - }; - - common_hal_bleio_broadcaster_stop_advertising(self); - - const ble_gap_adv_data_t ble_gap_adv_data = { - .adv_data.p_data = self->adv_data, - .adv_data.len = data->len, - }; - - err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); - if (err_code == NRF_SUCCESS) { - err_code = sd_ble_gap_adv_start(m_adv_handle, BLE_CONN_CFG_TAG_CUSTOM); - } - - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg_varg(translate("Failed to start advertising, err 0x%04x"), err_code); - } -} - -void common_hal_bleio_broadcaster_stop_advertising(bleio_broadcaster_obj_t *self) { - - if (m_adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) { - return; - } - - const uint32_t err_code = sd_ble_gap_adv_stop(m_adv_handle); - - if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE)) { - mp_raise_OSError_msg_varg(translate("Failed to stop advertising, err 0x%04x"), err_code); - } -} diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index ad28523ae..2cd52841a 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -49,68 +49,12 @@ #define BLE_ADV_AD_TYPE_FIELD_SIZE 1 #define BLE_AD_TYPE_FLAGS_DATA_SIZE 1 -static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; - STATIC void check_data_fit(size_t data_len) { if (data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX) { mp_raise_ValueError(translate("Data too large for advertisement packet")); } } -STATIC uint32_t start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { - common_hal_bleio_adapter_set_enabled(true); - - uint32_t err_code; - - GET_STR_DATA_LEN(self->name, name_data, name_len); - if (name_len > 0) { - ble_gap_conn_sec_mode_t sec_mode; - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - - err_code = sd_ble_gap_device_name_set(&sec_mode, name_data, name_len); - if (err_code != NRF_SUCCESS) { - return err_code; - } - } - - check_data_fit(advertising_data_bufinfo->len); - memcpy(self->advertising_data, advertising_data_bufinfo->buf, advertising_data_bufinfo->len); - - check_data_fit(scan_response_data_bufinfo->len); - memcpy(self->scan_response_data, scan_response_data_bufinfo->buf, scan_response_data_bufinfo->len); - - - static ble_gap_adv_params_t m_adv_params = { - .interval = MSEC_TO_UNITS(1000, UNIT_0_625_MS), - .properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED, - .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, - .filter_policy = BLE_GAP_ADV_FP_ANY, - .primary_phy = BLE_GAP_PHY_1MBPS, - }; - - if (!connectable) { - m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED; - } - - common_hal_bleio_peripheral_stop_advertising(self); - - const ble_gap_adv_data_t ble_gap_adv_data = { - .adv_data.p_data = self->advertising_data, - .adv_data.len = advertising_data_bufinfo->len, - .scan_rsp_data.p_data = scan_response_data_bufinfo-> len > 0 ? self->scan_response_data : NULL, - .scan_rsp_data.len = scan_response_data_bufinfo->len, - }; - - err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - err_code = sd_ble_gap_adv_start(m_adv_handle, BLE_CONN_CFG_TAG_CUSTOM); - - return err_code; -} - STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { bleio_peripheral_obj_t *self = (bleio_peripheral_obj_t*)self_in; @@ -172,12 +116,12 @@ STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { } } - void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self) { common_hal_bleio_adapter_set_enabled(true); self->gatt_role = GATT_ROLE_SERVER; self->conn_handle = BLE_CONN_HANDLE_INVALID; + self->adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; // Add all the services. @@ -208,13 +152,62 @@ bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self) { return self->conn_handle != BLE_CONN_HANDLE_INVALID; } -void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { +void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_float_t interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { + + // interval value has already been validated. + if (connectable) { ble_drv_add_event_handler(peripheral_on_ble_evt, self); } - const uint32_t err_code = start_advertising(self, connectable, - advertising_data_bufinfo, scan_response_data_bufinfo); + common_hal_bleio_adapter_set_enabled(true); + + uint32_t err_code; + + GET_STR_DATA_LEN(self->name, name_data, name_len); + if (name_len > 0) { + ble_gap_conn_sec_mode_t sec_mode; + BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); + + err_code = sd_ble_gap_device_name_set(&sec_mode, name_data, name_len); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg_varg(translate("Failed to set device name, err 0x%04x"), err_code); + + } + } + + check_data_fit(advertising_data_bufinfo->len); + memcpy(self->advertising_data, advertising_data_bufinfo->buf, advertising_data_bufinfo->len); + + check_data_fit(scan_response_data_bufinfo->len); + memcpy(self->scan_response_data, scan_response_data_bufinfo->buf, scan_response_data_bufinfo->len); + + + ble_gap_adv_params_t adv_params = { + .interval = SEC_TO_UNITS(interval, UNIT_0_625_MS), + .properties.type = connectable ? BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED + : BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED, + .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, + .filter_policy = BLE_GAP_ADV_FP_ANY, + .primary_phy = BLE_GAP_PHY_1MBPS, + }; + + common_hal_bleio_peripheral_stop_advertising(self); + + const ble_gap_adv_data_t ble_gap_adv_data = { + .adv_data.p_data = self->advertising_data, + .adv_data.len = advertising_data_bufinfo->len, + .scan_rsp_data.p_data = scan_response_data_bufinfo-> len > 0 ? self->scan_response_data : NULL, + .scan_rsp_data.len = scan_response_data_bufinfo->len, + }; + + err_code = sd_ble_gap_adv_set_configure(&self->adv_handle, &ble_gap_adv_data, &adv_params); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg_varg(translate("Failed to configure advertising, err 0x%04x"), err_code); + } + + err_code = sd_ble_gap_adv_start(self->adv_handle, BLE_CONN_CFG_TAG_CUSTOM); + if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to start advertising, err 0x%04x"), err_code); } @@ -222,10 +215,10 @@ void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *self) { - if (m_adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) + if (self->adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) return; - const uint32_t err_code = sd_ble_gap_adv_stop(m_adv_handle); + const uint32_t err_code = sd_ble_gap_adv_stop(self->adv_handle); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE)) { mp_raise_OSError_msg_varg(translate("Failed to stop advertising, err 0x%04x"), err_code); diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index bf1931dda..58526fc48 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -48,6 +48,7 @@ typedef struct { // there are tricks to get the SD to notice (see DevZone - TBS). uint8_t advertising_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; uint8_t scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; + uint8_t adv_handle; } bleio_peripheral_obj_t; diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 1aca33901..31af38d8d 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -221,7 +221,6 @@ $(filter $(SRC_PATTERNS), \ audioio/AudioOut.c \ bleio/__init__.c \ bleio/Adapter.c \ - bleio/Broadcaster.c \ bleio/Characteristic.c \ bleio/CharacteristicBuffer.c \ bleio/Descriptor.c \ @@ -285,7 +284,6 @@ SRC_BINDINGS_ENUMS += \ $(filter $(SRC_PATTERNS), \ bleio/Address.c \ bleio/AddressType.c \ - bleio/AdvertisementData.c \ bleio/ScanEntry.c \ ) diff --git a/shared-bindings/bleio/AdvertisementData.c b/shared-bindings/bleio/AdvertisementData.c deleted file mode 100644 index 9cfdd74e9..000000000 --- a/shared-bindings/bleio/AdvertisementData.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" -#include "shared-module/bleio/AdvertisementData.h" - -//| .. currentmodule:: bleio -//| -//| :class:`AdvertisementData` -- data used during BLE advertising -//| ============================================================== -//| -//| Represents the data to be broadcast during BLE advertising. -//| - -STATIC const mp_rom_map_elem_t bleio_advertisementdata_locals_dict_table[] = { - // Static variables - { MP_ROM_QSTR(MP_QSTR_FLAGS), MP_ROM_INT(AdFlags) }, - { MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_16BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf16BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_16BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf16BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_32BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf32BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_32BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf32BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_128BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf128BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_128BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf128BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_SHORTENED_LOCAL_NAME), MP_ROM_INT(AdShortenedLocalName) }, - { MP_ROM_QSTR(MP_QSTR_COMPLETE_LOCAL_NAME), MP_ROM_INT(AdCompleteLocalName) }, - { MP_ROM_QSTR(MP_QSTR_TX_POWER_LEVEL), MP_ROM_INT(AdTxPowerLevel) }, - { MP_ROM_QSTR(MP_QSTR_CLASS_OF_DEVICE), MP_ROM_INT(AdClassOfDevice) }, - { MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_HASH_C), MP_ROM_INT(AdSimplePairingHashC) }, - { MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_RANDOMIZER_R), MP_ROM_INT(AdSimplePairingRandomizerR) }, - { MP_ROM_QSTR(MP_QSTR_SECURITY_MANAGER_TK_VALUE), MP_ROM_INT(AdSecurityManagerTKValue) }, - { MP_ROM_QSTR(MP_QSTR_SECURITY_MANAGER_OOB_FLAGS), MP_ROM_INT(AdSecurityManagerOOBFlags) }, - { MP_ROM_QSTR(MP_QSTR_SLAVE_CONNECTION_INTERVAL_RANGE), MP_ROM_INT(AdSlaveConnectionIntervalRange) }, - { MP_ROM_QSTR(MP_QSTR_LIST_OF_16BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf16BitServiceSolicitationUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_LIST_OF_128BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf128BitServiceSolicitationUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_SERVICE_DATA), MP_ROM_INT(AdServiceData) }, - { MP_ROM_QSTR(MP_QSTR_PUBLIC_TARGET_ADDRESS), MP_ROM_INT(AdPublicTargetAddress) }, - { MP_ROM_QSTR(MP_QSTR_RANDOM_TARGET_ADDRESS), MP_ROM_INT(AdRandomTargetAddress) }, - { MP_ROM_QSTR(MP_QSTR_APPEARANCE), MP_ROM_INT(AdAppearance) }, - { MP_ROM_QSTR(MP_QSTR_ADVERTISING_INTERNAL), MP_ROM_INT(AdAdvertisingInterval) }, - { MP_ROM_QSTR(MP_QSTR_LE_BLUETOOTH_DEVICE_ADDRESS), MP_ROM_INT(AdLEBluetoothDeviceAddress) }, - { MP_ROM_QSTR(MP_QSTR_LE_ROLE), MP_ROM_INT(AdLERole) }, - { MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_HASH_C256), MP_ROM_INT(AdSimplePairingHashC256) }, - { MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_RANDOMIZER_R256), MP_ROM_INT(AdSimplePairingRandomizerR256) }, - { MP_ROM_QSTR(MP_QSTR_LIST_OF_32BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf32BitServiceSolicitationUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_SERVICE_DATA_32BIT_UUID), MP_ROM_INT(AdServiceData32BitUUID) }, - { MP_ROM_QSTR(MP_QSTR_SERVICE_DATA_128BIT_UUID), MP_ROM_INT(AdServiceData128BitUUID) }, - { MP_ROM_QSTR(MP_QSTR_LE_SECURE_CONNECTIONS_CONFIRMATION_VALUE), MP_ROM_INT(AdLESecureConnectionsConfirmationValue) }, - { MP_ROM_QSTR(MP_QSTR_LE_SECURE_CONNECTIONS_RANDOM_VALUE), MP_ROM_INT(AdLESecureConnectionsRandomValue) }, - { MP_ROM_QSTR(MP_QSTR_URI), MP_ROM_INT(AdURI) }, - { MP_ROM_QSTR(MP_QSTR_INDOOR_POSITIONING), MP_ROM_INT(AdIndoorPositioning) }, - { MP_ROM_QSTR(MP_QSTR_TRANSPORT_DISCOVERY_DATA), MP_ROM_INT(AdTransportDiscoveryData) }, - { MP_ROM_QSTR(MP_QSTR_LE_SUPPORTED_FEATURES), MP_ROM_INT(AdLESupportedFeatures) }, - { MP_ROM_QSTR(MP_QSTR_CHANNEL_MAP_UPDATE_INDICATION), MP_ROM_INT(AdChannelMapUpdateIndication) }, - { MP_ROM_QSTR(MP_QSTR_PB_ADV), MP_ROM_INT(AdPBADV) }, - { MP_ROM_QSTR(MP_QSTR_MESH_MESSAGE), MP_ROM_INT(AdMeshMessage) }, - { MP_ROM_QSTR(MP_QSTR_MESH_BEACON), MP_ROM_INT(AdMeshBeacon) }, - { MP_ROM_QSTR(MP_QSTR_3D_INFORMATION_DATA), MP_ROM_INT(Ad3DInformationData) }, - { MP_ROM_QSTR(MP_QSTR_MANUFACTURER_SPECIFIC_DATA), MP_ROM_INT(AdManufacturerSpecificData) }, -}; - -STATIC MP_DEFINE_CONST_DICT(bleio_advertisementdata_locals_dict, bleio_advertisementdata_locals_dict_table); - -const mp_obj_type_t bleio_advertisementdata_type = { - { &mp_type_type }, - .name = MP_QSTR_AdvertisementData, - .locals_dict = (mp_obj_dict_t*)&bleio_advertisementdata_locals_dict -}; diff --git a/shared-bindings/bleio/Broadcaster.c b/shared-bindings/bleio/Broadcaster.c deleted file mode 100644 index 294f1a83a..000000000 --- a/shared-bindings/bleio/Broadcaster.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Dan Halbert for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "ble_drv.h" -#include "py/runtime.h" - -#include "shared-bindings/bleio/Broadcaster.h" - -//| .. currentmodule:: bleio -//| -//| :class:`Broadcaster` -- Broadcast advertising packets. -//| ========================================================= -//| -//| Implement a BLE broadcaster which sends data in advertising packets and does not connect. -//| Used for beacons and other one-way data transmission. -//| -//| Usage:: -//| -//| import bleio -//| import time -//| -//| # Broadcast once a second. -//| broadcaster = bleio.Broadcaster(interval=1) -//| data = 0 -//| # Broadcast a byte of data that's incremented once a minute -//| while True: -//| # data is an entire advertising data packet, starting with flags. -//| broadcaster.start_advertising(data) -//| time.sleep(60) -//| data += 1 -//| -//| .. class:: Broadcaster(interval=1) -//| -//| Create a new Broadcaster object. - -//| :param float interval: how often to broadcast -//| - -STATIC mp_obj_t bleio_broadcaster_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_interval }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_interval, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_float_t interval = mp_obj_get_float(args[ARG_interval].u_obj); - - bleio_broadcaster_obj_t *self = m_new_obj(bleio_broadcaster_obj_t); - self->base.type = &bleio_broadcaster_type; - // Do port-specific initialization. interval will be validated. - common_hal_bleio_broadcaster_construct(self, interval); - - return MP_OBJ_FROM_PTR(self); -} - -//| .. method:: start_advertising(data) -//| -//| Start advertising using the given data packet. -//| -//| :param buf data: advertising data packet -//| -STATIC mp_obj_t bleio_broadcaster_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - bleio_broadcaster_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - - enum { ARG_data }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ); - - common_hal_bleio_broadcaster_start_advertising(self, &bufinfo); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_broadcaster_start_advertising_obj, 0, bleio_broadcaster_start_advertising); - -//| .. method:: stop_advertising() -//| -//| Stop sending advertising packets. -STATIC mp_obj_t bleio_broadcaster_stop_advertising(mp_obj_t self_in) { - bleio_broadcaster_obj_t *self = MP_OBJ_TO_PTR(self_in); - - common_hal_bleio_broadcaster_stop_advertising(self); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_broadcaster_stop_advertising_obj, bleio_broadcaster_stop_advertising); - -STATIC const mp_rom_map_elem_t bleio_broadcaster_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR_start_advertising), MP_ROM_PTR(&bleio_broadcaster_start_advertising_obj) }, - { MP_ROM_QSTR(MP_QSTR_stop_advertising), MP_ROM_PTR(&bleio_broadcaster_stop_advertising_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(bleio_broadcaster_locals_dict, bleio_broadcaster_locals_dict_table); - -const mp_obj_type_t bleio_broadcaster_type = { - { &mp_type_type }, - .name = MP_QSTR_Broadcaster, - .make_new = bleio_broadcaster_make_new, - .locals_dict = (mp_obj_dict_t*)&bleio_broadcaster_locals_dict -}; diff --git a/shared-bindings/bleio/Broadcaster.h b/shared-bindings/bleio/Broadcaster.h deleted file mode 100644 index 8aa125af9..000000000 --- a/shared-bindings/bleio/Broadcaster.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_BROADCASTER_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_BROADCASTER_H - -#include "common-hal/bleio/Broadcaster.h" - -extern const mp_obj_type_t bleio_broadcaster_type; - -extern void common_hal_bleio_broadcaster_construct(bleio_broadcaster_obj_t *self, mp_float_t interval); -extern void common_hal_bleio_broadcaster_start_advertising(bleio_broadcaster_obj_t *self, mp_buffer_info_t *data); -extern void common_hal_bleio_broadcaster_stop_advertising(bleio_broadcaster_obj_t *self); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_BROADCASTER_H diff --git a/shared-bindings/bleio/Device.c b/shared-bindings/bleio/Device.c index 80595ef33..fcdc84d27 100644 --- a/shared-bindings/bleio/Device.c +++ b/shared-bindings/bleio/Device.c @@ -39,7 +39,6 @@ #include "shared-bindings/bleio/Device.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/Device.h" #include "shared-module/bleio/ScanEntry.h" diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h index aebf1d639..1f85abe9a 100644 --- a/shared-bindings/bleio/Device.h +++ b/shared-bindings/bleio/Device.h @@ -27,7 +27,6 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/Device.h" #include "shared-module/bleio/Service.h" diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 960b3723c..1d657635f 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -40,14 +40,18 @@ #include "shared-bindings/bleio/Peripheral.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/ScanEntry.h" #include "common-hal/bleio/Peripheral.h" -// TODO: Add unique MAC address part to name static const char default_name[] = "CIRCUITPY"; +#define ADV_INTERVAL_DEFAULT (1.0f) +#define ADV_INTERVAL_MIN (0.0020f) +#define ADV_INTERVAL_MIN_STRING "0.0020" +#define ADV_INTERVAL_MAX (10.24f) +#define ADV_INTERVAL_MAX_STRING "10.24" + //| .. currentmodule:: bleio //| //| :class:`Peripheral` -- A BLE peripheral device @@ -75,19 +79,21 @@ static const char default_name[] = "CIRCUITPY"; //| # Wait for connection. //| pass //| -//| .. class:: Peripheral(services, *, name='CIRCUITPY') +//| .. class:: Peripheral(services=(), \*, name='CIRCUITPY') //| //| Create a new Peripheral object. -//| :param iterable services: the Service objects representing services available from this peripheral. -//| :param str name: The name used when advertising this peripheral +//| :param iterable services: the Service objects representing services available from this peripheral, if any. +//| A non-connectable peripheral will have no services. +//| :param str name: The name used when advertising this peripheral. Use ``None`` when a name is not needed, +//| such as when the peripheral is a beacon //| STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_services, ARG_name }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_services, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_name, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + { MP_QSTR_services, MP_ARG_OBJ, {.u_obj = mp_const_empty_tuple} }, + { MP_QSTR_name, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -112,8 +118,11 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar } const mp_obj_t name = args[ARG_name].u_obj; - if (name == mp_const_none) { + if (name == MP_OBJ_NULL) { self->name = mp_obj_new_str(default_name, strlen(default_name)); + } else if (name == mp_const_none) { + // Make None be the empty string. + self->name = MP_OBJ_NEW_QSTR(MP_QSTR_); } else if (MP_OBJ_IS_STR(name)) { self->name = name; } else { @@ -182,7 +191,7 @@ const mp_obj_property_t bleio_peripheral_name_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| .. method:: start_advertising(data, *, scan_response=None, connectable=True) +//| .. method:: start_advertising(data, *, scan_response=None, connectable=True, interval=1) //| //| Starts advertising the peripheral. The peripheral's name and //| services are included in the advertisement packets. @@ -190,16 +199,17 @@ const mp_obj_property_t bleio_peripheral_name_obj = { //| :param buf data: advertising data packet bytes //| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed. //| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral. -//| +//| :param float interval: advertising interval, in seconds //| STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_data, ARG_scan_response, ARG_connectable }; + enum { ARG_data, ARG_scan_response, ARG_connectable, ARG_interval }; static const mp_arg_t allowed_args[] = { { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_scan_response, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_connectable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, + { MP_QSTR_interval, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -210,11 +220,21 @@ STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_ob // Pass an empty buffer if scan_response not provided. mp_buffer_info_t scan_response_bufinfo = { 0 }; - if (args[ARG_data].u_obj != mp_const_none) { + if (args[ARG_scan_response].u_obj != mp_const_none) { mp_get_buffer_raise(args[ARG_scan_response].u_obj, &scan_response_bufinfo, MP_BUFFER_READ); } - common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, + if (args[ARG_interval].u_obj == MP_OBJ_NULL) { + args[ARG_interval].u_obj = mp_obj_new_float(1.0F); + } + + const mp_float_t interval = mp_obj_float_get(args[ARG_interval].u_obj); + if (interval < ADV_INTERVAL_MIN || interval > ADV_INTERVAL_MAX) { + mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), + ADV_INTERVAL_MIN_STRING, ADV_INTERVAL_MAX_STRING); + } + + common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, interval, &data_bufinfo, &scan_response_bufinfo); return mp_const_none; diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index c09c60088..7ef45edcd 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -34,7 +34,7 @@ extern const mp_obj_type_t bleio_peripheral_type; extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self); extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self); -extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); +extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, float interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_PERIPHERAL_H diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 03aef2ece..4b98e4673 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -28,8 +28,6 @@ #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/AddressType.h" -#include "shared-bindings/bleio/AdvertisementData.h" -#include "shared-bindings/bleio/Broadcaster.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/CharacteristicBuffer.h" #include "shared-bindings/bleio/Descriptor.h" @@ -57,7 +55,6 @@ //| AddressType //| AdvertisementData //| Adapter -//| Broadcaster //| Characteristic //| CharacteristicBuffer // Work-in-progress classes are omitted, and marked as :orphan: in their files. @@ -79,8 +76,6 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) }, { MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) }, - { MP_ROM_QSTR(MP_QSTR_AdvertisementData), MP_ROM_PTR(&bleio_advertisementdata_type) }, - { MP_ROM_QSTR(MP_QSTR_Broadcaster), MP_ROM_PTR(&bleio_broadcaster_type) }, { MP_ROM_QSTR(MP_QSTR_Characteristic), MP_ROM_PTR(&bleio_characteristic_type) }, { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) }, // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, diff --git a/shared-module/bleio/AdvertisementData.h b/shared-module/bleio/AdvertisementData.h index 738d53b23..66855172a 100644 --- a/shared-module/bleio/AdvertisementData.h +++ b/shared-module/bleio/AdvertisementData.h @@ -75,11 +75,4 @@ enum { AdManufacturerSpecificData = 0xFF, }; -typedef struct { - mp_obj_t device_name; - mp_obj_t services; - mp_obj_t data; - bool connectable; -} bleio_advertisement_data_t; - #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H -- cgit v1.2.3 From 1da8d4b4da7b71a68d367601e10b4633606fab56 Mon Sep 17 00:00:00 2001 From: Elvis Pfützenreuter Date: Wed, 15 May 2019 23:29:34 -0300 Subject: Add PS/2 support -- ps2io module --- locale/ID.po | 17 +- locale/circuitpython.pot | 17 +- locale/de_DE.po | 17 +- locale/en_US.po | 17 +- locale/en_x_pirate.po | 17 +- locale/es.po | 17 +- locale/fil.po | 17 +- locale/fr.po | 17 +- locale/it_IT.po | 17 +- locale/pl.po | 17 +- locale/pt_BR.po | 17 +- locale/zh_Latn_pinyin.po | 17 +- ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk | 2 + .../boards/datalore_ip_m4/mpconfigboard.mk | 2 + .../boards/feather_m4_express/mpconfigboard.mk | 2 + .../grandcentral_m4_express/mpconfigboard.mk | 2 + .../boards/itsybitsy_m4_express/mpconfigboard.mk | 2 + .../boards/metro_m4_airlift_lite/mpconfigboard.mk | 2 + .../boards/metro_m4_express/mpconfigboard.mk | 2 + .../atmel-samd/boards/mini_sam_m4/mpconfigboard.mk | 2 + .../boards/trellis_m4_express/mpconfigboard.mk | 2 + ports/atmel-samd/common-hal/ps2io/Ps2.c | 441 +++++++++++++++++++++ ports/atmel-samd/common-hal/ps2io/Ps2.h | 62 +++ ports/atmel-samd/common-hal/ps2io/__init__.c | 1 + ports/atmel-samd/eic_handler.c | 7 + ports/atmel-samd/eic_handler.h | 1 + ports/atmel-samd/supervisor/port.c | 1 + ports/atmel-samd/tools/gen_pin_name_table.py | 3 + py/circuitpy_defns.mk | 5 + py/circuitpy_mpconfig.h | 8 + py/circuitpy_mpconfig.mk | 6 + shared-bindings/index.rst | 1 + shared-bindings/ps2io/Ps2.c | 237 +++++++++++ shared-bindings/ps2io/Ps2.h | 45 +++ shared-bindings/ps2io/__init__.c | 73 ++++ shared-bindings/ps2io/__init__.h | 35 ++ 36 files changed, 1124 insertions(+), 24 deletions(-) create mode 100644 ports/atmel-samd/common-hal/ps2io/Ps2.c create mode 100644 ports/atmel-samd/common-hal/ps2io/Ps2.h create mode 100644 ports/atmel-samd/common-hal/ps2io/__init__.c create mode 100644 shared-bindings/ps2io/Ps2.c create mode 100644 shared-bindings/ps2io/Ps2.h create mode 100644 shared-bindings/ps2io/__init__.c create mode 100644 shared-bindings/ps2io/__init__.h (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index f5c0c0949..e9d26e2a6 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -518,6 +518,7 @@ msgid "Drive mode not used when direction is input." msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "Channel EXTINT sedang digunakan" @@ -546,6 +547,10 @@ msgstr "" msgid "Expected tuple of length %d, got %d" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c #, fuzzy msgid "Failed to acquire mutex" @@ -932,6 +937,10 @@ msgstr "Tidak ada GCLK yang kosong" msgid "No hardware random available" msgstr "" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -1015,6 +1024,10 @@ msgstr "" msgid "Plus any modules on the filesystem\n" msgstr "Tambahkan module apapun pada filesystem\n" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2176,7 +2189,7 @@ msgstr "" msgid "object not callable" msgstr "" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 34070dc69..ed58d75f0 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:41-0700\n" +"POT-Creation-Date: 2019-05-22 16:00-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -506,6 +506,7 @@ msgid "Drive mode not used when direction is input." msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "" @@ -534,6 +535,10 @@ msgstr "" msgid "Expected tuple of length %d, got %d" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c msgid "Failed to acquire mutex" msgstr "" @@ -907,6 +912,10 @@ msgstr "" msgid "No hardware random available" msgstr "" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -989,6 +998,10 @@ msgstr "" msgid "Plus any modules on the filesystem\n" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2131,7 +2144,7 @@ msgstr "" msgid "object not callable" msgstr "" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 2cb97c3d3..936aaffa2 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -510,6 +510,7 @@ msgid "Drive mode not used when direction is input." msgstr "Drive mode wird nicht verwendet, wenn die Richtung input ist." #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "EXTINT Kanal ist schon in Benutzung" @@ -538,6 +539,10 @@ msgstr "Eine UUID wird erwartet" msgid "Expected tuple of length %d, got %d" msgstr "Habe ein Tupel der Länge %d erwartet aber %d erhalten" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c msgid "Failed to acquire mutex" msgstr "Akquirieren des Mutex gescheitert" @@ -920,6 +925,10 @@ msgstr "Keine freien GCLKs" msgid "No hardware random available" msgstr "Kein hardware random verfügbar" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -1004,6 +1013,10 @@ msgstr "Pixel außerhalb der Puffergrenzen" msgid "Plus any modules on the filesystem\n" msgstr "und alle Module im Dateisystem \n" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2178,7 +2191,7 @@ msgstr "Objekt ist kein Iterator" msgid "object not callable" msgstr "" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "Objekt ist nicht in sequence" diff --git a/locale/en_US.po b/locale/en_US.po index ebc18cfae..cea074190 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -506,6 +506,7 @@ msgid "Drive mode not used when direction is input." msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "" @@ -534,6 +535,10 @@ msgstr "" msgid "Expected tuple of length %d, got %d" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c msgid "Failed to acquire mutex" msgstr "" @@ -907,6 +912,10 @@ msgstr "" msgid "No hardware random available" msgstr "" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -989,6 +998,10 @@ msgstr "" msgid "Plus any modules on the filesystem\n" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2131,7 +2144,7 @@ msgstr "" msgid "object not callable" msgstr "" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 04706abdc..6889c29b7 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -510,6 +510,7 @@ msgid "Drive mode not used when direction is input." msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "Avast! EXTINT channel already in use" @@ -538,6 +539,10 @@ msgstr "" msgid "Expected tuple of length %d, got %d" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c msgid "Failed to acquire mutex" msgstr "" @@ -911,6 +916,10 @@ msgstr "" msgid "No hardware random available" msgstr "" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -993,6 +1002,10 @@ msgstr "" msgid "Plus any modules on the filesystem\n" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2135,7 +2148,7 @@ msgstr "" msgid "object not callable" msgstr "" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "" diff --git a/locale/es.po b/locale/es.po index 77739f49c..f7f1ea0c4 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -524,6 +524,7 @@ msgid "Drive mode not used when direction is input." msgstr "Modo Drive no se usa cuando la dirección es input." #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "El canal EXTINT ya está siendo utilizado" @@ -554,6 +555,10 @@ msgstr "Se espera un %q" msgid "Expected tuple of length %d, got %d" msgstr "Se esperaba un tuple de %d, se obtuvo %d" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c #, fuzzy msgid "Failed to acquire mutex" @@ -946,6 +951,10 @@ msgstr "Sin GCLKs libres" msgid "No hardware random available" msgstr "No hay hardware random disponible" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -1035,6 +1044,10 @@ msgstr "" msgid "Plus any modules on the filesystem\n" msgstr "Incapaz de montar de nuevo el sistema de archivos" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2213,7 +2226,7 @@ msgstr "objeto no es un iterator" msgid "object not callable" msgstr "objeto no puede ser llamado" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "objeto no en secuencia" diff --git a/locale/fil.po b/locale/fil.po index 5954e29b4..73e6e79e7 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -519,6 +519,7 @@ msgid "Drive mode not used when direction is input." msgstr "Drive mode ay hindi ginagamit kapag ang direksyon ay input." #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "Ginagamit na ang EXTINT channel" @@ -549,6 +550,10 @@ msgstr "Umasa ng %q" msgid "Expected tuple of length %d, got %d" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c #, fuzzy msgid "Failed to acquire mutex" @@ -941,6 +946,10 @@ msgstr "Walang libreng GCLKs" msgid "No hardware random available" msgstr "Walang magagamit na hardware random" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -1028,6 +1037,10 @@ msgstr "" msgid "Plus any modules on the filesystem\n" msgstr "Kasama ang kung ano pang modules na sa filesystem\n" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2212,7 +2225,7 @@ msgstr "object ay hindi iterator" msgid "object not callable" msgstr "hindi matatawag ang object" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "object wala sa sequence" diff --git a/locale/fr.po b/locale/fr.po index 0bd0f8771..0362e1c49 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -522,6 +522,7 @@ msgid "Drive mode not used when direction is input." msgstr "Le mode Drive n'est pas utilisé quand la direction est 'input'." #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "Canal EXTINT déjà utilisé" @@ -552,6 +553,10 @@ msgstr "Un UUID est attendu" msgid "Expected tuple of length %d, got %d" msgstr "Tuple de longueur %d attendu, obtenu %d" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c #, fuzzy msgid "Failed to acquire mutex" @@ -949,6 +954,10 @@ msgstr "Pas de GCLK libre" msgid "No hardware random available" msgstr "Pas de source matérielle d'aléa disponible" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -1045,6 +1054,10 @@ msgstr "Pixel au-delà des limites du tampon" msgid "Plus any modules on the filesystem\n" msgstr "Ainsi que tout autre module présent sur le système de fichiers\n" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "Appuyez sur une touche pour entrer sur REPL ou CTRL-D pour recharger." @@ -2247,7 +2260,7 @@ msgstr "l'objet n'est pas un itérateur" msgid "object not callable" msgstr "objet non appelable" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "l'objet n'est pas dans la séquence" diff --git a/locale/it_IT.po b/locale/it_IT.po index 12f21c38e..760f00423 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -519,6 +519,7 @@ msgid "Drive mode not used when direction is input." msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "Canale EXTINT già in uso" @@ -549,6 +550,10 @@ msgstr "Atteso un %q" msgid "Expected tuple of length %d, got %d" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c #, fuzzy msgid "Failed to acquire mutex" @@ -940,6 +945,10 @@ msgstr "Nessun GCLK libero" msgid "No hardware random available" msgstr "Nessun generatore hardware di numeri casuali disponibile" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -1033,6 +1042,10 @@ msgstr "" msgid "Plus any modules on the filesystem\n" msgstr "Imposssibile rimontare il filesystem" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2208,7 +2221,7 @@ msgstr "l'oggetto non è un iteratore" msgid "object not callable" msgstr "" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "oggetto non in sequenza" diff --git a/locale/pl.po b/locale/pl.po index 1a7471f72..10752c703 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -509,6 +509,7 @@ msgid "Drive mode not used when direction is input." msgstr "Tryb sterowania nieużywany w trybie wejścia." #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "Kanał EXTINT w użyciu" @@ -537,6 +538,10 @@ msgstr "Oczekiwano UUID" msgid "Expected tuple of length %d, got %d" msgstr "Oczekiwano krotkę długości %d, otrzymano %d" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c msgid "Failed to acquire mutex" msgstr "Nie udało się uzyskać blokady" @@ -917,6 +922,10 @@ msgstr "Brak wolnych GLCK" msgid "No hardware random available" msgstr "Brak generatora liczb losowych" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -999,6 +1008,10 @@ msgstr "Piksel poza granicami bufora" msgid "Plus any modules on the filesystem\n" msgstr "Oraz moduły w systemie plików\n" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "Dowolny klawisz aby uruchomić konsolę. CTRL-D aby przeładować." @@ -2156,7 +2169,7 @@ msgstr "obiekt nie jest iteratorem" msgid "object not callable" msgstr "obiekt nie jest wywoływalny" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "obiektu nie ma sekwencji" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 390610041..e2b13cbd3 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -514,6 +514,7 @@ msgid "Drive mode not used when direction is input." msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "Canal EXTINT em uso" @@ -544,6 +545,10 @@ msgstr "Esperado um" msgid "Expected tuple of length %d, got %d" msgstr "" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "Falha ao enviar comando." + #: ports/nrf/common-hal/bleio/Device.c #, fuzzy msgid "Failed to acquire mutex" @@ -930,6 +935,10 @@ msgstr "Não há GCLKs livre" msgid "No hardware random available" msgstr "" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "Sem suporte de hardware no pino de clock" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -1016,6 +1025,10 @@ msgstr "" msgid "Plus any modules on the filesystem\n" msgstr "Não é possível remontar o sistema de arquivos" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "Buffer Ps2 vazio" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "" @@ -2165,7 +2178,7 @@ msgstr "" msgid "object not callable" msgstr "" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "objeto não em seqüência" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 82264cb52..dbc87115b 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-05-22 15:56-0300\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -510,6 +510,7 @@ msgid "Drive mode not used when direction is input." msgstr "Fāngxiàng shūrù shí qūdòng móshì méiyǒu shǐyòng." #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/atmel-samd/common-hal/ps2io/Ps2.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "EXTINT channel already in use" msgstr "EXTINT píndào yǐjīng shǐyòng" @@ -538,6 +539,10 @@ msgstr "Yùqí UUID" msgid "Expected tuple of length %d, got %d" msgstr "Qīwàng de chángdù wèi %d de yuán zǔ, dédào %d" +#: shared-bindings/ps2io/Ps2.c +msgid "Failed sending command." +msgstr "" + #: ports/nrf/common-hal/bleio/Device.c msgid "Failed to acquire mutex" msgstr "Wúfǎ huòdé mutex" @@ -917,6 +922,10 @@ msgstr "Méiyǒu miǎnfèi de GCLKs" msgid "No hardware random available" msgstr "Méiyǒu kěyòng de yìngjiàn suíjī" +#: ports/atmel-samd/common-hal/ps2io/Ps2.c +msgid "No hardware support on clk pin" +msgstr "" + #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c #: ports/atmel-samd/common-hal/pulseio/PulseIn.c msgid "No hardware support on pin" @@ -1004,6 +1013,10 @@ msgstr "Xiàngsù chāochū huǎnchōng qū biānjiè" msgid "Plus any modules on the filesystem\n" msgstr "Zài wénjiàn xìtǒng shàng tiānjiā rènhé mókuài\n" +#: shared-bindings/ps2io/Ps2.c +msgid "Pop from an empty Ps2 buffer" +msgstr "" + #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload." msgstr "Àn xià rènhé jiàn jìnrù REPL. Shǐyòng CTRL-D chóngxīn jiāzài." @@ -2168,7 +2181,7 @@ msgstr "duìxiàng bùshì diédài qì" msgid "object not callable" msgstr "duìxiàng wúfǎ diàoyòng" -#: py/sequence.c +#: py/sequence.c shared-bindings/displayio/Group.c msgid "object not in sequence" msgstr "duìxiàng bùshì xùliè" diff --git a/ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk b/ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk index 0444a37b9..c566795c4 100644 --- a/ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/cp32-m4/mpconfigboard.mk @@ -15,3 +15,5 @@ CIRCUITPY_TOUCHIO = 0 CHIP_VARIANT = SAMD51J20A CHIP_FAMILY = samd51 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk b/ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk index e6b21e25b..af1037c38 100644 --- a/ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk @@ -18,3 +18,5 @@ CIRCUITPY_TOUCHIO = 0 CIRCUITPY_NETWORK = 1 MICROPY_PY_WIZNET5K = 5500 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk index 4fddcffc1..5972b5e46 100644 --- a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk @@ -18,3 +18,5 @@ CHIP_FAMILY = samd51 CIRCUITPY_NETWORK = 1 MICROPY_PY_WIZNET5K = 5500 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/grandcentral_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/grandcentral_m4_express/mpconfigboard.mk index 63158681b..0ae23bdef 100644 --- a/ports/atmel-samd/boards/grandcentral_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/grandcentral_m4_express/mpconfigboard.mk @@ -15,3 +15,5 @@ CIRCUITPY_TOUCHIO = 0 CHIP_VARIANT = SAMD51P20A CHIP_FAMILY = samd51 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk index d4d674d9d..176935c38 100644 --- a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk @@ -16,3 +16,5 @@ CIRCUITPY_TOUCHIO = 0 CHIP_VARIANT = SAMD51G19A CHIP_FAMILY = samd51 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/metro_m4_airlift_lite/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m4_airlift_lite/mpconfigboard.mk index 654a84eb8..2a6191b36 100644 --- a/ports/atmel-samd/boards/metro_m4_airlift_lite/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m4_airlift_lite/mpconfigboard.mk @@ -18,3 +18,5 @@ CHIP_FAMILY = samd51 CIRCUITPY_NETWORK = 1 MICROPY_PY_WIZNET5K = 5500 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk index 35162b678..32e623e67 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk @@ -18,3 +18,5 @@ CHIP_FAMILY = samd51 CIRCUITPY_NETWORK = 1 MICROPY_PY_WIZNET5K = 5500 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk b/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk index 27bad2693..5f744dfd2 100644 --- a/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk @@ -17,3 +17,5 @@ CIRCUITPY_TOUCHIO = 0 CHIP_VARIANT = SAMD51G19A CHIP_FAMILY = samd51 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk index 93b07bc76..bfcada0d7 100644 --- a/ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/trellis_m4_express/mpconfigboard.mk @@ -16,3 +16,5 @@ CIRCUITPY_TOUCHIO = 0 CHIP_VARIANT = SAMD51G19A CHIP_FAMILY = samd51 + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/common-hal/ps2io/Ps2.c b/ports/atmel-samd/common-hal/ps2io/Ps2.c new file mode 100644 index 000000000..6a06864f2 --- /dev/null +++ b/ports/atmel-samd/common-hal/ps2io/Ps2.c @@ -0,0 +1,441 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Elvis Pfutzenreuter + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "common-hal/ps2io/Ps2.h" + +#include + +#include "atmel_start_pins.h" +#include "hal/include/hal_gpio.h" + +#include "background.h" +#include "eic_handler.h" +#include "mpconfigport.h" +#include "py/gc.h" +#include "py/runtime.h" +#include "samd/external_interrupts.h" +#include "samd/pins.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/ps2io/Ps2.h" +#include "supervisor/shared/translate.h" + +#include "tick.h" + +#define STATE_IDLE 0 +#define STATE_RECV 1 +#define STATE_RECV_PARITY 2 +#define STATE_RECV_STOP 3 +#define STATE_RECV_ERR 10 + +#define ERROR_STARTBIT 0x01 +#define ERROR_TIMEOUT 0x02 +#define ERROR_PARITY 0x04 +#define ERROR_STOPBIT 0x08 +#define ERROR_BUFFER 0x10 + +#define ERROR_TX_CLKLO 0x100 +#define ERROR_TX_CLKHI 0x200 +#define ERROR_TX_ACKDATA 0x400 +#define ERROR_TX_ACKCLK 0x800 +#define ERROR_TX_RTS 0x1000 +#define ERROR_TX_NORESP 0x2000 + +static void ps2_set_config(ps2io_ps2_obj_t* self) { + uint32_t sense_setting = EIC_CONFIG_SENSE0_FALL_Val; + set_eic_handler(self->channel, EIC_HANDLER_PS2); + turn_on_eic_channel(self->channel, sense_setting); +} + +static void disable_interrupt(ps2io_ps2_obj_t* self) { + uint32_t mask = 1 << self->channel; + EIC->INTENCLR.reg = mask << EIC_INTENSET_EXTINT_Pos; +} + +static void resume_interrupt(ps2io_ps2_obj_t* self) { + disable_interrupt(self); + + self->state = STATE_IDLE; + gpio_set_pin_function(self->clk_pin, GPIO_PIN_FUNCTION_A); + uint32_t mask = 1 << self->channel; + EIC->INTFLAG.reg = mask << EIC_INTFLAG_EXTINT_Pos; + EIC->INTENSET.reg = mask << EIC_INTENSET_EXTINT_Pos; + + ps2_set_config(self); +} + +static void clk_hi(ps2io_ps2_obj_t* self) { + // External pull-up + // Must set pull after setting direction. + gpio_set_pin_direction(self->clk_pin, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(self->clk_pin, GPIO_PULL_OFF); +} + +static bool wait_clk_lo(ps2io_ps2_obj_t* self, uint32_t us) { + clk_hi(self); + common_hal_mcu_delay_us(1); + while (gpio_get_pin_level(self->clk_pin) && us) { + --us; + common_hal_mcu_delay_us(1); + } + return us; +} + +static bool wait_clk_hi(ps2io_ps2_obj_t* self, uint32_t us) { + clk_hi(self); + common_hal_mcu_delay_us(1); + while (!gpio_get_pin_level(self->clk_pin) && us) { + --us; + common_hal_mcu_delay_us(1); + } + return us; +} + +static void clk_lo(ps2io_ps2_obj_t* self) { + gpio_set_pin_pull_mode(self->clk_pin, GPIO_PULL_OFF); + gpio_set_pin_direction(self->clk_pin, GPIO_DIRECTION_OUT); + gpio_set_pin_level(self->clk_pin, 0); +} + +static void data_hi(ps2io_ps2_obj_t* self) { + // External pull-up + gpio_set_pin_direction(self->data_pin, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(self->data_pin, GPIO_PULL_OFF); +} + +static bool wait_data_lo(ps2io_ps2_obj_t* self, uint32_t us) { + data_hi(self); + common_hal_mcu_delay_us(1); + while (gpio_get_pin_level(self->data_pin) && us) { + --us; + common_hal_mcu_delay_us(1); + } + return us; +} + +static bool wait_data_hi(ps2io_ps2_obj_t* self, uint32_t us) { + data_hi(self); + common_hal_mcu_delay_us(1); + while (!gpio_get_pin_level(self->data_pin) && us) { + --us; + common_hal_mcu_delay_us(1); + } + return us; +} + +static void data_lo(ps2io_ps2_obj_t* self) { + gpio_set_pin_pull_mode(self->data_pin, GPIO_PULL_OFF); + gpio_set_pin_direction(self->data_pin, GPIO_DIRECTION_OUT); + gpio_set_pin_level(self->data_pin, 0); +} + +static void idle(ps2io_ps2_obj_t* self) { + clk_hi(self); + data_hi(self); +} + +static void inhibit(ps2io_ps2_obj_t* self) { + clk_lo(self); + data_hi(self); +} + +static void delay_us(uint32_t t) { + common_hal_mcu_delay_us(t); +} + +void ps2_interrupt_handler(uint8_t channel) { + // Grab the current time first. + uint32_t current_us; + uint64_t current_ms; + current_tick(¤t_ms, ¤t_us); + + ps2io_ps2_obj_t* self = get_eic_channel_data(channel); + int data_bit = gpio_get_pin_level(self->data_pin) ? 1 : 0; + + // test for timeout + if (self->state != STATE_IDLE) { + int64_t diff_ms = current_ms - self->last_int_ms; + if (diff_ms >= 2) { // a.k.a. > 1.001ms + self->last_errors |= ERROR_TIMEOUT; + self->state = STATE_IDLE; + } + } + + self->last_int_us = current_us; + self->last_int_ms = current_ms; + + if (self->state == STATE_IDLE) { + self->bits = 0; + self->parity = false; + self->bitcount = 0; + self->state = STATE_RECV; + if (data_bit) { + // start bit should be 0 + self->last_errors |= ERROR_STARTBIT; + self->state = STATE_RECV_ERR; + } else { + self->state = STATE_RECV; + } + + } else if (self->state == STATE_RECV) { + if (data_bit) { + self->bits |= data_bit << self->bitcount; + self->parity = !self->parity; + } + ++self->bitcount; + if (self->bitcount >= 8) { + self->state = STATE_RECV_PARITY; + } + + } else if (self->state == STATE_RECV_PARITY) { + ++self->bitcount; + if (data_bit) { + self->parity = !self->parity; + } + if (!self->parity) { + self->last_errors |= ERROR_PARITY; + self->state = STATE_RECV_ERR; + } else { + self->state = STATE_RECV_STOP; + } + + } else if (self->state == STATE_RECV_STOP) { + ++self->bitcount; + if (! data_bit) { + self->last_errors |= ERROR_STOPBIT; + } else if (self->waiting_cmd_response) { + self->cmd_response = self->bits; + self->waiting_cmd_response = false; + } else if (self->bufcount >= sizeof(self->buffer)) { + self->last_errors |= ERROR_BUFFER; + } else { + self->buffer[self->bufposw] = self->bits; + self->bufposw = (self->bufposw + 1) % sizeof(self->buffer); + self->bufcount++; + } + self->state = STATE_IDLE; + + } else if (self->state == STATE_RECV_ERR) { + // just count the bits until idle + if (++self->bitcount >= 10) { + self->state = STATE_IDLE; + } + } +} + +void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t* self, + const mcu_pin_obj_t* data_pin, const mcu_pin_obj_t* clk_pin) { + if (!clk_pin->has_extint) { + mp_raise_RuntimeError(translate("No hardware support on clk pin")); + } + if (eic_get_enable() && !eic_channel_free(clk_pin->extint_channel)) { + mp_raise_RuntimeError(translate("EXTINT channel already in use")); + } + + clk_hi(self); + data_hi(self); + + self->channel = clk_pin->extint_channel; + self->clk_pin = clk_pin->number; + self->data_pin = data_pin->number; + self->state = STATE_IDLE; + self->bufcount = 0; + self->bufposr = 0; + self->bufposw = 0; + self->waiting_cmd_response = false; + + set_eic_channel_data(clk_pin->extint_channel, (void*) self); + + // Check to see if the EIC is enabled and start it up if its not.' + if (eic_get_enable() == 0) { + turn_on_external_interrupt_controller(); + } + + gpio_set_pin_function(clk_pin->number, GPIO_PIN_FUNCTION_A); + gpio_set_pin_function(data_pin->number, GPIO_PIN_FUNCTION_A); + + turn_on_cpu_interrupt(self->channel); + + claim_pin(clk_pin); + claim_pin(data_pin); + + // Set config will enable the EIC. + ps2_set_config(self); +} + +bool common_hal_ps2io_ps2_deinited(ps2io_ps2_obj_t* self) { + return self->clk_pin == NO_PIN; +} + +void common_hal_ps2io_ps2_deinit(ps2io_ps2_obj_t* self) { + if (common_hal_ps2io_ps2_deinited(self)) { + return; + } + set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT); + turn_off_eic_channel(self->channel); + reset_pin_number(self->clk_pin); + reset_pin_number(self->data_pin); + self->clk_pin = NO_PIN; + self->data_pin = NO_PIN; +} + +uint16_t common_hal_ps2io_ps2_get_len(ps2io_ps2_obj_t* self) { + return self->bufcount; +} + +bool common_hal_ps2io_ps2_get_paused(ps2io_ps2_obj_t* self) { + uint32_t mask = 1 << self->channel; + return (EIC->INTENSET.reg & (mask << EIC_INTENSET_EXTINT_Pos)) == 0; +} + +int16_t common_hal_ps2io_ps2_popleft(ps2io_ps2_obj_t* self) +{ + common_hal_mcu_disable_interrupts(); + if (self->bufcount <= 0) { + common_hal_mcu_enable_interrupts(); + return -1; + } + uint8_t b = self->buffer[self->bufposr]; + self->bufposr = (self->bufposr + 1) % sizeof(self->buffer); + self->bufcount -= 1; + common_hal_mcu_enable_interrupts(); + return b; +} + +uint16_t common_hal_ps2io_ps2_clear_errors(ps2io_ps2_obj_t* self) +{ + common_hal_mcu_disable_interrupts(); + uint16_t errors = self->last_errors; + self->last_errors = 0; + common_hal_mcu_enable_interrupts(); + return errors; +} + +// Based upon TMK implementation of PS/2 protocol +// https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/protocol/ps2_interrupt.c + +int16_t common_hal_ps2io_ps2_sendcmd(ps2io_ps2_obj_t* self, uint8_t b) +{ + disable_interrupt(self); + inhibit(self); + delay_us(100); + + /* RTS and start bit */ + data_lo(self); + clk_hi(self); + if (!wait_clk_lo(self, 10000)) { + self->last_errors |= ERROR_TX_RTS; + goto ERROR; + } + + bool parity = true; + for (uint8_t i = 0; i < 8; i++) { + delay_us(15); + if (b & (1 << i)) { + parity = !parity; + data_hi(self); + } else { + data_lo(self); + } + if (!wait_clk_hi(self, 50)) { + self->last_errors |= ERROR_TX_CLKHI; + goto ERROR; + } + if (!wait_clk_lo(self, 50)) { + self->last_errors |= ERROR_TX_CLKLO; + goto ERROR; + } + } + + delay_us(15); + if (parity) { + data_hi(self); + } else { + data_lo(self); + } + if (!wait_clk_hi(self, 50)) { + self->last_errors |= ERROR_TX_CLKHI; + goto ERROR; + } + if (!wait_clk_lo(self, 50)) { + self->last_errors |= ERROR_TX_CLKLO; + goto ERROR; + } + + /* Stop bit */ + delay_us(15); + data_hi(self); + + /* Ack */ + if (!wait_data_lo(self, 50)) { + self->last_errors |= ERROR_TX_ACKDATA; + goto ERROR; + } + if (!wait_clk_lo(self, 50)) { + self->last_errors |= ERROR_TX_ACKCLK; + goto ERROR; + } + + /* wait for idle state */ + if (!wait_clk_hi(self, 50)) { + self->last_errors |= ERROR_TX_ACKCLK; + goto ERROR; + } + if (!wait_data_hi(self, 50)) { + self->last_errors |= ERROR_TX_ACKDATA; + goto ERROR; + } + + /* Wait for response byte */ + self->waiting_cmd_response = true; + idle(self); + resume_interrupt(self); + + for (int i = 0; i < 25; ++i) { + delay_us(1000); + common_hal_mcu_disable_interrupts(); + bool has_response = !self->waiting_cmd_response; + uint8_t response = self->cmd_response; + common_hal_mcu_enable_interrupts(); + + if (has_response) { + return response; + } + } + + /* No response */ + common_hal_mcu_disable_interrupts(); + self->waiting_cmd_response = false; + self->last_errors |= ERROR_TX_NORESP; + common_hal_mcu_enable_interrupts(); + return -1; + + /* Other errors */ +ERROR: + idle(self); + resume_interrupt(self); + return -1; +} diff --git a/ports/atmel-samd/common-hal/ps2io/Ps2.h b/ports/atmel-samd/common-hal/ps2io/Ps2.h new file mode 100644 index 000000000..cce6ae474 --- /dev/null +++ b/ports/atmel-samd/common-hal/ps2io/Ps2.h @@ -0,0 +1,62 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Elvis Pfutzenreuter + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PS2IO_PS2_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PS2IO_PS2_H + +#include "common-hal/microcontroller/Pin.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + uint8_t channel; + uint8_t clk_pin; + uint8_t data_pin; + + uint8_t state; + uint64_t last_int_ms; + uint32_t last_int_us; + + uint16_t bits; + bool parity; + uint8_t bitcount; + + uint8_t buffer[16]; + uint8_t bufcount; + uint8_t bufposr; + uint8_t bufposw; + + uint16_t last_errors; + + bool waiting_cmd_response; + uint8_t cmd_response; +} ps2io_ps2_obj_t; + +void ps2_interrupt_handler(uint8_t channel); + +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PS2IO_PS2_H diff --git a/ports/atmel-samd/common-hal/ps2io/__init__.c b/ports/atmel-samd/common-hal/ps2io/__init__.c new file mode 100644 index 000000000..ba4b4249f --- /dev/null +++ b/ports/atmel-samd/common-hal/ps2io/__init__.c @@ -0,0 +1 @@ +// No ps2io module functions. diff --git a/ports/atmel-samd/eic_handler.c b/ports/atmel-samd/eic_handler.c index db5f260e5..30ecaa7ca 100644 --- a/ports/atmel-samd/eic_handler.c +++ b/ports/atmel-samd/eic_handler.c @@ -25,6 +25,7 @@ */ #include "common-hal/pulseio/PulseIn.h" +#include "common-hal/ps2io/Ps2.h" #include "common-hal/rotaryio/IncrementalEncoder.h" #include "shared-bindings/microcontroller/__init__.h" //#include "samd/external_interrupts.h" @@ -46,6 +47,12 @@ void shared_eic_handler(uint8_t channel) { break; #endif +#if CIRCUITPY_PS2IO + case EIC_HANDLER_PS2: + ps2_interrupt_handler(channel); + break; +#endif + #if CIRCUITPY_ROTARYIO case EIC_HANDLER_INCREMENTAL_ENCODER: incrementalencoder_interrupt_handler(channel); diff --git a/ports/atmel-samd/eic_handler.h b/ports/atmel-samd/eic_handler.h index 2f9ccd67f..71b0fce67 100644 --- a/ports/atmel-samd/eic_handler.h +++ b/ports/atmel-samd/eic_handler.h @@ -29,6 +29,7 @@ #define EIC_HANDLER_NO_INTERRUPT 0x0 #define EIC_HANDLER_PULSEIN 0x1 #define EIC_HANDLER_INCREMENTAL_ENCODER 0x2 +#define EIC_HANDLER_PS2 0x3 void set_eic_handler(uint8_t channel, uint8_t eic_handler); void shared_eic_handler(uint8_t channel); diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 4f53d30f9..37360deb0 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -52,6 +52,7 @@ #include "common-hal/pulseio/PulseIn.h" #include "common-hal/pulseio/PulseOut.h" #include "common-hal/pulseio/PWMOut.h" +#include "common-hal/ps2io/Ps2.h" #include "common-hal/rtc/RTC.h" #include "common-hal/touchio/TouchIn.h" #include "samd/cache.h" diff --git a/ports/atmel-samd/tools/gen_pin_name_table.py b/ports/atmel-samd/tools/gen_pin_name_table.py index 76c9cf255..ded64e5f6 100644 --- a/ports/atmel-samd/tools/gen_pin_name_table.py +++ b/ports/atmel-samd/tools/gen_pin_name_table.py @@ -156,6 +156,9 @@ capabilities = { "PA14", "PA15", "PA16", "PA17", "PA18", "PA19", "PA20", "PA21", "PA22", "PA23", "PA30", "PA31"] }, + "ps2io": { + "Ps2": ALL_BUT_USB, + }, "touchio": { "TouchIn": ["PA02", "PA03", "PB08", "PB09", "PA04", "PA05", "PA06", "PA07", "PB02", "PB03"] diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 1aca33901..722f06e93 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -162,6 +162,9 @@ endif ifeq ($(CIRCUITPY_PULSEIO),1) SRC_PATTERNS += pulseio/% endif +ifeq ($(CIRCUITPY_PS2IO),1) +SRC_PATTERNS += ps2io/% +endif ifeq ($(CIRCUITPY_RANDOM),1) SRC_PATTERNS += random/% endif @@ -252,6 +255,8 @@ $(filter $(SRC_PATTERNS), \ pulseio/PulseIn.c \ pulseio/PulseOut.c \ pulseio/__init__.c \ + ps2io/Ps2.c \ + ps2io/__init__.c \ rotaryio/IncrementalEncoder.c \ rotaryio/__init__.c \ rtc/RTC.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 0575bcfe0..c794759f8 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -416,6 +416,13 @@ extern const struct _mp_obj_module_t pulseio_module; #define PULSEIO_MODULE #endif +#if CIRCUITPY_PS2IO +extern const struct _mp_obj_module_t ps2io_module; +#define PS2IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ps2io), (mp_obj_t)&ps2io_module }, +#else +#define PS2IO_MODULE +#endif + #if CIRCUITPY_RANDOM extern const struct _mp_obj_module_t random_module; #define RANDOM_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, @@ -580,6 +587,7 @@ extern const struct _mp_obj_module_t ustack_module; PEW_MODULE \ PIXELBUF_MODULE \ PULSEIO_MODULE \ + PS2IO_MODULE \ RANDOM_MODULE \ RE_MODULE \ ROTARYIO_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index b436929e0..ed9b9f461 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -153,6 +153,12 @@ CIRCUITPY_PULSEIO = 1 endif CFLAGS += -DCIRCUITPY_PULSEIO=$(CIRCUITPY_PULSEIO) +# Only for SAMD boards for the moment +ifndef CIRCUITPY_PS2IO +CIRCUITPY_PS2IO = 0 +endif +CFLAGS += -DCIRCUITPY_PS2IO=$(CIRCUITPY_PS2IO) + ifndef CIRCUITPY_RANDOM CIRCUITPY_RANDOM = 1 endif diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index 4f2e28702..8f9bbbb31 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -53,6 +53,7 @@ Module Supported Ports `nvm` **SAMD Express** `os` **All Supported** `pulseio` **SAMD/SAMD Express** +`ps2io` **SAMD/SAMD Express** `random` **All Supported** `rotaryio` **SAMD51, SAMD Express** `storage` **All Supported** diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c new file mode 100644 index 000000000..bdbbf795c --- /dev/null +++ b/shared-bindings/ps2io/Ps2.c @@ -0,0 +1,237 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Elvis Pfutzenreuter + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/runtime0.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/ps2io/Ps2.h" +#include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: ps2io +//| +//| :class:`Ps2` -- Communicate with a PS/2 keyboard or mouse +//| ========================================================= +//| +//| Ps2 implements the PS/2 keyboard/mouse serial protocol, used in +//| legacy devices. It is similar to UART but there are only two +//| lines (Data and Clock). PS/2 devices are 5V, so bidirectional +//| level converters must be used to connect the I/O lines to pins +//| of 3.3V boards. +//| +//| .. class:: Ps2(data_pin, clock_pin) +//| +//| Create a Ps2 object associated with the given pins. +//| +//| :param ~microcontroller.Pin data_pin: Pin tied to data wire. +//| :param ~microcontroller.Pin clock_pin: Pin tied to clock wire. +//| This pin must support interrupts. +//| +//| Read one byte from PS/2 keyboard and turn on Scroll Lock LED:: +//| +//| import ps2io +//| import board +//| +//| kbd = ps2io.Ps2(board.D10, board.D11) +//| +//| while len(kbd) == 0: +//| pass +//| +//| print(kbd.popleft()) +//| print(kbd.sendcmd(0xed)) +//| print(kbd.sendcmd(0x01)) +//| +STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_datapin, ARG_clkpin }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_datapin, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_clkpin, MP_ARG_REQUIRED | MP_ARG_OBJ }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + assert_pin(args[ARG_clkpin].u_obj, false); + assert_pin(args[ARG_datapin].u_obj, false); + const mcu_pin_obj_t* clkpin = MP_OBJ_TO_PTR(args[ARG_clkpin].u_obj); + assert_pin_free(clkpin); + const mcu_pin_obj_t* datapin = MP_OBJ_TO_PTR(args[ARG_datapin].u_obj); + assert_pin_free(datapin); + + ps2io_ps2_obj_t *self = m_new_obj(ps2io_ps2_obj_t); + self->base.type = &ps2io_ps2_type; + + common_hal_ps2io_ps2_construct(self, datapin, clkpin); + + return MP_OBJ_FROM_PTR(self); +} + +//| .. method:: deinit() +//| +//| Deinitialises the Ps2 and releases any hardware resources for reuse. +//| +STATIC mp_obj_t ps2io_ps2_deinit(mp_obj_t self_in) { + ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_ps2io_ps2_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_deinit_obj, ps2io_ps2_deinit); + +//| .. method:: __enter__() +//| +//| No-op used by Context Managers. +//| +// Provided by context manager helper. + +//| .. method:: __exit__() +//| +//| Automatically deinitializes the hardware when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| +STATIC mp_obj_t ps2io_ps2_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_ps2io_ps2_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ps2io_ps2___exit___obj, 4, 4, ps2io_ps2_obj___exit__); + +//| .. method:: popleft() +//| +//| Removes and returns the oldest received byte. When buffer +//| is empty, raises an IndexError exception. +//| +STATIC mp_obj_t ps2io_ps2_obj_popleft(mp_obj_t self_in) { + ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_ps2io_ps2_deinited(self)); + + int b = common_hal_ps2io_ps2_popleft(self); + if (b < 0) { + mp_raise_IndexError(translate("Pop from an empty Ps2 buffer")); + } + return MP_OBJ_NEW_SMALL_INT(b); +} +MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_popleft_obj, ps2io_ps2_obj_popleft); + +//| .. method:: sendcmd(byte) +//| +//| Sends a command byte to PS/2. Returns the response byte, typically +//| the general ack value (0xFA). Some commands return additional data +//| which is available through :py:func:`popleft()`. +//| +//| Raises a RuntimeError in case of failure. The root cause can be found +//| by calling :py:func:`clear_errors()`. It is advisable to call +//| :py:func:`clear_errors()` before :py:func:`sendcmd()` to flush any +//| previous errors. +//| +//| :param int byte: byte value of the command +//| +STATIC mp_obj_t ps2io_ps2_obj_sendcmd(mp_obj_t self_in, mp_obj_t ob) { + ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_ps2io_ps2_deinited(self)); + mp_int_t cmd = mp_obj_get_int(ob) & 0xff; + int resp = common_hal_ps2io_ps2_sendcmd(self, cmd); + if (resp < 0) { + mp_raise_RuntimeError(translate("Failed sending command.")); + } + return MP_OBJ_NEW_SMALL_INT(resp); +} +MP_DEFINE_CONST_FUN_OBJ_2(ps2io_ps2_sendcmd_obj, ps2io_ps2_obj_sendcmd); + +//| .. method:: clear_errors() +//| +//| Returns and clears a bitmap with latest recorded communication errors. +//| +//| Reception errors (arise asynchronously, as data is received): +//| +//| 0x01: start bit not 0 +//| +//| 0x02: timeout +//| +//| 0x04: parity bit error +//| +//| 0x08: stop bit not 1 +//| +//| 0x10: buffer overflow, newest data discarded +//| +//| Transmission errors (can only arise in the course of sendcmd()): +//| +//| 0x100: clock pin didn't go to LO in time +//| +//| 0x200: clock pin didn't go to HI in time +//| +//| 0x400: data pin didn't ACK +//| +//| 0x800: clock pin didn't ACK +//| +//| 0x1000: device didn't respond to RTS +//| +//| 0x2000: device didn't send a response byte in time +//| +STATIC mp_obj_t ps2io_ps2_obj_clear_errors(mp_obj_t self_in) { + ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_ps2io_ps2_deinited(self)); + + return MP_OBJ_NEW_SMALL_INT(common_hal_ps2io_ps2_clear_errors(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_clear_errors_obj, ps2io_ps2_obj_clear_errors); + +//| .. method:: __len__() +//| +//| Returns the number of received bytes in buffer, available +//| to :py:func:`popleft()`. +//| +STATIC mp_obj_t ps2_unary_op(mp_unary_op_t op, mp_obj_t self_in) { + ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_ps2io_ps2_deinited(self)); + uint16_t len = common_hal_ps2io_ps2_get_len(self); + switch (op) { + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len != 0); + case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(len); + default: return MP_OBJ_NULL; // op not supported + } +} + +STATIC const mp_rom_map_elem_t ps2io_ps2_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&ps2io_ps2_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&ps2io_ps2___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_popleft), MP_ROM_PTR(&ps2io_ps2_popleft_obj) }, + { MP_ROM_QSTR(MP_QSTR_sendcmd), MP_ROM_PTR(&ps2io_ps2_sendcmd_obj) }, + { MP_ROM_QSTR(MP_QSTR_clear_errors), MP_ROM_PTR(&ps2io_ps2_clear_errors_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(ps2io_ps2_locals_dict, ps2io_ps2_locals_dict_table); + +const mp_obj_type_t ps2io_ps2_type = { + { &mp_type_type }, + .name = MP_QSTR_Ps2, + .make_new = ps2io_ps2_make_new, + .unary_op = ps2_unary_op, + .locals_dict = (mp_obj_dict_t*)&ps2io_ps2_locals_dict, +}; diff --git a/shared-bindings/ps2io/Ps2.h b/shared-bindings/ps2io/Ps2.h new file mode 100644 index 000000000..523869d55 --- /dev/null +++ b/shared-bindings/ps2io/Ps2.h @@ -0,0 +1,45 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Elvis Pfutzenreuter + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_PS2IO_PS2_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_PS2IO_PS2_H + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/ps2io/Ps2.h" + +extern const mp_obj_type_t ps2io_ps2_type; + +extern void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t* self, + const mcu_pin_obj_t* data_pin, const mcu_pin_obj_t* clk_pin); +extern void common_hal_ps2io_ps2_deinit(ps2io_ps2_obj_t* self); +extern bool common_hal_ps2io_ps2_deinited(ps2io_ps2_obj_t* self); +extern uint16_t common_hal_ps2io_ps2_get_len(ps2io_ps2_obj_t* self); +extern int16_t common_hal_ps2io_ps2_popleft(ps2io_ps2_obj_t* self); +extern int16_t common_hal_ps2io_ps2_sendcmd(ps2io_ps2_obj_t* self, uint8_t b); +extern uint16_t common_hal_ps2io_ps2_clear_errors(ps2io_ps2_obj_t* self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_PS2IO_PS2_H diff --git a/shared-bindings/ps2io/__init__.c b/shared-bindings/ps2io/__init__.c new file mode 100644 index 000000000..ec7c43e51 --- /dev/null +++ b/shared-bindings/ps2io/__init__.c @@ -0,0 +1,73 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Elvis Pfutzenreuter + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/ps2io/Ps2.h" + +//| :mod:`ps2io` --- Support for PS/2 protocol +//| ===================================================== +//| +//| .. module:: ps2io +//| :synopsis: Support for PS/2 based devices +//| :platform: SAMD21 +//| +//| The `ps2io` module contains classes to provide PS/2 communication. +//| +//| Libraries +//| +//| .. toctree:: +//| :maxdepth: 3 +//| +//| Ps2 +//| + +//| .. warning:: This module is not available in some SAMD21 builds. See the +//| :ref:`module-support-matrix` for more info. +//| + +//| All classes change hardware state and should be deinitialized when they +//| are no longer needed if the program continues after use. To do so, either +//| call :py:meth:`!deinit` or use a context manager. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| + +STATIC const mp_rom_map_elem_t ps2io_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ps2io) }, + { MP_ROM_QSTR(MP_QSTR_Ps2), MP_ROM_PTR(&ps2io_ps2_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(ps2io_module_globals, ps2io_module_globals_table); + +const mp_obj_module_t ps2io_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&ps2io_module_globals, +}; diff --git a/shared-bindings/ps2io/__init__.h b/shared-bindings/ps2io/__init__.h new file mode 100644 index 000000000..1ff3d97b5 --- /dev/null +++ b/shared-bindings/ps2io/__init__.h @@ -0,0 +1,35 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * Copyright (c) 2019 Elvis Pfutzenreuter + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_PS2IO___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_PS2IO___INIT___H + +#include "py/obj.h" + +// Nothing now. + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_PS2IO___INIT___H -- cgit v1.2.3 From f45daae09c6ae8227f99b6220ff96868cf0123ee Mon Sep 17 00:00:00 2001 From: Baozhu Zuo Date: Thu, 6 Jun 2019 15:44:29 +0800 Subject: This __init__.h should be redundant. I deleted it for you --- shared-bindings/busio/__init__.c | 1 - 1 file changed, 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/busio/__init__.c b/shared-bindings/busio/__init__.c index 958ee062a..ff2933dc6 100644 --- a/shared-bindings/busio/__init__.c +++ b/shared-bindings/busio/__init__.c @@ -35,7 +35,6 @@ #include "shared-bindings/busio/OneWire.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/busio/UART.h" -#include "shared-bindings/busio/__init__.h" #include "py/runtime.h" -- cgit v1.2.3 From 62de2506e47c14a71c7a9fe04360697ccb966aeb Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 6 Jun 2019 17:49:32 -0400 Subject: Include display objects in gc. --- main.c | 5 +++++ ports/nrf/background.c | 4 ++-- ports/nrf/supervisor/port.c | 10 ++++++++-- py/gc.c | 4 ++++ py/gc.h | 1 + shared-bindings/board/__init__.c | 1 - shared-module/board/__init__.c | 2 +- shared-module/displayio/__init__.c | 16 ++++++++++++++-- shared-module/displayio/__init__.h | 1 + 9 files changed, 36 insertions(+), 8 deletions(-) (limited to 'shared-bindings') diff --git a/main.c b/main.c index 107b5b3c2..6d7502ba4 100755 --- a/main.c +++ b/main.c @@ -455,6 +455,11 @@ void gc_collect(void) { // This collects root pointers from the VFS mount table. Some of them may // have lost their references in the VM even though they are mounted. gc_collect_root((void**)&MP_STATE_VM(vfs_mount_table), sizeof(mp_vfs_mount_t) / sizeof(mp_uint_t)); + + #if CIRCUITPY_DISPLAYIO + displayio_gc_collect(); + #endif + // This naively collects all object references from an approximate stack // range. gc_collect_root((void**)sp, ((uint32_t)&_estack - sp) / sizeof(uint32_t)); diff --git a/ports/nrf/background.c b/ports/nrf/background.c index 3fb5febd3..9c4f3ab27 100644 --- a/ports/nrf/background.c +++ b/ports/nrf/background.c @@ -29,7 +29,7 @@ #include "supervisor/usb.h" #include "supervisor/shared/stack.h" -#ifdef CIRCUITPY_DISPLAYIO +#if CIRCUITPY_DISPLAYIO #include "shared-module/displayio/__init__.h" #endif @@ -48,7 +48,7 @@ void run_background_tasks(void) { filesystem_background(); usb_background(); - #ifdef CIRCUITPY_DISPLAYIO + #if CIRCUITPY_DISPLAYIO displayio_refresh_displays(); #endif running_background_tasks = false; diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 85ecd6afe..8fbf75498 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -93,16 +93,22 @@ void reset_port(void) { i2c_reset(); spi_reset(); uart_reset(); + +#if CIRCUITPY_PULSEIO pwmout_reset(); pulseout_reset(); pulsein_reset(); +#endif + timers_reset(); - #if CIRCUITPY_RTC +#if CIRCUITPY_RTC rtc_reset(); - #endif +#endif +#if CIRCUITPY_BLEIO bleio_reset(); +#endif reset_all_pins(); } diff --git a/py/gc.c b/py/gc.c index e9b85fa7c..10b36950c 100755 --- a/py/gc.c +++ b/py/gc.c @@ -383,6 +383,10 @@ void gc_collect_start(void) { #endif } +void gc_collect_ptr(void *ptr) { + gc_mark(ptr); +} + void gc_collect_root(void **ptrs, size_t len) { for (size_t i = 0; i < len; i++) { void *ptr = ptrs[i]; diff --git a/py/gc.h b/py/gc.h index 757a2a6e0..02bf45158 100644 --- a/py/gc.h +++ b/py/gc.h @@ -43,6 +43,7 @@ bool gc_is_locked(void); // A given port must implement gc_collect by using the other collect functions. void gc_collect(void); void gc_collect_start(void); +void gc_collect_ptr(void *ptr); void gc_collect_root(void **ptrs, size_t len); void gc_collect_end(void); diff --git a/shared-bindings/board/__init__.c b/shared-bindings/board/__init__.c index 82a0cab67..448b397ab 100644 --- a/shared-bindings/board/__init__.c +++ b/shared-bindings/board/__init__.c @@ -34,7 +34,6 @@ //| //| .. module:: board //| :synopsis: Board specific pin names -//| :platform: SAMD21 //| //| Common container for board base pin names. These will vary from board to //| board so don't expect portability when using this module. diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index ac4de2fe5..be8502bc0 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -103,7 +103,7 @@ void reset_board_busses(void) { #endif #if BOARD_SPI bool display_using_spi = false; - #ifdef CIRCUITPY_DISPLAYIO + #if CIRCUITPY_DISPLAYIO for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { if (displays[i].fourwire_bus.bus == spi_singleton) { display_using_spi = true; diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 156640440..3b98536e9 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -3,6 +3,7 @@ #include "shared-module/displayio/__init__.h" #include "lib/utils/interrupt_char.h" +#include "py/gc.h" #include "py/reload.h" #include "py/runtime.h" #include "shared-bindings/board/__init__.h" @@ -181,7 +182,6 @@ void common_hal_displayio_release_displays(void) { } void reset_displays(void) { - #if CIRCUITPY_DISPLAYIO // The SPI buses used by FourWires may be allocated on the heap so we need to move them inline. for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { if (displays[i].fourwire_bus.base.type != &displayio_fourwire_type) { @@ -218,5 +218,17 @@ void reset_displays(void) { display->auto_brightness = true; common_hal_displayio_display_show(display, &circuitpython_splash); } - #endif +} + +void displayio_gc_collect(void) { + for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { + if (displays[i].display.base.type == NULL) { + continue; + } + + // Alternatively, we could use gc_collect_root over the whole object, + // but this is more precise, and is the only field that needs marking. + gc_collect_ptr(displays[i].display.current_group); + + } } diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h index 5b56ed55c..de021276c 100644 --- a/shared-module/displayio/__init__.h +++ b/shared-module/displayio/__init__.h @@ -46,5 +46,6 @@ extern displayio_group_t circuitpython_splash; void displayio_refresh_displays(void); void reset_displays(void); +void displayio_gc_collect(void); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H -- cgit v1.2.3 From 6fed24e1b6fce58f2c06328b9bc8b8f9d9512b42 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 10 Jun 2019 07:18:28 -0400 Subject: WIP --- shared-bindings/bleio/Address.c | 58 +++++++---------------------------------- shared-bindings/bleio/UUID.c | 5 ++-- 2 files changed, 12 insertions(+), 51 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index b7c76b7b2..226c011a3 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -53,9 +53,8 @@ STATIC uint8_t xdigit_8b_value(byte nibble1, byte nibble2) { //| Create a new Address object encapsulating the address value. //| The value itself can be one of: //| -//| - a `str` value in the format of 'XXXXXXXXXXXX' or 'XX:XX:XX:XX:XX:XX' (12 hex digits) -//| - a `bytes` or `bytearray` containing 6 bytes -//| - another Address object +//| :param buf: The address value to encapsulate +//| - a buffer object (bytearray, bytes) of 6 bytes //| //| :param address: The address to encapsulate //| @@ -84,54 +83,15 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t address = args[ARG_address].u_obj; - if (MP_OBJ_IS_STR(address)) { - GET_STR_DATA_LEN(address, str, str_len); - - size_t value_index = 0; - int str_index = str_len; - bool error = false; - - // Loop until fewer than two characters left. - while (str_index >= 1 && value_index < sizeof(self->value)) { - if (str[str_index] == ':') { - // Skip colon separators. - str_index--; - continue; - } - - if (!unichar_isxdigit(str[str_index]) || - !unichar_isxdigit(str[str_index-1])) { - error = true; - break; - } - - self->value[value_index] = xdigit_8b_value(str[str_index], - str[str_index-1]); - value_index += 1; - str_index -= 2; - } - // Check for correct number of hex digits and no parsing errors. - if (error || value_index != ADDRESS_BYTE_LEN || str_index != -1) { - mp_raise_ValueError_varg(translate("Address is not %d bytes long or is in wrong format"), - ADDRESS_BYTE_LEN); - } - } else if (MP_OBJ_IS_TYPE(address, &mp_type_bytearray) || MP_OBJ_IS_TYPE(address, &mp_type_bytes)) { - mp_buffer_info_t buf_info; - mp_get_buffer_raise(address, &buf_info, MP_BUFFER_READ); - if (buf_info.len != BLEIO_ADDRESS_BYTES) { - mp_raise_ValueError_varg(translate("Address must be %d bytes long"), BLEIO_ADDRESS_BYTES); - } - - for (size_t b = 0; b < BLEIO_ADDRESS_BYTES; ++b) { - self->value[BLEIO_ADDRESS_BYTES - b - 1] = ((uint8_t*)buf_info.buf)[b]; - } - } else if (MP_OBJ_IS_TYPE(address, &bleio_address_type)) { - // deep copy - bleio_address_obj_t *other = MP_OBJ_TO_PTR(address); - self->type = other->type; - memcpy(self->value, other->value, BLEIO_ADDRESS_BYTES); + mp_buffer_info_t buf_info; + mp_get_buffer_raise(address, &buf_info, MP_BUFFER_READ); + if (buf_info.len != BLEIO_ADDRESS_BYTES) { + mp_raise_ValueError_varg(translate("Address must be %d bytes long"), BLEIO_ADDRESS_BYTES); } + for (size_t b = 0; b < BLEIO_ADDRESS_BYTES; ++b) { + self->value[BLEIO_ADDRESS_BYTES - b - 1] = ((uint8_t*)buf_info.buf)[b]; + } return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index c6ad9e626..d054ea719 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -48,8 +48,9 @@ //| //| - an `int` value in range 0 to 0xFFFF (Bluetooth SIG 16-bit UUID) //| - a buffer object (bytearray, bytes) of 16 bytes in little-endian order (128-bit UUID) +//| - a string of hex digits of the form 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' //| -//| :param int/buffer value: The uuid value to encapsulate +//| :param value: The uuid value to encapsulate //| STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_check_num(n_args, kw_args, 1, 1, false); @@ -63,7 +64,7 @@ STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, co if (MP_OBJ_IS_INT(value)) { mp_int_t uuid16 = mp_obj_get_int(value); if (uuid16 < 0 || uuid16 > 0xffff) { - mp_raise_ValueError(translate("UUID integer value not in range 0 to 0xffff")); + mp_raise_ValueError(translate("UUID integer value must be 0-0xffff")); } // NULL means no 128-bit value. -- cgit v1.2.3 From eb21fc3e31790cee094d5c11811b55a57625340a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 6 Jun 2019 15:11:02 -0700 Subject: Add partial display update support. Different operations to the display tree have different costs. Be aware of these costs when optimizing your code. * Changing tiles indices in a TileGrid will update an area covering them all. * Changing a palette will refresh every object that references it. * Moving a TileGrid will update both where it was and where it moved to. * Adding something to a Group will refresh each individual area it covers. * Removing things from a Group will refresh one area that covers all previous locations. (Not separate areas like add.) * Setting a new top level Group will refresh the entire display. Only TileGrid moves are optimized for overlap. All other overlaps cause sending of duplicate pixels. This also adds flip_x, flip_y and transpose_xy to TileGrid. They change the direction of the pixels but not the location. Fixes #1169. Fixes #1705. Fixes #1923. --- ports/atmel-samd/boards/pybadge/board.c | 4 +- shared-bindings/displayio/Display.h | 2 +- shared-bindings/displayio/TileGrid.c | 80 +++++++ shared-bindings/displayio/TileGrid.h | 8 + shared-module/displayio/Display.c | 101 +++++++-- shared-module/displayio/Display.h | 12 +- shared-module/displayio/Group.c | 216 +++++++++++++++---- shared-module/displayio/Group.h | 11 +- shared-module/displayio/Palette.c | 6 +- shared-module/displayio/TileGrid.c | 359 ++++++++++++++++++++++++++------ shared-module/displayio/TileGrid.h | 33 ++- shared-module/displayio/__init__.c | 280 +++++++++++++++---------- shared-module/displayio/area.h | 22 +- supervisor/shared/display.c | 32 +-- tools/gen_display_resources.py | 18 +- 15 files changed, 905 insertions(+), 279 deletions(-) (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 2b0e334fa..64fb8e852 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -87,8 +87,8 @@ void board_init(void) { display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, - 160, // Width - 128, // Height + 160, // Width (after rotation) + 128, // Height (after rotation) 0, // column start 0, // row start 270, // rotation diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 6695da32b..5a027561b 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -59,7 +59,7 @@ bool displayio_display_frame_queued(displayio_display_obj_t* self); bool displayio_display_refresh_queued(displayio_display_obj_t* self); void displayio_display_finish_refresh(displayio_display_obj_t* self); -void displayio_display_send_pixels(displayio_display_obj_t* self, uint32_t* pixels, uint32_t length); +void displayio_display_send_pixels(displayio_display_obj_t* self, uint8_t* pixels, uint32_t length); bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t* self); void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* self, bool auto_brightness); diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 10bed4c77..5d064ae10 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -196,6 +196,83 @@ const mp_obj_property_t displayio_tilegrid_y_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| .. attribute:: flip_x +//| +//| If true, the left edge rendered will be the right edge of the right-most tile. +//| +STATIC mp_obj_t displayio_tilegrid_obj_get_flip_x(mp_obj_t self_in) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + return mp_obj_new_bool(common_hal_displayio_tilegrid_get_flip_x(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_flip_x_obj, displayio_tilegrid_obj_get_flip_x); + +STATIC mp_obj_t displayio_tilegrid_obj_set_flip_x(mp_obj_t self_in, mp_obj_t flip_x_obj) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + + common_hal_displayio_tilegrid_set_flip_x(self, mp_obj_is_true(flip_x_obj)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(displayio_tilegrid_set_flip_x_obj, displayio_tilegrid_obj_set_flip_x); + +const mp_obj_property_t displayio_tilegrid_flip_x_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_tilegrid_get_flip_x_obj, + (mp_obj_t)&displayio_tilegrid_set_flip_x_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| .. attribute:: flip_y +//| +//| If true, the top edge rendered will be the bottom edge of the bottom-most tile. +//| +STATIC mp_obj_t displayio_tilegrid_obj_get_flip_y(mp_obj_t self_in) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + return mp_obj_new_bool(common_hal_displayio_tilegrid_get_flip_y(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_flip_y_obj, displayio_tilegrid_obj_get_flip_y); + +STATIC mp_obj_t displayio_tilegrid_obj_set_flip_y(mp_obj_t self_in, mp_obj_t flip_y_obj) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + + common_hal_displayio_tilegrid_set_flip_y(self, mp_obj_is_true(flip_y_obj)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(displayio_tilegrid_set_flip_y_obj, displayio_tilegrid_obj_set_flip_y); + +const mp_obj_property_t displayio_tilegrid_flip_y_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_tilegrid_get_flip_y_obj, + (mp_obj_t)&displayio_tilegrid_set_flip_y_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + + +//| .. attribute:: transpose_xy +//| +//| If true, the TileGrid will be rotate 90 degrees. When combined with mirroring any 90 degree +//| rotation can be achieved. +//| +STATIC mp_obj_t displayio_tilegrid_obj_get_transpose_xy(mp_obj_t self_in) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + return mp_obj_new_bool(common_hal_displayio_tilegrid_get_transpose_xy(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_transpose_xy_obj, displayio_tilegrid_obj_get_transpose_xy); + +STATIC mp_obj_t displayio_tilegrid_obj_set_transpose_xy(mp_obj_t self_in, mp_obj_t transpose_xy_obj) { + displayio_tilegrid_t *self = native_tilegrid(self_in); + + common_hal_displayio_tilegrid_set_transpose_xy(self, mp_obj_is_true(transpose_xy_obj)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(displayio_tilegrid_set_transpose_xy_obj, displayio_tilegrid_obj_set_transpose_xy); + +const mp_obj_property_t displayio_tilegrid_transpose_xy_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_tilegrid_get_transpose_xy_obj, + (mp_obj_t)&displayio_tilegrid_set_transpose_xy_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + //| .. attribute:: pixel_shader //| //| The pixel shader of the tilegrid. @@ -292,6 +369,9 @@ STATIC const mp_rom_map_elem_t displayio_tilegrid_locals_dict_table[] = { // Properties { MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&displayio_tilegrid_x_obj) }, { MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&displayio_tilegrid_y_obj) }, + { MP_ROM_QSTR(MP_QSTR_flip_x), MP_ROM_PTR(&displayio_tilegrid_flip_x_obj) }, + { MP_ROM_QSTR(MP_QSTR_flip_y), MP_ROM_PTR(&displayio_tilegrid_flip_y_obj) }, + { MP_ROM_QSTR(MP_QSTR_transpose_xy), MP_ROM_PTR(&displayio_tilegrid_transpose_xy_obj) }, { MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&displayio_tilegrid_pixel_shader_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_tilegrid_locals_dict, displayio_tilegrid_locals_dict_table); diff --git a/shared-bindings/displayio/TileGrid.h b/shared-bindings/displayio/TileGrid.h index 15a71b53b..1f9995a94 100644 --- a/shared-bindings/displayio/TileGrid.h +++ b/shared-bindings/displayio/TileGrid.h @@ -42,6 +42,14 @@ void common_hal_displayio_tilegrid_set_y(displayio_tilegrid_t *self, mp_int_t y) mp_obj_t common_hal_displayio_tilegrid_get_pixel_shader(displayio_tilegrid_t *self); void common_hal_displayio_tilegrid_set_pixel_shader(displayio_tilegrid_t *self, mp_obj_t pixel_shader); + +bool common_hal_displayio_tilegrid_get_flip_x(displayio_tilegrid_t *self); +void common_hal_displayio_tilegrid_set_flip_x(displayio_tilegrid_t *self, bool flip_x); +bool common_hal_displayio_tilegrid_get_flip_y(displayio_tilegrid_t *self); +void common_hal_displayio_tilegrid_set_flip_y(displayio_tilegrid_t *self, bool flip_y); +bool common_hal_displayio_tilegrid_get_transpose_xy(displayio_tilegrid_t *self); +void common_hal_displayio_tilegrid_set_transpose_xy(displayio_tilegrid_t *self, bool transpose_xy); + uint16_t common_hal_displayio_tilegrid_get_width(displayio_tilegrid_t *self); uint16_t common_hal_displayio_tilegrid_get_height(displayio_tilegrid_t *self); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 3b1613974..4385e15f2 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -107,28 +107,26 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, supervisor_start_terminal(width, height); - // Set the group after initialization otherwise we may send pixels while we delay in - // initialization. - self->refresh = true; - self->current_group = &circuitpython_splash; - self->width = width; self->height = height; rotation = rotation % 360; - self->mirror_x = false; - self->mirror_y = false; - self->transpose_xy = false; + self->transform.x = 0; + self->transform.y = 0; + self->transform.scale = 1; + self->transform.mirror_x = false; + self->transform.mirror_y = false; + self->transform.transpose_xy = false; if (rotation == 0 || rotation == 180) { if (rotation == 180) { - self->mirror_x = true; - self->mirror_y = true; + self->transform.mirror_x = true; + self->transform.mirror_y = true; } } else { - self->transpose_xy = true; - if (rotation == 90) { - self->mirror_y = true; + self->transform.transpose_xy = true; + if (rotation == 270) { + self->transform.mirror_y = true; } else { - self->mirror_x = true; + self->transform.mirror_x = true; } } @@ -148,13 +146,52 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, } } } + + self->area.x1 = 0; + self->area.y1 = 0; + self->area.next = NULL; + + self->transform.dx = 1; + self->transform.dy = 1; + if (self->transform.transpose_xy) { + self->area.x2 = height; + self->area.y2 = width; + if (self->transform.mirror_x) { + self->transform.x = height; + self->transform.dx = -1; + } + if (self->transform.mirror_y) { + self->transform.y = width; + self->transform.dy = -1; + } + } else { + self->area.x2 = width; + self->area.y2 = height; + if (self->transform.mirror_x) { + self->transform.x = width; + self->transform.dx = -1; + } + if (self->transform.mirror_y) { + self->transform.y = height; + self->transform.dy = -1; + } + } + + // Set the group after initialization otherwise we may send pixels while we delay in + // initialization. + common_hal_displayio_display_show(self, &circuitpython_splash); } void common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) { if (root_group == NULL) { root_group = &circuitpython_splash; } + if (root_group == self->current_group) { + return; + } + displayio_group_update_transform(root_group, &self->transform); self->current_group = root_group; + self->full_refresh = true; common_hal_displayio_display_refresh_soon(self); } @@ -162,6 +199,15 @@ void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self) { self->refresh = true; } +const displayio_area_t* displayio_display_get_refresh_areas(displayio_display_obj_t *self) { + if (self->full_refresh) { + self->area.next = NULL; + return &self->area; + } else { + return displayio_group_get_refresh_areas(self->current_group, NULL); + } +} + int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self) { uint64_t last_refresh = self->last_refresh; // Don't try to refresh if we got an exception. @@ -224,7 +270,6 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) { } void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - self->send(self->bus, true, &self->set_column_command, 1); bool isCommand = self->data_as_commands; if (self->single_byte_bounds) { @@ -255,13 +300,16 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint1 } } -bool displayio_display_frame_queued(displayio_display_obj_t* self) { - // Refresh at ~30 fps. - return (ticks_ms - self->last_refresh) > 32; +void displayio_display_start_refresh(displayio_display_obj_t* self) { + self->last_refresh = ticks_ms; } -bool displayio_display_refresh_queued(displayio_display_obj_t* self) { - return self->refresh || (self->current_group != NULL && displayio_group_needs_refresh(self->current_group)); +bool displayio_display_frame_queued(displayio_display_obj_t* self) { + if (self->current_group == NULL) { + return false; + } + // Refresh at ~60 fps. + return (ticks_ms - self->last_refresh) > 16; } void displayio_display_finish_refresh(displayio_display_obj_t* self) { @@ -269,11 +317,12 @@ void displayio_display_finish_refresh(displayio_display_obj_t* self) { displayio_group_finish_refresh(self->current_group); } self->refresh = false; + self->full_refresh = false; self->last_refresh = ticks_ms; } -void displayio_display_send_pixels(displayio_display_obj_t* self, uint32_t* pixels, uint32_t length) { - self->send(self->bus, false, (uint8_t*) pixels, length * 4); +void displayio_display_send_pixels(displayio_display_obj_t* self, uint8_t* pixels, uint32_t length) { + self->send(self->bus, false, pixels, length); } void displayio_display_update_backlight(displayio_display_obj_t* self) { @@ -298,3 +347,11 @@ void release_display(displayio_display_obj_t* self) { common_hal_digitalio_digitalinout_deinit(&self->backlight_inout); } } + +bool displayio_display_fill_area(displayio_display_obj_t *self, displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { + return displayio_group_fill_area(self->current_group, area, mask, buffer); +} + +bool displayio_display_clip_area(displayio_display_obj_t *self, const displayio_area_t* area, displayio_area_t* clipped) { + return displayio_area_compute_overlap(&self->area, area, clipped); +} \ No newline at end of file diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 52f98a252..687e412c2 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -31,6 +31,8 @@ #include "shared-bindings/displayio/Group.h" #include "shared-bindings/pulseio/PWMOut.h" +#include "shared-module/displayio/area.h" + typedef bool (*display_bus_begin_transaction)(mp_obj_t bus); typedef void (*display_bus_send)(mp_obj_t bus, bool command, uint8_t *data, uint32_t data_length); typedef void (*display_bus_end_transaction)(mp_obj_t bus); @@ -61,12 +63,16 @@ typedef struct { uint64_t last_backlight_refresh; bool auto_brightness:1; bool updating_backlight:1; - bool mirror_x; - bool mirror_y; - bool transpose_xy; + bool full_refresh; // New group means we need to refresh the whole display. + displayio_buffer_transform_t transform; + displayio_area_t area; } displayio_display_obj_t; +void displayio_display_start_refresh(displayio_display_obj_t* self); +const displayio_area_t* displayio_display_get_refresh_areas(displayio_display_obj_t *self); +bool displayio_display_fill_area(displayio_display_obj_t *self, displayio_area_t* area, uint32_t* mask, uint32_t *buffer); void displayio_display_update_backlight(displayio_display_obj_t* self); +bool displayio_display_clip_area(displayio_display_obj_t *self, const displayio_area_t* area, displayio_area_t* clipped); void release_display(displayio_display_obj_t* self); #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_DISPLAY_H diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index f91e2ce3c..76c29d644 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -38,9 +38,85 @@ uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) { return self->scale; } +bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t* area) { + bool first = true; + for (int32_t i = 0; i < self->size; i++) { + mp_obj_t layer = self->children[i].native; + displayio_area_t layer_area; + if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + if (!displayio_tilegrid_get_previous_area(layer, &layer_area)) { + continue; + } + } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + if (!displayio_group_get_previous_area(layer, &layer_area)) { + continue; + } + } + if (first) { + displayio_area_copy(&layer_area, area); + first = false; + } else { + displayio_area_expand(area, &layer_area); + } + } + if (self->item_removed) { + if (first) { + displayio_area_copy(&self->dirty_area, area); + first = false; + } else { + displayio_area_expand(area, &self->dirty_area); + } + } + return !first; +} + +static void _update_child_transforms(displayio_group_t* self) { + if (!self->in_group) { + return; + } + for (int32_t i = 0; i < self->size; i++) { + mp_obj_t layer = self->children[i].native; + if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + displayio_tilegrid_update_transform(layer, &self->absolute_transform); + } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + displayio_group_update_transform(layer, &self->absolute_transform); + } + } +} + +void displayio_group_update_transform(displayio_group_t *self, + const displayio_buffer_transform_t* parent_transform) { + self->in_group = parent_transform != NULL; + if (self->in_group) { + int16_t x = self->x; + int16_t y = self->y; + if (parent_transform->transpose_xy) { + x = y; + y = self->x; + } + self->absolute_transform.x = parent_transform->x + parent_transform->dx * x; + self->absolute_transform.y = parent_transform->y + parent_transform->dy * y; + self->absolute_transform.dx = parent_transform->dx * self->scale; + self->absolute_transform.dy = parent_transform->dy * self->scale; + self->absolute_transform.transpose_xy = parent_transform->transpose_xy; + self->absolute_transform.mirror_x = parent_transform->mirror_x; + self->absolute_transform.mirror_y = parent_transform->mirror_y; + + self->absolute_transform.scale = parent_transform->scale * self->scale; + } + _update_child_transforms(self); +} + void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scale) { - self->needs_refresh = self->scale != scale; + if (self->scale == scale) { + return; + } + uint8_t parent_scale = self->absolute_transform.scale / self->scale; + self->absolute_transform.dx = self->absolute_transform.dx / self->scale * scale; + self->absolute_transform.dy = self->absolute_transform.dy / self->scale * scale; + self->absolute_transform.scale = parent_scale * scale; self->scale = scale; + _update_child_transforms(self); } mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self) { @@ -48,8 +124,19 @@ mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self) { } void common_hal_displayio_group_set_x(displayio_group_t* self, mp_int_t x) { - self->needs_refresh = self->x != x; + if (self->x == x) { + return; + } + if (self->absolute_transform.transpose_xy) { + int8_t dy = self->absolute_transform.dy / self->scale; + self->absolute_transform.y += dy * (x - self->x); + } else { + int8_t dx = self->absolute_transform.dx / self->scale; + self->absolute_transform.x += dx * (x - self->x); + } + self->x = x; + _update_child_transforms(self); } mp_int_t common_hal_displayio_group_get_y(displayio_group_t* self) { @@ -57,21 +144,75 @@ mp_int_t common_hal_displayio_group_get_y(displayio_group_t* self) { } void common_hal_displayio_group_set_y(displayio_group_t* self, mp_int_t y) { - self->needs_refresh = self->y != y; + if (self->y == y) { + return; + } + if (self->absolute_transform.transpose_xy) { + int8_t dx = self->absolute_transform.dx / self->scale; + self->absolute_transform.x += dx * (y - self->y); + } else { + int8_t dy = self->absolute_transform.dy / self->scale; + self->absolute_transform.y += dy * (y - self->y); + } self->y = y; + _update_child_transforms(self); } -void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp_obj_t layer) { - if (self->size == self->max_size) { - mp_raise_RuntimeError(translate("Group full")); - } +static mp_obj_t _add_layer(displayio_group_t* self, mp_obj_t layer) { mp_obj_t native_layer = mp_instance_cast_to_native_base(layer, &displayio_group_type); if (native_layer == MP_OBJ_NULL) { native_layer = mp_instance_cast_to_native_base(layer, &displayio_tilegrid_type); + if (native_layer == MP_OBJ_NULL) { + mp_raise_ValueError(translate("Layer must be a Group or TileGrid subclass.")); + } + displayio_tilegrid_t* tilegrid = native_layer; + if (tilegrid->in_group) { + mp_raise_ValueError(translate("Layer already in a group.")); + } else { + tilegrid->in_group = true; + } + displayio_tilegrid_update_transform(tilegrid, &self->absolute_transform); + } else { + displayio_group_t* group = native_layer; + if (group->in_group) { + mp_raise_ValueError(translate("Layer already in a group.")); + } else { + group->in_group = true; + } + displayio_group_update_transform(group, &self->absolute_transform); } - if (native_layer == MP_OBJ_NULL) { - mp_raise_ValueError(translate("Layer must be a Group or TileGrid subclass.")); + return native_layer; +} + +static void _remove_layer(displayio_group_t* self, size_t index) { + mp_obj_t layer = self->children[index].native; + displayio_area_t layer_area; + bool rendered_last_frame = false; + if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + displayio_tilegrid_t* tilegrid = layer; + rendered_last_frame = displayio_tilegrid_get_previous_area(tilegrid, &layer_area); + displayio_tilegrid_update_transform(tilegrid, NULL); + } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + displayio_group_t* group = layer; + rendered_last_frame = displayio_group_get_previous_area(group, &layer_area); + displayio_group_update_transform(group, NULL); + } + if (!rendered_last_frame) { + return; } + if (!self->item_removed) { + displayio_area_copy(&layer_area, &self->dirty_area); + } else { + displayio_area_expand(&self->dirty_area, &layer_area); + } + self->item_removed = true; +} + +void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp_obj_t layer) { + if (self->size == self->max_size) { + mp_raise_RuntimeError(translate("Group full")); + } + mp_obj_t native_layer = _add_layer(self, layer); // Shift everything right. for (size_t i = self->size; i > index; i--) { self->children[i] = self->children[i - 1]; @@ -79,19 +220,19 @@ void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp self->children[index].native = native_layer; self->children[index].original = layer; self->size++; - self->needs_refresh = true; } mp_obj_t common_hal_displayio_group_pop(displayio_group_t* self, size_t index) { self->size--; mp_obj_t item = self->children[index].original; + _remove_layer(self, index); + // Shift everything left. for (size_t i = index; i < self->size; i++) { self->children[i] = self->children[i + 1]; } self->children[self->size].native = NULL; self->children[self->size].original = NULL; - self->needs_refresh = true; return item; } @@ -113,16 +254,10 @@ mp_obj_t common_hal_displayio_group_get(displayio_group_t* self, size_t index) { } void common_hal_displayio_group_set(displayio_group_t* self, size_t index, mp_obj_t layer) { - mp_obj_t native_layer = mp_instance_cast_to_native_base(layer, &displayio_group_type); - if (native_layer == MP_OBJ_NULL) { - native_layer = mp_instance_cast_to_native_base(layer, &displayio_tilegrid_type); - } - if (native_layer == MP_OBJ_NULL) { - mp_raise_ValueError(translate("Layer must be a Group or TileGrid subclass.")); - } + mp_obj_t native_layer = _add_layer(self, layer); + _remove_layer(self, index); self->children[index].native = native_layer; self->children[index].original = layer; - self->needs_refresh = true; } void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y) { @@ -130,63 +265,58 @@ void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* self->y = y; self->children = child_array; self->max_size = max_size; - self->needs_refresh = false; + self->item_removed = false; self->scale = scale; + self->in_group = false; } -bool displayio_group_get_area(displayio_group_t *self, displayio_buffer_transform_t* transform, displayio_area_t* area, uint32_t* mask, uint32_t* buffer) { - displayio_area_shift(area, -self->x * transform->scale, -self->y * transform->scale); - transform->scale *= self->scale; - +bool displayio_group_fill_area(displayio_group_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t* buffer) { // Track if any of the layers finishes filling in the given area. We can ignore any remaining // layers at that point. bool full_coverage = false; for (int32_t i = self->size - 1; i >= 0 ; i--) { mp_obj_t layer = self->children[i].native; if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { - if (displayio_tilegrid_get_area(layer, transform, area, mask, buffer)) { + if (displayio_tilegrid_fill_area(layer, area, mask, buffer)) { full_coverage = true; break; } } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { - if (displayio_group_get_area(layer, transform, area, mask, buffer)) { + if (displayio_group_fill_area(layer, area, mask, buffer)) { full_coverage = true; break; } } } - transform->scale /= self->scale; - displayio_area_shift(area, self->x * transform->scale, self->y * transform->scale); return full_coverage; } -bool displayio_group_needs_refresh(displayio_group_t *self) { - if (self->needs_refresh) { - return true; - } +void displayio_group_finish_refresh(displayio_group_t *self) { + self->item_removed = false; for (int32_t i = self->size - 1; i >= 0 ; i--) { mp_obj_t layer = self->children[i].native; if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { - if (displayio_tilegrid_needs_refresh(layer)) { - return true; - } + displayio_tilegrid_finish_refresh(layer); } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { - if (displayio_group_needs_refresh(layer)) { - return true; - } + displayio_group_finish_refresh(layer); } } - return false; } -void displayio_group_finish_refresh(displayio_group_t *self) { - self->needs_refresh = false; +displayio_area_t* displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t* tail) { + if (self->item_removed) { + self->dirty_area.next = tail; + tail = &self->dirty_area; + } + for (int32_t i = self->size - 1; i >= 0 ; i--) { mp_obj_t layer = self->children[i].native; if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { - displayio_tilegrid_finish_refresh(layer); + tail = displayio_tilegrid_get_refresh_areas(layer, tail); } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { - displayio_group_finish_refresh(layer); + tail = displayio_group_get_refresh_areas(layer, tail); } } + + return tail; } diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h index f8fe9be04..1642b4602 100644 --- a/shared-module/displayio/Group.h +++ b/shared-module/displayio/Group.h @@ -46,12 +46,17 @@ typedef struct { uint16_t size; uint16_t max_size; displayio_group_child_t* children; - bool needs_refresh; + bool item_removed; + bool in_group; + displayio_buffer_transform_t absolute_transform; + displayio_area_t dirty_area; // Catch all for changed area } displayio_group_t; void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); -bool displayio_group_get_area(displayio_group_t *group, displayio_buffer_transform_t* transform, displayio_area_t* area, uint32_t* mask, uint32_t *buffer); -bool displayio_group_needs_refresh(displayio_group_t *self); +bool displayio_group_get_previous_area(displayio_group_t *group, displayio_area_t* area); +bool displayio_group_fill_area(displayio_group_t *group, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); +void displayio_group_update_transform(displayio_group_t *group, const displayio_buffer_transform_t* parent_transform); void displayio_group_finish_refresh(displayio_group_t *self); +displayio_area_t* displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t* tail); #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_GROUP_H diff --git a/shared-module/displayio/Palette.c b/shared-module/displayio/Palette.c index e810be875..8dc6e766b 100644 --- a/shared-module/displayio/Palette.c +++ b/shared-module/displayio/Palette.c @@ -53,7 +53,11 @@ void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t uint32_t packed = r5 << 11 | g6 << 5 | b5; // swap bytes packed = __builtin_bswap16(packed); - self->colors[palette_index / 2] = masked | packed << shift; + uint32_t final_color = masked | packed << shift; + if (self->colors[palette_index / 2] == final_color) { + return; + } + self->colors[palette_index / 2] = final_color; self->needs_refresh = true; } diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 078ddf6b1..4420fc480 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -56,39 +56,127 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_ self->bitmap_width_in_tiles = bitmap_width_in_tiles; self->width_in_tiles = width; self->height_in_tiles = height; - self->area.x1 = x; - self->area.y1 = y; - self->area.x2 = x + width * tile_width; - self->area.y2 = y + height * tile_height; + self->x = x; + self->y = y; + self->pixel_width = width * tile_width; + self->pixel_height = height * tile_height; self->tile_width = tile_width; self->tile_height = tile_height; self->bitmap = bitmap; self->pixel_shader = pixel_shader; + self->in_group = false; + self->first_draw = true; + self->flip_x = false; + self->flip_y = false; + self->transpose_xy = false; } +bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t* area) { + if (self->first_draw) { + return false; + } + displayio_area_copy(&self->previous_area, area); + return true; +} + +void _update_current_x(displayio_tilegrid_t *self) { + if (self->absolute_transform->transpose_xy) { + self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->x; + if (self->transpose_xy) { + self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + self->pixel_height); + } else { + self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + self->pixel_width); + } + if (self->current_area.y2 < self->current_area.y1) { + int16_t temp = self->current_area.y2; + self->current_area.y2 = self->current_area.y1; + self->current_area.y1 = temp; + } + } else { + self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->x; + if (self->transpose_xy) { + self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + self->pixel_height); + } else { + self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + self->pixel_width); + } + if (self->current_area.x2 < self->current_area.x1) { + int16_t temp = self->current_area.x2; + self->current_area.x2 = self->current_area.x1; + self->current_area.x1 = temp; + } + } +} + +void _update_current_y(displayio_tilegrid_t *self) { + if (self->absolute_transform->transpose_xy) { + self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->y; + if (self->transpose_xy) { + self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + self->pixel_width); + } else { + self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + self->pixel_height); + } + if (self->current_area.x2 < self->current_area.x1) { + int16_t temp = self->current_area.x2; + self->current_area.x2 = self->current_area.x1; + self->current_area.x1 = temp; + } + } else { + self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->y; + if (self->transpose_xy) { + self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + self->pixel_width); + } else { + self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + self->pixel_height); + } + if (self->current_area.y2 < self->current_area.y1) { + int16_t temp = self->current_area.y2; + self->current_area.y2 = self->current_area.y1; + self->current_area.y1 = temp; + } + } +} + +void displayio_tilegrid_update_transform(displayio_tilegrid_t *self, + const displayio_buffer_transform_t* absolute_transform) { + self->in_group = absolute_transform != NULL; + self->absolute_transform = absolute_transform; + if (absolute_transform != NULL) { + self->moved = !self->first_draw; + + _update_current_x(self); + _update_current_y(self); + } else { + self->first_draw = true; + } +} mp_int_t common_hal_displayio_tilegrid_get_x(displayio_tilegrid_t *self) { - return self->area.x1; + return self->x; } void common_hal_displayio_tilegrid_set_x(displayio_tilegrid_t *self, mp_int_t x) { - if (self->area.x1 == x) { + if (self->x == x) { return; } - self->needs_refresh = true; - self->area.x2 += (self->area.x1 - x); - self->area.x1 = x; + + self->moved = !self->first_draw; + + self->x = x; + if (self->absolute_transform != NULL) { + _update_current_x(self); + } } mp_int_t common_hal_displayio_tilegrid_get_y(displayio_tilegrid_t *self) { - return self->area.y1; + return self->y; } void common_hal_displayio_tilegrid_set_y(displayio_tilegrid_t *self, mp_int_t y) { - if (self->area.y1 == y) { + if (self->y == y) { return; } - self->needs_refresh = true; - self->area.y2 += (self->area.y1 - y); - self->area.y1 = y; + self->moved = !self->first_draw; + self->y = y; + if (self->absolute_transform != NULL) { + _update_current_y(self); + } } mp_obj_t common_hal_displayio_tilegrid_get_pixel_shader(displayio_tilegrid_t *self) { @@ -97,10 +185,9 @@ mp_obj_t common_hal_displayio_tilegrid_get_pixel_shader(displayio_tilegrid_t *se void common_hal_displayio_tilegrid_set_pixel_shader(displayio_tilegrid_t *self, mp_obj_t pixel_shader) { self->pixel_shader = pixel_shader; - self->needs_refresh = true; + self->full_change = true; } - uint16_t common_hal_displayio_tilegrid_get_width(displayio_tilegrid_t *self) { return self->width_in_tiles; } @@ -129,17 +216,77 @@ void common_hal_displayio_tilegrid_set_tile(displayio_tilegrid_t *self, uint16_t return; } tiles[y * self->width_in_tiles + x] = tile_index; - self->needs_refresh = true; + displayio_area_t temp_area; + displayio_area_t* tile_area; + if (!self->partial_change) { + tile_area = &self->dirty_area; + } else { + tile_area = &temp_area; + } + tile_area->x1 = x * self->tile_width; + tile_area->x2 = tile_area->x1 + self->tile_width; + tile_area->y1 = y * self->tile_height; + tile_area->y2 = tile_area->y1 + self->tile_height; + if (self->partial_change) { + displayio_area_expand(&self->dirty_area, &temp_area); + } + + self->partial_change = true; +} + +bool common_hal_displayio_tilegrid_get_flip_x(displayio_tilegrid_t *self) { + return self->flip_x; +} + +void common_hal_displayio_tilegrid_set_flip_x(displayio_tilegrid_t *self, bool flip_x) { + if (self->flip_x == flip_x) { + return; + } + self->flip_x = flip_x; + self->full_change = true; +} + +bool common_hal_displayio_tilegrid_get_flip_y(displayio_tilegrid_t *self) { + return self->flip_y; +} + +void common_hal_displayio_tilegrid_set_flip_y(displayio_tilegrid_t *self, bool flip_y) { + if (self->flip_y == flip_y) { + return; + } + self->flip_y = flip_y; + self->full_change = true; } +bool common_hal_displayio_tilegrid_get_transpose_xy(displayio_tilegrid_t *self) { + return self->transpose_xy; +} + +void common_hal_displayio_tilegrid_set_transpose_xy(displayio_tilegrid_t *self, bool transpose_xy) { + if (self->transpose_xy == transpose_xy) { + return; + } + self->transpose_xy = transpose_xy; + + // Square TileGrids do not change dimensions when transposed. + if (self->pixel_width == self->pixel_height) { + self->full_change = true; + return; + } + + _update_current_x(self); + _update_current_y(self); + + self->moved = true; +} void common_hal_displayio_tilegrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y) { self->top_left_x = x; self->top_left_y = y; - self->needs_refresh = true; + self->full_change = true; } -bool displayio_tilegrid_get_area(displayio_tilegrid_t *self, displayio_buffer_transform_t* transform, displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { +bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { // If no tiles are present we have no impact. uint8_t* tiles = self->tiles; if (self->inline_tiles) { @@ -150,30 +297,40 @@ bool displayio_tilegrid_get_area(displayio_tilegrid_t *self, displayio_buffer_tr } displayio_area_t overlap; - displayio_area_t scaled_area = { - .x1 = self->area.x1 * transform->scale, - .y1 = self->area.y1 * transform->scale, - .x2 = self->area.x2 * transform->scale, - .y2 = self->area.y2 * transform->scale - }; - if (!displayio_area_compute_overlap(area, &scaled_area, &overlap)) { + if (!displayio_area_compute_overlap(area, &self->current_area, &overlap)) { return false; } int16_t x_stride = 1; int16_t y_stride = displayio_area_width(area); - if (transform->transpose_xy) { - x_stride = displayio_area_height(area); - y_stride = 1; + + bool flip_x = self->flip_x; + bool flip_y = self->flip_y; + if (self->transpose_xy != self->absolute_transform->transpose_xy) { + bool temp_flip = flip_x; + flip_x = flip_y; + flip_y = temp_flip; } + + // How many pixels are outside of our area between us and the start of the row. uint16_t start = 0; - if (transform->mirror_x) { - start += (area->x2 - area->x1 - 1) * x_stride; - x_stride *= -1; + if ((self->absolute_transform->dx < 0) != flip_x) { + // if (self->absolute_transform->transpose_xy) { + // start += (area->y2 - area->y1 - 1) * y_stride; + // y_stride *= -1; + // } else { + start += (area->x2 - area->x1 - 1) * x_stride; + x_stride *= -1; + //} } - if (transform->mirror_y) { - start += (area->y2 - area->y1 - 1) * y_stride; - y_stride *= -1; + if ((self->absolute_transform->dy < 0) != flip_y) { + // if (self->absolute_transform->transpose_xy) { + // start += (area->x2 - area->x1 - 1) * x_stride; + // x_stride *= -1; + // } else { + start += (area->y2 - area->y1 - 1) * y_stride; + y_stride *= -1; + //} } // Track if this layer finishes filling in the given area. We can ignore any remaining @@ -185,25 +342,49 @@ bool displayio_tilegrid_get_area(displayio_tilegrid_t *self, displayio_buffer_tr // TODO(tannewt): Check to see if the pixel_shader has any transparency. If it doesn't then we // can either return full coverage or bulk update the mask. - int16_t y = overlap.y1 - scaled_area.y1; - if (y < 0) { - y = 0; - } - int16_t x_shift = area->x1 - scaled_area.x1; - int16_t y_shift = area->y1 - scaled_area.y1; - for (; y < overlap.y2 - scaled_area.y1; y++) { - int16_t x = overlap.x1 - scaled_area.x1; - if (x < 0) { - x = 0; - } - int16_t row_start = start + (y - y_shift) * y_stride; - int16_t local_y = y / transform->scale; - for (; x < overlap.x2 - scaled_area.x1; x++) { + displayio_area_t transformed; + displayio_area_transform_within(flip_x != (self->absolute_transform->dx < 0), flip_y != (self->absolute_transform->dy < 0), self->transpose_xy != self->absolute_transform->transpose_xy, + &overlap, + &self->current_area, + &transformed); + + int16_t start_x = (transformed.x1 - self->current_area.x1); + int16_t end_x = (transformed.x2 - self->current_area.x1); + int16_t start_y = (transformed.y1 - self->current_area.y1); + int16_t end_y = (transformed.y2 - self->current_area.y1); + + int16_t y_shift = 0; + int16_t x_shift = 0; + if ((self->absolute_transform->dx < 0) != flip_x) { + x_shift = area->x2 - overlap.x2; + } else { + x_shift = overlap.x1 - area->x1; + } + if ((self->absolute_transform->dy < 0) != flip_y) { + y_shift = area->y2 - overlap.y2; + } else { + y_shift = overlap.y1 - area->y1; + } + + // This untransposes x and y so it aligns with bitmap rows. + if (self->transpose_xy != self->absolute_transform->transpose_xy) { + int16_t temp_stride = x_stride; + x_stride = y_stride; + y_stride = temp_stride; + int16_t temp_shift = x_shift; + x_shift = y_shift; + y_shift = temp_shift; + } + + for (int16_t y = start_y; y < end_y; y++) { + int16_t row_start = start + (y - start_y + y_shift) * y_stride; + int16_t local_y = y / self->absolute_transform->scale; + for (int16_t x = start_x; x < end_x; x++) { // Compute the destination pixel in the buffer and mask based on the transformations. - uint16_t offset = row_start + (x - x_shift) * x_stride; + int16_t offset = row_start + (x - start_x + x_shift) * x_stride; // This is super useful for debugging out range accesses. Uncomment to use. - // if (offset < 0 || offset >= displayio_area_size(area)) { + // if (offset < 0 || offset >= (int32_t) displayio_area_size(area)) { // asm("bkpt"); // } @@ -211,7 +392,7 @@ bool displayio_tilegrid_get_area(displayio_tilegrid_t *self, displayio_buffer_tr if ((mask[offset / 32] & (1 << (offset % 32))) != 0) { continue; } - int16_t local_x = x / transform->scale; + int16_t local_x = x / self->absolute_transform->scale; uint16_t tile_location = ((local_y / self->tile_height + self->top_left_y) % self->height_in_tiles) * self->width_in_tiles + (local_x / self->tile_width + self->top_left_x) % self->width_in_tiles; uint8_t tile = tiles[tile_location]; uint16_t tile_x = (tile % self->bitmap_width_in_tiles) * self->tile_width + local_x % self->tile_width; @@ -252,20 +433,15 @@ bool displayio_tilegrid_get_area(displayio_tilegrid_t *self, displayio_buffer_tr return full_coverage; } -bool displayio_tilegrid_needs_refresh(displayio_tilegrid_t *self) { - if (self->needs_refresh) { - return true; - } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type)) { - return displayio_palette_needs_refresh(self->pixel_shader); - } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type)) { - return displayio_colorconverter_needs_refresh(self->pixel_shader); +void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) { + if (self->moved || self->first_draw) { + displayio_area_copy(&self->current_area, &self->previous_area); } - return false; -} - -void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) { - self->needs_refresh = false; + self->moved = false; + self->full_change = false; + self->partial_change = false; + self->first_draw = false; if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type)) { displayio_palette_finish_refresh(self->pixel_shader); } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type)) { @@ -274,3 +450,58 @@ void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) { // TODO(tannewt): We could double buffer changes to position and move them over here. // That way they won't change during a refresh and tear. } + +displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t* tail) { + if (self->moved && !self->first_draw) { + displayio_area_union(&self->previous_area, &self->current_area, &self->dirty_area); + if (displayio_area_size(&self->dirty_area) <= 2 * self->pixel_width * self->pixel_height) { + self->dirty_area.next = tail; + return &self->dirty_area; + } + self->previous_area.next = tail; + self->current_area.next = &self->previous_area; + return &self->current_area; + } + + // We must recheck if our sources require a refresh because needs_refresh may or may not have + // been called. + self->full_change = self->full_change || + (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type) && + displayio_palette_needs_refresh(self->pixel_shader)) || + (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type) && + displayio_colorconverter_needs_refresh(self->pixel_shader)); + if (self->full_change || self->first_draw) { + self->current_area.next = tail; + return &self->current_area; + } + + if (self->partial_change) { + if (self->absolute_transform->transpose_xy) { + int16_t x1 = self->dirty_area.x1; + self->dirty_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + self->dirty_area.y1); + self->dirty_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + x1); + int16_t x2 = self->dirty_area.x2; + self->dirty_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + self->dirty_area.y2); + self->dirty_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + x2); + } else { + self->dirty_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + self->dirty_area.x1); + self->dirty_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + self->dirty_area.y1); + self->dirty_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + self->dirty_area.x2); + self->dirty_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + self->dirty_area.y2); + } + if (self->dirty_area.y2 < self->dirty_area.y1) { + int16_t temp = self->dirty_area.y2; + self->dirty_area.y2 = self->dirty_area.y1; + self->dirty_area.y1 = temp; + } + if (self->dirty_area.x2 < self->dirty_area.x1) { + int16_t temp = self->dirty_area.x2; + self->dirty_area.x2 = self->dirty_area.x1; + self->dirty_area.x1 = temp; + } + + self->dirty_area.next = tail; + return &self->dirty_area; + } + return tail; +} diff --git a/shared-module/displayio/TileGrid.h b/shared-module/displayio/TileGrid.h index 6157dfbe8..4d97eccc2 100644 --- a/shared-module/displayio/TileGrid.h +++ b/shared-module/displayio/TileGrid.h @@ -37,7 +37,10 @@ typedef struct { mp_obj_base_t base; mp_obj_t bitmap; mp_obj_t pixel_shader; - displayio_area_t area; + int16_t x; + int16_t y; + uint16_t pixel_width; + uint16_t pixel_height; uint16_t bitmap_width_in_tiles; uint16_t width_in_tiles; uint16_t height_in_tiles; @@ -46,12 +49,34 @@ typedef struct { uint16_t top_left_x; uint16_t top_left_y; uint8_t* tiles; - bool needs_refresh; + const displayio_buffer_transform_t* absolute_transform; + displayio_area_t dirty_area; // Stored as a relative area until the refresh area is fetched. + displayio_area_t previous_area; // Stored as an absolute area. + displayio_area_t current_area; // Stored as an absolute area so it applies across frames. + bool partial_change; + bool full_change; + bool first_draw; + bool moved; bool inline_tiles; + bool in_group; + bool flip_x; + bool flip_y; + bool transpose_xy; } displayio_tilegrid_t; -bool displayio_tilegrid_get_area(displayio_tilegrid_t *self, displayio_buffer_transform_t* transform, displayio_area_t* area, uint32_t* mask, uint32_t *buffer); -bool displayio_tilegrid_needs_refresh(displayio_tilegrid_t *self); +// Updating the screen is a three stage process. + +// The first stage is used to determine i +displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t* tail); + +// Area is always in absolute screen coordinates. Update transform is used to inform TileGrids how +// they relate to it. +bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); +void displayio_tilegrid_update_transform(displayio_tilegrid_t *group, const displayio_buffer_transform_t* parent_transform); + +// Fills in area with the maximum bounds of all related pixels in the last rendered frame. Returns +// false if the tilegrid wasn't rendered in the last frame. +bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t* area); void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self); #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_TILEGRID_H diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 35bdad8fe..b6709e0eb 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -1,5 +1,6 @@ #include + #include "shared-module/displayio/__init__.h" #include "lib/utils/interrupt_char.h" @@ -19,14 +20,83 @@ primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT]; -static inline void swap(int16_t* a, int16_t* b) { - int16_t temp = *a; - *a = *b; - *b = temp; +bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area) { + uint16_t buffer_size = 512; + + displayio_area_t clipped; + // Clip the area to the display by overlapping the areas. If there is no overlap then we're done. + if (!displayio_display_clip_area(display, area, &clipped)) { + return true; + } + uint16_t subrectangles = 1; + uint16_t rows_per_buffer = displayio_area_height(&clipped); + if (displayio_area_size(area) > buffer_size) { + rows_per_buffer = buffer_size / displayio_area_width(&clipped); + subrectangles = displayio_area_height(&clipped) / rows_per_buffer; + if (displayio_area_height(&clipped) % rows_per_buffer != 0) { + subrectangles++; + } + buffer_size = rows_per_buffer * displayio_area_width(&clipped); + } + uint32_t buffer[buffer_size / 2]; + uint16_t remaining_rows = displayio_area_height(&clipped); + + for (uint16_t j = 0; j < subrectangles; j++) { + displayio_area_t subrectangle = { + .x1 = clipped.x1, + .y1 = clipped.y1 + rows_per_buffer * j, + .x2 = clipped.x2, + .y2 = clipped.y1 + rows_per_buffer * (j + 1) + }; + if (remaining_rows < rows_per_buffer) { + subrectangle.y2 = subrectangle.y1 + remaining_rows; + } + remaining_rows -= rows_per_buffer; + + displayio_display_begin_transaction(display); + displayio_display_set_region_to_update(display, subrectangle.x1, subrectangle.y1, + subrectangle.x2, subrectangle.y2); + displayio_display_end_transaction(display); + + uint32_t mask[(buffer_size / 32) + 1]; + for (uint16_t k = 0; k < (buffer_size / 32) + 1; k++) { + mask[k] = 0x00000000; + } + + bool full_coverage = displayio_display_fill_area(display, &subrectangle, mask, buffer); + if (!full_coverage) { + uint32_t index = 0; + uint32_t current_mask = 0; + for (int16_t y = subrectangle.y1; y < subrectangle.y2; y++) { + for (int16_t x = subrectangle.x1; x < subrectangle.x2; x++) { + if (index % 32 == 0) { + current_mask = mask[index / 32]; + } + if ((current_mask & (1 << (index % 32))) == 0) { + ((uint16_t*) buffer)[index] = 0x0000; + } + index++; + } + } + } + + if (!displayio_display_begin_transaction(display)) { + // Can't acquire display bus; skip the rest of the data. Try next display. + return false; + } + displayio_display_send_pixels(display, (uint8_t*) buffer, displayio_area_size(&subrectangle) * sizeof(uint16_t)); + displayio_display_end_transaction(display); + + // TODO(tannewt): Make refresh displays faster so we don't starve other + // background tasks. + usb_background(); + } + return true; } // Check for recursive calls to displayio_refresh_displays. bool refresh_displays_in_progress = false; +uint32_t frame_count = 0; void displayio_refresh_displays(void) { if (mp_hal_is_interrupted()) { @@ -57,115 +127,19 @@ void displayio_refresh_displays(void) { // Too soon. Try next display. continue; } - if (displayio_display_refresh_queued(display)) { - if (!displayio_display_begin_transaction(display)) { - // Can't acquire display bus; skip updating this display. Try next display. - continue; - } - displayio_display_end_transaction(display); - - displayio_area_t whole_screen = { - .x1 = 0, - .y1 = 0, - .x2 = display->width, - .y2 = display->height - }; - if (display->transpose_xy) { - swap(&whole_screen.x2, &whole_screen.y2); - } - - uint16_t buffer_size = 512; - - uint16_t subrectangles = 1; - uint16_t rows_per_buffer = displayio_area_height(&whole_screen); - if (displayio_area_size(&whole_screen) > buffer_size) { - rows_per_buffer = buffer_size / displayio_area_width(&whole_screen); - subrectangles = displayio_area_height(&whole_screen) / rows_per_buffer; - buffer_size = rows_per_buffer * displayio_area_width(&whole_screen); - } - uint32_t buffer[buffer_size / 2]; - - for (uint16_t j = 0; j < subrectangles; j++) { - displayio_area_t subrectangle = { - .x1 = 0, - .y1 = rows_per_buffer * j, - .x2 = displayio_area_width(&whole_screen), - .y2 = rows_per_buffer * (j + 1) - }; - - displayio_display_begin_transaction(display); - displayio_display_set_region_to_update(display, subrectangle.x1, subrectangle.y1, - subrectangle.x2, subrectangle.y2); - displayio_display_end_transaction(display); - - // Handle display mirroring and transpose. - displayio_area_t transformed_subrectangle; - displayio_buffer_transform_t transform; - if (display->mirror_x) { - uint16_t width = displayio_area_width(&whole_screen); - transformed_subrectangle.x1 = width - subrectangle.x2; - transformed_subrectangle.x2 = width - subrectangle.x1; - } else { - transformed_subrectangle.x1 = subrectangle.x1; - transformed_subrectangle.x2 = subrectangle.x2; - } - if (display->mirror_y != display->transpose_xy) { - uint16_t height = displayio_area_height(&whole_screen); - transformed_subrectangle.y1 = height - subrectangle.y2; - transformed_subrectangle.y2 = height - subrectangle.y1; - } else { - transformed_subrectangle.y1 = subrectangle.y1; - transformed_subrectangle.y2 = subrectangle.y2; - } - transform.width = transformed_subrectangle.x2 - transformed_subrectangle.x1; - transform.height = transformed_subrectangle.y2 - transformed_subrectangle.y1; - if (display->transpose_xy) { - int16_t y1 = transformed_subrectangle.y1; - int16_t y2 = transformed_subrectangle.y2; - transformed_subrectangle.y1 = transformed_subrectangle.x1; - transformed_subrectangle.y2 = transformed_subrectangle.x2; - transformed_subrectangle.x1 = y1; - transformed_subrectangle.x2 = y2; - } - transform.transpose_xy = display->transpose_xy; - transform.mirror_x = display->mirror_x; - transform.mirror_y = display->mirror_y; - transform.scale = 1; - - uint32_t mask[(buffer_size / 32) + 1]; - for (uint16_t k = 0; k < (buffer_size / 32) + 1; k++) { - mask[k] = 0x00000000; - } - bool full_coverage = displayio_group_get_area(display->current_group, &transform, &transformed_subrectangle, mask, buffer); - if (!full_coverage) { - uint32_t index = 0; - uint32_t current_mask = 0; - for (int16_t y = subrectangle.y1; y < subrectangle.y2; y++) { - for (int16_t x = subrectangle.x1; x < subrectangle.x2; x++) { - if (index % 32 == 0) { - current_mask = mask[index / 32]; - } - if ((current_mask & (1 << (index % 32))) == 0) { - ((uint16_t*) buffer)[index] = 0x0000; - } - index++; - } - } - } - - if (!displayio_display_begin_transaction(display)) { - // Can't acquire display bus; skip the rest of the data. Try next display. - break; - } - displayio_display_send_pixels(display, buffer, buffer_size / 2); - displayio_display_end_transaction(display); - - // TODO(tannewt): Make refresh displays faster so we don't starve other - // background tasks. - usb_background(); - } + if (!displayio_display_begin_transaction(display)) { + // Can't acquire display bus; skip updating this display. Try next display. + continue; + } + displayio_display_end_transaction(display); + displayio_display_start_refresh(display); + const displayio_area_t* current_area = displayio_display_get_refresh_areas(display); + while (current_area != NULL) { + refresh_area(display, current_area); + current_area = current_area->next; } displayio_display_finish_refresh(display); + frame_count++; } // All done. @@ -244,6 +218,35 @@ void displayio_gc_collect(void) { } } +void displayio_area_expand(displayio_area_t* original, const displayio_area_t* addition) { + if (addition->x1 < original->x1) { + original->x1 = addition->x1; + } + if (addition->y1 < original->y1) { + original->y1 = addition->y1; + } + if (addition->x2 > original->x2) { + original->x2 = addition->x2; + } + if (addition->y2 > original->y2) { + original->y2 = addition->y2; + } +} + +void displayio_area_copy(const displayio_area_t* src, displayio_area_t* dst) { + dst->x1 = src->x1; + dst->y1 = src->y1; + dst->x2 = src->x2; + dst->y2 = src->y2; +} + +void displayio_area_scale(displayio_area_t* area, uint16_t scale) { + area->x1 *= scale; + area->y1 *= scale; + area->x2 *= scale; + area->y2 *= scale; +} + void displayio_area_shift(displayio_area_t* area, int16_t dx, int16_t dy) { area->x1 += dx; area->y1 += dy; @@ -262,7 +265,7 @@ bool displayio_area_compute_overlap(const displayio_area_t* a, if (b->x2 < overlap->x2) { overlap->x2 = b->x2; } - if (overlap->x1 > overlap->x2) { + if (overlap->x1 >= overlap->x2) { return false; } overlap->y1 = a->y1; @@ -273,12 +276,34 @@ bool displayio_area_compute_overlap(const displayio_area_t* a, if (b->y2 < overlap->y2) { overlap->y2 = b->y2; } - if (overlap->y1 > overlap->y2) { + if (overlap->y1 >= overlap->y2) { return false; } return true; } +void displayio_area_union(const displayio_area_t* a, + const displayio_area_t* b, + displayio_area_t* u) { + u->x1 = a->x1; + if (b->x1 < u->x1) { + u->x1 = b->x1; + } + u->x2 = a->x2; + if (b->x2 > u->x2) { + u->x2 = b->x2; + } + + u->y1 = a->y1; + if (b->y1 < u->y1) { + u->y1 = b->y1; + } + u->y2 = a->y2; + if (b->y2 > u->y2) { + u->y2 = b->y2; + } +} + uint16_t displayio_area_width(const displayio_area_t* area) { return area->x2 - area->x1; } @@ -297,3 +322,32 @@ bool displayio_area_equal(const displayio_area_t* a, const displayio_area_t* b) a->x2 == b->x2 && a->y2 == b->y2; } + +// Original and whole must be in the same coordinate space. +void displayio_area_transform_within(bool mirror_x, bool mirror_y, bool transpose_xy, + const displayio_area_t* original, + const displayio_area_t* whole, + displayio_area_t* transformed) { + if (mirror_x) { + transformed->x1 = whole->x1 + (whole->x2 - original->x2); + transformed->x2 = whole->x2 - (original->x1 - whole->x1); + } else { + transformed->x1 = original->x1; + transformed->x2 = original->x2; + } + if (mirror_y) { + transformed->y1 = whole->y1 + (whole->y2 - original->y2); + transformed->y2 = whole->y2 - (original->y1 - whole->y1); + } else { + transformed->y1 = original->y1; + transformed->y2 = original->y2; + } + if (transpose_xy) { + int16_t y1 = transformed->y1; + int16_t y2 = transformed->y2; + transformed->y1 = whole->y1 + (transformed->x1 - whole->x1); + transformed->y2 = whole->y1 + (transformed->x2 - whole->x1); + transformed->x2 = whole->x1 + (y2 - whole->y1); + transformed->x1 = whole->x1 + (y1 - whole->y1); + } +} diff --git a/shared-module/displayio/area.h b/shared-module/displayio/area.h index 9db57e13f..ec7c389b4 100644 --- a/shared-module/displayio/area.h +++ b/shared-module/displayio/area.h @@ -28,23 +28,35 @@ #define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_AREA_H // Implementations are in __init__.c +typedef struct _displayio_area_t displayio_area_t; -typedef struct { +struct _displayio_area_t { int16_t x1; int16_t y1; int16_t x2; // Second point is exclusive. int16_t y2; -} displayio_area_t; + const displayio_area_t* next; // Next area in the linked list. +}; typedef struct { + uint16_t x; + uint16_t y; + int8_t dx; + int8_t dy; + uint8_t scale; uint16_t width; uint16_t height; - uint8_t scale; bool mirror_x; bool mirror_y; bool transpose_xy; } displayio_buffer_transform_t; +void displayio_area_union(const displayio_area_t* a, + const displayio_area_t* b, + displayio_area_t* u); +void displayio_area_expand(displayio_area_t* original, const displayio_area_t* addition); +void displayio_area_copy(const displayio_area_t* src, displayio_area_t* dst); +void displayio_area_scale(displayio_area_t* area, uint16_t scale); void displayio_area_shift(displayio_area_t* area, int16_t dx, int16_t dy); bool displayio_area_compute_overlap(const displayio_area_t* a, const displayio_area_t* b, @@ -53,5 +65,9 @@ uint16_t displayio_area_width(const displayio_area_t* area); uint16_t displayio_area_height(const displayio_area_t* area); uint32_t displayio_area_size(const displayio_area_t* area); bool displayio_area_equal(const displayio_area_t* a, const displayio_area_t* b); +void displayio_area_transform_within(bool mirror_x, bool mirror_y, bool transpose_xy, + const displayio_area_t* original, + const displayio_area_t* whole, + displayio_area_t* transformed); #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_AREA_H diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 5eab74e16..c3afb3e00 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -50,6 +50,10 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { } width_in_tiles = (width_px - blinka_bitmap.width * scale) / (grid->tile_width * scale); uint16_t height_in_tiles = height_px / (grid->tile_height * scale); + uint16_t remaining_pixels = height_px % (grid->tile_height * scale); + if (remaining_pixels > 0) { + height_in_tiles += 1; + } circuitpython_splash.scale = scale; uint16_t total_tiles = width_in_tiles * height_in_tiles; @@ -67,11 +71,13 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { if (tiles == NULL) { return; } - + if (remaining_pixels > 0) { + grid->y -= (grid->tile_height - remaining_pixels); + } grid->width_in_tiles = width_in_tiles; grid->height_in_tiles = height_in_tiles; - grid->area.x2 = grid->area.x1 + width_in_tiles * grid->tile_width; - grid->area.y2 = grid->area.y1 + height_in_tiles * grid->tile_height; + grid->pixel_width = width_in_tiles * grid->tile_width; + grid->pixel_height = height_in_tiles * grid->tile_height; grid->tiles = tiles; supervisor_terminal.cursor_x = 0; @@ -157,12 +163,10 @@ displayio_tilegrid_t blinka_sprite = { .base = {.type = &displayio_tilegrid_type }, .bitmap = &blinka_bitmap, .pixel_shader = &blinka_palette, - .area = { - .x1 = 0, - .y1 = 0, - .x2 = 16, - .y2 = 16 - }, + .x = 0, + .y = 0, + .pixel_width = 16, + .pixel_height = 16, .bitmap_width_in_tiles = 1, .width_in_tiles = 1, .height_in_tiles = 1, @@ -171,8 +175,12 @@ displayio_tilegrid_t blinka_sprite = { .top_left_x = 16, .top_left_y = 16, .tiles = 0, - .needs_refresh = false, - .inline_tiles = true + .partial_change = false, + .full_change = false, + .first_draw = true, + .moved = false, + .inline_tiles = true, + .in_group = true }; displayio_group_child_t splash_children[2] = { @@ -188,5 +196,5 @@ displayio_group_t circuitpython_splash = { .size = 2, .max_size = 2, .children = splash_children, - .needs_refresh = true + .item_removed = false }; diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py index b1fd04831..7b28c3105 100644 --- a/tools/gen_display_resources.py +++ b/tools/gen_display_resources.py @@ -120,20 +120,22 @@ displayio_tilegrid_t supervisor_terminal_text_grid = {{ .base = {{ .type = &displayio_tilegrid_type }}, .bitmap = (displayio_bitmap_t*) &supervisor_terminal_font_bitmap, .pixel_shader = &supervisor_terminal_color, - .area = {{ - .x1 = 16, - .y1 = 0, - .x2 = {1} + 16, - .y2 = {2}, - }}, + .x = 16, + .y = 0, + .pixel_width = {1}, + .pixel_height = {2}, .bitmap_width_in_tiles = {0}, .width_in_tiles = 1, .height_in_tiles = 1, .tile_width = {1}, .tile_height = {2}, .tiles = NULL, - .needs_refresh = false, - .inline_tiles = false + .partial_change = false, + .full_change = false, + .first_draw = true, + .moved = false, + .inline_tiles = false, + .in_group = true }}; """.format(len(all_characters), tile_x, tile_y)) -- cgit v1.2.3 From a35d9b469d4ed65fd992771aa98ac57241983794 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 12 Jun 2019 01:00:59 -0700 Subject: Refactor deinit check to reduce code size. --- shared-bindings/_pew/PewPew.c | 15 ++++++++------ shared-bindings/analogio/AnalogIn.c | 9 +++++++-- shared-bindings/analogio/AnalogOut.c | 4 +++- shared-bindings/audiobusio/I2SOut.c | 17 ++++++++++------ shared-bindings/audiobusio/PDMIn.c | 9 +++++++-- shared-bindings/audioio/AudioOut.c | 17 ++++++++++------ shared-bindings/audioio/Mixer.c | 14 +++++++++---- shared-bindings/audioio/RawSample.c | 10 +++++++-- shared-bindings/audioio/WaveFile.c | 14 +++++++++---- shared-bindings/bitbangio/I2C.c | 17 ++++++++++------ shared-bindings/bitbangio/OneWire.c | 12 ++++++++--- shared-bindings/bitbangio/SPI.c | 18 +++++++++++------ shared-bindings/bleio/CharacteristicBuffer.c | 14 +++++++++---- shared-bindings/busio/I2C.c | 16 ++++++++++----- shared-bindings/busio/OneWire.c | 12 ++++++++--- shared-bindings/busio/SPI.c | 21 +++++++++++-------- shared-bindings/busio/UART.c | 20 +++++++++++------- shared-bindings/digitalio/DigitalInOut.c | 29 ++++++++++++++++----------- shared-bindings/frequencyio/FrequencyIn.c | 18 +++++++++++------ shared-bindings/i2cslave/I2CSlave.c | 4 +++- shared-bindings/ps2io/Ps2.c | 14 +++++++++---- shared-bindings/pulseio/PWMOut.c | 14 +++++++++---- shared-bindings/pulseio/PulseIn.c | 22 ++++++++++++-------- shared-bindings/pulseio/PulseOut.c | 4 +++- shared-bindings/rotaryio/IncrementalEncoder.c | 10 +++++++-- shared-bindings/touchio/TouchIn.c | 14 +++++++++---- shared-bindings/util.c | 8 +++----- shared-bindings/util.h | 2 +- shared-module/displayio/Display.h | 28 +++++++++++++------------- shared-module/displayio/Group.h | 2 +- 30 files changed, 270 insertions(+), 138 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index d7ae0116d..3ff208761 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -96,8 +96,9 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_TypeError(translate("Row entry must be digitalio.DigitalInOut")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(rows[i]); - raise_error_if_deinited( - common_hal_digitalio_digitalinout_deinited(pin)); + if (common_hal_digitalio_digitalinout_deinited(pin)) { + raise_deinited_error(); + } } for (size_t i = 0; i < cols_size; ++i) { @@ -105,8 +106,9 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_TypeError(translate("Column entry must be digitalio.DigitalInOut")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(cols[i]); - raise_error_if_deinited( - common_hal_digitalio_digitalinout_deinited(pin)); + if (common_hal_digitalio_digitalinout_deinited(pin)) { + raise_deinited_error(); + } } if (!MP_OBJ_IS_TYPE(args[ARG_buttons].u_obj, @@ -115,8 +117,9 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, } digitalio_digitalinout_obj_t *buttons = MP_OBJ_TO_PTR( args[ARG_buttons].u_obj); - raise_error_if_deinited( - common_hal_digitalio_digitalinout_deinited(buttons)); + if (common_hal_digitalio_digitalinout_deinited(buttons)) { + raise_deinited_error(); + } pew_obj_t *pew = MP_STATE_VM(pew_singleton); if (!pew) { diff --git a/shared-bindings/analogio/AnalogIn.c b/shared-bindings/analogio/AnalogIn.c index 116f82a03..a8bbbf59a 100644 --- a/shared-bindings/analogio/AnalogIn.c +++ b/shared-bindings/analogio/AnalogIn.c @@ -86,6 +86,11 @@ STATIC mp_obj_t analogio_analogin_deinit(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogin_deinit_obj, analogio_analogin_deinit); +STATIC void check_for_deinit(analogio_analogin_obj_t *self) { + if (common_hal_analogio_analogin_deinited(self)) { + raise_deinited_error(); + } +} //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -113,7 +118,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(analogio_analogin___exit___obj, 4, 4, //| STATIC mp_obj_t analogio_analogin_obj_get_value(mp_obj_t self_in) { analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_analogio_analogin_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_analogio_analogin_get_value(self)); } MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogin_get_value_obj, analogio_analogin_obj_get_value); @@ -132,7 +137,7 @@ const mp_obj_property_t analogio_analogin_value_obj = { //| STATIC mp_obj_t analogio_analogin_obj_get_reference_voltage(mp_obj_t self_in) { analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_analogio_analogin_deinited(self)); + check_for_deinit(self); return mp_obj_new_float(common_hal_analogio_analogin_get_reference_voltage(self)); } MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogin_get_reference_voltage_obj, diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c index dcbd7ecfb..0816da465 100644 --- a/shared-bindings/analogio/AnalogOut.c +++ b/shared-bindings/analogio/AnalogOut.c @@ -112,7 +112,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(analogio_analogout___exit___obj, 4, 4 //| resolution, the value is 16-bit. STATIC mp_obj_t analogio_analogout_obj_set_value(mp_obj_t self_in, mp_obj_t value) { analogio_analogout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_analogio_analogout_deinited(self)); + if (common_hal_analogio_analogout_deinited(self)) { + raise_deinited_error(); + } uint32_t v = mp_obj_get_int(value); if (v >= (1 << 16)) { mp_raise_ValueError(translate("AnalogOut is only 16 bits. Value must be less than 65536.")); diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index 48424d073..980f11392 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -134,6 +134,11 @@ STATIC mp_obj_t audiobusio_i2sout_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_deinit_obj, audiobusio_i2sout_deinit); +STATIC void check_for_deinit(audiobusio_i2sout_obj_t *self) { + if (common_hal_audiobusio_i2sout_deinited(self)) { + raise_deinited_error(); + } +} //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -169,7 +174,7 @@ STATIC mp_obj_t audiobusio_i2sout_obj_play(size_t n_args, const mp_obj_t *pos_ar { MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_audiobusio_i2sout_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -186,7 +191,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiobusio_i2sout_play_obj, 1, audiobusio_i2sout_obj_ //| STATIC mp_obj_t audiobusio_i2sout_obj_stop(mp_obj_t self_in) { audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audiobusio_i2sout_deinited(self)); + check_for_deinit(self); common_hal_audiobusio_i2sout_stop(self); return mp_const_none; } @@ -198,7 +203,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_stop_obj, audiobusio_i2sout_obj_stop //| STATIC mp_obj_t audiobusio_i2sout_obj_get_playing(mp_obj_t self_in) { audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audiobusio_i2sout_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_audiobusio_i2sout_get_playing(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_get_playing_obj, audiobusio_i2sout_obj_get_playing); @@ -216,7 +221,7 @@ const mp_obj_property_t audiobusio_i2sout_playing_obj = { //| STATIC mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) { audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audiobusio_i2sout_deinited(self)); + check_for_deinit(self); if (!common_hal_audiobusio_i2sout_get_playing(self)) { mp_raise_RuntimeError(translate("Not playing")); @@ -232,7 +237,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_pause_obj, audiobusio_i2sout_obj_pau //| STATIC mp_obj_t audiobusio_i2sout_obj_resume(mp_obj_t self_in) { audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audiobusio_i2sout_deinited(self)); + check_for_deinit(self); if (common_hal_audiobusio_i2sout_get_paused(self)) { common_hal_audiobusio_i2sout_resume(self); @@ -248,7 +253,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_resume_obj, audiobusio_i2sout_obj_re //| STATIC mp_obj_t audiobusio_i2sout_obj_get_paused(mp_obj_t self_in) { audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audiobusio_i2sout_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_audiobusio_i2sout_get_paused(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_get_paused_obj, audiobusio_i2sout_obj_get_paused); diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index 0f19e2587..0c92c2478 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -156,6 +156,11 @@ STATIC mp_obj_t audiobusio_pdmin_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_pdmin_deinit_obj, audiobusio_pdmin_deinit); +STATIC void check_for_deinit(audiobusio_pdmin_obj_t *self) { + if (common_hal_audiobusio_pdmin_deinited(self)) { + raise_deinited_error(); + } +} //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -188,7 +193,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_pdmin___exit___obj, 4, 4, //| STATIC mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destination, mp_obj_t destination_length) { audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_obj); - raise_error_if_deinited(common_hal_audiobusio_pdmin_deinited(self)); + check_for_deinit(self); if (!MP_OBJ_IS_SMALL_INT(destination_length) || MP_OBJ_SMALL_INT_VALUE(destination_length) < 0) { mp_raise_TypeError(translate("destination_length must be an int >= 0")); } @@ -223,7 +228,7 @@ MP_DEFINE_CONST_FUN_OBJ_3(audiobusio_pdmin_record_obj, audiobusio_pdmin_obj_reco //| STATIC mp_obj_t audiobusio_pdmin_obj_get_sample_rate(mp_obj_t self_in) { audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audiobusio_pdmin_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_audiobusio_pdmin_get_sample_rate(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_pdmin_get_sample_rate_obj, audiobusio_pdmin_obj_get_sample_rate); diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 9cb98d1f8..571dcdaca 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -133,6 +133,11 @@ STATIC mp_obj_t audioio_audioout_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_deinit_obj, audioio_audioout_deinit); +STATIC void check_for_deinit(audioio_audioout_obj_t *self) { + if (common_hal_audioio_audioout_deinited(self)) { + raise_deinited_error(); + } +} //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -170,7 +175,7 @@ STATIC mp_obj_t audioio_audioout_obj_play(size_t n_args, const mp_obj_t *pos_arg { MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_audioio_audioout_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -187,7 +192,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audioio_audioout_play_obj, 1, audioio_audioout_obj_pl //| STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) { audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_audioout_deinited(self)); + check_for_deinit(self); common_hal_audioio_audioout_stop(self); return mp_const_none; } @@ -199,7 +204,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_stop_obj, audioio_audioout_obj_stop); //| STATIC mp_obj_t audioio_audioout_obj_get_playing(mp_obj_t self_in) { audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_audioout_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_audioio_audioout_get_playing(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_get_playing_obj, audioio_audioout_obj_get_playing); @@ -217,7 +222,7 @@ const mp_obj_property_t audioio_audioout_playing_obj = { //| STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) { audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_audioout_deinited(self)); + check_for_deinit(self); if (!common_hal_audioio_audioout_get_playing(self)) { mp_raise_RuntimeError(translate("Not playing")); @@ -233,7 +238,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_pause_obj, audioio_audioout_obj_pause //| STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) { audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_audioout_deinited(self)); + check_for_deinit(self); if (common_hal_audioio_audioout_get_paused(self)) { common_hal_audioio_audioout_resume(self); @@ -249,7 +254,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_resume_obj, audioio_audioout_obj_resu //| STATIC mp_obj_t audioio_audioout_obj_get_paused(mp_obj_t self_in) { audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_audioout_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_audioio_audioout_get_paused(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_get_paused_obj, audioio_audioout_obj_get_paused); diff --git a/shared-bindings/audioio/Mixer.c b/shared-bindings/audioio/Mixer.c index 43ef2c524..dce4b3955 100644 --- a/shared-bindings/audioio/Mixer.c +++ b/shared-bindings/audioio/Mixer.c @@ -121,6 +121,12 @@ STATIC mp_obj_t audioio_mixer_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_deinit_obj, audioio_mixer_deinit); +STATIC void check_for_deinit(audioio_mixer_obj_t *self) { + if (common_hal_audioio_mixer_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -157,7 +163,7 @@ STATIC mp_obj_t audioio_mixer_obj_play(size_t n_args, const mp_obj_t *pos_args, { MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_audioio_mixer_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -178,7 +184,7 @@ STATIC mp_obj_t audioio_mixer_obj_stop_voice(size_t n_args, const mp_obj_t *pos_ { MP_QSTR_voice, MP_ARG_INT, {.u_int = 0} }, }; audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_audioio_mixer_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -193,7 +199,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audioio_mixer_stop_voice_obj, 1, audioio_mixer_obj_st //| STATIC mp_obj_t audioio_mixer_obj_get_playing(mp_obj_t self_in) { audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_mixer_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_audioio_mixer_get_playing(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_playing_obj, audioio_mixer_obj_get_playing); @@ -211,7 +217,7 @@ const mp_obj_property_t audioio_mixer_playing_obj = { //| STATIC mp_obj_t audioio_mixer_obj_get_sample_rate(mp_obj_t self_in) { audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_mixer_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_mixer_get_sample_rate(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_sample_rate_obj, audioio_mixer_obj_get_sample_rate); diff --git a/shared-bindings/audioio/RawSample.c b/shared-bindings/audioio/RawSample.c index 7fc896449..62998f580 100644 --- a/shared-bindings/audioio/RawSample.c +++ b/shared-bindings/audioio/RawSample.c @@ -115,6 +115,12 @@ STATIC mp_obj_t audioio_rawsample_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_rawsample_deinit_obj, audioio_rawsample_deinit); +STATIC void check_for_deinit(audioio_rawsample_obj_t *self) { + if (common_hal_audioio_rawsample_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -142,14 +148,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_rawsample___exit___obj, 4, 4, //| STATIC mp_obj_t audioio_rawsample_obj_get_sample_rate(mp_obj_t self_in) { audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_rawsample_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_rawsample_get_sample_rate(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audioio_rawsample_get_sample_rate_obj, audioio_rawsample_obj_get_sample_rate); STATIC mp_obj_t audioio_rawsample_obj_set_sample_rate(mp_obj_t self_in, mp_obj_t sample_rate) { audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_rawsample_deinited(self)); + check_for_deinit(self); common_hal_audioio_rawsample_set_sample_rate(self, mp_obj_get_int(sample_rate)); return mp_const_none; } diff --git a/shared-bindings/audioio/WaveFile.c b/shared-bindings/audioio/WaveFile.c index a4e37231a..242c915d3 100644 --- a/shared-bindings/audioio/WaveFile.c +++ b/shared-bindings/audioio/WaveFile.c @@ -92,6 +92,12 @@ STATIC mp_obj_t audioio_wavefile_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_deinit_obj, audioio_wavefile_deinit); +STATIC void check_for_deinit(audioio_wavefile_obj_t *self) { + if (common_hal_audioio_wavefile_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -118,14 +124,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_wavefile___exit___obj, 4, 4, //| STATIC mp_obj_t audioio_wavefile_obj_get_sample_rate(mp_obj_t self_in) { audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_wavefile_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_sample_rate(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_sample_rate_obj, audioio_wavefile_obj_get_sample_rate); STATIC mp_obj_t audioio_wavefile_obj_set_sample_rate(mp_obj_t self_in, mp_obj_t sample_rate) { audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_wavefile_deinited(self)); + check_for_deinit(self); common_hal_audioio_wavefile_set_sample_rate(self, mp_obj_get_int(sample_rate)); return mp_const_none; } @@ -144,7 +150,7 @@ const mp_obj_property_t audioio_wavefile_sample_rate_obj = { //| STATIC mp_obj_t audioio_wavefile_obj_get_bits_per_sample(mp_obj_t self_in) { audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_wavefile_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_bits_per_sample(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_bits_per_sample_obj, audioio_wavefile_obj_get_bits_per_sample); @@ -162,7 +168,7 @@ const mp_obj_property_t audioio_wavefile_bits_per_sample_obj = { //| STATIC mp_obj_t audioio_wavefile_obj_get_channel_count(mp_obj_t self_in) { audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_audioio_wavefile_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_channel_count(self)); } MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_channel_count_obj, audioio_wavefile_obj_get_channel_count); diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index a74f08b0b..0a3b03f51 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -69,7 +69,6 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj); bitbangio_i2c_obj_t *self = m_new_obj(bitbangio_i2c_obj_t); - raise_error_if_deinited(shared_module_bitbangio_i2c_deinited(self)); self->base.type = &bitbangio_i2c_type; shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int); return (mp_obj_t)self; @@ -86,6 +85,12 @@ STATIC mp_obj_t bitbangio_i2c_obj_deinit(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_deinit_obj, bitbangio_i2c_obj_deinit); +STATIC void check_for_deinit(bitbangio_i2c_obj_t *self) { + if (shared_module_bitbangio_i2c_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used in Context Managers. @@ -118,7 +123,7 @@ static void check_lock(bitbangio_i2c_obj_t *self) { //| STATIC mp_obj_t bitbangio_i2c_scan(mp_obj_t self_in) { bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_i2c_deinited(self)); + check_for_deinit(self); check_lock(self); mp_obj_t list = mp_obj_new_list(0, NULL); // 7-bit addresses 0b0000xxx and 0b1111xxx are reserved @@ -138,7 +143,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_scan_obj, bitbangio_i2c_scan); //| STATIC mp_obj_t bitbangio_i2c_obj_try_lock(mp_obj_t self_in) { bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_i2c_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(shared_module_bitbangio_i2c_try_lock(self)); } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_try_lock_obj, bitbangio_i2c_obj_try_lock); @@ -149,7 +154,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_try_lock_obj, bitbangio_i2c_obj_try_lock //| STATIC mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) { bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_i2c_deinited(self)); + check_for_deinit(self); shared_module_bitbangio_i2c_unlock(self); return mp_const_none; } @@ -179,7 +184,7 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a { MP_QSTR_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, }; bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(shared_module_bitbangio_i2c_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); check_lock(self); @@ -232,7 +237,7 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m { MP_QSTR_stop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, }; bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(shared_module_bitbangio_i2c_deinited(self)); + check_for_deinit(self); check_lock(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); diff --git a/shared-bindings/bitbangio/OneWire.c b/shared-bindings/bitbangio/OneWire.c index a3c53d2a5..73bedcd8d 100644 --- a/shared-bindings/bitbangio/OneWire.c +++ b/shared-bindings/bitbangio/OneWire.c @@ -91,6 +91,12 @@ STATIC mp_obj_t bitbangio_onewire_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_deinit_obj, bitbangio_onewire_deinit); +STATIC void check_for_deinit(bitbangio_onewire_obj_t *self) { + if (shared_module_bitbangio_onewire_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -115,7 +121,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_onewire___exit___obj, 4, 4, //| STATIC mp_obj_t bitbangio_onewire_obj_reset(mp_obj_t self_in) { bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_onewire_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(shared_module_bitbangio_onewire_reset(self)); } @@ -130,7 +136,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_reset_obj, bitbangio_onewire_obj_res //| STATIC mp_obj_t bitbangio_onewire_obj_read_bit(mp_obj_t self_in) { bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_onewire_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(shared_module_bitbangio_onewire_read_bit(self)); } @@ -142,7 +148,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_read_bit_obj, bitbangio_onewire_obj_ //| STATIC mp_obj_t bitbangio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) { bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_onewire_deinited(self)); + check_for_deinit(self); shared_module_bitbangio_onewire_write_bit(self, mp_obj_is_true(bool_obj)); return mp_const_none; diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 9d00264cd..88bd3d6cb 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -95,6 +95,12 @@ STATIC mp_obj_t bitbangio_spi_obj_deinit(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_deinit_obj, bitbangio_spi_obj_deinit); +STATIC void check_for_deinit(bitbangio_spi_obj_t *self) { + if (shared_module_bitbangio_spi_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -139,7 +145,7 @@ STATIC mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args, { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, }; bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(shared_module_bitbangio_spi_deinited(self)); + check_for_deinit(self); check_lock(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -171,7 +177,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_configure_obj, 1, bitbangio_spi_configu //| STATIC mp_obj_t bitbangio_spi_obj_try_lock(mp_obj_t self_in) { bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_spi_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(shared_module_bitbangio_spi_try_lock(self)); } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_try_lock_obj, bitbangio_spi_obj_try_lock); @@ -182,7 +188,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_try_lock_obj, bitbangio_spi_obj_try_lock //| STATIC mp_obj_t bitbangio_spi_obj_unlock(mp_obj_t self_in) { bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_spi_deinited(self)); + check_for_deinit(self); shared_module_bitbangio_spi_unlock(self); return mp_const_none; } @@ -196,7 +202,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_unlock_obj, bitbangio_spi_obj_unlock); // TODO(tannewt): Add support for start and end kwargs. STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) { bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(shared_module_bitbangio_spi_deinited(self)); + check_for_deinit(self); mp_buffer_info_t src; mp_get_buffer_raise(wr_buf, &src, MP_BUFFER_READ); if (src.len == 0) { @@ -221,7 +227,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_spi_write_obj, bitbangio_spi_write); // TODO(tannewt): Add support for start and end kwargs. STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) { bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(args[0]); - raise_error_if_deinited(shared_module_bitbangio_spi_deinited(self)); + check_for_deinit(self); mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); if (bufinfo.len == 0) { @@ -261,7 +267,7 @@ STATIC mp_obj_t bitbangio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_ { MP_QSTR_in_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, }; bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(shared_module_bitbangio_spi_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index 3604aeedb..a1dc663fd 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -92,6 +92,12 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, return MP_OBJ_FROM_PTR(self); } +STATIC void check_for_deinit(bleio_characteristic_buffer_obj_t *self) { + if (common_hal_bleio_characteristic_buffer_deinited(self)) { + raise_deinited_error(); + } +} + // These are standard stream methods. Code is in py/stream.c. // //| .. method:: read(nbytes=None) @@ -122,7 +128,7 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, // These three methods are used by the shared stream methods. STATIC mp_uint_t bleio_characteristic_buffer_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { bleio_characteristic_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_bleio_characteristic_buffer_deinited(self)); + check_for_deinit(self); raise_error_if_not_connected(self); byte *buf = buf_in; @@ -141,7 +147,7 @@ STATIC mp_uint_t bleio_characteristic_buffer_write(mp_obj_t self_in, const void STATIC mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { bleio_characteristic_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_bleio_characteristic_buffer_deinited(self)); + check_for_deinit(self); raise_error_if_not_connected(self); if (!common_hal_bleio_characteristic_buffer_connected(self)) { mp_raise_ValueError(translate("Not connected")); @@ -170,7 +176,7 @@ STATIC mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t r //| STATIC mp_obj_t bleio_characteristic_buffer_obj_get_in_waiting(mp_obj_t self_in) { bleio_characteristic_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_bleio_characteristic_buffer_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_characteristic_buffer_rx_characters_available(self)); } MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_buffer_get_in_waiting_obj, bleio_characteristic_buffer_obj_get_in_waiting); @@ -188,7 +194,7 @@ const mp_obj_property_t bleio_characteristic_buffer_in_waiting_obj = { //| STATIC mp_obj_t bleio_characteristic_buffer_obj_reset_input_buffer(mp_obj_t self_in) { bleio_characteristic_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_bleio_characteristic_buffer_deinited(self)); + check_for_deinit(self); common_hal_bleio_characteristic_buffer_clear_rx_buffer(self); return mp_const_none; } diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 1c50c07b0..0e639f0b5 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -93,6 +93,12 @@ STATIC mp_obj_t busio_i2c_obj_deinit(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_deinit_obj, busio_i2c_obj_deinit); +STATIC void check_for_deinit(busio_i2c_obj_t *self) { + if (common_hal_busio_i2c_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used in Context Managers. @@ -128,7 +134,7 @@ static void check_lock(busio_i2c_obj_t *self) { //| STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) { busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_i2c_deinited(self)); + check_for_deinit(self); check_lock(self); mp_obj_t list = mp_obj_new_list(0, NULL); // 7-bit addresses 0b0000xxx and 0b1111xxx are reserved @@ -151,7 +157,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_scan_obj, busio_i2c_scan); //| STATIC mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) { busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_i2c_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_busio_i2c_try_lock(self)); } MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock); @@ -162,7 +168,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock); //| STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) { busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_i2c_deinited(self)); + check_for_deinit(self); common_hal_busio_i2c_unlock(self); return mp_const_none; } @@ -192,7 +198,7 @@ STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, { MP_QSTR_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, }; busio_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_busio_i2c_deinited(self)); + check_for_deinit(self); check_lock(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -245,7 +251,7 @@ STATIC mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_ma { MP_QSTR_stop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, }; busio_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_busio_i2c_deinited(self)); + check_for_deinit(self); check_lock(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); diff --git a/shared-bindings/busio/OneWire.c b/shared-bindings/busio/OneWire.c index ceba4f8ee..aca2a3ef2 100644 --- a/shared-bindings/busio/OneWire.c +++ b/shared-bindings/busio/OneWire.c @@ -91,6 +91,12 @@ STATIC mp_obj_t busio_onewire_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_deinit_obj, busio_onewire_deinit); +STATIC void check_for_deinit(busio_onewire_obj_t *self) { + if (common_hal_busio_onewire_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -118,7 +124,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_onewire___exit___obj, 4, 4, bus //| STATIC mp_obj_t busio_onewire_obj_reset(mp_obj_t self_in) { busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_onewire_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_busio_onewire_reset(self)); } @@ -133,7 +139,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_reset_obj, busio_onewire_obj_reset); //| STATIC mp_obj_t busio_onewire_obj_read_bit(mp_obj_t self_in) { busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_onewire_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_busio_onewire_read_bit(self)); } @@ -145,7 +151,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_read_bit_obj, busio_onewire_obj_read_bit //| STATIC mp_obj_t busio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) { busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_onewire_deinited(self)); + check_for_deinit(self); common_hal_busio_onewire_write_bit(self, mp_obj_is_true(bool_obj)); return mp_const_none; diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index bd788365e..a7d7d515c 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -124,13 +124,19 @@ STATIC mp_obj_t busio_spi_obj___exit__(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_spi_obj___exit___obj, 4, 4, busio_spi_obj___exit__); -static void check_lock(busio_spi_obj_t *self) { +STATIC void check_lock(busio_spi_obj_t *self) { asm(""); if (!common_hal_busio_spi_has_lock(self)) { mp_raise_RuntimeError(translate("Function requires lock")); } } +STATIC void check_for_deinit(busio_spi_obj_t *self) { + if (common_hal_busio_spi_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: configure(*, baudrate=100000, polarity=0, phase=0, bits=8) //| //| Configures the SPI bus. The SPI object must be locked. @@ -162,7 +168,7 @@ STATIC mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_ { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, }; busio_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_busio_spi_deinited(self)); + check_for_deinit(self); check_lock(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -197,7 +203,6 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_configure_obj, 1, busio_spi_configure); //| STATIC mp_obj_t busio_spi_obj_try_lock(mp_obj_t self_in) { busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_spi_deinited(self)); return mp_obj_new_bool(common_hal_busio_spi_try_lock(self)); } MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_try_lock_obj, busio_spi_obj_try_lock); @@ -208,7 +213,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_try_lock_obj, busio_spi_obj_try_lock); //| STATIC mp_obj_t busio_spi_obj_unlock(mp_obj_t self_in) { busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_spi_deinited(self)); + check_for_deinit(self); common_hal_busio_spi_unlock(self); return mp_const_none; } @@ -231,7 +236,7 @@ STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_ { MP_QSTR_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, }; busio_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_busio_spi_deinited(self)); + check_for_deinit(self); check_lock(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -275,7 +280,7 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m { MP_QSTR_write_value,MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, }; busio_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_busio_spi_deinited(self)); + check_for_deinit(self); check_lock(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -324,7 +329,7 @@ STATIC mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args { MP_QSTR_in_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, }; busio_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_busio_spi_deinited(self)); + check_for_deinit(self); check_lock(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -367,7 +372,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_readinto_obj, 2, busio_spi_write_read //| STATIC mp_obj_t busio_spi_obj_get_frequency(mp_obj_t self_in) { busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_spi_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_busio_spi_get_frequency(self)); } MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_get_frequency_obj, busio_spi_obj_get_frequency); diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index eeffb62ef..c7eef8c43 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -137,6 +137,12 @@ STATIC mp_obj_t busio_uart_obj_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_deinit_obj, busio_uart_obj_deinit); +STATIC void check_for_deinit(busio_uart_obj_t *self) { + if (common_hal_busio_uart_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -196,7 +202,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_ // These three methods are used by the shared stream methods. STATIC mp_uint_t busio_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_uart_deinited(self)); + check_for_deinit(self); byte *buf = buf_in; // make sure we want at least 1 char @@ -209,7 +215,7 @@ STATIC mp_uint_t busio_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, STATIC mp_uint_t busio_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_uart_deinited(self)); + check_for_deinit(self); const byte *buf = buf_in; return common_hal_busio_uart_write(self, buf, size, errcode); @@ -217,7 +223,7 @@ STATIC mp_uint_t busio_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_ STATIC mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_uart_deinited(self)); + check_for_deinit(self); mp_uint_t ret; if (request == MP_IOCTL_POLL) { mp_uint_t flags = arg; @@ -241,14 +247,14 @@ STATIC mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t //| STATIC mp_obj_t busio_uart_obj_get_baudrate(mp_obj_t self_in) { busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_uart_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_busio_uart_get_baudrate(self)); } MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_get_baudrate_obj, busio_uart_obj_get_baudrate); STATIC mp_obj_t busio_uart_obj_set_baudrate(mp_obj_t self_in, mp_obj_t baudrate) { busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_uart_deinited(self)); + check_for_deinit(self); common_hal_busio_uart_set_baudrate(self, mp_obj_get_int(baudrate)); return mp_const_none; } @@ -268,7 +274,7 @@ const mp_obj_property_t busio_uart_baudrate_obj = { //| STATIC mp_obj_t busio_uart_obj_get_in_waiting(mp_obj_t self_in) { busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_uart_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_busio_uart_rx_characters_available(self)); } MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_get_in_waiting_obj, busio_uart_obj_get_in_waiting); @@ -286,7 +292,7 @@ const mp_obj_property_t busio_uart_in_waiting_obj = { //| STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) { busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_busio_uart_deinited(self)); + check_for_deinit(self); common_hal_busio_uart_clear_rx_buffer(self); return mp_const_none; } diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index 1ced15137..6587ee7ea 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -105,6 +105,12 @@ STATIC mp_obj_t digitalio_digitalinout_obj___exit__(size_t n_args, const mp_obj_ } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(digitalio_digitalinout_obj___exit___obj, 4, 4, digitalio_digitalinout_obj___exit__); +STATIC void check_for_deinit(digitalio_digitalinout_obj_t *self) { + if (common_hal_digitalio_digitalinout_deinited(self)) { + raise_deinited_error(); + } +} + //| //| .. method:: switch_to_output(value=False, drive_mode=digitalio.DriveMode.PUSH_PULL) //| @@ -121,7 +127,7 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_ { MP_QSTR_drive_mode, MP_ARG_OBJ, {.u_rom_obj = &digitalio_drive_mode_push_pull_obj} }, }; digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -158,7 +164,7 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_input(size_t n_args, const mp_o { MP_QSTR_pull, MP_ARG_OBJ, {.u_rom_obj = mp_const_none} }, }; digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -191,7 +197,7 @@ extern const digitalio_digitalio_direction_obj_t digitalio_digitalio_direction_o STATIC mp_obj_t digitalio_digitalinout_obj_get_direction(mp_obj_t self_in) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); digitalio_direction_t direction = common_hal_digitalio_digitalinout_get_direction(self); if (direction == DIRECTION_INPUT) { return (mp_obj_t)&digitalio_direction_input_obj; @@ -202,7 +208,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_get_direction_obj, digitalio_di STATIC mp_obj_t digitalio_digitalinout_obj_set_direction(mp_obj_t self_in, mp_obj_t value) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); if (value == &digitalio_direction_input_obj) { common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); } else if (value == &digitalio_direction_output_obj) { @@ -227,7 +233,7 @@ const mp_obj_property_t digitalio_digitalio_direction_obj = { //| STATIC mp_obj_t digitalio_digitalinout_obj_get_value(mp_obj_t self_in) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); bool value = common_hal_digitalio_digitalinout_get_value(self); return mp_obj_new_bool(value); } @@ -235,7 +241,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_get_value_obj, digitalio_digita STATIC mp_obj_t digitalio_digitalinout_obj_set_value(mp_obj_t self_in, mp_obj_t value) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { mp_raise_AttributeError(translate("Cannot set value when direction is input.")); return mp_const_none; @@ -261,7 +267,7 @@ const mp_obj_property_t digitalio_digitalinout_value_obj = { //| STATIC mp_obj_t digitalio_digitalinout_obj_get_drive_mode(mp_obj_t self_in) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { mp_raise_AttributeError(translate("Drive mode not used when direction is input.")); return mp_const_none; @@ -276,7 +282,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_get_drive_mode_obj, digitalio_d STATIC mp_obj_t digitalio_digitalinout_obj_set_drive_mode(mp_obj_t self_in, mp_obj_t drive_mode) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_INPUT) { mp_raise_AttributeError(translate("Drive mode not used when direction is input.")); return mp_const_none; @@ -309,7 +315,7 @@ const mp_obj_property_t digitalio_digitalio_drive_mode_obj = { //| STATIC mp_obj_t digitalio_digitalinout_obj_get_pull(mp_obj_t self_in) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_OUTPUT) { mp_raise_AttributeError(translate("Pull not used when direction is output.")); return mp_const_none; @@ -326,7 +332,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_get_pull_obj, digitalio_digital STATIC mp_obj_t digitalio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t pull_obj) { digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(self)); + check_for_deinit(self); if (common_hal_digitalio_digitalinout_get_direction(self) == DIRECTION_OUTPUT) { mp_raise_AttributeError(translate("Pull not used when direction is output.")); return mp_const_none; @@ -381,7 +387,6 @@ digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj) { mp_raise_TypeError(translate("argument num/types mismatch")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj); - raise_error_if_deinited( - common_hal_digitalio_digitalinout_deinited(pin)); + check_for_deinit(pin); return pin; } diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index 908cb307d..e2b924c07 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -109,6 +109,12 @@ STATIC mp_obj_t frequencyio_frequencyin_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_deinit_obj, frequencyio_frequencyin_deinit); +STATIC void check_for_deinit(frequencyio_frequencyin_obj_t *self) { + if (common_hal_frequencyio_frequencyin_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -133,7 +139,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(frequencyio_frequencyin___exit___obj, //| STATIC mp_obj_t frequencyio_frequencyin_obj_pause(mp_obj_t self_in) { frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + check_for_deinit(self); common_hal_frequencyio_frequencyin_pause(self); return mp_const_none; @@ -146,7 +152,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_pause_obj, frequencyio_frequen //| STATIC mp_obj_t frequencyio_frequencyin_obj_resume(mp_obj_t self_in) { frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + check_for_deinit(self); common_hal_frequencyio_frequencyin_resume(self); return mp_const_none; @@ -160,7 +166,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_resume_obj, frequencyio_freque STATIC mp_obj_t frequencyio_frequencyin_obj_clear(mp_obj_t self_in) { frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + check_for_deinit(self); common_hal_frequencyio_frequencyin_clear(self); return mp_const_none; @@ -178,7 +184,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_clear_obj, frequencyio_frequen //| STATIC mp_obj_t frequencyio_frequencyin_obj_get_capture_period(mp_obj_t self_in) { frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_frequencyio_frequencyin_get_capture_period(self)); } @@ -186,7 +192,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequency_get_capture_period_obj, frequenc STATIC mp_obj_t frequencyio_frequencyin_obj_set_capture_period(mp_obj_t self_in, mp_obj_t capture_period) { frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + check_for_deinit(self); common_hal_frequencyio_frequencyin_set_capture_period(self, mp_obj_get_int(capture_period)); return mp_const_none; @@ -206,7 +212,7 @@ const mp_obj_property_t frequencyio_frequencyin_capture_period_obj = { //| STATIC mp_obj_t frequencyio_frequencyin_obj_get_value(mp_obj_t self_in) { frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_frequencyio_frequencyin_deinited(self)); + check_for_deinit(self); //return MP_OBJ_NEW_SMALL_INT(common_hal_frequencyio_frequencyin_get_item(self)); return mp_obj_new_int_from_float(common_hal_frequencyio_frequencyin_get_item(self)); diff --git a/shared-bindings/i2cslave/I2CSlave.c b/shared-bindings/i2cslave/I2CSlave.c index 090a53581..2598accbb 100644 --- a/shared-bindings/i2cslave/I2CSlave.c +++ b/shared-bindings/i2cslave/I2CSlave.c @@ -150,7 +150,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cslave_i2c_slave___exit___obj, 4, 4 STATIC mp_obj_t i2cslave_i2c_slave_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cslave_i2c_slave_type)); i2cslave_i2c_slave_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_i2cslave_i2c_slave_deinited(self)); + if(common_hal_i2cslave_i2c_slave_deinited(self)) { + raise_deinited_error(); + } enum { ARG_timeout }; static const mp_arg_t allowed_args[] = { { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} }, diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c index bdbbf795c..fb5c24b85 100644 --- a/shared-bindings/ps2io/Ps2.c +++ b/shared-bindings/ps2io/Ps2.c @@ -103,6 +103,12 @@ STATIC mp_obj_t ps2io_ps2_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_deinit_obj, ps2io_ps2_deinit); +STATIC void check_for_deinit(ps2io_ps2_obj_t *self) { + if (common_hal_ps2io_ps2_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -128,7 +134,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ps2io_ps2___exit___obj, 4, 4, ps2io_p //| STATIC mp_obj_t ps2io_ps2_obj_popleft(mp_obj_t self_in) { ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_ps2io_ps2_deinited(self)); + check_for_deinit(self); int b = common_hal_ps2io_ps2_popleft(self); if (b < 0) { @@ -153,7 +159,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_popleft_obj, ps2io_ps2_obj_popleft); //| STATIC mp_obj_t ps2io_ps2_obj_sendcmd(mp_obj_t self_in, mp_obj_t ob) { ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_ps2io_ps2_deinited(self)); + check_for_deinit(self); mp_int_t cmd = mp_obj_get_int(ob) & 0xff; int resp = common_hal_ps2io_ps2_sendcmd(self, cmd); if (resp < 0) { @@ -195,7 +201,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(ps2io_ps2_sendcmd_obj, ps2io_ps2_obj_sendcmd); //| STATIC mp_obj_t ps2io_ps2_obj_clear_errors(mp_obj_t self_in) { ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_ps2io_ps2_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_ps2io_ps2_clear_errors(self)); } @@ -208,7 +214,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_clear_errors_obj, ps2io_ps2_obj_clear_errors //| STATIC mp_obj_t ps2_unary_op(mp_unary_op_t op, mp_obj_t self_in) { ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_ps2io_ps2_deinited(self)); + check_for_deinit(self); uint16_t len = common_hal_ps2io_ps2_get_len(self); switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len != 0); diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c index a7a90fb0d..40981e0a8 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pulseio/PWMOut.c @@ -133,6 +133,12 @@ STATIC mp_obj_t pulseio_pwmout_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pwmout_deinit_obj, pulseio_pwmout_deinit); +STATIC void check_for_deinit(pulseio_pwmout_obj_t *self) { + if (common_hal_pulseio_pwmout_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -158,14 +164,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pwmout___exit___obj, 4, 4, pu //| be half high and then half low. STATIC mp_obj_t pulseio_pwmout_obj_get_duty_cycle(mp_obj_t self_in) { pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pwmout_get_duty_cycle(self)); } MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pwmout_get_duty_cycle_obj, pulseio_pwmout_obj_get_duty_cycle); STATIC mp_obj_t pulseio_pwmout_obj_set_duty_cycle(mp_obj_t self_in, mp_obj_t duty_cycle) { pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); + check_for_deinit(self); mp_int_t duty = mp_obj_get_int(duty_cycle); if (duty < 0 || duty > 0xffff) { mp_raise_ValueError(translate("PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)")); @@ -189,14 +195,14 @@ const mp_obj_property_t pulseio_pwmout_duty_cycle_obj = { //| STATIC mp_obj_t pulseio_pwmout_obj_get_frequency(mp_obj_t self_in) { pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pwmout_get_frequency(self)); } MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pwmout_get_frequency_obj, pulseio_pwmout_obj_get_frequency); STATIC mp_obj_t pulseio_pwmout_obj_set_frequency(mp_obj_t self_in, mp_obj_t frequency) { pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); + check_for_deinit(self); if (!common_hal_pulseio_pwmout_get_variable_frequency(self)) { mp_raise_AttributeError(translate( "PWM frequency not writable when variable_frequency is False on " diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index 9f37c65c9..8b69109f0 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -114,6 +114,12 @@ STATIC mp_obj_t pulseio_pulsein_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulsein_deinit_obj, pulseio_pulsein_deinit); +STATIC void check_for_deinit(pulseio_pulsein_obj_t *self) { + if (common_hal_pulseio_pulsein_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -138,7 +144,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pulsein___exit___obj, 4, 4, p //| STATIC mp_obj_t pulseio_pulsein_obj_pause(mp_obj_t self_in) { pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); + check_for_deinit(self); common_hal_pulseio_pulsein_pause(self); return mp_const_none; @@ -162,7 +168,7 @@ STATIC mp_obj_t pulseio_pulsein_obj_resume(size_t n_args, const mp_obj_t *pos_ar { MP_QSTR_trigger_duration, MP_ARG_INT, {.u_int = 0} }, }; pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); + check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -178,7 +184,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pulseio_pulsein_resume_obj, 1, pulseio_pulsein_obj_re //| STATIC mp_obj_t pulseio_pulsein_obj_clear(mp_obj_t self_in) { pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); + check_for_deinit(self); common_hal_pulseio_pulsein_clear(self); return mp_const_none; @@ -191,7 +197,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulsein_clear_obj, pulseio_pulsein_obj_clear); //| STATIC mp_obj_t pulseio_pulsein_obj_popleft(mp_obj_t self_in) { pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pulsein_popleft(self)); } @@ -204,7 +210,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pulsein_popleft_obj, pulseio_pulsein_obj_pople //| STATIC mp_obj_t pulseio_pulsein_obj_get_maxlen(mp_obj_t self_in) { pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pulsein_get_maxlen(self)); } @@ -224,7 +230,7 @@ const mp_obj_property_t pulseio_pulsein_maxlen_obj = { //| STATIC mp_obj_t pulseio_pulsein_obj_get_paused(mp_obj_t self_in) { pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_pulseio_pulsein_get_paused(self)); } @@ -248,7 +254,7 @@ const mp_obj_property_t pulseio_pulsein_paused_obj = { //| STATIC mp_obj_t pulsein_unary_op(mp_unary_op_t op, mp_obj_t self_in) { pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); + check_for_deinit(self); uint16_t len = common_hal_pulseio_pulsein_get_len(self); switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len != 0); @@ -272,7 +278,7 @@ STATIC mp_obj_t pulsein_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t va mp_raise_AttributeError(translate("Cannot delete values")); } else { pulseio_pulsein_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pulsein_deinited(self)); + check_for_deinit(self); if (MP_OBJ_IS_TYPE(index_obj, &mp_type_slice)) { mp_raise_NotImplementedError(translate("Slices not supported")); diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 493b7e2ff..172459e5d 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -127,7 +127,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pulseout___exit___obj, 4, 4, //| STATIC mp_obj_t pulseio_pulseout_obj_send(mp_obj_t self_in, mp_obj_t pulses) { pulseio_pulseout_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_pulseio_pulseout_deinited(self)); + if (common_hal_pulseio_pulseout_deinited(self)) { + raise_deinited_error(); + } mp_buffer_info_t bufinfo; mp_get_buffer_raise(pulses, &bufinfo, MP_BUFFER_READ); diff --git a/shared-bindings/rotaryio/IncrementalEncoder.c b/shared-bindings/rotaryio/IncrementalEncoder.c index 5d2264ffc..f2f157847 100644 --- a/shared-bindings/rotaryio/IncrementalEncoder.c +++ b/shared-bindings/rotaryio/IncrementalEncoder.c @@ -100,6 +100,12 @@ STATIC mp_obj_t rotaryio_incrementalencoder_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(rotaryio_incrementalencoder_deinit_obj, rotaryio_incrementalencoder_deinit); +STATIC void check_for_deinit(rotaryio_incrementalencoder_obj_t *self) { + if (common_hal_rotaryio_incrementalencoder_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -126,7 +132,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rotaryio_incrementalencoder___exit___ //| STATIC mp_obj_t rotaryio_incrementalencoder_obj_get_position(mp_obj_t self_in) { rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_rotaryio_incrementalencoder_deinited(self)); + check_for_deinit(self); return mp_obj_new_int(common_hal_rotaryio_incrementalencoder_get_position(self)); } @@ -134,7 +140,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(rotaryio_incrementalencoder_get_position_obj, rotaryio STATIC mp_obj_t rotaryio_incrementalencoder_obj_set_position(mp_obj_t self_in, mp_obj_t new_position) { rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_rotaryio_incrementalencoder_deinited(self)); + check_for_deinit(self); common_hal_rotaryio_incrementalencoder_set_position(self, mp_obj_get_int(new_position)); return mp_const_none; diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c index 3b26aca8c..78fceef41 100644 --- a/shared-bindings/touchio/TouchIn.c +++ b/shared-bindings/touchio/TouchIn.c @@ -88,6 +88,12 @@ STATIC mp_obj_t touchio_touchin_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(touchio_touchin_deinit_obj, touchio_touchin_deinit); +STATIC void check_for_deinit(touchio_touchin_obj_t *self) { + if (common_hal_touchio_touchin_deinited(self)) { + raise_deinited_error(); + } +} + //| .. method:: __enter__() //| //| No-op used by Context Managers. @@ -114,7 +120,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(touchio_touchin___exit___obj, 4, 4, t //| STATIC mp_obj_t touchio_touchin_obj_get_value(mp_obj_t self_in) { touchio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_touchio_touchin_deinited(self)); + check_for_deinit(self); return mp_obj_new_bool(common_hal_touchio_touchin_get_value(self)); } MP_DEFINE_CONST_FUN_OBJ_1(touchio_touchin_get_value_obj, touchio_touchin_obj_get_value); @@ -133,7 +139,7 @@ const mp_obj_property_t touchio_touchin_value_obj = { //| STATIC mp_obj_t touchio_touchin_obj_get_raw_value(mp_obj_t self_in) { touchio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_touchio_touchin_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_touchio_touchin_get_raw_value(self)); } @@ -158,7 +164,7 @@ const mp_obj_property_t touchio_touchin_raw_value_obj = { //| STATIC mp_obj_t touchio_touchin_obj_get_threshold(mp_obj_t self_in) { touchio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_touchio_touchin_deinited(self)); + check_for_deinit(self); return MP_OBJ_NEW_SMALL_INT(common_hal_touchio_touchin_get_threshold(self)); } @@ -166,7 +172,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(touchio_touchin_get_threshold_obj, touchio_touchin_obj STATIC mp_obj_t touchio_touchin_obj_set_threshold(mp_obj_t self_in, mp_obj_t threshold_obj) { touchio_touchin_obj_t *self = MP_OBJ_TO_PTR(self_in); - raise_error_if_deinited(common_hal_touchio_touchin_deinited(self)); + check_for_deinit(self); uint32_t new_threshold = mp_obj_get_int(threshold_obj); if (new_threshold < 0 || new_threshold > UINT16_MAX) { // I would use MP_STRINGIFY(UINT16_MAX), but that prints "0xffff" instead of 65536. diff --git a/shared-bindings/util.c b/shared-bindings/util.c index 80a0bdaeb..c1ca01e0a 100644 --- a/shared-bindings/util.c +++ b/shared-bindings/util.c @@ -32,11 +32,9 @@ #include "shared-bindings/util.h" #include "supervisor/shared/translate.h" -// Check if pin is None. If so, deinit() has already been called on the object, so complain. -void raise_error_if_deinited(bool deinited) { - if (deinited) { - mp_raise_ValueError(translate("Object has been deinitialized and can no longer be used. Create a new object.")); - } +// If so, deinit() has already been called on the object, so complain. +void raise_deinited_error(void) { + mp_raise_ValueError(translate("Object has been deinitialized and can no longer be used. Create a new object.")); } diff --git a/shared-bindings/util.h b/shared-bindings/util.h index b26ed7e93..33454f10e 100644 --- a/shared-bindings/util.h +++ b/shared-bindings/util.h @@ -27,7 +27,7 @@ #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H -void raise_error_if_deinited(bool deinited); +void raise_deinited_error(void); #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 687e412c2..fa8902ced 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -40,19 +40,8 @@ typedef void (*display_bus_end_transaction)(mp_obj_t bus); typedef struct { mp_obj_base_t base; mp_obj_t bus; - uint16_t width; - uint16_t height; - uint16_t color_depth; - uint8_t set_column_command; - uint8_t set_row_command; - uint8_t write_ram_command; displayio_group_t *current_group; - bool refresh; uint64_t last_refresh; - int16_t colstart; - int16_t rowstart; - bool single_byte_bounds; - bool data_as_commands; display_bus_begin_transaction begin_transaction; display_bus_send send; display_bus_end_transaction end_transaction; @@ -61,11 +50,22 @@ typedef struct { pulseio_pwmout_obj_t backlight_pwm; }; uint64_t last_backlight_refresh; - bool auto_brightness:1; - bool updating_backlight:1; - bool full_refresh; // New group means we need to refresh the whole display. displayio_buffer_transform_t transform; displayio_area_t area; + uint16_t width; + uint16_t height; + uint16_t color_depth; + int16_t colstart; + int16_t rowstart; + uint8_t set_column_command; + uint8_t set_row_command; + uint8_t write_ram_command; + bool refresh; + bool single_byte_bounds; + bool data_as_commands; + bool auto_brightness; + bool updating_backlight; + bool full_refresh; // New group means we need to refresh the whole display. } displayio_display_obj_t; void displayio_display_start_refresh(displayio_display_obj_t* self); diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h index 1642b4602..7ce19a4cd 100644 --- a/shared-module/displayio/Group.h +++ b/shared-module/displayio/Group.h @@ -40,12 +40,12 @@ typedef struct { typedef struct { mp_obj_base_t base; + displayio_group_child_t* children; int16_t x; int16_t y; uint16_t scale; uint16_t size; uint16_t max_size; - displayio_group_child_t* children; bool item_removed; bool in_group; displayio_buffer_transform_t absolute_transform; -- cgit v1.2.3 From 5e265f4fbd11e1bc099f2a0860aac2ac72eaf854 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 12 Jun 2019 10:06:39 +0200 Subject: When clearing gamepad buffer, use the last button state, not 0 When reading the accumulated button presses in gamepad and gamepadshift, don't clear the buffer to "no buttons pressed", but instead set it to the current (last checked) state. This clears the accumulated presses, but retains any ongoing ones. This fixes #1935 --- shared-bindings/gamepad/GamePad.c | 2 +- shared-bindings/gamepadshift/GamePadShift.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/gamepad/GamePad.c b/shared-bindings/gamepad/GamePad.c index 15304d6a2..d3c29019a 100644 --- a/shared-bindings/gamepad/GamePad.c +++ b/shared-bindings/gamepad/GamePad.c @@ -127,7 +127,7 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t gamepad_get_pressed(mp_obj_t self_in) { gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); mp_obj_t pressed = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed); - gamepad_singleton->pressed = 0; + gamepad_singleton->pressed = gamepad_singleton->last; return pressed; } MP_DEFINE_CONST_FUN_OBJ_1(gamepad_get_pressed_obj, gamepad_get_pressed); diff --git a/shared-bindings/gamepadshift/GamePadShift.c b/shared-bindings/gamepadshift/GamePadShift.c index d6f365388..91203ad20 100644 --- a/shared-bindings/gamepadshift/GamePadShift.c +++ b/shared-bindings/gamepadshift/GamePadShift.c @@ -94,7 +94,7 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t gamepadshift_get_pressed(mp_obj_t self_in) { gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); mp_obj_t pressed = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed); - gamepad_singleton->pressed = 0; + gamepad_singleton->pressed = gamepad_singleton->last; return pressed; } MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_get_pressed_obj, gamepadshift_get_pressed); -- cgit v1.2.3 From 6f6dcafd906b2ac49291f4220f3fcc7cea6112e1 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 13 Jun 2019 00:34:19 -0700 Subject: Minor tweaks based on Dan's feedback --- shared-bindings/displayio/TileGrid.c | 4 +-- shared-module/displayio/Display.c | 2 +- shared-module/displayio/Group.c | 8 +++--- shared-module/displayio/TileGrid.c | 54 +++++++++++++----------------------- 4 files changed, 27 insertions(+), 41 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 5d064ae10..6ba4914a0 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -249,8 +249,8 @@ const mp_obj_property_t displayio_tilegrid_flip_y_obj = { //| .. attribute:: transpose_xy //| -//| If true, the TileGrid will be rotate 90 degrees. When combined with mirroring any 90 degree -//| rotation can be achieved. +//| If true, the TileGrid's axis will be swapped. When combined with mirroring, any 90 degree +//| rotation can be achieved along with the corresponding mirrored version. //| STATIC mp_obj_t displayio_tilegrid_obj_get_transpose_xy(mp_obj_t self_in) { displayio_tilegrid_t *self = native_tilegrid(self_in); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 4385e15f2..0ae88300a 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -354,4 +354,4 @@ bool displayio_display_fill_area(displayio_display_obj_t *self, displayio_area_t bool displayio_display_clip_area(displayio_display_obj_t *self, const displayio_area_t* area, displayio_area_t* clipped) { return displayio_area_compute_overlap(&self->area, area, clipped); -} \ No newline at end of file +} diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index 76c29d644..15060e87b 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -40,7 +40,7 @@ uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) { bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t* area) { bool first = true; - for (int32_t i = 0; i < self->size; i++) { + for (size_t i = 0; i < self->size; i++) { mp_obj_t layer = self->children[i].native; displayio_area_t layer_area; if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { @@ -74,7 +74,7 @@ static void _update_child_transforms(displayio_group_t* self) { if (!self->in_group) { return; } - for (int32_t i = 0; i < self->size; i++) { + for (size_t i = 0; i < self->size; i++) { mp_obj_t layer = self->children[i].native; if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { displayio_tilegrid_update_transform(layer, &self->absolute_transform); @@ -128,10 +128,10 @@ void common_hal_displayio_group_set_x(displayio_group_t* self, mp_int_t x) { return; } if (self->absolute_transform.transpose_xy) { - int8_t dy = self->absolute_transform.dy / self->scale; + int16_t dy = self->absolute_transform.dy / self->scale; self->absolute_transform.y += dy * (x - self->x); } else { - int8_t dx = self->absolute_transform.dx / self->scale; + int16_t dx = self->absolute_transform.dx / self->scale; self->absolute_transform.x += dx * (x - self->x); } diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 4420fc480..97b704c40 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -80,13 +80,15 @@ bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_ } void _update_current_x(displayio_tilegrid_t *self) { + int16_t width; + if (self->transpose_xy) { + width = self->pixel_height; + } else { + width = self->pixel_width; + } if (self->absolute_transform->transpose_xy) { self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->x; - if (self->transpose_xy) { - self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + self->pixel_height); - } else { - self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + self->pixel_width); - } + self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + width); if (self->current_area.y2 < self->current_area.y1) { int16_t temp = self->current_area.y2; self->current_area.y2 = self->current_area.y1; @@ -94,11 +96,7 @@ void _update_current_x(displayio_tilegrid_t *self) { } } else { self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->x; - if (self->transpose_xy) { - self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + self->pixel_height); - } else { - self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + self->pixel_width); - } + self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + width); if (self->current_area.x2 < self->current_area.x1) { int16_t temp = self->current_area.x2; self->current_area.x2 = self->current_area.x1; @@ -108,13 +106,15 @@ void _update_current_x(displayio_tilegrid_t *self) { } void _update_current_y(displayio_tilegrid_t *self) { + int16_t height; + if (self->transpose_xy) { + height = self->pixel_width; + } else { + height = self->pixel_height; + } if (self->absolute_transform->transpose_xy) { self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->y; - if (self->transpose_xy) { - self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + self->pixel_width); - } else { - self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + self->pixel_height); - } + self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + height); if (self->current_area.x2 < self->current_area.x1) { int16_t temp = self->current_area.x2; self->current_area.x2 = self->current_area.x1; @@ -122,11 +122,7 @@ void _update_current_y(displayio_tilegrid_t *self) { } } else { self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->y; - if (self->transpose_xy) { - self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + self->pixel_width); - } else { - self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + self->pixel_height); - } + self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + height); if (self->current_area.y2 < self->current_area.y1) { int16_t temp = self->current_area.y2; self->current_area.y2 = self->current_area.y1; @@ -315,22 +311,12 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_ar // How many pixels are outside of our area between us and the start of the row. uint16_t start = 0; if ((self->absolute_transform->dx < 0) != flip_x) { - // if (self->absolute_transform->transpose_xy) { - // start += (area->y2 - area->y1 - 1) * y_stride; - // y_stride *= -1; - // } else { - start += (area->x2 - area->x1 - 1) * x_stride; - x_stride *= -1; - //} + start += (area->x2 - area->x1 - 1) * x_stride; + x_stride *= -1; } if ((self->absolute_transform->dy < 0) != flip_y) { - // if (self->absolute_transform->transpose_xy) { - // start += (area->x2 - area->x1 - 1) * x_stride; - // x_stride *= -1; - // } else { - start += (area->y2 - area->y1 - 1) * y_stride; - y_stride *= -1; - //} + start += (area->y2 - area->y1 - 1) * y_stride; + y_stride *= -1; } // Track if this layer finishes filling in the given area. We can ignore any remaining -- cgit v1.2.3 From 4013bcde9eeab3dd2f8fd15a156c32f866a637b9 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 17 Jun 2019 17:48:05 -0700 Subject: Add baudrate to FourWire and shorten delay. --- shared-bindings/displayio/FourWire.c | 8 +++++--- shared-bindings/displayio/FourWire.h | 2 +- shared-module/displayio/FourWire.c | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c index 8ffe54be0..af64a2028 100644 --- a/shared-bindings/displayio/FourWire.c +++ b/shared-bindings/displayio/FourWire.c @@ -46,7 +46,7 @@ //| Manage updating a display over SPI four wire protocol in the background while Python code runs. //| It doesn't handle display initialization. //| -//| .. class:: FourWire(spi_bus, *, command, chip_select, reset=None) +//| .. class:: FourWire(spi_bus, *, command, chip_select, reset=None, baudrate=24000000) //| //| Create a FourWire object associated with the given pins. //| @@ -59,14 +59,16 @@ //| :param microcontroller.Pin command: Data or command pin //| :param microcontroller.Pin chip_select: Chip select pin //| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used +//| :param int baudrate: Maximum baudrate in Hz for the display on the bus //| STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset }; + enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset, ARG_baudrate }; static const mp_arg_t allowed_args[] = { { MP_QSTR_spi_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, { MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, { MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + { MP_QSTR_baudrate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 24000000} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -97,7 +99,7 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_ } common_hal_displayio_fourwire_construct(self, - MP_OBJ_TO_PTR(spi), command, chip_select, reset); + MP_OBJ_TO_PTR(spi), command, chip_select, reset, args[ARG_baudrate].u_int); return self; } diff --git a/shared-bindings/displayio/FourWire.h b/shared-bindings/displayio/FourWire.h index b65b1b5b7..5dbd60764 100644 --- a/shared-bindings/displayio/FourWire.h +++ b/shared-bindings/displayio/FourWire.h @@ -36,7 +36,7 @@ extern const mp_obj_type_t displayio_fourwire_type; void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self, busio_spi_obj_t* spi, const mcu_pin_obj_t* command, - const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset); + const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint32_t baudrate); void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self); diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c index b01456bba..d38da56fc 100644 --- a/shared-module/displayio/FourWire.c +++ b/shared-module/displayio/FourWire.c @@ -31,13 +31,14 @@ #include "py/gc.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/time/__init__.h" #include "tick.h" void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self, busio_spi_obj_t* spi, const mcu_pin_obj_t* command, - const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset) { + const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint32_t baudrate) { self->bus = spi; common_hal_busio_spi_never_reset(self->bus); @@ -45,7 +46,7 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self, // of the heap as well. gc_never_free(self->bus); - self->frequency = common_hal_busio_spi_get_frequency(spi); + self->frequency = baudrate; self->polarity = common_hal_busio_spi_get_polarity(spi); self->phase = common_hal_busio_spi_get_phase(spi); @@ -89,7 +90,7 @@ void common_hal_displayio_fourwire_send(mp_obj_t obj, bool command, uint8_t *dat displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj); if (command) { common_hal_digitalio_digitalinout_set_value(&self->chip_select, true); - common_hal_time_delay_ms(1); + common_hal_mcu_delay_us(1); common_hal_digitalio_digitalinout_set_value(&self->chip_select, false); } common_hal_digitalio_digitalinout_set_value(&self->command, !command); -- cgit v1.2.3 From 1356819de195810da09b5fc051ef5cc9dc21b2f4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 17 Jun 2019 23:16:40 -0400 Subject: Handle None for BLE name; fix ScanEntry bug; compile issue --- ports/nrf/Makefile | 2 +- shared-bindings/bleio/Peripheral.c | 5 +---- shared-bindings/bleio/ScanEntry.c | 1 + shared-module/displayio/TileGrid.c | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index d947ab34c..b7ff2fcba 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -91,7 +91,7 @@ INC += -I../../supervisor/shared/usb ifeq ($(DEBUG), 1) CFLAGS += -ggdb # You may want to enable these flags to make setting breakpoints easier. - CFLAGS += -fno-inline -fno-ipa-sra + # CFLAGS += -fno-inline -fno-ipa-sra else CFLAGS += -Os -DNDEBUG # TODO: Test with -flto diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index ca703bd53..4492a8e26 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -117,11 +117,8 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar } const mp_obj_t name = args[ARG_name].u_obj; - if (name == MP_OBJ_NULL) { + if (name == MP_OBJ_NULL || name == mp_const_none) { self->name = mp_obj_new_str(default_name, strlen(default_name)); - } else if (name == mp_const_none) { - // Make None be the empty string. - self->name = MP_OBJ_NEW_QSTR(MP_QSTR_); } else if (MP_OBJ_IS_STR(name)) { self->name = name; } else { diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index 475bade15..f66b3df4b 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -55,6 +55,7 @@ STATIC mp_obj_t bleio_scanentry_get_address(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); + address->base.type = &bleio_address_type; memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); address->type = self->address.type; return MP_OBJ_TO_PTR(address); diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 97b704c40..43ce36ed3 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -440,7 +440,7 @@ void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) { displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t* tail) { if (self->moved && !self->first_draw) { displayio_area_union(&self->previous_area, &self->current_area, &self->dirty_area); - if (displayio_area_size(&self->dirty_area) <= 2 * self->pixel_width * self->pixel_height) { + if (displayio_area_size(&self->dirty_area) <= 2U * self->pixel_width * self->pixel_height) { self->dirty_area.next = tail; return &self->dirty_area; } -- cgit v1.2.3 From db74b92e77757caab7c5f2bb1d6ae09f5be3ed97 Mon Sep 17 00:00:00 2001 From: Craig Forbes Date: Fri, 14 Jun 2019 15:30:38 -0500 Subject: Fix displayio.Display docstring type for display_bus. Add docs for group parameter for Display.show. --- shared-bindings/displayio/Display.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 84302a175..1a36872a6 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -78,7 +78,8 @@ //| The initialization sequence should always leave the display memory access inline with the scan //| of the display to minimize tearing artifacts. //| -//| :param displayio.FourWire or displayio.ParallelBus display_bus: The bus that the display is connected to +//| :param display_bus: The bus that the display is connected to +//| :type display_bus: displayio.FourWire or displayio.ParallelBus //| :param buffer init_sequence: Byte-packed initialization sequence. //| :param int width: Width in pixels //| :param int height: Height in pixels @@ -182,6 +183,7 @@ static displayio_display_obj_t* native_display(mp_obj_t display_obj) { //| Switches to displaying the given group of layers. When group is None, the default //| CircuitPython terminal will be shown. //| +//| :param Group group: The group to show. STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) { displayio_display_obj_t *self = native_display(self_in); displayio_group_t* group = NULL; -- cgit v1.2.3 From e442efbdecf35066412efc155e20ee280c5449f3 Mon Sep 17 00:00:00 2001 From: Craig Forbes Date: Mon, 17 Jun 2019 11:58:05 -0500 Subject: Fix docs in digitalio. --- shared-bindings/digitalio/DigitalInOut.c | 4 ++-- shared-bindings/digitalio/Direction.c | 2 +- shared-bindings/digitalio/DriveMode.c | 2 +- shared-bindings/digitalio/Pull.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index 6587ee7ea..16472c12c 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -49,8 +49,8 @@ //| ========================================================= //| //| A DigitalInOut is used to digitally control I/O pins. For analog control of -//| a pin, see the :py:class:`~digitalio.AnalogIn` and -//| :py:class:`~digitalio.AnalogOut` classes. +//| a pin, see the :py:class:`analogio.AnalogIn` and +//| :py:class:`analogio.AnalogOut` classes. //| //| .. class:: DigitalInOut(pin) diff --git a/shared-bindings/digitalio/Direction.c b/shared-bindings/digitalio/Direction.c index a3433d4b0..c8188fc89 100644 --- a/shared-bindings/digitalio/Direction.c +++ b/shared-bindings/digitalio/Direction.c @@ -43,7 +43,7 @@ //| :class:`Direction` -- defines the direction of a digital pin //| ============================================================= //| -//| .. class:: digitalio.DigitalInOut.Direction +//| .. class:: Direction //| //| Enum-like class to define which direction the digital values are //| going. diff --git a/shared-bindings/digitalio/DriveMode.c b/shared-bindings/digitalio/DriveMode.c index 477cd904c..51e1e2ee5 100644 --- a/shared-bindings/digitalio/DriveMode.c +++ b/shared-bindings/digitalio/DriveMode.c @@ -31,7 +31,7 @@ //| :class:`DriveMode` -- defines the drive mode of a digital pin //| ============================================================= //| -//| .. class:: digitalio.DriveMode +//| .. class:: DriveMode //| //| Enum-like class to define the drive mode used when outputting //| digital values. diff --git a/shared-bindings/digitalio/Pull.c b/shared-bindings/digitalio/Pull.c index 8d03f6c05..813268db7 100644 --- a/shared-bindings/digitalio/Pull.c +++ b/shared-bindings/digitalio/Pull.c @@ -31,7 +31,7 @@ //| :class:`Pull` -- defines the pull of a digital input pin //| ============================================================= //| -//| .. class:: digitalio.Pull +//| .. class:: Pull //| //| Enum-like class to define the pull value, if any, used while reading //| digital values in. -- cgit v1.2.3 From 09e7f4db00c13dd7fcea0fac3ced5ce9749ba331 Mon Sep 17 00:00:00 2001 From: Craig Forbes Date: Tue, 18 Jun 2019 18:44:50 -0500 Subject: Fix reference to Bitmap in fontio.Glyph docs. --- shared-bindings/fontio/Glyph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/fontio/Glyph.c b/shared-bindings/fontio/Glyph.c index 80298fd16..a23284152 100644 --- a/shared-bindings/fontio/Glyph.c +++ b/shared-bindings/fontio/Glyph.c @@ -37,7 +37,7 @@ //| //| Named tuple used to capture a single glyph and its attributes. //| -//| :param fontio.Bitmap bitmap: the bitmap including the glyph +//| :param displayio.Bitmap bitmap: the bitmap including the glyph //| :param int tile_index: the tile index within the bitmap //| :param int width: the width of the glyph's bitmap //| :param int height: the height of the glyph's bitmap -- cgit v1.2.3 From 35b919185747c42e183ccfc41f99fd370acca450 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 18 Jun 2019 23:46:20 -0400 Subject: Don't operate directly on bleio objects in shared-bindings: use common_hal routines instead. Changes made but not yet tested. --- ports/nrf/common-hal/bleio/Broadcaster.h | 6 +-- ports/nrf/common-hal/bleio/Characteristic.c | 16 +++++++- ports/nrf/common-hal/bleio/Characteristic.h | 8 ++-- ports/nrf/common-hal/bleio/CharacteristicBuffer.h | 6 +-- ports/nrf/common-hal/bleio/Device.c | 14 +++---- ports/nrf/common-hal/bleio/Peripheral.c | 18 ++++++++- ports/nrf/common-hal/bleio/Peripheral.h | 12 +++--- ports/nrf/common-hal/bleio/Scanner.c | 12 +++++- ports/nrf/common-hal/bleio/Scanner.h | 40 ++++++++++++++++++ ports/nrf/common-hal/bleio/Service.c | 36 +++++++++++++++-- ports/nrf/common-hal/bleio/Service.h | 44 ++++++++++++++++++++ ports/nrf/common-hal/bleio/__init__.h | 6 +-- py/circuitpy_defns.mk | 2 + py/obj.h | 1 + py/objlist.c | 4 +- shared-bindings/bleio/Address.c | 10 ++--- shared-bindings/bleio/Address.h | 5 +++ shared-bindings/bleio/Characteristic.c | 22 +++++----- shared-bindings/bleio/Characteristic.h | 5 ++- shared-bindings/bleio/CharacteristicBuffer.c | 3 +- shared-bindings/bleio/Device.h | 2 +- shared-bindings/bleio/Peripheral.c | 25 ++++++------ shared-bindings/bleio/Peripheral.h | 4 +- shared-bindings/bleio/ScanEntry.c | 24 ++++------- shared-bindings/bleio/ScanEntry.h | 5 +++ shared-bindings/bleio/Scanner.c | 6 +-- shared-bindings/bleio/Scanner.h | 6 ++- shared-bindings/bleio/Service.c | 24 +++++------ shared-bindings/bleio/Service.h | 8 +++- shared-module/bleio/Address.c | 45 +++++++++++++++++++++ shared-module/bleio/Address.h | 2 + shared-module/bleio/Characteristic.h | 1 + shared-module/bleio/ScanEntry.c | 49 +++++++++++++++++++++++ shared-module/bleio/ScanEntry.h | 3 +- shared-module/bleio/Scanner.h | 39 ------------------ shared-module/bleio/Service.h | 44 -------------------- 36 files changed, 369 insertions(+), 188 deletions(-) create mode 100644 ports/nrf/common-hal/bleio/Scanner.h create mode 100644 ports/nrf/common-hal/bleio/Service.h create mode 100644 shared-module/bleio/Address.c create mode 100644 shared-module/bleio/ScanEntry.c delete mode 100644 shared-module/bleio/Scanner.h delete mode 100644 shared-module/bleio/Service.h (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Broadcaster.h b/ports/nrf/common-hal/bleio/Broadcaster.h index 72f93a443..2d1ae69a1 100644 --- a/ports/nrf/common-hal/bleio/Broadcaster.h +++ b/ports/nrf/common-hal/bleio/Broadcaster.h @@ -25,8 +25,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H #include "ble.h" @@ -44,4 +44,4 @@ typedef struct { } bleio_broadcaster_obj_t; -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 9409b73ce..45fb1d092 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -237,7 +237,11 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, } -void common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) { +void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service) { + self->service = service; +} + +mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) { switch (common_hal_bleio_device_get_gatt_role(self->service->device)) { case GATT_ROLE_CLIENT: gattc_read(self); @@ -251,6 +255,8 @@ void common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) mp_raise_RuntimeError(translate("bad GATT role")); break; } + + return self->value_data; } void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo) { @@ -285,3 +291,11 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, break; } } + +bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self) { + return self->uuid; +} + +bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self) { + return self->props; +} diff --git a/ports/nrf/common-hal/bleio/Characteristic.h b/ports/nrf/common-hal/bleio/Characteristic.h index bce1eec1d..662485bad 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.h +++ b/ports/nrf/common-hal/bleio/Characteristic.h @@ -24,11 +24,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H #include "shared-module/bleio/Characteristic.h" -#include "shared-module/bleio/Service.h" +#include "common-hal/bleio/Service.h" #include "common-hal/bleio/UUID.h" typedef struct { @@ -43,4 +43,4 @@ typedef struct { uint16_t sccd_handle; } bleio_characteristic_obj_t; -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H diff --git a/ports/nrf/common-hal/bleio/CharacteristicBuffer.h b/ports/nrf/common-hal/bleio/CharacteristicBuffer.h index b36f63fec..6a44229f7 100644 --- a/ports/nrf/common-hal/bleio/CharacteristicBuffer.h +++ b/ports/nrf/common-hal/bleio/CharacteristicBuffer.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H #include "nrf_soc.h" @@ -40,4 +40,4 @@ typedef struct { ringbuf_t ringbuf; } bleio_characteristic_buffer_obj_t; -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H diff --git a/ports/nrf/common-hal/bleio/Device.c b/ports/nrf/common-hal/bleio/Device.c index 5f625829e..b1ac72e75 100644 --- a/ports/nrf/common-hal/bleio/Device.c +++ b/ports/nrf/common-hal/bleio/Device.c @@ -323,7 +323,7 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); service->base.type = &bleio_service_type; service->device = device; - service->char_list = mp_obj_new_list(0, NULL); + service->characteristic_list = mp_obj_new_list(0, NULL); service->start_handle = gattc_service->handle_range.start_handle; service->end_handle = gattc_service->handle_range.end_handle; service->handle = gattc_service->handle_range.start_handle; @@ -366,7 +366,7 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio characteristic->handle = gattc_char->handle_value; characteristic->service = m_char_discovery_service; - mp_obj_list_append(m_char_discovery_service->char_list, MP_OBJ_FROM_PTR(characteristic)); + mp_obj_list_append(m_char_discovery_service->characteristic_list, MP_OBJ_FROM_PTR(characteristic)); } if (response->count > 0) { @@ -491,9 +491,9 @@ void common_hal_bleio_device_add_service(bleio_device_obj_t *device, bleio_servi mp_raise_OSError_msg(translate("Failed to add service")); } - const mp_obj_list_t *char_list = MP_OBJ_TO_PTR(service->char_list); - for (size_t i = 0; i < char_list->len; ++i) { - bleio_characteristic_obj_t *characteristic = char_list->items[i]; + const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); + for (size_t i = 0; i < characteristic_list->len; ++i) { + bleio_characteristic_obj_t *characteristic = characteristic_list->items[i]; common_hal_bleio_service_add_characteristic(service, characteristic); } } @@ -583,8 +583,8 @@ void common_hal_bleio_device_connect(bleio_device_obj_t *device) { bool found_char = discover_characteristics(device, service, service->start_handle); while (found_char) { - const mp_obj_list_t *char_list = MP_OBJ_TO_PTR(service->char_list); - const bleio_characteristic_obj_t *characteristic = char_list->items[char_list->len - 1]; + const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); + const bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_list->len - 1]; const uint16_t next_handle = characteristic->handle + 1; if (next_handle >= service->end_handle) { diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index e59676fde..36c20373d 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -33,6 +33,7 @@ #include "ble_hci.h" #include "nrf_soc.h" #include "py/gc.h" +#include "py/objlist.h" #include "py/objstr.h" #include "py/runtime.h" #include "shared-bindings/bleio/Adapter.h" @@ -40,6 +41,7 @@ #include "shared-bindings/bleio/Peripheral.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/UUID.h" +#include "common-hal/bleio/Service.h" #define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_0_625_MS) #define BLE_MAX_CONN_INTERVAL MSEC_TO_UNITS(300, UNIT_0_625_MS) @@ -117,19 +119,23 @@ STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { } } -void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self) { +void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self, mp_obj_list_t *service_list, mp_obj_t name) { common_hal_bleio_adapter_set_enabled(true); + self->service_list = service_list; + self->name = name; + self->gatt_role = GATT_ROLE_SERVER; self->conn_handle = BLE_CONN_HANDLE_INVALID; self->adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; // Add all the services. - mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); for (size_t service_idx = 0; service_idx < service_list->len; ++service_idx) { bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[service_idx]); + common_hal_bleio_service_set_device(service, MP_OBJ_FROM_PTR(self)); + ble_uuid_t uuid; bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); @@ -149,10 +155,18 @@ void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self) { } +mp_obj_list_t *common_hal_bleio_peripheral_get_service_list(bleio_peripheral_obj_t *self) { + return self->service_list; +} + bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self) { return self->conn_handle != BLE_CONN_HANDLE_INVALID; } +mp_obj_t common_hal_bleio_peripheral_get_name(bleio_peripheral_obj_t *self) { + return self->name; +} + void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_float_t interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { // interval value has already been validated. diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index eb0b0417a..9103fcf94 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -25,13 +25,16 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_PERIPHERAL_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_PERIPHERAL_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_PERIPHERAL_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_PERIPHERAL_H #include #include "ble.h" +#include "py/obj.h" +#include "py/objlist.h" + #include "shared-module/bleio/__init__.h" #include "shared-module/bleio/Address.h" @@ -40,8 +43,7 @@ typedef struct { mp_obj_t name; gatt_role_t gatt_role; volatile uint16_t conn_handle; - mp_obj_t service_list; - mp_obj_t notif_handler; + mp_obj_list_t *service_list; mp_obj_t conn_handler; // The advertising data and scan response buffers are held by us, not by the SD, so we must // maintain them and not change it. If we need to change the contents during advertising, @@ -52,4 +54,4 @@ typedef struct { } bleio_peripheral_obj_t; -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_PERIPHERAL_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_PERIPHERAL_H diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index 08600bc0a..64f7decad 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -30,6 +30,7 @@ #include "ble_drv.h" #include "ble_gap.h" #include "py/mphal.h" +#include "py/objlist.h" #include "py/runtime.h" #include "shared-bindings/bleio/Adapter.h" #include "shared-bindings/bleio/ScanEntry.h" @@ -68,6 +69,10 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { } } +void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self) { + self->adv_reports = mp_obj_new_list(0, NULL); +} + void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { common_hal_bleio_adapter_set_enabled(true); ble_drv_add_event_handler(on_ble_evt, self); @@ -78,7 +83,8 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout .scan_phys = BLE_GAP_PHY_1MBPS, }; - common_hal_bleio_adapter_set_enabled(true); + // Empty the advertising reports list. + mp_obj_list_clear(self->adv_reports); uint32_t err_code; err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); @@ -90,3 +96,7 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout mp_hal_delay_ms(timeout * 1000); sd_ble_gap_scan_stop(); } + +mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self) { + return self->adv_reports; +} diff --git a/ports/nrf/common-hal/bleio/Scanner.h b/ports/nrf/common-hal/bleio/Scanner.h new file mode 100644 index 000000000..a71066487 --- /dev/null +++ b/ports/nrf/common-hal/bleio/Scanner.h @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SCANNER_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SCANNER_H + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + mp_obj_t adv_reports; // List of reports. + uint16_t interval; + uint16_t window; +} bleio_scanner_obj_t; + +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SCANNER_H diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 26a1f1cff..77d3f0259 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -29,18 +29,46 @@ #include "py/runtime.h" #include "common-hal/bleio/__init__.h" #include "common-hal/bleio/Characteristic.h" +#include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/Adapter.h" -void common_hal_bleio_service_construct(bleio_service_obj_t *self) { +void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *characteristic_list, bool is_secondary) { + self->device = mp_const_none; + self->handle = 0xFFFF; + self->uuid = uuid; + self->characteristic_list = characteristic_list; + self->is_secondary = is_secondary; + + for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { + bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(characteristic_list->items[characteristic_idx]); + common_hal_bleio_characteristic_set_service(characteristic, self); + } + +} + +bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self) { + return self->uuid; +} + +mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self) { + return self->characteristic_list; +} + +bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) { + return self->is_secondary; +} + +void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device) { + self->device = device; } // Call this after the Service has been added to the Peripheral. void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self) { // Add all the characteristics. - const mp_obj_list_t *char_list = MP_OBJ_TO_PTR(self->char_list); - for (size_t char_idx = 0; char_idx < char_list->len; ++char_idx) { - bleio_characteristic_obj_t *characteristic = char_list->items[char_idx]; + const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(self->characteristic_list); + for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { + bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_idx]; ble_gatts_char_md_t char_md = { .char_props.broadcast = characteristic->props.broadcast, diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h new file mode 100644 index 000000000..7998cc862 --- /dev/null +++ b/ports/nrf/common-hal/bleio/Service.h @@ -0,0 +1,44 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H + +#include "common-hal/bleio/UUID.h" + +typedef struct { + mp_obj_base_t base; + uint16_t handle; + bool is_secondary; + bleio_uuid_obj_t *uuid; + // May be a Peripheral, Central, etc. + mp_obj_t *device; + mp_obj_t characteristic_list; + uint16_t start_handle; + uint16_t end_handle; +} bleio_service_obj_t; + +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H diff --git a/ports/nrf/common-hal/bleio/__init__.h b/ports/nrf/common-hal/bleio/__init__.h index 9e044f37c..0c46b631f 100644 --- a/ports/nrf/common-hal/bleio/__init__.h +++ b/ports/nrf/common-hal/bleio/__init__.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_INIT_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_INIT_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_INIT_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_INIT_H #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Adapter.h" @@ -39,4 +39,4 @@ gatt_role_t common_hal_bleio_device_get_gatt_role(mp_obj_t device); uint16_t common_hal_bleio_device_get_conn_handle(mp_obj_t device); -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_INIT_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_INIT_H diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index fd43a11a6..435cf2c33 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -308,6 +308,8 @@ $(filter $(SRC_PATTERNS), \ bitbangio/SPI.c \ bitbangio/__init__.c \ board/__init__.c \ + bleio/Address.c \ + bleio/ScanEntry.c \ busio/OneWire.c \ displayio/Bitmap.c \ displayio/ColorConverter.c \ diff --git a/py/obj.h b/py/obj.h index 773043b59..6eead377d 100644 --- a/py/obj.h +++ b/py/obj.h @@ -763,6 +763,7 @@ void mp_obj_tuple_del(mp_obj_t self_in); mp_int_t mp_obj_tuple_hash(mp_obj_t self_in); // list +mp_obj_t mp_obj_list_clear(mp_obj_t self_in); mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg); mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value); void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items); diff --git a/py/objlist.c b/py/objlist.c index 16ca4b353..558c4c611 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -340,7 +340,7 @@ mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ return mp_const_none; } -STATIC mp_obj_t list_clear(mp_obj_t self_in) { +mp_obj_t mp_obj_list_clear(mp_obj_t self_in) { mp_check_self(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); self->len = 0; @@ -418,7 +418,7 @@ STATIC mp_obj_t list_reverse(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append); STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_extend_obj, list_extend); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, list_clear); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, mp_obj_list_clear); STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_copy_obj, list_copy); STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_count_obj, list_count); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index); diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index 7367da535..5875cf9bd 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -74,13 +75,12 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_ValueError_varg(translate("Address must be %d bytes long"), NUM_BLEIO_ADDRESS_BYTES); } - memcpy(self->bytes, buf_info.buf, buf_info.len); - const mp_int_t address_type = args[ARG_address_type].u_int; if (address_type < BLEIO_ADDRESS_TYPE_MIN || address_type > BLEIO_ADDRESS_TYPE_MAX) { mp_raise_ValueError(translate("Address type out of range")); } - self->type = address_type; + + common_hal_bleio_address_construct(self, buf_info.buf, buf_info.len, address_type); return MP_OBJ_FROM_PTR(self); } @@ -97,7 +97,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES); + return common_hal_bleio_address_get_address_bytes(self); } MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get_address_bytes); @@ -113,7 +113,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get STATIC mp_obj_t bleio_address_get_type(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_NEW_SMALL_INT(self->type); + return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_address_get_type(self)); } MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_type_obj, bleio_address_get_type); diff --git a/shared-bindings/bleio/Address.h b/shared-bindings/bleio/Address.h index ef84d7432..9652a9841 100644 --- a/shared-bindings/bleio/Address.h +++ b/shared-bindings/bleio/Address.h @@ -28,6 +28,7 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADDRESS_H #include "py/objtype.h" +#include "shared-module/bleio/Address.h" #define BLEIO_ADDRESS_TYPE_PUBLIC (0) #define BLEIO_ADDRESS_TYPE_RANDOM_STATIC (1) @@ -39,4 +40,8 @@ extern const mp_obj_type_t bleio_address_type; +extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type); +extern mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self); +extern uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADDRESS_H diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index ae83de864..e48cfd433 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -73,10 +73,10 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) { mp_raise_ValueError(translate("Expected a UUID")); } + bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid); bleio_characteristic_obj_t *self = m_new_obj(bleio_characteristic_obj_t); self->base.type = &bleio_characteristic_type; - self->uuid = MP_OBJ_TO_PTR(uuid); bleio_characteristic_properties_t properties; @@ -87,7 +87,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t properties.write = args[ARG_write].u_bool; properties.write_no_response = args[ARG_write_no_response].u_bool; - common_hal_bleio_characteristic_construct(self, uuid, properties); + common_hal_bleio_characteristic_construct(self, uuid_obj, properties); return MP_OBJ_FROM_PTR(self); } @@ -99,7 +99,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t STATIC mp_obj_t bleio_characteristic_get_broadcast(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.broadcast); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).broadcast); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_broadcast_obj, bleio_characteristic_get_broadcast); @@ -117,7 +117,7 @@ const mp_obj_property_t bleio_characteristic_broadcast_obj = { STATIC mp_obj_t bleio_characteristic_get_indicate(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.indicate); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).indicate); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_indicate_obj, bleio_characteristic_get_indicate); @@ -136,7 +136,7 @@ const mp_obj_property_t bleio_characteristic_indicate_obj = { STATIC mp_obj_t bleio_characteristic_get_notify(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.notify); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).notify); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_notify_obj, bleio_characteristic_get_notify); @@ -154,7 +154,7 @@ const mp_obj_property_t bleio_characteristic_notify_obj = { STATIC mp_obj_t bleio_characteristic_get_read(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.read); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).read); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_read_obj, bleio_characteristic_get_read); @@ -172,7 +172,7 @@ const mp_obj_property_t bleio_characteristic_read_obj = { STATIC mp_obj_t bleio_characteristic_get_write(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.write); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).write); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_write_obj, bleio_characteristic_get_write); @@ -190,7 +190,7 @@ const mp_obj_property_t bleio_characteristic_write_obj = { STATIC mp_obj_t bleio_characteristic_get_write_no_response(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.write_no_response); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).write_no_response); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_write_no_response_obj, bleio_characteristic_get_write_no_response); @@ -208,7 +208,7 @@ const mp_obj_property_t bleio_characteristic_write_no_response_obj = { STATIC mp_obj_t bleio_characteristic_get_uuid(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(self->uuid); + return MP_OBJ_FROM_PTR(common_hal_bleio_characteristic_get_uuid(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_uuid_obj, bleio_characteristic_get_uuid); @@ -228,9 +228,7 @@ const mp_obj_property_t bleio_characteristic_uuid_obj = { STATIC mp_obj_t bleio_characteristic_get_value(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_bleio_characteristic_get_value(self); - - return self->value_data; + return common_hal_bleio_characteristic_get_value(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_value_obj, bleio_characteristic_get_value); diff --git a/shared-bindings/bleio/Characteristic.h b/shared-bindings/bleio/Characteristic.h index 206cbcd40..ffee6bdbc 100644 --- a/shared-bindings/bleio/Characteristic.h +++ b/shared-bindings/bleio/Characteristic.h @@ -32,7 +32,10 @@ extern const mp_obj_type_t bleio_characteristic_type; extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props); -extern void common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self); +extern void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service); +extern mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self); extern void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo); +extern bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self); +extern bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index a1dc663fd..da79c5d7a 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -85,9 +85,8 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t); self->base.type = &bleio_characteristic_buffer_type; - self->characteristic = MP_OBJ_TO_PTR(characteristic); - common_hal_bleio_characteristic_buffer_construct(self, self->characteristic, timeout, buffer_size); + common_hal_bleio_characteristic_buffer_construct(self, characteristic, timeout, buffer_size); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h index 1f85abe9a..e452a8ad6 100644 --- a/shared-bindings/bleio/Device.h +++ b/shared-bindings/bleio/Device.h @@ -28,7 +28,7 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H #include "shared-module/bleio/Device.h" -#include "shared-module/bleio/Service.h" +#include "common-hal/bleio/Service.h" extern const mp_obj_type_t bleio_device_type; diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 4492a8e26..5397f4c3a 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -101,32 +101,33 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar // If services is not an iterable, an exception will be thrown. mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(args[ARG_services].u_obj, &iter_buf); - mp_obj_t service; bleio_peripheral_obj_t *self = m_new_obj(bleio_peripheral_obj_t); self->base.type = &bleio_peripheral_type; - self->service_list = mp_obj_new_list(0, NULL); - self->notif_handler = mp_const_none; + + // Copy the services list and validate its items. + mp_obj_t service_list = mp_obj_new_list(0, NULL); + mp_obj_list_t *service_list_obj = MP_OBJ_FROM_PTR(service_list); + + mp_obj_t service; while ((service = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(service, &bleio_service_type)) { mp_raise_ValueError(translate("services includes an object that is not a Service")); } - bleio_service_obj_t *service_ptr = MP_OBJ_TO_PTR(service); - service_ptr->device = MP_OBJ_FROM_PTR(self); - mp_obj_list_append(self->service_list, service); + mp_obj_list_append(service_list, service); } const mp_obj_t name = args[ARG_name].u_obj; + mp_obj_t name_str; if (name == MP_OBJ_NULL || name == mp_const_none) { - self->name = mp_obj_new_str(default_name, strlen(default_name)); + name_str = mp_obj_new_str(default_name, strlen(default_name)); } else if (MP_OBJ_IS_STR(name)) { - self->name = name; + name_str = name; } else { mp_raise_ValueError(translate("name must be a string")); } - // Do port-specific initialization. - common_hal_bleio_peripheral_construct(self); + common_hal_bleio_peripheral_construct(self, service_list_obj, name_str); return MP_OBJ_FROM_PTR(self); } @@ -157,7 +158,7 @@ const mp_obj_property_t bleio_peripheral_connected_obj = { STATIC mp_obj_t bleio_peripheral_get_services(mp_obj_t self_in) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); // Return list as a tuple so user won't be able to change it. - mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + mp_obj_list_t *service_list = common_hal_bleio_peripheral_get_service_list(self); return mp_obj_new_tuple(service_list->len, service_list->items); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_get_services_obj, bleio_peripheral_get_services); @@ -176,7 +177,7 @@ const mp_obj_property_t bleio_peripheral_services_obj = { STATIC mp_obj_t bleio_peripheral_get_name(mp_obj_t self_in) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); - return self->name; + return common_hal_bleio_peripheral_get_name(self); } MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_get_name_obj, bleio_peripheral_get_name); diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index 7ef45edcd..6468325c2 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -32,8 +32,10 @@ extern const mp_obj_type_t bleio_peripheral_type; -extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self); +extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self, mp_obj_list_t *service_list, mp_obj_t name); +extern mp_obj_list_t *common_hal_bleio_peripheral_get_service_list(bleio_peripheral_obj_t *self); extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self); +extern mp_obj_t common_hal_bleio_peripheral_get_name(bleio_peripheral_obj_t *self); extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, float interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device); diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index f66b3df4b..145d2b023 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * Copyright (c) 2017 Glenn Ruben Bakke * @@ -27,10 +28,7 @@ #include -#include "py/objarray.h" #include "py/objproperty.h" -#include "py/objstr.h" -#include "py/objtuple.h" #include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/UUID.h" @@ -53,18 +51,13 @@ //| STATIC mp_obj_t bleio_scanentry_get_address(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); - - bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); - address->base.type = &bleio_address_type; - memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); - address->type = self->address.type; - return MP_OBJ_TO_PTR(address); + return common_hal_bleio_scanentry_get_address(self); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_address_obj, bleio_scanentry_get_address); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_address_obj, bleio_scanentry_get_address); const mp_obj_property_t bleio_scanentry_address_obj = { .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bluepy_scanentry_get_address_obj, + .proxy = { (mp_obj_t)&bleio_scanentry_get_address_obj, (mp_obj_t)&mp_const_none_obj, (mp_obj_t)&mp_const_none_obj }, }; @@ -75,7 +68,7 @@ const mp_obj_property_t bleio_scanentry_address_obj = { //| STATIC mp_obj_t scanentry_get_raw_data(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); - return self->data; + return common_hal_bleio_scanentry_get_raw_data(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_raw_data_obj, scanentry_get_raw_data); @@ -92,14 +85,13 @@ const mp_obj_property_t bleio_scanentry_raw_data_obj = { //| STATIC mp_obj_t scanentry_get_rssi(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return mp_obj_new_int(self->rssi); + return mp_obj_new_int(common_hal_bleio_scanentry_get_rssi(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_rssi_obj, scanentry_get_rssi); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_rssi_obj, scanentry_get_rssi); const mp_obj_property_t bleio_scanentry_rssi_obj = { .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bluepy_scanentry_get_rssi_obj, + .proxy = { (mp_obj_t)&bleio_scanentry_get_rssi_obj, (mp_obj_t)&mp_const_none_obj, (mp_obj_t)&mp_const_none_obj }, }; diff --git a/shared-bindings/bleio/ScanEntry.h b/shared-bindings/bleio/ScanEntry.h index 2b44ba3f4..c1b52e6b4 100644 --- a/shared-bindings/bleio/ScanEntry.h +++ b/shared-bindings/bleio/ScanEntry.h @@ -29,7 +29,12 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H #include "py/obj.h" +#include "shared-module/bleio/ScanEntry.h" extern const mp_obj_type_t bleio_scanentry_type; +mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self); +mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self); +mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index a249d5343..92f6a2a18 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -61,6 +61,8 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t); self->base.type = type; + common_hal_bleio_scanner_construct(self); + return MP_OBJ_FROM_PTR(self); } @@ -108,11 +110,9 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m mp_raise_ValueError(translate("window must be <= interval")); } - self->adv_reports = mp_obj_new_list(0, NULL); - common_hal_bleio_scanner_scan(self, timeout, interval, window); - return self->adv_reports; + return common_hal_bleio_scanner_get_adv_reports(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index 54c09675b..b9e3ecdee 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -29,11 +29,13 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H #include "py/objtype.h" -#include "shared-module/bleio/Scanner.h" +#include "common-hal/bleio/Scanner.h" extern const mp_obj_type_t bleio_scanner_type; -void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); +extern void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self); +extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); +extern mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index d9bc4021f..352ef8d6a 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -67,18 +67,20 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, } bleio_service_obj_t *self = m_new_obj(bleio_service_obj_t); - self->char_list = mp_obj_new_list(0, NULL); self->base.type = &bleio_service_type; - self->device = mp_const_none; - self->handle = 0xFFFF; - self->is_secondary = args[ARG_secondary].u_bool; - self->uuid = MP_OBJ_TO_PTR(uuid); + + const bool is_secondary = args[ARG_secondary].u_bool; + bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid); // If characteristics is not an iterable, an exception will be thrown. mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(args[ARG_characteristics].u_obj, &iter_buf); mp_obj_t characteristic; + // Copy the characteristics list and validate its items. + mp_obj_t char_list = mp_obj_new_list(0, NULL); + mp_obj_list_t *char_list_obj = MP_OBJ_FROM_PTR(char_list); + while ((characteristic = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(characteristic, &bleio_characteristic_type)) { mp_raise_ValueError(translate("characteristics includes an object that is not a Characteristic")); @@ -89,12 +91,10 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, // The descriptor base UUID doesn't match the characteristic base UUID. mp_raise_ValueError(translate("Characteristic UUID doesn't match Service UUID")); } - characteristic_ptr->service = self; - mp_obj_list_append(self->char_list, characteristic); + mp_obj_list_append(char_list, characteristic); } - // Do port-specific initialization. - common_hal_bleio_service_construct(self); + common_hal_bleio_service_construct(self, uuid_obj, char_list_obj, is_secondary); return MP_OBJ_FROM_PTR(self); } @@ -106,7 +106,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t bleio_service_get_characteristics(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); // Return list as a tuple so user won't be able to change it. - mp_obj_list_t *char_list = MP_OBJ_TO_PTR(self->char_list); + mp_obj_list_t *char_list = common_hal_bleio_service_get_characteristic_list(self); return mp_obj_new_tuple(char_list->len, char_list->items); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_characteristics_obj, bleio_service_get_characteristics); @@ -125,7 +125,7 @@ const mp_obj_property_t bleio_service_characteristics_obj = { STATIC mp_obj_t bleio_service_get_secondary(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->is_secondary); + return mp_obj_new_bool(common_hal_bleio_service_get_is_secondary(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_secondary_obj, bleio_service_get_secondary); @@ -143,7 +143,7 @@ const mp_obj_property_t bleio_service_secondary_obj = { STATIC mp_obj_t bleio_service_get_uuid(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(self->uuid); + return MP_OBJ_FROM_PTR(common_hal_bleio_service_get_uuid(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_uuid_obj, bleio_service_get_uuid); diff --git a/shared-bindings/bleio/Service.h b/shared-bindings/bleio/Service.h index 389db3b2e..27d79f953 100644 --- a/shared-bindings/bleio/Service.h +++ b/shared-bindings/bleio/Service.h @@ -28,11 +28,15 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H #include "shared-module/bleio/Characteristic.h" -#include "shared-module/bleio/Service.h" +#include "common-hal/bleio/Service.h" const mp_obj_type_t bleio_service_type; -extern void common_hal_bleio_service_construct(bleio_service_obj_t *self); +extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *char_list, bool is_secondary); +extern bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self); +extern mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self); +extern bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self); +extern void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device); extern void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H diff --git a/shared-module/bleio/Address.c b/shared-module/bleio/Address.c new file mode 100644 index 000000000..e26bbe2ac --- /dev/null +++ b/shared-module/bleio/Address.c @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/objproperty.h" +#include "shared-bindings/bleio/Address.h" +#include "shared-module/bleio/Address.h" + +void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type) { + memcpy(self->bytes, bytes, bytes_length); + self->type = address_type; +} + +mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self) { + return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES); +} + +uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self) { + return self->type; +} diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h index 65f493c16..f66e97d64 100644 --- a/shared-module/bleio/Address.h +++ b/shared-module/bleio/Address.h @@ -27,6 +27,8 @@ #ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H #define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H +#include "py/obj.h" + #define NUM_BLEIO_ADDRESS_BYTES 6 typedef struct { diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h index 958837e64..3132fd47b 100644 --- a/shared-module/bleio/Characteristic.h +++ b/shared-module/bleio/Characteristic.h @@ -37,5 +37,6 @@ typedef struct { bool indicate : 1; } bleio_characteristic_properties_t; +// bleio_characteristic_obj_t is defined in ports/*/common-hal. #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H diff --git a/shared-module/bleio/ScanEntry.c b/shared-module/bleio/ScanEntry.c new file mode 100644 index 000000000..44b50a4ce --- /dev/null +++ b/shared-module/bleio/ScanEntry.c @@ -0,0 +1,49 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "shared-bindings/bleio/Address.h" +#include "shared-module/bleio/Address.h" +#include "shared-module/bleio/ScanEntry.h" + +mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self) { + bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); + address->base.type = &bleio_address_type; + memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); + address->type = self->address.type; + return MP_OBJ_TO_PTR(address); +} + +mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self) { + return self->data; +} + +mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self) { + return self->rssi; +} diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h index 6ae7334a8..40e02f9fa 100644 --- a/shared-module/bleio/ScanEntry.h +++ b/shared-module/bleio/ScanEntry.h @@ -27,7 +27,8 @@ #ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H #define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H -#include "shared-module/bleio/Address.h" +#include "py/obj.h" +#include "shared-bindings/bleio/Address.h" typedef struct { mp_obj_base_t base; diff --git a/shared-module/bleio/Scanner.h b/shared-module/bleio/Scanner.h deleted file mode 100644 index 76f5e5866..000000000 --- a/shared-module/bleio/Scanner.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H - -#include "py/obj.h" - -typedef struct { - mp_obj_base_t base; - mp_obj_t adv_reports; - uint16_t interval; - uint16_t window; -} bleio_scanner_obj_t; - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H diff --git a/shared-module/bleio/Service.h b/shared-module/bleio/Service.h deleted file mode 100644 index 828d4cdc8..000000000 --- a/shared-module/bleio/Service.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H - -#include "common-hal/bleio/UUID.h" - -typedef struct { - mp_obj_base_t base; - uint16_t handle; - bool is_secondary; - bleio_uuid_obj_t *uuid; - // May be a Peripheral, Central, etc. - mp_obj_t *device; - mp_obj_t char_list; - uint16_t start_handle; - uint16_t end_handle; -} bleio_service_obj_t; - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H -- cgit v1.2.3 From a1b5d800f30418a08a39e73ba4b3e276ca6c7241 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 19 Jun 2019 10:42:36 -0400 Subject: Update copyrights; get ready for Central --- locale/ID.po | 69 +-- locale/circuitpython.pot | 65 ++- locale/de_DE.po | 82 +-- locale/en_US.po | 65 ++- locale/en_x_pirate.po | 65 ++- locale/es.po | 82 +-- locale/fil.po | 69 +-- locale/fr.po | 82 +-- locale/it_IT.po | 69 +-- locale/pl.po | 82 +-- locale/pt_BR.po | 69 +-- locale/zh_Latn_pinyin.po | 82 +-- ports/nrf/Makefile | 1 - ports/nrf/bluetooth/ble_drv.c | 3 +- ports/nrf/bluetooth/ble_drv.h | 3 +- ports/nrf/bluetooth/ble_uart.c | 3 +- ports/nrf/common-hal/analogio/AnalogIn.c | 2 +- ports/nrf/common-hal/bleio/Adapter.c | 1 + ports/nrf/common-hal/bleio/Adapter.h | 3 +- ports/nrf/common-hal/bleio/Broadcaster.h | 47 -- ports/nrf/common-hal/bleio/Characteristic.c | 2 +- ports/nrf/common-hal/bleio/Characteristic.h | 3 +- ports/nrf/common-hal/bleio/CharacteristicBuffer.h | 2 +- ports/nrf/common-hal/bleio/Descriptor.c | 3 +- ports/nrf/common-hal/bleio/Descriptor.h | 3 +- ports/nrf/common-hal/bleio/Device.c | 601 ---------------------- ports/nrf/common-hal/bleio/Peripheral.c | 2 +- ports/nrf/common-hal/bleio/Peripheral.h | 2 +- ports/nrf/common-hal/bleio/Scanner.c | 3 +- ports/nrf/common-hal/bleio/Service.c | 1 + ports/nrf/common-hal/bleio/Service.h | 1 + ports/nrf/common-hal/bleio/UUID.c | 3 +- ports/nrf/common-hal/bleio/UUID.h | 3 +- ports/nrf/common-hal/bleio/__init__.c | 3 +- ports/nrf/common-hal/busio/I2C.c | 5 +- ports/nrf/common-hal/busio/SPI.c | 8 +- ports/nrf/mphalport.c | 3 +- shared-bindings/bleio/Adapter.c | 1 + shared-bindings/bleio/Adapter.h | 1 + shared-bindings/bleio/Address.h | 1 + shared-bindings/bleio/AdvertisementData.h | 1 + shared-bindings/bleio/Characteristic.c | 3 +- shared-bindings/bleio/Characteristic.h | 2 + shared-bindings/bleio/CharacteristicBuffer.h | 2 +- shared-bindings/bleio/Descriptor.c | 3 +- shared-bindings/bleio/Descriptor.h | 1 + shared-bindings/bleio/Device.c | 362 ------------- shared-bindings/bleio/Device.h | 1 + shared-bindings/bleio/Peripheral.c | 3 +- shared-bindings/bleio/Peripheral.h | 2 +- shared-bindings/bleio/ScanEntry.h | 1 + shared-bindings/bleio/Service.c | 3 +- shared-bindings/bleio/Service.h | 4 +- shared-bindings/bleio/UUID.c | 4 +- shared-bindings/bleio/UUID.h | 1 + shared-bindings/bleio/__init__.c | 7 +- shared-bindings/bleio/__init__.h | 3 +- shared-module/bleio/Address.h | 1 + shared-module/bleio/AdvertisementData.h | 1 + shared-module/bleio/Characteristic.h | 42 -- shared-module/bleio/Device.h | 45 -- shared-module/bleio/ScanEntry.h | 1 + 62 files changed, 602 insertions(+), 1486 deletions(-) delete mode 100644 ports/nrf/common-hal/bleio/Broadcaster.h delete mode 100644 ports/nrf/common-hal/bleio/Device.c delete mode 100644 shared-bindings/bleio/Device.c delete mode 100644 shared-module/bleio/Characteristic.h delete mode 100644 shared-module/bleio/Device.h (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index c1760e6b4..701763109 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -218,16 +218,15 @@ msgstr "" msgid "A hardware interrupt channel is already in use" msgstr "Sebuah channel hardware interrupt sedang digunakan" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "buffers harus mempunyai panjang yang sama" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Semua perangkat I2C sedang digunakan" @@ -354,19 +353,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -494,13 +493,12 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Tidak bisa menyesuaikan data ke dalam paket advertisment" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Tidak bisa menyesuaikan data ke dalam paket advertisment" @@ -551,7 +549,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX" @@ -566,7 +564,7 @@ msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "Gagal untuk menambahkan karakteristik, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Gagal untuk menambahkan layanan, status: 0x%08lX" @@ -591,12 +589,17 @@ msgstr "Gagal untuk megalokasikan buffer RX dari %d byte" msgid "Failed to change softdevice state" msgstr "Gagal untuk merubah status softdevice, error: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "Gagal untuk menyambungkan, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" @@ -606,12 +609,12 @@ msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" msgid "Failed to continue scanning, err 0x%04x" msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Gagal untuk membuat mutex, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Gagal untuk menemukan layanan, status: 0x%08lX" @@ -651,7 +654,7 @@ msgstr "Gagal untuk menulis nilai gatts, status: 0x%08lX" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Gagal untuk menambahkan Vendor Spesific UUID, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" @@ -661,18 +664,22 @@ msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" msgid "Failed to release mutex, err 0x%04x" msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" @@ -682,12 +689,11 @@ msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" msgid "Failed to start scanning, err 0x%04x" msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Gagal untuk memberhentikan advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1221,7 +1227,7 @@ msgid "USB Error" msgstr "" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1366,8 +1372,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "argumen num/types tidak cocok" @@ -1920,8 +1926,9 @@ msgstr "" msgid "integer required" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2616,6 +2623,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index d32502e18..bbf77887a 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-12 00:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -219,12 +219,11 @@ msgstr "" #: shared-bindings/bleio/Address.c #, c-format -msgid "Address is not %d bytes long or is in wrong format" +msgid "Address must be %d bytes long" msgstr "" #: shared-bindings/bleio/Address.c -#, c-format -msgid "Address must be %d bytes long" +msgid "Address type out of range" msgstr "" #: ports/nrf/common-hal/busio/I2C.c @@ -349,19 +348,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -484,12 +483,11 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "" @@ -539,7 +537,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "" @@ -553,7 +551,7 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "" @@ -576,11 +574,16 @@ msgstr "" msgid "Failed to change softdevice state" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "" @@ -589,11 +592,11 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -630,7 +633,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "" @@ -639,17 +642,21 @@ msgstr "" msgid "Failed to release mutex, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "" @@ -658,11 +665,10 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1188,7 +1194,7 @@ msgid "USB Error" msgstr "" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1323,8 +1329,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "" @@ -1876,8 +1882,9 @@ msgstr "" msgid "integer required" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2569,6 +2576,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 2bdaaf712..8b559edab 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -219,16 +219,15 @@ msgstr "3-arg pow() wird nicht unterstützt" msgid "A hardware interrupt channel is already in use" msgstr "Ein Hardware Interrupt Kanal wird schon benutzt" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Die Adresse ist nicht %d Bytes lang oder das Format ist falsch" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address must be %d bytes long" msgstr "Die Adresse muss %d Bytes lang sein" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Alle I2C-Peripheriegeräte sind in Benutzung" @@ -353,19 +352,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Kann dotstar nicht mit %s verwenden" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Im Central mode können Dienste nicht hinzugefügt werden" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Im Central mode kann advertise nicht gemacht werden" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Im Central mode kann name nicht geändert werden" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Im Peripheral mode kann keine Verbindung hergestellt werden" @@ -488,12 +487,11 @@ msgstr "Data 0 pin muss am Byte ausgerichtet sein" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "Zu vielen Daten für das advertisement packet" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "Daten sind zu groß für das advertisement packet" @@ -543,7 +541,7 @@ msgstr "Habe ein Tupel der Länge %d erwartet aber %d erhalten" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "Akquirieren des Mutex gescheitert" @@ -557,7 +555,7 @@ msgstr "Mutex konnte nicht akquiriert werden. Status: 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Hinzufügen des Characteristic ist gescheitert. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "Dienst konnte nicht hinzugefügt werden" @@ -580,11 +578,16 @@ msgstr "Konnte keine RX Buffer mit %d allozieren" msgid "Failed to change softdevice state" msgstr "Fehler beim Ändern des Softdevice-Status" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "Verbindung fehlgeschlagen:" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "Der Scanvorgang kann nicht fortgesetzt werden" @@ -593,11 +596,11 @@ msgstr "Der Scanvorgang kann nicht fortgesetzt werden" msgid "Failed to continue scanning, err 0x%04x" msgstr "Der Scanvorgang kann nicht fortgesetzt werden. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "Erstellen des Mutex ist fehlgeschlagen" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Es konnten keine Dienste gefunden werden" @@ -634,7 +637,7 @@ msgstr "gatts value konnte nicht gelesen werden. Status: 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Kann keine herstellerspezifische UUID hinzufügen. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "Loslassen des Mutex gescheitert" @@ -643,17 +646,21 @@ msgstr "Loslassen des Mutex gescheitert" msgid "Failed to release mutex, err 0x%04x" msgstr "Mutex konnte nicht freigegeben werden. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "Kann advertisement nicht starten" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Kann advertisement nicht starten. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "Der Scanvorgang kann nicht gestartet werden" @@ -662,11 +669,10 @@ msgstr "Der Scanvorgang kann nicht gestartet werden" msgid "Failed to start scanning, err 0x%04x" msgstr "Der Scanvorgang kann nicht gestartet werden. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "Kann advertisement nicht stoppen" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1217,8 +1223,8 @@ msgid "USB Error" msgstr "USB Fehler" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "UUID-Integer nicht im Bereich 0 bis 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1363,8 +1369,8 @@ msgstr "arg ist eine leere Sequenz" msgid "argument has wrong type" msgstr "Argument hat falschen Typ" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "Anzahl/Type der Argumente passen nicht" @@ -1917,9 +1923,10 @@ msgstr "int() arg 2 muss >= 2 und <= 36 sein" msgid "integer required" msgstr "integer erforderlich" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "Das Interval ist nicht im Bereich 0.0020 bis 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2625,6 +2632,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "write_args muss eine Liste, ein Tupel oder None sein" @@ -2656,6 +2667,9 @@ msgstr "" #~ msgid "AP required" #~ msgstr "AP erforderlich" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "Die Adresse ist nicht %d Bytes lang oder das Format ist falsch" + #~ msgid "C-level assert" #~ msgstr "C-Level Assert" @@ -2761,6 +2775,9 @@ msgstr "" #~ msgid "UART(1) can't read" #~ msgstr "UART(1) kann nicht lesen" +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "UUID-Integer nicht im Bereich 0 bis 0xffff" + #~ msgid "Unable to remount filesystem" #~ msgstr "Dateisystem konnte nicht wieder eingebunden werden." @@ -2792,6 +2809,9 @@ msgstr "" #~ msgid "impossible baudrate" #~ msgstr "Unmögliche Baudrate" +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "Das Interval ist nicht im Bereich 0.0020 bis 10.24" + #~ msgid "invalid alarm" #~ msgstr "ungültiger Alarm" diff --git a/locale/en_US.po b/locale/en_US.po index 152ece432..616e89630 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -219,12 +219,11 @@ msgstr "" #: shared-bindings/bleio/Address.c #, c-format -msgid "Address is not %d bytes long or is in wrong format" +msgid "Address must be %d bytes long" msgstr "" #: shared-bindings/bleio/Address.c -#, c-format -msgid "Address must be %d bytes long" +msgid "Address type out of range" msgstr "" #: ports/nrf/common-hal/busio/I2C.c @@ -349,19 +348,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -484,12 +483,11 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "" @@ -539,7 +537,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "" @@ -553,7 +551,7 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "" @@ -576,11 +574,16 @@ msgstr "" msgid "Failed to change softdevice state" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "" @@ -589,11 +592,11 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -630,7 +633,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "" @@ -639,17 +642,21 @@ msgstr "" msgid "Failed to release mutex, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "" @@ -658,11 +665,10 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1188,7 +1194,7 @@ msgid "USB Error" msgstr "" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1323,8 +1329,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "" @@ -1876,8 +1882,9 @@ msgstr "" msgid "integer required" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2569,6 +2576,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index d91dc95ca..44db05045 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -221,12 +221,11 @@ msgstr "Avast! A hardware interrupt channel be used already" #: shared-bindings/bleio/Address.c #, c-format -msgid "Address is not %d bytes long or is in wrong format" +msgid "Address must be %d bytes long" msgstr "" #: shared-bindings/bleio/Address.c -#, c-format -msgid "Address must be %d bytes long" +msgid "Address type out of range" msgstr "" #: ports/nrf/common-hal/busio/I2C.c @@ -353,19 +352,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -488,12 +487,11 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "" @@ -543,7 +541,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "" @@ -557,7 +555,7 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "" @@ -580,11 +578,16 @@ msgstr "" msgid "Failed to change softdevice state" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "" @@ -593,11 +596,11 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -634,7 +637,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "" @@ -643,17 +646,21 @@ msgstr "" msgid "Failed to release mutex, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "" @@ -662,11 +669,10 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1192,7 +1198,7 @@ msgid "USB Error" msgstr "" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1327,8 +1333,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "" @@ -1880,8 +1886,9 @@ msgstr "" msgid "integer required" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2573,6 +2580,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/es.po b/locale/es.po index d954d574c..194dea86b 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -223,16 +223,15 @@ msgstr "pow() con 3 argumentos no soportado" msgid "A hardware interrupt channel is already in use" msgstr "El canal EXTINT ya está siendo utilizado" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Direción no es %d bytes largo o esta en el formato incorrecto" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "Direción debe ser %d bytes de largo" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Todos los periféricos I2C están siendo usados" @@ -363,19 +362,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "No se puede usar dotstar con %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "No se pueden agregar servicio en modo Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "No se puede anunciar en modo Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "No se puede cambiar el nombre en modo Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "No se puede conectar en modo Peripheral" @@ -500,13 +499,12 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "El Data Chunk debe seguir el fmt chunk" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Los datos no caben en el paquete de anuncio." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Los datos no caben en el paquete de anuncio." @@ -559,7 +557,7 @@ msgstr "Se esperaba un tuple de %d, se obtuvo %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "No se puede adquirir el mutex, status: 0x%08lX" @@ -574,7 +572,7 @@ msgstr "No se puede adquirir el mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "No se puede añadir caracteristica, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "No se puede detener el anuncio. status: 0x%02x" @@ -599,12 +597,17 @@ msgstr "Falló la asignación del buffer RX de %d bytes" msgid "Failed to change softdevice state" msgstr "No se puede cambiar el estado del softdevice, error: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "No se puede conectar. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "No se puede iniciar el escaneo. status: 0x%02x" @@ -614,12 +617,12 @@ msgstr "No se puede iniciar el escaneo. status: 0x%02x" msgid "Failed to continue scanning, err 0x%04x" msgstr "No se puede iniciar el escaneo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "No se puede leer el valor del atributo. status 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "No se puede descubrir servicios, status: 0x%08lX" @@ -659,7 +662,7 @@ msgstr "No se puede escribir el valor del atributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "No se puede agregar el Vendor Specific 128-bit UUID." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "No se puede liberar el mutex, status: 0x%08lX" @@ -669,18 +672,22 @@ msgstr "No se puede liberar el mutex, status: 0x%08lX" msgid "Failed to release mutex, err 0x%04x" msgstr "No se puede liberar el mutex, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "No se puede inicar el anuncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "No se puede inicar el anuncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "No se puede iniciar el escaneo. status: 0x%02x" @@ -690,12 +697,11 @@ msgstr "No se puede iniciar el escaneo. status: 0x%02x" msgid "Failed to start scanning, err 0x%04x" msgstr "No se puede iniciar el escaneo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "No se puede detener el anuncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1244,8 +1250,8 @@ msgid "USB Error" msgstr "Error USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "El valor integer UUID no está en el rango 0 a 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1389,8 +1395,8 @@ msgstr "argumento es una secuencia vacía" msgid "argument has wrong type" msgstr "el argumento tiene un tipo erroneo" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "argumento número/tipos no coinciden" @@ -1951,9 +1957,10 @@ msgstr "int() arg 2 debe ser >= 2 y <= 36" msgid "integer required" msgstr "Entero requerido" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "El intervalo está fuera del rango de 0.0020 a 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2658,6 +2665,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "value_count debe ser > 0" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "write_args debe ser lista, tuple, o None" @@ -2691,6 +2702,9 @@ msgstr "paso cero" #~ msgid "AP required" #~ msgstr "AP requerido" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "Direción no es %d bytes largo o esta en el formato incorrecto" + #~ msgid "Cannot connect to AP" #~ msgstr "No se puede conectar a AP" @@ -2803,6 +2817,9 @@ msgstr "paso cero" #~ msgid "UART(1) can't read" #~ msgstr "UART(1) no puede leer" +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "El valor integer UUID no está en el rango 0 a 0xffff" + #~ msgid "Unable to remount filesystem" #~ msgstr "Incapaz de montar de nuevo el sistema de archivos" @@ -2852,6 +2869,9 @@ msgstr "paso cero" #~ msgid "impossible baudrate" #~ msgstr "baudrate imposible" +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "El intervalo está fuera del rango de 0.0020 a 10.24" + #~ msgid "invalid alarm" #~ msgstr "alarma inválida" diff --git a/locale/fil.po b/locale/fil.po index b6ad3643c..9c688ec14 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -220,16 +220,15 @@ msgstr "3-arg pow() hindi suportado" msgid "A hardware interrupt channel is already in use" msgstr "Isang channel ng hardware interrupt ay ginagamit na" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "ang palette ay dapat 32 bytes ang haba" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Lahat ng I2C peripherals ginagamit" @@ -356,19 +355,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Hindi maarang maglagay ng service sa Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Hindi ma advertise habang nasa Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Hindi mapalitan ang pangalan sa Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Hindi maconnect sa Peripheral mode" @@ -494,13 +493,12 @@ msgstr "graphic ay dapat 2048 bytes ang haba" msgid "Data chunk must follow fmt chunk" msgstr "Dapat sunurin ng Data chunk ang fmt chunk" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Hindi makasya ang data sa loob ng advertisement packet" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Hindi makasya ang data sa loob ng advertisement packet" @@ -554,7 +552,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Nabigo sa pag kuha ng mutex, status: 0x%08lX" @@ -569,7 +567,7 @@ msgstr "Nabigo sa pag kuha ng mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "Nabigo sa paglagay ng characteristic, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Hindi matagumpay ang paglagay ng service, status: 0x%08lX" @@ -594,12 +592,17 @@ msgstr "Nabigong ilaan ang RX buffer ng %d bytes" msgid "Failed to change softdevice state" msgstr "Nabigo sa pagbago ng softdevice state, error: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "Hindi makaconnect, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" @@ -609,12 +612,12 @@ msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" msgid "Failed to continue scanning, err 0x%04x" msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Hindi matagumpay ang pagbuo ng mutex, status: 0x%0xlX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Nabigo sa pagdiscover ng services, status: 0x%08lX" @@ -654,7 +657,7 @@ msgstr "Hindi maisulat ang gatts value, status: 0x%08lX" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Hindi matagumpay ang paglagay ng Vender Specific UUID, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" @@ -664,18 +667,22 @@ msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" msgid "Failed to release mutex, err 0x%04x" msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" @@ -685,12 +692,11 @@ msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" msgid "Failed to start scanning, err 0x%04x" msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Hindi mahinto ang advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1241,7 +1247,7 @@ msgid "USB Error" msgstr "May pagkakamali ang USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1386,8 +1392,8 @@ msgstr "arg ay walang laman na sequence" msgid "argument has wrong type" msgstr "may maling type ang argument" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "hindi tugma ang argument num/types" @@ -1952,8 +1958,9 @@ msgstr "int() arg 2 ay dapat >=2 at <= 36" msgid "integer required" msgstr "kailangan ng int" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2657,6 +2664,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/fr.po b/locale/fr.po index 6fd6e9015..60122a5d0 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -221,16 +221,15 @@ msgstr "pow() non supporté avec 3 arguments" msgid "A hardware interrupt channel is already in use" msgstr "Un canal d'interruptions matérielles est déjà utilisé" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "L'adresse n'est pas longue de %d octets ou est d'un format erroné" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "L'adresse doit être longue de %d octets" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c #, fuzzy msgid "All I2C peripherals are in use" @@ -361,19 +360,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Impossible d'utiliser 'dotstar' avec %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Impossible d'ajouter des services en mode Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Impossible de publier en mode Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Modification du nom impossible en mode Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Impossible de se connecter en mode 'Peripheral'" @@ -500,12 +499,11 @@ msgstr "La broche 'Data 0' doit être aligné sur l'octet" msgid "Data chunk must follow fmt chunk" msgstr "Un bloc de données doit suivre un bloc de format" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "Données trop volumineuses pour un paquet de diffusion" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "Données trop volumineuses pour le paquet de diffusion" @@ -557,7 +555,7 @@ msgstr "Tuple de longueur %d attendu, obtenu %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Echec de l'obtention de mutex" @@ -572,7 +570,7 @@ msgstr "Echec de l'obtention de mutex, err 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Echec de l'ajout de caractéristique, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Echec de l'ajout de service" @@ -597,12 +595,17 @@ msgstr "Echec de l'allocation de %d octets du tampon RX" msgid "Failed to change softdevice state" msgstr "Echec de la modification de l'état du périphérique" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "Echec de connection:" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "Impossible de poursuivre le scan" @@ -612,12 +615,12 @@ msgstr "Impossible de poursuivre le scan" msgid "Failed to continue scanning, err 0x%04x" msgstr "Impossible de poursuivre le scan, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Echec de la création de mutex" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Echec de la découverte de services" @@ -658,7 +661,7 @@ msgstr "Impossible de lire la valeur de 'gatts', err 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Echec de l'ajout de l'UUID du fournisseur, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Impossible de libérer mutex" @@ -668,18 +671,22 @@ msgstr "Impossible de libérer mutex" msgid "Failed to release mutex, err 0x%04x" msgstr "Impossible de libérer mutex, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Echec du démarrage de la diffusion" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Impossible de commencer à diffuser, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Impossible de commencer à scanner" @@ -689,12 +696,11 @@ msgstr "Impossible de commencer à scanner" msgid "Failed to start scanning, err 0x%04x" msgstr "Impossible de commencer à scanner, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Echec de l'arrêt de diffusion" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1261,8 +1267,8 @@ msgid "USB Error" msgstr "Erreur USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "valeur de l'entier UUID est hors-bornes 0 à 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1410,8 +1416,8 @@ msgstr "l'argument est une séquence vide" msgid "argument has wrong type" msgstr "l'argument est d'un mauvais type" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "argument num/types ne correspond pas" @@ -1984,9 +1990,10 @@ msgstr "l'argument 2 de int() doit être >=2 et <=36" msgid "integer required" msgstr "entier requis" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "intervalle hors bornes 0.0020 à 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2699,6 +2706,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "'value_count' doit être > 0" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "'write_args' doit être une liste, un tuple ou 'None'" @@ -2733,6 +2744,9 @@ msgstr "'step' nul" #~ msgid "AP required" #~ msgstr "'AP' requis" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "L'adresse n'est pas longue de %d octets ou est d'un format erroné" + #~ msgid "Cannot connect to AP" #~ msgstr "Impossible de se connecter à 'AP'" @@ -2835,6 +2849,9 @@ msgstr "'step' nul" #~ msgid "UART(1) can't read" #~ msgstr "UART(1) ne peut pas lire" +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "valeur de l'entier UUID est hors-bornes 0 à 0xffff" + #~ msgid "Unable to remount filesystem" #~ msgstr "Impossible de remonter le système de fichiers" @@ -2881,6 +2898,9 @@ msgstr "'step' nul" #~ msgid "impossible baudrate" #~ msgstr "débit impossible" +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "intervalle hors bornes 0.0020 à 10.24" + #~ msgid "invalid alarm" #~ msgstr "alarme invalide" diff --git a/locale/it_IT.po b/locale/it_IT.po index d89d4ae07..6f0e90e17 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -219,16 +219,15 @@ msgstr "pow() con tre argmomenti non supportata" msgid "A hardware interrupt channel is already in use" msgstr "Un canale di interrupt hardware è già in uso" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "la palette deve essere lunga 32 byte" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Tutte le periferiche I2C sono in uso" @@ -356,19 +355,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "dotstar non può essere usato con %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "non si può aggiungere servizi in Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "non si può pubblicizzare in Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "non si può cambiare il nome in Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "non si può connettere in Periferal mode" @@ -495,13 +494,12 @@ msgstr "graphic deve essere lunga 2048 byte" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Impossibile inserire dati nel pacchetto di advertisement." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Impossibile inserire dati nel pacchetto di advertisement." @@ -554,7 +552,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Impossibile allocare buffer RX" @@ -569,7 +567,7 @@ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Impossibile fermare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Impossibile fermare advertisement. status: 0x%02x" @@ -594,12 +592,17 @@ msgstr "Fallita allocazione del buffer RX di %d byte" msgid "Failed to change softdevice state" msgstr "Impossibile fermare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "Impossibile connettersi. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "Impossible iniziare la scansione. status: 0x%02x" @@ -609,12 +612,12 @@ msgstr "Impossible iniziare la scansione. status: 0x%02x" msgid "Failed to continue scanning, err 0x%04x" msgstr "Impossible iniziare la scansione. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Impossibile fermare advertisement. status: 0x%02x" @@ -653,7 +656,7 @@ msgstr "Impossibile scrivere valore dell'attributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Non è possibile aggiungere l'UUID del vendor specifico da 128-bit" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" @@ -663,18 +666,22 @@ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" msgid "Failed to release mutex, err 0x%04x" msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Impossibile avviare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Impossibile avviare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Impossible iniziare la scansione. status: 0x%02x" @@ -684,12 +691,11 @@ msgstr "Impossible iniziare la scansione. status: 0x%02x" msgid "Failed to start scanning, err 0x%04x" msgstr "Impossible iniziare la scansione. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Impossibile fermare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1240,7 +1246,7 @@ msgid "USB Error" msgstr "Errore USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1380,8 +1386,8 @@ msgstr "l'argomento è una sequenza vuota" msgid "argument has wrong type" msgstr "il tipo dell'argomento è errato" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "discrepanza di numero/tipo di argomenti" @@ -1944,8 +1950,9 @@ msgstr "il secondo argomanto di int() deve essere >= 2 e <= 36" msgid "integer required" msgstr "intero richiesto" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2655,6 +2662,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/pl.po b/locale/pl.po index e7dc248be..a7155e0c8 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -218,16 +218,15 @@ msgstr "3-argumentowy pow() jest niewspierany" msgid "A hardware interrupt channel is already in use" msgstr "Kanał przerwań sprzętowych w użyciu" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Adres nie ma długości %d bajtów lub zły format" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address must be %d bytes long" msgstr "Adres musi mieć %d bajtów" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Wszystkie peryferia I2C w użyciu" @@ -352,19 +351,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Nie można używać dotstar z %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Nie można dodać serwisów w trybie Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Nie można rozgłaszać w trybie Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Nie można zmienić nazwy w trybie Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Nie można się łączyć w trybie Peripheral" @@ -487,12 +486,11 @@ msgstr "Nóżka data 0 musi być wyrównana do bajtu" msgid "Data chunk must follow fmt chunk" msgstr "Fragment danych musi następować po fragmencie fmt" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "Zbyt dużo danych pakietu rozgłoszeniowego" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "Zbyt dużo danych pakietu rozgłoszeniowego" @@ -542,7 +540,7 @@ msgstr "Oczekiwano krotkę długości %d, otrzymano %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "Nie udało się uzyskać blokady" @@ -556,7 +554,7 @@ msgstr "Nie udało się uzyskać blokady, błąd 0x$04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Nie udało się dodać charakterystyki, błąd 0x$04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "Nie udało się dodać serwisu" @@ -579,11 +577,16 @@ msgstr "Nie udała się alokacja %d bajtów na bufor RX" msgid "Failed to change softdevice state" msgstr "Nie udało się zmienić stanu softdevice" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "Nie udało się połączenie:" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "Nie udała się kontynuacja skanowania" @@ -592,11 +595,11 @@ msgstr "Nie udała się kontynuacja skanowania" msgid "Failed to continue scanning, err 0x%04x" msgstr "Nie udała się kontynuacja skanowania, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "Nie udało się stworzyć blokady" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Nie udało się odkryć serwisów" @@ -633,7 +636,7 @@ msgstr "Nie udało się odczytać gatts, błąd 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Nie udało się zarejestrować UUID dostawcy, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "Nie udało się zwolnić blokady" @@ -642,17 +645,21 @@ msgstr "Nie udało się zwolnić blokady" msgid "Failed to release mutex, err 0x%04x" msgstr "Nie udało się zwolnić blokady, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "Nie udało się rozpocząć rozgłaszania" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Nie udało się rozpocząć rozgłaszania, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "Nie udało się rozpocząć skanowania" @@ -661,11 +668,10 @@ msgstr "Nie udało się rozpocząć skanowania" msgid "Failed to start scanning, err 0x%04x" msgstr "Nie udało się rozpocząć skanowania, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "Nie udało się zatrzymać rozgłaszania" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1208,8 +1214,8 @@ msgid "USB Error" msgstr "Błąd USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "Wartość UUID poza zakresem 0 do 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1347,8 +1353,8 @@ msgstr "arg jest puste" msgid "argument has wrong type" msgstr "argument ma zły typ" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "zła liczba lub typ argumentów" @@ -1901,9 +1907,10 @@ msgstr "argument 2 do int() busi być pomiędzy 2 a 36" msgid "integer required" msgstr "wymagana liczba całkowita" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "przedział poza zakresem 0.0020 do 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2596,6 +2603,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "value_count musi być > 0" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "write_args musi być listą, krotką lub None" @@ -2624,6 +2635,9 @@ msgstr "y poza zakresem" msgid "zero step" msgstr "zerowy krok" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "Adres nie ma długości %d bajtów lub zły format" + #~ msgid "Invalid bit clock pin" #~ msgstr "Zła nóżka zegara" @@ -2635,3 +2649,9 @@ msgstr "zerowy krok" #~ msgid "Must be a Group subclass." #~ msgstr "Musi dziedziczyć z Group." + +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "Wartość UUID poza zakresem 0 do 0xffff" + +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "przedział poza zakresem 0.0020 do 10.24" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index f08619187..01eda181f 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -219,16 +219,15 @@ msgstr "" msgid "A hardware interrupt channel is already in use" msgstr "Um canal de interrupção de hardware já está em uso" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "buffers devem ser o mesmo tamanho" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Todos os periféricos I2C estão em uso" @@ -353,19 +352,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -490,13 +489,12 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "Pedaço de dados deve seguir o pedaço de cortes" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Não é possível ajustar dados no pacote de anúncios." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Não é possível ajustar dados no pacote de anúncios." @@ -549,7 +547,7 @@ msgstr "" msgid "Failed sending command." msgstr "Falha ao enviar comando." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Falha ao alocar buffer RX" @@ -564,7 +562,7 @@ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Não pode parar propaganda. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Não pode parar propaganda. status: 0x%02x" @@ -589,11 +587,16 @@ msgstr "Falha ao alocar buffer RX de %d bytes" msgid "Failed to change softdevice state" msgstr "Não pode parar propaganda. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "" @@ -602,12 +605,12 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Não é possível ler o valor do atributo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Não pode parar propaganda. status: 0x%02x" @@ -646,7 +649,7 @@ msgstr "Não é possível gravar o valor do atributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Não é possível adicionar o UUID de 128 bits específico do fornecedor." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Não é possível ler o valor do atributo. status: 0x%02x" @@ -656,18 +659,22 @@ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" msgid "Failed to release mutex, err 0x%04x" msgstr "Não é possível ler o valor do atributo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" @@ -677,12 +684,11 @@ msgstr "Não é possível iniciar o anúncio. status: 0x%02x" msgid "Failed to start scanning, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Não pode parar propaganda. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1216,7 +1222,7 @@ msgid "USB Error" msgstr "Erro na USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1352,8 +1358,8 @@ msgstr "" msgid "argument has wrong type" msgstr "argumento tem tipo errado" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "" @@ -1909,8 +1915,9 @@ msgstr "" msgid "integer required" msgstr "inteiro requerido" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2606,6 +2613,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index dd61f1362..79d803d67 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -219,16 +219,15 @@ msgstr "bù zhīchí 3-arg pow ()" msgid "A hardware interrupt channel is already in use" msgstr "Yìngjiàn zhōngduàn tōngdào yǐ zài shǐyòng zhōng" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Dìzhǐ bùshì %d zì jié zhǎng, huòzhě géshì cuòwù" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address must be %d bytes long" msgstr "Dìzhǐ bìxū shì %d zì jié zhǎng" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Suǒyǒu I2C wàiwéi qì zhèngzài shǐyòng" @@ -353,19 +352,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Wúfǎ yǔ dotstar yīqǐ shǐyòng %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Wúfǎ zài zhōngyāng móshì xià tiānjiā fúwù" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Wúfǎ zài zhōngyāng móshì zhōng guǎnggào" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Wúfǎ gēnggǎi zhōngyāng móshì de míngchēng" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Wúfǎ zài biānyuán móshì zhōng liánjiē" @@ -488,12 +487,11 @@ msgstr "Shùjù 0 de yǐn jiǎo bìxū shì zì jié duìqí" msgid "Data chunk must follow fmt chunk" msgstr "Shùjù kuài bìxū zūnxún fmt qū kuài" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "Guǎnggào bāo de shùjù tài dà" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "Guǎnggào bāo de shùjù tài dà" @@ -543,7 +541,7 @@ msgstr "Qīwàng de chángdù wèi %d de yuán zǔ, dédào %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "Wúfǎ huòdé mutex" @@ -557,7 +555,7 @@ msgstr "Wúfǎ huòdé mutex, err 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Tiānjiā tèxìng shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "Tiānjiā fúwù shībài" @@ -580,11 +578,16 @@ msgstr "Fēnpèi RX huǎnchōng qū%d zì jié shībài" msgid "Failed to change softdevice state" msgstr "Gēnggǎi ruǎn shèbèi zhuàngtài shībài" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "Liánjiē shībài:" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "Jìxù sǎomiáo shībài" @@ -593,11 +596,11 @@ msgstr "Jìxù sǎomiáo shībài" msgid "Failed to continue scanning, err 0x%04x" msgstr "Jìxù sǎomiáo shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "Wúfǎ chuàngjiàn hù chì suǒ" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Fāxiàn fúwù shībài" @@ -634,7 +637,7 @@ msgstr "Wúfǎ dòu qǔ gatts zhí, err 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Wúfǎ zhùcè màizhǔ tèdìng de UUID, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "Wúfǎ shìfàng mutex" @@ -643,17 +646,21 @@ msgstr "Wúfǎ shìfàng mutex" msgid "Failed to release mutex, err 0x%04x" msgstr "Wúfǎ shìfàng mutex, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "Qǐdòng guǎnggào shībài" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Qǐdòng guǎnggào shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "Qǐdòng sǎomiáo shībài" @@ -662,11 +669,10 @@ msgstr "Qǐdòng sǎomiáo shībài" msgid "Failed to start scanning, err 0x%04x" msgstr "Qǐdòng sǎomiáo shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "Wúfǎ tíngzhǐ guǎnggào" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1213,8 +1219,8 @@ msgid "USB Error" msgstr "USB Cuòwù" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "UUID zhěngshù zhí bùzài fànwéi 0 zhì 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1355,8 +1361,8 @@ msgstr "cānshù shì yīgè kōng de xùliè" msgid "argument has wrong type" msgstr "cānshù lèixíng cuòwù" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "cānshù biānhào/lèixíng bù pǐpèi" @@ -1911,9 +1917,10 @@ msgstr "zhěngshù() cānshù 2 bìxū > = 2 qiě <= 36" msgid "integer required" msgstr "xūyào zhěngshù" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "jùlí 0.0020 Zhì 10.24 Zhī jiān de jiàngé shíjiān" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2608,6 +2615,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "zhí jìshù bìxū wèi > 0" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "xiě cānshù bìxū shì yuán zǔ, lièbiǎo huò None" @@ -2636,6 +2647,9 @@ msgstr "y zhí chāochū biānjiè" msgid "zero step" msgstr "líng bù" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "Dìzhǐ bùshì %d zì jié zhǎng, huòzhě géshì cuòwù" + #~ msgid "Invalid bit clock pin" #~ msgstr "Wúxiào de wèi shízhōng yǐn jiǎo" @@ -2660,9 +2674,15 @@ msgstr "líng bù" #~ msgid "Only bit maps of 8 bit color or less are supported" #~ msgstr "Jǐn zhīchí 8 wèi yánsè huò xiǎoyú" +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "UUID zhěngshù zhí bùzài fànwéi 0 zhì 0xffff" + #~ msgid "expected a DigitalInOut" #~ msgstr "qídài de DigitalInOut" +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "jùlí 0.0020 Zhì 10.24 Zhī jiān de jiàngé shíjiān" + #~ msgid "row must be packed and word aligned" #~ msgstr "xíng bìxū dǎbāo bìngqiě zì duìqí" diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index b7ff2fcba..18990485b 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -159,7 +159,6 @@ SRC_C += \ boards/$(BOARD)/pins.c \ device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \ bluetooth/ble_drv.c \ - bluetooth/ble_uart.c \ lib/libc/string0.c \ lib/mp-readline/readline.c \ lib/oofatfs/ff.c \ diff --git a/ports/nrf/bluetooth/ble_drv.c b/ports/nrf/bluetooth/ble_drv.c index f6e575a8c..6b17e7af2 100644 --- a/ports/nrf/bluetooth/ble_drv.c +++ b/ports/nrf/bluetooth/ble_drv.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/bluetooth/ble_drv.h b/ports/nrf/bluetooth/ble_drv.h index 133d77b48..d349fa4e0 100644 --- a/ports/nrf/bluetooth/ble_drv.h +++ b/ports/nrf/bluetooth/ble_drv.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/bluetooth/ble_uart.c b/ports/nrf/bluetooth/ble_uart.c index 7faaafb0e..91d10cff1 100644 --- a/ports/nrf/bluetooth/ble_uart.c +++ b/ports/nrf/bluetooth/ble_uart.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/analogio/AnalogIn.c b/ports/nrf/common-hal/analogio/AnalogIn.c index 1e572f7cb..f20802ac9 100644 --- a/ports/nrf/common-hal/analogio/AnalogIn.c +++ b/ports/nrf/common-hal/analogio/AnalogIn.c @@ -3,8 +3,8 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries - * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Adapter.c b/ports/nrf/common-hal/bleio/Adapter.c index 120fcf055..9d0912930 100644 --- a/ports/nrf/common-hal/bleio/Adapter.c +++ b/ports/nrf/common-hal/bleio/Adapter.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2016 Glenn Ruben Bakke * Copyright (c) 2018 Artur Pacholec * diff --git a/ports/nrf/common-hal/bleio/Adapter.h b/ports/nrf/common-hal/bleio/Adapter.h index 0497f9ac9..5dcc62540 100644 --- a/ports/nrf/common-hal/bleio/Adapter.h +++ b/ports/nrf/common-hal/bleio/Adapter.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Broadcaster.h b/ports/nrf/common-hal/bleio/Broadcaster.h deleted file mode 100644 index 2d1ae69a1..000000000 --- a/ports/nrf/common-hal/bleio/Broadcaster.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * Copyright (c) 2018 Dan Halbert for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H -#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H - -#include "ble.h" - -#include "shared-module/bleio/__init__.h" -#include "shared-module/bleio/Address.h" - -typedef struct { - mp_obj_base_t base; - // In seconds. - mp_float_t interval; - // The advertising data buffer is held by us, not by the SD, so we must - // maintain it and not change it. If we need to change its contents during advertising, - // there are tricks to get the SD to notice (see DevZone - TBS). - uint8_t adv_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; - -} bleio_broadcaster_obj_t; - -#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 45fb1d092..346cfefbc 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -34,7 +35,6 @@ #include "py/runtime.h" #include "common-hal/bleio/__init__.h" #include "common-hal/bleio/Characteristic.h" -#include "shared-module/bleio/Characteristic.h" STATIC volatile bleio_characteristic_obj_t *m_read_characteristic; STATIC volatile uint8_t m_tx_in_progress; diff --git a/ports/nrf/common-hal/bleio/Characteristic.h b/ports/nrf/common-hal/bleio/Characteristic.h index 662485bad..451bae471 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.h +++ b/ports/nrf/common-hal/bleio/Characteristic.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -27,9 +28,9 @@ #ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H #define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H -#include "shared-module/bleio/Characteristic.h" #include "common-hal/bleio/Service.h" #include "common-hal/bleio/UUID.h" +#include "shared-module/bleio/Characteristic.h" typedef struct { mp_obj_base_t base; diff --git a/ports/nrf/common-hal/bleio/CharacteristicBuffer.h b/ports/nrf/common-hal/bleio/CharacteristicBuffer.h index 6a44229f7..db8fd2fad 100644 --- a/ports/nrf/common-hal/bleio/CharacteristicBuffer.h +++ b/ports/nrf/common-hal/bleio/CharacteristicBuffer.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Descriptor.c b/ports/nrf/common-hal/bleio/Descriptor.c index 8282be8f2..418cc07c1 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.c +++ b/ports/nrf/common-hal/bleio/Descriptor.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Descriptor.h b/ports/nrf/common-hal/bleio/Descriptor.h index ee0886c22..47552f39d 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.h +++ b/ports/nrf/common-hal/bleio/Descriptor.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Device.c b/ports/nrf/common-hal/bleio/Device.c deleted file mode 100644 index b1ac72e75..000000000 --- a/ports/nrf/common-hal/bleio/Device.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include - -#include "ble.h" -#include "ble_drv.h" -#include "ble_hci.h" -#include "nrf_soc.h" -#include "py/objstr.h" -#include "py/runtime.h" -#include "shared-bindings/bleio/Adapter.h" -#include "shared-bindings/bleio/Characteristic.h" -#include "shared-bindings/bleio/Device.h" -#include "shared-bindings/bleio/Service.h" -#include "shared-bindings/bleio/UUID.h" - -#define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_0_625_MS) -#define BLE_MAX_CONN_INTERVAL MSEC_TO_UNITS(300, UNIT_0_625_MS) -#define BLE_SLAVE_LATENCY 0 -#define BLE_CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) - -#define BLE_ADV_LENGTH_FIELD_SIZE 1 -#define BLE_ADV_AD_TYPE_FIELD_SIZE 1 -#define BLE_AD_TYPE_FLAGS_DATA_SIZE 1 - -#ifndef BLE_GAP_ADV_MAX_SIZE -#define BLE_GAP_ADV_MAX_SIZE 31 -#endif - -static bleio_service_obj_t *m_char_discovery_service; -static volatile bool m_discovery_successful; -static nrf_mutex_t *m_discovery_mutex; - -#if (BLUETOOTH_SD == 140) -static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; - -static uint8_t m_scan_buffer_data[BLE_GAP_SCAN_BUFFER_MIN]; - -static ble_data_t m_scan_buffer = { - .p_data = m_scan_buffer_data, - .len = BLE_GAP_SCAN_BUFFER_MIN -}; -#endif - -STATIC uint32_t set_advertisement_data(bleio_device_obj_t *device, bool connectable, mp_buffer_info_t *raw_data) { - common_hal_bleio_adapter_set_enabled(true); - - uint8_t adv_data[BLE_GAP_ADV_MAX_SIZE]; - uint8_t byte_pos = 0; - uint32_t err_code; - -#define ADD_FIELD(field, len) \ - do { \ - if (byte_pos + (len) > BLE_GAP_ADV_MAX_SIZE) { \ - mp_raise_ValueError(translate("Data too large for the advertisement packet")); \ - } \ - adv_data[byte_pos] = (field); \ - byte_pos += (len); \ - } while (0) - - GET_STR_DATA_LEN(device->name, name_data, name_len); - if (name_len > 0) { - ble_gap_conn_sec_mode_t sec_mode; - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - - err_code = sd_ble_gap_device_name_set(&sec_mode, name_data, name_len); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - // TODO: Shorten if too long - - ADD_FIELD(BLE_ADV_AD_TYPE_FIELD_SIZE + name_len, BLE_ADV_LENGTH_FIELD_SIZE); - ADD_FIELD(BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, BLE_ADV_AD_TYPE_FIELD_SIZE); - - memcpy(&adv_data[byte_pos], name_data, name_len); - byte_pos += name_len; - } - - // set flags, default to disc mode - if (raw_data->len == 0) { - ADD_FIELD(BLE_ADV_AD_TYPE_FIELD_SIZE + BLE_AD_TYPE_FLAGS_DATA_SIZE, BLE_ADV_LENGTH_FIELD_SIZE); - ADD_FIELD(BLE_GAP_AD_TYPE_FLAGS, BLE_AD_TYPE_FLAGS_DATA_SIZE); - ADD_FIELD(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE, BLE_AD_TYPE_FLAGS_DATA_SIZE); - } else { - if (byte_pos + raw_data->len > BLE_GAP_ADV_MAX_SIZE) { - mp_raise_ValueError(translate("Data too large for the advertisement packet")); - } - - memcpy(&adv_data[byte_pos], raw_data->buf, raw_data->len); - byte_pos += raw_data->len; - } - - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(device->service_list); - if (service_list->len > 0) { - bool has_128bit_services = false; - bool has_16bit_services = false; - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - - if (service->is_secondary) { - continue; - } - - switch (common_hal_bleio_uuid_get_size(service->uuid)) { - case 16: - has_16bit_services = true; - break; - case 128: - has_128bit_services = true; - break; - } - } - - if (has_16bit_services) { - const uint8_t size_byte_pos = byte_pos; - uint8_t uuid_total_size = 0; - - // skip length byte for now, apply total length post calculation - byte_pos += BLE_ADV_LENGTH_FIELD_SIZE; - - ADD_FIELD(BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE, BLE_ADV_AD_TYPE_FIELD_SIZE); - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - uint8_t encoded_size = 0; - - if (common_hal_bleio_uuid_get_size(service->uuid) != 16 || service->is_secondary) { - continue; - } - - ble_uuid_t uuid; - bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); - - err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - uuid_total_size += encoded_size; - byte_pos += encoded_size; - } - - adv_data[size_byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + uuid_total_size); - } - - if (has_128bit_services) { - const uint8_t size_byte_pos = byte_pos; - uint8_t uuid_total_size = 0; - - // skip length byte for now, apply total length post calculation - byte_pos += BLE_ADV_LENGTH_FIELD_SIZE; - - ADD_FIELD(BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE, BLE_ADV_AD_TYPE_FIELD_SIZE); - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - uint8_t encoded_size = 0; - - if (common_hal_bleio_uuid_get_size(service->uuid) != 16 || service->is_secondary) { - continue; - } - - ble_uuid_t uuid; - bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); - - err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - uuid_total_size += encoded_size; - byte_pos += encoded_size; - } - - adv_data[size_byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + uuid_total_size); - } - } - -#if (BLUETOOTH_SD == 132) - err_code = sd_ble_gap_adv_data_set(adv_data, byte_pos, NULL, 0); - if (err_code != NRF_SUCCESS) { - return err_code; - } -#endif - - static ble_gap_adv_params_t m_adv_params = { - .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), -#if (BLUETOOTH_SD == 140) - .properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED, - .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, - .filter_policy = BLE_GAP_ADV_FP_ANY, - .primary_phy = BLE_GAP_PHY_1MBPS, -#else - .type = BLE_GAP_ADV_TYPE_ADV_IND, - .fp = BLE_GAP_ADV_FP_ANY, -#endif - }; - - if (!connectable) { -#if (BLUETOOTH_SD == 140) - m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED; -#else - m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND; -#endif - } - - common_hal_bleio_device_stop_advertising(device); - -#if (BLUETOOTH_SD == 140) - const ble_gap_adv_data_t ble_gap_adv_data = { - .adv_data.p_data = adv_data, - .adv_data.len = byte_pos, - }; - - err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - err_code = sd_ble_gap_adv_start(m_adv_handle, BLE_CONN_CFG_TAG_CUSTOM); -#elif (BLUETOOTH_SD == 132 && BLE_API_VERSION == 4) - err_code = sd_ble_gap_adv_start(&m_adv_params, BLE_CONN_CFG_TAG_CUSTOM); -#else - err_code = sd_ble_gap_adv_start(&m_adv_params); -#endif - - return err_code; -} - -STATIC bool discover_services(bleio_device_obj_t *device, uint16_t start_handle) { - m_discovery_successful = false; - - uint32_t err_code = sd_ble_gattc_primary_services_discover(device->conn_handle, start_handle, NULL); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to discover services")); - } - - // Serialize discovery. - err_code = sd_mutex_acquire(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to acquire mutex")); - } - - // Wait for someone else to release m_discovery_mutex. - while (sd_mutex_acquire(m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - err_code = sd_mutex_release(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } - - return m_discovery_successful; -} - -STATIC bool discover_characteristics(bleio_device_obj_t *device, bleio_service_obj_t *service, uint16_t start_handle) { - m_char_discovery_service = service; - - ble_gattc_handle_range_t handle_range; - handle_range.start_handle = start_handle; - handle_range.end_handle = service->end_handle; - - m_discovery_successful = false; - - uint32_t err_code = sd_ble_gattc_characteristics_discover(device->conn_handle, &handle_range); - if (err_code != NRF_SUCCESS) { - return false; - } - - err_code = sd_mutex_acquire(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to acquire mutex")); - } - - while (sd_mutex_acquire(m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - err_code = sd_mutex_release(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } - - return m_discovery_successful; -} - -STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *response, bleio_device_obj_t *device) { - for (size_t i = 0; i < response->count; ++i) { - ble_gattc_service_t *gattc_service = &response->services[i]; - - bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); - service->base.type = &bleio_service_type; - service->device = device; - service->characteristic_list = mp_obj_new_list(0, NULL); - service->start_handle = gattc_service->handle_range.start_handle; - service->end_handle = gattc_service->handle_range.end_handle; - service->handle = gattc_service->handle_range.start_handle; - - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); - bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid); - service->uuid = uuid; - - mp_obj_list_append(device->service_list, service); - } - - if (response->count > 0) { - m_discovery_successful = true; - } - - const uint32_t err_code = sd_mutex_release(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } -} - -STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio_device_obj_t *device) { - for (size_t i = 0; i < response->count; ++i) { - ble_gattc_char_t *gattc_char = &response->chars[i]; - - bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); - characteristic->base.type = &bleio_characteristic_type; - - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); - uuid->base.type = &bleio_uuid_type; - bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); - characteristic->uuid = uuid; - - characteristic->props.broadcast = gattc_char->char_props.broadcast; - characteristic->props.indicate = gattc_char->char_props.indicate; - characteristic->props.notify = gattc_char->char_props.notify; - characteristic->props.read = gattc_char->char_props.read; - characteristic->props.write = gattc_char->char_props.write; - characteristic->props.write_no_response = gattc_char->char_props.write_wo_resp; - characteristic->handle = gattc_char->handle_value; - characteristic->service = m_char_discovery_service; - - mp_obj_list_append(m_char_discovery_service->characteristic_list, MP_OBJ_FROM_PTR(characteristic)); - } - - if (response->count > 0) { - m_discovery_successful = true; - } - - const uint32_t err_code = sd_mutex_release(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } -} - -STATIC void on_adv_report(ble_gap_evt_adv_report_t *report, bleio_device_obj_t *device) { - uint32_t err_code; - - if (memcmp(report->peer_addr.addr, device->address.value, BLEIO_ADDRESS_BYTES) != 0) { -#if (BLUETOOTH_SD == 140) - err_code = sd_ble_gap_scan_start(NULL, &m_scan_buffer); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to continue scanning")); - } -#endif - return; - } - - ble_gap_scan_params_t scan_params = { - .active = 1, - .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), - .window = MSEC_TO_UNITS(100, UNIT_0_625_MS), - }; - - ble_gap_addr_t addr; - memset(&addr, 0, sizeof(addr)); - - addr.addr_type = report->peer_addr.addr_type; - memcpy(addr.addr, report->peer_addr.addr, BLEIO_ADDRESS_BYTES); - - ble_gap_conn_params_t conn_params = { - .min_conn_interval = BLE_MIN_CONN_INTERVAL, - .max_conn_interval = BLE_MAX_CONN_INTERVAL, - .conn_sup_timeout = BLE_CONN_SUP_TIMEOUT, - .slave_latency = BLE_SLAVE_LATENCY, - }; - -#if (BLE_API_VERSION == 2) - err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params); -#else - err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params, BLE_CONN_CFG_TAG_CUSTOM); -#endif - - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to connect:")); - } -} - -STATIC void on_ble_evt(ble_evt_t *ble_evt, void *device_in) { - bleio_device_obj_t *device = (bleio_device_obj_t*)device_in; - - switch (ble_evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: - { - ble_gap_conn_params_t conn_params; - device->conn_handle = ble_evt->evt.gap_evt.conn_handle; - - sd_ble_gap_ppcp_get(&conn_params); - sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); - break; - } - - case BLE_GAP_EVT_DISCONNECTED: - device->conn_handle = BLE_CONN_HANDLE_INVALID; - break; - - case BLE_GAP_EVT_ADV_REPORT: - on_adv_report(&ble_evt->evt.gap_evt.params.adv_report, device); - break; - - case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: - on_primary_srv_discovery_rsp(&ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp, device); - break; - - case BLE_GATTC_EVT_CHAR_DISC_RSP: - on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, device); - break; - - case BLE_GATTS_EVT_SYS_ATTR_MISSING: - sd_ble_gatts_sys_attr_set(ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0); - break; - -#if (BLE_API_VERSION == 4) - case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: - sd_ble_gatts_exchange_mtu_reply(device->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); - break; -#endif - - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: - sd_ble_gap_sec_params_reply(device->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); - break; - - case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: - { - ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; - sd_ble_gap_conn_param_update(device->conn_handle, &request->conn_params); - break; - } - } -} - -void common_hal_bleio_device_add_service(bleio_device_obj_t *device, bleio_service_obj_t *service) { - ble_uuid_t uuid; - bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); - - uint8_t service_type = BLE_GATTS_SRVC_TYPE_PRIMARY; - if (service->is_secondary) { - service_type = BLE_GATTS_SRVC_TYPE_SECONDARY; - } - - common_hal_bleio_adapter_set_enabled(true); - - const uint32_t err_code = sd_ble_gatts_service_add(service_type, &uuid, &service->handle); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to add service")); - } - - const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); - for (size_t i = 0; i < characteristic_list->len; ++i) { - bleio_characteristic_obj_t *characteristic = characteristic_list->items[i]; - common_hal_bleio_service_add_characteristic(service, characteristic); - } -} - -void common_hal_bleio_device_start_advertising(bleio_device_obj_t *device, bool connectable, mp_buffer_info_t *raw_data) { - if (connectable) { - ble_drv_add_event_handler(on_ble_evt, device); - } - - const uint32_t err_code = set_advertisement_data(device, connectable, raw_data); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to start advertising")); - } -} - -void common_hal_bleio_device_stop_advertising(bleio_device_obj_t *device) { - uint32_t err_code; - -#if (BLUETOOTH_SD == 140) - if (m_adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) - return; - - err_code = sd_ble_gap_adv_stop(m_adv_handle); -#else - err_code = sd_ble_gap_adv_stop(); -#endif - - if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE)) { - mp_raise_OSError_msg(translate("Failed to stop advertising")); - } -} - -void common_hal_bleio_device_connect(bleio_device_obj_t *device) { - ble_drv_add_event_handler(on_ble_evt, device); - - ble_gap_scan_params_t scan_params = { - .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), - .window = MSEC_TO_UNITS(100, UNIT_0_625_MS), -#if (BLUETOOTH_SD == 140) - .scan_phys = BLE_GAP_PHY_1MBPS, -#endif - }; - - common_hal_bleio_adapter_set_enabled(true); - - uint32_t err_code; -#if (BLUETOOTH_SD == 140) - err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); -#else - err_code = sd_ble_gap_scan_start(&scan_params); -#endif - - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to start scanning")); - } - - while (device->conn_handle == BLE_CONN_HANDLE_INVALID) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - // TODO: read name - - if (m_discovery_mutex == NULL) { - m_discovery_mutex = m_new_ll(nrf_mutex_t, 1); - - err_code = sd_mutex_new(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to create mutex")); - } - } - - // find services - bool found_service = discover_services(device, BLE_GATT_HANDLE_START); - while (found_service) { - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(device->service_list); - const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; - - found_service = discover_services(device, service->end_handle + 1); - } - - // find characteristics in each service - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(device->service_list); - for (size_t i = 0; i < service_list->len; ++i) { - bleio_service_obj_t *service = service_list->items[i]; - - bool found_char = discover_characteristics(device, service, service->start_handle); - while (found_char) { - const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); - const bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_list->len - 1]; - - const uint16_t next_handle = characteristic->handle + 1; - if (next_handle >= service->end_handle) { - break; - } - - found_char = discover_characteristics(device, service, next_handle); - } - } -} - -void common_hal_bleio_device_disconnect(bleio_device_obj_t *device) { - sd_ble_gap_disconnect(device->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); -} diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 36c20373d..69e75ff27 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -3,8 +3,8 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Artur Pacholec * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index 9103fcf94..725bc1431 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -3,8 +3,8 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec - * Copyright (c) 2018 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index 64f7decad..6715bd7a2 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 77d3f0259..55193c5cb 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h index 7998cc862..b5acf39ae 100644 --- a/ports/nrf/common-hal/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/ports/nrf/common-hal/bleio/UUID.c b/ports/nrf/common-hal/bleio/UUID.c index 23e643433..ebd6b6d1f 100644 --- a/ports/nrf/common-hal/bleio/UUID.c +++ b/ports/nrf/common-hal/bleio/UUID.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/UUID.h b/ports/nrf/common-hal/bleio/UUID.h index b464093ea..7d3a6204e 100644 --- a/ports/nrf/common-hal/bleio/UUID.h +++ b/ports/nrf/common-hal/bleio/UUID.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/__init__.c b/ports/nrf/common-hal/bleio/__init__.c index cfb701019..58b81f066 100644 --- a/ports/nrf/common-hal/bleio/__init__.c +++ b/ports/nrf/common-hal/bleio/__init__.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c index 05106d490..538c87f2d 100644 --- a/ports/nrf/common-hal/busio/I2C.c +++ b/ports/nrf/common-hal/busio/I2C.c @@ -3,9 +3,10 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Sandeep Mistry All right reserved. - * Copyright (c) 2017 hathach + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 hathach + * Copyright (c) 2016 Sandeep Mistry All right reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 8881bdc6b..6ab6d9493 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -1,9 +1,11 @@ /* * SPI Master library for nRF5x. - * Copyright (c) 2015 Arduino LLC - * Copyright (c) 2016 Sandeep Mistry All right reserved. - * Copyright (c) 2017 hathach + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 hathach + * Copyright (c) 2016 Sandeep Mistry All right reserved. + * Copyright (c) 2015 Arduino LLC * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index ea864e7ce..7d9463d0b 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2015 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2015 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Adapter.c b/shared-bindings/bleio/Adapter.c index d9449d3ab..7b8df5103 100644 --- a/shared-bindings/bleio/Adapter.c +++ b/shared-bindings/bleio/Adapter.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Adapter.h b/shared-bindings/bleio/Adapter.h index fe3886e59..de9d1d6db 100644 --- a/shared-bindings/bleio/Adapter.h +++ b/shared-bindings/bleio/Adapter.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Address.h b/shared-bindings/bleio/Address.h index 9652a9841..bff1542cf 100644 --- a/shared-bindings/bleio/Address.h +++ b/shared-bindings/bleio/Address.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/AdvertisementData.h b/shared-bindings/bleio/AdvertisementData.h index 05b5a2c8d..3313cde3b 100644 --- a/shared-bindings/bleio/AdvertisementData.h +++ b/shared-bindings/bleio/AdvertisementData.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index e48cfd433..859611f91 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Characteristic.h b/shared-bindings/bleio/Characteristic.h index ffee6bdbc..1938845a9 100644 --- a/shared-bindings/bleio/Characteristic.h +++ b/shared-bindings/bleio/Characteristic.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -27,6 +28,7 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H +#include "shared-module/bleio/Characteristic.h" #include "common-hal/bleio/Characteristic.h" extern const mp_obj_type_t bleio_characteristic_type; diff --git a/shared-bindings/bleio/CharacteristicBuffer.h b/shared-bindings/bleio/CharacteristicBuffer.h index f25017c19..b45835ff3 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.h +++ b/shared-bindings/bleio/CharacteristicBuffer.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index b32f4f08e..9e051c89e 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Descriptor.h b/shared-bindings/bleio/Descriptor.h index f47378ee1..f4634d393 100644 --- a/shared-bindings/bleio/Descriptor.h +++ b/shared-bindings/bleio/Descriptor.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Device.c b/shared-bindings/bleio/Device.c deleted file mode 100644 index fcdc84d27..000000000 --- a/shared-bindings/bleio/Device.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include - -#include "ble_drv.h" -#include "py/objarray.h" -#include "py/objproperty.h" -#include "py/objstr.h" -#include "py/runtime.h" -#include "shared-bindings/bleio/Adapter.h" -#include "shared-bindings/bleio/AddressType.h" -#include "shared-bindings/bleio/Characteristic.h" -#include "shared-bindings/bleio/Device.h" -#include "shared-bindings/bleio/Service.h" -#include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/Device.h" -#include "shared-module/bleio/ScanEntry.h" - -// Work-in-progress: orphaned for now. -//| :orphan: -//| -//| .. currentmodule:: bleio -//| -//| :class:`Device` -- BLE device -//| ========================================================= -//| -//| **IGNORE ``Device`` and all its documentation. -//| It is being replaced by `Peripheral` and other classes.** -//| -//| Provides access a to BLE device, either in a Peripheral or Central role. -//| When a device is created without any parameter passed to the constructor, -//| it will be set to the Peripheral role. If a address is passed, the device -//| will be a Central. For a Peripheral you can set the `name`, add services -//| via `add_service` and then start and stop advertising via `bleio.Device.start_advertising` -//| and `bleio.Device.stop_advertising`. For the Central, you can `bleio.Device.connect` and `bleio.Device.disconnect` -//| to the device, once a connection is established, the device's services can -//| be accessed using `bleio.Device.services`. -//| -//| Usage:: -//| -//| import bleio -//| -//| # Peripheral -//| periph = bleio.Device() -//| -//| serv = bleio.Service(bleio.UUID(0x180f)) -//| p.add_service(serv) -//| -//| chara = bleio.Characteristic(bleio.UUID(0x2919)) -//| chara.read = True -//| chara.notify = True -//| serv.add_characteristic(chara) -//| -//| periph.start_advertising() -//| -//| # Central -//| scanner = bleio.Scanner() -//| entries = scanner.scan(2500) -//| -//| my_entry = None -//| for entry in entries: -//| if entry.name is not None and entry.name == 'MyDevice': -//| my_entry = entry -//| break -//| -//| central = bleio.Device(my_entry.address) -//| central.connect() -//| - -//| .. class:: Device(address=None, scan_entry=None) -//| -//| Create a new Device object. If the `address` or :py:data:`scan_entry` parameters are not `None`, -//| the role is set to Central, otherwise it's set to Peripheral. -//| -//| :param bleio.Address address: The address of the device to connect to -//| :param bleio.ScanEntry scan_entry: The scan entry returned from `bleio.Scanner` -//| - -//| .. attribute:: name -//| -//| For the Peripheral role, this property can be used to read and write the device's name. -//| For the Central role, this property will equal the name of the remote device, if one was -//| advertised by the device. In the Central role this property is read-only. -//| - -//| .. attribute:: services -//| -//| A `list` of `bleio.Service` that are offered by this device. (read-only) -//| For a Peripheral device, this list will contain services added using `add_service`, -//| for a Central, this list will be empty until a connection is established, at which point -//| it will be filled with the remote device's services. -//| - -//| .. method:: add_service(service) -//| -//| Appends the :py:data:`service` to the list of this devices's services. -//| This method can only be called for Peripheral devices. -//| -//| :param bleio.Service service: the service to append -//| - -//| .. method:: connect() -//| -//| Attempts a connection to the remote device. If the connection is successful, -//| the device's services are available via `services`. -//| This method can only be called for Central devices. -//| - -//| .. method:: disconnect() -//| -//| Disconnects from the remote device. -//| This method can only be called for Central devices. -//| - -//| .. method:: start_advertising(connectable=True) -//| -//| Starts advertising the device. The device's name and -//| services are put into the advertisement packets. -//| If :py:data:`connectable` is `True` then other devices are allowed to conncet to this device. -//| This method can only be called for Peripheral devices. -//| - -//| .. method:: stop_advertising() -//| -//| Disconnects from the remote device. -//| This method can only be called for Peripheral devices. -//| - -// TODO: Add unique MAC address part to name -static const char default_name[] = "CIRCUITPY"; - -STATIC void bleio_device_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - mp_printf(print, "Device(role: %s)", self->is_peripheral ? "Peripheral" : "Central"); -} - -STATIC mp_obj_t bleio_device_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 0, 1, true); - bleio_device_obj_t *self = m_new_obj(bleio_device_obj_t); - self->base.type = &bleio_device_type; - self->service_list = mp_obj_new_list(0, NULL); - self->notif_handler = mp_const_none; - self->conn_handler = mp_const_none; - self->conn_handle = 0xFFFF; - self->is_peripheral = true; - - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); - - enum { ARG_address, ARG_scan_entry }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_address, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_scan_entry, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - const mp_obj_t address_obj = args[ARG_address].u_obj; - const mp_obj_t scan_entry_obj = args[ARG_scan_entry].u_obj; - - if (address_obj != mp_const_none) { - bleio_address_obj_t *address = MP_OBJ_TO_PTR(address_obj); - - self->is_peripheral = false; - self->address.type = address->type; - memcpy(self->address.value, address->value, BLEIO_ADDRESS_BYTES); - } else if (scan_entry_obj != mp_const_none) { - bleio_scanentry_obj_t *scan_entry = MP_OBJ_TO_PTR(scan_entry_obj); - - self->is_peripheral = false; - self->address.type = scan_entry->address.type; - memcpy(self->address.value, scan_entry->address.value, BLEIO_ADDRESS_BYTES); - } else { - self->name = mp_obj_new_str(default_name, strlen(default_name)); - common_hal_bleio_adapter_get_address(&self->address); - } - - return MP_OBJ_FROM_PTR(self); -} - -STATIC mp_obj_t bleio_device_add_service(mp_obj_t self_in, mp_obj_t service_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_in); - - if (!self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't add services in Central mode"))); - } - - service->device = self; - - mp_obj_list_append(self->service_list, service); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_device_add_service_obj, bleio_device_add_service); - -STATIC mp_obj_t bleio_device_connect(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't connect in Peripheral mode"))); - } - - common_hal_bleio_device_connect(self); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_connect_obj, bleio_device_connect); - -STATIC mp_obj_t bleio_device_disconnect(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - common_hal_bleio_device_disconnect(self); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_disconnect_obj, bleio_device_disconnect); - -STATIC mp_obj_t bleio_device_get_name(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return self->name; -} -MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_get_name_obj, bleio_device_get_name); - -static mp_obj_t bleio_device_set_name(mp_obj_t self_in, mp_obj_t value) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (!self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't change the name in Central mode"))); - } - - self->name = value; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_device_set_name_obj, bleio_device_set_name); - -const mp_obj_property_t bleio_device_name_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_device_get_name_obj, - (mp_obj_t)&bleio_device_set_name_obj, - (mp_obj_t)&mp_const_none_obj }, -}; - -STATIC mp_obj_t bleio_device_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - - if (!self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't advertise in Central mode"))); - } - - enum { ARG_connectable, ARG_data }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_connectable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, - { MP_QSTR_data, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_buffer_info_t bufinfo = { 0 }; - if (args[ARG_data].u_obj != mp_const_none) { - mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ); - } - - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); - for (size_t i = 0; i < service_list->len; ++i) { - bleio_service_obj_t *service = service_list->items[i]; - if (service->handle == 0xFFFF) { - common_hal_bleio_device_add_service(self, service); - } - } - - common_hal_bleio_device_start_advertising(self, args[ARG_connectable].u_bool, &bufinfo); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_device_start_advertising_obj, 0, bleio_device_start_advertising); - -STATIC mp_obj_t bleio_device_stop_advertising(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (!self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't advertise in Central mode"))); - } - - common_hal_bleio_device_stop_advertising(self); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_stop_advertising_obj, bleio_device_stop_advertising); - -STATIC mp_obj_t bleio_device_get_services(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return self->service_list; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_get_services_obj, bleio_device_get_services); - -const mp_obj_property_t bleio_device_services_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_device_get_services_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj }, -}; - -STATIC const mp_rom_map_elem_t bleio_device_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR_add_service), MP_ROM_PTR(&bleio_device_add_service_obj) }, - { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&bleio_device_connect_obj) }, - { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_device_disconnect_obj) }, - { MP_ROM_QSTR(MP_QSTR_start_advertising), MP_ROM_PTR(&bleio_device_start_advertising_obj) }, - { MP_ROM_QSTR(MP_QSTR_stop_advertising), MP_ROM_PTR(&bleio_device_stop_advertising_obj) }, - - // Properties - { MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&bleio_device_name_obj) }, - { MP_ROM_QSTR(MP_QSTR_services), MP_ROM_PTR(&bleio_device_services_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(bleio_device_locals_dict, bleio_device_locals_dict_table); - -const mp_obj_type_t bleio_device_type = { - { &mp_type_type }, - .name = MP_QSTR_Device, - .print = bleio_device_print, - .make_new = bleio_device_make_new, - .locals_dict = (mp_obj_dict_t*)&bleio_device_locals_dict -}; diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h index e452a8ad6..d19b8c886 100644 --- a/shared-bindings/bleio/Device.h +++ b/shared-bindings/bleio/Device.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 5397f4c3a..e270c599c 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index 6468325c2..16438bba6 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -3,8 +3,8 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec - * Copyright (c) 2018 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/ScanEntry.h b/shared-bindings/bleio/ScanEntry.h index c1b52e6b4..3a02f2fac 100644 --- a/shared-bindings/bleio/ScanEntry.h +++ b/shared-bindings/bleio/ScanEntry.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * Copyright (c) 2017 Glenn Ruben Bakke * diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index 352ef8d6a..2719164d8 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Service.h b/shared-bindings/bleio/Service.h index 27d79f953..6693cc3bb 100644 --- a/shared-bindings/bleio/Service.h +++ b/shared-bindings/bleio/Service.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -27,12 +28,11 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H -#include "shared-module/bleio/Characteristic.h" #include "common-hal/bleio/Service.h" const mp_obj_type_t bleio_service_type; -extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *char_list, bool is_secondary); +extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *characteristic_list, bool is_secondary); extern bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self); extern mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self); extern bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self); diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index f79dfa675..972505058 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -3,9 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec - * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/UUID.h b/shared-bindings/bleio/UUID.h index aef2c1e29..caf039aec 100644 --- a/shared-bindings/bleio/UUID.h +++ b/shared-bindings/bleio/UUID.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 06c00d588..ca45a846e 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -53,11 +54,10 @@ //| Address //| AdvertisementData //| Adapter +//| Central //| Characteristic //| CharacteristicBuffer -// Work-in-progress classes are omitted, and marked as :orphan: in their files. // Descriptor -// Device //| Peripheral //| ScanEntry //| Scanner @@ -74,6 +74,7 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) }, { MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) }, +// { MP_ROM_QSTR(MP_QSTR_Central), MP_ROM_PTR(&bleio_central_type) }, { MP_ROM_QSTR(MP_QSTR_Characteristic), MP_ROM_PTR(&bleio_characteristic_type) }, { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) }, // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, diff --git a/shared-bindings/bleio/__init__.h b/shared-bindings/bleio/__init__.h index 1f4e0a66f..4aa6dd45b 100644 --- a/shared-bindings/bleio/__init__.h +++ b/shared-bindings/bleio/__init__.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h index f66e97d64..eb1aab258 100644 --- a/shared-module/bleio/Address.h +++ b/shared-module/bleio/Address.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-module/bleio/AdvertisementData.h b/shared-module/bleio/AdvertisementData.h index 66855172a..89cdfb070 100644 --- a/shared-module/bleio/AdvertisementData.h +++ b/shared-module/bleio/AdvertisementData.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h deleted file mode 100644 index 3132fd47b..000000000 --- a/shared-module/bleio/Characteristic.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H - -// Flags for each characteristic property. Common across ports. -typedef struct { - bool broadcast : 1; - bool read : 1; - bool write_no_response : 1; - bool write : 1; - bool notify : 1; - bool indicate : 1; -} bleio_characteristic_properties_t; - -// bleio_characteristic_obj_t is defined in ports/*/common-hal. - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H diff --git a/shared-module/bleio/Device.h b/shared-module/bleio/Device.h deleted file mode 100644 index 8d9ece5ef..000000000 --- a/shared-module/bleio/Device.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H - -#include - -#include "shared-module/bleio/Address.h" - -typedef struct { - mp_obj_base_t base; - bool is_peripheral; - mp_obj_t name; - bleio_address_obj_t address; - volatile uint16_t conn_handle; - mp_obj_t service_list; - mp_obj_t notif_handler; - mp_obj_t conn_handler; -} bleio_device_obj_t; - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h index 40e02f9fa..4e7028ba2 100644 --- a/shared-module/bleio/ScanEntry.h +++ b/shared-module/bleio/ScanEntry.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy -- cgit v1.2.3 From 24ac1fdcabdcdb02f9807192d3cb2a4210b4afc8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 19 Jun 2019 21:54:28 -0400 Subject: WIP: backup only; not compiled --- ports/nrf/bluetooth/ble_drv.h | 2 + ports/nrf/common-hal/bleio/Central.c | 312 ++++++++++++++++++++++++++++ ports/nrf/common-hal/bleio/Central.h | 45 ++++ ports/nrf/common-hal/bleio/Characteristic.c | 86 +++----- ports/nrf/common-hal/bleio/Service.h | 2 + ports/nrf/common-hal/bleio/__init__.c | 10 +- py/circuitpy_defns.mk | 1 + shared-bindings/bleio/Central.c | 186 +++++++++++++++++ shared-bindings/bleio/Central.h | 39 ++++ shared-module/bleio/Characteristic.h | 40 ++++ 10 files changed, 663 insertions(+), 60 deletions(-) create mode 100644 ports/nrf/common-hal/bleio/Central.c create mode 100644 ports/nrf/common-hal/bleio/Central.h create mode 100644 shared-bindings/bleio/Central.c create mode 100644 shared-bindings/bleio/Central.h create mode 100644 shared-module/bleio/Characteristic.h (limited to 'shared-bindings') diff --git a/ports/nrf/bluetooth/ble_drv.h b/ports/nrf/bluetooth/ble_drv.h index d349fa4e0..a066f588f 100644 --- a/ports/nrf/bluetooth/ble_drv.h +++ b/ports/nrf/bluetooth/ble_drv.h @@ -43,7 +43,9 @@ #define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION)) // 0.625 msecs (625 usecs) #define ADV_INTERVAL_UNIT_FLOAT_SECS (0.000625) +// Microseconds is the base unit. The macros above know that. #define UNIT_0_625_MS (625) +#define UNIT_1_25_MS (1250) #define UNIT_10_MS (10000) typedef void (*ble_drv_evt_handler_t)(ble_evt_t*, void*); diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c new file mode 100644 index 000000000..af5a56b76 --- /dev/null +++ b/ports/nrf/common-hal/bleio/Central.c @@ -0,0 +1,312 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +#include "ble.h" +#include "ble_drv.h" +#include "ble_hci.h" +#include "nrf_soc.h" +#include "py/objstr.h" +#include "py/runtime.h" +#include "shared-bindings/bleio/Adapter.h" +#include "shared-bindings/bleio/Characteristic.h" +#include "shared-bindings/bleio/Central.h" +#include "shared-bindings/bleio/Service.h" +#include "shared-bindings/bleio/UUID.h" + +static bleio_service_obj_t *m_char_discovery_service; +static volatile bool m_discovery_successful; + +STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_handle) { + m_discovery_successful = false; + + uint32_t err_code = sd_ble_gattc_primary_services_discover(self->conn_handle, start_handle, NULL); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to discover services")); + } + + // Serialize discovery. + err_code = sd_mutex_acquire(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to acquire mutex")); + } + + // Wait for someone else to release m_discovery_mutex. + while (sd_mutex_acquire(&m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { +#ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP +#endif + } + + err_code = sd_mutex_release(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to release mutex")); + } + + return m_discovery_successful; +} + +STATIC bool discover_next_characteristics(bleio_central_obj_t *self, bleio_service_obj_t *service, uint16_t start_handle) { + m_char_discovery_service = service; + + ble_gattc_handle_range_t handle_range; + handle_range.start_handle = start_handle; + handle_range.end_handle = service->end_handle; + + m_discovery_successful = false; + + uint32_t err_code = sd_ble_gattc_characteristics_discover(self->conn_handle, &handle_range); + if (err_code != NRF_SUCCESS) { + return false; + } + + err_code = sd_mutex_acquire(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to acquire mutex")); + } + + while (sd_mutex_acquire(&m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { + MICROPY_VM_HOOK_LOOP; + } + + err_code = sd_mutex_release(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to release mutex")); + } + + return m_discovery_successful; +} + +STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *response, bleio_central_obj_t *central) { + for (size_t i = 0; i < response->count; ++i) { + ble_gattc_service_t *gattc_service = &response->services[i]; + + bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); + service->base.type = &bleio_service_type; + service->device = central; + service->characteristic_list = mp_obj_new_list(0, NULL); + service->start_handle = gattc_service->handle_range.start_handle; + service->end_handle = gattc_service->handle_range.end_handle; + service->handle = gattc_service->handle_range.start_handle; + + bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid); + service->uuid = uuid; + + mp_obj_list_append(central->service_list, service); + } + + if (response->count > 0) { + m_discovery_successful = true; + } + + const uint32_t err_code = sd_mutex_release(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to release mutex")); + } +} + +STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio_central_obj_t *central) { + for (size_t i = 0; i < response->count; ++i) { + ble_gattc_char_t *gattc_char = &response->chars[i]; + + bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); + characteristic->base.type = &bleio_characteristic_type; + + bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + uuid->base.type = &bleio_uuid_type; + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); + characteristic->uuid = uuid; + + characteristic->props.broadcast = gattc_char->char_props.broadcast; + characteristic->props.indicate = gattc_char->char_props.indicate; + characteristic->props.notify = gattc_char->char_props.notify; + characteristic->props.read = gattc_char->char_props.read; + characteristic->props.write = gattc_char->char_props.write; + characteristic->props.write_no_response = gattc_char->char_props.write_wo_resp; + characteristic->handle = gattc_char->handle_value; + characteristic->service = m_char_discovery_service; + + mp_obj_list_append(m_char_discovery_service->characteristic_list, MP_OBJ_FROM_PTR(characteristic)); + } + + if (response->count > 0) { + m_discovery_successful = true; + } + + const uint32_t err_code = sd_mutex_release(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to release mutex")); + } +} + +STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { + bleio_central_obj_t *central = (bleio_central_obj_t*)central_in; + + switch (ble_evt->header.evt_id) { + case BLE_GAP_EVT_CONNECTED: + { + ble_gap_conn_params_t conn_params; + central->conn_handle = ble_evt->evt.gap_evt.conn_handle; + + sd_ble_gap_ppcp_get(&conn_params); + sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); + break; + } + + case BLE_GAP_EVT_TIMEOUT: + if (central->attempting_to_connect) { + // Signal that connection attempt has timed out. + central->attempting_to_connect = false; + } + break; + + case BLE_GAP_EVT_DISCONNECTED: + central->conn_handle = BLE_CONN_HANDLE_INVALID; + break; + + case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: + on_primary_srv_discovery_rsp(&ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp, central); + break; + + case BLE_GATTC_EVT_CHAR_DISC_RSP: + on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); + break; + + case BLE_GATTS_EVT_SYS_ATTR_MISSING: + sd_ble_gatts_sys_attr_set(ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0); + break; + + case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: + sd_ble_gatts_exchange_mtu_reply(central->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); + break; + + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); + break; + + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: + { + ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; + sd_ble_gap_conn_param_update(central->conn_handle, &request->conn_params); + break; + } + } +} + +void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout) { + common_hal_bleio_adapter_set_enabled(true); + ble_drv_add_event_handler(on_ble_evt, self); + + ble_gap_scan_params_t scan_params = { + .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), + .window = MSEC_TO_UNITS(100, UNIT_0_625_MS), + .scan_phys = BLE_GAP_PHY_1MBPS, + // timeout of 0 means no timeout + .timeout = SEC_TO_UNITS(timeout, UNIT_10_MS), + }; + + ble_gap_conn_params_t conn_params = { + .conn_sup_timeout = MSEC_TO_UNITS(4000, UNIT_10_MS), + .min_conn_interval = MSEC_TO_UNITS(15, UNIT_1_25_MS), + .max_conn_interval = MSEC_TO_UNITS(300, UNIT_1_25_MS), + .slave_latency = 0, // number of conn events + }; + + self->attempting_to_connect = true; + + uint32_t err_code = sd_ble_gap_connect(&scan_params, &m_scan_buffer); + + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg_varg(translate("Failed to start connecting, error 0x%04x"), err_code); + } + + while (self->conn_handle == BLE_CONN_HANDLE_INVALID && self->attempting_to_connect) { + #ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP + #endif + } + + if (!self->attempting_to_connect) { + mp_raise_OSError_msg(translate("Failed to connect: timeout")); + } + + // Conenction successful. + // Now discover all services on the remote peripheral. Ask for services repeatedly + // until no more are left. + + uint16_t next_start_handle; + + next_start_handle = BLE_GATT_HANDLE_START; + + while (1) { + if(!discover_next_services(self, discovery_start_handle)) { + break; + } + + // discover_next_services() appends to service_list. + const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + + // Get the most recently discovered service, and ask for services with handles + // starting after the last attribute handle of t + const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; + next_start_handle = service->end_handle + 1; + } + + // Now, for each service, discover its characteristics. + // find characteristics in each service + const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + for (size_t i = 0; i < service_list->len; ++i) { + bleio_service_obj_t *service = service_list->items[i]; + + next_start_handle = service->start_handle; + + while (1) { + if (!discover_next_characteristics(self, service, service->start_handle)) { + break; + } + + // discover_next_characteristics() appends to the characteristic_list. + const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); + + // Get the most recently discovered characteristic. + const bleio_characteristic_obj_t *characteristic = + characteristic_list->items[characteristic_list->len - 1]; + next_start_handle = characteristic->handle + 1; + if (next_start_handle >= service->end_handle) { + // Went past the end of the range of handles for this service. + break; + } + } + } +} + +void common_hal_bleio_central_disconnect(bleio_central_obj_t *self) { + sd_ble_gap_disconnect(self->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); +} diff --git a/ports/nrf/common-hal/bleio/Central.h b/ports/nrf/common-hal/bleio/Central.h new file mode 100644 index 000000000..c44cf3b77 --- /dev/null +++ b/ports/nrf/common-hal/bleio/Central.h @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H +#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H + +#include + +#include "shared-module/bleio/Address.h" + +typedef struct { + mp_obj_base_t base; + mp_obj_t remote_name; + bleio_address_obj_t address; + volatile bool attempting_to_connect; + volatile uint16_t conn_handle; + mp_obj_t service_list; + mp_obj_t conn_handler; +} bleio_central_obj_t; + +#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 346cfefbc..70ebd7aba 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -37,9 +37,6 @@ #include "common-hal/bleio/Characteristic.h" STATIC volatile bleio_characteristic_obj_t *m_read_characteristic; -STATIC volatile uint8_t m_tx_in_progress; -// Serialize gattc writes that send a response. This might be done per object? -STATIC nrf_mutex_t *m_write_mutex; STATIC uint16_t get_cccd(bleio_characteristic_obj_t *characteristic) { const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); @@ -118,17 +115,21 @@ STATIC void gatts_notify_indicate(bleio_characteristic_obj_t *characteristic, mp .p_data = bufinfo->buf, }; - while (m_tx_in_progress >= MAX_TX_IN_PROGRESS) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); - m_tx_in_progress++; - const uint32_t err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params); - if (err_code != NRF_SUCCESS) { - m_tx_in_progress--; + + while (1) { + const uint32_t err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params); + if (err_code == NRF_SUCCESS) { + break; + } + // TX buffer is full + // We could wait for an event indicating the write is complete, but just retrying is easier. + if (err_code == NRF_ERROR_RESOURCES) { + MICROPY_VM_HOOK_LOOP; + continue; + } + + // Some real error has occurred. mp_raise_OSError_msg_varg(translate("Failed to notify or indicate attribute value, err 0x%04x"), err_code); } @@ -144,11 +145,8 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) { mp_raise_OSError_msg_varg(translate("Failed to read attribute value, err 0x%04x"), err_code); } -// while (m_read_characteristic != NULL) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif + MICROPY_VM_HOOK_LOOP; } } @@ -158,67 +156,47 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in ble_gattc_write_params_t write_params = { .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL, - .write_op = BLE_GATT_OP_WRITE_REQ, + .write_op = characteristic->props.write_no_response ? BLE_GATT_OP_WRITE_CMD : BLE_GATT_OP_WRITE_REQ, .handle = characteristic->handle, .p_value = bufinfo->buf, .len = bufinfo->len, }; - if (characteristic->props.write_no_response) { - write_params.write_op = BLE_GATT_OP_WRITE_CMD; + while (1) { + uint32 err_code = sd_ble_gattc_write(conn_handle, &write_params); + if (err_code == NRF_SUCCESS) { + break; + } - err_code = sd_mutex_acquire(m_write_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg_varg(translate("Failed to acquire mutex, err 0x%04x"), err_code); + // Write with response will return NRF_ERROR_BUSY if the response has not been received. + // Write without reponse will return NRF_ERROR_RESOURCES if too many writes are pending. + if (err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_RESOURCES) { + // We could wait for an event indicating the write is complete, but just retrying is easier. + MICROPY_VM_HOOK_LOOP; + continue; } - } - err_code = sd_ble_gattc_write(conn_handle, &write_params); - if (err_code != NRF_SUCCESS) { + // Some real error occurred. mp_raise_OSError_msg_varg(translate("Failed to write attribute value, err 0x%04x"), err_code); } - while (sd_mutex_acquire(m_write_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - err_code = sd_mutex_release(m_write_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg_varg(translate("Failed to release mutex, err 0x%04x"), err_code); - } } STATIC void characteristic_on_ble_evt(ble_evt_t *ble_evt, void *param) { switch (ble_evt->header.evt_id) { - case BLE_GATTS_EVT_HVN_TX_COMPLETE: - { - uint8_t count = ble_evt->evt.gatts_evt.params.hvn_tx_complete.count; - // Don't underflow the count. - if (count >= m_tx_in_progress) { - m_tx_in_progress = 0; - } else { - m_tx_in_progress -= count; - } - break; - } + + // More events may be handled later, so keep this as a switch. case BLE_GATTC_EVT_READ_RSP: { ble_gattc_evt_read_rsp_t *response = &ble_evt->evt.gattc_evt.params.read_rsp; m_read_characteristic->value_data = mp_obj_new_bytearray(response->len, response->data); - // Flag to busy-wait loop that we've read the characteristic. + // Indicate to busy-wait loop that we've read the characteristic. m_read_characteristic = NULL; break; } - case BLE_GATTC_EVT_WRITE_RSP: - // Someone else can write now. - sd_mutex_release(m_write_mutex); - break; - - // For debugging. + // For debugging. default: // mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id); break; diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h index b5acf39ae..dc794ff28 100644 --- a/ports/nrf/common-hal/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -32,12 +32,14 @@ typedef struct { mp_obj_base_t base; + // Handle for this service. uint16_t handle; bool is_secondary; bleio_uuid_obj_t *uuid; // May be a Peripheral, Central, etc. mp_obj_t *device; mp_obj_t characteristic_list; + // Range of attribute handles of this service. uint16_t start_handle; uint16_t end_handle; } bleio_service_obj_t; diff --git a/ports/nrf/common-hal/bleio/__init__.c b/ports/nrf/common-hal/bleio/__init__.c index 58b81f066..699dcc57f 100644 --- a/ports/nrf/common-hal/bleio/__init__.c +++ b/ports/nrf/common-hal/bleio/__init__.c @@ -49,9 +49,8 @@ const super_adapter_obj_t common_hal_bleio_adapter_obj = { gatt_role_t common_hal_bleio_device_get_gatt_role(mp_obj_t device) { if (MP_OBJ_IS_TYPE(device, &bleio_peripheral_type)) { return ((bleio_peripheral_obj_t*) MP_OBJ_TO_PTR(device))->gatt_role; -// Does not exist yet. -// } else if (MP_OBJ_IS_TYPE(device, &bleio_central_type)) { -// return ((bleio_central_obj_t*) MP_OBJ_TO_PTR(device))->gatt_role; + } else if (MP_OBJ_IS_TYPE(device, &bleio_central_type)) { + return ((bleio_central_obj_t*) MP_OBJ_TO_PTR(device))->gatt_role; } else { return GATT_ROLE_NONE; } @@ -60,9 +59,8 @@ gatt_role_t common_hal_bleio_device_get_gatt_role(mp_obj_t device) { uint16_t common_hal_bleio_device_get_conn_handle(mp_obj_t device) { if (MP_OBJ_IS_TYPE(device, &bleio_peripheral_type)) { return ((bleio_peripheral_obj_t*) MP_OBJ_TO_PTR(device))->conn_handle; -// Does not exist yet. -// } else if (MP_OBJ_IS_TYPE(device, &bleio_central_type)) { -// return ((bleio_central_obj_t*) MP_OBJ_TO_PTR(device))->conn_handle; + } else if (MP_OBJ_IS_TYPE(device, &bleio_central_type)) { + return ((bleio_central_obj_t*) MP_OBJ_TO_PTR(device))->conn_handle; } else { return 0; } diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 435cf2c33..782314fc7 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -224,6 +224,7 @@ $(filter $(SRC_PATTERNS), \ audioio/AudioOut.c \ bleio/__init__.c \ bleio/Adapter.c \ + bleio/Central.c \ bleio/Characteristic.c \ bleio/CharacteristicBuffer.c \ bleio/Descriptor.c \ diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c new file mode 100644 index 000000000..e5fd66348 --- /dev/null +++ b/shared-bindings/bleio/Central.c @@ -0,0 +1,186 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +#include "ble_drv.h" +#include "py/objarray.h" +#include "py/objproperty.h" +#include "py/objstr.h" +#include "py/runtime.h" +#include "shared-bindings/bleio/Adapter.h" +#include "shared-bindings/bleio/AddressType.h" +#include "shared-bindings/bleio/Characteristic.h" +#include "shared-bindings/bleio/Central.h" +#include "shared-bindings/bleio/Service.h" +#include "shared-bindings/bleio/UUID.h" + +//| .. currentmodule:: bleio +//| +//| :class:`Central` -- A BLE central device +//| ========================================================= +//| +//| Implement a BLE central, which runs locally. Can connect to a given address. +//| +//| Usage:: +//| +//| import bleio +//| +//| scanner = bleio.Scanner() +//| entries = scanner.scan(2.5) +//| +//| my_entry = None +//| for entry in entries: +//| if entry.name is not None and entry.name == 'MyCentral': +//| my_entry = entry +//| break +//| +//| central = bleio.Central(my_entry.address) +//| central.connect() +//| + +//| .. class:: Central(address=None, scan_entry=None) +//| +//| Create a new Central object. If the `address` or :py:data:`scan_entry` parameters are not `None`, +//| the role is set to Central, otherwise it's set to Peripheral. +//| +//| :param bleio.Address address: The address of the central to connect to +//| :param bleio.ScanEntry scan_entry: The scan entry returned from `bleio.Scanner` +//| +STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { + mp_arg_check_num(n_args, n_kw, 0, 1, true); + bleio_central_obj_t *self = m_new_obj(bleio_central_obj_t); + self->base.type = &bleio_central_type; + self->service_list = mp_obj_new_list(0, NULL); + self->conn_handler = mp_const_none; + self->conn_handle = 0xFFFF; + + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); + + enum { ARG_address, ARG_scan_entry }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_address, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_scan_entry, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + const mp_obj_t address_obj = args[ARG_address].u_obj; + const mp_obj_t scan_entry_obj = args[ARG_scan_entry].u_obj; + + if (!MP_OBJ_IS_TYPE(address_obj, &bleio_address_type)) { + mp_raise_ValueError("Expected an Address"); + } + + return MP_OBJ_FROM_PTR(self); +} + + + +//| .. method:: connect() +//| +//| Attempts a connection to the remote peripheral. If the connection is successful, +//| +STATIC mp_obj_t bleio_central_connect(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + if (self->is_peripheral) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, + translate("Can't connect in Peripheral mode"))); + } + + common_hal_bleio_central_connect(self); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_connect_obj, bleio_central_connect); + + +//| .. method:: disconnect() +//| +//| Disconnects from the remote peripheral. +//| +STATIC mp_obj_t bleio_central_disconnect(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + common_hal_bleio_central_disconnect(self); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_disconnect_obj, bleio_central_disconnect); + +//| .. attribute:: remote_name (read-only) +//| +//| The name of the remote peripheral, if connected. May be None if no name was advertised. +//| +STATIC mp_obj_t bleio_central_get_remote_name(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return self->remote_name; +} +MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_name_obj, bleio_central_get_remote_name); + +//| .. attribute:: remote_services (read-only) +//| +//| Empty until connected, then a list of services provided by the remote peripheral. +//| +STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return self->service_list; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); + +const mp_obj_property_t bleio_central_remote_services_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_central_get_remote_services_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + +STATIC const mp_rom_map_elem_t bleio_central_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&bleio_central_connect_obj) }, + { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_central_disconnect_obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_remote_name), MP_ROM_PTR(&bleio_central_remote_name_obj) }, + { MP_ROM_QSTR(MP_QSTR_remote_services), MP_ROM_PTR(&bleio_central_remote_services_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(bleio_central_locals_dict, bleio_central_locals_dict_table); + +const mp_obj_type_t bleio_central_type = { + { &mp_type_type }, + .name = MP_QSTR_Central, + .make_new = bleio_central_make_new, + .locals_dict = (mp_obj_dict_t*)&bleio_central_locals_dict +}; diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h new file mode 100644 index 000000000..5ea2119af --- /dev/null +++ b/shared-bindings/bleio/Central.h @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H + +#include "common-hal/bleio/Central.h" +#include "common-hal/bleio/Service.h" + +extern const mp_obj_type_t bleio_device_type; + +extern void common_hal_bleio_device_connect(bleio_device_obj_t *device); +extern void common_hal_bleio_device_disconnect(bleio_device_obj_t *device); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h new file mode 100644 index 000000000..27b43588f --- /dev/null +++ b/shared-module/bleio/Characteristic.h @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H +#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H + +// Flags for each characteristic property. Common across ports. +typedef struct { + bool broadcast : 1; + bool read : 1; + bool write_no_response : 1; + bool write : 1; + bool notify : 1; + bool indicate : 1; +} bleio_characteristic_properties_t; + +#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H -- cgit v1.2.3 From 4881e1ff55768c027404cc6a1375c43d4c3acf2a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 21 Jun 2019 18:04:04 -0400 Subject: WIP: Central compiles; now will test --- ports/nrf/common-hal/bleio/Central.c | 73 ++++++++++++---------------- ports/nrf/common-hal/bleio/Central.h | 4 +- ports/nrf/common-hal/bleio/Characteristic.c | 3 +- ports/nrf/common-hal/bleio/Service.h | 2 +- ports/nrf/common-hal/bleio/__init__.c | 1 + shared-bindings/bleio/Central.c | 67 +++++++------------------ shared-bindings/bleio/Central.h | 8 +-- shared-bindings/bleio/Characteristic.c | 8 +-- shared-bindings/bleio/CharacteristicBuffer.c | 2 +- shared-bindings/bleio/Device.h | 42 ---------------- shared-bindings/bleio/Peripheral.c | 6 +-- shared-bindings/bleio/Service.c | 24 ++++----- 12 files changed, 78 insertions(+), 162 deletions(-) delete mode 100644 shared-bindings/bleio/Device.h (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index af5a56b76..5864a8a56 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -41,34 +41,22 @@ #include "shared-bindings/bleio/UUID.h" static bleio_service_obj_t *m_char_discovery_service; +static volatile bool m_discovery_in_process; static volatile bool m_discovery_successful; STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_handle) { m_discovery_successful = false; + m_discovery_in_process = true; uint32_t err_code = sd_ble_gattc_primary_services_discover(self->conn_handle, start_handle, NULL); if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg(translate("Failed to discover services")); } - // Serialize discovery. - err_code = sd_mutex_acquire(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to acquire mutex")); - } - - // Wait for someone else to release m_discovery_mutex. - while (sd_mutex_acquire(&m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - err_code = sd_mutex_release(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); + // Wait for a discovery event. + while (m_discovery_in_process) { + MICROPY_VM_HOOK_LOOP; } - return m_discovery_successful; } @@ -80,26 +68,17 @@ STATIC bool discover_next_characteristics(bleio_central_obj_t *self, bleio_servi handle_range.end_handle = service->end_handle; m_discovery_successful = false; + m_discovery_in_process = true; uint32_t err_code = sd_ble_gattc_characteristics_discover(self->conn_handle, &handle_range); if (err_code != NRF_SUCCESS) { return false; } - err_code = sd_mutex_acquire(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to acquire mutex")); - } - - while (sd_mutex_acquire(&m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { + // Wait for a discovery event. + while (m_discovery_in_process) { MICROPY_VM_HOOK_LOOP; } - - err_code = sd_mutex_release(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } - return m_discovery_successful; } @@ -109,7 +88,7 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); service->base.type = &bleio_service_type; - service->device = central; + service->device = MP_OBJ_FROM_PTR(central); service->characteristic_list = mp_obj_new_list(0, NULL); service->start_handle = gattc_service->handle_range.start_handle; service->end_handle = gattc_service->handle_range.end_handle; @@ -125,11 +104,7 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res if (response->count > 0) { m_discovery_successful = true; } - - const uint32_t err_code = sd_mutex_release(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } + m_discovery_in_process = false; } STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio_central_obj_t *central) { @@ -159,11 +134,7 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio if (response->count > 0) { m_discovery_successful = true; } - - const uint32_t err_code = sd_mutex_release(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } + m_discovery_in_process = false; } STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { @@ -189,6 +160,8 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { case BLE_GAP_EVT_DISCONNECTED: central->conn_handle = BLE_CONN_HANDLE_INVALID; + m_discovery_successful = false; + m_discovery_in_process = false; break; case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: @@ -220,10 +193,22 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { } } +void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address_obj_t *address) { + common_hal_bleio_adapter_set_enabled(true); + + self->service_list = mp_obj_new_list(0, NULL); + self->gatt_role = GATT_ROLE_CLIENT; + self->conn_handle = BLE_CONN_HANDLE_INVALID; +} + void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout) { common_hal_bleio_adapter_set_enabled(true); ble_drv_add_event_handler(on_ble_evt, self); + ble_gap_addr_t addr; + addr.addr_type = self->address.type; + memcpy(addr.addr, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); + ble_gap_scan_params_t scan_params = { .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), .window = MSEC_TO_UNITS(100, UNIT_0_625_MS), @@ -241,7 +226,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time self->attempting_to_connect = true; - uint32_t err_code = sd_ble_gap_connect(&scan_params, &m_scan_buffer); + uint32_t err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params, BLE_CONN_CFG_TAG_CUSTOM); if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to start connecting, error 0x%04x"), err_code); @@ -266,7 +251,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time next_start_handle = BLE_GATT_HANDLE_START; while (1) { - if(!discover_next_services(self, discovery_start_handle)) { + if(!discover_next_services(self, next_start_handle)) { break; } @@ -310,3 +295,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time void common_hal_bleio_central_disconnect(bleio_central_obj_t *self) { sd_ble_gap_disconnect(self->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); } + +mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self) { + return self->service_list; +} diff --git a/ports/nrf/common-hal/bleio/Central.h b/ports/nrf/common-hal/bleio/Central.h index c44cf3b77..ba4a92187 100644 --- a/ports/nrf/common-hal/bleio/Central.h +++ b/ports/nrf/common-hal/bleio/Central.h @@ -30,16 +30,16 @@ #include +#include "shared-module/bleio/__init__.h" #include "shared-module/bleio/Address.h" typedef struct { mp_obj_base_t base; - mp_obj_t remote_name; + gatt_role_t gatt_role; bleio_address_obj_t address; volatile bool attempting_to_connect; volatile uint16_t conn_handle; mp_obj_t service_list; - mp_obj_t conn_handler; } bleio_central_obj_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 70ebd7aba..d2f961fe6 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -152,7 +152,6 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) { STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *bufinfo) { const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); - uint32_t err_code; ble_gattc_write_params_t write_params = { .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL, @@ -163,7 +162,7 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in }; while (1) { - uint32 err_code = sd_ble_gattc_write(conn_handle, &write_params); + uint32_t err_code = sd_ble_gattc_write(conn_handle, &write_params); if (err_code == NRF_SUCCESS) { break; } diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h index dc794ff28..90f52027d 100644 --- a/ports/nrf/common-hal/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -37,7 +37,7 @@ typedef struct { bool is_secondary; bleio_uuid_obj_t *uuid; // May be a Peripheral, Central, etc. - mp_obj_t *device; + mp_obj_t device; mp_obj_t characteristic_list; // Range of attribute handles of this service. uint16_t start_handle; diff --git a/ports/nrf/common-hal/bleio/__init__.c b/ports/nrf/common-hal/bleio/__init__.c index 699dcc57f..2dba5780c 100644 --- a/ports/nrf/common-hal/bleio/__init__.c +++ b/ports/nrf/common-hal/bleio/__init__.c @@ -28,6 +28,7 @@ #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Adapter.h" +#include "shared-bindings/bleio/Central.h" #include "shared-bindings/bleio/Peripheral.h" #include "common-hal/bleio/__init__.h" diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index e5fd66348..b3be90606 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -35,11 +35,10 @@ #include "py/objstr.h" #include "py/runtime.h" #include "shared-bindings/bleio/Adapter.h" -#include "shared-bindings/bleio/AddressType.h" +#include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/Central.h" #include "shared-bindings/bleio/Service.h" -#include "shared-bindings/bleio/UUID.h" //| .. currentmodule:: bleio //| @@ -62,44 +61,28 @@ //| break //| //| central = bleio.Central(my_entry.address) -//| central.connect() +//| central.connect(10.0) # timeout after 10 seconds //| -//| .. class:: Central(address=None, scan_entry=None) -//| -//| Create a new Central object. If the `address` or :py:data:`scan_entry` parameters are not `None`, -//| the role is set to Central, otherwise it's set to Peripheral. +//| .. class:: Central(address) //| +//| Create a new Central object. //| :param bleio.Address address: The address of the central to connect to -//| :param bleio.ScanEntry scan_entry: The scan entry returned from `bleio.Scanner` //| -STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 0, 1, true); +STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 1, 1, false); + bleio_central_obj_t *self = m_new_obj(bleio_central_obj_t); self->base.type = &bleio_central_type; - self->service_list = mp_obj_new_list(0, NULL); - self->conn_handler = mp_const_none; - self->conn_handle = 0xFFFF; - - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); - - enum { ARG_address, ARG_scan_entry }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_address, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_scan_entry, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - const mp_obj_t address_obj = args[ARG_address].u_obj; - const mp_obj_t scan_entry_obj = args[ARG_scan_entry].u_obj; + const mp_obj_t address_obj = pos_args[0]; if (!MP_OBJ_IS_TYPE(address_obj, &bleio_address_type)) { - mp_raise_ValueError("Expected an Address"); + mp_raise_ValueError(translate("Expected an Address")); } + bleio_address_obj_t *address = MP_OBJ_TO_PTR(address_obj); + common_hal_bleio_central_construct(self, address); + return MP_OBJ_FROM_PTR(self); } @@ -109,19 +92,15 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, //| //| Attempts a connection to the remote peripheral. If the connection is successful, //| -STATIC mp_obj_t bleio_central_connect(mp_obj_t self_in) { +STATIC mp_obj_t bleio_central_connect(mp_obj_t self_in, mp_obj_t timeout_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - if (self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't connect in Peripheral mode"))); - } - - common_hal_bleio_central_connect(self); + mp_float_t timeout = mp_obj_float_get(timeout_in); + common_hal_bleio_central_connect(self, timeout); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_connect_obj, bleio_central_connect); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_central_connect_obj, bleio_central_connect); //| .. method:: disconnect() @@ -137,17 +116,6 @@ STATIC mp_obj_t bleio_central_disconnect(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_disconnect_obj, bleio_central_disconnect); -//| .. attribute:: remote_name (read-only) -//| -//| The name of the remote peripheral, if connected. May be None if no name was advertised. -//| -STATIC mp_obj_t bleio_central_get_remote_name(mp_obj_t self_in) { - bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return self->remote_name; -} -MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_name_obj, bleio_central_get_remote_name); - //| .. attribute:: remote_services (read-only) //| //| Empty until connected, then a list of services provided by the remote peripheral. @@ -155,7 +123,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_name_obj, bleio_central_get_r STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - return self->service_list; + return common_hal_bleio_central_get_remote_services(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); @@ -172,7 +140,6 @@ STATIC const mp_rom_map_elem_t bleio_central_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_central_disconnect_obj) }, // Properties - { MP_ROM_QSTR(MP_QSTR_remote_name), MP_ROM_PTR(&bleio_central_remote_name_obj) }, { MP_ROM_QSTR(MP_QSTR_remote_services), MP_ROM_PTR(&bleio_central_remote_services_obj) }, }; diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h index 5ea2119af..c6fb50bc0 100644 --- a/shared-bindings/bleio/Central.h +++ b/shared-bindings/bleio/Central.h @@ -31,9 +31,11 @@ #include "common-hal/bleio/Central.h" #include "common-hal/bleio/Service.h" -extern const mp_obj_type_t bleio_device_type; +extern const mp_obj_type_t bleio_central_type; -extern void common_hal_bleio_device_connect(bleio_device_obj_t *device); -extern void common_hal_bleio_device_disconnect(bleio_device_obj_t *device); +extern void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address_obj_t *address); +extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout); +extern void common_hal_bleio_central_disconnect(bleio_central_obj_t *self); +extern mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index 859611f91..050992bb8 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -69,12 +69,12 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mp_obj_t uuid = args[ARG_uuid].u_obj; + const mp_obj_t uuid_obj = args[ARG_uuid].u_obj; - if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) { + if (!MP_OBJ_IS_TYPE(uuid_obj, &bleio_uuid_type)) { mp_raise_ValueError(translate("Expected a UUID")); } - bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid); + bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_obj); bleio_characteristic_obj_t *self = m_new_obj(bleio_characteristic_obj_t); self->base.type = &bleio_characteristic_type; @@ -88,7 +88,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t properties.write = args[ARG_write].u_bool; properties.write_no_response = args[ARG_write_no_response].u_bool; - common_hal_bleio_characteristic_construct(self, uuid_obj, properties); + common_hal_bleio_characteristic_construct(self, uuid, properties); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index da79c5d7a..827f4947b 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -86,7 +86,7 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t); self->base.type = &bleio_characteristic_buffer_type; - common_hal_bleio_characteristic_buffer_construct(self, characteristic, timeout, buffer_size); + common_hal_bleio_characteristic_buffer_construct(self, MP_OBJ_TO_PTR(characteristic), timeout, buffer_size); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h deleted file mode 100644 index d19b8c886..000000000 --- a/shared-bindings/bleio/Device.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Dan Halbert for Adafruit Industries - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H - -#include "shared-module/bleio/Device.h" -#include "common-hal/bleio/Service.h" - -extern const mp_obj_type_t bleio_device_type; - -extern void common_hal_bleio_device_add_service(bleio_device_obj_t *device, bleio_service_obj_t *service); -extern void common_hal_bleio_device_start_advertising(bleio_device_obj_t *device, bool connectable, mp_buffer_info_t *raw_data); -extern void common_hal_bleio_device_stop_advertising(bleio_device_obj_t *device); -extern void common_hal_bleio_device_connect(bleio_device_obj_t *device); -extern void common_hal_bleio_device_disconnect(bleio_device_obj_t *device); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index e270c599c..002999b5d 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -107,8 +107,8 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar self->base.type = &bleio_peripheral_type; // Copy the services list and validate its items. - mp_obj_t service_list = mp_obj_new_list(0, NULL); - mp_obj_list_t *service_list_obj = MP_OBJ_FROM_PTR(service_list); + mp_obj_t service_list_obj = mp_obj_new_list(0, NULL); + mp_obj_list_t *service_list = MP_OBJ_FROM_PTR(service_list_obj); mp_obj_t service; while ((service = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { @@ -128,7 +128,7 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar mp_raise_ValueError(translate("name must be a string")); } - common_hal_bleio_peripheral_construct(self, service_list_obj, name_str); + common_hal_bleio_peripheral_construct(self, service_list, name_str); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index 2719164d8..e687019d1 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -61,9 +61,9 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mp_obj_t uuid = args[ARG_uuid].u_obj; + const mp_obj_t uuid_obj = args[ARG_uuid].u_obj; - if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) { + if (!MP_OBJ_IS_TYPE(uuid_obj, &bleio_uuid_type)) { mp_raise_ValueError(translate("Expected a UUID")); } @@ -71,31 +71,31 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, self->base.type = &bleio_service_type; const bool is_secondary = args[ARG_secondary].u_bool; - bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid); + bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_obj); // If characteristics is not an iterable, an exception will be thrown. mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(args[ARG_characteristics].u_obj, &iter_buf); - mp_obj_t characteristic; + mp_obj_t characteristic_obj; // Copy the characteristics list and validate its items. - mp_obj_t char_list = mp_obj_new_list(0, NULL); - mp_obj_list_t *char_list_obj = MP_OBJ_FROM_PTR(char_list); + mp_obj_t char_list_obj = mp_obj_new_list(0, NULL); + mp_obj_list_t *char_list = MP_OBJ_FROM_PTR(char_list); - while ((characteristic = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { - if (!MP_OBJ_IS_TYPE(characteristic, &bleio_characteristic_type)) { + while ((characteristic_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + if (!MP_OBJ_IS_TYPE(characteristic_obj, &bleio_characteristic_type)) { mp_raise_ValueError(translate("characteristics includes an object that is not a Characteristic")); } - bleio_characteristic_obj_t *characteristic_ptr = MP_OBJ_TO_PTR(characteristic); + bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(characteristic_obj); if (common_hal_bleio_uuid_get_uuid128_reference(uuid) != - common_hal_bleio_uuid_get_uuid128_reference(characteristic_ptr->uuid)) { + common_hal_bleio_uuid_get_uuid128_reference(characteristic->uuid)) { // The descriptor base UUID doesn't match the characteristic base UUID. mp_raise_ValueError(translate("Characteristic UUID doesn't match Service UUID")); } - mp_obj_list_append(char_list, characteristic); + mp_obj_list_append(char_list_obj, characteristic_obj); } - common_hal_bleio_service_construct(self, uuid_obj, char_list_obj, is_secondary); + common_hal_bleio_service_construct(self, uuid, char_list, is_secondary); return MP_OBJ_FROM_PTR(self); } -- cgit v1.2.3 From 140904ec84ad1900f280c1febaa89a499c42b8c5 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sat, 22 Jun 2019 22:10:15 -0400 Subject: getting Scanner to work --- ports/nrf/common-hal/bleio/Scanner.c | 17 +++++++----- ports/nrf/common-hal/bleio/Scanner.h | 2 +- shared-bindings/bleio/Address.c | 53 ++++++++++++++++++++++++++++++++++-- shared-bindings/bleio/Address.h | 2 +- shared-bindings/bleio/ScanEntry.c | 19 +++++++------ shared-bindings/bleio/ScanEntry.h | 2 +- shared-bindings/bleio/Scanner.c | 4 +-- shared-bindings/bleio/Scanner.h | 2 +- shared-bindings/bleio/UUID.c | 6 ++++ shared-module/bleio/Address.c | 8 +++--- shared-module/bleio/Address.h | 2 +- shared-module/bleio/ScanEntry.c | 8 ++---- shared-module/bleio/ScanEntry.h | 2 +- 13 files changed, 90 insertions(+), 37 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index 6715bd7a2..04dc62f95 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -57,12 +57,15 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { entry->base.type = &bleio_scanentry_type; entry->rssi = report->rssi; - memcpy(entry->address.bytes, report->data.p_data, NUM_BLEIO_ADDRESS_BYTES); - entry->address.type = report->peer_addr.addr_type; + bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); + address->base.type = &bleio_address_type; + common_hal_bleio_address_construct(MP_OBJ_TO_PTR(address), + report->peer_addr.addr, report->peer_addr.addr_type); + entry->address = address; entry->data = mp_obj_new_bytes(report->data.p_data, report->data.len); - mp_obj_list_append(scanner->adv_reports, entry); + mp_obj_list_append(scanner->scan_entries, MP_OBJ_FROM_PTR(entry)); const uint32_t err_code = sd_ble_gap_scan_start(NULL, &m_scan_buffer); if (err_code != NRF_SUCCESS) { @@ -71,7 +74,7 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { } void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self) { - self->adv_reports = mp_obj_new_list(0, NULL); + self->scan_entries = mp_obj_new_list(0, NULL); } void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { @@ -85,7 +88,7 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout }; // Empty the advertising reports list. - mp_obj_list_clear(self->adv_reports); + mp_obj_list_clear(self->scan_entries); uint32_t err_code; err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); @@ -98,6 +101,6 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout sd_ble_gap_scan_stop(); } -mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self) { - return self->adv_reports; +mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self) { + return self->scan_entries; } diff --git a/ports/nrf/common-hal/bleio/Scanner.h b/ports/nrf/common-hal/bleio/Scanner.h index a71066487..3768a52cb 100644 --- a/ports/nrf/common-hal/bleio/Scanner.h +++ b/ports/nrf/common-hal/bleio/Scanner.h @@ -32,7 +32,7 @@ typedef struct { mp_obj_base_t base; - mp_obj_t adv_reports; // List of reports. + mp_obj_t scan_entries; uint16_t interval; uint16_t window; } bleio_scanner_obj_t; diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index 5875cf9bd..0e094c2e3 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -80,7 +80,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_ValueError(translate("Address type out of range")); } - common_hal_bleio_address_construct(self, buf_info.buf, buf_info.len, address_type); + common_hal_bleio_address_construct(self, buf_info.buf, address_type); return MP_OBJ_FROM_PTR(self); } @@ -101,6 +101,13 @@ STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get_address_bytes); +const mp_obj_property_t bleio_address_address_bytes_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&bleio_address_get_address_bytes_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + //| .. attribute:: type //| //| The address type (read-only). One of these integers: @@ -124,9 +131,47 @@ const mp_obj_property_t bleio_address_type_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| .. method:: __eq__(other) +//| +//| Two Address objects are equal if their addresses and address types are equal. +//| +STATIC mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { + switch (op) { + // Two Addresses are equal if their address bytes and address_type are equal + case MP_BINARY_OP_EQUAL: + if (MP_OBJ_IS_TYPE(rhs_in, &bleio_address_type)) { + bleio_address_obj_t *lhs = MP_OBJ_TO_PTR(lhs_in); + bleio_address_obj_t *rhs = MP_OBJ_TO_PTR(rhs_in); + return mp_obj_new_bool( + mp_obj_equal(common_hal_bleio_address_get_address_bytes(lhs), + common_hal_bleio_address_get_address_bytes(rhs)) && + common_hal_bleio_address_get_type(lhs) == + common_hal_bleio_address_get_type(rhs)); + + } else { + return mp_const_false; + } + + default: + return MP_OBJ_NULL; // op not supported + } +} + +STATIC void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_obj_t address_bytes = common_hal_bleio_address_get_address_bytes(self); + + mp_buffer_info_t buf_info; + mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); + const uint8_t *buf = (uint8_t *) buf_info.buf; + mp_printf(print, + "%02x:%02x:%02x:%02x:%02x:%02x", + buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); +} + STATIC const mp_rom_map_elem_t bleio_address_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_get_address_bytes_obj) }, - { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_get_type_obj) }, + { MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_address_bytes_obj) }, + { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_type_obj) }, // These match the BLE_GAP_ADDR_TYPES values used by the nRF library. { MP_ROM_QSTR(MP_QSTR_PUBLIC), MP_OBJ_NEW_SMALL_INT(0) }, { MP_ROM_QSTR(MP_QSTR_RANDOM_STATIC), MP_OBJ_NEW_SMALL_INT(1) }, @@ -141,5 +186,7 @@ const mp_obj_type_t bleio_address_type = { { &mp_type_type }, .name = MP_QSTR_Address, .make_new = bleio_address_make_new, + .print = bleio_address_print, + .binary_op = bleio_address_binary_op, .locals_dict = (mp_obj_dict_t*)&bleio_address_locals_dict }; diff --git a/shared-bindings/bleio/Address.h b/shared-bindings/bleio/Address.h index bff1542cf..5e02ee210 100644 --- a/shared-bindings/bleio/Address.h +++ b/shared-bindings/bleio/Address.h @@ -41,7 +41,7 @@ extern const mp_obj_type_t bleio_address_type; -extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type); +extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, uint8_t address_type); extern mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self); extern uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self); diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index 145d2b023..b7798175c 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -62,19 +62,19 @@ const mp_obj_property_t bleio_scanentry_address_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| .. attribute:: raw_data +//| .. attribute:: advertisement_bytes //| //| All the advertisement data present in the packet, returned as a ``bytes`` object. (read-only) //| -STATIC mp_obj_t scanentry_get_raw_data(mp_obj_t self_in) { +STATIC mp_obj_t scanentry_get_advertisement_bytes(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_bleio_scanentry_get_raw_data(self); + return common_hal_bleio_scanentry_get_advertisement_bytes(self); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_raw_data_obj, scanentry_get_raw_data); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_advertisement_bytes_obj, scanentry_get_advertisement_bytes); -const mp_obj_property_t bleio_scanentry_raw_data_obj = { +const mp_obj_property_t bleio_scanentry_advertisement_bytes_obj = { .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_scanentry_get_raw_data_obj, + .proxy = { (mp_obj_t)&bleio_scanentry_get_advertisement_bytes_obj, (mp_obj_t)&mp_const_none_obj, (mp_obj_t)&mp_const_none_obj }, }; @@ -96,10 +96,11 @@ const mp_obj_property_t bleio_scanentry_rssi_obj = { (mp_obj_t)&mp_const_none_obj }, }; + STATIC const mp_rom_map_elem_t bleio_scanentry_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&bleio_scanentry_address_obj) }, - { MP_ROM_QSTR(MP_QSTR_raw_data), MP_ROM_PTR(&bleio_scanentry_raw_data_obj) }, - { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bleio_scanentry_rssi_obj) }, + { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&bleio_scanentry_address_obj) }, + { MP_ROM_QSTR(MP_QSTR_advertisement_bytes), MP_ROM_PTR(&bleio_scanentry_advertisement_bytes_obj) }, + { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bleio_scanentry_rssi_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bleio_scanentry_locals_dict, bleio_scanentry_locals_dict_table); diff --git a/shared-bindings/bleio/ScanEntry.h b/shared-bindings/bleio/ScanEntry.h index 3a02f2fac..77e93175f 100644 --- a/shared-bindings/bleio/ScanEntry.h +++ b/shared-bindings/bleio/ScanEntry.h @@ -35,7 +35,7 @@ extern const mp_obj_type_t bleio_scanentry_type; mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self); -mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self); +mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_t *self); mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 92f6a2a18..d50f69fc5 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -42,7 +42,7 @@ //| :class:`Scanner` -- scan for nearby BLE devices //| ========================================================= //| -//| Allows scanning for nearby BLE devices. +//| Scan for nearby BLE devices. //| //| Usage:: //| @@ -112,7 +112,7 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m common_hal_bleio_scanner_scan(self, timeout, interval, window); - return common_hal_bleio_scanner_get_adv_reports(self); + return common_hal_bleio_scanner_get_scan_entries(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index b9e3ecdee..1bbab78f4 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -36,6 +36,6 @@ extern const mp_obj_type_t bleio_scanner_type; extern void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self); extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); -extern mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self); +extern mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index 972505058..0db7435f4 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -220,6 +220,12 @@ STATIC mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } +//| + +//| .. method:: __eq__(other) +//| +//| Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit. +//| STATIC mp_obj_t bleio_uuid_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { switch (op) { // Two UUID's are equal if their uuid16 values and uuid128 references match. diff --git a/shared-module/bleio/Address.c b/shared-module/bleio/Address.c index e26bbe2ac..6bc458b7c 100644 --- a/shared-module/bleio/Address.c +++ b/shared-module/bleio/Address.c @@ -27,17 +27,17 @@ #include -#include "py/objproperty.h" +#include "py/objstr.h" #include "shared-bindings/bleio/Address.h" #include "shared-module/bleio/Address.h" -void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type) { - memcpy(self->bytes, bytes, bytes_length); +void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, uint8_t address_type) { + self->bytes = mp_obj_new_bytes(bytes, NUM_BLEIO_ADDRESS_BYTES); self->type = address_type; } mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self) { - return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES); + return self->bytes; } uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self) { diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h index eb1aab258..39789842f 100644 --- a/shared-module/bleio/Address.h +++ b/shared-module/bleio/Address.h @@ -35,7 +35,7 @@ typedef struct { mp_obj_base_t base; uint8_t type; - uint8_t bytes[NUM_BLEIO_ADDRESS_BYTES]; + mp_obj_t bytes; // a bytes() object } bleio_address_obj_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H diff --git a/shared-module/bleio/ScanEntry.c b/shared-module/bleio/ScanEntry.c index 44b50a4ce..306ac33c5 100644 --- a/shared-module/bleio/ScanEntry.c +++ b/shared-module/bleio/ScanEntry.c @@ -33,14 +33,10 @@ #include "shared-module/bleio/ScanEntry.h" mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self) { - bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); - address->base.type = &bleio_address_type; - memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); - address->type = self->address.type; - return MP_OBJ_TO_PTR(address); + return MP_OBJ_FROM_PTR(self->address); } -mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self) { +mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_t *self) { return self->data; } diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h index 4e7028ba2..b302460e6 100644 --- a/shared-module/bleio/ScanEntry.h +++ b/shared-module/bleio/ScanEntry.h @@ -35,7 +35,7 @@ typedef struct { mp_obj_base_t base; bool connectable; int8_t rssi; - bleio_address_obj_t address; + bleio_address_obj_t *address; mp_obj_t data; } bleio_scanentry_obj_t; -- cgit v1.2.3 From 6ea01ea9b0334a175419f9d449be25a5838627da Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sat, 29 Jun 2019 00:20:06 -0400 Subject: Central is connecting; characteristics can be read and written --- ports/nrf/Makefile | 2 +- ports/nrf/common-hal/bleio/Central.c | 151 ++++++++++++++++------------ ports/nrf/common-hal/bleio/Central.h | 3 +- ports/nrf/common-hal/bleio/Characteristic.c | 10 +- ports/nrf/common-hal/bleio/Scanner.c | 4 +- shared-bindings/bleio/Central.c | 59 +++++++---- shared-bindings/bleio/Central.h | 4 +- shared-bindings/bleio/Characteristic.c | 17 +++- shared-bindings/bleio/Peripheral.c | 4 +- shared-bindings/bleio/Service.c | 17 +++- shared-bindings/bleio/UUID.c | 3 + shared-bindings/bleio/__init__.c | 5 +- 12 files changed, 182 insertions(+), 97 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 18990485b..83f87536b 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -91,7 +91,7 @@ INC += -I../../supervisor/shared/usb ifeq ($(DEBUG), 1) CFLAGS += -ggdb # You may want to enable these flags to make setting breakpoints easier. - # CFLAGS += -fno-inline -fno-ipa-sra + CFLAGS += -fno-inline -fno-ipa-sra else CFLAGS += -Os -DNDEBUG # TODO: Test with -flto diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index 5864a8a56..0eedd2b56 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -44,11 +44,13 @@ static bleio_service_obj_t *m_char_discovery_service; static volatile bool m_discovery_in_process; static volatile bool m_discovery_successful; -STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_handle) { +// service_uuid may be NULL, to discover all services. +STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_handle, ble_uuid_t *service_uuid) { m_discovery_successful = false; m_discovery_in_process = true; - uint32_t err_code = sd_ble_gattc_primary_services_discover(self->conn_handle, start_handle, NULL); + uint32_t err_code = sd_ble_gattc_primary_services_discover(self->conn_handle, start_handle, service_uuid); + if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg(translate("Failed to discover services")); } @@ -88,15 +90,26 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); service->base.type = &bleio_service_type; + service->device = MP_OBJ_FROM_PTR(central); service->characteristic_list = mp_obj_new_list(0, NULL); service->start_handle = gattc_service->handle_range.start_handle; service->end_handle = gattc_service->handle_range.end_handle; service->handle = gattc_service->handle_range.start_handle; - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); - bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid); - service->uuid = uuid; + if (gattc_service->uuid.type != BLE_UUID_TYPE_UNKNOWN) { + // Known service UUID. + bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + uuid->base.type = &bleio_uuid_type; + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid); + service->uuid = uuid; + service->device = MP_OBJ_FROM_PTR(central); + } else { + // The discovery response contained a 128-bit UUID that has not yet been registered with the + // softdevice via sd_ble_uuid_vs_add(). We need to fetch the 128-bit value and register it. + // For now, just set the UUID to NULL. + service->uuid = NULL; + } mp_obj_list_append(central->service_list, service); } @@ -114,10 +127,18 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); characteristic->base.type = &bleio_characteristic_type; - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); - uuid->base.type = &bleio_uuid_type; - bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); - characteristic->uuid = uuid; + if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) { + // Known characteristic UUID. + bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + uuid->base.type = &bleio_uuid_type; + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); + characteristic->uuid = uuid; + } else { + // The discovery response contained a 128-bit UUID that has not yet been registered with the + // softdevice via sd_ble_uuid_vs_add(). We need to fetch the 128-bit value and register it. + // For now, just set the UUID to NULL. + characteristic->uuid = NULL; + } characteristic->props.broadcast = gattc_char->char_props.broadcast; characteristic->props.indicate = gattc_char->char_props.indicate; @@ -137,25 +158,18 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio m_discovery_in_process = false; } -STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { +STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { bleio_central_obj_t *central = (bleio_central_obj_t*)central_in; switch (ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: - { - ble_gap_conn_params_t conn_params; central->conn_handle = ble_evt->evt.gap_evt.conn_handle; - - sd_ble_gap_ppcp_get(&conn_params); - sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); + central->waiting_to_connect = false; break; - } case BLE_GAP_EVT_TIMEOUT: - if (central->attempting_to_connect) { - // Signal that connection attempt has timed out. - central->attempting_to_connect = false; - } + // Handle will be invalid. + central->waiting_to_connect = false; break; case BLE_GAP_EVT_DISCONNECTED: @@ -172,14 +186,6 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); break; - case BLE_GATTS_EVT_SYS_ATTR_MISSING: - sd_ble_gatts_sys_attr_set(ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0); - break; - - case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: - sd_ble_gatts_exchange_mtu_reply(central->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); - break; - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); break; @@ -193,7 +199,7 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { } } -void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address_obj_t *address) { +void common_hal_bleio_central_construct(bleio_central_obj_t *self) { common_hal_bleio_adapter_set_enabled(true); self->service_list = mp_obj_new_list(0, NULL); @@ -201,13 +207,16 @@ void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address self->conn_handle = BLE_CONN_HANDLE_INVALID; } -void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout) { +void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_obj_t *address, mp_float_t timeout, mp_obj_t service_uuids) { common_hal_bleio_adapter_set_enabled(true); - ble_drv_add_event_handler(on_ble_evt, self); + ble_drv_add_event_handler(central_on_ble_evt, self); ble_gap_addr_t addr; - addr.addr_type = self->address.type; - memcpy(addr.addr, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); + + addr.addr_type = address->type; + mp_buffer_info_t address_buf_info; + mp_get_buffer_raise(address->bytes, &address_buf_info, MP_BUFFER_READ); + memcpy(addr.addr, (uint8_t *) address_buf_info.buf, NUM_BLEIO_ADDRESS_BYTES); ble_gap_scan_params_t scan_params = { .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), @@ -224,7 +233,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time .slave_latency = 0, // number of conn events }; - self->attempting_to_connect = true; + self->waiting_to_connect = true; uint32_t err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params, BLE_CONN_CFG_TAG_CUSTOM); @@ -232,50 +241,68 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time mp_raise_OSError_msg_varg(translate("Failed to start connecting, error 0x%04x"), err_code); } - while (self->conn_handle == BLE_CONN_HANDLE_INVALID && self->attempting_to_connect) { - #ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP - #endif + while (self->waiting_to_connect) { + MICROPY_VM_HOOK_LOOP; } - if (!self->attempting_to_connect) { + if (self->conn_handle == BLE_CONN_HANDLE_INVALID) { mp_raise_OSError_msg(translate("Failed to connect: timeout")); } - // Conenction successful. - // Now discover all services on the remote peripheral. Ask for services repeatedly - // until no more are left. + // Connection successful. + // Now discover services on the remote peripheral. + + if (service_uuids == mp_const_none) { - uint16_t next_start_handle; + // List of service UUID's not given, so discover all available services. - next_start_handle = BLE_GATT_HANDLE_START; + uint16_t next_start_handle = BLE_GATT_HANDLE_START; - while (1) { - if(!discover_next_services(self, next_start_handle)) { - break; + while (discover_next_services(self, next_start_handle, MP_OBJ_NULL)) { + // discover_next_services() appends to service_list. + const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + + // Get the most recently discovered service, and then ask for services + // whose handles start after the last attribute handle inside that service. + const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; + next_start_handle = service->end_handle + 1; } + } else { + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(service_uuids, &iter_buf); + mp_obj_t uuid_obj; + while ((uuid_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + if (!MP_OBJ_IS_TYPE(uuid_obj, &bleio_uuid_type)) { + mp_raise_ValueError(translate("non-UUID found in service_uuids")); + } + bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_obj); - // discover_next_services() appends to service_list. - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + ble_uuid_t nrf_uuid; + bleio_uuid_convert_to_nrf_ble_uuid(uuid, &nrf_uuid); - // Get the most recently discovered service, and ask for services with handles - // starting after the last attribute handle of t - const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; - next_start_handle = service->end_handle + 1; + // Service might or might not be discovered; that's ok. Caller has to check + // Central.remote_services to find out. + // We only need to call this once for each service to discover. + discover_next_services(self, BLE_GATT_HANDLE_START, &nrf_uuid); + } } - // Now, for each service, discover its characteristics. - // find characteristics in each service + const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); for (size_t i = 0; i < service_list->len; ++i) { bleio_service_obj_t *service = service_list->items[i]; - next_start_handle = service->start_handle; + // Skip the service if it had an unknown (unregistered) UUID. + if (service->uuid == NULL) { + continue; + } - while (1) { - if (!discover_next_characteristics(self, service, service->start_handle)) { - break; - } + uint16_t next_start_handle = service->start_handle; + + // Stop when we go past the end of the range of handles for this service or + // discovery call returns nothing. + while (next_start_handle <= service->end_handle && + discover_next_characteristics(self, service, next_start_handle)) { // discover_next_characteristics() appends to the characteristic_list. const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); @@ -284,10 +311,6 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time const bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_list->len - 1]; next_start_handle = characteristic->handle + 1; - if (next_start_handle >= service->end_handle) { - // Went past the end of the range of handles for this service. - break; - } } } } diff --git a/ports/nrf/common-hal/bleio/Central.h b/ports/nrf/common-hal/bleio/Central.h index ba4a92187..8b38e87ac 100644 --- a/ports/nrf/common-hal/bleio/Central.h +++ b/ports/nrf/common-hal/bleio/Central.h @@ -36,8 +36,7 @@ typedef struct { mp_obj_base_t base; gatt_role_t gatt_role; - bleio_address_obj_t address; - volatile bool attempting_to_connect; + volatile bool waiting_to_connect; volatile uint16_t conn_handle; mp_obj_t service_list; } bleio_central_obj_t; diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index d2f961fe6..ea43d8a8a 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -60,7 +60,7 @@ STATIC uint16_t get_cccd(bleio_characteristic_obj_t *characteristic) { } STATIC void gatts_read(bleio_characteristic_obj_t *characteristic) { - // This might be BLE_CONN_HANDLE_INVALID if we're not conected, but that's OK, because + // This might be BLE_CONN_HANDLE_INVALID if we're not connected, but that's OK, because // we can still read and write the local value. const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); @@ -135,8 +135,15 @@ STATIC void gatts_notify_indicate(bleio_characteristic_obj_t *characteristic, mp } +STATIC void check_connected(uint16_t conn_handle) { + if (conn_handle == BLE_CONN_HANDLE_INVALID) { + mp_raise_OSError_msg(translate("Not connected")); + } +} + STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) { const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); + check_connected(conn_handle); m_read_characteristic = characteristic; @@ -152,6 +159,7 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) { STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *bufinfo) { const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); + check_connected(conn_handle); ble_gattc_write_params_t write_params = { .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL, diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index 04dc62f95..fa4f3923c 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -45,7 +45,7 @@ static ble_data_t m_scan_buffer = { BLE_GAP_SCAN_BUFFER_MIN }; -STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { +STATIC void scanner_on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { bleio_scanner_obj_t *scanner = (bleio_scanner_obj_t*)scanner_in; ble_gap_evt_adv_report_t *report = &ble_evt->evt.gap_evt.params.adv_report; @@ -79,7 +79,7 @@ void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self) { void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { common_hal_bleio_adapter_set_enabled(true); - ble_drv_add_event_handler(on_ble_evt, self); + ble_drv_add_event_handler(scanner_on_ble_evt, self); ble_gap_scan_params_t scan_params = { .interval = SEC_TO_UNITS(interval, UNIT_0_625_MS), diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index b3be90606..dd2dd0d50 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -64,43 +64,68 @@ //| central.connect(10.0) # timeout after 10 seconds //| -//| .. class:: Central(address) +//| .. class:: Central() //| //| Create a new Central object. -//| :param bleio.Address address: The address of the central to connect to //| STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); + mp_arg_check_num(n_args, kw_args, 0, 0, false); bleio_central_obj_t *self = m_new_obj(bleio_central_obj_t); self->base.type = &bleio_central_type; - const mp_obj_t address_obj = pos_args[0]; - if (!MP_OBJ_IS_TYPE(address_obj, &bleio_address_type)) { - mp_raise_ValueError(translate("Expected an Address")); - } - - bleio_address_obj_t *address = MP_OBJ_TO_PTR(address_obj); - common_hal_bleio_central_construct(self, address); + common_hal_bleio_central_construct(self); return MP_OBJ_FROM_PTR(self); } -//| .. method:: connect() -//| +//| .. method:: connect(address, timeout, *, service_uuids=None) //| Attempts a connection to the remote peripheral. If the connection is successful, +//| Do BLE discovery for the listed services, to find their handles and characteristics. +//| The attribute `remote_services` will contain a list of all discovered services. //| -STATIC mp_obj_t bleio_central_connect(mp_obj_t self_in, mp_obj_t timeout_in) { - bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); +//| :param bleio.Address address: The address of the peripheral to connect to +//| :param float/int timeout: Try to connect for timeout seconds. +//| :param iterable service_uuids: a collection of `UUID` objects for the services +//| provided by the peripheral that you want to use. +//| The peripheral may provide more services, but services not listed are ignored. +//| If a service in `service_uuids` is not found during discovery, it will not +//| appear in `remote_services`. +//| +//| If `services` is None, then all services will undergo discovery, which can be slow. +//| +//| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you +//| you must have already created a `UUID` object for that UUID in order for the +//| service or characteristic to be discovered. (This restriction may be lifted in the future.) +//| +STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + + enum { ARG_address, ARG_timeout, ARG_service_uuids }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_address, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_timeout, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_service_uuids, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (!MP_OBJ_IS_TYPE(args[ARG_address].u_obj, &bleio_address_type)) { + mp_raise_ValueError(translate("Expected an Address")); + } + + bleio_address_obj_t *address = MP_OBJ_TO_PTR(args[ARG_address].u_obj); + mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); - mp_float_t timeout = mp_obj_float_get(timeout_in); - common_hal_bleio_central_connect(self, timeout); + // common_hal_bleio_central_connect() will validate that services is an iterable or None. + common_hal_bleio_central_connect(self, address, timeout, args[ARG_service_uuids].u_obj); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_central_connect_obj, bleio_central_connect); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_central_connect_obj, 3, bleio_central_connect); //| .. method:: disconnect() diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h index c6fb50bc0..542ba8fa2 100644 --- a/shared-bindings/bleio/Central.h +++ b/shared-bindings/bleio/Central.h @@ -33,8 +33,8 @@ extern const mp_obj_type_t bleio_central_type; -extern void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address_obj_t *address); -extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout); +extern void common_hal_bleio_central_construct(bleio_central_obj_t *self); +extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_obj_t *address, mp_float_t timeout, mp_obj_t service_uuids); extern void common_hal_bleio_central_disconnect(bleio_central_obj_t *self); extern mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index 050992bb8..ede38c86b 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -205,11 +205,13 @@ const mp_obj_property_t bleio_characteristic_write_no_response_obj = { //| .. attribute:: uuid //| //| The UUID of this characteristic. (read-only) +//| Will be ``None`` if the 128-bit UUID for this characteristic is not known. //| STATIC mp_obj_t bleio_characteristic_get_uuid(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(common_hal_bleio_characteristic_get_uuid(self)); + bleio_uuid_obj_t *uuid = common_hal_bleio_characteristic_get_uuid(self); + return uuid ? MP_OBJ_FROM_PTR(uuid) : mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_uuid_obj, bleio_characteristic_get_uuid); @@ -262,12 +264,23 @@ STATIC const mp_rom_map_elem_t bleio_characteristic_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&bleio_characteristic_write_obj) }, { MP_ROM_QSTR(MP_QSTR_write_no_response), MP_ROM_PTR(&bleio_characteristic_write_no_response_obj) }, }; - STATIC MP_DEFINE_CONST_DICT(bleio_characteristic_locals_dict, bleio_characteristic_locals_dict_table); +STATIC void bleio_characteristic_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "Characteristic("); + if (self->uuid) { + bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + } else { + mp_printf(print, "Unregistered uUID"); + } + mp_printf(print, ")"); +} + const mp_obj_type_t bleio_characteristic_type = { { &mp_type_type }, .name = MP_QSTR_Characteristic, .make_new = bleio_characteristic_make_new, + .print = bleio_characteristic_print, .locals_dict = (mp_obj_dict_t*)&bleio_characteristic_locals_dict }; diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 002999b5d..37a765ae9 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -113,7 +113,7 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar mp_obj_t service; while ((service = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(service, &bleio_service_type)) { - mp_raise_ValueError(translate("services includes an object that is not a Service")); + mp_raise_ValueError(translate("non-Service found in services")); } mp_obj_list_append(service_list, service); } @@ -237,7 +237,7 @@ STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_ob return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_peripheral_start_advertising_obj, 0, bleio_peripheral_start_advertising); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_peripheral_start_advertising_obj, 2, bleio_peripheral_start_advertising); //| .. method:: stop_advertising() //| diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index e687019d1..e6bb7dcc3 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -140,11 +140,13 @@ const mp_obj_property_t bleio_service_secondary_obj = { //| .. attribute:: uuid //| //| The UUID of this service. (read-only) +//| Will be ``None`` if the 128-bit UUID for this service is not known. //| STATIC mp_obj_t bleio_service_get_uuid(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(common_hal_bleio_service_get_uuid(self)); + bleio_uuid_obj_t *uuid = common_hal_bleio_service_get_uuid(self); + return uuid ? MP_OBJ_FROM_PTR(uuid) : mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_uuid_obj, bleio_service_get_uuid); @@ -160,12 +162,23 @@ STATIC const mp_rom_map_elem_t bleio_service_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_secondary), MP_ROM_PTR(&bleio_service_secondary_obj) }, { MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_service_uuid_obj) }, }; - STATIC MP_DEFINE_CONST_DICT(bleio_service_locals_dict, bleio_service_locals_dict_table); +STATIC void bleio_service_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "Service("); + if (self->uuid) { + bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + } else { + mp_printf(print, "unregistered UUID"); + } + mp_printf(print, ")"); +} + const mp_obj_type_t bleio_service_type = { { &mp_type_type }, .name = MP_QSTR_Service, .make_new = bleio_service_make_new, + .print = bleio_service_print, .locals_dict = (mp_obj_dict_t*)&bleio_service_locals_dict }; diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index 0db7435f4..dca7ea010 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -50,6 +50,9 @@ //| - a buffer object (bytearray, bytes) of 16 bytes in little-endian order (128-bit UUID) //| - a string of hex digits of the form 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' //| +//| Creating a 128-bit UUID registers the UUID with the onboard BLE software, and provides a +//| temporary 16-bit UUID that can be used in place of the full 128-bit UUID. +//| //| :param value: The uuid value to encapsulate //| :type value: int or typing.ByteString //| diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index ca45a846e..9e80b49e3 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -28,9 +28,10 @@ #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Address.h" +#include "shared-bindings/bleio/Central.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/CharacteristicBuffer.h" -#include "shared-bindings/bleio/Descriptor.h" +// #include "shared-bindings/bleio/Descriptor.h" #include "shared-bindings/bleio/Peripheral.h" #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/Scanner.h" @@ -74,7 +75,7 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) }, { MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) }, -// { MP_ROM_QSTR(MP_QSTR_Central), MP_ROM_PTR(&bleio_central_type) }, + { MP_ROM_QSTR(MP_QSTR_Central), MP_ROM_PTR(&bleio_central_type) }, { MP_ROM_QSTR(MP_QSTR_Characteristic), MP_ROM_PTR(&bleio_characteristic_type) }, { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) }, // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, -- cgit v1.2.3 From 745ff8f8c185ea924922e708d1257f4c6377fb90 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 2 Jul 2019 18:15:23 -0700 Subject: Fix Group subscr to detect delete correctly Fixes #1957 --- shared-bindings/displayio/Group.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 76719c580..5a35424ce 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -295,7 +295,7 @@ STATIC mp_obj_t group_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t valu if (value == MP_OBJ_SENTINEL) { // load return common_hal_displayio_group_get(self, index); - } else if (value == mp_const_none) { + } else if (value == MP_OBJ_NULL) { common_hal_displayio_group_pop(self, index); } else { common_hal_displayio_group_set(self, index, value); -- cgit v1.2.3 From bf8a35b2f835fbc97d54867f8e21b486a46c245b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 2 Jul 2019 22:34:54 -0400 Subject: WIP: CharacteristicBuffer for Central; not working: need to set remote Characteristic Service --- ports/nrf/common-hal/bleio/Central.c | 73 +++++++++--------- ports/nrf/common-hal/bleio/Characteristic.c | 47 ++++++------ ports/nrf/common-hal/bleio/CharacteristicBuffer.c | 45 +++++++---- ports/nrf/common-hal/bleio/Peripheral.c | 93 ++++++++++++----------- shared-bindings/bleio/Central.c | 26 ++++++- shared-bindings/bleio/Central.h | 1 + shared-bindings/bleio/CharacteristicBuffer.c | 9 ++- shared-bindings/bleio/Peripheral.c | 1 - shared-bindings/bleio/Service.c | 2 +- 9 files changed, 171 insertions(+), 126 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index 0eedd2b56..5bd5a6321 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -162,40 +162,41 @@ STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { bleio_central_obj_t *central = (bleio_central_obj_t*)central_in; switch (ble_evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: - central->conn_handle = ble_evt->evt.gap_evt.conn_handle; - central->waiting_to_connect = false; - break; - - case BLE_GAP_EVT_TIMEOUT: - // Handle will be invalid. - central->waiting_to_connect = false; - break; - - case BLE_GAP_EVT_DISCONNECTED: - central->conn_handle = BLE_CONN_HANDLE_INVALID; - m_discovery_successful = false; - m_discovery_in_process = false; - break; - - case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: - on_primary_srv_discovery_rsp(&ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp, central); - break; - - case BLE_GATTC_EVT_CHAR_DISC_RSP: - on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); - break; - - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: - sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); - break; - - case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: - { - ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; - sd_ble_gap_conn_param_update(central->conn_handle, &request->conn_params); - break; - } + case BLE_GAP_EVT_CONNECTED: + central->conn_handle = ble_evt->evt.gap_evt.conn_handle; + central->waiting_to_connect = false; + break; + + case BLE_GAP_EVT_TIMEOUT: + // Handle will be invalid. + central->waiting_to_connect = false; + break; + + case BLE_GAP_EVT_DISCONNECTED: + central->conn_handle = BLE_CONN_HANDLE_INVALID; + m_discovery_successful = false; + m_discovery_in_process = false; + break; + + case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: + on_primary_srv_discovery_rsp(&ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp, central); + break; + + case BLE_GATTC_EVT_CHAR_DISC_RSP: + on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); + break; + + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); + break; + + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: + { + ble_gap_evt_conn_param_update_request_t *request = + &ble_evt->evt.gap_evt.params.conn_param_update_request; + sd_ble_gap_conn_param_update(central->conn_handle, &request->conn_params); + break; + } } } @@ -319,6 +320,10 @@ void common_hal_bleio_central_disconnect(bleio_central_obj_t *self) { sd_ble_gap_disconnect(self->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); } +bool common_hal_bleio_central_get_connected(bleio_central_obj_t *self) { + return self->conn_handle != BLE_CONN_HANDLE_INVALID; +} + mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self) { return self->service_list; } diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index ea43d8a8a..c00d8c30b 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -249,34 +249,35 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, uint16_t cccd = 0; switch (common_hal_bleio_device_get_gatt_role(self->service->device)) { - case GATT_ROLE_SERVER: - if (self->props.notify || self->props.indicate) { - cccd = get_cccd(self); - } - // It's possible that both notify and indicate are set. - if (self->props.notify && (cccd & BLE_GATT_HVX_NOTIFICATION)) { - gatts_notify_indicate(self, bufinfo, BLE_GATT_HVX_NOTIFICATION); - sent = true; - } - if (self->props.indicate && (cccd & BLE_GATT_HVX_INDICATION)) { - gatts_notify_indicate(self, bufinfo, BLE_GATT_HVX_INDICATION); - sent = true; - } - if (!sent) { - gatts_write(self, bufinfo); - } - break; + case GATT_ROLE_SERVER: + if (self->props.notify || self->props.indicate) { + cccd = get_cccd(self); + } + // It's possible that both notify and indicate are set. + if (self->props.notify && (cccd & BLE_GATT_HVX_NOTIFICATION)) { + gatts_notify_indicate(self, bufinfo, BLE_GATT_HVX_NOTIFICATION); + sent = true; + } + if (self->props.indicate && (cccd & BLE_GATT_HVX_INDICATION)) { + gatts_notify_indicate(self, bufinfo, BLE_GATT_HVX_INDICATION); + sent = true; + } + if (!sent) { + gatts_write(self, bufinfo); + } + break; - case GATT_ROLE_CLIENT: - gattc_write(self, bufinfo); - break; + case GATT_ROLE_CLIENT: + gattc_write(self, bufinfo); + break; - default: - mp_raise_RuntimeError(translate("bad GATT role")); - break; + default: + mp_raise_RuntimeError(translate("bad GATT role")); + break; } } + bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self) { return self->uuid; } diff --git a/ports/nrf/common-hal/bleio/CharacteristicBuffer.c b/ports/nrf/common-hal/bleio/CharacteristicBuffer.c index 19b3b85ea..59eaaf02b 100644 --- a/ports/nrf/common-hal/bleio/CharacteristicBuffer.c +++ b/ports/nrf/common-hal/bleio/CharacteristicBuffer.c @@ -40,25 +40,42 @@ #include "common-hal/bleio/__init__.h" #include "common-hal/bleio/CharacteristicBuffer.h" +STATIC void write_to_ringbuf(bleio_characteristic_buffer_obj_t *self, uint8_t *data, uint16_t len) { + // Push all the data onto the ring buffer. + uint8_t is_nested_critical_region; + sd_nvic_critical_region_enter(&is_nested_critical_region); + for (size_t i = 0; i < len; i++) { + ringbuf_put(&self->ringbuf, data[i]); + } + sd_nvic_critical_region_exit(is_nested_critical_region); +} + STATIC void characteristic_buffer_on_ble_evt(ble_evt_t *ble_evt, void *param) { bleio_characteristic_buffer_obj_t *self = (bleio_characteristic_buffer_obj_t *) param; switch (ble_evt->header.evt_id) { - case BLE_GATTS_EVT_WRITE: { - ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write; - // Event handle must match the handle for my characteristic. - if (evt_write->handle == self->characteristic->handle) { - // Push all the data onto the ring buffer. - uint8_t is_nested_critical_region; - sd_nvic_critical_region_enter(&is_nested_critical_region); - for (size_t i = 0; i < evt_write->len; i++) { - ringbuf_put(&self->ringbuf, evt_write->data[i]); + case BLE_GATTS_EVT_WRITE: { + // A client wrote to this server characteristic. + + ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write; + // Event handle must match the handle for my characteristic. + if (evt_write->handle == self->characteristic->handle) { + write_to_ringbuf(self, evt_write->data, evt_write->len); } - sd_nvic_critical_region_exit(is_nested_critical_region); break; } - } - } + case BLE_GATTC_EVT_HVX: { + // A remote service wrote to this characteristic. + + ble_gattc_evt_hvx_t* evt_hvx = &ble_evt->evt.gattc_evt.params.hvx; + // Must be a notification, and event handle must match the handle for my characteristic. + if (evt_hvx->type == BLE_GATT_HVX_NOTIFICATION && + evt_hvx->handle == self->characteristic->handle) { + write_to_ringbuf(self, evt_hvx->data, evt_hvx->len); + } + break; + } + } } // Assumes that timeout and buffer_size have been validated before call. @@ -82,13 +99,11 @@ int common_hal_bleio_characteristic_buffer_read(bleio_characteristic_buffer_obj_ // Wait for all bytes received or timeout while ( (ringbuf_count(&self->ringbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP ; + MICROPY_VM_HOOK_LOOP; // Allow user to break out of a timeout with a KeyboardInterrupt. if ( mp_hal_is_interrupted() ) { return 0; } -#endif } // Copy received data. Lock out write interrupt handler while copying. diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 69e75ff27..fc9a146c3 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -62,60 +62,61 @@ STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { bleio_peripheral_obj_t *self = (bleio_peripheral_obj_t*)self_in; switch (ble_evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: { - // Central has connected. - ble_gap_conn_params_t conn_params; - self->conn_handle = ble_evt->evt.gap_evt.conn_handle; - sd_ble_gap_ppcp_get(&conn_params); - sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); - break; - } + case BLE_GAP_EVT_CONNECTED: { + // Central has connected. + ble_gap_conn_params_t conn_params; + self->conn_handle = ble_evt->evt.gap_evt.conn_handle; + sd_ble_gap_ppcp_get(&conn_params); + sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); + break; + } - case BLE_GAP_EVT_DISCONNECTED: - // Central has disconnected. - self->conn_handle = BLE_CONN_HANDLE_INVALID; - break; - - case BLE_GAP_EVT_PHY_UPDATE_REQUEST: { - ble_gap_phys_t const phys = { - .rx_phys = BLE_GAP_PHY_AUTO, - .tx_phys = BLE_GAP_PHY_AUTO, - }; - sd_ble_gap_phy_update(ble_evt->evt.gap_evt.conn_handle, &phys); - break; - } + case BLE_GAP_EVT_DISCONNECTED: + // Central has disconnected. + self->conn_handle = BLE_CONN_HANDLE_INVALID; + break; + + case BLE_GAP_EVT_PHY_UPDATE_REQUEST: { + ble_gap_phys_t const phys = { + .rx_phys = BLE_GAP_PHY_AUTO, + .tx_phys = BLE_GAP_PHY_AUTO, + }; + sd_ble_gap_phy_update(ble_evt->evt.gap_evt.conn_handle, &phys); + break; + } - case BLE_GAP_EVT_ADV_SET_TERMINATED: - // Someday may handle timeouts or limit reached. - break; + case BLE_GAP_EVT_ADV_SET_TERMINATED: + // Someday may handle timeouts or limit reached. + break; - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: - sd_ble_gap_sec_params_reply(self->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); - break; + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + sd_ble_gap_sec_params_reply(self->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); + break; - case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: { - ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; - sd_ble_gap_conn_param_update(self->conn_handle, &request->conn_params); - break; - } + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: { + ble_gap_evt_conn_param_update_request_t *request = + &ble_evt->evt.gap_evt.params.conn_param_update_request; + sd_ble_gap_conn_param_update(self->conn_handle, &request->conn_params); + break; + } - case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: - sd_ble_gap_data_length_update(self->conn_handle, NULL, NULL); - break; + case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: + sd_ble_gap_data_length_update(self->conn_handle, NULL, NULL); + break; - case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: { - sd_ble_gatts_exchange_mtu_reply(self->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); - break; - } + case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: { + sd_ble_gatts_exchange_mtu_reply(self->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); + break; + } - case BLE_GATTS_EVT_SYS_ATTR_MISSING: - sd_ble_gatts_sys_attr_set(self->conn_handle, NULL, 0, 0); - break; + case BLE_GATTS_EVT_SYS_ATTR_MISSING: + sd_ble_gatts_sys_attr_set(self->conn_handle, NULL, 0, 0); + break; - default: - // For debugging. - // mp_printf(&mp_plat_print, "Unhandled peripheral event: 0x%04x\n", ble_evt->header.evt_id); - break; + default: + // For debugging. + // mp_printf(&mp_plat_print, "Unhandled peripheral event: 0x%04x\n", ble_evt->header.evt_id); + break; } } diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index dd2dd0d50..efadcbb2a 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -141,6 +141,25 @@ STATIC mp_obj_t bleio_central_disconnect(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_disconnect_obj, bleio_central_disconnect); +//| .. attribute:: connected +//| +//| True if connected to a remove peripheral. +//| +STATIC mp_obj_t bleio_central_get_connected(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_bool(common_hal_bleio_central_get_connected(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_connected_obj, bleio_central_get_connected); + +const mp_obj_property_t bleio_central_connected_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_central_get_connected_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + + //| .. attribute:: remote_services (read-only) //| //| Empty until connected, then a list of services provided by the remote peripheral. @@ -161,11 +180,12 @@ const mp_obj_property_t bleio_central_remote_services_obj = { STATIC const mp_rom_map_elem_t bleio_central_locals_dict_table[] = { // Methods - { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&bleio_central_connect_obj) }, - { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_central_disconnect_obj) }, + { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&bleio_central_connect_obj) }, + { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_central_disconnect_obj) }, // Properties - { MP_ROM_QSTR(MP_QSTR_remote_services), MP_ROM_PTR(&bleio_central_remote_services_obj) }, + { MP_ROM_QSTR(MP_QSTR_connected), MP_ROM_PTR(&bleio_central_connected_obj) }, + { MP_ROM_QSTR(MP_QSTR_remote_services), MP_ROM_PTR(&bleio_central_remote_services_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bleio_central_locals_dict, bleio_central_locals_dict_table); diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h index 542ba8fa2..2ca423945 100644 --- a/shared-bindings/bleio/Central.h +++ b/shared-bindings/bleio/Central.h @@ -36,6 +36,7 @@ extern const mp_obj_type_t bleio_central_type; extern void common_hal_bleio_central_construct(bleio_central_obj_t *self); extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_obj_t *address, mp_float_t timeout, mp_obj_t service_uuids); extern void common_hal_bleio_central_disconnect(bleio_central_obj_t *self); +extern bool common_hal_bleio_central_get_connected(bleio_central_obj_t *self); extern mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index 827f4947b..26f9e012b 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -49,10 +49,13 @@ STATIC void raise_error_if_not_connected(bleio_characteristic_buffer_obj_t *self //| //| .. class:: CharacteristicBuffer(characteristic, *, timeout=1, buffer_size=64) //| -//| Create a new Characteristic object identified by the specified UUID. +//| Monitor the given Characteristic. Each time a new value is written to the Characteristic +//| add the newly-written bytes to a FIFO buffer. //| -//| :param bleio.Characteristic characteristic: The characteristic to monitor -//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters.//| +//| :param bleio.Characteristic characteristic: The Characteristic to monitor. +//| It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic +//| in a remote Service that a Central has connected to. +//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters. //| :param int buffer_size: Size of ring buffer that stores incoming data coming from client. //| Must be >= 1. //| diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 37a765ae9..665f5baaf 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -140,7 +140,6 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar STATIC mp_obj_t bleio_peripheral_get_connected(mp_obj_t self_in) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); - // Return list as a tuple so user won't be able to change it. return mp_obj_new_bool(common_hal_bleio_peripheral_get_connected(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_get_connected_obj, bleio_peripheral_get_connected); diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index e6bb7dcc3..f8993ef61 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -80,7 +80,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, // Copy the characteristics list and validate its items. mp_obj_t char_list_obj = mp_obj_new_list(0, NULL); - mp_obj_list_t *char_list = MP_OBJ_FROM_PTR(char_list); + mp_obj_list_t *char_list = MP_OBJ_TO_PTR(char_list_obj); while ((characteristic_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(characteristic_obj, &bleio_characteristic_type)) { -- cgit v1.2.3 From 6e5d70fa1929a6ab2b2de4d9fb0fb224d7618700 Mon Sep 17 00:00:00 2001 From: iot49 Date: Wed, 3 Jul 2019 12:02:01 -0700 Subject: changed type of receiver_buffer_size to uint16_t --- ports/nrf/common-hal/busio/UART.c | 2 +- shared-bindings/busio/UART.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 593914afc..b9e9e5538 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -131,7 +131,7 @@ void uart_reset(void) { void common_hal_busio_uart_construct (busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, - uint8_t receiver_buffer_size) { + uint16_t receiver_buffer_size) { // Find a free UART peripheral. self->uarte = NULL; for (size_t i = 0 ; i < MP_ARRAY_SIZE(nrfx_uartes); i++) { diff --git a/shared-bindings/busio/UART.h b/shared-bindings/busio/UART.h index e171f8bb4..776a996be 100644 --- a/shared-bindings/busio/UART.h +++ b/shared-bindings/busio/UART.h @@ -42,7 +42,7 @@ typedef enum { extern void common_hal_busio_uart_construct(busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, - uint8_t receiver_buffer_size); + uint16_t receiver_buffer_size); extern void common_hal_busio_uart_deinit(busio_uart_obj_t *self); extern bool common_hal_busio_uart_deinited(busio_uart_obj_t *self); -- cgit v1.2.3 From f1256c0b35d8ff3e1893bd345a6ff29c2ee2e752 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 4 Jul 2019 01:18:16 -0500 Subject: add script to gather module support matrix info; add initial json file --- docs/shared_bindings_matrix.py | 130 +++++++++++ shared-bindings/support_matrix.json | 441 ++++++++++++++++++++++++++++++++++++ 2 files changed, 571 insertions(+) create mode 100644 docs/shared_bindings_matrix.py create mode 100644 shared-bindings/support_matrix.json (limited to 'shared-bindings') diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py new file mode 100644 index 000000000..ebcadb7ad --- /dev/null +++ b/docs/shared_bindings_matrix.py @@ -0,0 +1,130 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Michael Schroeder +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +import json +import os +import re + + +SUPPORTED_PORTS = ["atmel-samd", "nrf"] + + +def get_shared_bindings(): + """ Get a list of modules in shared-bindings based on folder names + """ + return [item for item in os.listdir("./shared-bindings")] + + +def read_mpconfig(): + """ Open 'circuitpy_mpconfig.mk' and return the contents. + """ + configs = [] + with open("py/circuitpy_mpconfig.mk") as mpconfig: + configs = mpconfig.read() + + return configs + + +def build_json(modules, configs): + """ Establish the base of the JSON file, based on the contents from + `configs`. Base will contain module names, if they're part of + the `FULL_BUILD`, or their default value (0 | 1). + + """ + base_json = dict() + full_build = False + for module in modules: + full_name = module + search_name = module.lstrip("_") + re_pattern = "CIRCUITPY_{}\s=\s(.+)".format(search_name.upper()) + find_config = re.search(re_pattern, configs) + #print(module, "|", find_config) + if not find_config: + continue + full_build = int("FULL_BUILD" in find_config[0]) + #print(find_config[1]) + if not full_build: + default_val = find_config[1] + else: + default_val = "None" + base_json[search_name] = { + "name": full_name, + "full_build": str(full_build), + "default_value": default_val, + "excluded": [] + } + + return get_excluded_boards(base_json) + + +def get_excluded_boards(base_json): + """ Cycles through each board's `mpconfigboard.mk` file to determine + if each module is included or not. Boards are selected by existence + in a port listed in `SUPPORTED_PORTS` (e.g. `/port/nrf/feather_52840`) + """ + modules = list(base_json.keys()) + for port in SUPPORTED_PORTS: + port_dir = "ports/{}/boards".format(port) + with os.scandir(port_dir) as boards: + for entry in boards: + if not entry.is_dir(): + continue + contents = "" + board_dir = os.path.join(entry.path, "mpconfigboard.mk") + #print(board_dir) + with open(board_dir) as board: + contents = board.read() + for module in modules: + # check if board uses `SMALL_BUILD`. if yes, and current + # module is marked as `FULL_BUILD`, board is excluded + small_build = re.search("CIRCUITPY_SMALL_BUILD = 1", contents) + if small_build and base_json[module]["full_build"] == "1": + base_json[module]["excluded"].append(entry.name) + continue + + # check if module is specifically disabled for this board + re_pattern = "CIRCUITPY_{}\s=\s(\w)".format(module.upper()) + find_module = re.search(re_pattern, contents) + if not find_module: + continue + if (find_module[1] == "0" and + find_module[1] != base_json[module]["default_value"]): + base_json[module]["excluded"].append(entry.name) + + return base_json + +if __name__ == "__main__": + modules = get_shared_bindings() + configs = read_mpconfig() + base = build_json(sorted(modules), configs) + + final_json = json.dumps(base, indent=2) + + shared_bindings_json = 'support_matrix.json' + if 'TRAVIS' in os.environ: + shared_bindings_json = os.path.join('$HOME', shared_bindings_json) + else: + print(final_json) + shared_bindings_json = os.path.join('shared-bindings', shared_bindings_json) + with open(shared_bindings_json, "w") as matrix: + json.dump(base, matrix, indent=2) diff --git a/shared-bindings/support_matrix.json b/shared-bindings/support_matrix.json new file mode 100644 index 000000000..2d2a7d1ed --- /dev/null +++ b/shared-bindings/support_matrix.json @@ -0,0 +1,441 @@ +{ + "pew": { + "name": "_pew", + "full_build": "0", + "default_value": "0", + "excluded": [] + }, + "pixelbuf": { + "name": "_pixelbuf", + "full_build": "1", + "default_value": "None", + "excluded": [ + "circuitplayground_express_crickit", + "feather_m0_rfm69", + "arduino_mkr1300", + "bast_pro_mini_m0", + "feather_m0_adalogger", + "ugame10", + "pewpew10", + "trinket_m0", + "catwan_usbstick", + "pirkey_m0", + "feather_m0_rfm9x", + "sparkfun_samd21_mini", + "feather_m0_basic", + "gemma_m0", + "arduino_mkrzero", + "meowmeow", + "escornabot_makech", + "sparkfun_samd21_dev", + "arduino_zero", + "uchip" + ] + }, + "stage": { + "name": "_stage", + "full_build": "0", + "default_value": "0", + "excluded": [] + }, + "analogio": { + "name": "analogio", + "full_build": "0", + "default_value": "1", + "excluded": [ + "pirkey_m0" + ] + }, + "audiobusio": { + "name": "audiobusio", + "full_build": "1", + "default_value": "None", + "excluded": [ + "feather_m0_rfm69", + "arduino_mkr1300", + "kicksat-sprite", + "bast_pro_mini_m0", + "feather_m0_adalogger", + "ugame10", + "pewpew10", + "mini_sam_m4", + "trinket_m0", + "catwan_usbstick", + "pirkey_m0", + "sparkfun_lumidrive", + "feather_m0_rfm9x", + "sparkfun_samd21_mini", + "capablerobot_usbhub", + "feather_m0_basic", + "gemma_m0", + "hallowing_m0_express", + "arduino_mkrzero", + "trellis_m4_express", + "feather_radiofruit_zigbee", + "itsybitsy_m4_express", + "meowmeow", + "cp32-m4", + "escornabot_makech", + "sparkfun_samd21_dev", + "arduino_zero", + "uchip" + ] + }, + "audioio": { + "name": "audioio", + "full_build": "1", + "default_value": "None", + "excluded": [ + "feather_m0_rfm69", + "arduino_mkr1300", + "bast_pro_mini_m0", + "feather_m0_adalogger", + "pewpew10", + "trinket_m0", + "catwan_usbstick", + "pirkey_m0", + "sparkfun_lumidrive", + "feather_m0_rfm9x", + "sparkfun_samd21_mini", + "feather_m0_basic", + "gemma_m0", + "arduino_mkrzero", + "feather_radiofruit_zigbee", + "meowmeow", + "escornabot_makech", + "sparkfun_samd21_dev", + "arduino_zero", + "uchip" + ] + }, + "bitbangio": { + "name": "bitbangio", + "full_build": "1", + "default_value": "None", + "excluded": [ + "feather_m0_rfm69", + "arduino_mkr1300", + "bast_pro_mini_m0", + "feather_m0_adalogger", + "pewpew10", + "feather_m0_express_crickit", + "trinket_m0", + "catwan_usbstick", + "pirkey_m0", + "feather_m0_rfm9x", + "sparkfun_samd21_mini", + "feather_m0_basic", + "gemma_m0", + "arduino_mkrzero", + "meowmeow", + "escornabot_makech", + "sparkfun_samd21_dev", + "arduino_zero", + "uchip" + ] + }, + "bleio": { + "name": "bleio", + "full_build": "0", + "default_value": "0", + "excluded": [] + }, + "board": { + "name": "board", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "busio": { + "name": "busio", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "digitalio": { + "name": "digitalio", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "displayio": { + "name": "displayio", + "full_build": "1", + "default_value": "None", + "excluded": [ + "circuitplayground_express_crickit", + "feather_m0_rfm69", + "arduino_mkr1300", + "kicksat-sprite", + "bast_pro_mini_m0", + "feather_m0_adalogger", + "circuitplayground_express", + "pewpew10", + "feather_m0_express_crickit", + "trinket_m0", + "catwan_usbstick", + "pirkey_m0", + "feather_m0_rfm9x", + "sparkfun_samd21_mini", + "robohatmm1", + "feather_m0_basic", + "gemma_m0", + "arduino_mkrzero", + "meowmeow", + "escornabot_makech", + "sparkfun_samd21_dev", + "arduino_zero", + "uchip" + ] + }, + "frequencyio": { + "name": "frequencyio", + "full_build": "1", + "default_value": "None", + "excluded": [ + "circuitplayground_express_crickit", + "feather_m0_rfm69", + "arduino_mkr1300", + "bast_pro_mini_m0", + "feather_m0_adalogger", + "ugame10", + "circuitplayground_express", + "pewpew10", + "feather_m0_express_crickit", + "trinket_m0", + "catwan_usbstick", + "pirkey_m0", + "feather_m0_rfm9x", + "sparkfun_samd21_mini", + "robohatmm1", + "feather_m0_basic", + "gemma_m0", + "hallowing_m0_express", + "arduino_mkrzero", + "meowmeow", + "escornabot_makech", + "sparkfun_samd21_dev", + "arduino_zero", + "uchip" + ] + }, + "gamepad": { + "name": "gamepad", + "full_build": "1", + "default_value": "None", + "excluded": [ + "feather_m0_rfm69", + "arduino_mkr1300", + "bast_pro_mini_m0", + "feather_m0_adalogger", + "pewpew10", + "feather_m0_express_crickit", + "trinket_m0", + "catwan_usbstick", + "pirkey_m0", + "feather_m0_rfm9x", + "sparkfun_samd21_mini", + "feather_m0_basic", + "gemma_m0", + "arduino_mkrzero", + "meowmeow", + "escornabot_makech", + "sparkfun_samd21_dev", + "arduino_zero", + "uchip" + ] + }, + "gamepadshift": { + "name": "gamepadshift", + "full_build": "0", + "default_value": "0", + "excluded": [] + }, + "i2cslave": { + "name": "i2cslave", + "full_build": "1", + "default_value": "None", + "excluded": [ + "circuitplayground_express_crickit", + "feather_m0_rfm69", + "arduino_mkr1300", + "bast_pro_mini_m0", + "feather_m0_adalogger", + "ugame10", + "circuitplayground_express", + "pewpew10", + "feather_m0_express_crickit", + "trinket_m0", + "catwan_usbstick", + "pirkey_m0", + "feather_m0_rfm9x", + "sparkfun_samd21_mini", + "feather_m0_basic", + "gemma_m0", + "hallowing_m0_express", + "arduino_mkrzero", + "meowmeow", + "escornabot_makech", + "sparkfun_samd21_dev", + "arduino_zero", + "uchip" + ] + }, + "math": { + "name": "math", + "full_build": "0", + "default_value": "1", + "excluded": [ + "pirkey_m0" + ] + }, + "microcontroller": { + "name": "microcontroller", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "neopixel_write": { + "name": "neopixel_write", + "full_build": "0", + "default_value": "1", + "excluded": [ + "ugame10", + "pirkey_m0" + ] + }, + "network": { + "name": "network", + "full_build": "0", + "default_value": "0", + "excluded": [] + }, + "nvm": { + "name": "nvm", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "os": { + "name": "os", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "ps2io": { + "name": "ps2io", + "full_build": "0", + "default_value": "0", + "excluded": [] + }, + "pulseio": { + "name": "pulseio", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "random": { + "name": "random", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "rotaryio": { + "name": "rotaryio", + "full_build": "0", + "default_value": "1", + "excluded": [ + "pewpew10", + "pirkey_m0" + ] + }, + "rtc": { + "name": "rtc", + "full_build": "0", + "default_value": "1", + "excluded": [ + "ugame10", + "pewpew10", + "pirkey_m0" + ] + }, + "storage": { + "name": "storage", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "struct": { + "name": "struct", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "supervisor": { + "name": "supervisor", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "time": { + "name": "time", + "full_build": "0", + "default_value": "1", + "excluded": [] + }, + "touchio": { + "name": "touchio", + "full_build": "0", + "default_value": "1", + "excluded": [ + "kicksat-sprite", + "ugame10", + "datalore_ip_m4", + "pybadge", + "pyportal", + "sam32", + "mini_sam_m4", + "grandcentral_m4_express", + "feather_m4_express", + "pirkey_m0", + "pygamer", + "capablerobot_usbhub", + "metro_m4_airlift_lite", + "trellis_m4_express", + "itsybitsy_m4_express", + "pygamer_advance", + "metro_m4_express", + "cp32-m4", + "pybadge_airlift" + ] + }, + "uheap": { + "name": "uheap", + "full_build": "0", + "default_value": "0", + "excluded": [] + }, + "usb_hid": { + "name": "usb_hid", + "full_build": "0", + "default_value": "1", + "excluded": [ + "ugame10" + ] + }, + "usb_midi": { + "name": "usb_midi", + "full_build": "0", + "default_value": "1", + "excluded": [ + "ugame10", + "pewpew10" + ] + }, + "ustack": { + "name": "ustack", + "full_build": "0", + "default_value": "0", + "excluded": [] + } +} \ No newline at end of file -- cgit v1.2.3 From 4342383d9595914786475aa55c001864333ddcc1 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 4 Jul 2019 01:19:56 -0500 Subject: add jinja extension; update shared-bindings/index.rst to use jinja --- conf.py | 17 ++++++++++++++++- docs/rstjinja.py | 24 ++++++++++++++++++++++++ shared-bindings/index.rst | 45 ++++----------------------------------------- 3 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 docs/rstjinja.py (limited to 'shared-bindings') diff --git a/conf.py b/conf.py index 858657388..3bc7d2764 100644 --- a/conf.py +++ b/conf.py @@ -13,6 +13,7 @@ # All configuration values have a default; values that are commented out # serve to show the default. +import json import sys import os @@ -26,6 +27,19 @@ sys.path.insert(0, os.path.abspath('.')) master_doc = 'docs/index' +# Grab the JSON values to use while building the module support matrix +# in 'shared-bindings/index.rst' +shared_bindings_json = 'support_matrix.json' +if 'TRAVIS' in os.environ: + shared_bindings_json = os.path.join('$HOME', shared_bindings_json) +else: + shared_bindings_json = os.path.join('shared-bindings', shared_bindings_json) +with open(shared_bindings_json) as json_file: + modules_support_matrix = json.load(json_file) +html_context = { + 'support_matrix': modules_support_matrix +} + # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. @@ -40,7 +54,8 @@ extensions = [ 'sphinxcontrib.rsvgconverter', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', - 'sphinx.ext.coverage' + 'sphinx.ext.coverage', + 'rstjinja' ] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/rstjinja.py b/docs/rstjinja.py new file mode 100644 index 000000000..a92f2280c --- /dev/null +++ b/docs/rstjinja.py @@ -0,0 +1,24 @@ +# Derived from code on Eric Holscher's blog, found at: +# https://www.ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/ + +def rstjinja(app, docname, source): + """ + Render our pages as a jinja template for fancy templating goodness. + """ + # Make sure we're outputting HTML + if app.builder.format != 'html': + return + + # we only want our one jinja template to run through this func + if "shared-bindings/index" not in docname: + return + + src = source[0] + print(docname) + rendered = app.builder.templates.render_string( + src, app.config.html_context + ) + source[0] = rendered + +def setup(app): + app.connect("source-read", rstjinja) diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index 8f9bbbb31..f32745bc7 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -21,48 +21,11 @@ Modules Support Matrix --------------- -NOTE 1: **All Supported** means the following ports are supported: SAMD21, SAMD21 Express, -SAMD51, SAMD51 Express, and ESP8266. - -NOTE 2: **SAMD** and/or **SAMD Express** without additional numbers, means both SAMD21 & SAMD51 versions -are supported. - -NOTE 3: The `pIRkey SAMD21 board `_ is specialized and may not -have modules as listed below. ================= ============================== -Module Supported Ports +Module Not Available On ================= ============================== -`analogio` **All Supported** -`audiobusio` **SAMD/SAMD Express** -`audioio` **SAMD Express** -`binascii` **ESP8266** -`bitbangio` **SAMD Express, ESP8266** -`board` **All Supported** -`bleio` **nRF** -`busio` **All Supported** -`digitalio` **All Supported** -`frequencyio` **SAMD51** -`gamepad` **SAMD Express, nRF** -`hashlib` **ESP8266** -`i2cslave` **SAMD Express** -`math` **All Supported** -`microcontroller` **All Supported** -`multiterminal` **ESP8266** -`neopixel_write` **All Supported** -`nvm` **SAMD Express** -`os` **All Supported** -`pulseio` **SAMD/SAMD Express** -`ps2io` **SAMD/SAMD Express** -`random` **All Supported** -`rotaryio` **SAMD51, SAMD Express** -`storage` **All Supported** -`struct` **All Supported** -`supervisor` **SAMD/SAMD Express** -`time` **All Supported** -`touchio` **SAMD/SAMD Express** -`uheap` **Debug (All)** -`usb_hid` **SAMD/SAMD Express** -`_pixelbuf` **SAMD Express** -`_stage` **SAMD/SAMD Express** +{%- for key, value in support_matrix|dictsort %} +{{ value.name.ljust(18) }} {{ value.excluded|join(", ") }}{{ '\n'|e }} +{%- endfor %} ================= ============================== -- cgit v1.2.3 From 09ddff8df1349c590e6c0533b6f5085fbcb92483 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 7 Jul 2019 00:07:47 -0400 Subject: WIP: Need descriptors for Central CCCD discovery; not done yet --- ports/nrf/common-hal/bleio/Central.c | 163 +++++++++++++++++++++++----- ports/nrf/common-hal/bleio/Central.h | 3 +- ports/nrf/common-hal/bleio/Characteristic.c | 27 +++-- ports/nrf/common-hal/bleio/Characteristic.h | 3 +- ports/nrf/common-hal/bleio/Descriptor.c | 1 - ports/nrf/common-hal/bleio/Descriptor.h | 2 + ports/nrf/common-hal/bleio/Peripheral.c | 4 + ports/nrf/common-hal/bleio/Service.c | 9 +- ports/nrf/common-hal/bleio/Service.h | 3 +- shared-bindings/bleio/Central.c | 4 +- shared-bindings/bleio/Central.h | 2 +- shared-bindings/bleio/Descriptor.c | 3 - shared-bindings/bleio/Peripheral.c | 16 +++ shared-bindings/bleio/Peripheral.h | 1 + 14 files changed, 183 insertions(+), 58 deletions(-) (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index 5bd5a6321..f7077f4b9 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -37,10 +37,13 @@ #include "shared-bindings/bleio/Adapter.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/Central.h" +#include "shared-bindings/bleio/Descriptor.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/UUID.h" static bleio_service_obj_t *m_char_discovery_service; +static bleio_characteristic_obj_t *m_desc_discovery_characteristic; + static volatile bool m_discovery_in_process; static volatile bool m_discovery_successful; @@ -84,6 +87,28 @@ STATIC bool discover_next_characteristics(bleio_central_obj_t *self, bleio_servi return m_discovery_successful; } +STATIC bool discover_next_descriptors(bleio_central_obj_t *self, bleio_characteristic_obj_t *characteristic, uint16_t start_handle, uint16_t end_handle) { + m_desc_discovery_characteristic = characteristic; + + ble_gattc_handle_range_t handle_range; + handle_range.start_handle = start_handle; + handle_range.end_handle = end_handle; + + m_discovery_successful = false; + m_discovery_in_process = true; + + uint32_t err_code = sd_ble_gattc_characteristics_discover(self->conn_handle, &handle_range); + if (err_code != NRF_SUCCESS) { + return false; + } + + // Wait for a discovery event. + while (m_discovery_in_process) { + MICROPY_VM_HOOK_LOOP; + } + return m_discovery_successful; +} + STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *response, bleio_central_obj_t *central) { for (size_t i = 0; i < response->count; ++i) { ble_gattc_service_t *gattc_service = &response->services[i]; @@ -127,25 +152,30 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); characteristic->base.type = &bleio_characteristic_type; + bleio_uuid_obj_t *uuid = NULL; + if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) { // Known characteristic UUID. - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + uuid = m_new_obj(bleio_uuid_obj_t); uuid->base.type = &bleio_uuid_type; bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); - characteristic->uuid = uuid; } else { // The discovery response contained a 128-bit UUID that has not yet been registered with the // softdevice via sd_ble_uuid_vs_add(). We need to fetch the 128-bit value and register it. - // For now, just set the UUID to NULL. - characteristic->uuid = NULL; + // For now, just leave the UUID as NULL. } - characteristic->props.broadcast = gattc_char->char_props.broadcast; - characteristic->props.indicate = gattc_char->char_props.indicate; - characteristic->props.notify = gattc_char->char_props.notify; - characteristic->props.read = gattc_char->char_props.read; - characteristic->props.write = gattc_char->char_props.write; - characteristic->props.write_no_response = gattc_char->char_props.write_wo_resp; + bleio_characteristic_properties_t props; + + props.broadcast = gattc_char->char_props.broadcast; + props.indicate = gattc_char->char_props.indicate; + props.notify = gattc_char->char_props.notify; + props.read = gattc_char->char_props.read; + props.write = gattc_char->char_props.write; + props.write_no_response = gattc_char->char_props.write_wo_resp; + + // Call common_hal_bleio_characteristic_construct() to set up evt handler. + common_hal_bleio_characteristic_construct(characteristic, uuid, props); characteristic->handle = gattc_char->handle_value; characteristic->service = m_char_discovery_service; @@ -158,6 +188,39 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio m_discovery_in_process = false; } +STATIC void on_desc_discovery_rsp(ble_gattc_evt_desc_disc_rsp_t *response, bleio_central_obj_t *central) { + for (size_t i = 0; i < response->count; ++i) { + ble_gattc_desc_t *gattc_desc = &response->descs[i]; + + bleio_descriptor_obj_t *descriptor = m_new_obj(bleio_descriptor_obj_t); + descriptor->base.type = &bleio_descriptor_type; + + bleio_uuid_obj_t *uuid = NULL; + + if (gattc_desc->uuid.type != BLE_UUID_TYPE_UNKNOWN) { + // Known descriptor UUID. + uuid = m_new_obj(bleio_uuid_obj_t); + uuid->base.type = &bleio_uuid_type; + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_desc->uuid); + } else { + // The discovery response contained a 128-bit UUID that has not yet been registered with the + // softdevice via sd_ble_uuid_vs_add(). We need to fetch the 128-bit value and register it. + // For now, just leave the UUID as NULL. + } + + common_hal_bleio_descriptor_construct(descriptor, uuid); + descriptor->handle = gattc_desc->handle; + descriptor->characteristic = m_desc_discovery_characteristic; + + mp_obj_list_append(m_desc_discovery_characteristic->descriptor_list, MP_OBJ_FROM_PTR(descriptor)); + } + + if (response->count > 0) { + m_discovery_successful = true; + } + m_discovery_in_process = false; +} + STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { bleio_central_obj_t *central = (bleio_central_obj_t*)central_in; @@ -186,17 +249,24 @@ STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); break; + case BLE_GATTC_EVT_DESC_DISC_RSP: + on_desc_discovery_rsp(&ble_evt->evt.gattc_evt.params.desc_disc_rsp, central); + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); break; - case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: - { + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: { ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; sd_ble_gap_conn_param_update(central->conn_handle, &request->conn_params); break; } + + default: + // For debugging. + mp_printf(&mp_plat_print, "Unhandled central event: 0x%04x\n", ble_evt->header.evt_id); + break; } } @@ -257,16 +327,16 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o // List of service UUID's not given, so discover all available services. - uint16_t next_start_handle = BLE_GATT_HANDLE_START; + uint16_t next_service_start_handle = BLE_GATT_HANDLE_START; - while (discover_next_services(self, next_start_handle, MP_OBJ_NULL)) { + while (discover_next_services(self, next_service_start_handle, MP_OBJ_NULL)) { // discover_next_services() appends to service_list. - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); // Get the most recently discovered service, and then ask for services // whose handles start after the last attribute handle inside that service. - const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; - next_start_handle = service->end_handle + 1; + const bleio_service_obj_t *service = + MP_OBJ_TO_PTR(self->service_list->items[self->service_list->len - 1]); + next_service_start_handle = service->end_handle + 1; } } else { mp_obj_iter_buf_t iter_buf; @@ -289,30 +359,65 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o } - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); - for (size_t i = 0; i < service_list->len; ++i) { - bleio_service_obj_t *service = service_list->items[i]; + for (size_t service_idx = 0; service_idx < self->service_list->len; ++service_idx) { + bleio_service_obj_t *service = MP_OBJ_TO_PTR(self->service_list->items[service_idx]); // Skip the service if it had an unknown (unregistered) UUID. if (service->uuid == NULL) { continue; } - uint16_t next_start_handle = service->start_handle; + uint16_t next_char_start_handle = service->start_handle; // Stop when we go past the end of the range of handles for this service or // discovery call returns nothing. - while (next_start_handle <= service->end_handle && - discover_next_characteristics(self, service, next_start_handle)) { + // discover_next_characteristics() appends to the characteristic_list. + while (next_char_start_handle <= service->end_handle && + discover_next_characteristics(self, service, next_char_start_handle)) { - // discover_next_characteristics() appends to the characteristic_list. - const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); - // Get the most recently discovered characteristic. + // Get the most recently discovered characteristic, and then ask for characteristics + // whose handles start after the last attribute handle inside that characteristic. const bleio_characteristic_obj_t *characteristic = - characteristic_list->items[characteristic_list->len - 1]; - next_start_handle = characteristic->handle + 1; + MP_OBJ_TO_PTR(service->characteristic_list->items[service->characteristic_list->len - 1]); + next_char_start_handle = characteristic->handle + 1; + } + + // Got characteristics for this service. Now discover descriptors for each characteristic. + for (size_t char_idx = 0; char_idx < service->characteristic_list->len; ++char_idx) { + bleio_characteristic_obj_t *characteristic = + MP_OBJ_TO_PTR(service->characteristic_list->items[char_idx]); + const bool last_characteristic = char_idx == service->characteristic_list->len - 1; + bleio_characteristic_obj_t *next_characteristic = last_characteristic + ? NULL + : MP_OBJ_TO_PTR(service->characteristic_list->items[char_idx + 1]); + + // Skip the characteristic if it had an unknown (unregistered) UUID. + if (characteristic->uuid == NULL) { + continue; + } + + uint16_t next_desc_start_handle = characteristic->handle + 1; + + // Don't run past the end of this service or the beginning of the next characteristic. + uint16_t next_desc_end_handle = next_characteristic == NULL + ? service->end_handle + : next_characteristic->handle; + + // Stop when we go past the end of the range of handles for this service or + // discovery call returns nothing. + // discover_next_descriptors() appends to the descriptor_list. + while (next_desc_start_handle <= service->end_handle && + discover_next_descriptors(self, characteristic, next_desc_start_handle, next_desc_end_handle)) { + + // Get the most recently discovered descriptor, and then ask for descriptors + // whose handles start after that descriptor's handle. + const bleio_descriptor_obj_t *descriptor = + MP_OBJ_TO_PTR(characteristic->descriptor_list->items[characteristic->descriptor_list->len - 1]); + next_desc_start_handle = descriptor->handle + 1; + } } + } } @@ -324,6 +429,6 @@ bool common_hal_bleio_central_get_connected(bleio_central_obj_t *self) { return self->conn_handle != BLE_CONN_HANDLE_INVALID; } -mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self) { +mp_obj_list_t *common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self) { return self->service_list; } diff --git a/ports/nrf/common-hal/bleio/Central.h b/ports/nrf/common-hal/bleio/Central.h index 8b38e87ac..ac1670088 100644 --- a/ports/nrf/common-hal/bleio/Central.h +++ b/ports/nrf/common-hal/bleio/Central.h @@ -30,6 +30,7 @@ #include +#include "py/objlist.h" #include "shared-module/bleio/__init__.h" #include "shared-module/bleio/Address.h" @@ -38,7 +39,7 @@ typedef struct { gatt_role_t gatt_role; volatile bool waiting_to_connect; volatile uint16_t conn_handle; - mp_obj_t service_list; + mp_obj_list_t *service_list; } bleio_central_obj_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index c00d8c30b..1db0a9378 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -194,27 +194,26 @@ STATIC void characteristic_on_ble_evt(ble_evt_t *ble_evt, void *param) { // More events may be handled later, so keep this as a switch. - case BLE_GATTC_EVT_READ_RSP: - { - ble_gattc_evt_read_rsp_t *response = &ble_evt->evt.gattc_evt.params.read_rsp; - m_read_characteristic->value_data = mp_obj_new_bytearray(response->len, response->data); - // Indicate to busy-wait loop that we've read the characteristic. - m_read_characteristic = NULL; - break; - } + case BLE_GATTC_EVT_READ_RSP: { + ble_gattc_evt_read_rsp_t *response = &ble_evt->evt.gattc_evt.params.read_rsp; + m_read_characteristic->value_data = mp_obj_new_bytearray(response->len, response->data); + // Indicate to busy-wait loop that we've read the characteristic. + m_read_characteristic = NULL; + break; + } - // For debugging. - default: - // mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id); - break; + // For debugging. + default: + // mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id); + break; } } void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props) { - self->service = NULL; + self->service = mp_const_none; self->uuid = uuid; - self->value_data = NULL; + self->value_data = mp_const_none; self->props = props; self->handle = BLE_GATT_HANDLE_INVALID; diff --git a/ports/nrf/common-hal/bleio/Characteristic.h b/ports/nrf/common-hal/bleio/Characteristic.h index 451bae471..7cb227596 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.h +++ b/ports/nrf/common-hal/bleio/Characteristic.h @@ -36,9 +36,10 @@ typedef struct { mp_obj_base_t base; bleio_service_obj_t *service; bleio_uuid_obj_t *uuid; - mp_obj_t value_data; + volatile mp_obj_t value_data; uint16_t handle; bleio_characteristic_properties_t props; + mp_obj_list_t *descriptor_list; uint16_t user_desc_handle; uint16_t cccd_handle; uint16_t sccd_handle; diff --git a/ports/nrf/common-hal/bleio/Descriptor.c b/ports/nrf/common-hal/bleio/Descriptor.c index 418cc07c1..d3f2a0ff8 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.c +++ b/ports/nrf/common-hal/bleio/Descriptor.c @@ -30,7 +30,6 @@ #include "shared-bindings/bleio/UUID.h" void common_hal_bleio_descriptor_construct(bleio_descriptor_obj_t *self, bleio_uuid_obj_t *uuid) { - // TODO: set handle ??? self->uuid = uuid; } diff --git a/ports/nrf/common-hal/bleio/Descriptor.h b/ports/nrf/common-hal/bleio/Descriptor.h index 47552f39d..b7af6a42f 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.h +++ b/ports/nrf/common-hal/bleio/Descriptor.h @@ -30,11 +30,13 @@ #define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_DESCRIPTOR_H #include "py/obj.h" +#include "common-hal/bleio/Characteristic.h" #include "common-hal/bleio/UUID.h" typedef struct { mp_obj_base_t base; uint16_t handle; + bleio_characteristic_obj_t *characteristic; bleio_uuid_obj_t *uuid; } bleio_descriptor_obj_t; diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index fc9a146c3..b31bb84b0 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -243,3 +243,7 @@ void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *self) mp_raise_OSError_msg_varg(translate("Failed to stop advertising, err 0x%04x"), err_code); } } + +void common_hal_bleio_peripheral_disconnect(bleio_peripheral_obj_t *self) { + sd_ble_gap_disconnect(self->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); +} diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 55193c5cb..9939de775 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -42,7 +42,8 @@ void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_ob self->is_secondary = is_secondary; for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { - bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(characteristic_list->items[characteristic_idx]); + bleio_characteristic_obj_t *characteristic = + MP_OBJ_TO_PTR(characteristic_list->items[characteristic_idx]); common_hal_bleio_characteristic_set_service(characteristic, self); } @@ -67,9 +68,9 @@ void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t dev // Call this after the Service has been added to the Peripheral. void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self) { // Add all the characteristics. - const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(self->characteristic_list); - for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { - bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_idx]; + for (size_t characteristic_idx = 0; characteristic_idx < self->characteristic_list->len; ++characteristic_idx) { + bleio_characteristic_obj_t *characteristic = + MP_OBJ_TO_PTR(self->characteristic_list->items[characteristic_idx]); ble_gatts_char_md_t char_md = { .char_props.broadcast = characteristic->props.broadcast, diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h index 90f52027d..583593fb8 100644 --- a/ports/nrf/common-hal/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -28,6 +28,7 @@ #ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H #define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H +#include "py/objlist.h" #include "common-hal/bleio/UUID.h" typedef struct { @@ -38,7 +39,7 @@ typedef struct { bleio_uuid_obj_t *uuid; // May be a Peripheral, Central, etc. mp_obj_t device; - mp_obj_t characteristic_list; + mp_obj_list_t *characteristic_list; // Range of attribute handles of this service. uint16_t start_handle; uint16_t end_handle; diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index efadcbb2a..95ba19dd0 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -79,8 +79,6 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(self); } - - //| .. method:: connect(address, timeout, *, service_uuids=None) //| Attempts a connection to the remote peripheral. If the connection is successful, //| Do BLE discovery for the listed services, to find their handles and characteristics. @@ -167,7 +165,7 @@ const mp_obj_property_t bleio_central_connected_obj = { STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_bleio_central_get_remote_services(self); + return MP_OBJ_FROM_PTR(common_hal_bleio_central_get_remote_services(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h index 2ca423945..0e84037f9 100644 --- a/shared-bindings/bleio/Central.h +++ b/shared-bindings/bleio/Central.h @@ -37,6 +37,6 @@ extern void common_hal_bleio_central_construct(bleio_central_obj_t *self); extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_obj_t *address, mp_float_t timeout, mp_obj_t service_uuids); extern void common_hal_bleio_central_disconnect(bleio_central_obj_t *self); extern bool common_hal_bleio_central_get_connected(bleio_central_obj_t *self); -extern mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); +extern mp_obj_list_t *common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index 9e051c89e..723352ea1 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -49,9 +49,6 @@ enum { DescriptorUuidTimeTriggerSetting = 0x290E, }; -// Work-in-progress: orphaned for now. -//| :orphan: -//| //| .. currentmodule:: bleio //| //| :class:`Descriptor` -- BLE descriptor diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 665f5baaf..320d83471 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -250,10 +250,26 @@ STATIC mp_obj_t bleio_peripheral_stop_advertising(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_stop_advertising_obj, bleio_peripheral_stop_advertising); +//| .. method:: disconnect() +//| +//| Disconnects from the remote central. +//| Normally the central initiates a disconnection. Use this only +//| if necessary for your application. +//| +STATIC mp_obj_t bleio_peripheral_disconnect(mp_obj_t self_in) { + bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); + + common_hal_bleio_peripheral_disconnect(self); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_disconnect_obj, bleio_peripheral_disconnect); + STATIC const mp_rom_map_elem_t bleio_peripheral_locals_dict_table[] = { // Methods { MP_ROM_QSTR(MP_QSTR_start_advertising), MP_ROM_PTR(&bleio_peripheral_start_advertising_obj) }, { MP_ROM_QSTR(MP_QSTR_stop_advertising), MP_ROM_PTR(&bleio_peripheral_stop_advertising_obj) }, + { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_peripheral_disconnect_obj) }, // Properties { MP_ROM_QSTR(MP_QSTR_connected), MP_ROM_PTR(&bleio_peripheral_connected_obj) }, diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index 16438bba6..846250a5f 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -38,5 +38,6 @@ extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *se extern mp_obj_t common_hal_bleio_peripheral_get_name(bleio_peripheral_obj_t *self); extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, float interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device); +extern void common_hal_bleio_peripheral_disconnect(bleio_peripheral_obj_t *device); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_PERIPHERAL_H -- cgit v1.2.3 From 118b26b335c7153eeb4847e04019cdc0829ca960 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 9 Jul 2019 00:21:46 -0400 Subject: UARTClient now works both directions --- ports/nrf/common-hal/bleio/Central.c | 59 +++++++++++++----- ports/nrf/common-hal/bleio/Characteristic.c | 53 ++++++++++++++-- ports/nrf/common-hal/bleio/Descriptor.c | 4 +- ports/nrf/common-hal/bleio/Peripheral.c | 4 +- ports/nrf/common-hal/bleio/Peripheral.h | 1 - ports/nrf/common-hal/bleio/Service.c | 6 +- shared-bindings/bleio/Address.c | 21 +++---- shared-bindings/bleio/AdvertisementData.h | 35 ----------- shared-bindings/bleio/Characteristic.c | 50 +++++++++++++++- shared-bindings/bleio/Characteristic.h | 5 +- shared-bindings/bleio/Descriptor.c | 93 ++++++++++++++++++----------- shared-bindings/bleio/Descriptor.h | 18 ++++++ shared-bindings/bleio/Peripheral.c | 3 +- shared-bindings/bleio/Service.c | 2 +- shared-bindings/bleio/Service.h | 1 - shared-bindings/bleio/__init__.c | 7 +-- 16 files changed, 239 insertions(+), 123 deletions(-) delete mode 100644 shared-bindings/bleio/AdvertisementData.h (limited to 'shared-bindings') diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index f7077f4b9..d90737411 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -97,7 +97,7 @@ STATIC bool discover_next_descriptors(bleio_central_obj_t *self, bleio_character m_discovery_successful = false; m_discovery_in_process = true; - uint32_t err_code = sd_ble_gattc_characteristics_discover(self->conn_handle, &handle_range); + uint32_t err_code = sd_ble_gattc_descriptors_discover(self->conn_handle, &handle_range); if (err_code != NRF_SUCCESS) { return false; } @@ -116,8 +116,10 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); service->base.type = &bleio_service_type; + // Initialize several fields at once. + common_hal_bleio_service_construct(service, NULL, mp_obj_new_list(0, NULL), false); + service->device = MP_OBJ_FROM_PTR(central); - service->characteristic_list = mp_obj_new_list(0, NULL); service->start_handle = gattc_service->handle_range.start_handle; service->end_handle = gattc_service->handle_range.end_handle; service->handle = gattc_service->handle_range.start_handle; @@ -152,6 +154,8 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); characteristic->base.type = &bleio_characteristic_type; + characteristic->descriptor_list = mp_obj_new_list(0, NULL); + bleio_uuid_obj_t *uuid = NULL; if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) { @@ -174,8 +178,8 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio props.write = gattc_char->char_props.write; props.write_no_response = gattc_char->char_props.write_wo_resp; - // Call common_hal_bleio_characteristic_construct() to set up evt handler. - common_hal_bleio_characteristic_construct(characteristic, uuid, props); + // Call common_hal_bleio_characteristic_construct() to initalize some fields and set up evt handler. + common_hal_bleio_characteristic_construct(characteristic, uuid, props, mp_obj_new_list(0, NULL)); characteristic->handle = gattc_char->handle_value; characteristic->service = m_char_discovery_service; @@ -192,6 +196,27 @@ STATIC void on_desc_discovery_rsp(ble_gattc_evt_desc_disc_rsp_t *response, bleio for (size_t i = 0; i < response->count; ++i) { ble_gattc_desc_t *gattc_desc = &response->descs[i]; + // Remember handles for certain well-known descriptors. + switch (gattc_desc->uuid.uuid) { + case DESCRIPTOR_UUID_CLIENT_CHARACTERISTIC_CONFIGURATION: + m_desc_discovery_characteristic->cccd_handle = gattc_desc->handle; + break; + + case DESCRIPTOR_UUID_SERVER_CHARACTERISTIC_CONFIGURATION: + m_desc_discovery_characteristic->sccd_handle = gattc_desc->handle; + break; + + case DESCRIPTOR_UUID_CHARACTERISTIC_USER_DESCRIPTION: + m_desc_discovery_characteristic->user_desc_handle = gattc_desc->handle; + break; + + default: + // TODO: sd_ble_gattc_descriptors_discover() can return things that are not descriptors, + // so ignore those. + // https://devzone.nordicsemi.com/f/nordic-q-a/49500/sd_ble_gattc_descriptors_discover-is-returning-attributes-that-are-not-descriptors + break; + } + bleio_descriptor_obj_t *descriptor = m_new_obj(bleio_descriptor_obj_t); descriptor->base.type = &bleio_descriptor_type; @@ -251,6 +276,7 @@ STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { case BLE_GATTC_EVT_DESC_DISC_RSP: on_desc_discovery_rsp(&ble_evt->evt.gattc_evt.params.desc_disc_rsp, central); + break; case BLE_GAP_EVT_SEC_PARAMS_REQUEST: sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); @@ -265,7 +291,7 @@ STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { default: // For debugging. - mp_printf(&mp_plat_print, "Unhandled central event: 0x%04x\n", ble_evt->header.evt_id); + // mp_printf(&mp_plat_print, "Unhandled central event: 0x%04x\n", ble_evt->header.evt_id); break; } } @@ -330,13 +356,13 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o uint16_t next_service_start_handle = BLE_GATT_HANDLE_START; while (discover_next_services(self, next_service_start_handle, MP_OBJ_NULL)) { - // discover_next_services() appends to service_list. + // discover_next_services() appends to service_list. - // Get the most recently discovered service, and then ask for services - // whose handles start after the last attribute handle inside that service. - const bleio_service_obj_t *service = - MP_OBJ_TO_PTR(self->service_list->items[self->service_list->len - 1]); - next_service_start_handle = service->end_handle + 1; + // Get the most recently discovered service, and then ask for services + // whose handles start after the last attribute handle inside that service. + const bleio_service_obj_t *service = + MP_OBJ_TO_PTR(self->service_list->items[self->service_list->len - 1]); + next_service_start_handle = service->end_handle + 1; } } else { mp_obj_iter_buf_t iter_buf; @@ -384,10 +410,11 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o } // Got characteristics for this service. Now discover descriptors for each characteristic. - for (size_t char_idx = 0; char_idx < service->characteristic_list->len; ++char_idx) { + size_t char_list_len = service->characteristic_list->len; + for (size_t char_idx = 0; char_idx < char_list_len; ++char_idx) { bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(service->characteristic_list->items[char_idx]); - const bool last_characteristic = char_idx == service->characteristic_list->len - 1; + const bool last_characteristic = char_idx == char_list_len - 1; bleio_characteristic_obj_t *next_characteristic = last_characteristic ? NULL : MP_OBJ_TO_PTR(service->characteristic_list->items[char_idx + 1]); @@ -402,13 +429,15 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o // Don't run past the end of this service or the beginning of the next characteristic. uint16_t next_desc_end_handle = next_characteristic == NULL ? service->end_handle - : next_characteristic->handle; + : next_characteristic->handle - 1; // Stop when we go past the end of the range of handles for this service or // discovery call returns nothing. // discover_next_descriptors() appends to the descriptor_list. while (next_desc_start_handle <= service->end_handle && - discover_next_descriptors(self, characteristic, next_desc_start_handle, next_desc_end_handle)) { + next_desc_start_handle < next_desc_end_handle && + discover_next_descriptors(self, characteristic, + next_desc_start_handle, next_desc_end_handle)) { // Get the most recently discovered descriptor, and then ask for descriptors // whose handles start after that descriptor's handle. diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 1db0a9378..17417a5e6 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -162,7 +162,6 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in check_connected(conn_handle); ble_gattc_write_params_t write_params = { - .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL, .write_op = characteristic->props.write_no_response ? BLE_GATT_OP_WRITE_CMD : BLE_GATT_OP_WRITE_REQ, .handle = characteristic->handle, .p_value = bufinfo->buf, @@ -210,19 +209,19 @@ STATIC void characteristic_on_ble_evt(ble_evt_t *ble_evt, void *param) { } -void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props) { +void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, mp_obj_list_t *descriptor_list) { self->service = mp_const_none; self->uuid = uuid; self->value_data = mp_const_none; self->props = props; + self->descriptor_list = descriptor_list; self->handle = BLE_GATT_HANDLE_INVALID; ble_drv_add_event_handler(characteristic_on_ble_evt, self); - } -void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service) { - self->service = service; +mp_obj_list_t *common_hal_bleio_characteristic_get_descriptor_list(bleio_characteristic_obj_t *self) { + return self->descriptor_list; } mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) { @@ -284,3 +283,47 @@ bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_ bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self) { return self->props; } + +void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate) { + if (self->cccd_handle == BLE_GATT_HANDLE_INVALID) { + mp_raise_ValueError(translate("No CCCD for this Characteristic")); + } + + if (common_hal_bleio_device_get_gatt_role(self->service->device) != GATT_ROLE_CLIENT) { + mp_raise_ValueError(translate("Can't set CCCD for local Characteristic")); + } + + uint16_t cccd_value = + (notify ? BLE_GATT_HVX_NOTIFICATION : 0) | + (indicate ? BLE_GATT_HVX_INDICATION : 0); + + const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(self->service->device); + check_connected(conn_handle); + + + ble_gattc_write_params_t write_params = { + .write_op = BLE_GATT_OP_WRITE_REQ, + .handle = self->cccd_handle, + .p_value = (uint8_t *) &cccd_value, + .len = 2, + }; + + while (1) { + uint32_t err_code = sd_ble_gattc_write(conn_handle, &write_params); + if (err_code == NRF_SUCCESS) { + break; + } + + // Write with response will return NRF_ERROR_BUSY if the response has not been received. + // Write without reponse will return NRF_ERROR_RESOURCES if too many writes are pending. + if (err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_RESOURCES) { + // We could wait for an event indicating the write is complete, but just retrying is easier. + MICROPY_VM_HOOK_LOOP; + continue; + } + + // Some real error occurred. + mp_raise_OSError_msg_varg(translate("Failed to write CCCD, err 0x%04x"), err_code); + } + +} diff --git a/ports/nrf/common-hal/bleio/Descriptor.c b/ports/nrf/common-hal/bleio/Descriptor.c index d3f2a0ff8..005af6eaa 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.c +++ b/ports/nrf/common-hal/bleio/Descriptor.c @@ -37,6 +37,6 @@ mp_int_t common_hal_bleio_descriptor_get_handle(bleio_descriptor_obj_t *self) { return self->handle; } -mp_obj_t common_hal_bleio_descriptor_get_uuid(bleio_descriptor_obj_t *self) { - return MP_OBJ_FROM_PTR(self->uuid); +bleio_uuid_obj_t *common_hal_bleio_descriptor_get_uuid(bleio_descriptor_obj_t *self) { + return self->uuid; } diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index b31bb84b0..608bd1342 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -135,13 +135,13 @@ void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self, mp_obj_ for (size_t service_idx = 0; service_idx < service_list->len; ++service_idx) { bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[service_idx]); - common_hal_bleio_service_set_device(service, MP_OBJ_FROM_PTR(self)); + service->device = MP_OBJ_FROM_PTR(self); ble_uuid_t uuid; bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); uint8_t service_type = BLE_GATTS_SRVC_TYPE_PRIMARY; - if (service->is_secondary) { + if (common_hal_bleio_service_get_is_secondary(service)) { service_type = BLE_GATTS_SRVC_TYPE_SECONDARY; } diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index 725bc1431..2a1251715 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -44,7 +44,6 @@ typedef struct { gatt_role_t gatt_role; volatile uint16_t conn_handle; mp_obj_list_t *service_list; - mp_obj_t conn_handler; // The advertising data and scan response buffers are held by us, not by the SD, so we must // maintain them and not change it. If we need to change the contents during advertising, // there are tricks to get the SD to notice (see DevZone - TBS). diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 9939de775..b6fcde827 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -44,7 +44,7 @@ void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_ob for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(characteristic_list->items[characteristic_idx]); - common_hal_bleio_characteristic_set_service(characteristic, self); + characteristic->service = self; } } @@ -61,10 +61,6 @@ bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) { return self->is_secondary; } -void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device) { - self->device = device; -} - // Call this after the Service has been added to the Peripheral. void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self) { // Add all the characteristics. diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index 0e094c2e3..cfad8fc11 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -49,10 +49,10 @@ //| //| :param buf address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes. //| :param int address_type: one of these integers: -//| - `bleio.Address.PUBLIC` = 0 -//| - `bleio.Address.RANDOM_STATIC` = 1 -//| - `bleio.Address.RANDOM_PRIVATE_RESOLVABLE` = 2 -//| - `bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE` = 3 +//| - ``bleio.Address.PUBLIC`` = 0 +//| - ``bleio.Address.RANDOM_STATIC`` = 1 +//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 +//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 //| STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -89,11 +89,6 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, //| //| The bytes that make up the device address (read-only) //| -//| - `bleio.Address.PUBLIC` -//| - `bleio.Address.RANDOM_STATIC` -//| - `bleio.Address.RANDOM_PRIVATE_RESOLVABLE` -//| - `bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE` -//| STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -112,10 +107,10 @@ const mp_obj_property_t bleio_address_address_bytes_obj = { //| //| The address type (read-only). One of these integers: //| -//| - `bleio.Address.PUBLIC` -//| - `bleio.Address.RANDOM_STATIC` -//| - `bleio.Address.RANDOM_PRIVATE_RESOLVABLE` -//| - `bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE` +//| - ``bleio.Address.PUBLIC`` = 0 +//| - ``bleio.Address.RANDOM_STATIC`` = 1 +//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 +//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 //| STATIC mp_obj_t bleio_address_get_type(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/bleio/AdvertisementData.h b/shared-bindings/bleio/AdvertisementData.h deleted file mode 100644 index 3313cde3b..000000000 --- a/shared-bindings/bleio/AdvertisementData.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Dan Halbert for Adafruit Industries - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADVERTISEMENTDATA_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADVERTISEMENTDATA_H - -#include "py/obj.h" - -extern const mp_obj_type_t bleio_advertisementdata_type; - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADVERTISEMENTDATA_H diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index ede38c86b..0d5f8f79a 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -88,7 +88,8 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t properties.write = args[ARG_write].u_bool; properties.write_no_response = args[ARG_write_no_response].u_bool; - common_hal_bleio_characteristic_construct(self, uuid, properties); + // Initialize, with an empty descriptor list. + common_hal_bleio_characteristic_construct(self, uuid, properties, mp_obj_new_list(0, NULL)); return MP_OBJ_FROM_PTR(self); } @@ -254,11 +255,58 @@ const mp_obj_property_t bleio_characteristic_value_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| .. attribute:: descriptors +//| +//| A tuple of `bleio.Descriptor` that describe this characteristic. (read-only) +//| +STATIC mp_obj_t bleio_characteristic_get_descriptors(mp_obj_t self_in) { + bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); + // Return list as a tuple so user won't be able to change it. + mp_obj_list_t *char_list = common_hal_bleio_characteristic_get_descriptor_list(self); + return mp_obj_new_tuple(char_list->len, char_list->items); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_descriptors_obj, bleio_characteristic_get_descriptors); + +const mp_obj_property_t bleio_characteristic_descriptors_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_characteristic_get_descriptors_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + +//| .. method:: set_cccd(*, notify=False, indicate=False) +//| +//| Set the remote characteristic's CCCD to enable or disable notification and indication. +//| +//| :param bool notify: True if Characteristic should receive notifications of remote writes +//| :param float indicate: True if Characteristic should receive indications of remote writes +//| +STATIC mp_obj_t bleio_characteristic_set_cccd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + + enum { ARG_notify, ARG_indicate }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_notify, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + { MP_QSTR_indicate, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + common_hal_bleio_characteristic_set_cccd(self, args[ARG_notify].u_bool, args[ARG_indicate].u_bool); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_characteristic_set_cccd_obj, 1, bleio_characteristic_set_cccd); + + STATIC const mp_rom_map_elem_t bleio_characteristic_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_broadcast), MP_ROM_PTR(&bleio_characteristic_broadcast_obj) }, + { MP_ROM_QSTR(MP_QSTR_descriptors), MP_ROM_PTR(&bleio_characteristic_descriptors_obj) }, { MP_ROM_QSTR(MP_QSTR_indicate), MP_ROM_PTR(&bleio_characteristic_indicate_obj) }, { MP_ROM_QSTR(MP_QSTR_notify), MP_ROM_PTR(&bleio_characteristic_notify_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&bleio_characteristic_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_set_cccd), MP_ROM_PTR(&bleio_characteristic_set_cccd_obj) }, { MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_characteristic_uuid_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&bleio_characteristic_value_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&bleio_characteristic_write_obj) }, diff --git a/shared-bindings/bleio/Characteristic.h b/shared-bindings/bleio/Characteristic.h index 1938845a9..d450c42b4 100644 --- a/shared-bindings/bleio/Characteristic.h +++ b/shared-bindings/bleio/Characteristic.h @@ -33,11 +33,12 @@ extern const mp_obj_type_t bleio_characteristic_type; -extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props); -extern void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service); +extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, mp_obj_list_t *descriptor_list); extern mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self); extern void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo); extern bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self); extern bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self); +extern mp_obj_list_t *common_hal_bleio_characteristic_get_descriptor_list(bleio_characteristic_obj_t *self); +extern void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index 723352ea1..f39283892 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -31,24 +31,6 @@ #include "shared-bindings/bleio/Descriptor.h" #include "shared-bindings/bleio/UUID.h" -enum { - DescriptorUuidCharacteristicExtendedProperties = 0x2900, - DescriptorUuidCharacteristicUserDescription = 0x2901, - DescriptorUuidClientCharacteristicConfiguration = 0x2902, - DescriptorUuidServerCharacteristicConfiguration = 0x2903, - DescriptorUuidCharacteristicPresentationFormat = 0x2904, - DescriptorUuidCharacteristicAggregateFormat = 0x2905, - DescriptorUuidValidRange = 0x2906, - DescriptorUuidExternalReportReference = 0x2907, - DescriptorUuidReportReference = 0x2908, - DescriptorUuidNumberOfDigitals = 0x2909, - DescriptorUuidValueTriggerSetting = 0x290A, - DescriptorUuidEnvironmentalSensingConfiguration = 0x290B, - DescriptorUuidEnvironmentalSensingMeasurement = 0x290C, - DescriptorUuidEnvironmentalSensingTriggerSetting = 0x290D, - DescriptorUuidTimeTriggerSetting = 0x290E, -}; - //| .. currentmodule:: bleio //| //| :class:`Descriptor` -- BLE descriptor @@ -111,7 +93,9 @@ const mp_obj_property_t bleio_descriptor_handle_obj = { STATIC mp_obj_t bleio_descriptor_get_uuid(mp_obj_t self_in) { bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_bleio_descriptor_get_uuid(self); + + bleio_uuid_obj_t *uuid = common_hal_bleio_descriptor_get_uuid(self); + return uuid ? MP_OBJ_FROM_PTR(uuid) : mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(bleio_descriptor_get_uuid_obj, bleio_descriptor_get_uuid); @@ -128,28 +112,69 @@ STATIC const mp_rom_map_elem_t bleio_descriptor_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_descriptor_uuid_obj) }, // Static variables - { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_EXTENDED_PROPERTIES), MP_ROM_INT(DescriptorUuidCharacteristicExtendedProperties) }, - { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_USER_DESCRIPTION), MP_ROM_INT(DescriptorUuidCharacteristicUserDescription) }, - { MP_ROM_QSTR(MP_QSTR_CLIENT_CHARACTERISTIC_CONFIGURATION), MP_ROM_INT(DescriptorUuidClientCharacteristicConfiguration) }, - { MP_ROM_QSTR(MP_QSTR_SERVER_CHARACTERISTIC_CONFIGURATION), MP_ROM_INT(DescriptorUuidServerCharacteristicConfiguration) }, - { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_PRESENTATION_FORMAT), MP_ROM_INT(DescriptorUuidCharacteristicPresentationFormat) }, - { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_AGGREGATE_FORMAT), MP_ROM_INT(DescriptorUuidCharacteristicAggregateFormat) }, - { MP_ROM_QSTR(MP_QSTR_VALID_RANGE), MP_ROM_INT(DescriptorUuidValidRange) }, - { MP_ROM_QSTR(MP_QSTR_EXTERNAL_REPORT_REFERENCE), MP_ROM_INT(DescriptorUuidExternalReportReference) }, - { MP_ROM_QSTR(MP_QSTR_REPORT_REFERENCE), MP_ROM_INT(DescriptorUuidReportReference) }, - { MP_ROM_QSTR(MP_QSTR_NUMBER_OF_DIGITALS), MP_ROM_INT(DescriptorUuidNumberOfDigitals) }, - { MP_ROM_QSTR(MP_QSTR_VALUE_TRIGGER_SETTING), MP_ROM_INT(DescriptorUuidValueTriggerSetting) }, - { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_CONFIGURATION), MP_ROM_INT(DescriptorUuidEnvironmentalSensingConfiguration) }, - { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_MEASUREMENT ), MP_ROM_INT(DescriptorUuidEnvironmentalSensingMeasurement) }, - { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_TRIGGER_SETTING), MP_ROM_INT(DescriptorUuidEnvironmentalSensingTriggerSetting) }, - { MP_ROM_QSTR(MP_QSTR_TIME_TRIGGER_SETTING), MP_ROM_INT(DescriptorUuidTimeTriggerSetting) } + { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_EXTENDED_PROPERTIES), + MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_EXTENDED_PROPERTIES) }, + + { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_USER_DESCRIPTION), + MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_USER_DESCRIPTION) }, + + { MP_ROM_QSTR(MP_QSTR_CLIENT_CHARACTERISTIC_CONFIGURATION), + MP_ROM_INT(DESCRIPTOR_UUID_CLIENT_CHARACTERISTIC_CONFIGURATION) }, + + { MP_ROM_QSTR(MP_QSTR_SERVER_CHARACTERISTIC_CONFIGURATION), + MP_ROM_INT(DESCRIPTOR_UUID_SERVER_CHARACTERISTIC_CONFIGURATION) }, + + { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_PRESENTATION_FORMAT), + MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_PRESENTATION_FORMAT) }, + + { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_AGGREGATE_FORMAT), + MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_AGGREGATE_FORMAT) }, + + { MP_ROM_QSTR(MP_QSTR_VALID_RANGE), + MP_ROM_INT(DESCRIPTOR_UUID_VALID_RANGE) }, + + { MP_ROM_QSTR(MP_QSTR_EXTERNAL_REPORT_REFERENCE), + MP_ROM_INT(DESCRIPTOR_UUID_EXTERNAL_REPORT_REFERENCE) }, + + { MP_ROM_QSTR(MP_QSTR_REPORT_REFERENCE), + MP_ROM_INT(DESCRIPTOR_UUID_REPORT_REFERENCE) }, + + { MP_ROM_QSTR(MP_QSTR_NUMBER_OF_DIGITALS), + MP_ROM_INT(DESCRIPTOR_UUID_NUMBER_OF_DIGITALS) }, + + { MP_ROM_QSTR(MP_QSTR_VALUE_TRIGGER_SETTING), + MP_ROM_INT(DESCRIPTOR_UUID_VALUE_TRIGGER_SETTING) }, + + { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_CONFIGURATION), + MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_CONFIGURATION) }, + + { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_MEASUREMENT ), + MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_MEASUREMENT) }, + + { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_TRIGGER_SETTING), + MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_TRIGGER_SETTING) }, + + { MP_ROM_QSTR(MP_QSTR_TIME_TRIGGER_SETTING), + MP_ROM_INT(DESCRIPTOR_UUID_TIME_TRIGGER_SETTING) }, }; STATIC MP_DEFINE_CONST_DICT(bleio_descriptor_locals_dict, bleio_descriptor_locals_dict_table); +STATIC void bleio_descriptor_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "Descriptor("); + if (self->uuid) { + bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + } else { + mp_printf(print, "Unregistered uUID"); + } + mp_printf(print, ")"); +} + const mp_obj_type_t bleio_descriptor_type = { { &mp_type_type }, .name = MP_QSTR_Descriptor, .make_new = bleio_descriptor_make_new, + .print = bleio_descriptor_print, .locals_dict = (mp_obj_dict_t*)&bleio_descriptor_locals_dict }; diff --git a/shared-bindings/bleio/Descriptor.h b/shared-bindings/bleio/Descriptor.h index f4634d393..fd11ea08c 100644 --- a/shared-bindings/bleio/Descriptor.h +++ b/shared-bindings/bleio/Descriptor.h @@ -31,6 +31,24 @@ #include "common-hal/bleio/Descriptor.h" #include "common-hal/bleio/UUID.h" +enum { + DESCRIPTOR_UUID_CHARACTERISTIC_EXTENDED_PROPERTIES = 0x2900, + DESCRIPTOR_UUID_CHARACTERISTIC_USER_DESCRIPTION = 0x2901, + DESCRIPTOR_UUID_CLIENT_CHARACTERISTIC_CONFIGURATION = 0x2902, + DESCRIPTOR_UUID_SERVER_CHARACTERISTIC_CONFIGURATION = 0x2903, + DESCRIPTOR_UUID_CHARACTERISTIC_PRESENTATION_FORMAT = 0x2904, + DESCRIPTOR_UUID_CHARACTERISTIC_AGGREGATE_FORMAT = 0x2905, + DESCRIPTOR_UUID_VALID_RANGE = 0x2906, + DESCRIPTOR_UUID_EXTERNAL_REPORT_REFERENCE = 0x2907, + DESCRIPTOR_UUID_REPORT_REFERENCE = 0x2908, + DESCRIPTOR_UUID_NUMBER_OF_DIGITALS = 0x2909, + DESCRIPTOR_UUID_VALUE_TRIGGER_SETTING = 0x290A, + DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_CONFIGURATION = 0x290B, + DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_MEASUREMENT = 0x290C, + DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_TRIGGER_SETTING = 0x290D, + DESCRIPTOR_UUID_TIME_TRIGGER_SETTING = 0x290E, +}; + extern const mp_obj_type_t bleio_descriptor_type; extern void common_hal_bleio_descriptor_construct(bleio_descriptor_obj_t *self, bleio_uuid_obj_t *uuid); diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 320d83471..b8d4c3975 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -82,13 +82,12 @@ static const char default_name[] = "CIRCUITPY"; //| .. class:: Peripheral(services=(), \*, name='CIRCUITPY') //| //| Create a new Peripheral object. - +//| //| :param iterable services: the Service objects representing services available from this peripheral, if any. //| A non-connectable peripheral will have no services. //| :param str name: The name used when advertising this peripheral. Use ``None`` when a name is not needed, //| such as when the peripheral is a beacon //| - STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_services, ARG_name }; static const mp_arg_t allowed_args[] = { diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index f8993ef61..af215c6a5 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -102,7 +102,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, //| .. attribute:: characteristics //| -//| A `list` of `bleio.Characteristic` that are offered by this service. (read-only) +//| A tuple of `bleio.Characteristic` that are offered by this service. (read-only) //| STATIC mp_obj_t bleio_service_get_characteristics(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/bleio/Service.h b/shared-bindings/bleio/Service.h index 6693cc3bb..f646c81a9 100644 --- a/shared-bindings/bleio/Service.h +++ b/shared-bindings/bleio/Service.h @@ -36,7 +36,6 @@ extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_ extern bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self); extern mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self); extern bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self); -extern void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device); extern void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 9e80b49e3..ba3bae6c7 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -53,15 +53,14 @@ //| :maxdepth: 3 //| //| Address -//| AdvertisementData //| Adapter //| Central //| Characteristic //| CharacteristicBuffer -// Descriptor +//| Descriptor //| Peripheral -//| ScanEntry -//| Scanner +//| ScanEntry +//| Scanner //| Service //| UUID //| -- cgit v1.2.3 From 514d4146d3bf786fe6c582a645e305e709b618ad Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Jul 2019 18:23:45 -0400 Subject: Fix sphinx warnings. --- shared-bindings/bleio/Central.c | 8 ++++---- shared-bindings/bleio/Scanner.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index 95ba19dd0..a21f711af 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -86,16 +86,16 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, //| //| :param bleio.Address address: The address of the peripheral to connect to //| :param float/int timeout: Try to connect for timeout seconds. -//| :param iterable service_uuids: a collection of `UUID` objects for the services +//| :param iterable service_uuids: a collection of :py:class:~`UUID` objects for the services //| provided by the peripheral that you want to use. //| The peripheral may provide more services, but services not listed are ignored. -//| If a service in `service_uuids` is not found during discovery, it will not +//| If a service in service_uuids is not found during discovery, it will not //| appear in `remote_services`. //| -//| If `services` is None, then all services will undergo discovery, which can be slow. +//| If service_uuids is None, then all services will undergo discovery, which can be slow. //| //| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you -//| you must have already created a `UUID` object for that UUID in order for the +//| you must have already created a :py:class:~`UUID` object for that UUID in order for the //| service or characteristic to be discovered. (This restriction may be lifted in the future.) //| STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index d50f69fc5..79ab34931 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -73,8 +73,8 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, //| :param float timeout: the scan timeout in seconds //| :param float interval: the interval (in seconds) between the start of two consecutive scan windows //| Must be in the range 0.0025 - 40.959375 seconds. -//| :param float window: the duration (in seconds) to scan a single BLE channel -//| `window` must be <= `interval`. +//| :param float window: the duration (in seconds) to scan a single BLE channel. +//| window must be <= interval. //| :returns: advertising packets found //| :rtype: list of :py:class:`bleio.ScanEntry` //| -- cgit v1.2.3 From 364ee62d108bbdc1d4da8bb646a9332a68964b76 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 16 Jul 2019 19:53:36 -0400 Subject: Address review comments. --- conf.py | 1 + ports/nrf/common-hal/bleio/Scanner.c | 13 +++--- shared-bindings/bleio/Address.c | 54 +++++++++++++--------- shared-bindings/bleio/Central.c | 19 ++++---- shared-bindings/bleio/Characteristic.c | 6 +-- shared-bindings/bleio/Descriptor.c | 6 +-- shared-bindings/bleio/Peripheral.c | 1 + shared-bindings/bleio/ScanEntry.c | 1 - shared-bindings/bleio/Scanner.c | 8 ++-- shared-bindings/bleio/Scanner.h | 3 +- shared-bindings/bleio/Service.c | 6 +-- shared-module/bleio/AdvertisementData.h | 79 --------------------------------- 12 files changed, 66 insertions(+), 131 deletions(-) delete mode 100644 shared-module/bleio/AdvertisementData.h (limited to 'shared-bindings') diff --git a/conf.py b/conf.py index 858657388..6b0f40da6 100644 --- a/conf.py +++ b/conf.py @@ -84,6 +84,7 @@ version = release = '0.0.0' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ["**/build*", + ".git", ".venv", ".direnv", "docs/README.md", diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index fa4f3923c..57ce940ab 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -74,10 +74,9 @@ STATIC void scanner_on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { } void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self) { - self->scan_entries = mp_obj_new_list(0, NULL); } -void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { +mp_obj_t common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { common_hal_bleio_adapter_set_enabled(true); ble_drv_add_event_handler(scanner_on_ble_evt, self); @@ -87,8 +86,7 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout .scan_phys = BLE_GAP_PHY_1MBPS, }; - // Empty the advertising reports list. - mp_obj_list_clear(self->scan_entries); + self->scan_entries = mp_obj_new_list(0, NULL); uint32_t err_code; err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); @@ -99,8 +97,9 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout mp_hal_delay_ms(timeout * 1000); sd_ble_gap_scan_stop(); -} -mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self) { - return self->scan_entries; + // Return list, and don't hang on to it, so it can be GC'd. + mp_obj_t entries = self->scan_entries; + self->scan_entries = MP_OBJ_NULL; + return entries; } diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index cfad8fc11..37f01042c 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -48,13 +48,9 @@ //| The value itself can be one of: //| //| :param buf address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes. -//| :param int address_type: one of these integers: -//| - ``bleio.Address.PUBLIC`` = 0 -//| - ``bleio.Address.RANDOM_STATIC`` = 1 -//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 -//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 +//| :param int address_type: one of the integer values: `PUBLIC`, `RANDOM_STATIC`, +//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`. //| - STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_address, ARG_address_type }; static const mp_arg_t allowed_args[] = { @@ -105,12 +101,9 @@ const mp_obj_property_t bleio_address_address_bytes_obj = { //| .. attribute:: type //| -//| The address type (read-only). One of these integers: -//| -//| - ``bleio.Address.PUBLIC`` = 0 -//| - ``bleio.Address.RANDOM_STATIC`` = 1 -//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 -//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 +//| The address type (read-only). +//| One of the integer values: `PUBLIC`, `RANDOM_STATIC`, +//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`. //| STATIC mp_obj_t bleio_address_get_type(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -154,16 +147,37 @@ STATIC mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_o STATIC void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_t address_bytes = common_hal_bleio_address_get_address_bytes(self); - - mp_buffer_info_t buf_info; - mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); - const uint8_t *buf = (uint8_t *) buf_info.buf; - mp_printf(print, - "%02x:%02x:%02x:%02x:%02x:%02x", - buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); + if (kind == PRINT_STR) { + mp_buffer_info_t buf_info; + mp_obj_t address_bytes = common_hal_bleio_address_get_address_bytes(self); + mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); + + const uint8_t *buf = (uint8_t *) buf_info.buf; + mp_printf(print, + "%02x:%02x:%02x:%02x:%02x:%02x", + buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); + } else { + mp_printf(print, "
"); + } } +//| .. data:: PUBLIC +//| +//| A publicly known address, with a company ID (high 24 bits)and company-assigned part (low 24 bits). +//| +//| .. data:: RANDOM_STATIC +//| +//| A randomly generated address that does not change often. It may never change or may change after +//| a power cycle. +//| +//| .. data:: RANDOM_PRIVATE_RESOLVABLE +//| +//| An address that is usable when the peer knows the other device's secret Identity Resolving Key (IRK). +//| +//| .. data:: RANDOM_PRIVATE_NON_RESOLVABLE +//| +//| A randomly generated address that changes on every connection. +//| STATIC const mp_rom_map_elem_t bleio_address_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_address_bytes_obj) }, { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_type_obj) }, diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index a21f711af..fc00bce5c 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -56,7 +56,7 @@ //| //| my_entry = None //| for entry in entries: -//| if entry.name is not None and entry.name == 'MyCentral': +//| if entry.name is not None and entry.name == 'MyPeripheral': //| my_entry = entry //| break //| @@ -86,13 +86,13 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, //| //| :param bleio.Address address: The address of the peripheral to connect to //| :param float/int timeout: Try to connect for timeout seconds. -//| :param iterable service_uuids: a collection of :py:class:~`UUID` objects for the services +//| :param iterable service_uuids_whitelist: an iterable of :py:class:~`UUID` objects for the services //| provided by the peripheral that you want to use. //| The peripheral may provide more services, but services not listed are ignored. //| If a service in service_uuids is not found during discovery, it will not //| appear in `remote_services`. //| -//| If service_uuids is None, then all services will undergo discovery, which can be slow. +//| If service_uuids_whitelist is None, then all services will undergo discovery, which can be slow. //| //| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you //| you must have already created a :py:class:~`UUID` object for that UUID in order for the @@ -101,11 +101,11 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_address, ARG_timeout, ARG_service_uuids }; + enum { ARG_address, ARG_timeout, ARG_service_uuids_whitelist }; static const mp_arg_t allowed_args[] = { { MP_QSTR_address, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_timeout, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_service_uuids, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_service_uuids_whitelist, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -119,7 +119,7 @@ STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); // common_hal_bleio_central_connect() will validate that services is an iterable or None. - common_hal_bleio_central_connect(self, address, timeout, args[ARG_service_uuids].u_obj); + common_hal_bleio_central_connect(self, address, timeout, args[ARG_service_uuids_whitelist].u_obj); return mp_const_none; } @@ -160,12 +160,15 @@ const mp_obj_property_t bleio_central_connected_obj = { //| .. attribute:: remote_services (read-only) //| -//| Empty until connected, then a list of services provided by the remote peripheral. +//| A tuple of services provided by the remote peripheral. +//| If the Central is not connected, an empty tuple will be returned. //| STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(common_hal_bleio_central_get_remote_services(self)); + // Return list as a tuple so user won't be able to change it. + mp_obj_list_t *service_list = common_hal_bleio_central_get_remote_services(self); + return mp_obj_new_tuple(service_list->len, service_list->items); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index 0d5f8f79a..3bf0476ab 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -316,13 +316,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_characteristic_locals_dict, bleio_characterist STATIC void bleio_characteristic_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Characteristic("); if (self->uuid) { + mp_printf(print, "Characteristic("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "Unregistered uUID"); + mp_printf(print, ""); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_characteristic_type = { diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index f39283892..f2e5aa01d 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -162,13 +162,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_descriptor_locals_dict, bleio_descriptor_local STATIC void bleio_descriptor_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Descriptor("); if (self->uuid) { + mp_printf(print, "Descriptor("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "Unregistered uUID"); + mp_printf(print, ""); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_descriptor_type = { diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index b8d4c3975..1302c9652 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -63,6 +63,7 @@ static const char default_name[] = "CIRCUITPY"; //| Usage:: //| //| import bleio +//| from adafruit_ble.advertising import ServerAdvertisement //| //| # Create a Characteristic. //| chara = bleio.Characteristic(bleio.UUID(0x2919), read=True, notify=True) diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index b7798175c..6eb02c716 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -32,7 +32,6 @@ #include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/ScanEntry.h" //| .. currentmodule:: bleio diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 79ab34931..712425c25 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -75,8 +75,8 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, //| Must be in the range 0.0025 - 40.959375 seconds. //| :param float window: the duration (in seconds) to scan a single BLE channel. //| window must be <= interval. -//| :returns: advertising packets found -//| :rtype: list of :py:class:`bleio.ScanEntry` +//| :returns: an iterable of `bleio.ScanEntry` objects +//| :rtype: iterable //| STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_timeout, ARG_interval, ARG_window }; @@ -110,9 +110,7 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m mp_raise_ValueError(translate("window must be <= interval")); } - common_hal_bleio_scanner_scan(self, timeout, interval, window); - - return common_hal_bleio_scanner_get_scan_entries(self); + return common_hal_bleio_scanner_scan(self, timeout, interval, window); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index 1bbab78f4..3a0ce7eae 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -34,8 +34,7 @@ extern const mp_obj_type_t bleio_scanner_type; extern void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self); -extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); +extern mp_obj_t common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); -extern mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index af215c6a5..db0606991 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -166,13 +166,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_service_locals_dict, bleio_service_locals_dict STATIC void bleio_service_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Service("); if (self->uuid) { + mp_printf(print, "Service("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "unregistered UUID"); + mp_printf(print, ""); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_service_type = { diff --git a/shared-module/bleio/AdvertisementData.h b/shared-module/bleio/AdvertisementData.h deleted file mode 100644 index 89cdfb070..000000000 --- a/shared-module/bleio/AdvertisementData.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Dan Halbert for Adafruit Industries - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H - -#include "py/obj.h" - -// Taken from https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile -enum { - AdFlags = 0x01, - AdIncompleteListOf16BitServiceClassUUIDs = 0x02, - AdCompleteListOf16BitServiceClassUUIDs = 0x03, - AdIncompleteListOf32BitServiceClassUUIDs = 0x04, - AdCompleteListOf32BitServiceClassUUIDs = 0x05, - AdIncompleteListOf128BitServiceClassUUIDs = 0x06, - AdCompleteListOf128BitServiceClassUUIDs = 0x07, - AdShortenedLocalName = 0x08, - AdCompleteLocalName = 0x09, - AdTxPowerLevel = 0x0A, - AdClassOfDevice = 0x0D, - AdSimplePairingHashC = 0x0E, - AdSimplePairingRandomizerR = 0x0F, - AdSecurityManagerTKValue = 0x10, - AdSecurityManagerOOBFlags = 0x11, - AdSlaveConnectionIntervalRange = 0x12, - AdListOf16BitServiceSolicitationUUIDs = 0x14, - AdListOf128BitServiceSolicitationUUIDs = 0x15, - AdServiceData = 0x16, - AdPublicTargetAddress = 0x17, - AdRandomTargetAddress = 0x18, - AdAppearance = 0x19, - AdAdvertisingInterval = 0x1A, - AdLEBluetoothDeviceAddress = 0x1B, - AdLERole = 0x1C, - AdSimplePairingHashC256 = 0x1D, - AdSimplePairingRandomizerR256 = 0x1E, - AdListOf32BitServiceSolicitationUUIDs = 0x1F, - AdServiceData32BitUUID = 0x20, - AdServiceData128BitUUID = 0x21, - AdLESecureConnectionsConfirmationValue = 0x22, - AdLESecureConnectionsRandomValue = 0x23, - AdURI = 0x24, - AdIndoorPositioning = 0x25, - AdTransportDiscoveryData = 0x26, - AdLESupportedFeatures = 0x27, - AdChannelMapUpdateIndication = 0x28, - AdPBADV = 0x29, - AdMeshMessage = 0x2A, - AdMeshBeacon = 0x2B, - Ad3DInformationData = 0x3D, - AdManufacturerSpecificData = 0xFF, -}; - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H -- cgit v1.2.3 From 1c31cf5f6a6d9cff6f086114f6e0a03b5247c623 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 16 Jul 2019 21:03:36 -0400 Subject: sphinx fix --- shared-bindings/bleio/Scanner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 712425c25..269c42591 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -75,7 +75,7 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, //| Must be in the range 0.0025 - 40.959375 seconds. //| :param float window: the duration (in seconds) to scan a single BLE channel. //| window must be <= interval. -//| :returns: an iterable of `bleio.ScanEntry` objects +//| :returns: an iterable of `ScanEntry` objects //| :rtype: iterable //| STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { -- cgit v1.2.3 From 6797ec6ed396f65916fe816f8b2b49114253dd86 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 5 Jul 2019 19:01:54 -0700 Subject: Add support for grayscale displays that are < 8 bit depth. This also improves Palette so it stores the original RGB888 colors. Lastly, it adds I2CDisplay as a display bus to talk over I2C. Particularly useful for the SSD1306. Fixes #1828. Fixes #1956 --- .../atmel-samd/boards/hallowing_m0_express/board.c | 3 + ports/atmel-samd/boards/pybadge/board.c | 3 + ports/atmel-samd/boards/pybadge_airlift/board.c | 3 + ports/atmel-samd/boards/pygamer/board.c | 3 + ports/atmel-samd/boards/pygamer_advance/board.c | 3 + ports/atmel-samd/boards/pyportal/board.c | 5 +- ports/atmel-samd/boards/ugame10/board.c | 3 + ports/atmel-samd/common-hal/busio/I2C.c | 9 ++ ports/atmel-samd/common-hal/busio/SPI.h | 1 + .../atmel-samd/common-hal/displayio/ParallelBus.c | 17 +- ports/nrf/common-hal/busio/I2C.c | 17 ++ ports/nrf/common-hal/busio/SPI.c | 2 +- py/circuitpy_defns.mk | 1 + shared-bindings/_stage/__init__.c | 7 +- shared-bindings/busio/I2C.h | 3 + shared-bindings/displayio/ColorConverter.c | 6 +- shared-bindings/displayio/ColorConverter.h | 4 +- shared-bindings/displayio/Display.c | 16 +- shared-bindings/displayio/Display.h | 6 +- shared-bindings/displayio/I2CDisplay.c | 138 ++++++++++++++++ shared-bindings/displayio/I2CDisplay.h | 46 ++++++ shared-bindings/displayio/Palette.c | 27 +++- shared-bindings/displayio/Palette.h | 2 + shared-bindings/displayio/__init__.c | 3 + shared-module/displayio/ColorConverter.c | 35 ++++- shared-module/displayio/ColorConverter.h | 4 + shared-module/displayio/Display.c | 173 +++++++++++++++------ shared-module/displayio/Display.h | 4 +- shared-module/displayio/FourWire.c | 21 ++- shared-module/displayio/FourWire.h | 6 +- shared-module/displayio/Group.c | 6 +- shared-module/displayio/Group.h | 3 +- shared-module/displayio/I2CDisplay.c | 105 +++++++++++++ shared-module/displayio/I2CDisplay.h | 41 +++++ shared-module/displayio/Palette.c | 50 +++--- shared-module/displayio/Palette.h | 19 ++- shared-module/displayio/TileGrid.c | 50 ++++-- shared-module/displayio/TileGrid.h | 3 +- shared-module/displayio/__init__.c | 135 ++++++++++------ shared-module/displayio/__init__.h | 2 + shared-module/terminalio/Terminal.c | 2 + supervisor/shared/display.c | 49 ++++-- tools/gen_display_resources.py | 17 +- 43 files changed, 855 insertions(+), 198 deletions(-) create mode 100644 shared-bindings/displayio/I2CDisplay.c create mode 100644 shared-bindings/displayio/I2CDisplay.h create mode 100644 shared-module/displayio/I2CDisplay.c create mode 100644 shared-module/displayio/I2CDisplay.h (limited to 'shared-bindings') diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index a0e160757..1bbbfbaf8 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -91,6 +91,8 @@ void board_init(void) { 1, // row start 0, // rotation 16, // Color depth + false, // Grayscale + false, // Pixels in a byte share a row. Only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -98,6 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, + 0x100, // Brightness command. Only available when <= 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 38902315a..7e6c11dd4 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -93,6 +93,8 @@ void board_init(void) { 0, // row start 270, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -100,6 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // no brightness command 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge_airlift/board.c b/ports/atmel-samd/boards/pybadge_airlift/board.c index a1f778df1..d7f291d7d 100644 --- a/ports/atmel-samd/boards/pybadge_airlift/board.c +++ b/ports/atmel-samd/boards/pybadge_airlift/board.c @@ -71,6 +71,8 @@ void board_init(void) { 0, // row start 90, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. Only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -78,6 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // brightness command, only valid <= 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index 7b54b6fb5..e59b7c458 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -93,6 +93,8 @@ void board_init(void) { 0, // row start 270, // rotation 16, // Color depth + false, // Grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -100,6 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // Brightness command. Only available when < 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer_advance/board.c b/ports/atmel-samd/boards/pygamer_advance/board.c index d1c5edc99..b23353998 100644 --- a/ports/atmel-samd/boards/pygamer_advance/board.c +++ b/ports/atmel-samd/boards/pygamer_advance/board.c @@ -71,6 +71,8 @@ void board_init(void) { 0, // row start 90, // rotation 16, // Color depth + false, // Grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -78,6 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // Brightness command. Only available when < 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index bb80c5b48..7fffb764f 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -83,13 +83,16 @@ void board_init(void) { 0, // row start 0, // rotation 16, // Color depth + false, // grayscale + false, // pixels_in_byte_share_row (unused for depths > 8) MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command 0x37, // Set vertical scroll command display_init_sequence, sizeof(display_init_sequence), - &pin_PB31, + &pin_PB31, // Backlight pin + 0x100, // Brightness command > 0xff is none s 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index 828f0c87d..27a03ad91 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -91,6 +91,8 @@ void board_init(void) { 2, // row start 0, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. Only used with depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -98,6 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), NULL, + 0x100, // brightness command. Only valid <=0xff 1.0f, // brightness false, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/common-hal/busio/I2C.c b/ports/atmel-samd/common-hal/busio/I2C.c index a0c04d65d..cdc616bbc 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.c +++ b/ports/atmel-samd/common-hal/busio/I2C.c @@ -36,6 +36,8 @@ #include "shared-bindings/microcontroller/__init__.h" #include "supervisor/shared/translate.h" +#include "common-hal/busio/SPI.h" // for never_reset_sercom + // Number of times to try to send packet if failed. #define ATTEMPTS 2 @@ -225,3 +227,10 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, } return MP_EIO; } + +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + never_reset_sercom(self->i2c_desc.device.hw); + + never_reset_pin_number(self->scl_pin); + never_reset_pin_number(self->sda_pin); +} diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 56d163a9d..a1c0e1517 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -43,6 +43,7 @@ typedef struct { } busio_spi_obj_t; void reset_sercoms(void); +void never_reset_sercom(Sercom* sercom); #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/atmel-samd/common-hal/displayio/ParallelBus.c b/ports/atmel-samd/common-hal/displayio/ParallelBus.c index 7a5f61448..c370f7e52 100644 --- a/ports/atmel-samd/common-hal/displayio/ParallelBus.c +++ b/ports/atmel-samd/common-hal/displayio/ParallelBus.c @@ -31,6 +31,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/runtime.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/__init__.h" #include "tick.h" @@ -66,10 +67,6 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel common_hal_digitalio_digitalinout_construct(&self->chip_select, chip_select); common_hal_digitalio_digitalinout_switch_to_output(&self->chip_select, true, DRIVE_MODE_PUSH_PULL); - self->reset.base.type = &digitalio_digitalinout_type; - common_hal_digitalio_digitalinout_construct(&self->reset, reset); - common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); - self->write.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->write, write); common_hal_digitalio_digitalinout_switch_to_output(&self->write, true, DRIVE_MODE_PUSH_PULL); @@ -82,11 +79,21 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel self->write_group = &PORT->Group[write->number / 32]; self->write_mask = 1 << (write->number % 32); + if (reset != NULL) { + self->reset.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&self->reset, reset); + common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); + never_reset_pin_number(reset->number); + + common_hal_digitalio_digitalinout_set_value(&self->reset, false); + common_hal_mcu_delay_us(4); + common_hal_digitalio_digitalinout_set_value(&self->reset, true); + } + never_reset_pin_number(command->number); never_reset_pin_number(chip_select->number); never_reset_pin_number(write->number); never_reset_pin_number(read->number); - never_reset_pin_number(reset->number); for (uint8_t i = 0; i < 8; i++) { never_reset_pin_number(data_pin + i); } diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c index 538c87f2d..71835d16a 100644 --- a/ports/nrf/common-hal/busio/I2C.c +++ b/ports/nrf/common-hal/busio/I2C.c @@ -57,13 +57,30 @@ STATIC twim_peripheral_t twim_peripherals[] = { #endif }; +STATIC bool never_reset[MP_ARRAY_SIZE(twim_peripherals)]; + void i2c_reset(void) { for (size_t i = 0 ; i < MP_ARRAY_SIZE(twim_peripherals); i++) { + if (never_reset[i]) { + continue; + } nrf_twim_disable(twim_peripherals[i].twim.p_twim); twim_peripherals[i].in_use = false; } } +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + for (size_t i = 0 ; i < MP_ARRAY_SIZE(twim_peripherals); i++) { + if (self->twim_peripheral == &twim_peripherals[i]) { + never_reset[i] = true; + + never_reset_pin_number(self->scl_pin_number); + never_reset_pin_number(self->sda_pin_number); + break; + } + } +} + static uint8_t twi_error_to_mp(const nrfx_err_t err) { switch (err) { case NRFX_ERROR_DRV_TWI_ERR_ANACK: diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 6ab6d9493..5f1aac193 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -61,7 +61,7 @@ STATIC spim_peripheral_t spim_peripherals[] = { #endif }; -STATIC bool never_reset[4]; +STATIC bool never_reset[MP_ARRAY_SIZE(spim_peripherals)]; void spi_reset(void) { for (size_t i = 0 ; i < MP_ARRAY_SIZE(spim_peripherals); i++) { diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 782314fc7..93ca4deb9 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -317,6 +317,7 @@ $(filter $(SRC_PATTERNS), \ displayio/Display.c \ displayio/FourWire.c \ displayio/Group.c \ + displayio/I2CDisplay.c \ displayio/OnDiskBitmap.c \ displayio/Palette.c \ displayio/Shape.c \ diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 03775b1de..9f3f89462 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -95,7 +95,12 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { MICROPY_VM_HOOK_LOOP ; #endif } - displayio_display_set_region_to_update(display, x0, y0, x1, y1); + displayio_area_t area; + area.x1 = x0; + area.y1 = y0; + area.x2 = x1; + area.y2 = y1; + displayio_display_set_region_to_update(display, &area); render_stage(x0, y0, x1, y1, layers, layers_size, buffer, buffer_size, display); displayio_display_end_transaction(display); diff --git a/shared-bindings/busio/I2C.h b/shared-bindings/busio/I2C.h index 739732e97..a2d5dbf50 100644 --- a/shared-bindings/busio/I2C.h +++ b/shared-bindings/busio/I2C.h @@ -69,4 +69,7 @@ extern uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addres extern uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t address, uint8_t * data, size_t len); +// This is used by the supervisor to claim I2C devices indefinitely. +extern void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_H diff --git a/shared-bindings/displayio/ColorConverter.c b/shared-bindings/displayio/ColorConverter.c index 561883810..e170e0340 100644 --- a/shared-bindings/displayio/ColorConverter.c +++ b/shared-bindings/displayio/ColorConverter.c @@ -69,8 +69,10 @@ STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t if (!mp_obj_get_int_maybe(color_obj, &color)) { mp_raise_ValueError(translate("color should be an int")); } - uint16_t output_color; - common_hal_displayio_colorconverter_convert(self, color, &output_color); + _displayio_colorspace_t colorspace; + colorspace.depth = 16; + uint32_t output_color; + common_hal_displayio_colorconverter_convert(self, &colorspace, color, &output_color); return MP_OBJ_NEW_SMALL_INT(output_color); } MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_convert_obj, displayio_colorconverter_obj_convert); diff --git a/shared-bindings/displayio/ColorConverter.h b/shared-bindings/displayio/ColorConverter.h index 71be7f543..8f61e6642 100644 --- a/shared-bindings/displayio/ColorConverter.h +++ b/shared-bindings/displayio/ColorConverter.h @@ -29,9 +29,11 @@ #include "shared-module/displayio/ColorConverter.h" +#include "shared-module/displayio/Palette.h" + extern const mp_obj_type_t displayio_colorconverter_type; void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self); -bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, uint32_t input_color, uint16_t* output_color); +bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_COLORCONVERTER_H diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 1a36872a6..2586e562f 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -51,7 +51,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness_command=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -88,18 +88,21 @@ //| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270) //| :param int color_depth: The number of bits of color per pixel transmitted. (Some displays //| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.) +//| :param bool grayscale: True if the display only shows a single color. +//| :param bool pixels_in_byte_share_row: True when pixels are less than a byte and a byte includes pixels from the same row of the display. When False, pixels share a column. //| :param int set_column_command: Command used to set the start and end columns to update //| :param int set_row_command: Command used so set the start and end rows to update -//| :param int write_ram_command: Command used to write pixels values into the update region +//| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set. //| :param int set_vertical_scroll: Command used to set the first row to show //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight +//| :param int brightness_command: Command to set display brightness. Usually available in OLED controllers. //| :param bool brightness: Initial display brightness. This value is ignored if auto_brightness is True. //| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism. //| :param bool single_byte_bounds: Display column and row commands use single bytes //| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this. //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -109,11 +112,14 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_rowstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_rotation, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, + { MP_QSTR_grayscale, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_pixels_in_byte_share_row, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, { MP_QSTR_set_column_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2a} }, { MP_QSTR_set_row_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2b} }, { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + { MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x100} }, { MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, { MP_QSTR_auto_brightness, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, @@ -157,11 +163,13 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a common_hal_displayio_display_construct( self, display_bus, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation, - args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, + args[ARG_color_depth].u_int, args[ARG_grayscale].u_bool, args[ARG_pixels_in_byte_share_row].u_bool, + args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, args[ARG_write_ram_command].u_int, args[ARG_set_vertical_scroll].u_int, bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin), + args[ARG_brightness_command].u_int, brightness, args[ARG_auto_brightness].u_bool, args[ARG_single_byte_bounds].u_bool, diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 5a027561b..a60a0cf5a 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -38,9 +38,9 @@ extern const mp_obj_type_t displayio_display_type; void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, - int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, + int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, - uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, + uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, bool single_byte_bounds, bool data_as_commands); @@ -54,7 +54,7 @@ bool displayio_display_begin_transaction(displayio_display_obj_t* self); void displayio_display_end_transaction(displayio_display_obj_t* self); // The second point of the region is exclusive. -void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); +void displayio_display_set_region_to_update(displayio_display_obj_t* self, displayio_area_t* area); bool displayio_display_frame_queued(displayio_display_obj_t* self); bool displayio_display_refresh_queued(displayio_display_obj_t* self); diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c new file mode 100644 index 000000000..2aac49b4d --- /dev/null +++ b/shared-bindings/displayio/I2CDisplay.c @@ -0,0 +1,138 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/displayio/I2CDisplay.h" + +#include +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/binary.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/util.h" +#include "shared-module/displayio/__init__.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: displayio +//| +//| :class:`I2CDisplay` -- Manage updating a display over I2C +//| ========================================================================== +//| +//| Manage updating a display over I2C in the background while Python code runs. +//| It doesn't handle display initialization. +//| +//| .. class:: I2CDisplay(i2c_bus, *, device_address, reset=None) +//| +//| Create a I2CDisplay object associated with the given I2C bus and reset pin. +//| +//| The I2C bus and pins are then in use by the display until `displayio.release_displays()` is +//| called even after a reload. (It does this so CircuitPython can use the display after your code +//| is done.) So, the first time you initialize a display bus in code.py you should call +//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run. +//| +//| :param busio.I2C i2c_bus: The I2C bus that make up the clock and data lines +//| :param int device_address: The I2C address of the device +//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used +//| +STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_i2c_bus, ARG_device_address, ARG_reset }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_i2c_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_device_address, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, + { MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_obj_t reset = args[ARG_reset].u_obj; + if (reset != mp_const_none) { + assert_pin_free(reset); + } else { + reset = NULL; + } + + displayio_i2cdisplay_obj_t* self = NULL; + mp_obj_t i2c = args[ARG_i2c_bus].u_obj; + for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { + if (displays[i].i2cdisplay_bus.base.type == NULL || + displays[i].i2cdisplay_bus.base.type == &mp_type_NoneType) { + self = &displays[i].i2cdisplay_bus; + self->base.type = &displayio_i2cdisplay_type; + break; + } + } + if (self == NULL) { + mp_raise_RuntimeError(translate("Too many display busses")); + } + + common_hal_displayio_i2cdisplay_construct(self, + MP_OBJ_TO_PTR(i2c), args[ARG_device_address].u_int, reset); + return self; +} + +//| .. method:: send(command, data) +//| +//| Sends the given command value followed by the full set of data. Display state, such as +//| vertical scroll, set via ``send`` may or may not be reset once the code is done. +//| +STATIC mp_obj_t displayio_i2cdisplay_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) { + mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj); + if (!MP_OBJ_IS_SMALL_INT(command_obj) || command_int > 255 || command_int < 0) { + mp_raise_ValueError(translate("Command must be an int between 0 and 255")); + } + uint8_t command = command_int; + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(data_obj, &bufinfo, MP_BUFFER_READ); + + // Wait for display bus to be available. + while (!common_hal_displayio_i2cdisplay_begin_transaction(self)) { +#ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP ; +#endif + } + uint8_t full_command[bufinfo.len + 1]; + full_command[0] = command; + memcpy(full_command + 1, ((uint8_t*) bufinfo.buf), bufinfo.len); + common_hal_displayio_i2cdisplay_send(self, true, full_command, bufinfo.len + 1); + common_hal_displayio_i2cdisplay_end_transaction(self); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_3(displayio_i2cdisplay_send_obj, displayio_i2cdisplay_obj_send); + +STATIC const mp_rom_map_elem_t displayio_i2cdisplay_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_i2cdisplay_send_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(displayio_i2cdisplay_locals_dict, displayio_i2cdisplay_locals_dict_table); + +const mp_obj_type_t displayio_i2cdisplay_type = { + { &mp_type_type }, + .name = MP_QSTR_I2CDisplay, + .make_new = displayio_i2cdisplay_make_new, + .locals_dict = (mp_obj_dict_t*)&displayio_i2cdisplay_locals_dict, +}; diff --git a/shared-bindings/displayio/I2CDisplay.h b/shared-bindings/displayio/I2CDisplay.h new file mode 100644 index 000000000..cc4162800 --- /dev/null +++ b/shared-bindings/displayio/I2CDisplay.h @@ -0,0 +1,46 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_I2CDISPLAY_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_I2CDISPLAY_H + +#include "shared-module/displayio/I2CDisplay.h" +#include "common-hal/microcontroller/Pin.h" + +extern const mp_obj_type_t displayio_i2cdisplay_type; + +void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self, + busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset); + +void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self); + +bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t self); + +void common_hal_displayio_i2cdisplay_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length); + +void common_hal_displayio_i2cdisplay_end_transaction(mp_obj_t self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_I2CDISPLAY_H diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 11c2f677c..974cadb02 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -66,11 +66,26 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a return MP_OBJ_FROM_PTR(self); } + +//| .. method:: __len__() +//| +//| Returns the number of colors in a Palette +//| +STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { + displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); + switch (op) { + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(true); + case MP_UNARY_OP_LEN: + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_palette_get_len(self)); + default: return MP_OBJ_NULL; // op not supported + } +} + //| .. method:: __setitem__(index, value) //| //| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1. //| -//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value). +//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value). //| Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), or bytearray. //| //| This allows you to:: @@ -89,12 +104,12 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { return MP_OBJ_NULL; } - // index read is not supported - if (value == MP_OBJ_SENTINEL) { - return MP_OBJ_NULL; - } displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); size_t index = mp_get_index(&displayio_palette_type, self->color_count, index_in, false); + // index read + if (value == MP_OBJ_SENTINEL) { + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_palette_get_color(self, index)); + } uint32_t color; mp_int_t int_value; @@ -160,5 +175,7 @@ const mp_obj_type_t displayio_palette_type = { .name = MP_QSTR_Palette, .make_new = displayio_palette_make_new, .subscr = palette_subscr, + .unary_op = group_unary_op, + .getiter = mp_obj_new_generic_iterator, .locals_dict = (mp_obj_dict_t*)&displayio_palette_locals_dict, }; diff --git a/shared-bindings/displayio/Palette.h b/shared-bindings/displayio/Palette.h index 767fc7b63..8c9fe11e3 100644 --- a/shared-bindings/displayio/Palette.h +++ b/shared-bindings/displayio/Palette.h @@ -33,6 +33,8 @@ extern const mp_obj_type_t displayio_palette_type; void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t color_count); void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t palette_index, uint32_t color); +uint32_t common_hal_displayio_palette_get_color(displayio_palette_t* self, uint32_t palette_index); +uint32_t common_hal_displayio_palette_get_len(displayio_palette_t* self); void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t palette_index); void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t palette_index); diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 9dc17103b..fd3dc4233 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -35,6 +35,7 @@ #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/FourWire.h" #include "shared-bindings/displayio/Group.h" +#include "shared-bindings/displayio/I2CDisplay.h" #include "shared-bindings/displayio/OnDiskBitmap.h" #include "shared-bindings/displayio/Palette.h" #include "shared-bindings/displayio/ParallelBus.h" @@ -61,6 +62,7 @@ //| Display //| FourWire //| Group +//| I2CDisplay //| OnDiskBitmap //| Palette //| ParallelBus @@ -96,6 +98,7 @@ STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_TileGrid), MP_ROM_PTR(&displayio_tilegrid_type) }, { MP_ROM_QSTR(MP_QSTR_FourWire), MP_ROM_PTR(&displayio_fourwire_type) }, + { MP_ROM_QSTR(MP_QSTR_I2CDisplay), MP_ROM_PTR(&displayio_i2cdisplay_type) }, { MP_ROM_QSTR(MP_QSTR_ParallelBus), MP_ROM_PTR(&displayio_parallelbus_type) }, { MP_ROM_QSTR(MP_QSTR_release_displays), MP_ROM_PTR(&displayio_release_displays_obj) }, diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c index 3928e115a..563d40c51 100644 --- a/shared-module/displayio/ColorConverter.c +++ b/shared-module/displayio/ColorConverter.c @@ -29,15 +29,36 @@ void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self) { } -bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, uint32_t input_color, uint16_t* output_color) { - // TODO(tannewt): Validate the color input against the input format. - uint32_t r5 = (input_color >> 19); - uint32_t g6 = (input_color >> 10) & 0x3f; - uint32_t b5 = (input_color >> 3) & 0x1f; +uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) { + uint32_t r5 = (color_rgb888 >> 19); + uint32_t g6 = (color_rgb888 >> 10) & 0x3f; + uint32_t b5 = (color_rgb888 >> 3) & 0x1f; uint32_t packed = r5 << 11 | g6 << 5 | b5; // swap bytes - *output_color = __builtin_bswap16(packed); - return true; + return __builtin_bswap16(packed); +} + +uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888) { + uint32_t r8 = (color_rgb888 >> 16); + uint32_t g8 = (color_rgb888 >> 8) & 0xff; + uint32_t b8 = color_rgb888 & 0xff; + return (r8 * 19) / 255 + (g8 * 182) / 255 + (b8 + 54) / 255; +} + +bool displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) { + if (colorspace->depth == 16) { + *output_color = displayio_colorconverter_compute_rgb565(input_color); + return true; + } else if (colorspace->grayscale && colorspace->depth <= 8) { + uint8_t luma = displayio_colorconverter_compute_luma(input_color); + *output_color = luma >> (8 - colorspace->depth); + return true; + } + return false; +} + +bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) { + return displayio_colorconverter_convert(self, colorspace, input_color, output_color); } // Currently no refresh logic is needed for a ColorConverter. diff --git a/shared-module/displayio/ColorConverter.h b/shared-module/displayio/ColorConverter.h index 7f3c1a0a0..c48b98e6d 100644 --- a/shared-module/displayio/ColorConverter.h +++ b/shared-module/displayio/ColorConverter.h @@ -31,6 +31,7 @@ #include #include "py/obj.h" +#include "shared-module/displayio/Palette.h" typedef struct { mp_obj_base_t base; @@ -38,5 +39,8 @@ typedef struct { bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self); void displayio_colorconverter_finish_refresh(displayio_colorconverter_t *self); +bool displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color); +uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888); +uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888); #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_COLORCONVERTER_H diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 0ae88300a..9aee70e32 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -28,6 +28,7 @@ #include "py/runtime.h" #include "shared-bindings/displayio/FourWire.h" +#include "shared-bindings/displayio/I2CDisplay.h" #include "shared-bindings/displayio/ParallelBus.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/time/__init__.h" @@ -35,6 +36,7 @@ #include "supervisor/shared/display.h" #include +#include #include "tick.h" @@ -42,11 +44,14 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, - uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, + uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, + uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, - const mcu_pin_obj_t* backlight_pin, mp_float_t brightness, bool auto_brightness, + const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, bool single_byte_bounds, bool data_as_commands) { - self->color_depth = color_depth; + self->colorspace.depth = color_depth; + self->colorspace.grayscale = grayscale; + self->colorspace.pixels_in_byte_share_row = pixels_in_byte_share_row; self->set_column_command = set_column_command; self->set_row_command = set_row_command; self->write_ram_command = write_ram_command; @@ -54,6 +59,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->current_group = NULL; self->colstart = colstart; self->rowstart = rowstart; + self->brightness_command = brightness_command; self->auto_brightness = auto_brightness; self->data_as_commands = data_as_commands; self->single_byte_bounds = single_byte_bounds; @@ -66,6 +72,10 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->begin_transaction = common_hal_displayio_fourwire_begin_transaction; self->send = common_hal_displayio_fourwire_send; self->end_transaction = common_hal_displayio_fourwire_end_transaction; + } else if (MP_OBJ_IS_TYPE(bus, &displayio_i2cdisplay_type)) { + self->begin_transaction = common_hal_displayio_i2cdisplay_begin_transaction; + self->send = common_hal_displayio_i2cdisplay_send; + self->end_transaction = common_hal_displayio_i2cdisplay_end_transaction; } else { mp_raise_ValueError(translate("Unsupported display bus type")); } @@ -83,13 +93,13 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, bool delay = (data_size & DELAY) != 0; data_size &= ~DELAY; uint8_t *data = cmd + 2; - self->send(self->bus, true, cmd, 1); if (self->data_as_commands) { - // Loop through each parameter to force a CS toggle - for (uint32_t j=0; j < data_size; j++) { - self->send(self->bus, true, data + j, 1); - } + uint8_t full_command[data_size + 1]; + full_command[0] = cmd[0]; + memcpy(full_command + 1, data, data_size); + self->send(self->bus, true, full_command, data_size + 1); } else { + self->send(self->bus, true, cmd, 1); self->send(self->bus, false, data, data_size); } uint16_t delay_length_ms = 10; @@ -141,11 +151,13 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, } else { self->backlight_pwm.base.type = &pulseio_pwmout_type; common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm); - if (!self->auto_brightness) { - common_hal_displayio_display_set_brightness(self, brightness); - } } } + if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType || brightness_command <= 0xff)) { + common_hal_displayio_display_set_brightness(self, brightness); + } else { + self->current_brightness = -1.0; + } self->area.x1 = 0; self->area.y1 = 0; @@ -234,17 +246,7 @@ void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* s } mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t* self) { - if (self->backlight_pwm.base.type == &pulseio_pwmout_type) { - uint16_t duty_cycle = common_hal_pulseio_pwmout_get_duty_cycle(&self->backlight_pwm); - return duty_cycle / ((mp_float_t) 0xffff); - } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { - if (common_hal_digitalio_digitalinout_get_value(&self->backlight_inout)) { - return 1.0; - } else { - return 0.0; - } - } - return -1.0; + return self->current_brightness; } bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, mp_float_t brightness) { @@ -256,8 +258,26 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { common_hal_digitalio_digitalinout_set_value(&self->backlight_inout, brightness > 0.99); ok = true; + } else if (self->brightness_command < 0x100) { + ok = self->begin_transaction(self->bus); + if (ok) { + if (self->data_as_commands) { + uint8_t set_brightness[2] = {self->brightness_command, (uint8_t) (0xff * brightness)}; + self->send(self->bus, true, set_brightness, 2); + } else { + uint8_t command = self->brightness_command; + uint8_t hex_brightness = 0xff * brightness; + self->send(self->bus, true, &command, 1); + self->send(self->bus, false, &hex_brightness, 1); + } + self->end_transaction(self->bus); + } + } self->updating_backlight = false; + if (ok) { + self->current_brightness = brightness; + } return ok; } @@ -269,35 +289,67 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) { self->end_transaction(self->bus); } -void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - self->send(self->bus, true, &self->set_column_command, 1); - bool isCommand = self->data_as_commands; - if (self->single_byte_bounds) { - uint8_t data[2]; - data[0] = x0 + self->colstart; - data[1] = x1 - 1 + self->colstart; - self->send(self->bus, isCommand, (uint8_t*) data, 2); - } else { - uint16_t data[2]; - data[0] = __builtin_bswap16(x0 + self->colstart); - data[1] = __builtin_bswap16(x1 - 1 + self->colstart); - self->send(self->bus, isCommand, (uint8_t*) data, 4); +void displayio_display_set_region_to_update(displayio_display_obj_t* self, displayio_area_t* area) { + uint16_t x1 = area->x1; + uint16_t x2 = area->x2; + uint16_t y1 = area->y1; + uint16_t y2 = area->y2; + // Collapse down the dimension where multiple pixels are in a byte. + if (self->colorspace.depth < 8) { + uint8_t pixels_per_byte = 8 / self->colorspace.depth; + if (self->colorspace.pixels_in_byte_share_row) { + x1 /= pixels_per_byte; + x2 /= pixels_per_byte; + } else { + y1 /= pixels_per_byte; + y2 /= pixels_per_byte; + } + } + + // Set column. + uint8_t data[5]; + data[0] = self->set_column_command; + uint8_t data_length = 1; + if (!self->data_as_commands) { + self->send(self->bus, true, data, 1); + data_length = 0; } - self->send(self->bus, true, &self->set_row_command, 1); if (self->single_byte_bounds) { - uint8_t data[2]; - data[0] = y0 + self->rowstart; - data[1] = y1 - 1 + self->rowstart; - self->send(self->bus, isCommand, (uint8_t*) data, 2); + data[data_length] = x1 + self->colstart; + data[data_length + 1] = x2 - 1 + self->colstart; + data_length += 2; } else { - uint16_t data[2]; - data[0] = __builtin_bswap16(y0 + self->rowstart); - data[1] = __builtin_bswap16(y1 - 1 + self->rowstart); - self->send(self->bus, isCommand, (uint8_t*) data, 4); + x1 += self->colstart; + x2 += self->colstart - 1; + data[data_length] = x1 >> 8; + data[data_length + 1] = x1 & 0xff; + data[data_length + 2] = x2 >> 8; + data[data_length + 3] = x2 & 0xff; + data_length += 4; } + self->send(self->bus, self->data_as_commands, data, data_length); + + // Set row. + data[0] = self->set_row_command; + data_length = 1; if (!self->data_as_commands) { - self->send(self->bus, true, &self->write_ram_command, 1); + self->send(self->bus, true, data, 1); + data_length = 0; } + if (self->single_byte_bounds) { + data[data_length] = y1 + self->rowstart; + data[data_length + 1] = y2 - 1 + self->rowstart; + data_length += 2; + } else { + y1 += self->rowstart; + y2 += self->rowstart - 1; + data[data_length] = y1 >> 8; + data[data_length + 1] = y1 & 0xff; + data[data_length + 2] = y2 >> 8; + data[data_length + 3] = y2 & 0xff; + data_length += 4; + } + self->send(self->bus, self->data_as_commands, data, data_length); } void displayio_display_start_refresh(displayio_display_obj_t* self) { @@ -322,6 +374,9 @@ void displayio_display_finish_refresh(displayio_display_obj_t* self) { } void displayio_display_send_pixels(displayio_display_obj_t* self, uint8_t* pixels, uint32_t length) { + if (!self->data_as_commands) { + self->send(self->bus, true, &self->write_ram_command, 1); + } self->send(self->bus, false, pixels, length); } @@ -349,9 +404,33 @@ void release_display(displayio_display_obj_t* self) { } bool displayio_display_fill_area(displayio_display_obj_t *self, displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { - return displayio_group_fill_area(self->current_group, area, mask, buffer); + return displayio_group_fill_area(self->current_group, &self->colorspace, area, mask, buffer); } bool displayio_display_clip_area(displayio_display_obj_t *self, const displayio_area_t* area, displayio_area_t* clipped) { - return displayio_area_compute_overlap(&self->area, area, clipped); + bool overlaps = displayio_area_compute_overlap(&self->area, area, clipped); + if (!overlaps) { + return false; + } + // Expand the area if we have multiple pixels per byte and we need to byte + // align the bounds. + if (self->colorspace.depth < 8) { + uint8_t pixels_per_byte = 8 / self->colorspace.depth; + if (self->colorspace.pixels_in_byte_share_row) { + if (clipped->x1 % pixels_per_byte != 0) { + clipped->x1 -= clipped->x1 % pixels_per_byte; + } + if (clipped->x2 % pixels_per_byte != 0) { + clipped->x2 += pixels_per_byte - clipped->x2 % pixels_per_byte; + } + } else { + if (clipped->y1 % pixels_per_byte != 0) { + clipped->y1 -= clipped->y1 % pixels_per_byte; + } + if (clipped->y2 % pixels_per_byte != 0) { + clipped->y2 += pixels_per_byte - clipped->y2 % pixels_per_byte; + } + } + } + return true; } diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index fa8902ced..96d1c06d5 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -52,11 +52,13 @@ typedef struct { uint64_t last_backlight_refresh; displayio_buffer_transform_t transform; displayio_area_t area; + mp_float_t current_brightness; uint16_t width; uint16_t height; - uint16_t color_depth; + _displayio_colorspace_t colorspace; int16_t colstart; int16_t rowstart; + uint16_t brightness_command; uint8_t set_column_command; uint8_t set_row_command; uint8_t write_ram_command; diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c index d38da56fc..913635db8 100644 --- a/shared-module/displayio/FourWire.c +++ b/shared-module/displayio/FourWire.c @@ -59,6 +59,11 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self, common_hal_digitalio_digitalinout_construct(&self->reset, reset); common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); never_reset_pin_number(reset->number); + + common_hal_digitalio_digitalinout_set_value(&self->reset, false); + common_hal_mcu_delay_us(10); + common_hal_digitalio_digitalinout_set_value(&self->reset, true); + common_hal_mcu_delay_us(10); } never_reset_pin_number(command->number); @@ -88,13 +93,19 @@ bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t obj) { void common_hal_displayio_fourwire_send(mp_obj_t obj, bool command, uint8_t *data, uint32_t data_length) { displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj); + common_hal_digitalio_digitalinout_set_value(&self->command, !command); if (command) { - common_hal_digitalio_digitalinout_set_value(&self->chip_select, true); - common_hal_mcu_delay_us(1); - common_hal_digitalio_digitalinout_set_value(&self->chip_select, false); + // Toggle chip select after each command byte in case the display driver + // IC latches commands based on it. + for (size_t i = 0; i < data_length; i++) { + common_hal_busio_spi_write(self->bus, &data[i], 1); + common_hal_digitalio_digitalinout_set_value(&self->chip_select, true); + common_hal_mcu_delay_us(1); + common_hal_digitalio_digitalinout_set_value(&self->chip_select, false); + } + } else { + common_hal_busio_spi_write(self->bus, data, data_length); } - common_hal_digitalio_digitalinout_set_value(&self->command, !command); - common_hal_busio_spi_write(self->bus, data, data_length); } void common_hal_displayio_fourwire_end_transaction(mp_obj_t obj) { diff --git a/shared-module/displayio/FourWire.h b/shared-module/displayio/FourWire.h index 743139e62..a4260a3ac 100644 --- a/shared-module/displayio/FourWire.h +++ b/shared-module/displayio/FourWire.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H -#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H +#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FOURWIRE_H +#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FOURWIRE_H #include "common-hal/busio/SPI.h" #include "common-hal/digitalio/DigitalInOut.h" @@ -43,4 +43,4 @@ typedef struct { uint8_t phase; } displayio_fourwire_obj_t; -#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H +#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FOURWIRE_H diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index 15060e87b..38418a029 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -270,19 +270,19 @@ void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* self->in_group = false; } -bool displayio_group_fill_area(displayio_group_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t* buffer) { +bool displayio_group_fill_area(displayio_group_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t* buffer) { // Track if any of the layers finishes filling in the given area. We can ignore any remaining // layers at that point. bool full_coverage = false; for (int32_t i = self->size - 1; i >= 0 ; i--) { mp_obj_t layer = self->children[i].native; if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { - if (displayio_tilegrid_fill_area(layer, area, mask, buffer)) { + if (displayio_tilegrid_fill_area(layer, colorspace, area, mask, buffer)) { full_coverage = true; break; } } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { - if (displayio_group_fill_area(layer, area, mask, buffer)) { + if (displayio_group_fill_area(layer, colorspace, area, mask, buffer)) { full_coverage = true; break; } diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h index 7ce19a4cd..4e2308e56 100644 --- a/shared-module/displayio/Group.h +++ b/shared-module/displayio/Group.h @@ -32,6 +32,7 @@ #include "py/obj.h" #include "shared-module/displayio/area.h" +#include "shared-module/displayio/Palette.h" typedef struct { mp_obj_t native; @@ -54,7 +55,7 @@ typedef struct { void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); bool displayio_group_get_previous_area(displayio_group_t *group, displayio_area_t* area); -bool displayio_group_fill_area(displayio_group_t *group, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); +bool displayio_group_fill_area(displayio_group_t *group, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); void displayio_group_update_transform(displayio_group_t *group, const displayio_buffer_transform_t* parent_transform); void displayio_group_finish_refresh(displayio_group_t *self); displayio_area_t* displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t* tail); diff --git a/shared-module/displayio/I2CDisplay.c b/shared-module/displayio/I2CDisplay.c new file mode 100644 index 000000000..9d8949528 --- /dev/null +++ b/shared-module/displayio/I2CDisplay.c @@ -0,0 +1,105 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/displayio/I2CDisplay.h" + +#include +#include + +#include "py/gc.h" +#include "py/runtime.h" +#include "shared-bindings/busio/I2C.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/time/__init__.h" + +#include "tick.h" + +void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self, + busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset) { + + // Probe the bus to see if a device acknowledges the given address. + if (!common_hal_busio_i2c_probe(i2c, device_address)) { + mp_raise_ValueError_varg(translate("Unable to find I2C Display at %x"), device_address); + } + + // Write to the device and return 0 on success or an appropriate error code from mperrno.h + self->bus = i2c; + common_hal_busio_i2c_never_reset(self->bus); + // Our object is statically allocated off the heap so make sure the bus object lives to the end + // of the heap as well. + gc_never_free(self->bus); + + self->address = device_address; + + if (reset != NULL) { + common_hal_digitalio_digitalinout_construct(&self->reset, reset); + common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); + never_reset_pin_number(reset->number); + + common_hal_digitalio_digitalinout_set_value(&self->reset, false); + common_hal_mcu_delay_us(1); + common_hal_digitalio_digitalinout_set_value(&self->reset, true); + } +} + +void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) { + if (self->bus == &self->inline_bus) { + common_hal_busio_i2c_deinit(self->bus); + } + + reset_pin_number(self->reset.pin->number); +} + +bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t obj) { + displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj); + if (!common_hal_busio_i2c_try_lock(self->bus)) { + return false; + } + return true; +} + +void common_hal_displayio_i2cdisplay_send(mp_obj_t obj, bool command, uint8_t *data, uint32_t data_length) { + displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj); + if (command) { + uint8_t command_bytes[2 * data_length]; + for (uint32_t i = 0; i < data_length; i++) { + command_bytes[2 * i] = 0x80; + command_bytes[2 * i + 1] = data[i]; + } + common_hal_busio_i2c_write(self->bus, self->address, command_bytes, 2 * data_length, true); + } else { + uint8_t data_bytes[data_length + 1]; + data_bytes[0] = 0x40; + memcpy(data_bytes + 1, data, data_length); + common_hal_busio_i2c_write(self->bus, self->address, data_bytes, data_length + 1, true); + } +} + +void common_hal_displayio_i2cdisplay_end_transaction(mp_obj_t obj) { + displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj); + common_hal_busio_i2c_unlock(self->bus); +} diff --git a/shared-module/displayio/I2CDisplay.h b/shared-module/displayio/I2CDisplay.h new file mode 100644 index 000000000..4636c3f73 --- /dev/null +++ b/shared-module/displayio/I2CDisplay.h @@ -0,0 +1,41 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_I2CDISPLAY_H +#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_I2CDISPLAY_H + +#include "common-hal/busio/I2C.h" +#include "common-hal/digitalio/DigitalInOut.h" + +typedef struct { + mp_obj_base_t base; + busio_i2c_obj_t* bus; + busio_i2c_obj_t inline_bus; + digitalio_digitalinout_obj_t reset; + uint16_t address; +} displayio_i2cdisplay_obj_t; + +#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_I2CDISPLAY_H diff --git a/shared-module/displayio/Palette.c b/shared-module/displayio/Palette.c index 8dc6e766b..444151b3c 100644 --- a/shared-module/displayio/Palette.c +++ b/shared-module/displayio/Palette.c @@ -26,49 +26,49 @@ #include "shared-bindings/displayio/Palette.h" +#include "shared-module/displayio/ColorConverter.h" + void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t color_count) { self->color_count = color_count; - self->colors = (uint32_t *) m_malloc(color_count * sizeof(uint16_t), false); - uint32_t opaque_byte_count = color_count / 8; - if (color_count % 8 > 0) { - opaque_byte_count += 1; - } - self->opaque = (uint32_t *) m_malloc(opaque_byte_count, false); + self->colors = (_displayio_color_t *) m_malloc(color_count * sizeof(_displayio_color_t), false); } void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t palette_index) { - self->opaque[palette_index / 32] &= ~(0x1 << (palette_index % 32)); + self->colors[palette_index].transparent = false; } void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t palette_index) { - self->opaque[palette_index / 32] |= (0x1 << (palette_index % 32)); + self->colors[palette_index].transparent = true; +} + +uint32_t common_hal_displayio_palette_get_len(displayio_palette_t* self) { + return self->color_count; } void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t palette_index, uint32_t color) { - uint32_t shift = (palette_index % 2) * 16; - uint32_t masked = self->colors[palette_index / 2] & ~(0xffff << shift); - uint32_t r5 = (color >> 19); - uint32_t g6 = (color >> 10) & 0x3f; - uint32_t b5 = (color >> 3) & 0x1f; - uint32_t packed = r5 << 11 | g6 << 5 | b5; - // swap bytes - packed = __builtin_bswap16(packed); - uint32_t final_color = masked | packed << shift; - if (self->colors[palette_index / 2] == final_color) { + if (self->colors[palette_index].rgb888 == color) { return; } - self->colors[palette_index / 2] = final_color; + self->colors[palette_index].rgb888 = color; + self->colors[palette_index].luma = displayio_colorconverter_compute_luma(color); + self->colors[palette_index].rgb565 = displayio_colorconverter_compute_rgb565(color); self->needs_refresh = true; } -bool displayio_palette_get_color(displayio_palette_t *self, uint32_t palette_index, uint16_t* color) { - if (palette_index > self->color_count) { - return false; +uint32_t common_hal_displayio_palette_get_color(displayio_palette_t* self, uint32_t palette_index) { + return self->colors[palette_index].rgb888; +} + +bool displayio_palette_get_color(displayio_palette_t *self, const _displayio_colorspace_t* colorspace, uint32_t palette_index, uint32_t* color) { + if (palette_index > self->color_count || self->colors[palette_index].transparent) { + return false; // returns opaque } - if ((self->opaque[palette_index / 32] & (0x1 << (palette_index % 32))) != 0) { - return false; + + if (colorspace->grayscale) { + *color = self->colors[palette_index].luma >> (8 - colorspace->depth); + } else { + *color = self->colors[palette_index].rgb565; } - *color = (self->colors[palette_index / 2] >> (16 * (palette_index % 2))) & 0xffff; return true; } diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h index 3813e8bdd..6f5e2774c 100644 --- a/shared-module/displayio/Palette.h +++ b/shared-module/displayio/Palette.h @@ -32,15 +32,28 @@ #include "py/obj.h" +typedef struct { + uint8_t depth; + bool grayscale; + bool pixels_in_byte_share_row; + uint8_t hue; +} _displayio_colorspace_t; + +typedef struct { + uint32_t rgb888; + uint16_t rgb565; + uint8_t luma; + bool transparent; // This may have additional bits added later for blending. +} _displayio_color_t; + typedef struct { mp_obj_base_t base; - uint32_t* opaque; - uint32_t* colors; + _displayio_color_t* colors; uint32_t color_count; bool needs_refresh; } displayio_palette_t; -bool displayio_palette_get_color(displayio_palette_t *palette, uint32_t palette_index, uint16_t* color); +bool displayio_palette_get_color(displayio_palette_t *palette, const _displayio_colorspace_t* colorspace, uint32_t palette_index, uint32_t* color); bool displayio_palette_needs_refresh(displayio_palette_t *self); void displayio_palette_finish_refresh(displayio_palette_t *self); diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 0cd00e0ce..77e6daf6f 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -291,7 +291,7 @@ void common_hal_displayio_tilegrid_set_top_left(displayio_tilegrid_t *self, uint self->full_change = true; } -bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { +bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { // If no tiles are present we have no impact. uint8_t* tiles = self->tiles; if (self->inline_tiles) { @@ -371,12 +371,13 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_ar y_shift = temp_shift; } + uint8_t pixels_per_byte = 8 / colorspace->depth; for (int16_t y = start_y; y < end_y; y++) { - int16_t row_start = start + (y - start_y + y_shift) * y_stride; + int16_t row_start = start + (y - start_y + y_shift) * y_stride; // in pixels int16_t local_y = y / self->absolute_transform->scale; for (int16_t x = start_x; x < end_x; x++) { // Compute the destination pixel in the buffer and mask based on the transformations. - int16_t offset = row_start + (x - start_x + x_shift) * x_stride; + int16_t offset = row_start + (x - start_x + x_shift) * x_stride; // in pixels // This is super useful for debugging out range accesses. Uncomment to use. // if (offset < 0 || offset >= (int32_t) displayio_area_size(area)) { @@ -404,23 +405,38 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_ar value = common_hal_displayio_ondiskbitmap_get_pixel(self->bitmap, tile_x, tile_y); } - uint16_t* pixel = ((uint16_t*) buffer) + offset; + uint32_t pixel; + bool opaque = true; if (self->pixel_shader == mp_const_none) { - *pixel = value; - return true; + pixel = value; } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type)) { - if (!displayio_palette_get_color(self->pixel_shader, value, pixel)) { - // A pixel is transparent so we haven't fully covered the area ourselves. - full_coverage = false; - } else { - mask[offset / 32] |= 1 << (offset % 32); - } + opaque = displayio_palette_get_color(self->pixel_shader, colorspace, value, &pixel); } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type)) { - if (!common_hal_displayio_colorconverter_convert(self->pixel_shader, value, pixel)) { - // A pixel is transparent so we haven't fully covered the area ourselves. - full_coverage = false; - } else { - mask[offset / 32] |= 1 << (offset % 32); + opaque = displayio_colorconverter_convert(self->pixel_shader, colorspace, value, &pixel); + } + if (!opaque) { + // A pixel is transparent so we haven't fully covered the area ourselves. + full_coverage = false; + } else { + mask[offset / 32] |= 1 << (offset % 32); + if (colorspace->depth == 16) { + *(((uint16_t*) buffer) + offset) = pixel; + } else if (colorspace->depth == 8) { + *(((uint8_t*) buffer) + offset) = pixel; + } else if (colorspace->depth < 8) { + // Reorder the offsets to pack multiple rows into a byte (meaning they share a column). + if (!colorspace->pixels_in_byte_share_row) { + uint16_t width = displayio_area_width(area); + uint16_t row = offset / width; + uint16_t col = offset % width; + // Dividing by pixels_per_byte does truncated division even if we multiply it back out. + offset = col * pixels_per_byte + (row / pixels_per_byte) * pixels_per_byte * width + row % pixels_per_byte; + // Also useful for validating that the bitpacking worked correctly. + // if (offset > displayio_area_size(area)) { + // asm("bkpt"); + // } + } + ((uint8_t*)buffer)[offset / pixels_per_byte] |= pixel << ((offset % pixels_per_byte) * colorspace->depth); } } } diff --git a/shared-module/displayio/TileGrid.h b/shared-module/displayio/TileGrid.h index 4d97eccc2..fb6033e9c 100644 --- a/shared-module/displayio/TileGrid.h +++ b/shared-module/displayio/TileGrid.h @@ -32,6 +32,7 @@ #include "py/obj.h" #include "shared-module/displayio/area.h" +#include "shared-module/displayio/Palette.h" typedef struct { mp_obj_base_t base; @@ -71,7 +72,7 @@ displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *sel // Area is always in absolute screen coordinates. Update transform is used to inform TileGrids how // they relate to it. -bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); +bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); void displayio_tilegrid_update_transform(displayio_tilegrid_t *group, const displayio_buffer_transform_t* parent_transform); // Fills in area with the maximum bounds of all related pixels in the last rendered frame. Returns diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index b6709e0eb..97060aaeb 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -19,9 +19,10 @@ #include "supervisor/usb.h" primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT]; +uint32_t frame_count = 0; bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area) { - uint16_t buffer_size = 512; + uint16_t buffer_size = 128; // In uint32_ts displayio_area_t clipped; // Clip the area to the display by overlapping the areas. If there is no overlap then we're done. @@ -30,15 +31,36 @@ bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area } uint16_t subrectangles = 1; uint16_t rows_per_buffer = displayio_area_height(&clipped); - if (displayio_area_size(area) > buffer_size) { - rows_per_buffer = buffer_size / displayio_area_width(&clipped); + uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / display->colorspace.depth; + uint16_t pixels_per_buffer = displayio_area_size(&clipped); + if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { + rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped); + if (rows_per_buffer == 0) { + rows_per_buffer = 1; + } + // If pixels are packed by column then ensure rows_per_buffer is on a byte boundary. + if (display->colorspace.depth < 8 && !display->colorspace.pixels_in_byte_share_row) { + uint8_t pixels_per_byte = 8 / display->colorspace.depth; + if (rows_per_buffer % pixels_per_byte != 0) { + rows_per_buffer -= rows_per_buffer % pixels_per_byte; + } + } subrectangles = displayio_area_height(&clipped) / rows_per_buffer; if (displayio_area_height(&clipped) % rows_per_buffer != 0) { subrectangles++; } - buffer_size = rows_per_buffer * displayio_area_width(&clipped); + pixels_per_buffer = rows_per_buffer * displayio_area_width(&clipped); + buffer_size = pixels_per_buffer / pixels_per_word; + if (pixels_per_buffer % pixels_per_word) { + buffer_size += 1; + } } - uint32_t buffer[buffer_size / 2]; + + // Allocated and shared as a uint32_t array so the compiler knows the + // alignment everywhere. + uint32_t buffer[buffer_size]; + volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1; + uint32_t mask[mask_length]; uint16_t remaining_rows = displayio_area_height(&clipped); for (uint16_t j = 0; j < subrectangles; j++) { @@ -54,37 +76,30 @@ bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area remaining_rows -= rows_per_buffer; displayio_display_begin_transaction(display); - displayio_display_set_region_to_update(display, subrectangle.x1, subrectangle.y1, - subrectangle.x2, subrectangle.y2); + displayio_display_set_region_to_update(display, &subrectangle); displayio_display_end_transaction(display); - uint32_t mask[(buffer_size / 32) + 1]; - for (uint16_t k = 0; k < (buffer_size / 32) + 1; k++) { - mask[k] = 0x00000000; + uint16_t subrectangle_size_bytes; + if (display->colorspace.depth >= 8) { + subrectangle_size_bytes = displayio_area_size(&subrectangle) * (display->colorspace.depth / 8); + } else { + subrectangle_size_bytes = displayio_area_size(&subrectangle) / (8 / display->colorspace.depth); } - bool full_coverage = displayio_display_fill_area(display, &subrectangle, mask, buffer); - if (!full_coverage) { - uint32_t index = 0; - uint32_t current_mask = 0; - for (int16_t y = subrectangle.y1; y < subrectangle.y2; y++) { - for (int16_t x = subrectangle.x1; x < subrectangle.x2; x++) { - if (index % 32 == 0) { - current_mask = mask[index / 32]; - } - if ((current_mask & (1 << (index % 32))) == 0) { - ((uint16_t*) buffer)[index] = 0x0000; - } - index++; - } - } + for (uint16_t k = 0; k < mask_length; k++) { + mask[k] = 0x00000000; + } + for (uint16_t k = 0; k < buffer_size; k++) { + buffer[k] = 0x00000000; } + displayio_display_fill_area(display, &subrectangle, mask, buffer); + if (!displayio_display_begin_transaction(display)) { // Can't acquire display bus; skip the rest of the data. Try next display. return false; } - displayio_display_send_pixels(display, (uint8_t*) buffer, displayio_area_size(&subrectangle) * sizeof(uint16_t)); + displayio_display_send_pixels(display, (uint8_t*) buffer, subrectangle_size_bytes); displayio_display_end_transaction(display); // TODO(tannewt): Make refresh displays faster so we don't starve other @@ -96,7 +111,6 @@ bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area // Check for recursive calls to displayio_refresh_displays. bool refresh_displays_in_progress = false; -uint32_t frame_count = 0; void displayio_refresh_displays(void) { if (mp_hal_is_interrupted()) { @@ -153,6 +167,8 @@ void common_hal_displayio_release_displays(void) { continue; } else if (bus_type == &displayio_fourwire_type) { common_hal_displayio_fourwire_deinit(&displays[i].fourwire_bus); + } else if (bus_type == &displayio_i2cdisplay_type) { + common_hal_displayio_i2cdisplay_deinit(&displays[i].i2cdisplay_bus); } else if (bus_type == &displayio_parallelbus_type) { common_hal_displayio_parallelbus_deinit(&displays[i].parallel_bus); } @@ -169,30 +185,53 @@ void common_hal_displayio_release_displays(void) { void reset_displays(void) { // The SPI buses used by FourWires may be allocated on the heap so we need to move them inline. for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - if (displays[i].fourwire_bus.base.type != &displayio_fourwire_type) { - continue; - } - displayio_fourwire_obj_t* fourwire = &displays[i].fourwire_bus; - if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) || - ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { - busio_spi_obj_t* original_spi = fourwire->bus; - #if BOARD_SPI - // We don't need to move original_spi if it is the board.SPI object because it is - // statically allocated already. (Doing so would also make it impossible to reference in - // a subsequent VM run.) - if (original_spi == common_hal_board_get_spi()) { - continue; + if (displays[i].fourwire_bus.base.type == &displayio_fourwire_type) { + displayio_fourwire_obj_t* fourwire = &displays[i].fourwire_bus; + if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) || + ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { + busio_spi_obj_t* original_spi = fourwire->bus; + #if BOARD_SPI + // We don't need to move original_spi if it is the board.SPI object because it is + // statically allocated already. (Doing so would also make it impossible to reference in + // a subsequent VM run.) + if (original_spi == common_hal_board_get_spi()) { + continue; + } + #endif + memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); + fourwire->bus = &fourwire->inline_bus; + // Check for other displays that use the same spi bus and swap them too. + for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { + if (displays[i].fourwire_bus.base.type == &displayio_fourwire_type && + displays[i].fourwire_bus.bus == original_spi) { + displays[i].fourwire_bus.bus = &fourwire->inline_bus; + } } - #endif - memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); - fourwire->bus = &fourwire->inline_bus; - // Check for other displays that use the same spi bus and swap them too. - for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { - if (displays[i].fourwire_bus.bus == original_spi) { - displays[i].fourwire_bus.bus = &fourwire->inline_bus; + } + } else if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type) { + displayio_i2cdisplay_obj_t* i2c = &displays[i].i2cdisplay_bus; + if (((uint32_t) i2c->bus) < ((uint32_t) &displays) || + ((uint32_t) i2c->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { + busio_i2c_obj_t* original_i2c = i2c->bus; + #if BOARD_I2C + // We don't need to move original_i2c if it is the board.SPI object because it is + // statically allocated already. (Doing so would also make it impossible to reference in + // a subsequent VM run.) + if (original_i2c == common_hal_board_get_i2c()) { + continue; + } + #endif + memcpy(&i2c->inline_bus, original_i2c, sizeof(busio_i2c_obj_t)); + i2c->bus = &i2c->inline_bus; + // Check for other displays that use the same i2c bus and swap them too. + for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { + if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type && + displays[i].i2cdisplay_bus.bus == original_i2c) { + displays[i].i2cdisplay_bus.bus = &i2c->inline_bus; + } + } } } - } } for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h index 18c1a4f4a..caa5ce36d 100644 --- a/shared-module/displayio/__init__.h +++ b/shared-module/displayio/__init__.h @@ -30,11 +30,13 @@ #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/FourWire.h" #include "shared-bindings/displayio/Group.h" +#include "shared-bindings/displayio/I2CDisplay.h" #include "shared-bindings/displayio/ParallelBus.h" typedef struct { union { displayio_fourwire_obj_t fourwire_bus; + displayio_i2cdisplay_obj_t i2cdisplay_bus; displayio_parallelbus_obj_t parallel_bus; }; displayio_display_obj_t display; diff --git a/shared-module/terminalio/Terminal.c b/shared-module/terminalio/Terminal.c index 7adf9d032..86c3e903e 100644 --- a/shared-module/terminalio/Terminal.c +++ b/shared-module/terminalio/Terminal.c @@ -35,6 +35,8 @@ void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, d self->font = font; self->tilegrid = tilegrid; self->first_row = 0; + + common_hal_displayio_tilegrid_set_top_left(self->tilegrid, 0, 1); } size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, const byte *data, size_t len, int *errcode) { diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 414f85034..6a39cbe8e 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -82,8 +82,7 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { grid->pixel_height = height_in_tiles * grid->tile_height; grid->tiles = tiles; - supervisor_terminal.cursor_x = 0; - supervisor_terminal.cursor_y = 0; + common_hal_terminalio_terminal_construct(&supervisor_terminal, grid, &supervisor_terminal_font); } void supervisor_stop_terminal(void) { @@ -147,17 +146,49 @@ displayio_bitmap_t blinka_bitmap = { .read_only = true }; -uint32_t blinka_transparency[1] = {0x80000000}; - -// These colors are RGB 565 with the bytes swapped. -uint32_t blinka_colors[8] = {0x78890000, 0x9F86B8FC, 0xffff0D5A, 0x0000f501, - 0x00000000, 0x00000000, 0x00000000, 0x00000000}; +_displayio_color_t blinka_colors[7] = { + { + .rgb888 = 0x000000, + .rgb565 = 0x0000, + .luma = 0x00, + .transparent = true + }, + { + .rgb888 = 0x8428bc, + .rgb565 = 0x7889, + .luma = 0xff // We cheat the luma here. It is actually 0x60 + }, + { + .rgb888 = 0xff89bc, + .rgb565 = 0xB8FC, + .luma = 0xb5 + }, + { + .rgb888 = 0x7beffe, + .rgb565 = 0x9F86, + .luma = 0xe0 + }, + { + .rgb888 = 0x51395f, + .rgb565 = 0x0D5A, + .luma = 0x47 + }, + { + .rgb888 = 0xffffff, + .rgb565 = 0xffff, + .luma = 0xff + }, + { + .rgb888 = 0x0736a0, + .rgb565 = 0xf501, + .luma = 0x44 + }, +}; displayio_palette_t blinka_palette = { .base = {.type = &displayio_palette_type }, - .opaque = blinka_transparency, .colors = blinka_colors, - .color_count = 16, + .color_count = 7, .needs_refresh = false }; diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py index 2c674c8eb..a731cbd9c 100644 --- a/tools/gen_display_resources.py +++ b/tools/gen_display_resources.py @@ -98,14 +98,21 @@ c_file.write("""\ """) c_file.write("""\ -uint32_t terminal_transparency[1] = {0x00000000}; - -// These colors are RGB 565 with the bytes swapped. -uint32_t terminal_colors[1] = {0xffff0000}; +_displayio_color_t terminal_colors[2] = { + { + .rgb888 = 0x000000, + .rgb565 = 0x0000, + .luma = 0x00 + }, + { + .rgb888 = 0xffffff, + .rgb565 = 0xffff, + .luma = 0xff + }, +}; displayio_palette_t supervisor_terminal_color = { .base = {.type = &displayio_palette_type }, - .opaque = terminal_transparency, .colors = terminal_colors, .color_count = 2, .needs_refresh = false -- cgit v1.2.3 From 1d1b8703b6c108b72a1abda9312646895f542672 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 19 Jul 2019 16:05:13 -0700 Subject: Review feedback including NO_BRIGHTNESS_COMMAND macro --- locale/ID.po | 13 +++++++-- locale/circuitpython.pot | 13 +++++++-- locale/de_DE.po | 13 +++++++-- locale/en_US.po | 13 +++++++-- locale/en_x_pirate.po | 13 +++++++-- locale/es.po | 13 +++++++-- locale/fil.po | 13 +++++++-- locale/fr.po | 13 +++++++-- locale/it_IT.po | 13 +++++++-- locale/pl.po | 13 +++++++-- locale/pt_BR.po | 13 +++++++-- locale/zh_Latn_pinyin.po | 13 +++++++-- .../atmel-samd/boards/hallowing_m0_express/board.c | 2 +- ports/atmel-samd/boards/pybadge/board.c | 2 +- ports/atmel-samd/boards/pybadge_airlift/board.c | 2 +- ports/atmel-samd/boards/pygamer/board.c | 2 +- ports/atmel-samd/boards/pygamer_advance/board.c | 2 +- ports/atmel-samd/boards/pyportal/board.c | 2 +- ports/atmel-samd/boards/ugame10/board.c | 2 +- shared-bindings/displayio/ColorConverter.c | 2 ++ shared-bindings/displayio/ColorConverter.h | 2 +- shared-bindings/displayio/Display.c | 10 +++++-- shared-bindings/displayio/Display.h | 2 ++ shared-bindings/displayio/I2CDisplay.c | 2 +- shared-bindings/displayio/Palette.c | 2 +- shared-module/displayio/ColorConverter.c | 4 +-- shared-module/displayio/Display.c | 32 ++++++++++------------ shared-module/displayio/Palette.h | 2 ++ shared-module/displayio/TileGrid.c | 2 +- 29 files changed, 161 insertions(+), 69 deletions(-) (limited to 'shared-bindings') diff --git a/locale/ID.po b/locale/ID.po index 5e555a025..b211d5379 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -312,6 +312,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "Kedua pin harus mendukung hardware interrut" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -443,8 +447,11 @@ msgstr "Clock unit sedang digunakan" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 67271258a..d91e2b3ac 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -308,6 +308,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -433,8 +437,11 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index b0ebf9bcb..748833147 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -312,6 +312,10 @@ msgstr "Bit depth muss ein Vielfaches von 8 sein." msgid "Both pins must support hardware interrupts" msgstr "Beide pins müssen Hardware Interrupts unterstützen" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "Die Helligkeit muss zwischen 0 und 255 liegen" @@ -437,8 +441,11 @@ msgstr "Clock unit wird benutzt" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" diff --git a/locale/en_US.po b/locale/en_US.po index 91fd15ac8..38074de98 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -308,6 +308,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -433,8 +437,11 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 5f0ab319f..9bee12d2a 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -312,6 +312,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -437,8 +441,11 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" diff --git a/locale/es.po b/locale/es.po index ff44238df..33cdfe348 100644 --- a/locale/es.po +++ b/locale/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -316,6 +316,10 @@ msgstr "Bits depth debe ser múltiplo de 8." msgid "Both pins must support hardware interrupts" msgstr "Ambos pines deben soportar interrupciones por hardware" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "El brillo debe estar entro 0 y 255" @@ -441,8 +445,11 @@ msgstr "Clock unit está siendo utilizado" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Entrada de columna debe ser digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Command debe estar entre 0 y 255." diff --git a/locale/fil.po b/locale/fil.po index 4693cde64..4f05812f7 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -314,6 +314,10 @@ msgstr "Bit depth ay dapat multiple ng 8." msgid "Both pins must support hardware interrupts" msgstr "Ang parehong mga pin ay dapat na sumusuporta sa hardware interrupts" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "Ang liwanag ay dapat sa gitna ng 0 o 255" @@ -441,8 +445,11 @@ msgstr "Clock unit ginagamit" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Sa gitna ng 0 o 255 dapat ang bytes." diff --git a/locale/fr.po b/locale/fr.po index db2b659dd..a948630ee 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -319,6 +319,10 @@ msgstr "La profondeur de bit doit être un multiple de 8." msgid "Both pins must support hardware interrupts" msgstr "Les deux entrées doivent supporter les interruptions matérielles" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "La luminosité doit être entre 0 et 255" @@ -447,8 +451,11 @@ msgstr "Horloge en cours d'utilisation" msgid "Column entry must be digitalio.DigitalInOut" msgstr "L'entrée 'Column' doit être un digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "La commande doit être un entier entre 0 et 255" diff --git a/locale/it_IT.po b/locale/it_IT.po index 0e717f15b..40a685f75 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -314,6 +314,10 @@ msgstr "La profondità di bit deve essere multipla di 8." msgid "Both pins must support hardware interrupts" msgstr "Entrambi i pin devono supportare gli interrupt hardware" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "La luminosità deve essere compreso tra 0 e 255" @@ -442,8 +446,11 @@ msgstr "Unità di clock in uso" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "I byte devono essere compresi tra 0 e 255" diff --git a/locale/pl.po b/locale/pl.po index 2bc1a7557..896785126 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -311,6 +311,10 @@ msgstr "Głębia musi być wielokrotnością 8." msgid "Both pins must support hardware interrupts" msgstr "Obie nóżki muszą wspierać przerwania sprzętowe" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "Jasność musi być pomiędzy 0 a 255" @@ -436,8 +440,11 @@ msgstr "Jednostka zegara w użyciu" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Kolumny muszą być typu digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Komenda musi być int pomiędzy 0 a 255" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 7af2e3d60..7e052bfb7 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -311,6 +311,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "Ambos os pinos devem suportar interrupções de hardware" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "O brilho deve estar entre 0 e 255" @@ -438,8 +442,11 @@ msgstr "Unidade de Clock em uso" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Os bytes devem estar entre 0 e 255." diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 7f6e80236..258a4d3df 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -312,6 +312,10 @@ msgstr "Bǐtè shēndù bìxū shì 8 bèi yǐshàng." msgid "Both pins must support hardware interrupts" msgstr "Liǎng gè yǐn jiǎo dōu bìxū zhīchí yìngjiàn zhōngduàn" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "Liàngdù bìxū jiè yú 0 dào 255 zhī jiān" @@ -437,8 +441,11 @@ msgstr "Shǐyòng shízhōng dānwèi" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Liè tiáomù bìxū shì digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Mìnglìng bìxū shì 0 dào 255 zhī jiān de int" diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 1bbbfbaf8..be1741c87 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -100,7 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, - 0x100, // Brightness command. Only available when <= 0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 7e6c11dd4..c9dca0329 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -102,7 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin - 0x100, // no brightness command + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge_airlift/board.c b/ports/atmel-samd/boards/pybadge_airlift/board.c index d7f291d7d..eeab3f2b2 100644 --- a/ports/atmel-samd/boards/pybadge_airlift/board.c +++ b/ports/atmel-samd/boards/pybadge_airlift/board.c @@ -80,7 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin - 0x100, // brightness command, only valid <= 0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index e59b7c458..d413c8e34 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -102,7 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin - 0x100, // Brightness command. Only available when < 0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer_advance/board.c b/ports/atmel-samd/boards/pygamer_advance/board.c index b23353998..498a29db2 100644 --- a/ports/atmel-samd/boards/pygamer_advance/board.c +++ b/ports/atmel-samd/boards/pygamer_advance/board.c @@ -80,7 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin - 0x100, // Brightness command. Only available when < 0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 7fffb764f..938072158 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -92,7 +92,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PB31, // Backlight pin - 0x100, // Brightness command > 0xff is none s + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index 27a03ad91..15e22a72c 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -100,7 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), NULL, - 0x100, // brightness command. Only valid <=0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness false, // auto_brightness false, // single_byte_bounds diff --git a/shared-bindings/displayio/ColorConverter.c b/shared-bindings/displayio/ColorConverter.c index e170e0340..d9524870d 100644 --- a/shared-bindings/displayio/ColorConverter.c +++ b/shared-bindings/displayio/ColorConverter.c @@ -62,6 +62,8 @@ STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, siz //| .. method:: convert(color) //| +//| Converts the given RGB888 color to RGB565 +//| STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t color_obj) { displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/displayio/ColorConverter.h b/shared-bindings/displayio/ColorConverter.h index 8f61e6642..24895500e 100644 --- a/shared-bindings/displayio/ColorConverter.h +++ b/shared-bindings/displayio/ColorConverter.h @@ -34,6 +34,6 @@ extern const mp_obj_type_t displayio_colorconverter_type; void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self); -bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color); +void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_COLORCONVERTER_H diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 2586e562f..361a37ece 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -119,7 +119,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, - { MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x100} }, + { MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = NO_BRIGHTNESS_COMMAND} }, { MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, { MP_QSTR_auto_brightness, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, @@ -242,10 +242,14 @@ STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_brightness_obj, displayio_display_obj_get_brightness); -STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness) { +STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) { displayio_display_obj_t *self = native_display(self_in); common_hal_displayio_display_set_auto_brightness(self, false); - bool ok = common_hal_displayio_display_set_brightness(self, mp_obj_get_float(brightness)); + mp_float_t brightness = mp_obj_get_float(brightness_obj); + if (brightness < 0 || brightness > 1.0) { + mp_raise_ValueError(translate("Brightness must be 0-1.0")); + } + bool ok = common_hal_displayio_display_set_brightness(self, brightness); if (!ok) { mp_raise_RuntimeError(translate("Brightness not adjustable")); } diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index a60a0cf5a..e765e6f25 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -36,6 +36,8 @@ extern const mp_obj_type_t displayio_display_type; #define DELAY 0x80 +#define NO_BRIGHTNESS_COMMAND 0x100 + void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c index 2aac49b4d..1f74e8c9e 100644 --- a/shared-bindings/displayio/I2CDisplay.c +++ b/shared-bindings/displayio/I2CDisplay.c @@ -103,7 +103,7 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t STATIC mp_obj_t displayio_i2cdisplay_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) { mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj); if (!MP_OBJ_IS_SMALL_INT(command_obj) || command_int > 255 || command_int < 0) { - mp_raise_ValueError(translate("Command must be an int between 0 and 255")); + mp_raise_ValueError(translate("Command must be 0-255")); } uint8_t command = command_int; mp_buffer_info_t bufinfo; diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 974cadb02..dda58e3c5 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -74,7 +74,7 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { - case MP_UNARY_OP_BOOL: return mp_obj_new_bool(true); + case MP_UNARY_OP_BOOL: return mp_const_true; case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_palette_get_len(self)); default: return MP_OBJ_NULL; // op not supported diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c index 563d40c51..6b9bd5840 100644 --- a/shared-module/displayio/ColorConverter.c +++ b/shared-module/displayio/ColorConverter.c @@ -57,8 +57,8 @@ bool displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d return false; } -bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) { - return displayio_colorconverter_convert(self, colorspace, input_color, output_color); +void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) { + displayio_colorconverter_convert(self, colorspace, input_color, output_color); } // Currently no refresh logic is needed for a ColorConverter. diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 9aee70e32..a8515b9e5 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -153,7 +153,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm); } } - if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType || brightness_command <= 0xff)) { + if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType || + brightness_command != NO_BRIGHTNESS_COMMAND)) { common_hal_displayio_display_set_brightness(self, brightness); } else { self->current_brightness = -1.0; @@ -258,7 +259,7 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { common_hal_digitalio_digitalinout_set_value(&self->backlight_inout, brightness > 0.99); ok = true; - } else if (self->brightness_command < 0x100) { + } else if (self->brightness_command != NO_BRIGHTNESS_COMMAND) { ok = self->begin_transaction(self->bus); if (ok) { if (self->data_as_commands) { @@ -315,17 +316,16 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, displ data_length = 0; } if (self->single_byte_bounds) { - data[data_length] = x1 + self->colstart; - data[data_length + 1] = x2 - 1 + self->colstart; + data[data_length++] = x1 + self->colstart; + data[data_length++] = x2 - 1 + self->colstart; data_length += 2; } else { x1 += self->colstart; x2 += self->colstart - 1; - data[data_length] = x1 >> 8; - data[data_length + 1] = x1 & 0xff; - data[data_length + 2] = x2 >> 8; - data[data_length + 3] = x2 & 0xff; - data_length += 4; + data[data_length++] = x1 >> 8; + data[data_length++] = x1 & 0xff; + data[data_length++] = x2 >> 8; + data[data_length++] = x2 & 0xff; } self->send(self->bus, self->data_as_commands, data, data_length); @@ -337,17 +337,15 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, displ data_length = 0; } if (self->single_byte_bounds) { - data[data_length] = y1 + self->rowstart; - data[data_length + 1] = y2 - 1 + self->rowstart; - data_length += 2; + data[data_length++] = y1 + self->rowstart; + data[data_length++] = y2 - 1 + self->rowstart; } else { y1 += self->rowstart; y2 += self->rowstart - 1; - data[data_length] = y1 >> 8; - data[data_length + 1] = y1 & 0xff; - data[data_length + 2] = y2 >> 8; - data[data_length + 3] = y2 & 0xff; - data_length += 4; + data[data_length++] = y1 >> 8; + data[data_length++] = y1 & 0xff; + data[data_length++] = y2 >> 8; + data[data_length++] = y2 & 0xff; } self->send(self->bus, self->data_as_commands, data, data_length); } diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h index 6f5e2774c..19c05baf5 100644 --- a/shared-module/displayio/Palette.h +++ b/shared-module/displayio/Palette.h @@ -53,6 +53,8 @@ typedef struct { bool needs_refresh; } displayio_palette_t; +// Returns false if color fetch did not succeed (out of range or transparent). +// Returns true if color is opaque, and sets color. bool displayio_palette_get_color(displayio_palette_t *palette, const _displayio_colorspace_t* colorspace, uint32_t palette_index, uint32_t* color); bool displayio_palette_needs_refresh(displayio_palette_t *self); void displayio_palette_finish_refresh(displayio_palette_t *self); diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 77e6daf6f..88873d3a9 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -379,7 +379,7 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c // Compute the destination pixel in the buffer and mask based on the transformations. int16_t offset = row_start + (x - start_x + x_shift) * x_stride; // in pixels - // This is super useful for debugging out range accesses. Uncomment to use. + // This is super useful for debugging out of range accesses. Uncomment to use. // if (offset < 0 || offset >= (int32_t) displayio_area_size(area)) { // asm("bkpt"); // } -- cgit v1.2.3 From 7b67ef15c4e8b142bf226df0c1eed91e3f934f39 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 23 Jul 2019 17:11:39 -0500 Subject: remove local copy of 'support_matrix.json' --- shared-bindings/support_matrix.json | 441 ------------------------------------ 1 file changed, 441 deletions(-) delete mode 100644 shared-bindings/support_matrix.json (limited to 'shared-bindings') diff --git a/shared-bindings/support_matrix.json b/shared-bindings/support_matrix.json deleted file mode 100644 index 2d2a7d1ed..000000000 --- a/shared-bindings/support_matrix.json +++ /dev/null @@ -1,441 +0,0 @@ -{ - "pew": { - "name": "_pew", - "full_build": "0", - "default_value": "0", - "excluded": [] - }, - "pixelbuf": { - "name": "_pixelbuf", - "full_build": "1", - "default_value": "None", - "excluded": [ - "circuitplayground_express_crickit", - "feather_m0_rfm69", - "arduino_mkr1300", - "bast_pro_mini_m0", - "feather_m0_adalogger", - "ugame10", - "pewpew10", - "trinket_m0", - "catwan_usbstick", - "pirkey_m0", - "feather_m0_rfm9x", - "sparkfun_samd21_mini", - "feather_m0_basic", - "gemma_m0", - "arduino_mkrzero", - "meowmeow", - "escornabot_makech", - "sparkfun_samd21_dev", - "arduino_zero", - "uchip" - ] - }, - "stage": { - "name": "_stage", - "full_build": "0", - "default_value": "0", - "excluded": [] - }, - "analogio": { - "name": "analogio", - "full_build": "0", - "default_value": "1", - "excluded": [ - "pirkey_m0" - ] - }, - "audiobusio": { - "name": "audiobusio", - "full_build": "1", - "default_value": "None", - "excluded": [ - "feather_m0_rfm69", - "arduino_mkr1300", - "kicksat-sprite", - "bast_pro_mini_m0", - "feather_m0_adalogger", - "ugame10", - "pewpew10", - "mini_sam_m4", - "trinket_m0", - "catwan_usbstick", - "pirkey_m0", - "sparkfun_lumidrive", - "feather_m0_rfm9x", - "sparkfun_samd21_mini", - "capablerobot_usbhub", - "feather_m0_basic", - "gemma_m0", - "hallowing_m0_express", - "arduino_mkrzero", - "trellis_m4_express", - "feather_radiofruit_zigbee", - "itsybitsy_m4_express", - "meowmeow", - "cp32-m4", - "escornabot_makech", - "sparkfun_samd21_dev", - "arduino_zero", - "uchip" - ] - }, - "audioio": { - "name": "audioio", - "full_build": "1", - "default_value": "None", - "excluded": [ - "feather_m0_rfm69", - "arduino_mkr1300", - "bast_pro_mini_m0", - "feather_m0_adalogger", - "pewpew10", - "trinket_m0", - "catwan_usbstick", - "pirkey_m0", - "sparkfun_lumidrive", - "feather_m0_rfm9x", - "sparkfun_samd21_mini", - "feather_m0_basic", - "gemma_m0", - "arduino_mkrzero", - "feather_radiofruit_zigbee", - "meowmeow", - "escornabot_makech", - "sparkfun_samd21_dev", - "arduino_zero", - "uchip" - ] - }, - "bitbangio": { - "name": "bitbangio", - "full_build": "1", - "default_value": "None", - "excluded": [ - "feather_m0_rfm69", - "arduino_mkr1300", - "bast_pro_mini_m0", - "feather_m0_adalogger", - "pewpew10", - "feather_m0_express_crickit", - "trinket_m0", - "catwan_usbstick", - "pirkey_m0", - "feather_m0_rfm9x", - "sparkfun_samd21_mini", - "feather_m0_basic", - "gemma_m0", - "arduino_mkrzero", - "meowmeow", - "escornabot_makech", - "sparkfun_samd21_dev", - "arduino_zero", - "uchip" - ] - }, - "bleio": { - "name": "bleio", - "full_build": "0", - "default_value": "0", - "excluded": [] - }, - "board": { - "name": "board", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "busio": { - "name": "busio", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "digitalio": { - "name": "digitalio", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "displayio": { - "name": "displayio", - "full_build": "1", - "default_value": "None", - "excluded": [ - "circuitplayground_express_crickit", - "feather_m0_rfm69", - "arduino_mkr1300", - "kicksat-sprite", - "bast_pro_mini_m0", - "feather_m0_adalogger", - "circuitplayground_express", - "pewpew10", - "feather_m0_express_crickit", - "trinket_m0", - "catwan_usbstick", - "pirkey_m0", - "feather_m0_rfm9x", - "sparkfun_samd21_mini", - "robohatmm1", - "feather_m0_basic", - "gemma_m0", - "arduino_mkrzero", - "meowmeow", - "escornabot_makech", - "sparkfun_samd21_dev", - "arduino_zero", - "uchip" - ] - }, - "frequencyio": { - "name": "frequencyio", - "full_build": "1", - "default_value": "None", - "excluded": [ - "circuitplayground_express_crickit", - "feather_m0_rfm69", - "arduino_mkr1300", - "bast_pro_mini_m0", - "feather_m0_adalogger", - "ugame10", - "circuitplayground_express", - "pewpew10", - "feather_m0_express_crickit", - "trinket_m0", - "catwan_usbstick", - "pirkey_m0", - "feather_m0_rfm9x", - "sparkfun_samd21_mini", - "robohatmm1", - "feather_m0_basic", - "gemma_m0", - "hallowing_m0_express", - "arduino_mkrzero", - "meowmeow", - "escornabot_makech", - "sparkfun_samd21_dev", - "arduino_zero", - "uchip" - ] - }, - "gamepad": { - "name": "gamepad", - "full_build": "1", - "default_value": "None", - "excluded": [ - "feather_m0_rfm69", - "arduino_mkr1300", - "bast_pro_mini_m0", - "feather_m0_adalogger", - "pewpew10", - "feather_m0_express_crickit", - "trinket_m0", - "catwan_usbstick", - "pirkey_m0", - "feather_m0_rfm9x", - "sparkfun_samd21_mini", - "feather_m0_basic", - "gemma_m0", - "arduino_mkrzero", - "meowmeow", - "escornabot_makech", - "sparkfun_samd21_dev", - "arduino_zero", - "uchip" - ] - }, - "gamepadshift": { - "name": "gamepadshift", - "full_build": "0", - "default_value": "0", - "excluded": [] - }, - "i2cslave": { - "name": "i2cslave", - "full_build": "1", - "default_value": "None", - "excluded": [ - "circuitplayground_express_crickit", - "feather_m0_rfm69", - "arduino_mkr1300", - "bast_pro_mini_m0", - "feather_m0_adalogger", - "ugame10", - "circuitplayground_express", - "pewpew10", - "feather_m0_express_crickit", - "trinket_m0", - "catwan_usbstick", - "pirkey_m0", - "feather_m0_rfm9x", - "sparkfun_samd21_mini", - "feather_m0_basic", - "gemma_m0", - "hallowing_m0_express", - "arduino_mkrzero", - "meowmeow", - "escornabot_makech", - "sparkfun_samd21_dev", - "arduino_zero", - "uchip" - ] - }, - "math": { - "name": "math", - "full_build": "0", - "default_value": "1", - "excluded": [ - "pirkey_m0" - ] - }, - "microcontroller": { - "name": "microcontroller", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "neopixel_write": { - "name": "neopixel_write", - "full_build": "0", - "default_value": "1", - "excluded": [ - "ugame10", - "pirkey_m0" - ] - }, - "network": { - "name": "network", - "full_build": "0", - "default_value": "0", - "excluded": [] - }, - "nvm": { - "name": "nvm", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "os": { - "name": "os", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "ps2io": { - "name": "ps2io", - "full_build": "0", - "default_value": "0", - "excluded": [] - }, - "pulseio": { - "name": "pulseio", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "random": { - "name": "random", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "rotaryio": { - "name": "rotaryio", - "full_build": "0", - "default_value": "1", - "excluded": [ - "pewpew10", - "pirkey_m0" - ] - }, - "rtc": { - "name": "rtc", - "full_build": "0", - "default_value": "1", - "excluded": [ - "ugame10", - "pewpew10", - "pirkey_m0" - ] - }, - "storage": { - "name": "storage", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "struct": { - "name": "struct", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "supervisor": { - "name": "supervisor", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "time": { - "name": "time", - "full_build": "0", - "default_value": "1", - "excluded": [] - }, - "touchio": { - "name": "touchio", - "full_build": "0", - "default_value": "1", - "excluded": [ - "kicksat-sprite", - "ugame10", - "datalore_ip_m4", - "pybadge", - "pyportal", - "sam32", - "mini_sam_m4", - "grandcentral_m4_express", - "feather_m4_express", - "pirkey_m0", - "pygamer", - "capablerobot_usbhub", - "metro_m4_airlift_lite", - "trellis_m4_express", - "itsybitsy_m4_express", - "pygamer_advance", - "metro_m4_express", - "cp32-m4", - "pybadge_airlift" - ] - }, - "uheap": { - "name": "uheap", - "full_build": "0", - "default_value": "0", - "excluded": [] - }, - "usb_hid": { - "name": "usb_hid", - "full_build": "0", - "default_value": "1", - "excluded": [ - "ugame10" - ] - }, - "usb_midi": { - "name": "usb_midi", - "full_build": "0", - "default_value": "1", - "excluded": [ - "ugame10", - "pewpew10" - ] - }, - "ustack": { - "name": "ustack", - "full_build": "0", - "default_value": "0", - "excluded": [] - } -} \ No newline at end of file -- cgit v1.2.3 From 6b44e40ee8dba415213468afe14f7202b42ec429 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 24 Jul 2019 20:57:32 -0500 Subject: audiocore: Factor from audioio When nrf pwm audio is introduced, it will be called `audiopwmio`. To enable code sharing with the existing (dac-based) `audioio`, factor the sample and mixer types to `audiocore`. INCOMPATIBLE CHANGE: Now, `Mixer`, `RawSample` and `WaveFile` must be imported from `audiocore`, not `audioio`. --- ports/atmel-samd/audio_dma.c | 4 +- ports/atmel-samd/audio_dma.h | 4 +- ports/atmel-samd/common-hal/audiobusio/I2SOut.c | 2 +- py/circuitpy_defns.mk | 10 +- py/circuitpy_mpconfig.h | 8 + py/circuitpy_mpconfig.mk | 5 + shared-bindings/audiocore/Mixer.c | 252 +++++++++++++++++ shared-bindings/audiocore/Mixer.h | 52 ++++ shared-bindings/audiocore/RawSample.c | 187 +++++++++++++ shared-bindings/audiocore/RawSample.h | 44 +++ shared-bindings/audiocore/WaveFile.c | 202 ++++++++++++++ shared-bindings/audiocore/WaveFile.h | 47 ++++ shared-bindings/audiocore/__init__.c | 69 +++++ shared-bindings/audiocore/__init__.h | 34 +++ shared-bindings/audioio/AudioOut.c | 2 +- shared-bindings/audioio/AudioOut.h | 2 +- shared-bindings/audioio/Mixer.c | 252 ----------------- shared-bindings/audioio/Mixer.h | 52 ---- shared-bindings/audioio/RawSample.c | 187 ------------- shared-bindings/audioio/RawSample.h | 45 ---- shared-bindings/audioio/WaveFile.c | 202 -------------- shared-bindings/audioio/WaveFile.h | 46 ---- shared-bindings/audioio/__init__.c | 17 +- shared-bindings/index.rst | 1 + shared-module/audiocore/Mixer.c | 341 ++++++++++++++++++++++++ shared-module/audiocore/Mixer.h | 75 ++++++ shared-module/audiocore/RawSample.c | 94 +++++++ shared-module/audiocore/RawSample.h | 59 ++++ shared-module/audiocore/WaveFile.c | 268 +++++++++++++++++++ shared-module/audiocore/WaveFile.h | 70 +++++ shared-module/audiocore/__init__.c | 125 +++++++++ shared-module/audiocore/__init__.h | 53 ++++ shared-module/audioio/Mixer.c | 341 ------------------------ shared-module/audioio/Mixer.h | 75 ------ shared-module/audioio/RawSample.c | 94 ------- shared-module/audioio/RawSample.h | 59 ---- shared-module/audioio/WaveFile.c | 268 ------------------- shared-module/audioio/WaveFile.h | 70 ----- shared-module/audioio/__init__.c | 125 --------- shared-module/audioio/__init__.h | 23 +- 40 files changed, 2009 insertions(+), 1857 deletions(-) create mode 100644 shared-bindings/audiocore/Mixer.c create mode 100644 shared-bindings/audiocore/Mixer.h create mode 100644 shared-bindings/audiocore/RawSample.c create mode 100644 shared-bindings/audiocore/RawSample.h create mode 100644 shared-bindings/audiocore/WaveFile.c create mode 100644 shared-bindings/audiocore/WaveFile.h create mode 100644 shared-bindings/audiocore/__init__.c create mode 100644 shared-bindings/audiocore/__init__.h delete mode 100644 shared-bindings/audioio/Mixer.c delete mode 100644 shared-bindings/audioio/Mixer.h delete mode 100644 shared-bindings/audioio/RawSample.c delete mode 100644 shared-bindings/audioio/RawSample.h delete mode 100644 shared-bindings/audioio/WaveFile.c delete mode 100644 shared-bindings/audioio/WaveFile.h create mode 100644 shared-module/audiocore/Mixer.c create mode 100644 shared-module/audiocore/Mixer.h create mode 100644 shared-module/audiocore/RawSample.c create mode 100644 shared-module/audiocore/RawSample.h create mode 100644 shared-module/audiocore/WaveFile.c create mode 100644 shared-module/audiocore/WaveFile.h create mode 100644 shared-module/audiocore/__init__.c create mode 100644 shared-module/audiocore/__init__.h delete mode 100644 shared-module/audioio/Mixer.c delete mode 100644 shared-module/audioio/Mixer.h delete mode 100644 shared-module/audioio/RawSample.c delete mode 100644 shared-module/audioio/RawSample.h delete mode 100644 shared-module/audioio/WaveFile.c delete mode 100644 shared-module/audioio/WaveFile.h (limited to 'shared-bindings') diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c index 68d6f182d..6b5eeddcc 100644 --- a/ports/atmel-samd/audio_dma.c +++ b/ports/atmel-samd/audio_dma.c @@ -29,8 +29,8 @@ #include "samd/events.h" #include "samd/dma.h" -#include "shared-bindings/audioio/RawSample.h" -#include "shared-bindings/audioio/WaveFile.h" +#include "shared-bindings/audiocore/RawSample.h" +#include "shared-bindings/audiocore/WaveFile.h" #include "py/mpstate.h" #include "py/runtime.h" diff --git a/ports/atmel-samd/audio_dma.h b/ports/atmel-samd/audio_dma.h index 041d675a2..53173c277 100644 --- a/ports/atmel-samd/audio_dma.h +++ b/ports/atmel-samd/audio_dma.h @@ -29,8 +29,8 @@ #include "extmod/vfs_fat.h" #include "py/obj.h" -#include "shared-module/audioio/RawSample.h" -#include "shared-module/audioio/WaveFile.h" +#include "shared-module/audiocore/RawSample.h" +#include "shared-module/audiocore/WaveFile.h" typedef struct { mp_obj_t sample; diff --git a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c index 20934bed4..05a6aaf7b 100644 --- a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c +++ b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c @@ -33,7 +33,7 @@ #include "py/runtime.h" #include "common-hal/audiobusio/I2SOut.h" #include "shared-bindings/audiobusio/I2SOut.h" -#include "shared-bindings/audioio/RawSample.h" +#include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/microcontroller/Pin.h" #include "supervisor/shared/translate.h" diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 93ca4deb9..bdefc18cc 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -108,6 +108,9 @@ endif ifeq ($(CIRCUITPY_AUDIOIO),1) SRC_PATTERNS += audioio/% endif +ifeq ($(CIRCUITPY_AUDIOCORE),1) +SRC_PATTERNS += audiocore/% +endif ifeq ($(CIRCUITPY_BITBANGIO),1) SRC_PATTERNS += bitbangio/% endif @@ -301,9 +304,10 @@ $(filter $(SRC_PATTERNS), \ _stage/Text.c \ _stage/__init__.c \ audioio/__init__.c \ - audioio/Mixer.c \ - audioio/RawSample.c \ - audioio/WaveFile.c \ + audiocore/__init__.c \ + audiocore/Mixer.c \ + audiocore/RawSample.c \ + audiocore/WaveFile.c \ bitbangio/I2C.c \ bitbangio/OneWire.c \ bitbangio/SPI.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 2026185ef..3440eb052 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -230,6 +230,13 @@ extern const struct _mp_obj_module_t audiobusio_module; #define AUDIOBUSIO_MODULE #endif +#if CIRCUITPY_AUDIOCORE +#define AUDIOCORE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_audiocore), (mp_obj_t)&audiocore_module }, +extern const struct _mp_obj_module_t audiocore_module; +#else +#define AUDIOCORE_MODULE +#endif + #if CIRCUITPY_AUDIOIO #define AUDIOIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_audioio), (mp_obj_t)&audioio_module }, extern const struct _mp_obj_module_t audioio_module; @@ -564,6 +571,7 @@ extern const struct _mp_obj_module_t ustack_module; #define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \ ANALOGIO_MODULE \ AUDIOBUSIO_MODULE \ + AUDIOCORE_MODULE \ AUDIOIO_MODULE \ BITBANGIO_MODULE \ BLEIO_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 47303a73a..1c1a4c8ea 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -61,6 +61,11 @@ CIRCUITPY_AUDIOIO = $(CIRCUITPY_FULL_BUILD) endif CFLAGS += -DCIRCUITPY_AUDIOIO=$(CIRCUITPY_AUDIOIO) +ifndef CIRCUITPY_AUDIOCORE +CIRCUITPY_AUDIOCORE = $(CIRCUITPY_AUDIOIO) +endif +CFLAGS += -DCIRCUITPY_AUDIOCORE=$(CIRCUITPY_AUDIOCORE) + ifndef CIRCUITPY_BITBANGIO CIRCUITPY_BITBANGIO = $(CIRCUITPY_FULL_BUILD) endif diff --git a/shared-bindings/audiocore/Mixer.c b/shared-bindings/audiocore/Mixer.c new file mode 100644 index 000000000..b2f0a3fda --- /dev/null +++ b/shared-bindings/audiocore/Mixer.c @@ -0,0 +1,252 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "shared-bindings/audiocore/Mixer.h" + +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/binary.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/audiocore/RawSample.h" +#include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: audioio +//| +//| :class:`Mixer` -- Mixes one or more audio samples together +//| =========================================================== +//| +//| Mixer mixes multiple samples into one sample. +//| +//| .. class:: Mixer(channel_count=2, buffer_size=1024) +//| +//| Create a Mixer object that can mix multiple channels with the same sample rate. +//| +//| :param int channel_count: The maximum number of samples to mix at once +//| :param int buffer_size: The total size in bytes of the buffers to mix into +//| +//| Playing a wave file from flash:: +//| +//| import board +//| import audioio +//| import digitalio +//| +//| # Required for CircuitPlayground Express +//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) +//| speaker_enable.switch_to_output(value=True) +//| +//| music = audioio.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb")) +//| drum = audioio.WaveFile(open("drum.wav", "rb")) +//| mixer = audioio.Mixer(voice_count=2, sample_rate=16000, channel_count=1, bits_per_sample=16, samples_signed=True) +//| a = audioio.AudioOut(board.A0) +//| +//| print("playing") +//| a.play(mixer) +//| mixer.play(music, voice=0) +//| while mixer.playing: +//| mixer.play(drum, voice=1) +//| time.sleep(1) +//| print("stopped") +//| +STATIC mp_obj_t audioio_mixer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_voice_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 2} }, + { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1024} }, + { MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 2} }, + { MP_QSTR_bits_per_sample, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, + { MP_QSTR_samples_signed, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, + { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_int_t voice_count = args[ARG_voice_count].u_int; + if (voice_count < 1 || voice_count > 255) { + mp_raise_ValueError(translate("Invalid voice count")); + } + + mp_int_t channel_count = args[ARG_channel_count].u_int; + if (channel_count < 1 || channel_count > 2) { + mp_raise_ValueError(translate("Invalid channel count")); + } + mp_int_t sample_rate = args[ARG_sample_rate].u_int; + if (sample_rate < 1) { + mp_raise_ValueError(translate("Sample rate must be positive")); + } + mp_int_t bits_per_sample = args[ARG_bits_per_sample].u_int; + if (bits_per_sample != 8 && bits_per_sample != 16) { + mp_raise_ValueError(translate("bits_per_sample must be 8 or 16")); + } + audioio_mixer_obj_t *self = m_new_obj_var(audioio_mixer_obj_t, audioio_mixer_voice_t, voice_count); + self->base.type = &audioio_mixer_type; + common_hal_audioio_mixer_construct(self, voice_count, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + + return MP_OBJ_FROM_PTR(self); +} + +//| .. method:: deinit() +//| +//| Deinitialises the Mixer and releases any hardware resources for reuse. +//| +STATIC mp_obj_t audioio_mixer_deinit(mp_obj_t self_in) { + audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_audioio_mixer_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_deinit_obj, audioio_mixer_deinit); + +STATIC void check_for_deinit(audioio_mixer_obj_t *self) { + if (common_hal_audioio_mixer_deinited(self)) { + raise_deinited_error(); + } +} + +//| .. method:: __enter__() +//| +//| No-op used by Context Managers. +//| +// Provided by context manager helper. + +//| .. method:: __exit__() +//| +//| Automatically deinitializes the hardware when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| +STATIC mp_obj_t audioio_mixer_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_audioio_mixer_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_mixer___exit___obj, 4, 4, audioio_mixer_obj___exit__); + + +//| .. method:: play(sample, *, voice=0, loop=False) +//| +//| Plays the sample once when loop=False and continuously when loop=True. +//| Does not block. Use `playing` to block. +//| +//| Sample must be an `audioio.WaveFile`, `audioio.Mixer` or `audioio.RawSample`. +//| +//| The sample must match the Mixer's encoding settings given in the constructor. +//| +STATIC mp_obj_t audioio_mixer_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_sample, ARG_voice, ARG_loop }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_sample, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_voice, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, + { MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + }; + audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_obj_t sample = args[ARG_sample].u_obj; + common_hal_audioio_mixer_play(self, sample, args[ARG_voice].u_int, args[ARG_loop].u_bool); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audioio_mixer_play_obj, 1, audioio_mixer_obj_play); + +//| .. method:: stop_voice(voice=0) +//| +//| Stops playback of the sample on the given voice. +//| +STATIC mp_obj_t audioio_mixer_obj_stop_voice(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_voice }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_voice, MP_ARG_INT, {.u_int = 0} }, + }; + audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + common_hal_audioio_mixer_stop_voice(self, args[ARG_voice].u_int); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audioio_mixer_stop_voice_obj, 1, audioio_mixer_obj_stop_voice); + +//| .. attribute:: playing +//| +//| True when any voice is being output. (read-only) +//| +STATIC mp_obj_t audioio_mixer_obj_get_playing(mp_obj_t self_in) { + audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_audioio_mixer_get_playing(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_playing_obj, audioio_mixer_obj_get_playing); + +const mp_obj_property_t audioio_mixer_playing_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&audioio_mixer_get_playing_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| .. attribute:: sample_rate +//| +//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second). +//| +STATIC mp_obj_t audioio_mixer_obj_get_sample_rate(mp_obj_t self_in) { + audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_mixer_get_sample_rate(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_sample_rate_obj, audioio_mixer_obj_get_sample_rate); + + +const mp_obj_property_t audioio_mixer_sample_rate_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&audioio_mixer_get_sample_rate_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +STATIC const mp_rom_map_elem_t audioio_mixer_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioio_mixer_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audioio_mixer___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audioio_mixer_play_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop_voice), MP_ROM_PTR(&audioio_mixer_stop_voice_obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audioio_mixer_playing_obj) }, + { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audioio_mixer_sample_rate_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(audioio_mixer_locals_dict, audioio_mixer_locals_dict_table); + +const mp_obj_type_t audioio_mixer_type = { + { &mp_type_type }, + .name = MP_QSTR_Mixer, + .make_new = audioio_mixer_make_new, + .locals_dict = (mp_obj_dict_t*)&audioio_mixer_locals_dict, +}; diff --git a/shared-bindings/audiocore/Mixer.h b/shared-bindings/audiocore/Mixer.h new file mode 100644 index 000000000..ef12f9a70 --- /dev/null +++ b/shared-bindings/audiocore/Mixer.h @@ -0,0 +1,52 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MIXER_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MIXER_H + +#include "common-hal/microcontroller/Pin.h" +#include "shared-module/audiocore/Mixer.h" +#include "shared-bindings/audiocore/RawSample.h" + +extern const mp_obj_type_t audioio_mixer_type; + +void common_hal_audioio_mixer_construct(audioio_mixer_obj_t* self, + uint8_t voice_count, + uint32_t buffer_size, + uint8_t bits_per_sample, + bool samples_signed, + uint8_t channel_count, + uint32_t sample_rate); + +void common_hal_audioio_mixer_deinit(audioio_mixer_obj_t* self); +bool common_hal_audioio_mixer_deinited(audioio_mixer_obj_t* self); +void common_hal_audioio_mixer_play(audioio_mixer_obj_t* self, mp_obj_t sample, uint8_t voice, bool loop); +void common_hal_audioio_mixer_stop_voice(audioio_mixer_obj_t* self, uint8_t voice); + +bool common_hal_audioio_mixer_get_playing(audioio_mixer_obj_t* self); +uint32_t common_hal_audioio_mixer_get_sample_rate(audioio_mixer_obj_t* self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MIXER_H diff --git a/shared-bindings/audiocore/RawSample.c b/shared-bindings/audiocore/RawSample.c new file mode 100644 index 000000000..912b48bfb --- /dev/null +++ b/shared-bindings/audiocore/RawSample.c @@ -0,0 +1,187 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/binary.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/util.h" +#include "shared-bindings/audiocore/RawSample.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: audioio +//| +//| :class:`RawSample` -- A raw audio sample buffer +//| ======================================================== +//| +//| An in-memory sound sample +//| +//| .. class:: RawSample(buffer, *, channel_count=1, sample_rate=8000) +//| +//| Create a RawSample based on the given buffer of signed values. If channel_count is more than +//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the +//| first sample will be for channel 1, the second sample will be for channel two, the third for +//| channel 1 and so on. +//| +//| :param array buffer: An `array.array` with samples +//| :param int channel_count: The number of channels in the buffer +//| :param int sample_rate: The desired playback sample rate +//| +//| Simple 8ksps 440 Hz sin wave:: +//| +//| import audioio +//| import board +//| import array +//| import time +//| import math +//| +//| # Generate one period of sine wav. +//| length = 8000 // 440 +//| sine_wave = array.array("h", [0] * length) +//| for i in range(length): +//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15)) +//| +//| dac = audioio.AudioOut(board.SPEAKER) +//| sine_wave = audioio.RawSample(sine_wave) +//| dac.play(sine_wave, loop=True) +//| time.sleep(1) +//| dac.stop() +//| +STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_buffer, ARG_channel_count, ARG_sample_rate }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1 } }, + { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + audioio_rawsample_obj_t *self = m_new_obj(audioio_rawsample_obj_t); + self->base.type = &audioio_rawsample_type; + mp_buffer_info_t bufinfo; + if (mp_get_buffer(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ)) { + uint8_t bytes_per_sample = 1; + bool signed_samples = bufinfo.typecode == 'b' || bufinfo.typecode == 'h'; + if (bufinfo.typecode == 'h' || bufinfo.typecode == 'H') { + bytes_per_sample = 2; + } else if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) { + mp_raise_ValueError(translate("sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or 'B'")); + } + common_hal_audioio_rawsample_construct(self, ((uint8_t*)bufinfo.buf), bufinfo.len, + bytes_per_sample, signed_samples, args[ARG_channel_count].u_int, + args[ARG_sample_rate].u_int); + } else { + mp_raise_TypeError(translate("buffer must be a bytes-like object")); + } + + return MP_OBJ_FROM_PTR(self); +} + +//| .. method:: deinit() +//| +//| Deinitialises the AudioOut and releases any hardware resources for reuse. +//| +STATIC mp_obj_t audioio_rawsample_deinit(mp_obj_t self_in) { + audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_audioio_rawsample_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_rawsample_deinit_obj, audioio_rawsample_deinit); + +STATIC void check_for_deinit(audioio_rawsample_obj_t *self) { + if (common_hal_audioio_rawsample_deinited(self)) { + raise_deinited_error(); + } +} + +//| .. method:: __enter__() +//| +//| No-op used by Context Managers. +//| +// Provided by context manager helper. + +//| .. method:: __exit__() +//| +//| Automatically deinitializes the hardware when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| +STATIC mp_obj_t audioio_rawsample_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_audioio_rawsample_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_rawsample___exit___obj, 4, 4, audioio_rawsample_obj___exit__); + +//| .. attribute:: sample_rate +//| +//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second). +//| When the sample is looped, this can change the pitch output without changing the underlying +//| sample. This will not change the sample rate of any active playback. Call ``play`` again to +//| change it. +//| +STATIC mp_obj_t audioio_rawsample_obj_get_sample_rate(mp_obj_t self_in) { + audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_rawsample_get_sample_rate(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audioio_rawsample_get_sample_rate_obj, audioio_rawsample_obj_get_sample_rate); + +STATIC mp_obj_t audioio_rawsample_obj_set_sample_rate(mp_obj_t self_in, mp_obj_t sample_rate) { + audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_audioio_rawsample_set_sample_rate(self, mp_obj_get_int(sample_rate)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(audioio_rawsample_set_sample_rate_obj, audioio_rawsample_obj_set_sample_rate); + +const mp_obj_property_t audioio_rawsample_sample_rate_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&audioio_rawsample_get_sample_rate_obj, + (mp_obj_t)&audioio_rawsample_set_sample_rate_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +STATIC const mp_rom_map_elem_t audioio_rawsample_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioio_rawsample_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audioio_rawsample___exit___obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audioio_rawsample_sample_rate_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(audioio_rawsample_locals_dict, audioio_rawsample_locals_dict_table); + +const mp_obj_type_t audioio_rawsample_type = { + { &mp_type_type }, + .name = MP_QSTR_RawSample, + .make_new = audioio_rawsample_make_new, + .locals_dict = (mp_obj_dict_t*)&audioio_rawsample_locals_dict, +}; diff --git a/shared-bindings/audiocore/RawSample.h b/shared-bindings/audiocore/RawSample.h new file mode 100644 index 000000000..b02778cad --- /dev/null +++ b/shared-bindings/audiocore/RawSample.h @@ -0,0 +1,44 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H + +#include "common-hal/microcontroller/Pin.h" +#include "shared-module/audiocore/RawSample.h" + +extern const mp_obj_type_t audioio_rawsample_type; + +void common_hal_audioio_rawsample_construct(audioio_rawsample_obj_t* self, + uint8_t* buffer, uint32_t len, uint8_t bytes_per_sample, bool samples_signed, + uint8_t channel_count, uint32_t sample_rate); + +void common_hal_audioio_rawsample_deinit(audioio_rawsample_obj_t* self); +bool common_hal_audioio_rawsample_deinited(audioio_rawsample_obj_t* self); +uint32_t common_hal_audioio_rawsample_get_sample_rate(audioio_rawsample_obj_t* self); +void common_hal_audioio_rawsample_set_sample_rate(audioio_rawsample_obj_t* self, uint32_t sample_rate); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H diff --git a/shared-bindings/audiocore/WaveFile.c b/shared-bindings/audiocore/WaveFile.c new file mode 100644 index 000000000..4c1993b7c --- /dev/null +++ b/shared-bindings/audiocore/WaveFile.c @@ -0,0 +1,202 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/audiocore/WaveFile.h" +#include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: audioio +//| +//| :class:`WaveFile` -- Load a wave file for audio playback +//| ======================================================== +//| +//| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must +//| be 8 bit unsigned or 16 bit signed. +//| +//| .. class:: WaveFile(file) +//| +//| Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`. +//| +//| :param typing.BinaryIO file: Already opened wave file +//| +//| Playing a wave file from flash:: +//| +//| import board +//| import audioio +//| import digitalio +//| +//| # Required for CircuitPlayground Express +//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) +//| speaker_enable.switch_to_output(value=True) +//| +//| data = open("cplay-5.1-16bit-16khz.wav", "rb") +//| wav = audioio.WaveFile(data) +//| a = audioio.AudioOut(board.A0) +//| +//| print("playing") +//| a.play(wav) +//| while a.playing: +//| pass +//| print("stopped") +//| +STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 1, 1, false); + + audioio_wavefile_obj_t *self = m_new_obj(audioio_wavefile_obj_t); + self->base.type = &audioio_wavefile_type; + if (MP_OBJ_IS_TYPE(args[0], &mp_type_fileio)) { + common_hal_audioio_wavefile_construct(self, MP_OBJ_TO_PTR(args[0])); + } else { + mp_raise_TypeError(translate("file must be a file opened in byte mode")); + } + + return MP_OBJ_FROM_PTR(self); +} + +//| .. method:: deinit() +//| +//| Deinitialises the WaveFile and releases all memory resources for reuse. +//| +STATIC mp_obj_t audioio_wavefile_deinit(mp_obj_t self_in) { + audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_audioio_wavefile_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_deinit_obj, audioio_wavefile_deinit); + +STATIC void check_for_deinit(audioio_wavefile_obj_t *self) { + if (common_hal_audioio_wavefile_deinited(self)) { + raise_deinited_error(); + } +} + +//| .. method:: __enter__() +//| +//| No-op used by Context Managers. +//| +// Provided by context manager helper. + +//| .. method:: __exit__() +//| +//| Automatically deinitializes the hardware when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| +STATIC mp_obj_t audioio_wavefile_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_audioio_wavefile_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_wavefile___exit___obj, 4, 4, audioio_wavefile_obj___exit__); + +//| .. attribute:: sample_rate +//| +//| 32 bit value that dictates how quickly samples are loaded into the DAC +//| in Hertz (cycles per second). When the sample is looped, this can change +//| the pitch output without changing the underlying sample. +//| +STATIC mp_obj_t audioio_wavefile_obj_get_sample_rate(mp_obj_t self_in) { + audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_sample_rate(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_sample_rate_obj, audioio_wavefile_obj_get_sample_rate); + +STATIC mp_obj_t audioio_wavefile_obj_set_sample_rate(mp_obj_t self_in, mp_obj_t sample_rate) { + audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_audioio_wavefile_set_sample_rate(self, mp_obj_get_int(sample_rate)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(audioio_wavefile_set_sample_rate_obj, audioio_wavefile_obj_set_sample_rate); + +const mp_obj_property_t audioio_wavefile_sample_rate_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&audioio_wavefile_get_sample_rate_obj, + (mp_obj_t)&audioio_wavefile_set_sample_rate_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| .. attribute:: bits_per_sample +//| +//| Bits per sample. (read only) +//| +STATIC mp_obj_t audioio_wavefile_obj_get_bits_per_sample(mp_obj_t self_in) { + audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_bits_per_sample(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_bits_per_sample_obj, audioio_wavefile_obj_get_bits_per_sample); + +const mp_obj_property_t audioio_wavefile_bits_per_sample_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&audioio_wavefile_get_bits_per_sample_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| .. attribute:: channel_count +//| +//| Number of audio channels. (read only) +//| +STATIC mp_obj_t audioio_wavefile_obj_get_channel_count(mp_obj_t self_in) { + audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_channel_count(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_channel_count_obj, audioio_wavefile_obj_get_channel_count); + +const mp_obj_property_t audioio_wavefile_channel_count_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&audioio_wavefile_get_channel_count_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + + +STATIC const mp_rom_map_elem_t audioio_wavefile_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioio_wavefile_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audioio_wavefile___exit___obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audioio_wavefile_sample_rate_obj) }, + { MP_ROM_QSTR(MP_QSTR_bits_per_sample), MP_ROM_PTR(&audioio_wavefile_bits_per_sample_obj) }, + { MP_ROM_QSTR(MP_QSTR_channel_count), MP_ROM_PTR(&audioio_wavefile_channel_count_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(audioio_wavefile_locals_dict, audioio_wavefile_locals_dict_table); + +const mp_obj_type_t audioio_wavefile_type = { + { &mp_type_type }, + .name = MP_QSTR_WaveFile, + .make_new = audioio_wavefile_make_new, + .locals_dict = (mp_obj_dict_t*)&audioio_wavefile_locals_dict, +}; diff --git a/shared-bindings/audiocore/WaveFile.h b/shared-bindings/audiocore/WaveFile.h new file mode 100644 index 000000000..d2572318b --- /dev/null +++ b/shared-bindings/audiocore/WaveFile.h @@ -0,0 +1,47 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_WAVEFILE_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_WAVEFILE_H + +#include "py/obj.h" +#include "extmod/vfs_fat.h" + +#include "shared-module/audiocore/WaveFile.h" + +extern const mp_obj_type_t audioio_wavefile_type; + +void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t* self, + pyb_file_obj_t* file); + +void common_hal_audioio_wavefile_deinit(audioio_wavefile_obj_t* self); +bool common_hal_audioio_wavefile_deinited(audioio_wavefile_obj_t* self); +uint32_t common_hal_audioio_wavefile_get_sample_rate(audioio_wavefile_obj_t* self); +void common_hal_audioio_wavefile_set_sample_rate(audioio_wavefile_obj_t* self, uint32_t sample_rate); +uint8_t common_hal_audioio_wavefile_get_bits_per_sample(audioio_wavefile_obj_t* self); +uint8_t common_hal_audioio_wavefile_get_channel_count(audioio_wavefile_obj_t* self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_WAVEFILE_H diff --git a/shared-bindings/audiocore/__init__.c b/shared-bindings/audiocore/__init__.c new file mode 100644 index 000000000..c64759d4f --- /dev/null +++ b/shared-bindings/audiocore/__init__.c @@ -0,0 +1,69 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/audiocore/__init__.h" +#include "shared-bindings/audiocore/Mixer.h" +#include "shared-bindings/audiocore/RawSample.h" +#include "shared-bindings/audiocore/WaveFile.h" + +//| :mod:`audiocore` --- Support for audio samples and mixer +//| ======================================================== +//| +//| .. module:: audiocore +//| :synopsis: Support for audio samples and mixer +//| :platform: SAMD21 +//| +//| The `audiocore` module contains core classes for audio IO +//| +//| Libraries +//| +//| .. toctree:: +//| :maxdepth: 3 +//| +//| Mixer +//| RawSample +//| WaveFile +//| + +STATIC const mp_rom_map_elem_t audiocore_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audiocore) }, + { MP_ROM_QSTR(MP_QSTR_Mixer), MP_ROM_PTR(&audioio_mixer_type) }, + { MP_ROM_QSTR(MP_QSTR_RawSample), MP_ROM_PTR(&audioio_rawsample_type) }, + { MP_ROM_QSTR(MP_QSTR_WaveFile), MP_ROM_PTR(&audioio_wavefile_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(audiocore_module_globals, audiocore_module_globals_table); + +const mp_obj_module_t audiocore_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&audiocore_module_globals, +}; diff --git a/shared-bindings/audiocore/__init__.h b/shared-bindings/audiocore/__init__.h new file mode 100644 index 000000000..02437cd13 --- /dev/null +++ b/shared-bindings/audiocore/__init__.h @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOCORE___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOCORE___INIT___H + +#include "py/obj.h" + +// Nothing now. + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOCORE___INIT___H diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 571dcdaca..79df66f7d 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audioio/AudioOut.h" -#include "shared-bindings/audioio/RawSample.h" +#include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/util.h" #include "supervisor/shared/translate.h" diff --git a/shared-bindings/audioio/AudioOut.h b/shared-bindings/audioio/AudioOut.h index d09a5c9ca..1076ac5cc 100644 --- a/shared-bindings/audioio/AudioOut.h +++ b/shared-bindings/audioio/AudioOut.h @@ -29,7 +29,7 @@ #include "common-hal/audioio/AudioOut.h" #include "common-hal/microcontroller/Pin.h" -#include "shared-bindings/audioio/RawSample.h" +#include "shared-bindings/audiocore/RawSample.h" extern const mp_obj_type_t audioio_audioout_type; diff --git a/shared-bindings/audioio/Mixer.c b/shared-bindings/audioio/Mixer.c deleted file mode 100644 index dce4b3955..000000000 --- a/shared-bindings/audioio/Mixer.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "shared-bindings/audioio/Mixer.h" - -#include - -#include "lib/utils/context_manager_helpers.h" -#include "py/binary.h" -#include "py/objproperty.h" -#include "py/runtime.h" -#include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/audioio/RawSample.h" -#include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" - -//| .. currentmodule:: audioio -//| -//| :class:`Mixer` -- Mixes one or more audio samples together -//| =========================================================== -//| -//| Mixer mixes multiple samples into one sample. -//| -//| .. class:: Mixer(channel_count=2, buffer_size=1024) -//| -//| Create a Mixer object that can mix multiple channels with the same sample rate. -//| -//| :param int channel_count: The maximum number of samples to mix at once -//| :param int buffer_size: The total size in bytes of the buffers to mix into -//| -//| Playing a wave file from flash:: -//| -//| import board -//| import audioio -//| import digitalio -//| -//| # Required for CircuitPlayground Express -//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) -//| speaker_enable.switch_to_output(value=True) -//| -//| music = audioio.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb")) -//| drum = audioio.WaveFile(open("drum.wav", "rb")) -//| mixer = audioio.Mixer(voice_count=2, sample_rate=16000, channel_count=1, bits_per_sample=16, samples_signed=True) -//| a = audioio.AudioOut(board.A0) -//| -//| print("playing") -//| a.play(mixer) -//| mixer.play(music, voice=0) -//| while mixer.playing: -//| mixer.play(drum, voice=1) -//| time.sleep(1) -//| print("stopped") -//| -STATIC mp_obj_t audioio_mixer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_voice_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 2} }, - { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1024} }, - { MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 2} }, - { MP_QSTR_bits_per_sample, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, - { MP_QSTR_samples_signed, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, - { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_int_t voice_count = args[ARG_voice_count].u_int; - if (voice_count < 1 || voice_count > 255) { - mp_raise_ValueError(translate("Invalid voice count")); - } - - mp_int_t channel_count = args[ARG_channel_count].u_int; - if (channel_count < 1 || channel_count > 2) { - mp_raise_ValueError(translate("Invalid channel count")); - } - mp_int_t sample_rate = args[ARG_sample_rate].u_int; - if (sample_rate < 1) { - mp_raise_ValueError(translate("Sample rate must be positive")); - } - mp_int_t bits_per_sample = args[ARG_bits_per_sample].u_int; - if (bits_per_sample != 8 && bits_per_sample != 16) { - mp_raise_ValueError(translate("bits_per_sample must be 8 or 16")); - } - audioio_mixer_obj_t *self = m_new_obj_var(audioio_mixer_obj_t, audioio_mixer_voice_t, voice_count); - self->base.type = &audioio_mixer_type; - common_hal_audioio_mixer_construct(self, voice_count, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); - - return MP_OBJ_FROM_PTR(self); -} - -//| .. method:: deinit() -//| -//| Deinitialises the Mixer and releases any hardware resources for reuse. -//| -STATIC mp_obj_t audioio_mixer_deinit(mp_obj_t self_in) { - audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_audioio_mixer_deinit(self); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_deinit_obj, audioio_mixer_deinit); - -STATIC void check_for_deinit(audioio_mixer_obj_t *self) { - if (common_hal_audioio_mixer_deinited(self)) { - raise_deinited_error(); - } -} - -//| .. method:: __enter__() -//| -//| No-op used by Context Managers. -//| -// Provided by context manager helper. - -//| .. method:: __exit__() -//| -//| Automatically deinitializes the hardware when exiting a context. See -//| :ref:`lifetime-and-contextmanagers` for more info. -//| -STATIC mp_obj_t audioio_mixer_obj___exit__(size_t n_args, const mp_obj_t *args) { - (void)n_args; - common_hal_audioio_mixer_deinit(args[0]); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_mixer___exit___obj, 4, 4, audioio_mixer_obj___exit__); - - -//| .. method:: play(sample, *, voice=0, loop=False) -//| -//| Plays the sample once when loop=False and continuously when loop=True. -//| Does not block. Use `playing` to block. -//| -//| Sample must be an `audioio.WaveFile`, `audioio.Mixer` or `audioio.RawSample`. -//| -//| The sample must match the Mixer's encoding settings given in the constructor. -//| -STATIC mp_obj_t audioio_mixer_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_sample, ARG_voice, ARG_loop }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_sample, MP_ARG_OBJ | MP_ARG_REQUIRED }, - { MP_QSTR_voice, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, - { MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, - }; - audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - check_for_deinit(self); - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_obj_t sample = args[ARG_sample].u_obj; - common_hal_audioio_mixer_play(self, sample, args[ARG_voice].u_int, args[ARG_loop].u_bool); - - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(audioio_mixer_play_obj, 1, audioio_mixer_obj_play); - -//| .. method:: stop_voice(voice=0) -//| -//| Stops playback of the sample on the given voice. -//| -STATIC mp_obj_t audioio_mixer_obj_stop_voice(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_voice }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_voice, MP_ARG_INT, {.u_int = 0} }, - }; - audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - check_for_deinit(self); - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - common_hal_audioio_mixer_stop_voice(self, args[ARG_voice].u_int); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(audioio_mixer_stop_voice_obj, 1, audioio_mixer_obj_stop_voice); - -//| .. attribute:: playing -//| -//| True when any voice is being output. (read-only) -//| -STATIC mp_obj_t audioio_mixer_obj_get_playing(mp_obj_t self_in) { - audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return mp_obj_new_bool(common_hal_audioio_mixer_get_playing(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_playing_obj, audioio_mixer_obj_get_playing); - -const mp_obj_property_t audioio_mixer_playing_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&audioio_mixer_get_playing_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| .. attribute:: sample_rate -//| -//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second). -//| -STATIC mp_obj_t audioio_mixer_obj_get_sample_rate(mp_obj_t self_in) { - audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_mixer_get_sample_rate(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_sample_rate_obj, audioio_mixer_obj_get_sample_rate); - - -const mp_obj_property_t audioio_mixer_sample_rate_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&audioio_mixer_get_sample_rate_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -STATIC const mp_rom_map_elem_t audioio_mixer_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioio_mixer_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audioio_mixer___exit___obj) }, - { MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audioio_mixer_play_obj) }, - { MP_ROM_QSTR(MP_QSTR_stop_voice), MP_ROM_PTR(&audioio_mixer_stop_voice_obj) }, - - // Properties - { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audioio_mixer_playing_obj) }, - { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audioio_mixer_sample_rate_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(audioio_mixer_locals_dict, audioio_mixer_locals_dict_table); - -const mp_obj_type_t audioio_mixer_type = { - { &mp_type_type }, - .name = MP_QSTR_Mixer, - .make_new = audioio_mixer_make_new, - .locals_dict = (mp_obj_dict_t*)&audioio_mixer_locals_dict, -}; diff --git a/shared-bindings/audioio/Mixer.h b/shared-bindings/audioio/Mixer.h deleted file mode 100644 index 832072b8f..000000000 --- a/shared-bindings/audioio/Mixer.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MIXER_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MIXER_H - -#include "common-hal/microcontroller/Pin.h" -#include "shared-module/audioio/Mixer.h" -#include "shared-bindings/audioio/RawSample.h" - -extern const mp_obj_type_t audioio_mixer_type; - -void common_hal_audioio_mixer_construct(audioio_mixer_obj_t* self, - uint8_t voice_count, - uint32_t buffer_size, - uint8_t bits_per_sample, - bool samples_signed, - uint8_t channel_count, - uint32_t sample_rate); - -void common_hal_audioio_mixer_deinit(audioio_mixer_obj_t* self); -bool common_hal_audioio_mixer_deinited(audioio_mixer_obj_t* self); -void common_hal_audioio_mixer_play(audioio_mixer_obj_t* self, mp_obj_t sample, uint8_t voice, bool loop); -void common_hal_audioio_mixer_stop_voice(audioio_mixer_obj_t* self, uint8_t voice); - -bool common_hal_audioio_mixer_get_playing(audioio_mixer_obj_t* self); -uint32_t common_hal_audioio_mixer_get_sample_rate(audioio_mixer_obj_t* self); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_MIXER_H diff --git a/shared-bindings/audioio/RawSample.c b/shared-bindings/audioio/RawSample.c deleted file mode 100644 index 62998f580..000000000 --- a/shared-bindings/audioio/RawSample.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "lib/utils/context_manager_helpers.h" -#include "py/binary.h" -#include "py/objproperty.h" -#include "py/runtime.h" -#include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/audioio/AudioOut.h" -#include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" - -//| .. currentmodule:: audioio -//| -//| :class:`RawSample` -- A raw audio sample buffer -//| ======================================================== -//| -//| An in-memory sound sample -//| -//| .. class:: RawSample(buffer, *, channel_count=1, sample_rate=8000) -//| -//| Create a RawSample based on the given buffer of signed values. If channel_count is more than -//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the -//| first sample will be for channel 1, the second sample will be for channel two, the third for -//| channel 1 and so on. -//| -//| :param array buffer: An `array.array` with samples -//| :param int channel_count: The number of channels in the buffer -//| :param int sample_rate: The desired playback sample rate -//| -//| Simple 8ksps 440 Hz sin wave:: -//| -//| import audioio -//| import board -//| import array -//| import time -//| import math -//| -//| # Generate one period of sine wav. -//| length = 8000 // 440 -//| sine_wave = array.array("h", [0] * length) -//| for i in range(length): -//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15)) -//| -//| dac = audioio.AudioOut(board.SPEAKER) -//| sine_wave = audioio.RawSample(sine_wave) -//| dac.play(sine_wave, loop=True) -//| time.sleep(1) -//| dac.stop() -//| -STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_buffer, ARG_channel_count, ARG_sample_rate }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, - { MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1 } }, - { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - audioio_rawsample_obj_t *self = m_new_obj(audioio_rawsample_obj_t); - self->base.type = &audioio_rawsample_type; - mp_buffer_info_t bufinfo; - if (mp_get_buffer(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ)) { - uint8_t bytes_per_sample = 1; - bool signed_samples = bufinfo.typecode == 'b' || bufinfo.typecode == 'h'; - if (bufinfo.typecode == 'h' || bufinfo.typecode == 'H') { - bytes_per_sample = 2; - } else if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) { - mp_raise_ValueError(translate("sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or 'B'")); - } - common_hal_audioio_rawsample_construct(self, ((uint8_t*)bufinfo.buf), bufinfo.len, - bytes_per_sample, signed_samples, args[ARG_channel_count].u_int, - args[ARG_sample_rate].u_int); - } else { - mp_raise_TypeError(translate("buffer must be a bytes-like object")); - } - - return MP_OBJ_FROM_PTR(self); -} - -//| .. method:: deinit() -//| -//| Deinitialises the AudioOut and releases any hardware resources for reuse. -//| -STATIC mp_obj_t audioio_rawsample_deinit(mp_obj_t self_in) { - audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_audioio_rawsample_deinit(self); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_rawsample_deinit_obj, audioio_rawsample_deinit); - -STATIC void check_for_deinit(audioio_rawsample_obj_t *self) { - if (common_hal_audioio_rawsample_deinited(self)) { - raise_deinited_error(); - } -} - -//| .. method:: __enter__() -//| -//| No-op used by Context Managers. -//| -// Provided by context manager helper. - -//| .. method:: __exit__() -//| -//| Automatically deinitializes the hardware when exiting a context. See -//| :ref:`lifetime-and-contextmanagers` for more info. -//| -STATIC mp_obj_t audioio_rawsample_obj___exit__(size_t n_args, const mp_obj_t *args) { - (void)n_args; - common_hal_audioio_rawsample_deinit(args[0]); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_rawsample___exit___obj, 4, 4, audioio_rawsample_obj___exit__); - -//| .. attribute:: sample_rate -//| -//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second). -//| When the sample is looped, this can change the pitch output without changing the underlying -//| sample. This will not change the sample rate of any active playback. Call ``play`` again to -//| change it. -//| -STATIC mp_obj_t audioio_rawsample_obj_get_sample_rate(mp_obj_t self_in) { - audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_rawsample_get_sample_rate(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(audioio_rawsample_get_sample_rate_obj, audioio_rawsample_obj_get_sample_rate); - -STATIC mp_obj_t audioio_rawsample_obj_set_sample_rate(mp_obj_t self_in, mp_obj_t sample_rate) { - audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - common_hal_audioio_rawsample_set_sample_rate(self, mp_obj_get_int(sample_rate)); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_2(audioio_rawsample_set_sample_rate_obj, audioio_rawsample_obj_set_sample_rate); - -const mp_obj_property_t audioio_rawsample_sample_rate_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&audioio_rawsample_get_sample_rate_obj, - (mp_obj_t)&audioio_rawsample_set_sample_rate_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -STATIC const mp_rom_map_elem_t audioio_rawsample_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioio_rawsample_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audioio_rawsample___exit___obj) }, - - // Properties - { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audioio_rawsample_sample_rate_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(audioio_rawsample_locals_dict, audioio_rawsample_locals_dict_table); - -const mp_obj_type_t audioio_rawsample_type = { - { &mp_type_type }, - .name = MP_QSTR_RawSample, - .make_new = audioio_rawsample_make_new, - .locals_dict = (mp_obj_dict_t*)&audioio_rawsample_locals_dict, -}; diff --git a/shared-bindings/audioio/RawSample.h b/shared-bindings/audioio/RawSample.h deleted file mode 100644 index 0d764b77c..000000000 --- a/shared-bindings/audioio/RawSample.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H - -#include "common-hal/audioio/AudioOut.h" -#include "common-hal/microcontroller/Pin.h" -#include "shared-module/audioio/RawSample.h" - -extern const mp_obj_type_t audioio_rawsample_type; - -void common_hal_audioio_rawsample_construct(audioio_rawsample_obj_t* self, - uint8_t* buffer, uint32_t len, uint8_t bytes_per_sample, bool samples_signed, - uint8_t channel_count, uint32_t sample_rate); - -void common_hal_audioio_rawsample_deinit(audioio_rawsample_obj_t* self); -bool common_hal_audioio_rawsample_deinited(audioio_rawsample_obj_t* self); -uint32_t common_hal_audioio_rawsample_get_sample_rate(audioio_rawsample_obj_t* self); -void common_hal_audioio_rawsample_set_sample_rate(audioio_rawsample_obj_t* self, uint32_t sample_rate); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H diff --git a/shared-bindings/audioio/WaveFile.c b/shared-bindings/audioio/WaveFile.c deleted file mode 100644 index 242c915d3..000000000 --- a/shared-bindings/audioio/WaveFile.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "lib/utils/context_manager_helpers.h" -#include "py/objproperty.h" -#include "py/runtime.h" -#include "shared-bindings/audioio/WaveFile.h" -#include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" - -//| .. currentmodule:: audioio -//| -//| :class:`WaveFile` -- Load a wave file for audio playback -//| ======================================================== -//| -//| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must -//| be 8 bit unsigned or 16 bit signed. -//| -//| .. class:: WaveFile(file) -//| -//| Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`. -//| -//| :param typing.BinaryIO file: Already opened wave file -//| -//| Playing a wave file from flash:: -//| -//| import board -//| import audioio -//| import digitalio -//| -//| # Required for CircuitPlayground Express -//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) -//| speaker_enable.switch_to_output(value=True) -//| -//| data = open("cplay-5.1-16bit-16khz.wav", "rb") -//| wav = audioio.WaveFile(data) -//| a = audioio.AudioOut(board.A0) -//| -//| print("playing") -//| a.play(wav) -//| while a.playing: -//| pass -//| print("stopped") -//| -STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); - - audioio_wavefile_obj_t *self = m_new_obj(audioio_wavefile_obj_t); - self->base.type = &audioio_wavefile_type; - if (MP_OBJ_IS_TYPE(args[0], &mp_type_fileio)) { - common_hal_audioio_wavefile_construct(self, MP_OBJ_TO_PTR(args[0])); - } else { - mp_raise_TypeError(translate("file must be a file opened in byte mode")); - } - - return MP_OBJ_FROM_PTR(self); -} - -//| .. method:: deinit() -//| -//| Deinitialises the WaveFile and releases all memory resources for reuse. -//| -STATIC mp_obj_t audioio_wavefile_deinit(mp_obj_t self_in) { - audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_audioio_wavefile_deinit(self); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_deinit_obj, audioio_wavefile_deinit); - -STATIC void check_for_deinit(audioio_wavefile_obj_t *self) { - if (common_hal_audioio_wavefile_deinited(self)) { - raise_deinited_error(); - } -} - -//| .. method:: __enter__() -//| -//| No-op used by Context Managers. -//| -// Provided by context manager helper. - -//| .. method:: __exit__() -//| -//| Automatically deinitializes the hardware when exiting a context. See -//| :ref:`lifetime-and-contextmanagers` for more info. -//| -STATIC mp_obj_t audioio_wavefile_obj___exit__(size_t n_args, const mp_obj_t *args) { - (void)n_args; - common_hal_audioio_wavefile_deinit(args[0]); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_wavefile___exit___obj, 4, 4, audioio_wavefile_obj___exit__); - -//| .. attribute:: sample_rate -//| -//| 32 bit value that dictates how quickly samples are loaded into the DAC -//| in Hertz (cycles per second). When the sample is looped, this can change -//| the pitch output without changing the underlying sample. -//| -STATIC mp_obj_t audioio_wavefile_obj_get_sample_rate(mp_obj_t self_in) { - audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_sample_rate(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_sample_rate_obj, audioio_wavefile_obj_get_sample_rate); - -STATIC mp_obj_t audioio_wavefile_obj_set_sample_rate(mp_obj_t self_in, mp_obj_t sample_rate) { - audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - common_hal_audioio_wavefile_set_sample_rate(self, mp_obj_get_int(sample_rate)); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_2(audioio_wavefile_set_sample_rate_obj, audioio_wavefile_obj_set_sample_rate); - -const mp_obj_property_t audioio_wavefile_sample_rate_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&audioio_wavefile_get_sample_rate_obj, - (mp_obj_t)&audioio_wavefile_set_sample_rate_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| .. attribute:: bits_per_sample -//| -//| Bits per sample. (read only) -//| -STATIC mp_obj_t audioio_wavefile_obj_get_bits_per_sample(mp_obj_t self_in) { - audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_bits_per_sample(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_bits_per_sample_obj, audioio_wavefile_obj_get_bits_per_sample); - -const mp_obj_property_t audioio_wavefile_bits_per_sample_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&audioio_wavefile_get_bits_per_sample_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| .. attribute:: channel_count -//| -//| Number of audio channels. (read only) -//| -STATIC mp_obj_t audioio_wavefile_obj_get_channel_count(mp_obj_t self_in) { - audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_channel_count(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_channel_count_obj, audioio_wavefile_obj_get_channel_count); - -const mp_obj_property_t audioio_wavefile_channel_count_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&audioio_wavefile_get_channel_count_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - - -STATIC const mp_rom_map_elem_t audioio_wavefile_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioio_wavefile_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audioio_wavefile___exit___obj) }, - - // Properties - { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audioio_wavefile_sample_rate_obj) }, - { MP_ROM_QSTR(MP_QSTR_bits_per_sample), MP_ROM_PTR(&audioio_wavefile_bits_per_sample_obj) }, - { MP_ROM_QSTR(MP_QSTR_channel_count), MP_ROM_PTR(&audioio_wavefile_channel_count_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(audioio_wavefile_locals_dict, audioio_wavefile_locals_dict_table); - -const mp_obj_type_t audioio_wavefile_type = { - { &mp_type_type }, - .name = MP_QSTR_WaveFile, - .make_new = audioio_wavefile_make_new, - .locals_dict = (mp_obj_dict_t*)&audioio_wavefile_locals_dict, -}; diff --git a/shared-bindings/audioio/WaveFile.h b/shared-bindings/audioio/WaveFile.h deleted file mode 100644 index 62a4200dc..000000000 --- a/shared-bindings/audioio/WaveFile.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_WAVEFILE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_WAVEFILE_H - -#include "common-hal/audioio/AudioOut.h" -#include "common-hal/microcontroller/Pin.h" -#include "extmod/vfs_fat.h" - -extern const mp_obj_type_t audioio_wavefile_type; - -void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t* self, - pyb_file_obj_t* file); - -void common_hal_audioio_wavefile_deinit(audioio_wavefile_obj_t* self); -bool common_hal_audioio_wavefile_deinited(audioio_wavefile_obj_t* self); -uint32_t common_hal_audioio_wavefile_get_sample_rate(audioio_wavefile_obj_t* self); -void common_hal_audioio_wavefile_set_sample_rate(audioio_wavefile_obj_t* self, uint32_t sample_rate); -uint8_t common_hal_audioio_wavefile_get_bits_per_sample(audioio_wavefile_obj_t* self); -uint8_t common_hal_audioio_wavefile_get_channel_count(audioio_wavefile_obj_t* self); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_WAVEFILE_H diff --git a/shared-bindings/audioio/__init__.c b/shared-bindings/audioio/__init__.c index 4786b6425..837b66255 100644 --- a/shared-bindings/audioio/__init__.c +++ b/shared-bindings/audioio/__init__.c @@ -32,9 +32,11 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audioio/__init__.h" #include "shared-bindings/audioio/AudioOut.h" -#include "shared-bindings/audioio/Mixer.h" -#include "shared-bindings/audioio/RawSample.h" -#include "shared-bindings/audioio/WaveFile.h" +#include "shared-bindings/audiocore/__init__.h" +#include "shared-bindings/audioio/AudioOut.h" +#include "shared-bindings/audiocore/Mixer.h" +#include "shared-bindings/audiocore/RawSample.h" +#include "shared-bindings/audiocore/WaveFile.h" //| :mod:`audioio` --- Support for audio input and output //| ====================================================== @@ -51,22 +53,19 @@ //| :maxdepth: 3 //| //| AudioOut -//| Mixer -//| RawSample -//| WaveFile //| //| All classes change hardware state and should be deinitialized when they //| are no longer needed if the program continues after use. To do so, either //| call :py:meth:`!deinit` or use a context manager. See //| :ref:`lifetime-and-contextmanagers` for more info. //| +//| Since CircuitPython 5, `Mixer`, `RawSample` and `WaveFile` are moved +//| to :mod:`audiocore`. +//| STATIC const mp_rom_map_elem_t audioio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audioio) }, { MP_ROM_QSTR(MP_QSTR_AudioOut), MP_ROM_PTR(&audioio_audioout_type) }, - { MP_ROM_QSTR(MP_QSTR_Mixer), MP_ROM_PTR(&audioio_mixer_type) }, - { MP_ROM_QSTR(MP_QSTR_RawSample), MP_ROM_PTR(&audioio_rawsample_type) }, - { MP_ROM_QSTR(MP_QSTR_WaveFile), MP_ROM_PTR(&audioio_wavefile_type) }, }; STATIC MP_DEFINE_CONST_DICT(audioio_module_globals, audioio_module_globals_table); diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index 8f9bbbb31..b7690d292 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -36,6 +36,7 @@ Module Supported Ports `analogio` **All Supported** `audiobusio` **SAMD/SAMD Express** `audioio` **SAMD Express** +`audiocore` **All with audioio** `binascii` **ESP8266** `bitbangio` **SAMD Express, ESP8266** `board` **All Supported** diff --git a/shared-module/audiocore/Mixer.c b/shared-module/audiocore/Mixer.c new file mode 100644 index 000000000..da66bb36e --- /dev/null +++ b/shared-module/audiocore/Mixer.c @@ -0,0 +1,341 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/audiocore/Mixer.h" + +#include + +#include "py/runtime.h" +#include "shared-module/audiocore/__init__.h" +#include "shared-module/audiocore/RawSample.h" + +void common_hal_audioio_mixer_construct(audioio_mixer_obj_t* self, + uint8_t voice_count, + uint32_t buffer_size, + uint8_t bits_per_sample, + bool samples_signed, + uint8_t channel_count, + uint32_t sample_rate) { + self->len = buffer_size / 2 / sizeof(uint32_t) * sizeof(uint32_t); + + self->first_buffer = m_malloc(self->len, false); + if (self->first_buffer == NULL) { + common_hal_audioio_mixer_deinit(self); + mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate first buffer")); + } + + self->second_buffer = m_malloc(self->len, false); + if (self->second_buffer == NULL) { + common_hal_audioio_mixer_deinit(self); + mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate second buffer")); + } + + self->bits_per_sample = bits_per_sample; + self->samples_signed = samples_signed; + self->channel_count = channel_count; + self->sample_rate = sample_rate; + self->voice_count = voice_count; + + for (uint8_t i = 0; i < self->voice_count; i++) { + self->voice[i].sample = NULL; + } +} + +void common_hal_audioio_mixer_deinit(audioio_mixer_obj_t* self) { + self->first_buffer = NULL; + self->second_buffer = NULL; +} + +bool common_hal_audioio_mixer_deinited(audioio_mixer_obj_t* self) { + return self->first_buffer == NULL; +} + +uint32_t common_hal_audioio_mixer_get_sample_rate(audioio_mixer_obj_t* self) { + return self->sample_rate; +} + +void common_hal_audioio_mixer_play(audioio_mixer_obj_t* self, mp_obj_t sample, uint8_t v, bool loop) { + if (v >= self->voice_count) { + mp_raise_ValueError(translate("Voice index too high")); + } + if (audiosample_sample_rate(sample) != self->sample_rate) { + mp_raise_ValueError(translate("The sample's sample rate does not match the mixer's")); + } + if (audiosample_channel_count(sample) != self->channel_count) { + mp_raise_ValueError(translate("The sample's channel count does not match the mixer's")); + } + if (audiosample_bits_per_sample(sample) != self->bits_per_sample) { + mp_raise_ValueError(translate("The sample's bits_per_sample does not match the mixer's")); + } + bool single_buffer; + bool samples_signed; + uint32_t max_buffer_length; + uint8_t spacing; + audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, + &max_buffer_length, &spacing); + if (samples_signed != self->samples_signed) { + mp_raise_ValueError(translate("The sample's signedness does not match the mixer's")); + } + audioio_mixer_voice_t* voice = &self->voice[v]; + voice->sample = sample; + voice->loop = loop; + + audiosample_reset_buffer(sample, false, 0); + audioio_get_buffer_result_t result = audiosample_get_buffer(sample, false, 0, (uint8_t**) &voice->remaining_buffer, &voice->buffer_length); + // Track length in terms of words. + voice->buffer_length /= sizeof(uint32_t); + voice->more_data = result == GET_BUFFER_MORE_DATA; +} + +void common_hal_audioio_mixer_stop_voice(audioio_mixer_obj_t* self, uint8_t voice) { + self->voice[voice].sample = NULL; +} + +bool common_hal_audioio_mixer_get_playing(audioio_mixer_obj_t* self) { + for (int32_t v = 0; v < self->voice_count; v++) { + if (self->voice[v].sample != NULL) { + return true; + } + } + return false; +} + +void audioio_mixer_reset_buffer(audioio_mixer_obj_t* self, + bool single_channel, + uint8_t channel) { + for (int32_t i = 0; i < self->voice_count; i++) { + self->voice[i].sample = NULL; + } +} + +uint32_t add8signed(uint32_t a, uint32_t b) { + #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) + return __QADD8(a, b); + #else + uint32_t result = 0; + for (int8_t i = 0; i < 4; i++) { + int8_t ai = a >> (sizeof(int8_t) * 8 * i); + int8_t bi = b >> (sizeof(int8_t) * 8 * i); + int32_t intermediate = (int32_t) ai + bi; + if (intermediate > CHAR_MAX) { + intermediate = CHAR_MAX; + } else if (intermediate < CHAR_MIN) { + //intermediate = CHAR_MIN; + } + result |= (((uint32_t) intermediate) & 0xff) << (sizeof(int8_t) * 8 * i); + } + return result; + #endif +} + +uint32_t add8unsigned(uint32_t a, uint32_t b) { + #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) + // Subtract out the DC offset, add and then shift back. + a = __USUB8(a, 0x80808080); + b = __USUB8(b, 0x80808080); + uint32_t sum = __QADD8(a, b); + return __UADD8(sum, 0x80808080); + #else + uint32_t result = 0; + for (int8_t i = 0; i < 4; i++) { + int8_t ai = (a >> (sizeof(uint8_t) * 8 * i)) - 128; + int8_t bi = (b >> (sizeof(uint8_t) * 8 * i)) - 128; + int32_t intermediate = (int32_t) ai + bi; + if (intermediate > UCHAR_MAX) { + intermediate = UCHAR_MAX; + } + result |= ((uint8_t) intermediate + 128) << (sizeof(uint8_t) * 8 * i); + } + return result; + #endif +} + +uint32_t add16signed(uint32_t a, uint32_t b) { + #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) + return __QADD16(a, b); + #else + uint32_t result = 0; + for (int8_t i = 0; i < 2; i++) { + int16_t ai = a >> (sizeof(int16_t) * 8 * i); + int16_t bi = b >> (sizeof(int16_t) * 8 * i); + int32_t intermediate = (int32_t) ai + bi; + if (intermediate > SHRT_MAX) { + intermediate = SHRT_MAX; + } else if (intermediate < SHRT_MIN) { + intermediate = SHRT_MIN; + } + result |= (((uint32_t) intermediate) & 0xffff) << (sizeof(int16_t) * 8 * i); + } + return result; + #endif +} + +uint32_t add16unsigned(uint32_t a, uint32_t b) { + #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) + // Subtract out the DC offset, add and then shift back. + a = __USUB16(a, 0x80008000); + b = __USUB16(b, 0x80008000); + uint32_t sum = __QADD16(a, b); + return __UADD16(sum, 0x80008000); + #else + uint32_t result = 0; + for (int8_t i = 0; i < 2; i++) { + int16_t ai = (a >> (sizeof(uint16_t) * 8 * i)) - 0x8000; + int16_t bi = (b >> (sizeof(uint16_t) * 8 * i)) - 0x8000; + int32_t intermediate = (int32_t) ai + bi; + if (intermediate > USHRT_MAX) { + intermediate = USHRT_MAX; + } + result |= ((uint16_t) intermediate + 0x8000) << (sizeof(int16_t) * 8 * i); + } + return result; + #endif +} + +audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self, + bool single_channel, + uint8_t channel, + uint8_t** buffer, + uint32_t* buffer_length) { + if (!single_channel) { + channel = 0; + } + + uint32_t channel_read_count = self->left_read_count; + if (channel == 1) { + channel_read_count = self->right_read_count; + } + *buffer_length = self->len; + + bool need_more_data = self->read_count == channel_read_count; + if (need_more_data) { + uint32_t* word_buffer; + if (self->use_first_buffer) { + *buffer = (uint8_t*) self->first_buffer; + word_buffer = self->first_buffer; + } else { + *buffer = (uint8_t*) self->second_buffer; + word_buffer = self->second_buffer; + } + self->use_first_buffer = !self->use_first_buffer; + bool voices_active = false; + for (int32_t v = 0; v < self->voice_count; v++) { + audioio_mixer_voice_t* voice = &self->voice[v]; + + uint32_t j = 0; + bool voice_done = voice->sample == NULL; + for (uint32_t i = 0; i < self->len / sizeof(uint32_t); i++) { + if (!voice_done && j >= voice->buffer_length) { + if (!voice->more_data) { + if (voice->loop) { + audiosample_reset_buffer(voice->sample, false, 0); + } else { + voice->sample = NULL; + voice_done = true; + } + } + if (!voice_done) { + // Load another buffer + audioio_get_buffer_result_t result = audiosample_get_buffer(voice->sample, false, 0, (uint8_t**) &voice->remaining_buffer, &voice->buffer_length); + // Track length in terms of words. + voice->buffer_length /= sizeof(uint32_t); + voice->more_data = result == GET_BUFFER_MORE_DATA; + j = 0; + } + } + // First active voice gets copied over verbatim. + uint32_t sample_value; + if (voice_done) { + // Exit early if another voice already set all samples once. + if (voices_active) { + continue; + } + sample_value = 0; + if (!self->samples_signed) { + if (self->bits_per_sample == 8) { + sample_value = 0x7f7f7f7f; + } else { + sample_value = 0x7fff7fff; + } + } + } else { + sample_value = voice->remaining_buffer[j]; + } + + if (!voices_active) { + word_buffer[i] = sample_value; + } else { + if (self->bits_per_sample == 8) { + if (self->samples_signed) { + word_buffer[i] = add8signed(word_buffer[i], sample_value); + } else { + word_buffer[i] = add8unsigned(word_buffer[i], sample_value); + } + } else { + if (self->samples_signed) { + word_buffer[i] = add16signed(word_buffer[i], sample_value); + } else { + word_buffer[i] = add16unsigned(word_buffer[i], sample_value); + } + } + } + j++; + } + voice->buffer_length -= j; + voice->remaining_buffer += j; + + voices_active = true; + } + + self->read_count += 1; + } else if (!self->use_first_buffer) { + *buffer = (uint8_t*) self->first_buffer; + } else { + *buffer = (uint8_t*) self->second_buffer; + } + + + if (channel == 0) { + self->left_read_count += 1; + } else if (channel == 1) { + self->right_read_count += 1; + *buffer = *buffer + self->bits_per_sample / 8; + } + return GET_BUFFER_MORE_DATA; +} + +void audioio_mixer_get_buffer_structure(audioio_mixer_obj_t* self, bool single_channel, + bool* single_buffer, bool* samples_signed, + uint32_t* max_buffer_length, uint8_t* spacing) { + *single_buffer = false; + *samples_signed = self->samples_signed; + *max_buffer_length = self->len; + if (single_channel) { + *spacing = self->channel_count; + } else { + *spacing = 1; + } +} diff --git a/shared-module/audiocore/Mixer.h b/shared-module/audiocore/Mixer.h new file mode 100644 index 000000000..22eb6a37f --- /dev/null +++ b/shared-module/audiocore/Mixer.h @@ -0,0 +1,75 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H +#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H + +#include "py/obj.h" + +#include "shared-module/audiocore/__init__.h" + +typedef struct { + mp_obj_t sample; + bool loop; + bool more_data; + uint32_t* remaining_buffer; + uint32_t buffer_length; +} audioio_mixer_voice_t; + +typedef struct { + mp_obj_base_t base; + uint32_t* first_buffer; + uint32_t* second_buffer; + uint32_t len; // in words + uint8_t bits_per_sample; + bool use_first_buffer; + bool samples_signed; + uint8_t channel_count; + uint32_t sample_rate; + + uint32_t read_count; + uint32_t left_read_count; + uint32_t right_read_count; + + uint8_t voice_count; + audioio_mixer_voice_t voice[]; +} audioio_mixer_obj_t; + + +// These are not available from Python because it may be called in an interrupt. +void audioio_mixer_reset_buffer(audioio_mixer_obj_t* self, + bool single_channel, + uint8_t channel); +audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self, + bool single_channel, + uint8_t channel, + uint8_t** buffer, + uint32_t* buffer_length); // length in bytes +void audioio_mixer_get_buffer_structure(audioio_mixer_obj_t* self, bool single_channel, + bool* single_buffer, bool* samples_signed, + uint32_t* max_buffer_length, uint8_t* spacing); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H diff --git a/shared-module/audiocore/RawSample.c b/shared-module/audiocore/RawSample.c new file mode 100644 index 000000000..d6bf3a567 --- /dev/null +++ b/shared-module/audiocore/RawSample.c @@ -0,0 +1,94 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/audiocore/RawSample.h" + +#include + +#include "shared-module/audiocore/RawSample.h" + +void common_hal_audioio_rawsample_construct(audioio_rawsample_obj_t* self, + uint8_t* buffer, + uint32_t len, + uint8_t bytes_per_sample, + bool samples_signed, + uint8_t channel_count, + uint32_t sample_rate) { + self->buffer = buffer; + self->bits_per_sample = bytes_per_sample * 8; + self->samples_signed = samples_signed; + self->len = len; + self->channel_count = channel_count; + self->sample_rate = sample_rate; + self->buffer_read = false; +} + +void common_hal_audioio_rawsample_deinit(audioio_rawsample_obj_t* self) { + self->buffer = NULL; +} +bool common_hal_audioio_rawsample_deinited(audioio_rawsample_obj_t* self) { + return self->buffer == NULL; +} + +uint32_t common_hal_audioio_rawsample_get_sample_rate(audioio_rawsample_obj_t* self) { + return self->sample_rate; +} +void common_hal_audioio_rawsample_set_sample_rate(audioio_rawsample_obj_t* self, + uint32_t sample_rate) { + self->sample_rate = sample_rate; +} + +void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t* self, + bool single_channel, + uint8_t channel) { +} + +audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t* self, + bool single_channel, + uint8_t channel, + uint8_t** buffer, + uint32_t* buffer_length) { + *buffer_length = self->len; + if (single_channel) { + *buffer = self->buffer + (channel % self->channel_count) * (self->bits_per_sample / 8); + } else { + *buffer = self->buffer; + } + return GET_BUFFER_DONE; +} + +void audioio_rawsample_get_buffer_structure(audioio_rawsample_obj_t* self, bool single_channel, + bool* single_buffer, bool* samples_signed, + uint32_t* max_buffer_length, uint8_t* spacing) { + *single_buffer = true; + *samples_signed = self->samples_signed; + *max_buffer_length = self->len; + if (single_channel) { + *spacing = self->channel_count; + } else { + *spacing = 1; + } +} diff --git a/shared-module/audiocore/RawSample.h b/shared-module/audiocore/RawSample.h new file mode 100644 index 000000000..6c2c19c9b --- /dev/null +++ b/shared-module/audiocore/RawSample.h @@ -0,0 +1,59 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_RAWSAMPLE_H +#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_RAWSAMPLE_H + +#include "py/obj.h" + +#include "shared-module/audiocore/__init__.h" + +typedef struct { + mp_obj_base_t base; + uint8_t* buffer; + uint32_t len; + uint8_t bits_per_sample; + bool samples_signed; + uint8_t channel_count; + uint32_t sample_rate; + bool buffer_read; +} audioio_rawsample_obj_t; + + +// These are not available from Python because it may be called in an interrupt. +void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t* self, + bool single_channel, + uint8_t channel); +audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t* self, + bool single_channel, + uint8_t channel, + uint8_t** buffer, + uint32_t* buffer_length); // length in bytes +void audioio_rawsample_get_buffer_structure(audioio_rawsample_obj_t* self, bool single_channel, + bool* single_buffer, bool* samples_signed, + uint32_t* max_buffer_length, uint8_t* spacing); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_RAWSAMPLE_H diff --git a/shared-module/audiocore/WaveFile.c b/shared-module/audiocore/WaveFile.c new file mode 100644 index 000000000..810d9c33b --- /dev/null +++ b/shared-module/audiocore/WaveFile.c @@ -0,0 +1,268 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/audiocore/WaveFile.h" + +#include +#include + +#include "py/mperrno.h" +#include "py/runtime.h" + +#include "shared-module/audiocore/WaveFile.h" +#include "supervisor/shared/translate.h" + +struct wave_format_chunk { + uint16_t audio_format; + uint16_t num_channels; + uint32_t sample_rate; + uint32_t byte_rate; + uint16_t block_align; + uint16_t bits_per_sample; + uint16_t extra_params; // Assumed to be zero below. +}; + +void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t* self, + pyb_file_obj_t* file) { + // Load the wave + self->file = file; + uint8_t chunk_header[16]; + f_rewind(&self->file->fp); + UINT bytes_read; + if (f_read(&self->file->fp, chunk_header, 16, &bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (bytes_read != 16 || + memcmp(chunk_header, "RIFF", 4) != 0 || + memcmp(chunk_header + 8, "WAVEfmt ", 8) != 0) { + mp_raise_ValueError(translate("Invalid wave file")); + } + uint32_t format_size; + if (f_read(&self->file->fp, &format_size, 4, &bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (bytes_read != 4 || + format_size > sizeof(struct wave_format_chunk)) { + mp_raise_ValueError(translate("Invalid format chunk size")); + } + struct wave_format_chunk format; + if (f_read(&self->file->fp, &format, format_size, &bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (bytes_read != format_size) { + } + + if (format.audio_format != 1 || + format.num_channels > 2 || + format.bits_per_sample > 16 || + (format_size == 18 && + format.extra_params != 0)) { + mp_raise_ValueError(translate("Unsupported format")); + } + // Get the sample_rate + self->sample_rate = format.sample_rate; + self->len = 256; + self->channel_count = format.num_channels; + self->bits_per_sample = format.bits_per_sample; + + // TODO(tannewt): Skip any extra chunks that occur before the data section. + + uint8_t data_tag[4]; + if (f_read(&self->file->fp, &data_tag, 4, &bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (bytes_read != 4 || + memcmp((uint8_t *) data_tag, "data", 4) != 0) { + mp_raise_ValueError(translate("Data chunk must follow fmt chunk")); + } + + uint32_t data_length; + if (f_read(&self->file->fp, &data_length, 4, &bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (bytes_read != 4) { + mp_raise_ValueError(translate("Invalid file")); + } + self->file_length = data_length; + self->data_start = self->file->fp.fptr; + + // Try to allocate two buffers, one will be loaded from file and the other + // DMAed to DAC. + self->buffer = m_malloc(self->len, false); + if (self->buffer == NULL) { + common_hal_audioio_wavefile_deinit(self); + mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate first buffer")); + } + + self->second_buffer = m_malloc(self->len, false); + if (self->second_buffer == NULL) { + common_hal_audioio_wavefile_deinit(self); + mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate second buffer")); + } +} + +void common_hal_audioio_wavefile_deinit(audioio_wavefile_obj_t* self) { + self->buffer = NULL; +} + +bool common_hal_audioio_wavefile_deinited(audioio_wavefile_obj_t* self) { + return self->buffer == NULL; +} + +uint32_t common_hal_audioio_wavefile_get_sample_rate(audioio_wavefile_obj_t* self) { + return self->sample_rate; +} + +void common_hal_audioio_wavefile_set_sample_rate(audioio_wavefile_obj_t* self, + uint32_t sample_rate) { + self->sample_rate = sample_rate; +} + +uint8_t common_hal_audioio_wavefile_get_bits_per_sample(audioio_wavefile_obj_t* self) { + return self->bits_per_sample; +} + +uint8_t common_hal_audioio_wavefile_get_channel_count(audioio_wavefile_obj_t* self) { + return self->channel_count; +} + +bool audioio_wavefile_samples_signed(audioio_wavefile_obj_t* self) { + return self->bits_per_sample > 8; +} + +uint32_t audioio_wavefile_max_buffer_length(audioio_wavefile_obj_t* self) { + return 512; +} + +void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t* self, + bool single_channel, + uint8_t channel) { + if (single_channel && channel == 1) { + return; + } + // We don't reset the buffer index in case we're looping and we have an odd number of buffer + // loads + self->bytes_remaining = self->file_length; + f_lseek(&self->file->fp, self->data_start); + self->read_count = 0; + self->left_read_count = 0; + self->right_read_count = 0; +} + +audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t* self, + bool single_channel, + uint8_t channel, + uint8_t** buffer, + uint32_t* buffer_length) { + if (!single_channel) { + channel = 0; + } + + uint32_t channel_read_count = self->left_read_count; + if (channel == 1) { + channel_read_count = self->right_read_count; + } + + bool need_more_data = self->read_count == channel_read_count; + + if (self->bytes_remaining == 0 && need_more_data) { + *buffer = NULL; + *buffer_length = 0; + return GET_BUFFER_DONE; + } + + if (need_more_data) { + uint16_t num_bytes_to_load = self->len; + if (num_bytes_to_load > self->bytes_remaining) { + num_bytes_to_load = self->bytes_remaining; + } + UINT length_read; + if (self->buffer_index % 2 == 1) { + *buffer = self->second_buffer; + } else { + *buffer = self->buffer; + } + if (f_read(&self->file->fp, *buffer, num_bytes_to_load, &length_read) != FR_OK) { + return GET_BUFFER_ERROR; + } + self->bytes_remaining -= length_read; + // Pad the last buffer to word align it. + if (self->bytes_remaining == 0 && length_read % sizeof(uint32_t) != 0) { + uint32_t pad = length_read % sizeof(uint32_t); + length_read += pad; + if (self->bits_per_sample == 8) { + for (uint32_t i = 0; i < pad; i++) { + ((uint8_t*) (*buffer))[length_read / sizeof(uint8_t) - i - 1] = 0x80; + } + } else if (self->bits_per_sample == 16) { + // We know the buffer is aligned because we allocated it onto the heap ourselves. + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + ((int16_t*) (*buffer))[length_read / sizeof(int16_t) - 1] = 0; + #pragma GCC diagnostic pop + } + } + *buffer_length = length_read; + if (self->buffer_index % 2 == 1) { + self->second_buffer_length = length_read; + } else { + self->buffer_length = length_read; + } + self->buffer_index += 1; + self->read_count += 1; + } + + uint32_t buffers_back = self->read_count - 1 - channel_read_count; + if ((self->buffer_index - buffers_back) % 2 == 0) { + *buffer = self->second_buffer; + *buffer_length = self->second_buffer_length; + } else { + *buffer = self->buffer; + *buffer_length = self->buffer_length; + } + + if (channel == 0) { + self->left_read_count += 1; + } else if (channel == 1) { + self->right_read_count += 1; + *buffer = *buffer + self->bits_per_sample / 8; + } + + return self->bytes_remaining == 0 ? GET_BUFFER_DONE : GET_BUFFER_MORE_DATA; +} + +void audioio_wavefile_get_buffer_structure(audioio_wavefile_obj_t* self, bool single_channel, + bool* single_buffer, bool* samples_signed, + uint32_t* max_buffer_length, uint8_t* spacing) { + *single_buffer = false; + *samples_signed = self->bits_per_sample > 8; + *max_buffer_length = 512; + if (single_channel) { + *spacing = self->channel_count; + } else { + *spacing = 1; + } +} diff --git a/shared-module/audiocore/WaveFile.h b/shared-module/audiocore/WaveFile.h new file mode 100644 index 000000000..97dd6a46f --- /dev/null +++ b/shared-module/audiocore/WaveFile.h @@ -0,0 +1,70 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_WAVEFILE_H +#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_WAVEFILE_H + +#include "py/obj.h" + +#include "shared-module/audiocore/__init__.h" + +typedef struct { + mp_obj_base_t base; + uint8_t* buffer; + uint32_t buffer_length; + uint8_t* second_buffer; + uint32_t second_buffer_length; + uint32_t file_length; // In bytes + uint16_t data_start; // Where the data values start + uint8_t bits_per_sample; + uint16_t buffer_index; + uint32_t bytes_remaining; + + uint8_t channel_count; + uint32_t sample_rate; + + uint32_t len; + pyb_file_obj_t* file; + + uint32_t read_count; + uint32_t left_read_count; + uint32_t right_read_count; +} audioio_wavefile_obj_t; + +// These are not available from Python because it may be called in an interrupt. +void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t* self, + bool single_channel, + uint8_t channel); +audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t* self, + bool single_channel, + uint8_t channel, + uint8_t** buffer, + uint32_t* buffer_length); // length in bytes +void audioio_wavefile_get_buffer_structure(audioio_wavefile_obj_t* self, bool single_channel, + bool* single_buffer, bool* samples_signed, + uint32_t* max_buffer_length, uint8_t* spacing); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_WAVEFILE_H diff --git a/shared-module/audiocore/__init__.c b/shared-module/audiocore/__init__.c new file mode 100644 index 000000000..067cae5dd --- /dev/null +++ b/shared-module/audiocore/__init__.c @@ -0,0 +1,125 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-module/audioio/__init__.h" + +#include "py/obj.h" +#include "shared-bindings/audiocore/Mixer.h" +#include "shared-bindings/audiocore/RawSample.h" +#include "shared-bindings/audiocore/WaveFile.h" +#include "shared-module/audiocore/Mixer.h" +#include "shared-module/audiocore/RawSample.h" +#include "shared-module/audiocore/WaveFile.h" + +uint32_t audiosample_sample_rate(mp_obj_t sample_obj) { + if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { + audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); + return sample->sample_rate; + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { + audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + return file->sample_rate; + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { + audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); + return mixer->sample_rate; + } + return 16000; +} + +uint8_t audiosample_bits_per_sample(mp_obj_t sample_obj) { + if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { + audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); + return sample->bits_per_sample; + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { + audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + return file->bits_per_sample; + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { + audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); + return mixer->bits_per_sample; + } + return 8; +} + +uint8_t audiosample_channel_count(mp_obj_t sample_obj) { + if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { + audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); + return sample->channel_count; + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { + audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + return file->channel_count; + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { + audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); + return mixer->channel_count; + } + return 1; +} + +void audiosample_reset_buffer(mp_obj_t sample_obj, bool single_channel, uint8_t audio_channel) { + if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { + audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); + audioio_rawsample_reset_buffer(sample, single_channel, audio_channel); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { + audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + audioio_wavefile_reset_buffer(file, single_channel, audio_channel); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { + audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + audioio_mixer_reset_buffer(file, single_channel, audio_channel); + } +} + +audioio_get_buffer_result_t audiosample_get_buffer(mp_obj_t sample_obj, + bool single_channel, + uint8_t channel, + uint8_t** buffer, uint32_t* buffer_length) { + if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { + audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); + return audioio_rawsample_get_buffer(sample, single_channel, channel, buffer, buffer_length); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { + audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + return audioio_wavefile_get_buffer(file, single_channel, channel, buffer, buffer_length); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { + audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + return audioio_mixer_get_buffer(file, single_channel, channel, buffer, buffer_length); + } + return GET_BUFFER_DONE; +} + +void audiosample_get_buffer_structure(mp_obj_t sample_obj, bool single_channel, + bool* single_buffer, bool* samples_signed, + uint32_t* max_buffer_length, uint8_t* spacing) { + if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { + audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); + audioio_rawsample_get_buffer_structure(sample, single_channel, single_buffer, + samples_signed, max_buffer_length, spacing); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { + audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + audioio_wavefile_get_buffer_structure(file, single_channel, single_buffer, samples_signed, + max_buffer_length, spacing); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { + audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + audioio_mixer_get_buffer_structure(file, single_channel, single_buffer, samples_signed, + max_buffer_length, spacing); + } +} diff --git a/shared-module/audiocore/__init__.h b/shared-module/audiocore/__init__.h new file mode 100644 index 000000000..7aa0c1824 --- /dev/null +++ b/shared-module/audiocore/__init__.h @@ -0,0 +1,53 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOCORE__INIT__H +#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOCORE__INIT__H + +#include +#include + +#include "py/obj.h" + +typedef enum { + GET_BUFFER_DONE, // No more data to read + GET_BUFFER_MORE_DATA, // More data to read. + GET_BUFFER_ERROR, // Error while reading data. +} audioio_get_buffer_result_t; + +uint32_t audiosample_sample_rate(mp_obj_t sample_obj); +uint8_t audiosample_bits_per_sample(mp_obj_t sample_obj); +uint8_t audiosample_channel_count(mp_obj_t sample_obj); +void audiosample_reset_buffer(mp_obj_t sample_obj, bool single_channel, uint8_t audio_channel); +audioio_get_buffer_result_t audiosample_get_buffer(mp_obj_t sample_obj, + bool single_channel, + uint8_t channel, + uint8_t** buffer, uint32_t* buffer_length); +void audiosample_get_buffer_structure(mp_obj_t sample_obj, bool single_channel, + bool* single_buffer, bool* samples_signed, + uint32_t* max_buffer_length, uint8_t* spacing); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOCORE__INIT__H diff --git a/shared-module/audioio/Mixer.c b/shared-module/audioio/Mixer.c deleted file mode 100644 index 8020a621e..000000000 --- a/shared-module/audioio/Mixer.c +++ /dev/null @@ -1,341 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-bindings/audioio/Mixer.h" - -#include - -#include "py/runtime.h" -#include "shared-module/audioio/__init__.h" -#include "shared-module/audioio/RawSample.h" - -void common_hal_audioio_mixer_construct(audioio_mixer_obj_t* self, - uint8_t voice_count, - uint32_t buffer_size, - uint8_t bits_per_sample, - bool samples_signed, - uint8_t channel_count, - uint32_t sample_rate) { - self->len = buffer_size / 2 / sizeof(uint32_t) * sizeof(uint32_t); - - self->first_buffer = m_malloc(self->len, false); - if (self->first_buffer == NULL) { - common_hal_audioio_mixer_deinit(self); - mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate first buffer")); - } - - self->second_buffer = m_malloc(self->len, false); - if (self->second_buffer == NULL) { - common_hal_audioio_mixer_deinit(self); - mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate second buffer")); - } - - self->bits_per_sample = bits_per_sample; - self->samples_signed = samples_signed; - self->channel_count = channel_count; - self->sample_rate = sample_rate; - self->voice_count = voice_count; - - for (uint8_t i = 0; i < self->voice_count; i++) { - self->voice[i].sample = NULL; - } -} - -void common_hal_audioio_mixer_deinit(audioio_mixer_obj_t* self) { - self->first_buffer = NULL; - self->second_buffer = NULL; -} - -bool common_hal_audioio_mixer_deinited(audioio_mixer_obj_t* self) { - return self->first_buffer == NULL; -} - -uint32_t common_hal_audioio_mixer_get_sample_rate(audioio_mixer_obj_t* self) { - return self->sample_rate; -} - -void common_hal_audioio_mixer_play(audioio_mixer_obj_t* self, mp_obj_t sample, uint8_t v, bool loop) { - if (v >= self->voice_count) { - mp_raise_ValueError(translate("Voice index too high")); - } - if (audiosample_sample_rate(sample) != self->sample_rate) { - mp_raise_ValueError(translate("The sample's sample rate does not match the mixer's")); - } - if (audiosample_channel_count(sample) != self->channel_count) { - mp_raise_ValueError(translate("The sample's channel count does not match the mixer's")); - } - if (audiosample_bits_per_sample(sample) != self->bits_per_sample) { - mp_raise_ValueError(translate("The sample's bits_per_sample does not match the mixer's")); - } - bool single_buffer; - bool samples_signed; - uint32_t max_buffer_length; - uint8_t spacing; - audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, - &max_buffer_length, &spacing); - if (samples_signed != self->samples_signed) { - mp_raise_ValueError(translate("The sample's signedness does not match the mixer's")); - } - audioio_mixer_voice_t* voice = &self->voice[v]; - voice->sample = sample; - voice->loop = loop; - - audiosample_reset_buffer(sample, false, 0); - audioio_get_buffer_result_t result = audiosample_get_buffer(sample, false, 0, (uint8_t**) &voice->remaining_buffer, &voice->buffer_length); - // Track length in terms of words. - voice->buffer_length /= sizeof(uint32_t); - voice->more_data = result == GET_BUFFER_MORE_DATA; -} - -void common_hal_audioio_mixer_stop_voice(audioio_mixer_obj_t* self, uint8_t voice) { - self->voice[voice].sample = NULL; -} - -bool common_hal_audioio_mixer_get_playing(audioio_mixer_obj_t* self) { - for (int32_t v = 0; v < self->voice_count; v++) { - if (self->voice[v].sample != NULL) { - return true; - } - } - return false; -} - -void audioio_mixer_reset_buffer(audioio_mixer_obj_t* self, - bool single_channel, - uint8_t channel) { - for (int32_t i = 0; i < self->voice_count; i++) { - self->voice[i].sample = NULL; - } -} - -uint32_t add8signed(uint32_t a, uint32_t b) { - #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) - return __QADD8(a, b); - #else - uint32_t result = 0; - for (int8_t i = 0; i < 4; i++) { - int8_t ai = a >> (sizeof(int8_t) * 8 * i); - int8_t bi = b >> (sizeof(int8_t) * 8 * i); - int32_t intermediate = (int32_t) ai + bi; - if (intermediate > CHAR_MAX) { - intermediate = CHAR_MAX; - } else if (intermediate < CHAR_MIN) { - //intermediate = CHAR_MIN; - } - result |= (((uint32_t) intermediate) & 0xff) << (sizeof(int8_t) * 8 * i); - } - return result; - #endif -} - -uint32_t add8unsigned(uint32_t a, uint32_t b) { - #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) - // Subtract out the DC offset, add and then shift back. - a = __USUB8(a, 0x80808080); - b = __USUB8(b, 0x80808080); - uint32_t sum = __QADD8(a, b); - return __UADD8(sum, 0x80808080); - #else - uint32_t result = 0; - for (int8_t i = 0; i < 4; i++) { - int8_t ai = (a >> (sizeof(uint8_t) * 8 * i)) - 128; - int8_t bi = (b >> (sizeof(uint8_t) * 8 * i)) - 128; - int32_t intermediate = (int32_t) ai + bi; - if (intermediate > UCHAR_MAX) { - intermediate = UCHAR_MAX; - } - result |= ((uint8_t) intermediate + 128) << (sizeof(uint8_t) * 8 * i); - } - return result; - #endif -} - -uint32_t add16signed(uint32_t a, uint32_t b) { - #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) - return __QADD16(a, b); - #else - uint32_t result = 0; - for (int8_t i = 0; i < 2; i++) { - int16_t ai = a >> (sizeof(int16_t) * 8 * i); - int16_t bi = b >> (sizeof(int16_t) * 8 * i); - int32_t intermediate = (int32_t) ai + bi; - if (intermediate > SHRT_MAX) { - intermediate = SHRT_MAX; - } else if (intermediate < SHRT_MIN) { - intermediate = SHRT_MIN; - } - result |= (((uint32_t) intermediate) & 0xffff) << (sizeof(int16_t) * 8 * i); - } - return result; - #endif -} - -uint32_t add16unsigned(uint32_t a, uint32_t b) { - #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) - // Subtract out the DC offset, add and then shift back. - a = __USUB16(a, 0x80008000); - b = __USUB16(b, 0x80008000); - uint32_t sum = __QADD16(a, b); - return __UADD16(sum, 0x80008000); - #else - uint32_t result = 0; - for (int8_t i = 0; i < 2; i++) { - int16_t ai = (a >> (sizeof(uint16_t) * 8 * i)) - 0x8000; - int16_t bi = (b >> (sizeof(uint16_t) * 8 * i)) - 0x8000; - int32_t intermediate = (int32_t) ai + bi; - if (intermediate > USHRT_MAX) { - intermediate = USHRT_MAX; - } - result |= ((uint16_t) intermediate + 0x8000) << (sizeof(int16_t) * 8 * i); - } - return result; - #endif -} - -audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self, - bool single_channel, - uint8_t channel, - uint8_t** buffer, - uint32_t* buffer_length) { - if (!single_channel) { - channel = 0; - } - - uint32_t channel_read_count = self->left_read_count; - if (channel == 1) { - channel_read_count = self->right_read_count; - } - *buffer_length = self->len; - - bool need_more_data = self->read_count == channel_read_count; - if (need_more_data) { - uint32_t* word_buffer; - if (self->use_first_buffer) { - *buffer = (uint8_t*) self->first_buffer; - word_buffer = self->first_buffer; - } else { - *buffer = (uint8_t*) self->second_buffer; - word_buffer = self->second_buffer; - } - self->use_first_buffer = !self->use_first_buffer; - bool voices_active = false; - for (int32_t v = 0; v < self->voice_count; v++) { - audioio_mixer_voice_t* voice = &self->voice[v]; - - uint32_t j = 0; - bool voice_done = voice->sample == NULL; - for (uint32_t i = 0; i < self->len / sizeof(uint32_t); i++) { - if (!voice_done && j >= voice->buffer_length) { - if (!voice->more_data) { - if (voice->loop) { - audiosample_reset_buffer(voice->sample, false, 0); - } else { - voice->sample = NULL; - voice_done = true; - } - } - if (!voice_done) { - // Load another buffer - audioio_get_buffer_result_t result = audiosample_get_buffer(voice->sample, false, 0, (uint8_t**) &voice->remaining_buffer, &voice->buffer_length); - // Track length in terms of words. - voice->buffer_length /= sizeof(uint32_t); - voice->more_data = result == GET_BUFFER_MORE_DATA; - j = 0; - } - } - // First active voice gets copied over verbatim. - uint32_t sample_value; - if (voice_done) { - // Exit early if another voice already set all samples once. - if (voices_active) { - continue; - } - sample_value = 0; - if (!self->samples_signed) { - if (self->bits_per_sample == 8) { - sample_value = 0x7f7f7f7f; - } else { - sample_value = 0x7fff7fff; - } - } - } else { - sample_value = voice->remaining_buffer[j]; - } - - if (!voices_active) { - word_buffer[i] = sample_value; - } else { - if (self->bits_per_sample == 8) { - if (self->samples_signed) { - word_buffer[i] = add8signed(word_buffer[i], sample_value); - } else { - word_buffer[i] = add8unsigned(word_buffer[i], sample_value); - } - } else { - if (self->samples_signed) { - word_buffer[i] = add16signed(word_buffer[i], sample_value); - } else { - word_buffer[i] = add16unsigned(word_buffer[i], sample_value); - } - } - } - j++; - } - voice->buffer_length -= j; - voice->remaining_buffer += j; - - voices_active = true; - } - - self->read_count += 1; - } else if (!self->use_first_buffer) { - *buffer = (uint8_t*) self->first_buffer; - } else { - *buffer = (uint8_t*) self->second_buffer; - } - - - if (channel == 0) { - self->left_read_count += 1; - } else if (channel == 1) { - self->right_read_count += 1; - *buffer = *buffer + self->bits_per_sample / 8; - } - return GET_BUFFER_MORE_DATA; -} - -void audioio_mixer_get_buffer_structure(audioio_mixer_obj_t* self, bool single_channel, - bool* single_buffer, bool* samples_signed, - uint32_t* max_buffer_length, uint8_t* spacing) { - *single_buffer = false; - *samples_signed = self->samples_signed; - *max_buffer_length = self->len; - if (single_channel) { - *spacing = self->channel_count; - } else { - *spacing = 1; - } -} diff --git a/shared-module/audioio/Mixer.h b/shared-module/audioio/Mixer.h deleted file mode 100644 index 6a88fe0bd..000000000 --- a/shared-module/audioio/Mixer.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H -#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H - -#include "py/obj.h" - -#include "shared-module/audioio/__init__.h" - -typedef struct { - mp_obj_t sample; - bool loop; - bool more_data; - uint32_t* remaining_buffer; - uint32_t buffer_length; -} audioio_mixer_voice_t; - -typedef struct { - mp_obj_base_t base; - uint32_t* first_buffer; - uint32_t* second_buffer; - uint32_t len; // in words - uint8_t bits_per_sample; - bool use_first_buffer; - bool samples_signed; - uint8_t channel_count; - uint32_t sample_rate; - - uint32_t read_count; - uint32_t left_read_count; - uint32_t right_read_count; - - uint8_t voice_count; - audioio_mixer_voice_t voice[]; -} audioio_mixer_obj_t; - - -// These are not available from Python because it may be called in an interrupt. -void audioio_mixer_reset_buffer(audioio_mixer_obj_t* self, - bool single_channel, - uint8_t channel); -audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self, - bool single_channel, - uint8_t channel, - uint8_t** buffer, - uint32_t* buffer_length); // length in bytes -void audioio_mixer_get_buffer_structure(audioio_mixer_obj_t* self, bool single_channel, - bool* single_buffer, bool* samples_signed, - uint32_t* max_buffer_length, uint8_t* spacing); - -#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H diff --git a/shared-module/audioio/RawSample.c b/shared-module/audioio/RawSample.c deleted file mode 100644 index 6422e346b..000000000 --- a/shared-module/audioio/RawSample.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-bindings/audioio/RawSample.h" - -#include - -#include "shared-module/audioio/RawSample.h" - -void common_hal_audioio_rawsample_construct(audioio_rawsample_obj_t* self, - uint8_t* buffer, - uint32_t len, - uint8_t bytes_per_sample, - bool samples_signed, - uint8_t channel_count, - uint32_t sample_rate) { - self->buffer = buffer; - self->bits_per_sample = bytes_per_sample * 8; - self->samples_signed = samples_signed; - self->len = len; - self->channel_count = channel_count; - self->sample_rate = sample_rate; - self->buffer_read = false; -} - -void common_hal_audioio_rawsample_deinit(audioio_rawsample_obj_t* self) { - self->buffer = NULL; -} -bool common_hal_audioio_rawsample_deinited(audioio_rawsample_obj_t* self) { - return self->buffer == NULL; -} - -uint32_t common_hal_audioio_rawsample_get_sample_rate(audioio_rawsample_obj_t* self) { - return self->sample_rate; -} -void common_hal_audioio_rawsample_set_sample_rate(audioio_rawsample_obj_t* self, - uint32_t sample_rate) { - self->sample_rate = sample_rate; -} - -void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t* self, - bool single_channel, - uint8_t channel) { -} - -audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t* self, - bool single_channel, - uint8_t channel, - uint8_t** buffer, - uint32_t* buffer_length) { - *buffer_length = self->len; - if (single_channel) { - *buffer = self->buffer + (channel % self->channel_count) * (self->bits_per_sample / 8); - } else { - *buffer = self->buffer; - } - return GET_BUFFER_DONE; -} - -void audioio_rawsample_get_buffer_structure(audioio_rawsample_obj_t* self, bool single_channel, - bool* single_buffer, bool* samples_signed, - uint32_t* max_buffer_length, uint8_t* spacing) { - *single_buffer = true; - *samples_signed = self->samples_signed; - *max_buffer_length = self->len; - if (single_channel) { - *spacing = self->channel_count; - } else { - *spacing = 1; - } -} diff --git a/shared-module/audioio/RawSample.h b/shared-module/audioio/RawSample.h deleted file mode 100644 index fe5283db4..000000000 --- a/shared-module/audioio/RawSample.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_RAWSAMPLE_H -#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_RAWSAMPLE_H - -#include "py/obj.h" - -#include "shared-module/audioio/__init__.h" - -typedef struct { - mp_obj_base_t base; - uint8_t* buffer; - uint32_t len; - uint8_t bits_per_sample; - bool samples_signed; - uint8_t channel_count; - uint32_t sample_rate; - bool buffer_read; -} audioio_rawsample_obj_t; - - -// These are not available from Python because it may be called in an interrupt. -void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t* self, - bool single_channel, - uint8_t channel); -audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t* self, - bool single_channel, - uint8_t channel, - uint8_t** buffer, - uint32_t* buffer_length); // length in bytes -void audioio_rawsample_get_buffer_structure(audioio_rawsample_obj_t* self, bool single_channel, - bool* single_buffer, bool* samples_signed, - uint32_t* max_buffer_length, uint8_t* spacing); - -#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_RAWSAMPLE_H diff --git a/shared-module/audioio/WaveFile.c b/shared-module/audioio/WaveFile.c deleted file mode 100644 index d5dd9419c..000000000 --- a/shared-module/audioio/WaveFile.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-bindings/audioio/WaveFile.h" - -#include -#include - -#include "py/mperrno.h" -#include "py/runtime.h" - -#include "shared-module/audioio/WaveFile.h" -#include "supervisor/shared/translate.h" - -struct wave_format_chunk { - uint16_t audio_format; - uint16_t num_channels; - uint32_t sample_rate; - uint32_t byte_rate; - uint16_t block_align; - uint16_t bits_per_sample; - uint16_t extra_params; // Assumed to be zero below. -}; - -void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t* self, - pyb_file_obj_t* file) { - // Load the wave - self->file = file; - uint8_t chunk_header[16]; - f_rewind(&self->file->fp); - UINT bytes_read; - if (f_read(&self->file->fp, chunk_header, 16, &bytes_read) != FR_OK) { - mp_raise_OSError(MP_EIO); - } - if (bytes_read != 16 || - memcmp(chunk_header, "RIFF", 4) != 0 || - memcmp(chunk_header + 8, "WAVEfmt ", 8) != 0) { - mp_raise_ValueError(translate("Invalid wave file")); - } - uint32_t format_size; - if (f_read(&self->file->fp, &format_size, 4, &bytes_read) != FR_OK) { - mp_raise_OSError(MP_EIO); - } - if (bytes_read != 4 || - format_size > sizeof(struct wave_format_chunk)) { - mp_raise_ValueError(translate("Invalid format chunk size")); - } - struct wave_format_chunk format; - if (f_read(&self->file->fp, &format, format_size, &bytes_read) != FR_OK) { - mp_raise_OSError(MP_EIO); - } - if (bytes_read != format_size) { - } - - if (format.audio_format != 1 || - format.num_channels > 2 || - format.bits_per_sample > 16 || - (format_size == 18 && - format.extra_params != 0)) { - mp_raise_ValueError(translate("Unsupported format")); - } - // Get the sample_rate - self->sample_rate = format.sample_rate; - self->len = 256; - self->channel_count = format.num_channels; - self->bits_per_sample = format.bits_per_sample; - - // TODO(tannewt): Skip any extra chunks that occur before the data section. - - uint8_t data_tag[4]; - if (f_read(&self->file->fp, &data_tag, 4, &bytes_read) != FR_OK) { - mp_raise_OSError(MP_EIO); - } - if (bytes_read != 4 || - memcmp((uint8_t *) data_tag, "data", 4) != 0) { - mp_raise_ValueError(translate("Data chunk must follow fmt chunk")); - } - - uint32_t data_length; - if (f_read(&self->file->fp, &data_length, 4, &bytes_read) != FR_OK) { - mp_raise_OSError(MP_EIO); - } - if (bytes_read != 4) { - mp_raise_ValueError(translate("Invalid file")); - } - self->file_length = data_length; - self->data_start = self->file->fp.fptr; - - // Try to allocate two buffers, one will be loaded from file and the other - // DMAed to DAC. - self->buffer = m_malloc(self->len, false); - if (self->buffer == NULL) { - common_hal_audioio_wavefile_deinit(self); - mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate first buffer")); - } - - self->second_buffer = m_malloc(self->len, false); - if (self->second_buffer == NULL) { - common_hal_audioio_wavefile_deinit(self); - mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate second buffer")); - } -} - -void common_hal_audioio_wavefile_deinit(audioio_wavefile_obj_t* self) { - self->buffer = NULL; -} - -bool common_hal_audioio_wavefile_deinited(audioio_wavefile_obj_t* self) { - return self->buffer == NULL; -} - -uint32_t common_hal_audioio_wavefile_get_sample_rate(audioio_wavefile_obj_t* self) { - return self->sample_rate; -} - -void common_hal_audioio_wavefile_set_sample_rate(audioio_wavefile_obj_t* self, - uint32_t sample_rate) { - self->sample_rate = sample_rate; -} - -uint8_t common_hal_audioio_wavefile_get_bits_per_sample(audioio_wavefile_obj_t* self) { - return self->bits_per_sample; -} - -uint8_t common_hal_audioio_wavefile_get_channel_count(audioio_wavefile_obj_t* self) { - return self->channel_count; -} - -bool audioio_wavefile_samples_signed(audioio_wavefile_obj_t* self) { - return self->bits_per_sample > 8; -} - -uint32_t audioio_wavefile_max_buffer_length(audioio_wavefile_obj_t* self) { - return 512; -} - -void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t* self, - bool single_channel, - uint8_t channel) { - if (single_channel && channel == 1) { - return; - } - // We don't reset the buffer index in case we're looping and we have an odd number of buffer - // loads - self->bytes_remaining = self->file_length; - f_lseek(&self->file->fp, self->data_start); - self->read_count = 0; - self->left_read_count = 0; - self->right_read_count = 0; -} - -audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t* self, - bool single_channel, - uint8_t channel, - uint8_t** buffer, - uint32_t* buffer_length) { - if (!single_channel) { - channel = 0; - } - - uint32_t channel_read_count = self->left_read_count; - if (channel == 1) { - channel_read_count = self->right_read_count; - } - - bool need_more_data = self->read_count == channel_read_count; - - if (self->bytes_remaining == 0 && need_more_data) { - *buffer = NULL; - *buffer_length = 0; - return GET_BUFFER_DONE; - } - - if (need_more_data) { - uint16_t num_bytes_to_load = self->len; - if (num_bytes_to_load > self->bytes_remaining) { - num_bytes_to_load = self->bytes_remaining; - } - UINT length_read; - if (self->buffer_index % 2 == 1) { - *buffer = self->second_buffer; - } else { - *buffer = self->buffer; - } - if (f_read(&self->file->fp, *buffer, num_bytes_to_load, &length_read) != FR_OK) { - return GET_BUFFER_ERROR; - } - self->bytes_remaining -= length_read; - // Pad the last buffer to word align it. - if (self->bytes_remaining == 0 && length_read % sizeof(uint32_t) != 0) { - uint32_t pad = length_read % sizeof(uint32_t); - length_read += pad; - if (self->bits_per_sample == 8) { - for (uint32_t i = 0; i < pad; i++) { - ((uint8_t*) (*buffer))[length_read / sizeof(uint8_t) - i - 1] = 0x80; - } - } else if (self->bits_per_sample == 16) { - // We know the buffer is aligned because we allocated it onto the heap ourselves. - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wcast-align" - ((int16_t*) (*buffer))[length_read / sizeof(int16_t) - 1] = 0; - #pragma GCC diagnostic pop - } - } - *buffer_length = length_read; - if (self->buffer_index % 2 == 1) { - self->second_buffer_length = length_read; - } else { - self->buffer_length = length_read; - } - self->buffer_index += 1; - self->read_count += 1; - } - - uint32_t buffers_back = self->read_count - 1 - channel_read_count; - if ((self->buffer_index - buffers_back) % 2 == 0) { - *buffer = self->second_buffer; - *buffer_length = self->second_buffer_length; - } else { - *buffer = self->buffer; - *buffer_length = self->buffer_length; - } - - if (channel == 0) { - self->left_read_count += 1; - } else if (channel == 1) { - self->right_read_count += 1; - *buffer = *buffer + self->bits_per_sample / 8; - } - - return self->bytes_remaining == 0 ? GET_BUFFER_DONE : GET_BUFFER_MORE_DATA; -} - -void audioio_wavefile_get_buffer_structure(audioio_wavefile_obj_t* self, bool single_channel, - bool* single_buffer, bool* samples_signed, - uint32_t* max_buffer_length, uint8_t* spacing) { - *single_buffer = false; - *samples_signed = self->bits_per_sample > 8; - *max_buffer_length = 512; - if (single_channel) { - *spacing = self->channel_count; - } else { - *spacing = 1; - } -} diff --git a/shared-module/audioio/WaveFile.h b/shared-module/audioio/WaveFile.h deleted file mode 100644 index 2cee2b1d2..000000000 --- a/shared-module/audioio/WaveFile.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_WAVEFILE_H -#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_WAVEFILE_H - -#include "py/obj.h" - -#include "shared-module/audioio/__init__.h" - -typedef struct { - mp_obj_base_t base; - uint8_t* buffer; - uint32_t buffer_length; - uint8_t* second_buffer; - uint32_t second_buffer_length; - uint32_t file_length; // In bytes - uint16_t data_start; // Where the data values start - uint8_t bits_per_sample; - uint16_t buffer_index; - uint32_t bytes_remaining; - - uint8_t channel_count; - uint32_t sample_rate; - - uint32_t len; - pyb_file_obj_t* file; - - uint32_t read_count; - uint32_t left_read_count; - uint32_t right_read_count; -} audioio_wavefile_obj_t; - -// These are not available from Python because it may be called in an interrupt. -void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t* self, - bool single_channel, - uint8_t channel); -audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t* self, - bool single_channel, - uint8_t channel, - uint8_t** buffer, - uint32_t* buffer_length); // length in bytes -void audioio_wavefile_get_buffer_structure(audioio_wavefile_obj_t* self, bool single_channel, - bool* single_buffer, bool* samples_signed, - uint32_t* max_buffer_length, uint8_t* spacing); - -#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_WAVEFILE_H diff --git a/shared-module/audioio/__init__.c b/shared-module/audioio/__init__.c index b87b06a83..e69de29bb 100644 --- a/shared-module/audioio/__init__.c +++ b/shared-module/audioio/__init__.c @@ -1,125 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "shared-module/audioio/__init__.h" - -#include "py/obj.h" -#include "shared-bindings/audioio/Mixer.h" -#include "shared-bindings/audioio/RawSample.h" -#include "shared-bindings/audioio/WaveFile.h" -#include "shared-module/audioio/Mixer.h" -#include "shared-module/audioio/RawSample.h" -#include "shared-module/audioio/WaveFile.h" - -uint32_t audiosample_sample_rate(mp_obj_t sample_obj) { - if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { - audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); - return sample->sample_rate; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { - audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - return file->sample_rate; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); - return mixer->sample_rate; - } - return 16000; -} - -uint8_t audiosample_bits_per_sample(mp_obj_t sample_obj) { - if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { - audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); - return sample->bits_per_sample; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { - audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - return file->bits_per_sample; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); - return mixer->bits_per_sample; - } - return 8; -} - -uint8_t audiosample_channel_count(mp_obj_t sample_obj) { - if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { - audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); - return sample->channel_count; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { - audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - return file->channel_count; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); - return mixer->channel_count; - } - return 1; -} - -void audiosample_reset_buffer(mp_obj_t sample_obj, bool single_channel, uint8_t audio_channel) { - if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { - audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); - audioio_rawsample_reset_buffer(sample, single_channel, audio_channel); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { - audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - audioio_wavefile_reset_buffer(file, single_channel, audio_channel); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - audioio_mixer_reset_buffer(file, single_channel, audio_channel); - } -} - -audioio_get_buffer_result_t audiosample_get_buffer(mp_obj_t sample_obj, - bool single_channel, - uint8_t channel, - uint8_t** buffer, uint32_t* buffer_length) { - if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { - audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); - return audioio_rawsample_get_buffer(sample, single_channel, channel, buffer, buffer_length); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { - audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - return audioio_wavefile_get_buffer(file, single_channel, channel, buffer, buffer_length); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - return audioio_mixer_get_buffer(file, single_channel, channel, buffer, buffer_length); - } - return GET_BUFFER_DONE; -} - -void audiosample_get_buffer_structure(mp_obj_t sample_obj, bool single_channel, - bool* single_buffer, bool* samples_signed, - uint32_t* max_buffer_length, uint8_t* spacing) { - if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { - audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); - audioio_rawsample_get_buffer_structure(sample, single_channel, single_buffer, - samples_signed, max_buffer_length, spacing); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { - audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - audioio_wavefile_get_buffer_structure(file, single_channel, single_buffer, samples_signed, - max_buffer_length, spacing); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - audioio_mixer_get_buffer_structure(file, single_channel, single_buffer, samples_signed, - max_buffer_length, spacing); - } -} diff --git a/shared-module/audioio/__init__.h b/shared-module/audioio/__init__.h index c805f3116..53b2d4a16 100644 --- a/shared-module/audioio/__init__.h +++ b/shared-module/audioio/__init__.h @@ -27,27 +27,6 @@ #ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO__INIT__H #define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO__INIT__H -#include -#include - -#include "py/obj.h" - -typedef enum { - GET_BUFFER_DONE, // No more data to read - GET_BUFFER_MORE_DATA, // More data to read. - GET_BUFFER_ERROR, // Error while reading data. -} audioio_get_buffer_result_t; - -uint32_t audiosample_sample_rate(mp_obj_t sample_obj); -uint8_t audiosample_bits_per_sample(mp_obj_t sample_obj); -uint8_t audiosample_channel_count(mp_obj_t sample_obj); -void audiosample_reset_buffer(mp_obj_t sample_obj, bool single_channel, uint8_t audio_channel); -audioio_get_buffer_result_t audiosample_get_buffer(mp_obj_t sample_obj, - bool single_channel, - uint8_t channel, - uint8_t** buffer, uint32_t* buffer_length); -void audiosample_get_buffer_structure(mp_obj_t sample_obj, bool single_channel, - bool* single_buffer, bool* samples_signed, - uint32_t* max_buffer_length, uint8_t* spacing); +#include "shared-module/audiocore/__init__.h" #endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO__INIT__H -- cgit v1.2.3 From 485f06e36f0cd3cb0cbdb7861251b7a5a6a3e340 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 25 Jul 2019 11:58:27 -0700 Subject: Remove unneeded headers --- shared-bindings/audioio/__init__.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/audioio/__init__.c b/shared-bindings/audioio/__init__.c index 837b66255..3fecf2708 100644 --- a/shared-bindings/audioio/__init__.c +++ b/shared-bindings/audioio/__init__.c @@ -32,11 +32,6 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audioio/__init__.h" #include "shared-bindings/audioio/AudioOut.h" -#include "shared-bindings/audiocore/__init__.h" -#include "shared-bindings/audioio/AudioOut.h" -#include "shared-bindings/audiocore/Mixer.h" -#include "shared-bindings/audiocore/RawSample.h" -#include "shared-bindings/audiocore/WaveFile.h" //| :mod:`audioio` --- Support for audio input and output //| ====================================================== -- cgit v1.2.3 From af8cfbedfb921bfead84a4fab08f5bf9f86274e5 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 24 Jul 2019 13:25:34 -0700 Subject: Add knobs for SSD1322 and two fixes. * Fix terminal clear after first successful code.py run. * Fix transmitting too many bytes for column constraint with single byte bounds. --- shared-bindings/displayio/Display.c | 16 +++++++++---- shared-bindings/displayio/Display.h | 5 ++-- shared-module/displayio/Display.c | 27 ++++++++++++++------- shared-module/displayio/Palette.h | 2 ++ shared-module/displayio/TileGrid.c | 6 ++++- shared-module/displayio/__init__.c | 48 ++++++++++++++++++------------------- supervisor/shared/display.c | 3 ++- 7 files changed, 66 insertions(+), 41 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 361a37ece..9cb4d6e74 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -51,7 +51,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness_command=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, bytes_per_cell=1, reverse_pixels_in_byte=False, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness_command=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -90,6 +90,8 @@ //| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.) //| :param bool grayscale: True if the display only shows a single color. //| :param bool pixels_in_byte_share_row: True when pixels are less than a byte and a byte includes pixels from the same row of the display. When False, pixels share a column. +//| :param int bytes_per_cell: Number of bytes per addressable memory location when color_depth < 8. When greater than one, bytes share a row or column according to pixels_in_byte_share_row. +//| :param bool reverse_pixels_in_byte: Reverses the pixel order within each byte when color_depth < 8. Does not apply across multiple bytes even if there is more than one byte per cell (bytes_per_cell.) //| :param int set_column_command: Command used to set the start and end columns to update //| :param int set_row_command: Command used so set the start and end rows to update //| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set. @@ -102,7 +104,7 @@ //| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this. //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -114,6 +116,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, { MP_QSTR_grayscale, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_pixels_in_byte_share_row, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, + { MP_QSTR_bytes_per_cell, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} }, + { MP_QSTR_reverse_pixels_in_byte, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_set_column_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2a} }, { MP_QSTR_set_row_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2b} }, { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, @@ -163,7 +167,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a common_hal_displayio_display_construct( self, display_bus, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation, - args[ARG_color_depth].u_int, args[ARG_grayscale].u_bool, args[ARG_pixels_in_byte_share_row].u_bool, + args[ARG_color_depth].u_int, args[ARG_grayscale].u_bool, + args[ARG_pixels_in_byte_share_row].u_bool, args[ARG_bytes_per_cell].u_bool, args[ARG_reverse_pixels_in_byte].u_bool, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, args[ARG_write_ram_command].u_int, args[ARG_set_vertical_scroll].u_int, @@ -199,7 +204,10 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) group = MP_OBJ_TO_PTR(native_group(group_in)); } - common_hal_displayio_display_show(self, group); + bool ok = common_hal_displayio_display_show(self, group); + if (!ok) { + mp_raise_ValueError(translate("Group already used")); + } return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show); diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index e765e6f25..a8938bbcd 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -40,7 +40,8 @@ extern const mp_obj_type_t displayio_display_type; void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, - int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, + int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, bool grayscale, + bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, @@ -48,7 +49,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self); -void common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group); +bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group); void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index a8515b9e5..51c6f292a 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, - uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, + uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, @@ -52,6 +52,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->colorspace.depth = color_depth; self->colorspace.grayscale = grayscale; self->colorspace.pixels_in_byte_share_row = pixels_in_byte_share_row; + self->colorspace.bytes_per_cell = bytes_per_cell; + self->colorspace.reverse_pixels_in_byte = reverse_pixels_in_byte; self->set_column_command = set_column_command; self->set_row_command = set_row_command; self->write_ram_command = write_ram_command; @@ -195,17 +197,25 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, common_hal_displayio_display_show(self, &circuitpython_splash); } -void common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) { +bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) { if (root_group == NULL) { root_group = &circuitpython_splash; } if (root_group == self->current_group) { - return; + return true; + } + if (root_group->in_group) { + return false; + } + if (self->current_group != NULL) { + self->current_group->in_group = false; } displayio_group_update_transform(root_group, &self->transform); + root_group->in_group = true; self->current_group = root_group; self->full_refresh = true; common_hal_displayio_display_refresh_soon(self); + return true; } void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self) { @@ -299,11 +309,11 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, displ if (self->colorspace.depth < 8) { uint8_t pixels_per_byte = 8 / self->colorspace.depth; if (self->colorspace.pixels_in_byte_share_row) { - x1 /= pixels_per_byte; - x2 /= pixels_per_byte; + x1 /= pixels_per_byte * self->colorspace.bytes_per_cell; + x2 /= pixels_per_byte * self->colorspace.bytes_per_cell; } else { - y1 /= pixels_per_byte; - y2 /= pixels_per_byte; + y1 /= pixels_per_byte * self->colorspace.bytes_per_cell; + y2 /= pixels_per_byte * self->colorspace.bytes_per_cell; } } @@ -318,7 +328,6 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, displ if (self->single_byte_bounds) { data[data_length++] = x1 + self->colstart; data[data_length++] = x2 - 1 + self->colstart; - data_length += 2; } else { x1 += self->colstart; x2 += self->colstart - 1; @@ -413,7 +422,7 @@ bool displayio_display_clip_area(displayio_display_obj_t *self, const displayio_ // Expand the area if we have multiple pixels per byte and we need to byte // align the bounds. if (self->colorspace.depth < 8) { - uint8_t pixels_per_byte = 8 / self->colorspace.depth; + uint8_t pixels_per_byte = 8 / self->colorspace.depth * self->colorspace.bytes_per_cell; if (self->colorspace.pixels_in_byte_share_row) { if (clipped->x1 % pixels_per_byte != 0) { clipped->x1 -= clipped->x1 % pixels_per_byte; diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h index 19c05baf5..a917e2432 100644 --- a/shared-module/displayio/Palette.h +++ b/shared-module/displayio/Palette.h @@ -36,6 +36,8 @@ typedef struct { uint8_t depth; bool grayscale; bool pixels_in_byte_share_row; + uint8_t bytes_per_cell; + bool reverse_pixels_in_byte; uint8_t hue; } _displayio_colorspace_t; diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 88873d3a9..fee2ae978 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -436,7 +436,11 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c // asm("bkpt"); // } } - ((uint8_t*)buffer)[offset / pixels_per_byte] |= pixel << ((offset % pixels_per_byte) * colorspace->depth); + uint8_t shift = (offset % pixels_per_byte) * colorspace->depth; + if (colorspace->reverse_pixels_in_byte) { + shift = (pixels_per_byte - 1) * colorspace->depth - shift; + } + ((uint8_t*)buffer)[offset / pixels_per_byte] |= pixel << shift; } } } diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 97060aaeb..8f6e650a1 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -209,35 +209,35 @@ void reset_displays(void) { } } } else if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type) { - displayio_i2cdisplay_obj_t* i2c = &displays[i].i2cdisplay_bus; - if (((uint32_t) i2c->bus) < ((uint32_t) &displays) || - ((uint32_t) i2c->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { - busio_i2c_obj_t* original_i2c = i2c->bus; - #if BOARD_I2C - // We don't need to move original_i2c if it is the board.SPI object because it is - // statically allocated already. (Doing so would also make it impossible to reference in - // a subsequent VM run.) - if (original_i2c == common_hal_board_get_i2c()) { - continue; - } - #endif - memcpy(&i2c->inline_bus, original_i2c, sizeof(busio_i2c_obj_t)); - i2c->bus = &i2c->inline_bus; - // Check for other displays that use the same i2c bus and swap them too. - for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { - if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type && - displays[i].i2cdisplay_bus.bus == original_i2c) { - displays[i].i2cdisplay_bus.bus = &i2c->inline_bus; - } + displayio_i2cdisplay_obj_t* i2c = &displays[i].i2cdisplay_bus; + if (((uint32_t) i2c->bus) < ((uint32_t) &displays) || + ((uint32_t) i2c->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { + busio_i2c_obj_t* original_i2c = i2c->bus; + #if BOARD_I2C + // We don't need to move original_i2c if it is the board.SPI object because it is + // statically allocated already. (Doing so would also make it impossible to reference in + // a subsequent VM run.) + if (original_i2c == common_hal_board_get_i2c()) { + continue; + } + #endif + memcpy(&i2c->inline_bus, original_i2c, sizeof(busio_i2c_obj_t)); + i2c->bus = &i2c->inline_bus; + // Check for other displays that use the same i2c bus and swap them too. + for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { + if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type && + displays[i].i2cdisplay_bus.bus == original_i2c) { + displays[i].i2cdisplay_bus.bus = &i2c->inline_bus; } } } - } - - for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - if (displays[i].display.base.type == NULL) { + } else { + // Not an active display. continue; } + + // Reset the displayed group. Only the first will get the terminal but + // that's ok. displayio_display_obj_t* display = &displays[i].display; display->auto_brightness = true; common_hal_displayio_display_show(display, &circuitpython_splash); diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 6a39cbe8e..fd51e2c07 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -229,5 +229,6 @@ displayio_group_t circuitpython_splash = { .size = 2, .max_size = 2, .children = splash_children, - .item_removed = false + .item_removed = false, + .in_group = false }; -- cgit v1.2.3 From c6ac0ba68338775275112839978616106792ec3c Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 27 Jul 2019 10:03:18 -0500 Subject: move the support matrix to its own page; add linking for modules --- docs/rstjinja.py | 2 +- shared-bindings/index.rst | 13 +------------ shared-bindings/support_matrix.rst | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 shared-bindings/support_matrix.rst (limited to 'shared-bindings') diff --git a/docs/rstjinja.py b/docs/rstjinja.py index a92f2280c..3a08b2599 100644 --- a/docs/rstjinja.py +++ b/docs/rstjinja.py @@ -10,7 +10,7 @@ def rstjinja(app, docname, source): return # we only want our one jinja template to run through this func - if "shared-bindings/index" not in docname: + if "shared-bindings/support_matrix" not in docname: return src = source[0] diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index f32745bc7..9eef42aeb 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -14,18 +14,7 @@ Modules :glob: :maxdepth: 3 + support_matrix */__init__ help - .. _module-support-matrix: - -Support Matrix ---------------- - -================= ============================== -Module Not Available On -================= ============================== -{%- for key, value in support_matrix|dictsort %} -{{ value.name.ljust(18) }} {{ value.excluded|join(", ") }}{{ '\n'|e }} -{%- endfor %} -================= ============================== diff --git a/shared-bindings/support_matrix.rst b/shared-bindings/support_matrix.rst new file mode 100644 index 000000000..0b40ec996 --- /dev/null +++ b/shared-bindings/support_matrix.rst @@ -0,0 +1,14 @@ +Support Matrix +=============== + +The following table lists the available built-in modules for each CircuitPython +capable board. + +.. csv-table:: + :header-rows: 1 + :widths: 7, 50 + + "Board", "Modules Available" + {% for key, value in support_matrix|dictsort -%} + "{{ key }}", "{{ '`' ~ value|join("`, `") ~ '`' }}" + {% endfor -%} -- cgit v1.2.3 From c335f170d7d561d07ca7412da60c260e13c5e746 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 27 Jul 2019 10:36:08 -0500 Subject: update 'Core Modules' description --- shared-bindings/index.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'shared-bindings') diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index 9eef42aeb..e4fccb458 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -1,11 +1,11 @@ Core Modules ======================================== -These core modules are intended on being consistent across ports. Currently -they are only implemented in the SAMD21 and ESP8266 ports. A module may not exist -in a port if no underlying hardware support is present or if flash space is -limited. For example, a microcontroller without analog features will not have -`analogio`. +These core modules are intended on being consistent across ports and boards. +A module may not exist on a port/board if no underlying hardware support is +present or if flash space is limited. For example, a microcontroller without +analog features will not have `analogio`. See the `support_matrix` page for +a list of modules supported on each board. Modules --------- -- cgit v1.2.3 From a2bab9f1724cd869495835cda20b18d2e24f150b Mon Sep 17 00:00:00 2001 From: Seth Itow <11025699+sethitow@users.noreply.github.com> Date: Sat, 27 Jul 2019 12:58:28 -0700 Subject: bleio: Fix typo in Peripheral example code. --- shared-bindings/bleio/Peripheral.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 1302c9652..570896d27 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -72,7 +72,7 @@ static const char default_name[] = "CIRCUITPY"; //| serv = bleio.Service(bleio.UUID(0x180f), [chara]) //| //| # Create a peripheral and start it up. -//| periph = bleio.Peripheral([service]) +//| periph = bleio.Peripheral([serv]) //| adv = ServerAdvertisement(periph) //| periph.start_advertising(adv.advertising_data_bytes, adv.scan_response_bytes) //| -- cgit v1.2.3 From bbc5255f046480fb2370bd6c2dd309c862478af7 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 28 Jul 2019 21:25:43 -0500 Subject: update rST ref link for support matrix --- shared-bindings/index.rst | 1 - shared-bindings/support_matrix.rst | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'shared-bindings') diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index e4fccb458..cbffdb614 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -17,4 +17,3 @@ Modules support_matrix */__init__ help -.. _module-support-matrix: diff --git a/shared-bindings/support_matrix.rst b/shared-bindings/support_matrix.rst index 0b40ec996..124f3a810 100644 --- a/shared-bindings/support_matrix.rst +++ b/shared-bindings/support_matrix.rst @@ -1,3 +1,5 @@ +.. _module-support-matrix: + Support Matrix =============== -- cgit v1.2.3