Merge remote-tracking branch 'circuitpython/main' into thunderpack1.2

This commit is contained in:
jgillick 2020-11-23 22:40:47 -08:00
commit 570353b946
50 changed files with 937 additions and 271 deletions

View File

@ -198,6 +198,7 @@ jobs:
- "circuitplayground_express_displayio"
- "clue_nrf52840_express"
- "cp32-m4"
- "cp_sapling_m0"
- "datalore_ip_m4"
- "datum_distance"
- "datum_imu"

View File

@ -21,7 +21,7 @@
STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) {
uintptr_t addr = mp_obj_int_get_truncated(addr_o);
if ((addr & (align - 1)) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, translate("address %08x is not aligned to %d bytes"), addr, align));
mp_raise_ValueError_varg(translate("address %08x is not aligned to %d bytes"), addr, align);
}
return addr;
}

View File

@ -62,7 +62,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_uheapq_heappush_obj, mod_uheapq_heappush);
STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) {
mp_obj_list_t *heap = get_heap(heap_in);
if (heap->len == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, translate("empty heap")));
mp_raise_IndexError(translate("empty heap"));
}
mp_obj_t item = heap->items[0];
heap->len -= 1;

View File

@ -43,7 +43,7 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t no = mp_obj_get_int(no_in);
if (no < 0 || no >= self->num_matches) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, no_in));
mp_raise_arg1(&mp_type_IndexError, no_in);
}
const char *start = self->caps[no * 2];
@ -82,7 +82,7 @@ STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span
if (n_args == 2) {
no = mp_obj_get_int(args[1]);
if (no < 0 || no >= self->num_matches) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, args[1]));
mp_raise_arg1(&mp_type_IndexError, args[1]);
}
}
@ -326,7 +326,7 @@ STATIC mp_obj_t re_sub_helper(mp_obj_t self_in, size_t n_args, const mp_obj_t *a
}
if (match_no >= (unsigned int)match->num_matches) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, MP_OBJ_NEW_SMALL_INT(match_no)));
mp_raise_arg1(&mp_type_IndexError, MP_OBJ_NEW_SMALL_INT(match_no));
}
const char *start_match = match->caps[match_no * 2];

View File

@ -179,7 +179,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
return res;
error:
nlr_raise(mp_obj_new_exception_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st)));
mp_raise_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress);

@ -1 +1 @@
Subproject commit 8242b84753355433b61230ab6631c06e5ac77f35
Subproject commit aa7e741530df471d206a4a321823a37a913a0eb8

View File

