diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-04-16 10:32:38 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-16 10:32:38 -0700 |
| commit | f58446e937ede4735a7ecb0852f2d2739f147cdd (patch) | |
| tree | 72185232547d424dfe0b61fb7f98ce11378d1e6d /shared-bindings | |
| parent | 2d303213ed4ee058c0fc4c541dd7a7181f59d50f (diff) | |
| parent | 7822d013cd6d379c777f95c73a803b749d1bebe4 (diff) | |
Merge branch 'master' into master
Diffstat (limited to 'shared-bindings')
| -rw-r--r-- | shared-bindings/_stage/__init__.c | 23 | ||||
| -rw-r--r-- | shared-bindings/bleio/CharacteristicBuffer.c | 2 | ||||
| -rw-r--r-- | shared-bindings/board/__init__.c | 76 | ||||
| -rw-r--r-- | shared-bindings/board/__init__.h | 12 | ||||
| -rw-r--r-- | shared-bindings/busio/SPI.h | 6 | ||||
| -rw-r--r-- | shared-bindings/busio/UART.c | 2 | ||||
| -rw-r--r-- | shared-bindings/digitalio/DigitalInOut.h | 1 | ||||
| -rw-r--r-- | shared-bindings/displayio/Bitmap.c | 16 | ||||
| -rw-r--r-- | shared-bindings/displayio/Display.c | 56 | ||||
| -rw-r--r-- | shared-bindings/displayio/Display.h | 3 | ||||
| -rw-r--r-- | shared-bindings/displayio/FourWire.h | 1 | ||||
| -rw-r--r-- | shared-bindings/displayio/TileGrid.c | 16 | ||||
| -rw-r--r-- | shared-bindings/rtc/RTC.c | 16 | ||||
| -rw-r--r-- | shared-bindings/socket/__init__.c | 53 |
14 files changed, 228 insertions, 55 deletions
diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 24a359664..dc9dbef65 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/Display.h" #include "shared-module/_stage/__init__.h" #include "Layer.h" #include "Text.h" @@ -49,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. //| @@ -59,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. @@ -85,12 +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 - busio_spi_obj_t *spi = MP_OBJ_TO_PTR(args[6]); + if (!MP_OBJ_IS_TYPE(args[6], &displayio_display_type)) { + mp_raise_TypeError(translate("argument num/types mismatch")); + } + displayio_display_obj_t *display = MP_OBJ_TO_PTR(args[6]); - if (!render_stage(x0, y0, x1, y1, layers, layers_size, - buffer, buffer_size, spi)) { - mp_raise_OSError(MP_EIO); + while (!displayio_display_begin_transaction(display)) { +#ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP ; +#endif } + 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-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) { diff --git a/shared-bindings/board/__init__.c b/shared-bindings/board/__init__.c index 06c2f218f..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" @@ -37,6 +38,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/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-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. 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-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); } diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 1f46330e8..17f275bc0 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, single_byte_bounds=False, data_as_commands=False) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -91,9 +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 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 }; + 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 }, @@ -108,6 +110,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_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); @@ -146,18 +150,26 @@ 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_single_byte_bounds].u_bool, + args[ARG_data_as_commands].u_bool); 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); @@ -177,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; } @@ -189,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); @@ -201,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")); @@ -211,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")); @@ -232,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)); @@ -259,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); @@ -277,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); @@ -289,6 +301,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 = native_display(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) }, @@ -299,6 +330,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); diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 7d6444a2d..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); + 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-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-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index a45feaec4..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); } @@ -259,9 +264,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) { diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index 474d4a399..17dccdb03 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -36,22 +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 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) }, |