@ -24,7 +24,7 @@ typedef struct _mp_obj_vfs_posix_file_t {
#ifdef MICROPY_CPYTHON_COMPAT
STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) {
if (o->fd < 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, translate("I/O operation on closed file")));
mp_raise_ValueError(translate("I/O operation on closed file"));
}
}
#else

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-11-10 15:30+0530\n"
"POT-Creation-Date: 2020-11-23 10:10-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -855,6 +855,10 @@ msgstr ""
msgid "FFT is defined for ndarrays only"
msgstr ""
#: extmod/ulab/code/fft/fft.c
msgid "FFT is implemented for linear arrays only"
msgstr ""
#: ports/esp32s2/common-hal/socketpool/Socket.c
msgid "Failed SSL handshake"
msgstr ""
@ -1951,7 +1955,7 @@ msgstr ""
msgid "WARNING: Your code filename has two extensions\n"
msgstr ""
#: shared-bindings/watchdog/WatchDogTimer.c
#: ports/nrf/common-hal/watchdog/WatchDogTimer.c
msgid "WatchDogTimer cannot be deinitialized once mode is set to RESET"
msgstr ""
@ -2030,10 +2034,6 @@ msgstr ""
msgid "addresses is empty"
msgstr ""
#: extmod/ulab/code/vector/vectorise.c
msgid "arctan2 is implemented for scalars and ndarrays only"
msgstr ""
#: py/modbuiltins.c
msgid "arg is an empty sequence"
msgstr ""
@ -2042,6 +2042,10 @@ msgstr ""
msgid "argsort argument must be an ndarray"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "argsort is not implemented for flattened arrays"
msgstr ""
#: py/runtime.c
msgid "argument has wrong type"
msgstr ""
@ -2059,14 +2063,22 @@ msgstr ""
msgid "argument should be a '%q' not a '%q'"
msgstr ""
#: extmod/ulab/code/linalg/linalg.c
#: extmod/ulab/code/linalg/linalg.c extmod/ulab/code/numerical/numerical.c
msgid "arguments must be ndarrays"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "array and index length must be equal"
msgstr ""
#: py/objarray.c shared-bindings/nvm/ByteArray.c
msgid "array/bytes required on right side"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "attempt to get (arg)min/(arg)max of empty sequence"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "attempt to get argmin/argmax of an empty sequence"
msgstr ""
@ -2076,15 +2088,15 @@ msgid "attributes not supported yet"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "axis must be -1, 0, None, or 1"
msgid "axis is out of bounds"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "axis must be -1, 0, or 1"
msgid "axis must be None, or an integer"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "axis must be None, 0, or 1"
msgid "axis too long"
msgstr ""
#: py/builtinevex.c
@ -2288,6 +2300,10 @@ msgid ""
"can't switch from manual field specification to automatic field numbering"
msgstr ""
#: extmod/ulab/code/ndarray_operators.c
msgid "cannot cast output with casting rule"
msgstr ""
#: py/objtype.c
msgid "cannot create '%q' instances"
msgstr ""
@ -2304,10 +2320,6 @@ msgstr ""
msgid "cannot perform relative import"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "cannot reshape array (incompatible input/output shape)"
msgstr ""
#: py/emitnative.c
msgid "casting"
msgstr ""
@ -2380,10 +2392,6 @@ msgstr ""
msgid "convolve arguments must not be empty"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "could not broadast input array from shape"
msgstr ""
#: extmod/ulab/code/poly/poly.c
msgid "could not invert Vandermonde matrix"
msgstr ""
@ -2392,6 +2400,10 @@ msgstr ""
msgid "couldn't determine SD card version"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "cross is defined for 1D arrays of length 3"
msgstr ""
#: extmod/ulab/code/approx/approx.c
msgid "data must be iterable"
msgstr ""
@ -2400,10 +2412,6 @@ msgstr ""
msgid "data must be of equal length"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "ddof must be smaller than length of data set"
msgstr ""
#: py/parsenum.c
msgid "decimal numbers not supported"
msgstr ""
@ -2433,6 +2441,10 @@ msgstr ""
msgid "diff argument must be an ndarray"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "differentiation order out of range"
msgstr ""
#: py/modmath.c py/objfloat.c py/objint_longlong.c py/objint_mpz.c py/runtime.c
#: shared-bindings/math/__init__.c
msgid "division by zero"
@ -2548,6 +2560,10 @@ msgstr ""
msgid "first argument must be a function"
msgstr ""
#: extmod/ulab/code/ulab_create.c
msgid "first argument must be a tuple of ndarrays"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "first argument must be an iterable"
msgstr ""
@ -2601,8 +2617,8 @@ msgstr ""
msgid "function has the same sign at the ends of interval"
msgstr ""
#: extmod/ulab/code/compare/compare.c
msgid "function is implemented for scalars and ndarrays only"
#: extmod/ulab/code/ndarray.c
msgid "function is defined for ndarrays only"
msgstr ""
#: py/argcheck.c
@ -2672,6 +2688,7 @@ msgstr ""
msgid "index is out of bounds"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
#: ports/esp32s2/common-hal/pulseio/PulseIn.c py/obj.c
msgid "index out of range"
msgstr ""
@ -2696,6 +2713,10 @@ msgstr ""
msgid "inline assembler must be a function"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "input and output shapes are not compatible"
msgstr ""
#: extmod/ulab/code/ulab_create.c
msgid "input argument must be an integer or a 2-tuple"
msgstr ""
@ -2704,6 +2725,10 @@ msgstr ""
msgid "input array length must be power of 2"
msgstr ""
#: extmod/ulab/code/ulab_create.c
msgid "input arrays are not compatible"
msgstr ""
#: extmod/ulab/code/poly/poly.c
msgid "input data must be an iterable"
msgstr ""
@ -2716,6 +2741,22 @@ msgstr ""
msgid "input matrix is singular"
msgstr ""
#: extmod/ulab/code/user/user.c
msgid "input must be a dense ndarray"
msgstr ""
#: extmod/ulab/code/ulab_create.c
msgid "input must be a tensor of rank 2"
msgstr ""
#: extmod/ulab/code/ulab_create.c extmod/ulab/code/user/user.c
msgid "input must be an ndarray"
msgstr ""
#: extmod/ulab/code/filter/filter.c
msgid "input must be one-dimensional"
msgstr ""
#: extmod/ulab/code/linalg/linalg.c
msgid "input must be square matrix"
msgstr ""
@ -2728,6 +2769,10 @@ msgstr ""
msgid "input vectors must be of equal length"
msgstr ""
#: extmod/ulab/code/poly/poly.c
msgid "inputs are not iterable"
msgstr ""
#: py/parsenum.c
msgid "int() arg 2 must be >= 2 and <= 36"
msgstr ""
@ -2896,6 +2941,10 @@ msgstr ""
msgid "max_length must be > 0"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "maximum number of dimensions is 4"
msgstr ""
#: py/runtime.c
msgid "maximum recursion depth exceeded"
msgstr ""
@ -2945,10 +2994,6 @@ msgstr ""
msgid "must use keyword argument for key function"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "n must be between 0, and 9"
msgstr ""
#: py/runtime.c
msgid "name '%q' is not defined"
msgstr ""
@ -3031,6 +3076,10 @@ msgstr ""
msgid "non-keyword arg after keyword arg"
msgstr ""
#: extmod/ulab/code/linalg/linalg.c
msgid "norm is defined for 1D and 2D arrays"
msgstr ""
#: shared-bindings/_bleio/UUID.c
msgid "not a 128-bit UUID"
msgstr ""
@ -3043,10 +3092,6 @@ msgstr ""
msgid "not enough arguments for format string"
msgstr ""
#: extmod/ulab/code/poly/poly.c
msgid "number of arguments must be 2, or 3"
msgstr ""
#: extmod/ulab/code/ulab_create.c
msgid "number of points must be at least 2"
msgstr ""
@ -3099,6 +3144,10 @@ msgstr ""
msgid "odd-length string"
msgstr ""
#: extmod/ulab/code/ulab_create.c
msgid "offset is too large"
msgstr ""
#: py/objstr.c py/objstrunicode.c
msgid "offset out of bounds"
msgstr ""
@ -3121,6 +3170,14 @@ msgstr ""
msgid "operands could not be broadcast together"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "operation is implemented for 1D Boolean arrays only"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "operation is not implemented for flattened array"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "operation is not implemented on ndarrays"
msgstr ""
@ -3255,6 +3312,10 @@ msgstr ""
msgid "requested length %d but object has length %d"
msgstr ""
#: extmod/ulab/code/ndarray_operators.c
msgid "results cannot be cast to specified type"
msgstr ""
#: py/compile.c
msgid "return annotation must be an identifier"
msgstr ""
@ -3273,8 +3334,8 @@ msgstr ""
msgid "rgb_pins[%d] is not on the same port as clock"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "right hand side must be an ndarray, or a scalar"
#: extmod/ulab/code/numerical/numerical.c
msgid "roll argument must be an ndarray"
msgstr ""
#: py/objstr.c
@ -3300,7 +3361,7 @@ msgid "script compilation not supported"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "shape must be a 2-tuple"
msgid "shape must be a tuple"
msgstr ""
#: py/objstr.c
@ -3343,10 +3404,6 @@ msgstr ""
msgid "sort argument must be an ndarray"
msgstr ""
#: extmod/ulab/code/numerical/numerical.c
msgid "sorted axis can't be longer than 65535"
msgstr ""
#: extmod/ulab/code/filter/filter.c
msgid "sos array must be of shape (n_section, 6)"
msgstr ""
@ -3452,6 +3509,10 @@ msgstr ""
msgid "timestamp out of range for platform time_t"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "tobytes can be invoked for dense arrays only"
msgstr ""
#: shared-module/struct/__init__.c
msgid "too many arguments provided with the given format"
msgstr ""
@ -3627,12 +3688,12 @@ msgstr ""
msgid "window must be <= interval"
msgstr ""
#: extmod/ulab/code/linalg/linalg.c
msgid "wrong argument type"
#: extmod/ulab/code/numerical/numerical.c
msgid "wrong axis index"
msgstr ""
#: extmod/ulab/code/ndarray.c
msgid "wrong index type"
#: extmod/ulab/code/ulab_create.c
msgid "wrong axis specified"
msgstr ""
#: extmod/ulab/code/vector/vectorise.c

View File

@ -8,8 +8,8 @@ msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-11-10 15:30+0530\n"
"PO-Revision-Date: 2020-11-15 16:28+0000\n"
"Last-Translator: Antonin ENFRUN <antonin.e@me.com>\n"
"PO-Revision-Date: 2020-11-20 22:28+0000\n"
"Last-Translator: Noel Gaetan <gaetan.noel@viacesi.fr>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
@ -1027,7 +1027,7 @@ msgstr "Taille de tampon incorrecte"
#: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c
msgid "Initialization failed due to lack of memory"
msgstr ""
msgstr "L'initialisation a échoué par manque de mémoire"
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
msgid "Input taking too long"
@ -3715,7 +3715,7 @@ msgstr "les vecteurs doivent avoir la même longueur"
#: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c
msgid "watchdog not initialized"
msgstr ""
msgstr "chien de garde non initialisé"
#: shared-bindings/watchdog/WatchDogTimer.c
msgid "watchdog timeout must be greater than 0"

View File

@ -6,7 +6,7 @@ msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-11-10 15:30+0530\n"
"PO-Revision-Date: 2020-11-15 16:28+0000\n"
"PO-Revision-Date: 2020-11-20 22:28+0000\n"
"Last-Translator: Jonny Bergdahl <jonny@bergdahl.it>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: sv\n"
@ -1014,7 +1014,7 @@ msgstr "Fel buffertstorlek"
#: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c
msgid "Initialization failed due to lack of memory"
msgstr ""
msgstr "Initieringen misslyckades på grund av minnesbrist"
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
msgid "Input taking too long"
@ -3672,7 +3672,7 @@ msgstr "vektorer måste ha samma längd"
#: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c
msgid "watchdog not initialized"
msgstr ""
msgstr "watchdog är inte initierad"
#: shared-bindings/watchdog/WatchDogTimer.c
msgid "watchdog timeout must be greater than 0"

View File

@ -0,0 +1,40 @@
/*
* 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 "boards/board.h"
#include "common-hal/microcontroller/Pin.h"
#include "supervisor/shared/board.h"
#include "hal/include/hal_gpio.h"
void board_init(void) {
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}

View File

@ -0,0 +1,57 @@
#define MICROPY_HW_BOARD_NAME "CP Sapling M0"
#define MICROPY_HW_MCU_NAME "samd21e18"
#define MICROPY_HW_NEOPIXEL (&pin_PA15)
#define MICROPY_PORT_A (0)
#define MICROPY_PORT_B (0)
#define MICROPY_PORT_C (0)
#define IGNORE_PIN_PA02 1
#define IGNORE_PIN_PA03 1
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA05 1
#define IGNORE_PIN_PA06 1
#define IGNORE_PIN_PA07 1
#define IGNORE_PIN_PA12 1
#define IGNORE_PIN_PA13 1
#define IGNORE_PIN_PA14 1
#define IGNORE_PIN_PA20 1
#define IGNORE_PIN_PA21 1
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
#define IGNORE_PIN_PA27 1
#define IGNORE_PIN_PA28 1
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1
#define IGNORE_PIN_PB01 1
#define IGNORE_PIN_PB02 1
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PB04 1
#define IGNORE_PIN_PB05 1
#define IGNORE_PIN_PB06 1
#define IGNORE_PIN_PB07 1
#define IGNORE_PIN_PB08 1
#define IGNORE_PIN_PB09 1
#define IGNORE_PIN_PB10 1
#define IGNORE_PIN_PB11 1
#define IGNORE_PIN_PB12 1
#define IGNORE_PIN_PB13 1
#define IGNORE_PIN_PB14 1
#define IGNORE_PIN_PB15 1
#define IGNORE_PIN_PB16 1
#define IGNORE_PIN_PB17 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PB30 1
#define IGNORE_PIN_PB31 1
#define IGNORE_PIN_PB00 1
#define DEFAULT_I2C_BUS_SCL (&pin_PA09)
#define DEFAULT_I2C_BUS_SDA (&pin_PA08)
#define DEFAULT_SPI_BUS_SS (&pin_PA22)
#define DEFAULT_SPI_BUS_SCK (&pin_PA19)
#define DEFAULT_SPI_BUS_MOSI (&pin_PA18)
#define DEFAULT_SPI_BUS_MISO (&pin_PA17)

View File

@ -0,0 +1,24 @@
USB_VID = 0x1209
USB_PID = 0x4DDD
USB_PRODUCT = "CP Sapling"
USB_MANUFACTURER = "Oak Development Technologies"
CHIP_VARIANT = SAMD21E18A
CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
SUPEROPT_GC = 0
CFLAGS_BOARD = --param max-inline-insns-auto=15
ifeq ($(TRANSLATION), zh_Latn_pinyin)
RELEASE_NEEDS_CLEAN_BUILD = 1
CFLAGS_INLINE_LIMIT = 35
endif
ifeq ($(TRANSLATION), de_DE)
RELEASE_NEEDS_CLEAN_BUILD = 1
CFLAGS_INLINE_LIMIT = 35
SUPEROPT_VM = 0
endif

View File

@ -0,0 +1,38 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA15) },
{ 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_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -337,7 +337,11 @@ const uint16_t sinc_filter [OVERSAMPLING] = {
94, 63, 39, 21, 9, 2, 0, 0
};
#define REPEAT_16_TIMES(X) X X X X X X X X X X X X X X X X
#ifdef SAMD21
#define REPEAT_16_TIMES(X) do { for(uint8_t j=0; j<4; j++) { X X X X } } while (0)
#else
#define REPEAT_16_TIMES(X) do { X X X X X X X X X X X X X X X X } while(0)
#endif
static uint16_t filter_sample(uint32_t pdm_samples[4]) {
uint16_t running_sum = 0;
@ -354,7 +358,7 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) {
filter_ptr++;
pdm_sample <<= 1;
}
)
);
}
return running_sum;
}

View File

@ -188,6 +188,7 @@ SRC_C += \
lib/utils/pyexec.c \
lib/utils/stdout_helpers.c \
lib/utils/sys_stdio_mphal.c \
peripherals/timer.c \
peripherals/pcnt.c \
peripherals/pins.c \
peripherals/rmt.c \

View File

@ -16,11 +16,19 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_EPD_CS), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_B), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_C), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_D), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_LIGHT), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO4) },
@ -36,6 +44,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },

View File

@ -0,0 +1,193 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 microDev
*
* 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/frequencyio/FrequencyIn.h"
#include "py/runtime.h"
static void IRAM_ATTR pcnt_overflow_handler(void *self_in) {
frequencyio_frequencyin_obj_t * self = self_in;
// reset counter
pcnt_counter_clear(self->unit);
// increase multiplier
self->multiplier++;
// reset interrupt
PCNT.int_clr.val = BIT(self->unit);
}
static void IRAM_ATTR timer_interrupt_handler(void *self_in) {
frequencyio_frequencyin_obj_t * self = self_in;
// get counter value
int16_t count;
pcnt_get_counter_value(self->unit, &count);
self->frequency = ((count / 2.0) + (self->multiplier * INT16_MAX / 4.0)) / (self->capture_period);
// reset multiplier
self->multiplier = 0;
// reset counter
pcnt_counter_clear(self->unit);
// reset interrupt
timg_dev_t *device = self->timer.group ? &(TIMERG1) : &(TIMERG0);
if (self->timer.idx) {
device->int_clr.t1 = 1;
} else {
device->int_clr.t0 = 1;
}
device->hw_timer[self->timer.idx].config.alarm_en = 1;
}
static void init_pcnt(frequencyio_frequencyin_obj_t* self) {
// Prepare configuration for the PCNT unit
const pcnt_config_t pcnt_config = {
// Set PCNT input signal and control GPIOs
.pulse_gpio_num = self->pin,
.ctrl_gpio_num = PCNT_PIN_NOT_USED,
.channel = PCNT_CHANNEL_0,
// What to do on the positive / negative edge of pulse input?
.pos_mode = PCNT_COUNT_INC, // count both rising and falling edges
.neg_mode = PCNT_COUNT_INC,
// Set counter limit
.counter_h_lim = INT16_MAX,
.counter_l_lim = 0,
};
// initialize PCNT
const int8_t unit = peripherals_pcnt_init(pcnt_config);
if (unit == -1) {
mp_raise_RuntimeError(translate("All PCNT units in use"));
}
// set the GPIO back to high-impedance, as pcnt_unit_config sets it as pull-up
gpio_set_pull_mode(self->pin, GPIO_FLOATING);
self->unit = (pcnt_unit_t)unit;
// enable pcnt interrupt
pcnt_event_enable(self->unit, PCNT_EVT_H_LIM);
pcnt_isr_register(pcnt_overflow_handler, (void *)self, ESP_INTR_FLAG_IRAM, &self->handle);
pcnt_intr_enable(self->unit);
}
static void init_timer(frequencyio_frequencyin_obj_t* self) {
// Prepare configuration for the timer module
const timer_config_t config = {
.alarm_en = true,
.counter_en = false,
.intr_type = TIMER_INTR_LEVEL,
.counter_dir = TIMER_COUNT_UP,
.auto_reload = true,
.divider = 80 // 1 us per tick
};
// initialize Timer
peripherals_timer_init(&config, &self->timer);
if (self->timer.idx == TIMER_MAX || self->timer.group == TIMER_GROUP_MAX) {
mp_raise_RuntimeError(translate("All timers in use"));
}
timer_idx_t idx = self->timer.idx;
timer_group_t group = self->timer.group;
// enable timer interrupt
timer_set_alarm_value(group, idx, self->capture_period * 1000000);
timer_isr_register(group, idx, timer_interrupt_handler, (void *)self, ESP_INTR_FLAG_IRAM, &self->handle);
timer_enable_intr(group, idx);
// start timer
timer_start(self->timer.group, self->timer.idx);
}
void common_hal_frequencyio_frequencyin_construct(frequencyio_frequencyin_obj_t* self,
const mcu_pin_obj_t* pin, const uint16_t capture_period) {
if ((capture_period == 0) || (capture_period > 500)) {
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
}
self->pin = pin->number;
self->handle = NULL;
self->multiplier = 0;
self->capture_period = capture_period;
// initialize pcnt and timer
init_pcnt(self);
init_timer(self);
claim_pin(pin);
}
bool common_hal_frequencyio_frequencyin_deinited(frequencyio_frequencyin_obj_t* self) {
return self->unit == PCNT_UNIT_MAX;
}
void common_hal_frequencyio_frequencyin_deinit(frequencyio_frequencyin_obj_t* self) {
if (common_hal_frequencyio_frequencyin_deinited(self)) {
return;
}
reset_pin_number(self->pin);
peripherals_pcnt_deinit(&self->unit);
peripherals_timer_deinit(&self->timer);
if (self->handle) {
esp_intr_free(self->handle);
self->handle = NULL;
}
}
uint32_t common_hal_frequencyio_frequencyin_get_item(frequencyio_frequencyin_obj_t* self) {
return self->frequency;
}
void common_hal_frequencyio_frequencyin_pause(frequencyio_frequencyin_obj_t* self) {
pcnt_counter_pause(self->unit);
timer_pause(self->timer.group, self->timer.idx);
}
void common_hal_frequencyio_frequencyin_resume(frequencyio_frequencyin_obj_t* self) {
pcnt_counter_resume(self->unit);
timer_start(self->timer.group, self->timer.idx);
}
void common_hal_frequencyio_frequencyin_clear(frequencyio_frequencyin_obj_t* self) {
self->frequency = 0;
pcnt_counter_clear(self->unit);
timer_set_counter_value(self->timer.group, self->timer.idx, 0);
}
uint16_t common_hal_frequencyio_frequencyin_get_capture_period(frequencyio_frequencyin_obj_t *self) {
return self->capture_period;
}
void common_hal_frequencyio_frequencyin_set_capture_period(frequencyio_frequencyin_obj_t *self, uint16_t capture_period) {
if ((capture_period == 0) || (capture_period > 500)) {
mp_raise_ValueError(translate("Invalid capture period. Valid range: 1 - 500"));
}
self->capture_period = capture_period;
common_hal_frequencyio_frequencyin_clear(self);
timer_set_alarm_value(self->timer.group, self->timer.idx, capture_period * 1000000);
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 microDev
*
* 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_ESP32S2_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H
#include "py/obj.h"
#include "peripherals/pcnt.h"
#include "peripherals/timer.h"
typedef struct {
mp_obj_base_t base;
pcnt_unit_t unit;
timer_index_t timer;
intr_handle_t handle;
uint8_t pin;
uint8_t multiplier;
uint32_t frequency;
uint16_t capture_period;
} frequencyio_frequencyin_obj_t;
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_FREQUENCYIO_FREQUENCYIN_H

View File

@ -0,0 +1 @@
// No ferquencyio module functions.

View File

@ -42,7 +42,7 @@
#include "freertos/FreeRTOS.h"
void common_hal_mcu_delay_us(uint32_t delay) {
mp_hal_delay_us(delay);
}
volatile uint32_t nesting_count = 0;

View File

@ -142,6 +142,13 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
} else {
config->sta.bssid_set = 0;
}
// If channel is 0 (default/unset) and BSSID is not given, do a full scan instead of fast scan
// This will ensure that the best AP in range is chosen automatically
if ((config->sta.bssid_set == 0) && (config->sta.channel == 0)) {
config->sta.scan_method = WIFI_ALL_CHANNEL_SCAN;
} else {
config->sta.scan_method = WIFI_FAST_SCAN;
}
esp_wifi_set_config(ESP_IF_WIFI_STA, config);
self->starting_retries = 5;
self->retries_left = 5;

View File

@ -18,7 +18,7 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_CANIO = 1
CIRCUITPY_COUNTIO = 1
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_FREQUENCYIO = 1
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_ROTARYIO = 1
CIRCUITPY_NVM = 0

View File

@ -0,0 +1,76 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 microDev
*
* 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 "peripherals/timer.h"
#define TIMER_FREE 1
#define TIMER_BUSY 0
static uint8_t timer_state[2][2];
void peripherals_timer_reset(void) {
timer_index_t timer;
for (uint8_t i = 0; i < 2; i++) {
for (uint8_t j = 0; j < 2; j++) {
if (timer_state[i][j] == TIMER_BUSY) {
timer.idx = (timer_idx_t)j;
timer.group = (timer_group_t)i;
timer_state[i][j] = TIMER_FREE;
peripherals_timer_deinit(&timer);
}
}
}
}
void peripherals_timer_init(const timer_config_t * config, timer_index_t * timer) {
bool break_loop = false;
// get free timer
for (uint8_t i = 0; i < 2; i++) {
for (uint8_t j = 0; j < 2; j++) {
if (timer_state[i][j] == TIMER_FREE) {
timer->idx = (timer_idx_t)j;
timer->group = (timer_group_t)i;
timer_state[i][j] = TIMER_BUSY;
break_loop = true;
break;
} else if (i == 1 && j == 1) {
timer->idx = TIMER_MAX;
timer->group = TIMER_GROUP_MAX;
return;
}
}
if (break_loop) {break;}
}
// initialize timer module
timer_init(timer->group, timer->idx, config);
timer_set_counter_value(timer->group, timer->idx, 0);
}
void peripherals_timer_deinit(timer_index_t * timer) {
timer_deinit(timer->group, timer->idx);
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 microDev
*
* 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_ESP32S2_PERIPHERALS_TIMER_HANDLER_H
#define MICROPY_INCLUDED_ESP32S2_PERIPHERALS_TIMER_HANDLER_H
#include "driver/timer.h"
typedef struct {
timer_idx_t idx;
timer_group_t group;
} timer_index_t;
extern void peripherals_timer_init(const timer_config_t * config, timer_index_t * timer);
extern void peripherals_timer_deinit(timer_index_t * timer);
extern void peripherals_timer_reset(void);
#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_TIMER_HANDLER_H

View File

@ -51,6 +51,7 @@
#include "peripherals/rmt.h"
#include "peripherals/pcnt.h"
#include "peripherals/timer.h"
#include "components/heap/include/esp_heap_caps.h"
#include "components/soc/soc/esp32s2/include/soc/cache_memory.h"
@ -104,15 +105,6 @@ void reset_port(void) {
analogout_reset();
#endif
#if CIRCUITPY_PULSEIO
esp32s2_peripherals_rmt_reset();
pulsein_reset();
#endif
#if CIRCUITPY_PWMIO
pwmout_reset();
#endif
#if CIRCUITPY_BUSIO
i2c_reset();
spi_reset();
@ -123,6 +115,19 @@ void reset_port(void) {
peripherals_pcnt_reset();
#endif
#if CIRCUITPY_FREQUENCYIO
peripherals_timer_reset();
#endif
#if CIRCUITPY_PULSEIO
esp32s2_peripherals_rmt_reset();
pulsein_reset();
#endif
#if CIRCUITPY_PWMIO
pwmout_reset();
#endif
#if CIRCUITPY_RTC
rtc_reset();
#endif

View File

@ -20,3 +20,5 @@ LD_COMMON = boards/common_default.ld
LD_FILE = boards/STM32F401xe_boot.ld
# For debugging - also comment BOOTLOADER_OFFSET and BOARD_VTOR_DEFER
# LD_FILE = boards/STM32F401xe_fs.ld
CIRCUITPY_ULAB = 0

View File

@ -15,3 +15,5 @@ MCU_PACKAGE = UFQFPN48
LD_COMMON = boards/common_nvm.ld
LD_FILE = boards/STM32F411_nvm.ld
CIRCUITPY_ULAB = 0

View File

@ -102,9 +102,9 @@ STATIC void check_exception(void) {
mp_obj_t py_e = new_jobject(exc);
JJ1(ExceptionClear);
if (JJ(IsInstanceOf, exc, IndexException_class)) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, py_e));
mp_raise_arg1(&mp_type_IndexError, py_e);
}
nlr_raise(mp_obj_new_exception_arg1(&mp_type_Exception, py_e));
mp_raise_arg1(&mp_type_Exception, py_e);
}
}

View File

@ -99,12 +99,12 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
mp_map_elem_t *kw = mp_map_lookup(kws, MP_OBJ_NEW_QSTR(allowed[i].qst), MP_MAP_LOOKUP);
if (kw == NULL) {
if (allowed[i].flags & MP_ARG_REQUIRED) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
} else {
#else
mp_raise_TypeError_varg(
translate("'%q' argument required"), allowed[i].qst);
}
#endif
}
out_vals[i] = allowed[i].defval;
continue;
@ -124,20 +124,20 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
}
if (pos_found < n_pos) {
extra_positional:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
} else {
#else
// TODO better error message
mp_raise_TypeError(translate("extra positional arguments given"));
}
#endif
}
if (kws_found < kws->used) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
} else {
#else
// TODO better error message
mp_raise_TypeError(translate("extra keyword arguments given"));
}
#endif
}
}

View File

@ -214,8 +214,8 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("unexpected keyword argument"));
#else
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
translate("unexpected keyword argument '%q'"), MP_OBJ_QSTR_VALUE(wanted_arg_name)));
mp_raise_TypeError_varg(
translate("unexpected keyword argument '%q'"), MP_OBJ_QSTR_VALUE(wanted_arg_name));
#endif
}
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);

View File

@ -426,12 +426,12 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
mp_module_call_init(mod_name, module_obj);
} else {
// couldn't find the file, so fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ImportError(translate("module not found"));
} else {
#else
mp_raise_msg_varg(&mp_type_ImportError,
translate("no module named '%q'"), mod_name);
}
#endif
}
} else {
// found the file, so get the module
@ -538,12 +538,12 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
#endif
// Couldn't find the module, so fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_msg(&mp_type_ImportError, translate("module not found"));
} else {
#else
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
translate("no module named '%q'"), module_name_qstr));
}
#endif
}
#endif // MICROPY_ENABLE_EXTERNAL_IMPORT

View File

@ -2486,21 +2486,21 @@ STATIC void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pn_i);
if (is_dict) {
if (!is_key_value) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("invalid syntax"));
} else {
#else
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("expecting key:value for dict"));
}
#endif
return;
}
EMIT(store_map);
} else {
if (is_key_value) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("invalid syntax"));
} else {
#else
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("expecting just a value for set"));
}
#endif
return;
}
}

View File

@ -346,12 +346,12 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
}
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("ord expects a character"));
} else {
#else
mp_raise_TypeError_varg(
translate("ord() expected a character, but string of length %d found"), (int)len);
}
#endif
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);

View File

@ -92,13 +92,11 @@ STATIC const MP_DEFINE_STR_OBJ(platform_obj, MICROPY_PY_SYS_PLATFORM);
// exit([retval]): raise SystemExit, with optional argument given to the exception
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
mp_obj_t exc;
if (n_args == 0) {
exc = mp_obj_new_exception(&mp_type_SystemExit);
nlr_raise(mp_obj_new_exception(&mp_type_SystemExit));
} else {
exc = mp_obj_new_exception_arg1(&mp_type_SystemExit, args[0]);
mp_raise_arg1(&mp_type_SystemExit, args[0]);
}
nlr_raise(exc);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit);

View File

@ -262,12 +262,12 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
return mp_obj_int_get_checked(arg);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_int);
} else {
#else
mp_raise_TypeError_varg(
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_int);
}
#endif
}
}
@ -325,12 +325,12 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
mp_float_t val;
if (!mp_obj_get_float_maybe(arg, &val)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_float);
} else {
#else
mp_raise_TypeError_varg(
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_float);
}
#endif
}
return val;
@ -358,12 +358,12 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_complex)) {
mp_obj_complex_get(arg, real, imag);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError_varg(translate("can't convert to %q"), MP_QSTR_complex);
} else {
#else
mp_raise_TypeError_varg(
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_complex);
}
#endif
}
}
#endif
@ -376,12 +376,12 @@ void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
} else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) {
mp_obj_list_get(o, len, items);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("expected tuple/list"));
} else {
#else
mp_raise_TypeError_varg(
translate("object '%q' is not a tuple or list"), mp_obj_get_type_qstr(o));
}
#endif
}
}
@ -390,12 +390,12 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
size_t seq_len;
mp_obj_get_array(o, &seq_len, items);
if (seq_len != len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError(translate("tuple/list has wrong length"));
} else {
#else
mp_raise_ValueError_varg(translate("requested length %d but object has length %d"),
(int)len, (int)seq_len);
}
#endif
}
}
@ -405,13 +405,13 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
if (MP_OBJ_IS_SMALL_INT(index)) {
i = MP_OBJ_SMALL_INT_VALUE(index);
} else if (!mp_obj_get_int_maybe(index, &i)) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("indices must be integers"));
} else {
#else
mp_raise_TypeError_varg(
translate("%q indices must be integers, not %q"),
type->name, mp_obj_get_type_qstr(index));
}
#endif
}
if (i < 0) {
@ -425,12 +425,12 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
}
} else {
if (i < 0 || (mp_uint_t)i >= len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_IndexError(translate("index out of range"));
} else {
#else
mp_raise_msg_varg(&mp_type_IndexError,
translate("%q index out of range"), type->name);
}
#endif
}
}
@ -460,12 +460,12 @@ mp_obj_t mp_obj_id(mp_obj_t o_in) {
mp_obj_t mp_obj_len(mp_obj_t o_in) {
mp_obj_t len = mp_obj_len_maybe(o_in);
if (len == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object has no len"));
} else {
#else
mp_raise_TypeError_varg(
translate("object of type '%q' has no len()"), mp_obj_get_type_qstr(o_in));
}
#endif
} else {
return len;
}
@ -503,26 +503,26 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
}
}
if (value == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object does not support item deletion"));
} else {
#else
mp_raise_TypeError_varg(
translate("'%q' object does not support item deletion"), mp_obj_get_type_qstr(base));
}
#endif
} else if (value == MP_OBJ_SENTINEL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object is not subscriptable"));
} else {
#else
mp_raise_TypeError_varg(
translate("'%q' object is not subscriptable"), mp_obj_get_type_qstr(base));
}
#endif
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object does not support item assignment"));
} else {
#else
mp_raise_TypeError_varg(
translate("'%q' object does not support item assignment"), mp_obj_get_type_qstr(base));
}
#endif
}
}

View File

@ -169,7 +169,7 @@ mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index) {
mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
mp_map_elem_t *elem = mp_map_lookup(&self->map, index, MP_MAP_LOOKUP);
if (elem == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_KeyError, index));
mp_raise_arg1(&mp_type_KeyError, index);
} else {
return elem->value;
}
@ -185,7 +185,7 @@ STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
mp_map_elem_t *elem = mp_map_lookup(&self->map, index, MP_MAP_LOOKUP);
if (elem == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_KeyError, index));
mp_raise_arg1(&mp_type_KeyError, index);
} else {
return elem->value;
}
@ -272,7 +272,7 @@ STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_look
if (elem == NULL || elem->value == MP_OBJ_NULL) {
if (n_args == 2) {
if (lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_KeyError, args[1]));
mp_raise_arg1(&mp_type_KeyError, args[1]);
} else {
value = mp_const_none;
}

View File

@ -102,17 +102,17 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const
n_kw = kw_args->used;
}
if (n_args + n_kw != num_fields) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
mp_raise_TypeError_varg(
translate("function takes %d positional arguments but %d were given"),
num_fields, n_args + n_kw);
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED) {
#else
mp_raise_TypeError_varg(
translate("%q() takes %d positional arguments but %d were given"),
type->base.name, num_fields, n_args + n_kw);
}
#endif
}
// Create a tuple and set the type to this namedtuple
@ -128,20 +128,20 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const
qstr kw = mp_obj_str_get_qstr(kw_args->table[i].key);
size_t id = mp_obj_namedtuple_find_field(type, kw);
if (id == (size_t)-1) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
} else {
#else
mp_raise_TypeError_varg(
translate("unexpected keyword argument '%q'"), kw);
}
#endif
}
if (tuple->items[id] != MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
} else {
#else
mp_raise_TypeError_varg(
translate("function got multiple values for argument '%q'"), kw);
}
#endif
}
tuple->items[id] = kw_args->table[i].value;
}

View File

@ -378,7 +378,7 @@ STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) {
check_set(self_in);
mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in);
if (mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND) == MP_OBJ_NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_KeyError, item));
mp_raise_arg1(&mp_type_KeyError, item);
}
return mp_const_none;
}

View File

@ -971,11 +971,11 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
vstr_add_byte(&vstr, '}');
continue;
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(translate("single '}' encountered in format string"));
}
#endif
}
if (*str != '{') {
vstr_add_byte(&vstr, *str);
@ -1010,18 +1010,18 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
if (str < top && (*str == 'r' || *str == 's')) {
conversion = *str++;
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
mp_raise_ValueError(translate("bad conversion specifier"));
} else {
#else
if (str >= top) {
mp_raise_ValueError(
translate("end of format while looking for conversion specifier"));
} else {
mp_raise_ValueError_varg(translate("unknown conversion specifier %c"), *str);
}
}
#endif
}
}
@ -1047,18 +1047,18 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
}
}
if (str >= top) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(translate("unmatched '{' in format"));
}
#endif
}
if (*str != '}') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error();
} else {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
:w
#else
mp_raise_ValueError(translate("expected ':' after format specifier"));
}
#endif
}
mp_obj_t arg = mp_const_none;
@ -1067,12 +1067,12 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
int index = 0;
if (MP_LIKELY(unichar_isdigit(*field_name))) {
if (*arg_i > 0) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(
translate("can't switch from automatic field numbering to manual field specification"));
}
#endif
}
field_name = str_to_int(field_name, field_name_top, &index);
if ((uint)index >= n_args - 1) {
@ -1087,7 +1087,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
field_name = lookup;
mp_map_elem_t *key_elem = mp_map_lookup(kwargs, field_q, MP_MAP_LOOKUP);
if (key_elem == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_KeyError, field_q));
mp_raise_arg1(&mp_type_KeyError, field_q);
}
arg = key_elem->value;
}
@ -1096,12 +1096,12 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
}
} else {
if (*arg_i < 0) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(
translate("can't switch from manual field specification to automatic field numbering"));
}
#endif
}
if ((uint)*arg_i >= n_args - 1) {
mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_tuple);
@ -1189,11 +1189,11 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
type = *s++;
}
if (*s) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(translate("invalid format specifier"));
}
#endif
}
vstr_clear(&format_spec_vstr);
}
@ -1210,19 +1210,19 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
if (flags & (PF_FLAG_SHOW_SIGN | PF_FLAG_SPACE_SIGN)) {
if (type == 's') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(translate("sign not allowed in string format specifier"));
}
#endif
}
if (type == 'c') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(
translate("sign not allowed with integer format specifier 'c'"));
}
#endif
}
}
@ -1276,13 +1276,13 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
break;
default:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError_varg(
translate("unknown format code '%c' for object of type '%q'"),
type, mp_obj_get_type_qstr(arg));
}
#endif
}
}
@ -1348,24 +1348,24 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
#endif
default:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError_varg(
translate("unknown format code '%c' for object of type '%q'"),
type, mp_obj_get_type_qstr(arg));
}
#endif
}
} else {
// arg doesn't look like a number
if (align == '=') {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(
translate("'=' alignment not allowed in string format specifier"));
}
#endif
}
switch (type) {
@ -1384,13 +1384,13 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
}
default:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError_varg(
translate("unknown format code '%c' for object of type '%q'"),
type, mp_obj_get_type_qstr(arg));
}
#endif
}
}
}
@ -1442,11 +1442,11 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
const byte *key = ++str;
while (*str != ')') {
if (str >= top) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(translate("incomplete format key"));
}
#endif
}
++str;
}
@ -1500,11 +1500,11 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_
if (str >= top) {
incomplete_format:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError(translate("incomplete format"));
}
#endif
}
// Tuple value lookup
@ -1587,13 +1587,13 @@ not_enough_args:
break;
default:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
terse_str_format_value_error();
} else {
#else
mp_raise_ValueError_varg(
translate("unsupported format character '%c' (0x%x) at index %d"),
*str, *str, str - start_str);
}
#endif
}
}
@ -2130,14 +2130,13 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) {
}
STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("can't convert to str implicitly"));
} else {
#else
const qstr src_name = mp_obj_get_type_qstr(self_in);
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
translate("can't convert '%q' object to %q implicitly"),
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str));
}
mp_raise_TypeError_varg(translate("can't convert '%q' object to %q implicitly"),
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str);
#endif
}
// use this if you will anyway convert the string to a qstr

View File

@ -373,12 +373,12 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, cons
m_del(mp_obj_t, args2, 2 + n_args + 2 * n_kw);
}
if (init_ret != mp_const_none) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("__init__() should return None"));
} else {
#else
mp_raise_TypeError_varg(translate("__init__() should return None, not '%q'"),
mp_obj_get_type_qstr(init_ret));
}
#endif
}
}
@ -888,12 +888,12 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
mp_obj_t member[2] = {MP_OBJ_NULL, MP_OBJ_NULL};
mp_obj_t call = mp_obj_instance_get_call(self_in, member);
if (call == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object not callable"));
} else {
#else
mp_raise_TypeError_varg(translate("'%q' object is not callable"),
mp_obj_get_type_qstr(self_in));
}
#endif
}
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
if (call == MP_OBJ_SENTINEL) {
@ -1024,11 +1024,11 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
if (self->make_new == NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("cannot create instance"));
} else {
#else
mp_raise_TypeError_varg(translate("cannot create '%q' instances"), self->name);
}
#endif
}
// create a map directly from the given args array and make a new instance
@ -1134,12 +1134,12 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
mp_obj_type_t *t = MP_OBJ_TO_PTR(bases_items[i]);
// TODO: Verify with CPy, tested on function type
if (t->make_new == NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("type is not an acceptable base type"));
} else {
#else
mp_raise_TypeError_varg(
translate("type '%q' is not an acceptable base type"), t->name);
}
#endif
}
#if ENABLE_SPECIAL_ACCESSORS
if (mp_obj_is_instance_type(t)) {

View File

@ -145,16 +145,16 @@ overflow:
goto have_ret_val;
}
value_error:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
value_error: ;
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_obj_t exc = mp_obj_new_exception_msg(&mp_type_ValueError,
translate("invalid syntax for integer"));
raise_exc(exc, lex);
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
mp_obj_t exc = mp_obj_new_exception_msg_varg(&mp_type_ValueError,
translate("invalid syntax for integer with base %d"), base);
raise_exc(exc, lex);
} else {
#else
vstr_t vstr;
mp_print_t print;
vstr_init_print(&vstr, 50, &print);
@ -163,7 +163,7 @@ value_error:
mp_obj_t exc = mp_obj_new_exception_arg1(&mp_type_ValueError,
mp_obj_new_str_from_vstr(&mp_type_str, &vstr));
raise_exc(exc, lex);
}
#endif
}
typedef enum {

View File

@ -7,7 +7,7 @@ HEADER_BUILD = $(BUILD)/genhdr
# file containing qstr defs for the core Python bit
PY_QSTR_DEFS = $(PY_SRC)/qstrdefs.h
TRANSLATION := en_US
TRANSLATION ?= en_US
# If qstr autogeneration is not disabled we specify the output header
# for all collected qstrings.
@ -109,7 +109,7 @@ ifeq ($(CIRCUITPY_ULAB),1)
SRC_MOD += $(patsubst $(TOP)/%,%,$(wildcard $(TOP)/extmod/ulab/code/*.c))
SRC_MOD += $(patsubst $(TOP)/%,%,$(wildcard $(TOP)/extmod/ulab/code/*/*.c))
CFLAGS_MOD += -DCIRCUITPY_ULAB=1 -DMODULE_ULAB_ENABLED=1
$(BUILD)/extmod/ulab/code/%.o: CFLAGS += -Wno-float-equal -Wno-sign-compare -DCIRCUITPY
$(BUILD)/extmod/ulab/code/%.o: CFLAGS += -Wno-missing-declarations -Wno-missing-prototypes -Wno-unused-parameter -Wno-float-equal -Wno-sign-compare -Wno-cast-align -Wno-shadow -DCIRCUITPY
endif
# External modules written in C.

View File

@ -43,8 +43,8 @@ void *mp_pystack_alloc(size_t n_bytes) {
#endif
if (MP_STATE_THREAD(pystack_cur) + n_bytes > MP_STATE_THREAD(pystack_end)) {
// out of memory in the pystack
nlr_raise(mp_obj_new_exception_arg1(&mp_type_RuntimeError,
MP_OBJ_NEW_QSTR(MP_QSTR_pystack_space_exhausted)));
mp_raise_arg1(&mp_type_RuntimeError,
MP_OBJ_NEW_QSTR(MP_QSTR_pystack_space_exhausted));
}
void *ptr = MP_STATE_THREAD(pystack_cur);
MP_STATE_THREAD(pystack_cur) += n_bytes;

View File

@ -177,12 +177,12 @@ mp_obj_t mp_load_global(qstr qst) {
#endif
elem = mp_map_lookup((mp_map_t*)&mp_module_builtins_globals.map, MP_OBJ_NEW_QSTR(qst), MP_MAP_LOOKUP);
if (elem == NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_msg(&mp_type_NameError, translate("name not defined"));
} else {
#else
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_NameError,
translate("name '%q' is not defined"), qst));
}
#endif
}
}
return elem->value;
@ -275,13 +275,13 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
return result;
}
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("unsupported type for operator"));
} else {
#else
mp_raise_TypeError_varg(
translate("unsupported type for %q: '%q'"),
mp_unary_op_method_name[op], mp_obj_get_type_qstr(arg));
}
#endif
}
}
@ -582,13 +582,13 @@ generic_binary_op:
}
unsupported_op:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("unsupported type for operator"));
} else {
#else
mp_raise_TypeError_varg(
translate("unsupported types for %q: '%q', '%q'"),
mp_binary_op_method_name[op], mp_obj_get_type_qstr(lhs), mp_obj_get_type_qstr(rhs));
}
#endif
zero_division:
mp_raise_msg(&mp_type_ZeroDivisionError, translate("division by zero"));
@ -624,11 +624,11 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, cons
return type->call(fun_in, n_args, n_kw, args);
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object not callable"));
} else {
#else
mp_raise_TypeError_varg(translate("'%q' object is not callable"), mp_obj_get_type_qstr(fun_in));
}
#endif
}
// args contains: fun self/NULL arg(0) ... arg(n_args-2) arg(n_args-1) kw_key(0) kw_val(0) ... kw_key(n_kw-1) kw_val(n_kw-1)
@ -852,19 +852,19 @@ void mp_unpack_sequence(mp_obj_t seq_in, size_t num, mp_obj_t *items) {
return;
too_short:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError(translate("wrong number of values to unpack"));
} else {
#else
mp_raise_ValueError_varg(translate("need more than %d values to unpack"),
(int)seq_len);
}
#endif
too_long:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError(translate("wrong number of values to unpack"));
} else {
#else
mp_raise_ValueError_varg(translate("too many values to unpack (expected %d)"),
(int)num);
}
#endif
}
// unpacked items are stored in reverse order into the array pointed to by items
@ -916,12 +916,12 @@ void mp_unpack_ex(mp_obj_t seq_in, size_t num_in, mp_obj_t *items) {
return;
too_short:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError(translate("wrong number of values to unpack"));
} else {
#else
mp_raise_ValueError_varg(translate("need more than %d values to unpack"),
(int)seq_len);
}
#endif
}
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr) {
@ -1094,9 +1094,9 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
if (dest[0] == MP_OBJ_NULL) {
// no attribute/method called attr
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_AttributeError(translate("no such attribute"));
} else {
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
// following CPython, we give a more detailed error message for type objects
if (MP_OBJ_IS_TYPE(base, &mp_type_type)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
@ -1107,7 +1107,11 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
translate("'%q' object has no attribute '%q'"),
mp_obj_get_type_qstr(base), attr));
}
}
#else
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
translate("'%q' object has no attribute '%q'"),
mp_obj_get_type_qstr(base), attr));
#endif
}
}
@ -1168,13 +1172,13 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
}
#endif
}
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_AttributeError(translate("no such attribute"));
} else {
#else
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
translate("'%q' object cannot assign attribute '%q'"),
mp_obj_get_type_qstr(base), attr));
}
#endif
}
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
@ -1209,12 +1213,12 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
}
// object not iterable
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object not iterable"));
} else {
#else
mp_raise_TypeError_varg(
translate("'%q' object is not iterable"), mp_obj_get_type_qstr(o_in));
}
#endif
}
// may return MP_OBJ_STOP_ITERATION as an optimisation instead of raise StopIteration()
@ -1231,12 +1235,12 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
// __next__ exists, call it and return its result
return mp_call_method_n_kw(0, 0, dest);
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object not an iterator"));
} else {
#else
mp_raise_TypeError_varg(translate("'%q' object is not an iterator"),
mp_obj_get_type_qstr(o_in));
}
#endif
}
}
}
@ -1267,12 +1271,12 @@ mp_obj_t mp_iternext(mp_obj_t o_in) {
}
}
} else {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("object not an iterator"));
} else {
#else
mp_raise_TypeError_varg(translate("'%q' object is not an iterator"),
mp_obj_get_type_qstr(o_in));
}
#endif
}
}
}
@ -1514,6 +1518,10 @@ NORETURN void m_malloc_fail(size_t num_bytes) {
translate("memory allocation failed, allocating %u bytes"), (uint)num_bytes);
}
NORETURN void mp_raise_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg) {
nlr_raise(mp_obj_new_exception_arg1(exc_type, arg));
}
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const compressed_string_t *msg) {
if (msg == NULL) {
nlr_raise(mp_obj_new_exception(exc_type));
@ -1580,7 +1588,7 @@ NORETURN void mp_raise_TypeError_varg(const compressed_string_t *fmt, ...) {
}
NORETURN void mp_raise_OSError(int errno_) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno_)));
mp_raise_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno_));
}
NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg) {
@ -1607,7 +1615,7 @@ NORETURN void mp_raise_ConnectionError(const compressed_string_t *msg) {
}
NORETURN void mp_raise_BrokenPipeError(void) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_BrokenPipeError, MP_OBJ_NEW_SMALL_INT(MP_EPIPE)));
mp_raise_arg1(&mp_type_BrokenPipeError, MP_OBJ_NEW_SMALL_INT(MP_EPIPE));
}
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg) {

View File

@ -150,6 +150,7 @@ mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level);
mp_obj_t mp_import_from(mp_obj_t module, qstr name);
void mp_import_all(mp_obj_t module);
NORETURN void mp_raise_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg);
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const compressed_string_t *msg);
NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, ...);
NORETURN void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, va_list argptr);

View File

@ -294,6 +294,29 @@ const mp_obj_property_t displayio_epaperdisplay_height_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| rotation: int
//| """The rotation of the display as an int in degrees."""
//|
STATIC mp_obj_t displayio_epaperdisplay_obj_get_rotation(mp_obj_t self_in) {
displayio_epaperdisplay_obj_t *self = native_display(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_epaperdisplay_get_rotation(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_epaperdisplay_get_rotation_obj, displayio_epaperdisplay_obj_get_rotation);
STATIC mp_obj_t displayio_epaperdisplay_obj_set_rotation(mp_obj_t self_in, mp_obj_t value) {
displayio_epaperdisplay_obj_t *self = native_display(self_in);
common_hal_displayio_epaperdisplay_set_rotation(self, mp_obj_get_int(value));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_epaperdisplay_set_rotation_obj, displayio_epaperdisplay_obj_set_rotation);
const mp_obj_property_t displayio_epaperdisplay_rotation_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_epaperdisplay_get_rotation_obj,
(mp_obj_t)&displayio_epaperdisplay_set_rotation_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| bus: _DisplayBus
//| """The bus being used by the display"""
//|
@ -317,6 +340,7 @@ STATIC const mp_rom_map_elem_t displayio_epaperdisplay_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_epaperdisplay_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_epaperdisplay_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&displayio_epaperdisplay_rotation_obj) },
{ MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_epaperdisplay_bus_obj) },
{ MP_ROM_QSTR(MP_QSTR_busy), MP_ROM_PTR(&displayio_epaperdisplay_busy_obj) },
{ MP_ROM_QSTR(MP_QSTR_time_to_refresh), MP_ROM_PTR(&displayio_epaperdisplay_time_to_refresh_obj) },

View File

@ -56,6 +56,8 @@ bool common_hal_displayio_epaperdisplay_get_busy(displayio_epaperdisplay_obj_t*
uint16_t common_hal_displayio_epaperdisplay_get_width(displayio_epaperdisplay_obj_t* self);
uint16_t common_hal_displayio_epaperdisplay_get_height(displayio_epaperdisplay_obj_t* self);
uint16_t common_hal_displayio_epaperdisplay_get_rotation(displayio_epaperdisplay_obj_t* self);
void common_hal_displayio_epaperdisplay_set_rotation(displayio_epaperdisplay_obj_t* self, int rotation);
mp_obj_t common_hal_displayio_epaperdisplay_get_bus(displayio_epaperdisplay_obj_t* self);

View File

@ -198,6 +198,29 @@ mp_obj_t common_hal_displayio_epaperdisplay_get_bus(displayio_epaperdisplay_obj_
return self->core.bus;
}
void common_hal_displayio_epaperdisplay_set_rotation(displayio_epaperdisplay_obj_t* self, int rotation){
bool transposed = (self->core.rotation == 90 || self->core.rotation == 270);
bool will_transposed = (rotation == 90 || rotation == 270);
if(transposed != will_transposed) {
int tmp = self->core.width;
self->core.width = self->core.height;
self->core.height = tmp;
}
displayio_display_core_set_rotation(&self->core, rotation);
if (self == &displays[0].epaper_display) {
supervisor_stop_terminal();
supervisor_start_terminal(self->core.width, self->core.height);
}
if (self->core.current_group != NULL) {
displayio_group_update_transform(self->core.current_group, &self->core.transform);
}
}
uint16_t common_hal_displayio_epaperdisplay_get_rotation(displayio_epaperdisplay_obj_t* self){
return self->core.rotation;
}
bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, const displayio_area_t* area) {
uint16_t buffer_size = 128; // In uint32_ts

View File

@ -60,18 +60,21 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
#if CIRCUITPY_TERMINALIO
displayio_tilegrid_t* grid = &supervisor_terminal_text_grid;
uint16_t width_in_tiles = (width_px - blinka_bitmap.width) / grid->tile_width;
bool tall = height_px > width_px;
uint16_t terminal_width_px = tall ? width_px : width_px - blinka_bitmap.width;
uint16_t terminal_height_px = tall ? height_px - blinka_bitmap.height : height_px ;
uint16_t width_in_tiles = terminal_width_px / grid->tile_width;
// determine scale based on h
if (width_in_tiles < 80) {
scale = 1;
}
width_in_tiles = (width_px - blinka_bitmap.width * scale) / (grid->tile_width * scale);
width_in_tiles = terminal_width_px / (grid->tile_width * scale);
if (width_in_tiles < 1) {
width_in_tiles = 1;
}
uint16_t height_in_tiles = height_px / (grid->tile_height * scale);
uint16_t remaining_pixels = height_px % (grid->tile_height * scale);
uint16_t height_in_tiles = terminal_height_px / (grid->tile_height * scale);
uint16_t remaining_pixels = tall ? 0 : terminal_height_px % (grid->tile_height * scale);
if (height_in_tiles < 1 || remaining_pixels > 0) {
height_in_tiles += 1;
}
@ -91,7 +94,8 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
if (tiles == NULL) {
return;
}
grid->y = 0;
grid->y = tall ? blinka_bitmap.height : 0;
grid->x = tall ? 0 : blinka_bitmap.width;
grid->top_left_y = 0;
if (remaining_pixels > 0) {
grid->y -= (grid->tile_height - remaining_pixels);