From a41ea275965af3e9bc43b285a5ee1080a6676d74 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Tue, 31 Jul 2018 12:32:37 +0200 Subject: Add pewpew70 board --- ports/atmel-samd/boards/pewpew70/board.c | 38 +++++++++++++++++++++++ ports/atmel-samd/boards/pewpew70/mpconfigboard.h | 12 +++++++ ports/atmel-samd/boards/pewpew70/mpconfigboard.mk | 11 +++++++ ports/atmel-samd/boards/pewpew70/pins.c | 31 ++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 ports/atmel-samd/boards/pewpew70/board.c create mode 100644 ports/atmel-samd/boards/pewpew70/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/pewpew70/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/pewpew70/pins.c diff --git a/ports/atmel-samd/boards/pewpew70/board.c b/ports/atmel-samd/boards/pewpew70/board.c new file mode 100644 index 000000000..c8e20206a --- /dev/null +++ b/ports/atmel-samd/boards/pewpew70/board.c @@ -0,0 +1,38 @@ +/* + * 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" + +void board_init(void) +{ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/pewpew70/mpconfigboard.h b/ports/atmel-samd/boards/pewpew70/mpconfigboard.h new file mode 100644 index 000000000..e839bc5ea --- /dev/null +++ b/ports/atmel-samd/boards/pewpew70/mpconfigboard.h @@ -0,0 +1,12 @@ +#define MICROPY_HW_BOARD_NAME "PewPew 7.0" +#define MICROPY_HW_MCU_NAME "samd21e18" + +#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + +#include "internal_flash.h" + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk new file mode 100644 index 000000000..1b5d1ff82 --- /dev/null +++ b/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk @@ -0,0 +1,11 @@ +LD_FILE = boards/samd21x18-bootloader.ld +USB_VID = 0x239A +USB_PID = 0x801D +USB_PRODUCT = "PewPew 7.0" +USB_MANUFACTURER = "Radomir Dopieralski" + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE + +CHIP_VARIANT = SAMD21E18A +CHIP_FAMILY = samd21 diff --git a/ports/atmel-samd/boards/pewpew70/pins.c b/ports/atmel-samd/boards/pewpew70/pins.c new file mode 100644 index 000000000..7102ff233 --- /dev/null +++ b/ports/atmel-samd/boards/pewpew70/pins.c @@ -0,0 +1,31 @@ +#include "shared-bindings/board/__init__.h" + +#include "board_busses.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_R1), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_R2), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_R3), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_R4), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_R5), MP_ROM_PTR(&pin_PA27) }, + { MP_ROM_QSTR(MP_QSTR_R6), MP_ROM_PTR(&pin_PA00) }, + { MP_ROM_QSTR(MP_QSTR_R7), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_R8), MP_ROM_PTR(&pin_PA19) }, + + { MP_ROM_QSTR(MP_QSTR_C1), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_C2), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_C3), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_C4), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_C5), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_C6), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_C7), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_C8), MP_ROM_PTR(&pin_PA17) }, + + { MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_PTR(&pin_PA04) }, + { MP_ROM_QSTR(MP_QSTR_DOWN), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_LEFT), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_RIGH), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_O), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA06) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); -- cgit v1.2.3 From 5a1e69f5b842fe091210a898f52712dfaceec3c6 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Tue, 31 Jul 2018 13:24:15 +0200 Subject: Correct a typo in the pin name --- ports/atmel-samd/boards/pewpew70/pins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/pewpew70/pins.c b/ports/atmel-samd/boards/pewpew70/pins.c index 7102ff233..9fca3c4ad 100644 --- a/ports/atmel-samd/boards/pewpew70/pins.c +++ b/ports/atmel-samd/boards/pewpew70/pins.c @@ -24,7 +24,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_PTR(&pin_PA04) }, { MP_ROM_QSTR(MP_QSTR_DOWN), MP_ROM_PTR(&pin_PA03) }, { MP_ROM_QSTR(MP_QSTR_LEFT), MP_ROM_PTR(&pin_PA02) }, - { MP_ROM_QSTR(MP_QSTR_RIGH), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_RIGHT), MP_ROM_PTR(&pin_PA05) }, { MP_ROM_QSTR(MP_QSTR_O), MP_ROM_PTR(&pin_PA07) }, { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA06) }, }; -- cgit v1.2.3 From 7ac11ed8e1da94c5408842cffd98a7265327f0df Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Tue, 31 Jul 2018 16:04:55 +0200 Subject: Enlarge the usb disk --- ports/atmel-samd/boards/pewpew70/mpconfigboard.h | 2 +- ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld | 2 +- ports/atmel-samd/supervisor/internal_flash.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/atmel-samd/boards/pewpew70/mpconfigboard.h b/ports/atmel-samd/boards/pewpew70/mpconfigboard.h index e839bc5ea..92662bd55 100644 --- a/ports/atmel-samd/boards/pewpew70/mpconfigboard.h +++ b/ports/atmel-samd/boards/pewpew70/mpconfigboard.h @@ -9,4 +9,4 @@ #include "internal_flash.h" -#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x014000) diff --git a/ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld b/ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld index 2adf4fa90..bc4b53ae9 100644 --- a/ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld +++ b/ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld @@ -6,7 +6,7 @@ MEMORY { /* Leave 8KiB for the bootloader, 256b for persistent config (clock), 64k for the flash file system and 256b for the user config. */ - FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K - 256 - 64K - 256 + FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K - 256 - 80K - 256 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K } diff --git a/ports/atmel-samd/supervisor/internal_flash.h b/ports/atmel-samd/supervisor/internal_flash.h index 0939a3454..d1037012d 100644 --- a/ports/atmel-samd/supervisor/internal_flash.h +++ b/ports/atmel-samd/supervisor/internal_flash.h @@ -37,7 +37,7 @@ #endif #ifdef SAMD21 -#define TOTAL_INTERNAL_FLASH_SIZE 0x010000 +#define TOTAL_INTERNAL_FLASH_SIZE 0x014000 #endif #define INTERNAL_FLASH_MEM_SEG1_START_ADDR (FLASH_SIZE - TOTAL_INTERNAL_FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE) -- cgit v1.2.3 From 88e40193ae92a390ff0cc8872ec2b7cd953c83cb Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 1 Aug 2018 15:29:26 +0200 Subject: Add a _pew module --- ports/atmel-samd/supervisor/port.c | 6 ++ ports/atmel-samd/tick.c | 6 ++ py/circuitpy_defns.mk | 3 + py/circuitpy_mpconfig.h | 7 ++ shared-bindings/_pew/PewPew.c | 130 +++++++++++++++++++++++++++++++++++++ shared-bindings/_pew/PewPew.h | 33 ++++++++++ shared-bindings/_pew/__init__.c | 54 +++++++++++++++ shared-module/_pew/PewPew.c | 52 +++++++++++++++ shared-module/_pew/PewPew.h | 47 ++++++++++++++ shared-module/_pew/__init__.c | 72 ++++++++++++++++++++ shared-module/_pew/__init__.h | 33 ++++++++++ 11 files changed, 443 insertions(+) create mode 100644 shared-bindings/_pew/PewPew.c create mode 100644 shared-bindings/_pew/PewPew.h create mode 100644 shared-bindings/_pew/__init__.c create mode 100644 shared-module/_pew/PewPew.c create mode 100644 shared-module/_pew/PewPew.h create mode 100644 shared-module/_pew/__init__.c create mode 100644 shared-module/_pew/__init__.h diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index aee082de0..9b5de88e6 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -71,6 +71,9 @@ #ifdef CIRCUITPY_GAMEPAD_TICKS #include "shared-module/gamepad/__init__.h" #endif +#ifdef CIRCUITPY_PEWPEW_TICKS +#include "shared-module/_pew/__init__.h" +#endif extern volatile bool mp_msc_enabled; @@ -225,6 +228,9 @@ void reset_port(void) { #ifdef CIRCUITPY_GAMEPAD_TICKS gamepad_reset(); #endif +#ifdef CIRCUITPY_PEWPEW_TICKS + pew_reset(); +#endif reset_event_system(); diff --git a/ports/atmel-samd/tick.c b/ports/atmel-samd/tick.c index 149347793..e1f9c180b 100644 --- a/ports/atmel-samd/tick.c +++ b/ports/atmel-samd/tick.c @@ -30,6 +30,7 @@ #include "supervisor/shared/autoreload.h" #include "shared-module/gamepad/__init__.h" +#include "shared-module/_pew/__init__.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Processor.h" @@ -54,6 +55,11 @@ void SysTick_Handler(void) { gamepad_tick(); } #endif + #ifdef CIRCUITPY_PEWPEW_TICKS + if (!(ticks_ms & CIRCUITPY_PEWPEW_TICKS)) { + pew_tick(); + } + #endif } void tick_init() { diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 2fa2e78e2..080263487 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -198,6 +198,9 @@ endif ifeq ($(CIRCUITPY_USTACK),1) SRC_PATTERNS += ustack/% endif +ifeq ($(CIRCUITPY_PEW),1) +SRC_PATTERNS += _pew/% +endif # All possible sources are listed here, and are filtered by SRC_PATTERNS. SRC_COMMON_HAL = \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 6f9705485..c20c0fb66 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -463,6 +463,13 @@ extern const struct _mp_obj_module_t ustack_module; #define USTACK_MODULE #endif +#if CIRCUITPY_PEW +extern const struct _mp_obj_module_t pew_module; +#define PEW_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__pew),(mp_obj_t)&pew_module }, +#else +#define PEW_MODULE +#endif + // These modules are not yet in shared-bindings, but we prefer the non-uxxx names. #if MICROPY_PY_UERRNO #define ERRNO_MODULE { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c new file mode 100644 index 000000000..c819dd861 --- /dev/null +++ b/shared-bindings/_pew/PewPew.c @@ -0,0 +1,130 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "py/gc.h" +#include "py/mpstate.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/util.h" +#include "PewPew.h" +#include "shared-module/_pew/PewPew.h" + + +//| .. currentmodule:: _pew +//| +//| :class:`PewPew` -- LED Matrix driver +//| ==================================== +//| +//| Usage:: +//| +//| + +//| .. class:: PewPew(buffer, rows, cols) +//| +//| Initializes matrix scanning routines. +//| +//| +STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, + size_t n_kw, const mp_obj_t *pos_args) { + mp_arg_check_num(n_args, n_kw, 3, 3, true); + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); + enum { ARG_buffer, ARG_rows, ARG_cols }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_rows, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_cols, MP_ARG_OBJ | MP_ARG_REQUIRED }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), + allowed_args, args); + + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); + + size_t rows_size = 0; + mp_obj_t *rows; + mp_obj_get_array(args[ARG_rows].u_obj, &rows_size, &rows); + + size_t cols_size = 0; + mp_obj_t *cols; + mp_obj_get_array(args[ARG_cols].u_obj, &cols_size, &cols); + + if (bufinfo.len != rows_size * cols_size) { + mp_raise_TypeError("wrong buffer size"); + } + + for (size_t i = 0; i < rows_size; ++i) { + if (!MP_OBJ_IS_TYPE(rows[i], &digitalio_digitalinout_type)) { + mp_raise_TypeError("expected a DigitalInOut"); + } + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(rows[i]); + raise_error_if_deinited( + common_hal_digitalio_digitalinout_deinited(pin)); + } + + for (size_t i = 0; i < cols_size; ++i) { + if (!MP_OBJ_IS_TYPE(cols[i], &digitalio_digitalinout_type)) { + mp_raise_TypeError("expected a DigitalInOut"); + } + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(cols[i]); + raise_error_if_deinited( + common_hal_digitalio_digitalinout_deinited(pin)); + } + + + pew_obj_t *pew = MP_STATE_VM(pew_singleton); + if (!pew) { + pew = m_new_obj(pew_obj_t); + pew->base.type = &pewpew_type; + pew = gc_make_long_lived(pew); + MP_STATE_VM(pew_singleton) = pew; + } + + pew->buffer = bufinfo.buf; + pew->rows = rows; + pew->rows_size = rows_size; + pew->cols = cols; + pew->cols_size = cols_size; + pew->col = 0; + pew->turn = 0; + pew_init(); + + return MP_OBJ_FROM_PTR(pew); +} + + +STATIC const mp_rom_map_elem_t pewpew_locals_dict_table[] = { +}; +STATIC MP_DEFINE_CONST_DICT(pewpew_locals_dict, pewpew_locals_dict_table); +const mp_obj_type_t pewpew_type = { + { &mp_type_type }, + .name = MP_QSTR_PewPew, + .make_new = pewpew_make_new, + .locals_dict = (mp_obj_dict_t*)&pewpew_locals_dict, +}; + diff --git a/shared-bindings/_pew/PewPew.h b/shared-bindings/_pew/PewPew.h new file mode 100644 index 000000000..13633ef93 --- /dev/null +++ b/shared-bindings/_pew/PewPew.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_PEW_PEWPEW_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_PEW_PEWPEW_H + +extern const mp_obj_type_t pewpew_type; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_PEW_PEWPEW_H diff --git a/shared-bindings/_pew/__init__.c b/shared-bindings/_pew/__init__.c new file mode 100644 index 000000000..39a3bc885 --- /dev/null +++ b/shared-bindings/_pew/__init__.c @@ -0,0 +1,54 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "PewPew.h" + + +//| :mod:`_pew` --- LED matrix driver +//| ================================== +//| +//| .. module:: _pew +//| :synopsis: LED matrix driver +//| :platform: SAMD21 +//| +//| .. toctree:: +//| :maxdepth: 3 +//| +//| PewPew +//| +STATIC const mp_rom_map_elem_t pew_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__pew) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_PewPew), MP_ROM_PTR(&pewpew_type)}, +}; +STATIC MP_DEFINE_CONST_DICT(pew_module_globals, + pew_module_globals_table); + +const mp_obj_module_t pew_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&pew_module_globals, +}; diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c new file mode 100644 index 000000000..ede8ed9bb --- /dev/null +++ b/shared-module/_pew/PewPew.c @@ -0,0 +1,52 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/mpstate.h" +#include "__init__.h" +#include "PewPew.h" + +#include "shared-bindings/digitalio/Pull.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/util.h" + + +void pew_init() { + pew_obj_t* pew_singleton = MP_STATE_VM(pew_singleton); + for (size_t i = 0; i < pew_singleton->rows_size; ++i) { + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR( + pew_singleton->rows[i]); + common_hal_digitalio_digitalinout_switch_to_output(pin, false, + DRIVE_MODE_PUSH_PULL); + } + for (size_t i = 0; i < pew_singleton->cols_size; ++i) { + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR( + pew_singleton->cols[i]); + common_hal_digitalio_digitalinout_switch_to_output(pin, true, + DRIVE_MODE_OPEN_DRAIN); + } +} diff --git a/shared-module/_pew/PewPew.h b/shared-module/_pew/PewPew.h new file mode 100644 index 000000000..b21ff0137 --- /dev/null +++ b/shared-module/_pew/PewPew.h @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_PEW_PEWPEW_H +#define MICROPY_INCLUDED_PEW_PEWPEW_H + +#include + +#include "shared-bindings/digitalio/DigitalInOut.h" + +typedef struct { + mp_obj_base_t base; + uint8_t* buffer; + mp_obj_t* rows; + mp_obj_t* cols; + size_t rows_size; + size_t cols_size; + volatile uint8_t col; + volatile uint8_t turn; +} pew_obj_t; + +void pew_init(void); + +#endif // MICROPY_INCLUDED_PEW_PEWPEW_H diff --git a/shared-module/_pew/__init__.c b/shared-module/_pew/__init__.c new file mode 100644 index 000000000..92637a04d --- /dev/null +++ b/shared-module/_pew/__init__.c @@ -0,0 +1,72 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/mpstate.h" +#include "__init__.h" +#include "PewPew.h" + +#include "shared-bindings/digitalio/DigitalInOut.h" + + +void pew_tick(void) { + digitalio_digitalinout_obj_t *pin; + pew_obj_t* pew = MP_STATE_VM(pew_singleton); + if (!pew) { return; } + + pin = MP_OBJ_TO_PTR(pew->cols[pew->col]); + common_hal_digitalio_digitalinout_set_value(pin, true); + pew->col += 1; + if (pew->col >= pew->cols_size) { + pew->col = 0; + pew->turn += 1; + if (pew->turn >= 4) { + pew->turn = 0; + } + } + for (size_t x = 0; x < pew->rows_size; ++x) { + pin = MP_OBJ_TO_PTR(pew->rows[x]); + uint8_t color = pew->buffer[(pew->col) * (pew->rows_size) + x]; + bool value = true; + switch (pew->turn) { + case 0: + if (color & 0x03) { value = true; } + break; + case 1: + case 2: + if (color & 0x02) { value = true; } + break; + } + common_hal_digitalio_digitalinout_set_value(pin, value); + } + pin = MP_OBJ_TO_PTR(pew->cols[pew->col]); + common_hal_digitalio_digitalinout_set_value(pin, false); +} + +void pew_reset(void) { + MP_STATE_VM(pew_singleton) = NULL; +} diff --git a/shared-module/_pew/__init__.h b/shared-module/_pew/__init__.h new file mode 100644 index 000000000..30c9c8c93 --- /dev/null +++ b/shared-module/_pew/__init__.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_PEW_H +#define MICROPY_INCLUDED_PEW_H + +void pew_tick(void); +void pew_reset(void); + +#endif // MICROPY_INCLUDED_PEW_H -- cgit v1.2.3 From 55b511a5d887c5e02031d40c661b31fce336c488 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Thu, 9 Aug 2018 22:35:26 +0200 Subject: Use a dedicated timer --- ports/atmel-samd/boards/pewpew70/mpconfigboard.h | 2 +- ports/atmel-samd/boards/pewpew70/mpconfigboard.mk | 2 + .../boards/samd21x18-bootloader-crystalless.ld | 2 +- ports/atmel-samd/supervisor/internal_flash.h | 2 +- ports/atmel-samd/supervisor/port.c | 2 +- ports/atmel-samd/tick.c | 5 -- shared-bindings/_pew/PewPew.c | 2 - shared-module/_pew/PewPew.c | 69 ++++++++++++++++++++++ shared-module/_pew/PewPew.h | 10 ++-- shared-module/_pew/__init__.c | 45 +++++++------- shared-module/_pew/__init__.h | 1 - 11 files changed, 104 insertions(+), 38 deletions(-) diff --git a/ports/atmel-samd/boards/pewpew70/mpconfigboard.h b/ports/atmel-samd/boards/pewpew70/mpconfigboard.h index 92662bd55..e839bc5ea 100644 --- a/ports/atmel-samd/boards/pewpew70/mpconfigboard.h +++ b/ports/atmel-samd/boards/pewpew70/mpconfigboard.h @@ -9,4 +9,4 @@ #include "internal_flash.h" -#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x014000) +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk index 1b5d1ff82..f316bfb2e 100644 --- a/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk @@ -9,3 +9,5 @@ LONGINT_IMPL = NONE CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 + +FROZEN_MPY_DIRS += $(TOP)/frozen/pewpew70 diff --git a/ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld b/ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld index bc4b53ae9..2adf4fa90 100644 --- a/ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld +++ b/ports/atmel-samd/boards/samd21x18-bootloader-crystalless.ld @@ -6,7 +6,7 @@ MEMORY { /* Leave 8KiB for the bootloader, 256b for persistent config (clock), 64k for the flash file system and 256b for the user config. */ - FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K - 256 - 80K - 256 + FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K - 256 - 64K - 256 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K } diff --git a/ports/atmel-samd/supervisor/internal_flash.h b/ports/atmel-samd/supervisor/internal_flash.h index d1037012d..0939a3454 100644 --- a/ports/atmel-samd/supervisor/internal_flash.h +++ b/ports/atmel-samd/supervisor/internal_flash.h @@ -37,7 +37,7 @@ #endif #ifdef SAMD21 -#define TOTAL_INTERNAL_FLASH_SIZE 0x014000 +#define TOTAL_INTERNAL_FLASH_SIZE 0x010000 #endif #define INTERNAL_FLASH_MEM_SEG1_START_ADDR (FLASH_SIZE - TOTAL_INTERNAL_FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE) diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 9b5de88e6..d1e0ae593 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -72,7 +72,7 @@ #include "shared-module/gamepad/__init__.h" #endif #ifdef CIRCUITPY_PEWPEW_TICKS -#include "shared-module/_pew/__init__.h" +#include "shared-module/_pew/PewPew.h" #endif extern volatile bool mp_msc_enabled; diff --git a/ports/atmel-samd/tick.c b/ports/atmel-samd/tick.c index e1f9c180b..44b631838 100644 --- a/ports/atmel-samd/tick.c +++ b/ports/atmel-samd/tick.c @@ -55,11 +55,6 @@ void SysTick_Handler(void) { gamepad_tick(); } #endif - #ifdef CIRCUITPY_PEWPEW_TICKS - if (!(ticks_ms & CIRCUITPY_PEWPEW_TICKS)) { - pew_tick(); - } - #endif } void tick_init() { diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index c819dd861..c9322100f 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -110,8 +110,6 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, pew->rows_size = rows_size; pew->cols = cols; pew->cols_size = cols_size; - pew->col = 0; - pew->turn = 0; pew_init(); return MP_OBJ_FROM_PTR(pew); diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index ede8ed9bb..de1224a37 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -27,14 +27,30 @@ #include #include "py/mpstate.h" +#include "py/runtime.h" #include "__init__.h" #include "PewPew.h" #include "shared-bindings/digitalio/Pull.h" #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/util.h" +#include "samd/timers.h" +static uint8_t pewpew_tc_index = 0xff; + + +void pewpew_interrupt_handler(uint8_t index) { + if (index != pewpew_tc_index) return; + Tc* tc = tc_insts[index]; + if (!tc->COUNT16.INTFLAG.bit.MC0) return; + + pew_tick(); + + // Clear the interrupt bit. + tc->COUNT16.INTFLAG.reg = TC_INTFLAG_MC0; +} + void pew_init() { pew_obj_t* pew_singleton = MP_STATE_VM(pew_singleton); for (size_t i = 0; i < pew_singleton->rows_size; ++i) { @@ -49,4 +65,57 @@ void pew_init() { common_hal_digitalio_digitalinout_switch_to_output(pin, true, DRIVE_MODE_OPEN_DRAIN); } + if (pewpew_tc_index == 0xff) { + // Find a spare timer. + Tc *tc = NULL; + int8_t index = TC_INST_NUM - 1; + for (; index >= 0; index--) { + if (tc_insts[index]->COUNT16.CTRLA.bit.ENABLE == 0) { + tc = tc_insts[index]; + break; + } + } + if (tc == NULL) { + mp_raise_RuntimeError("All timers in use"); + } + + pewpew_tc_index = index; + + // We use GCLK0 for SAMD21 and GCLK1 for SAMD51 because they both run + // at 48mhz making our math the same across the boards. + #ifdef SAMD21 + turn_on_clocks(true, index, 0); + #endif + #ifdef SAMD51 + turn_on_clocks(true, index, 1); + #endif + + + #ifdef SAMD21 + tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | + TC_CTRLA_PRESCALER_DIV64 | + TC_CTRLA_WAVEGEN_MFRQ; + #endif + #ifdef SAMD51 + tc_reset(tc); + tc_set_enable(tc, false); + tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 + | TC_CTRLA_PRESCALER_DIV64; + tc->COUNT16.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ; + #endif + + tc_set_enable(tc, true); + //tc->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_STOP; + tc->COUNT16.CC[0].reg = 160; + + // Clear our interrupt in case it was set earlier + tc->COUNT16.INTFLAG.reg = TC_INTFLAG_MC0; + tc->COUNT16.INTENSET.reg = TC_INTENSET_MC0; + tc_enable_interrupts(pewpew_tc_index); + } +} + +void pew_reset(void) { + MP_STATE_VM(pew_singleton) = NULL; + pewpew_tc_index = 0xff; } diff --git a/shared-module/_pew/PewPew.h b/shared-module/_pew/PewPew.h index b21ff0137..2f25f9ce2 100644 --- a/shared-module/_pew/PewPew.h +++ b/shared-module/_pew/PewPew.h @@ -29,19 +29,17 @@ #include -#include "shared-bindings/digitalio/DigitalInOut.h" - typedef struct { mp_obj_base_t base; uint8_t* buffer; mp_obj_t* rows; mp_obj_t* cols; - size_t rows_size; - size_t cols_size; - volatile uint8_t col; - volatile uint8_t turn; + uint8_t rows_size; + uint8_t cols_size; } pew_obj_t; void pew_init(void); +void pewpew_interrupt_handler(uint8_t index); +void pew_reset(void); #endif // MICROPY_INCLUDED_PEW_PEWPEW_H diff --git a/shared-module/_pew/__init__.c b/shared-module/_pew/__init__.c index 92637a04d..2e09932f3 100644 --- a/shared-module/_pew/__init__.c +++ b/shared-module/_pew/__init__.c @@ -34,39 +34,44 @@ void pew_tick(void) { + static uint8_t col = 0; + static uint8_t turn = 0; digitalio_digitalinout_obj_t *pin; + pew_obj_t* pew = MP_STATE_VM(pew_singleton); if (!pew) { return; } - pin = MP_OBJ_TO_PTR(pew->cols[pew->col]); - common_hal_digitalio_digitalinout_set_value(pin, true); - pew->col += 1; - if (pew->col >= pew->cols_size) { - pew->col = 0; - pew->turn += 1; - if (pew->turn >= 4) { - pew->turn = 0; + pin = MP_OBJ_TO_PTR(pew->cols[col]); + ++col; + if (col >= pew->cols_size) { + col = 0; + ++turn; + if (turn >= 8) { + turn = 0; } } + common_hal_digitalio_digitalinout_set_value(pin, true); for (size_t x = 0; x < pew->rows_size; ++x) { pin = MP_OBJ_TO_PTR(pew->rows[x]); - uint8_t color = pew->buffer[(pew->col) * (pew->rows_size) + x]; - bool value = true; - switch (pew->turn) { - case 0: - if (color & 0x03) { value = true; } + uint8_t color = pew->buffer[col * (pew->rows_size) + x]; + bool value = false; + switch (color & 0x03) { + case 3: + value = true; break; - case 1: case 2: - if (color & 0x02) { value = true; } + if (turn == 2 || turn == 4 || turn == 6) { + value = true; + } + case 1: + if (turn == 0) { + value = true; + } + case 0: break; } common_hal_digitalio_digitalinout_set_value(pin, value); } - pin = MP_OBJ_TO_PTR(pew->cols[pew->col]); + pin = MP_OBJ_TO_PTR(pew->cols[col]); common_hal_digitalio_digitalinout_set_value(pin, false); } - -void pew_reset(void) { - MP_STATE_VM(pew_singleton) = NULL; -} diff --git a/shared-module/_pew/__init__.h b/shared-module/_pew/__init__.h index 30c9c8c93..f85dec749 100644 --- a/shared-module/_pew/__init__.h +++ b/shared-module/_pew/__init__.h @@ -28,6 +28,5 @@ #define MICROPY_INCLUDED_PEW_H void pew_tick(void); -void pew_reset(void); #endif // MICROPY_INCLUDED_PEW_H -- cgit v1.2.3 From 0a5c1c94025a1d36762d14b48995337b0f09ce97 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sun, 12 Aug 2018 14:36:38 +0200 Subject: Some cleanup --- ports/atmel-samd/supervisor/port.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index d1e0ae593..4aa07a6db 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -71,9 +71,7 @@ #ifdef CIRCUITPY_GAMEPAD_TICKS #include "shared-module/gamepad/__init__.h" #endif -#ifdef CIRCUITPY_PEWPEW_TICKS #include "shared-module/_pew/PewPew.h" -#endif extern volatile bool mp_msc_enabled; @@ -228,9 +226,7 @@ void reset_port(void) { #ifdef CIRCUITPY_GAMEPAD_TICKS gamepad_reset(); #endif -#ifdef CIRCUITPY_PEWPEW_TICKS pew_reset(); -#endif reset_event_system(); -- cgit v1.2.3 From 59f63eaef6d1024163864c9b30f879efc9dfd682 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Thu, 23 Aug 2018 23:22:47 +0200 Subject: Handle new buttons --- frozen/pewpew10/pew.py | 217 ++++++++++++++++++++++ ports/atmel-samd/boards/pewpew10/board.c | 38 ++++ ports/atmel-samd/boards/pewpew10/mpconfigboard.h | 36 ++++ ports/atmel-samd/boards/pewpew10/mpconfigboard.mk | 13 ++ ports/atmel-samd/boards/pewpew10/pins.c | 35 ++++ shared-bindings/_pew/PewPew.c | 15 +- shared-bindings/_pew/__init__.c | 13 ++ shared-module/_pew/PewPew.c | 15 +- shared-module/_pew/PewPew.h | 3 + shared-module/_pew/__init__.c | 8 + 10 files changed, 384 insertions(+), 9 deletions(-) create mode 100644 frozen/pewpew10/pew.py create mode 100644 ports/atmel-samd/boards/pewpew10/board.c create mode 100644 ports/atmel-samd/boards/pewpew10/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/pewpew10/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/pewpew10/pins.c diff --git a/frozen/pewpew10/pew.py b/frozen/pewpew10/pew.py new file mode 100644 index 000000000..8d60d0ec6 --- /dev/null +++ b/frozen/pewpew10/pew.py @@ -0,0 +1,217 @@ +from micropython import const +import board +import time +import digitalio +import _pew + + +_FONT = ( + b'\xff\xff\xff\xff\xff\xff\xf3\xf3\xf7\xfb\xf3\xff\xcc\xdd\xee\xff\xff' + b'\xff\xdd\x80\xdd\x80\xdd\xff\xf7\x81\xe4\xc6\xd0\xf7\xcc\xdb\xf3\xf9' + b'\xcc\xff\xf6\xcdc\xdcf\xff\xf3\xf7\xfe\xff\xff\xff\xf6\xfd\xfc\xfd' + b'\xf6\xff\xe7\xdf\xcf\xdf\xe7\xff\xff\xd9\xe2\xd9\xff\xff\xff\xf3\xc0' + b'\xf3\xff\xff\xff\xff\xff\xf3\xf7\xfe\xff\xff\x80\xff\xff\xff\xff\xff' + b'\xff\xff\xf3\xff\xcf\xdb\xf3\xf9\xfc\xff\xd2\xcd\xc8\xdc\xe1\xff\xf7' + b'\xf1\xf3\xf3\xe2\xff\xe1\xce\xe3\xfd\xc0\xff\xe1\xce\xe3\xce\xe1\xff' + b'\xf3\xf9\xdc\xc0\xcf\xff\xc0\xfc\xe4\xcf\xe1\xff\xd2\xfc\xe1\xcc\xe2' + b'\xff\xc0\xdb\xf3\xf9\xfc\xff\xe2\xcc\xe2\xcc\xe2\xff\xe2\xcc\xd2\xcf' + b'\xe1\xff\xff\xf3\xff\xf3\xff\xff\xff\xf3\xff\xf3\xf7\xfe\xcf\xf3\xfc' + b'\xf3\xcf\xff\xff\xc0\xff\xc0\xff\xff\xfc\xf3\xcf\xf3\xfc\xff\xe1\xcf' + b'\xe3\xfb\xf3\xff\xe2\xcd\xc4\xd4\xbd\xd2\xe2\xdd\xcc\xc4\xcc\xff\xe4' + b'\xcc\xe4\xcc\xe4\xff\xe2\xcd\xfc\xcd\xe2\xff\xe4\xdc\xcc\xdc\xe4\xff' + b'\xd0\xfc\xf4\xfc\xd0\xff\xd0\xfc\xfc\xf4\xfc\xff\xd2\xfd\xfc\x8d\xd2' + b'\xff\xcc\xcc\xc4\xcc\xcc\xff\xd1\xf3\xf3\xf3\xd1\xff\xcb\xcf\xcf\xdc' + b'\xe2\xff\xdc\xcc\xd8\xf4\xc8\xff\xfc\xfc\xfc\xec\xc0\xff\xdd\xc4\xc0' + b'\xc8\xcc\xff\xcd\xd4\xd1\xc5\xdc\xff\xe2\xdd\xcc\xdd\xe2\xff\xe4\xcc' + b'\xcc\xe4\xfc\xff\xe2\xcc\xcc\xc8\xd2\xcf\xe4\xcc\xcc\xe0\xcc\xff\xd2' + b'\xec\xe2\xce\xe1\xff\xc0\xe2\xf3\xf3\xf3\xff\xcc\xcc\xcc\xdd\xe2\xff' + b'\xcc\xcc\xdd\xe6\xf3\xff\xcc\xc8\xc4\xc0\xd9\xff\xcc\xd9\xe2\xd9\xcc' + b'\xff\xcc\xdd\xe6\xf3\xf3\xff\xc0\xde\xf7\xed\xc0\xff\xd0\xfc\xfc\xfc' + b'\xd0\xff\xfc\xf9\xf3\xdb\xcf\xff\xc1\xcf\xcf\xcf\xc1\xff\xf3\xd9\xee' + b'\xff\xff\xff\xff\xff\xff\xff\x80\xff\xfc\xf7\xef\xff\xff\xff\xff\xd2' + b'\xcd\xcc\x86\xff\xfc\xe4\xdc\xcc\xe4\xff\xff\xd2\xfd\xbc\xc6\xff\xcf' + b'\xc6\xcd\xcc\x86\xff\xff\xd6\xcd\xb1\xd2\xff\xcb\xb7\xc1\xf3\xf3\xf6' + b'\xff\xe2\xcc\xd2\xdf\xe1\xfc\xe4\xdc\xcc\xcc\xff\xf3\xfb\xf1\xb3\xdb' + b'\xff\xcf\xef\xc7\xcf\xdd\xe2\xfd\xec\xd8\xf4\xcc\xff\xf6\xf3\xf3\xf3' + b'\xdb\xff\xff\xd9\xc4\xc8\xcc\xff\xff\xe4\xdd\xcc\xcc\xff\xff\xe2\xcc' + b'\xcc\xe2\xff\xff\xe4\xdc\xcc\xe4\xfc\xff\xc6\xcd\xcc\xc6\xcf\xff\xc9' + b'\xf4\xfc\xfc\xff\xff\xd2\xf8\xcb\xe1\xff\xf3\xd1\xf3\xb3\xdb\xff\xff' + b'\xcc\xcc\xcd\x82\xff\xff\xcc\xdd\xe6\xf3\xff\xff\xcc\xc8\xd1\xd9\xff' + b'\xff\xcc\xe6\xe6\xcc\xff\xff\xdc\xcd\xd2\xcf\xe1\xff\xc0\xdb\xf9\xc0' + b'\xff\xd3\xf3\xf9\xf3\xd3\xff\xf3\xf3\xf7\xf3\xf3\xff\xf1\xf3\xdb\xf3' + b'\xf1\xff\xbfr\x8d\xfe\xff\xfff\x99f\x99f\x99') + + +K_RIGHT = const(0x01) +K_DOWN = const(0x02) +K_LEFT = const(0x04) +K_UP = const(0x08) +K_O = const(0x40) +K_X = const(0x80) + +_screen = None + + +def brightness(level): + pass + + +def show(pix): + _screen.blit(pix) + + +def tick(delay): + global _tick + + _tick += delay + time.sleep(max(0, _tick - time.monotonic())) + + +class GameOver(Exception): + pass + + +class Pix: + def __init__(self, width=8, height=8, buffer=None): + if buffer is None: + buffer = bytearray(width * height) + self.buffer = buffer + self.width = width + self.height = height + + @classmethod + def from_text(cls, string, color=None, bgcolor=0, colors=None): + pix = cls(4 * len(string), 6) + font = memoryview(_FONT) + if colors is None: + if color is None: + colors = (3, 2, 1, bgcolor) + else: + colors = (color, color, bgcolor, bgcolor) + x = 0 + for c in string: + index = ord(c) - 0x20 + if not 0 <= index <= 95: + continue + row = 0 + for byte in font[index * 6:index * 6 + 6]: + for col in range(4): + pix.pixel(x + col, row, colors[byte & 0x03]) + byte >>= 2 + row += 1 + x += 4 + return pix + + @classmethod + def from_iter(cls, lines): + pix = cls(len(lines[0]), len(lines)) + y = 0 + for line in lines: + x = 0 + for pixel in line: + pix.pixel(x, y, pixel) + x += 1 + y += 1 + return pix + + def pixel(self, x, y, color=None): + if not 0 <= x < self.width or not 0 <= y < self.height: + return 0 + if color is None: + return self.buffer[x + y * self.width] + self.buffer[x + y * self.width] = color + + def box(self, color, x=0, y=0, width=None, height=None): + x = min(max(x, 0), self.width - 1) + y = min(max(y, 0), self.height - 1) + width = max(0, min(width or self.width, self.width - x)) + height = max(0, min(height or self.height, self.height - y)) + for y in range(y, y + height): + xx = y * self.width + x + for i in range(width): + self.buffer[xx] = color + xx += 1 + + def blit(self, source, dx=0, dy=0, x=0, y=0, + width=None, height=None, key=None): + if dx < 0: + x -= dx + dx = 0 + if x < 0: + dx -= x + x = 0 + if dy < 0: + y -= dy + dy = 0 + if y < 0: + dy -= y + y = 0 + width = min(min(width or source.width, source.width - x), + self.width - dx) + height = min(min(height or source.height, source.height - y), + self.height - dy) + source_buffer = memoryview(source.buffer) + self_buffer = self.buffer + if key is None: + for row in range(height): + xx = y * source.width + x + dxx = dy * self.width + dx + self_buffer[dxx:dxx + width] = source_buffer[xx:xx + width] + y += 1 + dy += 1 + else: + for row in range(height): + xx = y * source.width + x + dxx = dy * self.width + dx + for col in range(width): + color = source_buffer[xx] + if color != key: + self_buffer[dxx] = color + dxx += 1 + xx += 1 + y += 1 + dy += 1 + + def __str__(self): + return "\n".join( + "".join( + ('.', '+', '*', '@')[self.pixel(x, y)] + for x in range(self.width) + ) + for y in range(self.height) + ) + + +def init(): + global _screen, _tick, keys, _rows, _cols + + if _screen is not None: + return + + _screen = Pix(8, 8) + _tick = time.monotonic() + + _rows = ( + digitalio.DigitalInOut(board.R1), + digitalio.DigitalInOut(board.R2), + digitalio.DigitalInOut(board.R3), + digitalio.DigitalInOut(board.R4), + digitalio.DigitalInOut(board.R5), + digitalio.DigitalInOut(board.R6), + digitalio.DigitalInOut(board.R7), + digitalio.DigitalInOut(board.R8), + ) + + _cols = ( + digitalio.DigitalInOut(board.C1), + digitalio.DigitalInOut(board.C2), + digitalio.DigitalInOut(board.C3), + digitalio.DigitalInOut(board.C4), + digitalio.DigitalInOut(board.C5), + digitalio.DigitalInOut(board.C6), + digitalio.DigitalInOut(board.C7), + digitalio.DigitalInOut(board.C8), + ) + _buttons = digitalio.DigitalInOut(board.BUTTONS) + _pew.PewPew(_screen.buffer, _rows, _cols, _buttons) + keys = _pew.get_pressed diff --git a/ports/atmel-samd/boards/pewpew10/board.c b/ports/atmel-samd/boards/pewpew10/board.c new file mode 100644 index 000000000..c8e20206a --- /dev/null +++ b/ports/atmel-samd/boards/pewpew10/board.c @@ -0,0 +1,38 @@ +/* + * 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" + +void board_init(void) +{ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h new file mode 100644 index 000000000..3fd1cbce1 --- /dev/null +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h @@ -0,0 +1,36 @@ +#define MICROPY_HW_BOARD_NAME "PewPew 10.2" +#define MICROPY_HW_MCU_NAME "samd21e18" + +#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + +#include "internal_flash.h" + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) + + +#define IGNORE_PIN_PB00 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 diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk new file mode 100644 index 000000000..cf3004a4d --- /dev/null +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk @@ -0,0 +1,13 @@ +LD_FILE = boards/samd21x18-bootloader.ld +USB_VID = 0x239A +USB_PID = 0x801D +USB_PRODUCT = "PewPew 10.2" +USB_MANUFACTURER = "Radomir Dopieralski" + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE + +CHIP_VARIANT = SAMD21E18A +CHIP_FAMILY = samd21 + +FROZEN_MPY_DIRS += $(TOP)/frozen/pewpew10 diff --git a/ports/atmel-samd/boards/pewpew10/pins.c b/ports/atmel-samd/boards/pewpew10/pins.c new file mode 100644 index 000000000..499e6270b --- /dev/null +++ b/ports/atmel-samd/boards/pewpew10/pins.c @@ -0,0 +1,35 @@ +#include "shared-bindings/board/__init__.h" + +#include "board_busses.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_R1), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_R2), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_R3), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_R4), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_R5), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_R6), MP_ROM_PTR(&pin_PA27) }, + { MP_ROM_QSTR(MP_QSTR_R7), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_R8), MP_ROM_PTR(&pin_PA22) }, + + { MP_ROM_QSTR(MP_QSTR_C8), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_C7), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_C6), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_C5), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_C4), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_C3), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_C2), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_C1), MP_ROM_PTR(&pin_PA15) }, + + { MP_ROM_QSTR(MP_QSTR_P1), MP_ROM_PTR(&pin_PA30) }, + { MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_PA31) }, + { MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_PA00) }, + { MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_PA04) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTONS), MP_ROM_PTR(&pin_PA08) }, + +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index c9322100f..69c9ff4fc 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -50,14 +50,15 @@ //| STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 3, 3, true); + mp_arg_check_num(n_args, n_kw, 4, 4, true); mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); - enum { ARG_buffer, ARG_rows, ARG_cols }; + enum { ARG_buffer, ARG_rows, ARG_cols, ARG_buttons }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_rows, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_cols, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_buttons, MP_ARG_OBJ | MP_ARG_REQUIRED }, }; 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), @@ -96,6 +97,14 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, common_hal_digitalio_digitalinout_deinited(pin)); } + if (!MP_OBJ_IS_TYPE(args[ARG_buttons].u_obj, + &digitalio_digitalinout_type)) { + mp_raise_TypeError("expected a DigitalInOut"); + } + digitalio_digitalinout_obj_t *buttons = MP_OBJ_TO_PTR( + args[ARG_buttons].u_obj); + raise_error_if_deinited( + common_hal_digitalio_digitalinout_deinited(buttons)); pew_obj_t *pew = MP_STATE_VM(pew_singleton); if (!pew) { @@ -110,6 +119,8 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, pew->rows_size = rows_size; pew->cols = cols; pew->cols_size = cols_size; + pew->buttons = buttons; + pew->pressed = 0; pew_init(); return MP_OBJ_FROM_PTR(pew); diff --git a/shared-bindings/_pew/__init__.c b/shared-bindings/_pew/__init__.c index 39a3bc885..652d95f1b 100644 --- a/shared-bindings/_pew/__init__.c +++ b/shared-bindings/_pew/__init__.c @@ -27,6 +27,18 @@ #include "py/runtime.h" #include "py/mphal.h" #include "PewPew.h" +#include "shared-module/_pew/PewPew.h" + +STATIC mp_obj_t get_pressed(void) { + pew_obj_t *pew = MP_STATE_VM(pew_singleton); + if (!pew) { + return mp_const_none; + } + uint8_t pressed = pew->pressed; + pew->pressed = 0; + return mp_obj_new_int(pressed); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_pressed_obj, get_pressed); //| :mod:`_pew` --- LED matrix driver @@ -44,6 +56,7 @@ STATIC const mp_rom_map_elem_t pew_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__pew) }, { MP_OBJ_NEW_QSTR(MP_QSTR_PewPew), MP_ROM_PTR(&pewpew_type)}, + { MP_OBJ_NEW_QSTR(MP_QSTR_get_pressed), MP_ROM_PTR(&get_pressed_obj)}, }; STATIC MP_DEFINE_CONST_DICT(pew_module_globals, pew_module_globals_table); diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index de1224a37..27c2d1c99 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -52,16 +52,17 @@ void pewpew_interrupt_handler(uint8_t index) { } void pew_init() { - pew_obj_t* pew_singleton = MP_STATE_VM(pew_singleton); - for (size_t i = 0; i < pew_singleton->rows_size; ++i) { - digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR( - pew_singleton->rows[i]); + pew_obj_t* pew = MP_STATE_VM(pew_singleton); + + common_hal_digitalio_digitalinout_switch_to_input(pew->buttons, PULL_UP); + + for (size_t i = 0; i < pew->rows_size; ++i) { + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(pew->rows[i]); common_hal_digitalio_digitalinout_switch_to_output(pin, false, DRIVE_MODE_PUSH_PULL); } - for (size_t i = 0; i < pew_singleton->cols_size; ++i) { - digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR( - pew_singleton->cols[i]); + for (size_t i = 0; i < pew->cols_size; ++i) { + digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(pew->cols[i]); common_hal_digitalio_digitalinout_switch_to_output(pin, true, DRIVE_MODE_OPEN_DRAIN); } diff --git a/shared-module/_pew/PewPew.h b/shared-module/_pew/PewPew.h index 2f25f9ce2..57b25c3a0 100644 --- a/shared-module/_pew/PewPew.h +++ b/shared-module/_pew/PewPew.h @@ -28,14 +28,17 @@ #define MICROPY_INCLUDED_PEW_PEWPEW_H #include +#include "shared-bindings/digitalio/DigitalInOut.h" typedef struct { mp_obj_base_t base; uint8_t* buffer; mp_obj_t* rows; mp_obj_t* cols; + digitalio_digitalinout_obj_t *buttons; uint8_t rows_size; uint8_t cols_size; + uint8_t pressed; } pew_obj_t; void pew_init(void); diff --git a/shared-module/_pew/__init__.c b/shared-module/_pew/__init__.c index 2e09932f3..e44a4c0e3 100644 --- a/shared-module/_pew/__init__.c +++ b/shared-module/_pew/__init__.c @@ -36,6 +36,8 @@ void pew_tick(void) { static uint8_t col = 0; static uint8_t turn = 0; + static uint8_t pressed = 0; + static uint8_t last_pressed = 0; digitalio_digitalinout_obj_t *pin; pew_obj_t* pew = MP_STATE_VM(pew_singleton); @@ -44,12 +46,18 @@ void pew_tick(void) { pin = MP_OBJ_TO_PTR(pew->cols[col]); ++col; if (col >= pew->cols_size) { + pew->pressed |= last_pressed & pressed; + last_pressed = pressed; + pressed = 0; col = 0; ++turn; if (turn >= 8) { turn = 0; } } + if (!common_hal_digitalio_digitalinout_get_value(pew->buttons)) { + pressed |= 1 << col; + } common_hal_digitalio_digitalinout_set_value(pin, true); for (size_t x = 0; x < pew->rows_size; ++x) { pin = MP_OBJ_TO_PTR(pew->rows[x]); -- cgit v1.2.3 From 48f0a5163e6a3a5e44e6df231867b9bc90ce933b Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sat, 29 Sep 2018 20:51:32 +0200 Subject: Reset timer when releasing _pew --- shared-module/_pew/PewPew.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index 27c2d1c99..cbe7164bc 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -117,6 +117,7 @@ void pew_init() { } void pew_reset(void) { - MP_STATE_VM(pew_singleton) = NULL; + tc_insts[pewpew_tc_index]->COUNT16.CTRLA.bit.ENABLE = 0; pewpew_tc_index = 0xff; + MP_STATE_VM(pew_singleton) = NULL; } -- cgit v1.2.3 From 808304e8276a51a6ec2ac69e6f33a908c756f722 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 28 Feb 2019 19:53:35 -0500 Subject: Use TCC LUPD lock when updating CCB --- ports/atmel-samd/common-hal/pulseio/PWMOut.c | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pulseio/PWMOut.c index 19daaa14f..0908f9a01 100644 --- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PWMOut.c @@ -328,32 +328,29 @@ extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, #endif #ifdef SAMD51 Tc* tc = tc_insts[t->index]; - while (tc->COUNT16.SYNCBUSY.bit.CC1 != 0) { - // Wait for a previous value to be written. This can wait up to one period so we do - // other stuff in the meantime. - #ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP - #endif - } + while (tc->COUNT16.SYNCBUSY.bit.CC1 != 0) {} tc->COUNT16.CCBUF[1].reg = adjusted_duty; #endif } else { uint32_t adjusted_duty = ((uint64_t) tcc_periods[t->index]) * duty / 0xffff; uint8_t channel = tcc_channel(t); Tcc* tcc = tcc_insts[t->index]; - while ((tcc->SYNCBUSY.vec.CC & (1 << channel)) != 0) { - // Wait for a previous value to be written. This can wait up to one period so we do - // other stuff in the meantime. - #ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP - #endif - } + + // Write into the CC buffer register, which will be transferred to the + // CC register on an UPDATE (when period is finished). + // Do clock domain syncing as necessary. + + while (tcc->SYNCBUSY.reg != 0) {} + + // Lock out double-buffering while updating the CCB value. + tcc->CTRLBSET.bit.LUPD = 1; #ifdef SAMD21 tcc->CCB[channel].reg = adjusted_duty; #endif #ifdef SAMD51 tcc->CCBUF[channel].reg = adjusted_duty; #endif + tcc->CTRLBCLR.bit.LUPD = 1; } } @@ -368,7 +365,12 @@ uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { Tcc* tcc = tcc_insts[t->index]; uint8_t channel = tcc_channel(t); uint32_t cv = 0; + + while (tcc->SYNCBUSY.bit.CTRLB) {} + #ifdef SAMD21 + // If CCBV (CCB valid) is set, the CCB value hasn't yet been copied + // to the CC value. if ((tcc->STATUS.vec.CCBV & (1 << channel)) != 0) { cv = tcc->CCB[channel].reg; } else { @@ -425,7 +427,7 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, tc->COUNT16.CC[0].reg = new_top; #endif #ifdef SAMD51 - while (tc->COUNT16.SYNCBUSY.reg != 0) { + while (tc->COUNT16.SYNCBUSY.reg != 0) {} /* Wait for sync */ } tc->COUNT16.CCBUF[0].reg = new_top; @@ -438,14 +440,12 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, tcc->CTRLA.bit.PRESCALER = new_divisor; tcc_set_enable(tcc, true); } + while (tcc->SYNCBUSY.reg != 0) {} tcc_periods[t->index] = new_top; #ifdef SAMD21 tcc->PERB.bit.PERB = new_top; #endif #ifdef SAMD51 - while (tcc->SYNCBUSY.reg != 0) { - /* Wait for sync */ - } tcc->PERBUF.bit.PERBUF = new_top; #endif } -- cgit v1.2.3 From 3c24e893e98d158f939a8dba11c4b7783d998500 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 28 Feb 2019 23:38:26 -0500 Subject: Fix SYNCBUSY loop typo. --- ports/atmel-samd/common-hal/pulseio/PWMOut.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pulseio/PWMOut.c index 0908f9a01..dd85e8c02 100644 --- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PWMOut.c @@ -428,8 +428,6 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, #endif #ifdef SAMD51 while (tc->COUNT16.SYNCBUSY.reg != 0) {} - /* Wait for sync */ - } tc->COUNT16.CCBUF[0].reg = new_top; #endif } else { -- cgit v1.2.3 From 398c7060f8a51bb83b0f5e0c2a1611d684603d2b Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Wed, 27 Feb 2019 21:02:48 -0800 Subject: added monochrome, 8bpp indexed, and 32bpp ARGB BMPs --- locale/ID.po | 18 +++--- locale/circuitpython.pot | 18 +++--- locale/de_DE.po | 18 +++--- locale/en_US.po | 18 +++--- locale/es.po | 20 +++---- locale/fil.po | 20 +++---- locale/fr.po | 20 +++---- locale/it_IT.po | 20 +++---- locale/pt_BR.po | 18 +++--- shared-module/displayio/OnDiskBitmap.c | 104 ++++++++++++++++++++++----------- shared-module/displayio/OnDiskBitmap.h | 4 +- 11 files changed, 140 insertions(+), 138 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index bfa219222..c0b1dafdb 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -756,11 +756,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "Parity ganjil tidak didukung" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "Hanya 8 atau 16 bit mono dengan " @@ -771,13 +766,11 @@ msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -984,6 +977,9 @@ msgstr "Tidak dapat menemukan GCLK yang kosong" msgid "Unable to init parser" msgstr "" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Tidak dapat memasang filesystem kembali" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 318adc768..ea6b26c3f 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 19:57-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -730,11 +730,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "" @@ -745,13 +740,11 @@ msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -951,6 +944,9 @@ msgstr "" msgid "Unable to init parser" msgstr "" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index d9354f01f..ff9cafc76 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 19:57-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -748,11 +748,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "Eine ungerade Parität wird nicht unterstützt" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "Nur 8 oder 16 bit mono mit " @@ -764,13 +759,11 @@ msgid "Only bit maps of 8 bit color or less are supported" msgstr "" "Es werden nur Bitmaps mit einer Farbtiefe von 8 Bit oder weniger unterstützt" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -984,6 +977,9 @@ msgstr "Konnte keinen freien GCLK finden" msgid "Unable to init parser" msgstr "Parser konnte nicht gestartet werden" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Dateisystem konnte nicht wieder eingebunden werden." diff --git a/locale/en_US.po b/locale/en_US.po index cb9d85a18..45596fb62 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -730,11 +730,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "" @@ -745,13 +740,11 @@ msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -951,6 +944,9 @@ msgstr "" msgid "Unable to init parser" msgstr "" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "" diff --git a/locale/es.po b/locale/es.po index 06a1f10f9..996d58df6 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -770,11 +770,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "Paridad impar no soportada" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "Solo mono de 8 o 16 bit con " @@ -785,16 +780,14 @@ msgstr "Solo formato Windows, BMP sin comprimir soportado %d" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Solo se admiten bit maps de color de 8 bits o menos" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgstr "" + #, fuzzy msgid "Only slices with step=1 (aka None) are supported" msgstr "solo se admiten segmentos con step=1 (alias None)" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" -msgstr "" - msgid "Only tx supported on UART1 (GPIO2)." msgstr "Solo tx soportada en UART1 (GPIO2)" @@ -1003,6 +996,9 @@ msgstr "No se pudo encontrar un GCLK libre" msgid "Unable to init parser" msgstr "Incapaz de inicializar el parser" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Incapaz de montar de nuevo el sistema de archivos" diff --git a/locale/fil.po b/locale/fil.po index 0e79f2031..af5046d7c 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -768,11 +768,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "Odd na parity ay hindi supportado" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "Tanging 8 o 16 na bit mono na may " @@ -783,16 +778,14 @@ msgstr "Tanging Windows format, uncompressed BMP lamang ang supportado %d" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Tanging bit maps na may 8 bit color o mas mababa ang supportado" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgstr "" + #, fuzzy msgid "Only slices with step=1 (aka None) are supported" msgstr "ang mga slices lamang na may hakbang = 1 (aka None) ang sinusuportahan" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" -msgstr "" - msgid "Only tx supported on UART1 (GPIO2)." msgstr "Tanging suportado ang TX sa UART1 (GPIO2)." @@ -1005,6 +998,9 @@ msgstr "Hindi mahanap ang libreng GCLK" msgid "Unable to init parser" msgstr "Hindi ma-init ang parser" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Hindi ma-remount ang filesystem" diff --git a/locale/fr.po b/locale/fr.po index cb81f74ca..3fde90bde 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -772,11 +772,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "parité impaire non supportée" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "Uniquement 8 ou 16 bit mono avec " @@ -787,16 +782,14 @@ msgstr "Seul les BMP non-compressé au format Windows sont supportés %d" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Seules les bitmaps de 8bits par couleur ou moins sont supportées" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgstr "" + #, fuzzy msgid "Only slices with step=1 (aka None) are supported" msgstr "seuls les slices avec 'step=1' (cad None) sont supportées" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" -msgstr "" - msgid "Only tx supported on UART1 (GPIO2)." msgstr "Seul le tx est supporté sur l'UART1 (GPIO2)." @@ -1016,6 +1009,9 @@ msgstr "Impossible de trouver un GCLK libre" msgid "Unable to init parser" msgstr "Impossible d'initialiser le parser" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Impossible de remonter le système de fichiers" diff --git a/locale/it_IT.po b/locale/it_IT.po index 83664a146..ea1a42b11 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -767,11 +767,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "operazione I2C non supportata" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "" @@ -782,16 +777,14 @@ msgstr "Formato solo di Windows, BMP non compresso supportato %d" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Sono supportate solo bitmap con colori a 8 bit o meno" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgstr "" + #, fuzzy msgid "Only slices with step=1 (aka None) are supported" msgstr "solo slice con step=1 (aka None) sono supportate" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" -msgstr "" - msgid "Only tx supported on UART1 (GPIO2)." msgstr "Solo tx supportato su UART1 (GPIO2)." @@ -1003,6 +996,9 @@ msgstr "Impossibile trovare un GCLK libero" msgid "Unable to init parser" msgstr "Inizilizzazione del parser non possibile" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Imposssibile rimontare il filesystem" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 70e7bde4a..8477e1478 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -756,11 +756,6 @@ msgstr "" msgid "Odd parity is not supported" msgstr "I2C operação não suportada" -#, c-format -msgid "" -"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" -msgstr "" - msgid "Only 8 or 16 bit mono with " msgstr "" @@ -771,13 +766,11 @@ msgstr "Apenas formato Windows, BMP descomprimido suportado" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Apenas bit maps de cores de 8 bit ou menos são suportados" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -979,6 +972,9 @@ msgstr "Não é possível encontrar GCLK livre" msgid "Unable to init parser" msgstr "" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Não é possível remontar o sistema de arquivos" diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c index bc3064632..76d8fb2d1 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -56,42 +56,65 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, uint16_t bits_per_pixel = bmp_header[14]; uint32_t compression = read_word(bmp_header, 15); uint32_t number_of_colors = read_word(bmp_header, 23); + + bool indexed = ((bits_per_pixel <= 8) && (number_of_colors != 0)); self->bitfield_compressed = (compression == 3); - - self->grayscale = ((bits_per_pixel == 8) && (number_of_colors == 256)); + self->bits_per_pixel = bits_per_pixel; + self->width = read_word(bmp_header, 9); + self->height = read_word(bmp_header, 11); + if (bits_per_pixel == 16){ - if (((header_size == 124) || (header_size == 56)) && (self->bitfield_compressed)) { + if (((header_size >= 56)) || (self->bitfield_compressed)) { self->r_bitmask = read_word(bmp_header, 27); self->g_bitmask = read_word(bmp_header, 29); self->b_bitmask = read_word(bmp_header, 31); - if (!((self->r_bitmask == 0xf800) && (self->g_bitmask == 0x07e0) && (self->b_bitmask == 0x001f))){ - mp_raise_ValueError_varg(translate("Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x"), - self->r_bitmask, self->g_bitmask, self->b_bitmask); - } - } else if (header_size == 40){ // no bitmasks means 5:5:5 + } else { // no compression or short header means 5:5:5 self->r_bitmask = 0x7c00; self->g_bitmask = 0x3e0; self->b_bitmask = 0x1f; } + } else if ((indexed) && (self->bits_per_pixel != 1)) { + uint16_t palette_size = number_of_colors * sizeof(uint32_t); + uint16_t palette_offset = 0xe + header_size; + + self->palette_data = m_malloc(palette_size, false); + + f_rewind(&self->file->fp); + f_lseek(&self->file->fp, palette_offset); + + UINT palette_bytes_read; + if (f_read(&self->file->fp, self->palette_data, palette_size, &palette_bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (palette_bytes_read != palette_size) { + mp_raise_ValueError(translate("Unable to read color palette data")); + } + - } else if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124) || - !(compression == 0)) { + } else if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124)) { mp_raise_ValueError_varg(translate("Only Windows format, uncompressed BMP supported %d"), header_size); } - if (bits_per_pixel < 16 && !(self->grayscale)) { - mp_raise_ValueError_varg(translate("Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale BMP supported %d"), bits_per_pixel); + if ((bits_per_pixel == 4 ) || (( bits_per_pixel == 8) && (number_of_colors == 0))) { + mp_raise_ValueError_varg(translate("Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d"), bits_per_pixel); } - self->bytes_per_pixel = bits_per_pixel / 8; - self->width = read_word(bmp_header, 9); - self->height = read_word(bmp_header, 11); - uint32_t byte_width = self->width * self->bytes_per_pixel; - self->stride = byte_width; - // Rows are word aligned. - if (self->stride % 4 != 0) { - self->stride += 4 - self->stride % 4; + + if (self->bits_per_pixel >=8){ + self->stride = (self->width * (bits_per_pixel / 8)); + // Rows are word aligned. + if (self->stride % 4 != 0) { + self->stride += 4 - self->stride % 4; + } + + } else { + uint32_t bit_stride = self->width; + if (bit_stride % 32 != 0) { + bit_stride += 32 - bit_stride % 32; + } + self->stride = (bit_stride / 8); } + } @@ -100,39 +123,54 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s if (x < 0 || x >= self->width || y < 0 || y >= self->height) { return 0; } - uint32_t location = self->data_offset + (self->height - y) * self->stride + x * self->bytes_per_pixel; + uint32_t location; + uint8_t bytes_per_pixel = (self->bits_per_pixel / 8) ? (self->bits_per_pixel /8) : 1; + if (self->bits_per_pixel >= 8){ + location = self->data_offset + (self->height - y) * self->stride + x * bytes_per_pixel; + } else { + location = self->data_offset + (self->height - y) * self->stride + x / 8; + } // We don't cache here because the underlying FS caches sectors. f_lseek(&self->file->fp, location); UINT bytes_read; - uint32_t pixel = 0; - uint32_t result = f_read(&self->file->fp, &pixel, self->bytes_per_pixel, &bytes_read); + uint32_t pixel = 0; // this name is stale + uint32_t result = f_read(&self->file->fp, &pixel, bytes_per_pixel, &bytes_read); if (result == FR_OK) { uint32_t tmp = 0; uint8_t red; uint8_t green; uint8_t blue; - if (self->grayscale){ - red = pixel; - green = pixel; - blue = pixel; - tmp = (red << 16 | green << 8 | blue); + if (self->bits_per_pixel == 1){ + uint8_t bit_offset = x%8; + tmp = ( pixel & (0x80 >> (bit_offset))) >> (7 - bit_offset); + if (tmp == 1) { + return 0x00FFFFFF; + } else { + return 0x00000000; + } + } else if (bytes_per_pixel == 1){ + blue = ((self->palette_data[pixel] & 0xFF) >> 0); + red = ((self->palette_data[pixel] & 0xFF0000) >> 16); + green = ((self->palette_data[pixel] & 0xFF00) >> 8); + tmp = (red << 16 | green << 8 | blue ); return tmp; - } else if (self->bytes_per_pixel == 2) { - if (self->bitfield_compressed){ + } else if (bytes_per_pixel == 2) { + if (self->g_bitmask == 0x07e0){ // 565 red =((pixel & self->r_bitmask) >>11); green = ((pixel & self->g_bitmask) >>5); blue = ((pixel & self->b_bitmask) >> 0); - } else { + } else { // 555 red =((pixel & self->r_bitmask) >>10); green = ((pixel & self->g_bitmask) >>4); blue = ((pixel & self->b_bitmask) >> 0); } tmp = (red << 19 | green << 10 | blue << 3); return tmp; - }else { + }else if ((bytes_per_pixel == 4) && (self->bitfield_compressed)){ + return pixel & 0x00FFFFFF; + } else { return pixel; } - } return 0; } diff --git a/shared-module/displayio/OnDiskBitmap.h b/shared-module/displayio/OnDiskBitmap.h index 2102863d6..28426f11b 100644 --- a/shared-module/displayio/OnDiskBitmap.h +++ b/shared-module/displayio/OnDiskBitmap.h @@ -44,9 +44,9 @@ typedef struct { uint32_t g_bitmask; uint32_t b_bitmask; bool bitfield_compressed; - bool grayscale; pyb_file_obj_t* file; - uint8_t bytes_per_pixel; + uint8_t bits_per_pixel; + uint32_t* palette_data; } displayio_ondiskbitmap_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_ONDISKBITMAP_H -- cgit v1.2.3 From 45fea86554d42d07360ec16574908bc96c5e37ec Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 14:59:21 +0100 Subject: Rebase on top of CircuitPython 4.x --- ports/atmel-samd/boards/pewpew10/mpconfigboard.h | 2 -- ports/atmel-samd/boards/pewpew10/mpconfigboard.mk | 9 +++++++++ ports/atmel-samd/boards/pewpew10/pins.c | 2 +- ports/atmel-samd/timer_handler.c | 12 ++++++++++-- ports/atmel-samd/timer_handler.h | 1 + py/circuitpy_defns.mk | 2 ++ py/circuitpy_mpconfig.h | 2 ++ py/circuitpy_mpconfig.mk | 5 +++++ shared-bindings/_pew/PewPew.c | 17 ++++++++--------- shared-module/_pew/PewPew.c | 12 ++++++++---- 10 files changed, 46 insertions(+), 18 deletions(-) diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h index 3fd1cbce1..09618431b 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h @@ -7,8 +7,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 -#include "internal_flash.h" - #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk index cf3004a4d..eeb5632ef 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk @@ -11,3 +11,12 @@ CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 FROZEN_MPY_DIRS += $(TOP)/frozen/pewpew10 + +CIRCUITPY_PEW = 1 +CIRCUITPY_ANALOGIO = 1 +CIRCUITPY_MATH = 0 +CIRCUITPY_NEOPIXEL_WRITE = 1 +CIRCUITPY_RTC = 0 +CIRCUITPY_SAMD = 0 +CIRCUITPY_USB_MIDI = 0 +CIRCUITPY_SMALL_BUILD = 1 diff --git a/ports/atmel-samd/boards/pewpew10/pins.c b/ports/atmel-samd/boards/pewpew10/pins.c index 499e6270b..082394d17 100644 --- a/ports/atmel-samd/boards/pewpew10/pins.c +++ b/ports/atmel-samd/boards/pewpew10/pins.c @@ -1,6 +1,6 @@ #include "shared-bindings/board/__init__.h" -#include "board_busses.h" +#include "supervisor/shared/board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_R1), MP_ROM_PTR(&pin_PA05) }, diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index 26f984d96..ac162329e 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -30,6 +30,7 @@ #include "timer_handler.h" #include "common-hal/pulseio/PulseOut.h" +#include "shared-module/_pew/PewPew.h" static uint8_t tc_handler[TC_INST_NUM]; @@ -44,8 +45,15 @@ void shared_timer_handler(bool is_tc, uint8_t index) { // Make sure to add the handler #define to timer_handler.h if (is_tc) { uint8_t handler = tc_handler[index]; - if (handler == TC_HANDLER_PULSEOUT) { - pulseout_interrupt_handler(index); + switch(handler) { + case TC_HANDLER_PULSEOUT: + pulseout_interrupt_handler(index); + break; + case TC_HANDLER_PEW: + pewpew_interrupt_handler(index); + break; + default: + break; } } } diff --git a/ports/atmel-samd/timer_handler.h b/ports/atmel-samd/timer_handler.h index f7a6e6e0e..e249fca36 100644 --- a/ports/atmel-samd/timer_handler.h +++ b/ports/atmel-samd/timer_handler.h @@ -28,6 +28,7 @@ #define TC_HANDLER_NO_INTERRUPT 0x0 #define TC_HANDLER_PULSEOUT 0x1 +#define TC_HANDLER_PEW 0x2 void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler); void shared_timer_handler(bool is_tc, uint8_t index); diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 080263487..c10edfe4e 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -321,6 +321,8 @@ $(filter $(SRC_PATTERNS), \ terminalio/__init__.c \ uheap/__init__.c \ ustack/__init__.c \ + _pew/__init__.c \ + _pew/PewPew.c \ ) ifeq ($(INTERNAL_LIBM),1) diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index c20c0fb66..25aabc292 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -543,6 +543,7 @@ extern const struct _mp_obj_module_t pew_module; USB_HID_MODULE \ USB_MIDI_MODULE \ USTACK_MODULE \ + PEW_MODULE \ // If weak links are enabled, just include strong links in the main list of modules, // and also include the underscore alternate names. @@ -569,6 +570,7 @@ extern const struct _mp_obj_module_t pew_module; vstr_t *repl_line; \ mp_obj_t rtc_time_source; \ mp_obj_t gamepad_singleton; \ + mp_obj_t pew_singleton; \ mp_obj_t terminal_tilegrid_tiles; \ FLASH_ROOT_POINTERS \ NETWORK_ROOT_POINTERS \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index a4a59170f..54a38dfee 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -213,6 +213,11 @@ CIRCUITPY_USB_MIDI = 1 endif CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI) +ifndef CIRCUITPY_PEW +CIRCUITPY_PEW = 0 +endif +CFLAGS += -DCIRCUITPY_PEW=$(CIRCUITPY_PEW) + # For debugging. ifndef CIRCUITPY_USTACK CIRCUITPY_USTACK = 0 diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 69c9ff4fc..19eb00736 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -32,6 +32,7 @@ #include "shared-bindings/util.h" #include "PewPew.h" #include "shared-module/_pew/PewPew.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: _pew @@ -49,10 +50,8 @@ //| //| STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, - size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 4, 4, true); - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); + const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 4, 4, true); enum { ARG_buffer, ARG_rows, ARG_cols, ARG_buttons }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -61,7 +60,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, { MP_QSTR_buttons, MP_ARG_OBJ | MP_ARG_REQUIRED }, }; 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), + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t bufinfo; @@ -76,12 +75,12 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, mp_obj_get_array(args[ARG_cols].u_obj, &cols_size, &cols); if (bufinfo.len != rows_size * cols_size) { - mp_raise_TypeError("wrong buffer size"); + mp_raise_TypeError(translate("")); } for (size_t i = 0; i < rows_size; ++i) { if (!MP_OBJ_IS_TYPE(rows[i], &digitalio_digitalinout_type)) { - mp_raise_TypeError("expected a DigitalInOut"); + mp_raise_TypeError(translate("")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(rows[i]); raise_error_if_deinited( @@ -90,7 +89,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, for (size_t i = 0; i < cols_size; ++i) { if (!MP_OBJ_IS_TYPE(cols[i], &digitalio_digitalinout_type)) { - mp_raise_TypeError("expected a DigitalInOut"); + mp_raise_TypeError(translate("")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(cols[i]); raise_error_if_deinited( @@ -99,7 +98,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, if (!MP_OBJ_IS_TYPE(args[ARG_buttons].u_obj, &digitalio_digitalinout_type)) { - mp_raise_TypeError("expected a DigitalInOut"); + mp_raise_TypeError(translate("")); } digitalio_digitalinout_obj_t *buttons = MP_OBJ_TO_PTR( args[ARG_buttons].u_obj); diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index cbe7164bc..2900f2ac7 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -35,6 +35,8 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/util.h" #include "samd/timers.h" +#include "supervisor/shared/translate.h" +#include "timer_handler.h" static uint8_t pewpew_tc_index = 0xff; @@ -77,10 +79,11 @@ void pew_init() { } } if (tc == NULL) { - mp_raise_RuntimeError("All timers in use"); + mp_raise_RuntimeError(translate("")); } pewpew_tc_index = index; + set_timer_handler(true, index, TC_HANDLER_PEW); // We use GCLK0 for SAMD21 and GCLK1 for SAMD51 because they both run // at 48mhz making our math the same across the boards. @@ -106,7 +109,6 @@ void pew_init() { #endif tc_set_enable(tc, true); - //tc->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_STOP; tc->COUNT16.CC[0].reg = 160; // Clear our interrupt in case it was set earlier @@ -117,7 +119,9 @@ void pew_init() { } void pew_reset(void) { - tc_insts[pewpew_tc_index]->COUNT16.CTRLA.bit.ENABLE = 0; - pewpew_tc_index = 0xff; + if (pewpew_tc_index != 0xff) { + tc_reset(tc_insts[pewpew_tc_index]); + pewpew_tc_index = 0xff; + } MP_STATE_VM(pew_singleton) = NULL; } -- cgit v1.2.3 From fb027f202476f5ac8285a63084b312d25904052c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 1 Mar 2019 09:06:03 -0500 Subject: Update PyPortal pins to rev C --- ports/atmel-samd/boards/pyportal/pins.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ports/atmel-samd/boards/pyportal/pins.c b/ports/atmel-samd/boards/pyportal/pins.c index 24ebd92bb..6a4736a11 100644 --- a/ports/atmel-samd/boards/pyportal/pins.c +++ b/ports/atmel-samd/boards/pyportal/pins.c @@ -11,18 +11,21 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_AUDIO_OUT), MP_ROM_PTR(&pin_PA02) }, { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, // analog out/in { MP_OBJ_NEW_QSTR(MP_QSTR_SPEAKER_ENABLE), MP_ROM_PTR(&pin_PA27) }, + + // Light sensor { MP_OBJ_NEW_QSTR(MP_QSTR_LIGHT), MP_ROM_PTR(&pin_PA07) }, { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA07) }, // STEMMA connectors - { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA04) }, // D3 - { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA04) }, // A1/D3 - { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA05) }, // D4 - { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) }, // A4/D4 + { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) }, // Indicator LED - { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA27) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_PA27) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PB23) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_PB23) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL),MP_ROM_PTR(&pin_PB22) }, // LCD pins -- cgit v1.2.3 From 18870255ea4c18eddcbd91ffd36517c728e34907 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 15:06:24 +0100 Subject: Remove the pewpew70 board definition, leave only pewpew10 --- ports/atmel-samd/boards/pewpew70/board.c | 38 ----------------------- ports/atmel-samd/boards/pewpew70/mpconfigboard.h | 12 ------- ports/atmel-samd/boards/pewpew70/mpconfigboard.mk | 13 -------- ports/atmel-samd/boards/pewpew70/pins.c | 31 ------------------ 4 files changed, 94 deletions(-) delete mode 100644 ports/atmel-samd/boards/pewpew70/board.c delete mode 100644 ports/atmel-samd/boards/pewpew70/mpconfigboard.h delete mode 100644 ports/atmel-samd/boards/pewpew70/mpconfigboard.mk delete mode 100644 ports/atmel-samd/boards/pewpew70/pins.c diff --git a/ports/atmel-samd/boards/pewpew70/board.c b/ports/atmel-samd/boards/pewpew70/board.c deleted file mode 100644 index c8e20206a..000000000 --- a/ports/atmel-samd/boards/pewpew70/board.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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" - -void board_init(void) -{ -} - -bool board_requests_safe_mode(void) { - return false; -} - -void reset_board(void) { -} diff --git a/ports/atmel-samd/boards/pewpew70/mpconfigboard.h b/ports/atmel-samd/boards/pewpew70/mpconfigboard.h deleted file mode 100644 index e839bc5ea..000000000 --- a/ports/atmel-samd/boards/pewpew70/mpconfigboard.h +++ /dev/null @@ -1,12 +0,0 @@ -#define MICROPY_HW_BOARD_NAME "PewPew 7.0" -#define MICROPY_HW_MCU_NAME "samd21e18" - -#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25) -#define MICROPY_PORT_B (0) -#define MICROPY_PORT_C (0) - -#define CIRCUITPY_INTERNAL_NVM_SIZE 0 - -#include "internal_flash.h" - -#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk deleted file mode 100644 index f316bfb2e..000000000 --- a/ports/atmel-samd/boards/pewpew70/mpconfigboard.mk +++ /dev/null @@ -1,13 +0,0 @@ -LD_FILE = boards/samd21x18-bootloader.ld -USB_VID = 0x239A -USB_PID = 0x801D -USB_PRODUCT = "PewPew 7.0" -USB_MANUFACTURER = "Radomir Dopieralski" - -INTERNAL_FLASH_FILESYSTEM = 1 -LONGINT_IMPL = NONE - -CHIP_VARIANT = SAMD21E18A -CHIP_FAMILY = samd21 - -FROZEN_MPY_DIRS += $(TOP)/frozen/pewpew70 diff --git a/ports/atmel-samd/boards/pewpew70/pins.c b/ports/atmel-samd/boards/pewpew70/pins.c deleted file mode 100644 index 9fca3c4ad..000000000 --- a/ports/atmel-samd/boards/pewpew70/pins.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "shared-bindings/board/__init__.h" - -#include "board_busses.h" - -STATIC const mp_rom_map_elem_t board_global_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_R1), MP_ROM_PTR(&pin_PA08) }, - { MP_ROM_QSTR(MP_QSTR_R2), MP_ROM_PTR(&pin_PA15) }, - { MP_ROM_QSTR(MP_QSTR_R3), MP_ROM_PTR(&pin_PA01) }, - { MP_ROM_QSTR(MP_QSTR_R4), MP_ROM_PTR(&pin_PA11) }, - { MP_ROM_QSTR(MP_QSTR_R5), MP_ROM_PTR(&pin_PA27) }, - { MP_ROM_QSTR(MP_QSTR_R6), MP_ROM_PTR(&pin_PA00) }, - { MP_ROM_QSTR(MP_QSTR_R7), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_R8), MP_ROM_PTR(&pin_PA19) }, - - { MP_ROM_QSTR(MP_QSTR_C1), MP_ROM_PTR(&pin_PA14) }, - { MP_ROM_QSTR(MP_QSTR_C2), MP_ROM_PTR(&pin_PA23) }, - { MP_ROM_QSTR(MP_QSTR_C3), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_C4), MP_ROM_PTR(&pin_PA09) }, - { MP_ROM_QSTR(MP_QSTR_C5), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_C6), MP_ROM_PTR(&pin_PA10) }, - { MP_ROM_QSTR(MP_QSTR_C7), MP_ROM_PTR(&pin_PA16) }, - { MP_ROM_QSTR(MP_QSTR_C8), MP_ROM_PTR(&pin_PA17) }, - - { MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_PTR(&pin_PA04) }, - { MP_ROM_QSTR(MP_QSTR_DOWN), MP_ROM_PTR(&pin_PA03) }, - { MP_ROM_QSTR(MP_QSTR_LEFT), MP_ROM_PTR(&pin_PA02) }, - { MP_ROM_QSTR(MP_QSTR_RIGHT), MP_ROM_PTR(&pin_PA05) }, - { MP_ROM_QSTR(MP_QSTR_O), MP_ROM_PTR(&pin_PA07) }, - { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA06) }, -}; -MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); -- cgit v1.2.3 From f5f493222067a0be2123de1c6cea90ac4f06aef6 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 15:09:00 +0100 Subject: Clean unused include from tick.c --- ports/atmel-samd/tick.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/atmel-samd/tick.c b/ports/atmel-samd/tick.c index 44b631838..149347793 100644 --- a/ports/atmel-samd/tick.c +++ b/ports/atmel-samd/tick.c @@ -30,7 +30,6 @@ #include "supervisor/shared/autoreload.h" #include "shared-module/gamepad/__init__.h" -#include "shared-module/_pew/__init__.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Processor.h" -- cgit v1.2.3 From 3826ca41941922d820c1c2a24c3a335876254619 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 15:10:43 +0100 Subject: Rename internal pins to add underscore in front --- frozen/pewpew10/pew.py | 34 ++++++++++++++++----------------- ports/atmel-samd/boards/pewpew10/pins.c | 34 ++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/frozen/pewpew10/pew.py b/frozen/pewpew10/pew.py index 8d60d0ec6..99819cd5a 100644 --- a/frozen/pewpew10/pew.py +++ b/frozen/pewpew10/pew.py @@ -192,26 +192,26 @@ def init(): _tick = time.monotonic() _rows = ( - digitalio.DigitalInOut(board.R1), - digitalio.DigitalInOut(board.R2), - digitalio.DigitalInOut(board.R3), - digitalio.DigitalInOut(board.R4), - digitalio.DigitalInOut(board.R5), - digitalio.DigitalInOut(board.R6), - digitalio.DigitalInOut(board.R7), - digitalio.DigitalInOut(board.R8), + digitalio.DigitalInOut(board._R1), + digitalio.DigitalInOut(board._R2), + digitalio.DigitalInOut(board._R3), + digitalio.DigitalInOut(board._R4), + digitalio.DigitalInOut(board._R5), + digitalio.DigitalInOut(board._R6), + digitalio.DigitalInOut(board._R7), + digitalio.DigitalInOut(board._R8), ) _cols = ( - digitalio.DigitalInOut(board.C1), - digitalio.DigitalInOut(board.C2), - digitalio.DigitalInOut(board.C3), - digitalio.DigitalInOut(board.C4), - digitalio.DigitalInOut(board.C5), - digitalio.DigitalInOut(board.C6), - digitalio.DigitalInOut(board.C7), - digitalio.DigitalInOut(board.C8), + digitalio.DigitalInOut(board._C1), + digitalio.DigitalInOut(board._C2), + digitalio.DigitalInOut(board._C3), + digitalio.DigitalInOut(board._C4), + digitalio.DigitalInOut(board._C5), + digitalio.DigitalInOut(board._C6), + digitalio.DigitalInOut(board._C7), + digitalio.DigitalInOut(board._C8), ) - _buttons = digitalio.DigitalInOut(board.BUTTONS) + _buttons = digitalio.DigitalInOut(board._BUTTONS) _pew.PewPew(_screen.buffer, _rows, _cols, _buttons) keys = _pew.get_pressed diff --git a/ports/atmel-samd/boards/pewpew10/pins.c b/ports/atmel-samd/boards/pewpew10/pins.c index 082394d17..4a8225ad9 100644 --- a/ports/atmel-samd/boards/pewpew10/pins.c +++ b/ports/atmel-samd/boards/pewpew10/pins.c @@ -3,23 +3,23 @@ #include "supervisor/shared/board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_R1), MP_ROM_PTR(&pin_PA05) }, - { MP_ROM_QSTR(MP_QSTR_R2), MP_ROM_PTR(&pin_PA11) }, - { MP_ROM_QSTR(MP_QSTR_R3), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_R4), MP_ROM_PTR(&pin_PA09) }, - { MP_ROM_QSTR(MP_QSTR_R5), MP_ROM_PTR(&pin_PA16) }, - { MP_ROM_QSTR(MP_QSTR_R6), MP_ROM_PTR(&pin_PA27) }, - { MP_ROM_QSTR(MP_QSTR_R7), MP_ROM_PTR(&pin_PA17) }, - { MP_ROM_QSTR(MP_QSTR_R8), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR__R1), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR__R2), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR__R3), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR__R4), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR__R5), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR__R6), MP_ROM_PTR(&pin_PA27) }, + { MP_ROM_QSTR(MP_QSTR__R7), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR__R8), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_C8), MP_ROM_PTR(&pin_PA10) }, - { MP_ROM_QSTR(MP_QSTR_C7), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_C6), MP_ROM_PTR(&pin_PA19) }, - { MP_ROM_QSTR(MP_QSTR_C5), MP_ROM_PTR(&pin_PA06) }, - { MP_ROM_QSTR(MP_QSTR_C4), MP_ROM_PTR(&pin_PA23) }, - { MP_ROM_QSTR(MP_QSTR_C3), MP_ROM_PTR(&pin_PA07) }, - { MP_ROM_QSTR(MP_QSTR_C2), MP_ROM_PTR(&pin_PA14) }, - { MP_ROM_QSTR(MP_QSTR_C1), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR__C8), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR__C7), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR__C6), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR__C5), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR__C4), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR__C3), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR__C2), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR__C1), MP_ROM_PTR(&pin_PA15) }, { MP_ROM_QSTR(MP_QSTR_P1), MP_ROM_PTR(&pin_PA30) }, { MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_PA31) }, @@ -29,7 +29,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_PA03) }, { MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_PA04) }, - { MP_ROM_QSTR(MP_QSTR_BUTTONS), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR__BUTTONS), MP_ROM_PTR(&pin_PA08) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); -- cgit v1.2.3 From 8e50aeb06f24a264b474d62b52c7f59220db7195 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 15:54:16 +0100 Subject: Fix pew.tick() to not accumulate error over time --- frozen/pewpew10/pew.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frozen/pewpew10/pew.py b/frozen/pewpew10/pew.py index 99819cd5a..333b193d5 100644 --- a/frozen/pewpew10/pew.py +++ b/frozen/pewpew10/pew.py @@ -63,8 +63,12 @@ def show(pix): def tick(delay): global _tick + now = time.monotonic() _tick += delay - time.sleep(max(0, _tick - time.monotonic())) + if _tick < now: + _tick = now + else: + time.sleep(_tick - now) class GameOver(Exception): -- cgit v1.2.3 From 89b2788d119c811327b366e061481fbcc96cbc65 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 16:05:15 +0100 Subject: Apply review fixes: * fix formatting * fix copyrights * fix CIRCUITPYTHON_GAMEPAD guards * add CIRCUITPYTHON_PEW guards to reset * fix module list order --- ports/atmel-samd/boards/pewpew10/board.c | 3 +-- ports/atmel-samd/supervisor/port.c | 6 ++++-- py/circuitpy_mpconfig.h | 2 +- shared-bindings/_pew/PewPew.c | 2 +- shared-bindings/_pew/PewPew.h | 2 +- shared-bindings/_pew/__init__.c | 2 +- shared-module/_pew/PewPew.c | 2 +- shared-module/_pew/PewPew.h | 2 +- shared-module/_pew/__init__.c | 2 +- shared-module/_pew/__init__.h | 2 +- 10 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ports/atmel-samd/boards/pewpew10/board.c b/ports/atmel-samd/boards/pewpew10/board.c index c8e20206a..d7e856d61 100644 --- a/ports/atmel-samd/boards/pewpew10/board.c +++ b/ports/atmel-samd/boards/pewpew10/board.c @@ -26,8 +26,7 @@ #include "boards/board.h" -void board_init(void) -{ +void board_init(void) { } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 4aa07a6db..b3f4a2e89 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -68,7 +68,7 @@ #include "tusb.h" -#ifdef CIRCUITPY_GAMEPAD_TICKS +#if CIRCUITPY_GAMEPAD #include "shared-module/gamepad/__init__.h" #endif #include "shared-module/_pew/PewPew.h" @@ -223,10 +223,12 @@ void reset_port(void) { reset_gclks(); -#ifdef CIRCUITPY_GAMEPAD_TICKS +#if CIRCUITPY_GAMEPAD gamepad_reset(); #endif +#ifdef CIRCUITPY_PEW pew_reset(); +#endif reset_event_system(); diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 25aabc292..520f7c612 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -528,6 +528,7 @@ extern const struct _mp_obj_module_t pew_module; NETWORK_MODULE \ SOCKET_MODULE \ WIZNET_MODULE \ + PEW_MODULE \ PIXELBUF_MODULE \ PULSEIO_MODULE \ RANDOM_MODULE \ @@ -543,7 +544,6 @@ extern const struct _mp_obj_module_t pew_module; USB_HID_MODULE \ USB_MIDI_MODULE \ USTACK_MODULE \ - PEW_MODULE \ // If weak links are enabled, just include strong links in the main list of modules, // and also include the underscore alternate names. diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 19eb00736..d0803e0a9 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * Copyright (c) 2019 Radomir Dopieralski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/_pew/PewPew.h b/shared-bindings/_pew/PewPew.h index 13633ef93..f76384757 100644 --- a/shared-bindings/_pew/PewPew.h +++ b/shared-bindings/_pew/PewPew.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * Copyright (c) 2019 Radomir Dopieralski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/_pew/__init__.c b/shared-bindings/_pew/__init__.c index 652d95f1b..6c5520ac5 100644 --- a/shared-bindings/_pew/__init__.c +++ b/shared-bindings/_pew/__init__.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * Copyright (c) 2019 Radomir Dopieralski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index 2900f2ac7..3fea689a3 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * Copyright (c) 2019 Radomir Dopieralski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-module/_pew/PewPew.h b/shared-module/_pew/PewPew.h index 57b25c3a0..da1cae0a2 100644 --- a/shared-module/_pew/PewPew.h +++ b/shared-module/_pew/PewPew.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * Copyright (c) 2019 Radomir Dopieralski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-module/_pew/__init__.c b/shared-module/_pew/__init__.c index e44a4c0e3..90fba3990 100644 --- a/shared-module/_pew/__init__.c +++ b/shared-module/_pew/__init__.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries + * Copyright (c) 2019 Radomir Dopieralski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-module/_pew/__init__.h b/shared-module/_pew/__init__.h index f85dec749..4f953c610 100644 --- a/shared-module/_pew/__init__.h +++ b/shared-module/_pew/__init__.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Radomir Dopieralski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal -- cgit v1.2.3 From a9074f7bd10c102925510229bfc43e550c989cb9 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 16:11:22 +0100 Subject: More style fixes --- shared-module/_pew/PewPew.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index 3fea689a3..755b88394 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -43,9 +43,13 @@ static uint8_t pewpew_tc_index = 0xff; void pewpew_interrupt_handler(uint8_t index) { - if (index != pewpew_tc_index) return; + if (index != pewpew_tc_index) { + return; + } Tc* tc = tc_insts[index]; - if (!tc->COUNT16.INTFLAG.bit.MC0) return; + if (!tc->COUNT16.INTFLAG.bit.MC0) { + return; + } pew_tick(); -- cgit v1.2.3 From 014595bff593e51012483515adf92e21c7126f5d Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Fri, 1 Mar 2019 07:16:14 -0800 Subject: fixed whitespace, clarified variable name, and updated error messages --- locale/ID.po | 9 ++++++--- locale/circuitpython.pot | 9 ++++++--- locale/de_DE.po | 14 +++++++++---- locale/en_US.po | 9 ++++++--- locale/es.po | 14 +++++++++---- locale/fil.po | 14 +++++++++---- locale/fr.po | 14 +++++++++---- locale/it_IT.po | 14 +++++++++---- locale/pt_BR.po | 14 +++++++++---- shared-module/displayio/OnDiskBitmap.c | 36 +++++++++++++++++----------------- 10 files changed, 96 insertions(+), 51 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index c0b1dafdb..f5fadce49 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -760,14 +760,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "Hanya 8 atau 16 bit mono dengan " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index ea6b26c3f..0808ae43e 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -734,14 +734,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" diff --git a/locale/de_DE.po b/locale/de_DE.po index ff9cafc76..941a5d5d1 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -752,15 +752,18 @@ msgid "Only 8 or 16 bit mono with " msgstr "Nur 8 oder 16 bit mono mit " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Nur unkomprimiertes Windows-Format (BMP) unterstützt %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" "Es werden nur Bitmaps mit einer Farbtiefe von 8 Bit oder weniger unterstützt" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" @@ -2138,3 +2141,6 @@ msgstr "y Wert außerhalb der Grenzen" msgid "zero step" msgstr "" + +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Nur unkomprimiertes Windows-Format (BMP) unterstützt %d" diff --git a/locale/en_US.po b/locale/en_US.po index 45596fb62..01cbaeb51 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -734,14 +734,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" diff --git a/locale/es.po b/locale/es.po index 996d58df6..a4eceb1fb 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -774,14 +774,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "Solo mono de 8 o 16 bit con " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Solo formato Windows, BMP sin comprimir soportado %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Solo se admiten bit maps de color de 8 bits o menos" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" #, fuzzy @@ -2164,5 +2167,8 @@ msgstr "address fuera de límites" msgid "zero step" msgstr "paso cero" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Solo formato Windows, BMP sin comprimir soportado %d" + #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Solo color verdadero (24 bpp o superior) BMP admitido %x" diff --git a/locale/fil.po b/locale/fil.po index af5046d7c..fb6002a57 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -772,14 +772,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "Tanging 8 o 16 na bit mono na may " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Tanging Windows format, uncompressed BMP lamang ang supportado %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Tanging bit maps na may 8 bit color o mas mababa ang supportado" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" #, fuzzy @@ -2170,5 +2173,8 @@ msgstr "wala sa sakop ang address" msgid "zero step" msgstr "zero step" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Tanging Windows format, uncompressed BMP lamang ang supportado %d" + #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Dapat true color (24 bpp o mas mataas) BMP lamang ang supportado %x" diff --git a/locale/fr.po b/locale/fr.po index 3fde90bde..c937a4b5b 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -776,14 +776,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "Uniquement 8 ou 16 bit mono avec " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Seul les BMP non-compressé au format Windows sont supportés %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Seules les bitmaps de 8bits par couleur ou moins sont supportées" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" #, fuzzy @@ -2194,5 +2197,8 @@ msgstr "adresse hors limites" msgid "zero step" msgstr "'step' nul" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Seul les BMP non-compressé au format Windows sont supportés %d" + #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Seul les BMP 24bits ou plus sont supportés %x" diff --git a/locale/it_IT.po b/locale/it_IT.po index ea1a42b11..64fb22128 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -771,14 +771,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Formato solo di Windows, BMP non compresso supportato %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Sono supportate solo bitmap con colori a 8 bit o meno" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" #, fuzzy @@ -2166,5 +2169,8 @@ msgstr "indirizzo fuori limite" msgid "zero step" msgstr "zero step" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Formato solo di Windows, BMP non compresso supportato %d" + #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Solo BMP true color (24 bpp o superiore) sono supportati %x" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 8477e1478..cf46dfbc5 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -760,14 +760,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Apenas formato Windows, BMP descomprimido suportado" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Apenas bit maps de cores de 8 bit ou menos são suportados" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" @@ -2114,5 +2117,8 @@ msgstr "" msgid "zero step" msgstr "passo zero" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Apenas formato Windows, BMP descomprimido suportado" + #~ msgid "Only true color (24 bpp or higher) BMP supported %x" #~ msgstr "Apenas cores verdadeiras (24 bpp ou maior) BMP suportadas" diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c index 76d8fb2d1..92735e53c 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -93,11 +93,11 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, } else if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124)) { - mp_raise_ValueError_varg(translate("Only Windows format, uncompressed BMP supported %d"), header_size); + mp_raise_ValueError_varg(translate("Only Windows format, uncompressed BMP supported: given header size is %d"), header_size); } if ((bits_per_pixel == 4 ) || (( bits_per_pixel == 8) && (number_of_colors == 0))) { - mp_raise_ValueError_varg(translate("Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d"), bits_per_pixel); + mp_raise_ValueError_varg(translate("Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp given"), bits_per_pixel); } if (self->bits_per_pixel >=8){ @@ -133,8 +133,8 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s // We don't cache here because the underlying FS caches sectors. f_lseek(&self->file->fp, location); UINT bytes_read; - uint32_t pixel = 0; // this name is stale - uint32_t result = f_read(&self->file->fp, &pixel, bytes_per_pixel, &bytes_read); + uint32_t pixel_data = 0; // this name is stale + uint32_t result = f_read(&self->file->fp, &pixel_data, bytes_per_pixel, &bytes_read); if (result == FR_OK) { uint32_t tmp = 0; uint8_t red; @@ -142,34 +142,34 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s uint8_t blue; if (self->bits_per_pixel == 1){ uint8_t bit_offset = x%8; - tmp = ( pixel & (0x80 >> (bit_offset))) >> (7 - bit_offset); + tmp = ( pixel_data & (0x80 >> (bit_offset))) >> (7 - bit_offset); if (tmp == 1) { return 0x00FFFFFF; } else { return 0x00000000; } } else if (bytes_per_pixel == 1){ - blue = ((self->palette_data[pixel] & 0xFF) >> 0); - red = ((self->palette_data[pixel] & 0xFF0000) >> 16); - green = ((self->palette_data[pixel] & 0xFF00) >> 8); + blue = ((self->palette_data[pixel_data] & 0xFF) >> 0); + red = ((self->palette_data[pixel_data] & 0xFF0000) >> 16); + green = ((self->palette_data[pixel_data] & 0xFF00) >> 8); tmp = (red << 16 | green << 8 | blue ); return tmp; } else if (bytes_per_pixel == 2) { - if (self->g_bitmask == 0x07e0){ // 565 - red =((pixel & self->r_bitmask) >>11); - green = ((pixel & self->g_bitmask) >>5); - blue = ((pixel & self->b_bitmask) >> 0); + if (self->g_bitmask == 0x07e0) { // 565 + red =((pixel_data & self->r_bitmask) >>11); + green = ((pixel_data & self->g_bitmask) >>5); + blue = ((pixel_data & self->b_bitmask) >> 0); } else { // 555 - red =((pixel & self->r_bitmask) >>10); - green = ((pixel & self->g_bitmask) >>4); - blue = ((pixel & self->b_bitmask) >> 0); + red =((pixel_data & self->r_bitmask) >>10); + green = ((pixel_data & self->g_bitmask) >>4); + blue = ((pixel_data & self->b_bitmask) >> 0); } tmp = (red << 19 | green << 10 | blue << 3); return tmp; - }else if ((bytes_per_pixel == 4) && (self->bitfield_compressed)){ - return pixel & 0x00FFFFFF; + } else if ((bytes_per_pixel == 4) && (self->bitfield_compressed)) { + return pixel_data & 0x00FFFFFF; } else { - return pixel; + return pixel_data; } } return 0; -- cgit v1.2.3 From 5d85d5402613d2ec376dde1a7f3b9c77f54bd1e4 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 16:24:22 +0100 Subject: Move the frozen pew.py into a submodule --- .gitmodules | 3 + frozen/pew-pewpew-standalone-10.x | 1 + frozen/pewpew10/pew.py | 221 ---------------------- ports/atmel-samd/boards/pewpew10/mpconfigboard.mk | 2 +- shared-bindings/_pew/PewPew.c | 2 +- 5 files changed, 6 insertions(+), 223 deletions(-) create mode 160000 frozen/pew-pewpew-standalone-10.x delete mode 100644 frozen/pewpew10/pew.py diff --git a/.gitmodules b/.gitmodules index b36ad6203..1f7a28d14 100644 --- a/.gitmodules +++ b/.gitmodules @@ -92,3 +92,6 @@ [submodule "tools/Tecate-bitmap-fonts"] path = tools/Tecate-bitmap-fonts url = https://github.com/Tecate/bitmap-fonts.git +[submodule "frozen/pew-pewpew-standalone-10.x"] + path = frozen/pew-pewpew-standalone-10.x + url = https://github.com/pewpew-game/pew-pewpew-standalone-10.x.git diff --git a/frozen/pew-pewpew-standalone-10.x b/frozen/pew-pewpew-standalone-10.x new file mode 160000 index 000000000..87755e088 --- /dev/null +++ b/frozen/pew-pewpew-standalone-10.x @@ -0,0 +1 @@ +Subproject commit 87755e088150cc9bce42f4104cbd74d91b923c6f diff --git a/frozen/pewpew10/pew.py b/frozen/pewpew10/pew.py deleted file mode 100644 index 333b193d5..000000000 --- a/frozen/pewpew10/pew.py +++ /dev/null @@ -1,221 +0,0 @@ -from micropython import const -import board -import time -import digitalio -import _pew - - -_FONT = ( - b'\xff\xff\xff\xff\xff\xff\xf3\xf3\xf7\xfb\xf3\xff\xcc\xdd\xee\xff\xff' - b'\xff\xdd\x80\xdd\x80\xdd\xff\xf7\x81\xe4\xc6\xd0\xf7\xcc\xdb\xf3\xf9' - b'\xcc\xff\xf6\xcdc\xdcf\xff\xf3\xf7\xfe\xff\xff\xff\xf6\xfd\xfc\xfd' - b'\xf6\xff\xe7\xdf\xcf\xdf\xe7\xff\xff\xd9\xe2\xd9\xff\xff\xff\xf3\xc0' - b'\xf3\xff\xff\xff\xff\xff\xf3\xf7\xfe\xff\xff\x80\xff\xff\xff\xff\xff' - b'\xff\xff\xf3\xff\xcf\xdb\xf3\xf9\xfc\xff\xd2\xcd\xc8\xdc\xe1\xff\xf7' - b'\xf1\xf3\xf3\xe2\xff\xe1\xce\xe3\xfd\xc0\xff\xe1\xce\xe3\xce\xe1\xff' - b'\xf3\xf9\xdc\xc0\xcf\xff\xc0\xfc\xe4\xcf\xe1\xff\xd2\xfc\xe1\xcc\xe2' - b'\xff\xc0\xdb\xf3\xf9\xfc\xff\xe2\xcc\xe2\xcc\xe2\xff\xe2\xcc\xd2\xcf' - b'\xe1\xff\xff\xf3\xff\xf3\xff\xff\xff\xf3\xff\xf3\xf7\xfe\xcf\xf3\xfc' - b'\xf3\xcf\xff\xff\xc0\xff\xc0\xff\xff\xfc\xf3\xcf\xf3\xfc\xff\xe1\xcf' - b'\xe3\xfb\xf3\xff\xe2\xcd\xc4\xd4\xbd\xd2\xe2\xdd\xcc\xc4\xcc\xff\xe4' - b'\xcc\xe4\xcc\xe4\xff\xe2\xcd\xfc\xcd\xe2\xff\xe4\xdc\xcc\xdc\xe4\xff' - b'\xd0\xfc\xf4\xfc\xd0\xff\xd0\xfc\xfc\xf4\xfc\xff\xd2\xfd\xfc\x8d\xd2' - b'\xff\xcc\xcc\xc4\xcc\xcc\xff\xd1\xf3\xf3\xf3\xd1\xff\xcb\xcf\xcf\xdc' - b'\xe2\xff\xdc\xcc\xd8\xf4\xc8\xff\xfc\xfc\xfc\xec\xc0\xff\xdd\xc4\xc0' - b'\xc8\xcc\xff\xcd\xd4\xd1\xc5\xdc\xff\xe2\xdd\xcc\xdd\xe2\xff\xe4\xcc' - b'\xcc\xe4\xfc\xff\xe2\xcc\xcc\xc8\xd2\xcf\xe4\xcc\xcc\xe0\xcc\xff\xd2' - b'\xec\xe2\xce\xe1\xff\xc0\xe2\xf3\xf3\xf3\xff\xcc\xcc\xcc\xdd\xe2\xff' - b'\xcc\xcc\xdd\xe6\xf3\xff\xcc\xc8\xc4\xc0\xd9\xff\xcc\xd9\xe2\xd9\xcc' - b'\xff\xcc\xdd\xe6\xf3\xf3\xff\xc0\xde\xf7\xed\xc0\xff\xd0\xfc\xfc\xfc' - b'\xd0\xff\xfc\xf9\xf3\xdb\xcf\xff\xc1\xcf\xcf\xcf\xc1\xff\xf3\xd9\xee' - b'\xff\xff\xff\xff\xff\xff\xff\x80\xff\xfc\xf7\xef\xff\xff\xff\xff\xd2' - b'\xcd\xcc\x86\xff\xfc\xe4\xdc\xcc\xe4\xff\xff\xd2\xfd\xbc\xc6\xff\xcf' - b'\xc6\xcd\xcc\x86\xff\xff\xd6\xcd\xb1\xd2\xff\xcb\xb7\xc1\xf3\xf3\xf6' - b'\xff\xe2\xcc\xd2\xdf\xe1\xfc\xe4\xdc\xcc\xcc\xff\xf3\xfb\xf1\xb3\xdb' - b'\xff\xcf\xef\xc7\xcf\xdd\xe2\xfd\xec\xd8\xf4\xcc\xff\xf6\xf3\xf3\xf3' - b'\xdb\xff\xff\xd9\xc4\xc8\xcc\xff\xff\xe4\xdd\xcc\xcc\xff\xff\xe2\xcc' - b'\xcc\xe2\xff\xff\xe4\xdc\xcc\xe4\xfc\xff\xc6\xcd\xcc\xc6\xcf\xff\xc9' - b'\xf4\xfc\xfc\xff\xff\xd2\xf8\xcb\xe1\xff\xf3\xd1\xf3\xb3\xdb\xff\xff' - b'\xcc\xcc\xcd\x82\xff\xff\xcc\xdd\xe6\xf3\xff\xff\xcc\xc8\xd1\xd9\xff' - b'\xff\xcc\xe6\xe6\xcc\xff\xff\xdc\xcd\xd2\xcf\xe1\xff\xc0\xdb\xf9\xc0' - b'\xff\xd3\xf3\xf9\xf3\xd3\xff\xf3\xf3\xf7\xf3\xf3\xff\xf1\xf3\xdb\xf3' - b'\xf1\xff\xbfr\x8d\xfe\xff\xfff\x99f\x99f\x99') - - -K_RIGHT = const(0x01) -K_DOWN = const(0x02) -K_LEFT = const(0x04) -K_UP = const(0x08) -K_O = const(0x40) -K_X = const(0x80) - -_screen = None - - -def brightness(level): - pass - - -def show(pix): - _screen.blit(pix) - - -def tick(delay): - global _tick - - now = time.monotonic() - _tick += delay - if _tick < now: - _tick = now - else: - time.sleep(_tick - now) - - -class GameOver(Exception): - pass - - -class Pix: - def __init__(self, width=8, height=8, buffer=None): - if buffer is None: - buffer = bytearray(width * height) - self.buffer = buffer - self.width = width - self.height = height - - @classmethod - def from_text(cls, string, color=None, bgcolor=0, colors=None): - pix = cls(4 * len(string), 6) - font = memoryview(_FONT) - if colors is None: - if color is None: - colors = (3, 2, 1, bgcolor) - else: - colors = (color, color, bgcolor, bgcolor) - x = 0 - for c in string: - index = ord(c) - 0x20 - if not 0 <= index <= 95: - continue - row = 0 - for byte in font[index * 6:index * 6 + 6]: - for col in range(4): - pix.pixel(x + col, row, colors[byte & 0x03]) - byte >>= 2 - row += 1 - x += 4 - return pix - - @classmethod - def from_iter(cls, lines): - pix = cls(len(lines[0]), len(lines)) - y = 0 - for line in lines: - x = 0 - for pixel in line: - pix.pixel(x, y, pixel) - x += 1 - y += 1 - return pix - - def pixel(self, x, y, color=None): - if not 0 <= x < self.width or not 0 <= y < self.height: - return 0 - if color is None: - return self.buffer[x + y * self.width] - self.buffer[x + y * self.width] = color - - def box(self, color, x=0, y=0, width=None, height=None): - x = min(max(x, 0), self.width - 1) - y = min(max(y, 0), self.height - 1) - width = max(0, min(width or self.width, self.width - x)) - height = max(0, min(height or self.height, self.height - y)) - for y in range(y, y + height): - xx = y * self.width + x - for i in range(width): - self.buffer[xx] = color - xx += 1 - - def blit(self, source, dx=0, dy=0, x=0, y=0, - width=None, height=None, key=None): - if dx < 0: - x -= dx - dx = 0 - if x < 0: - dx -= x - x = 0 - if dy < 0: - y -= dy - dy = 0 - if y < 0: - dy -= y - y = 0 - width = min(min(width or source.width, source.width - x), - self.width - dx) - height = min(min(height or source.height, source.height - y), - self.height - dy) - source_buffer = memoryview(source.buffer) - self_buffer = self.buffer - if key is None: - for row in range(height): - xx = y * source.width + x - dxx = dy * self.width + dx - self_buffer[dxx:dxx + width] = source_buffer[xx:xx + width] - y += 1 - dy += 1 - else: - for row in range(height): - xx = y * source.width + x - dxx = dy * self.width + dx - for col in range(width): - color = source_buffer[xx] - if color != key: - self_buffer[dxx] = color - dxx += 1 - xx += 1 - y += 1 - dy += 1 - - def __str__(self): - return "\n".join( - "".join( - ('.', '+', '*', '@')[self.pixel(x, y)] - for x in range(self.width) - ) - for y in range(self.height) - ) - - -def init(): - global _screen, _tick, keys, _rows, _cols - - if _screen is not None: - return - - _screen = Pix(8, 8) - _tick = time.monotonic() - - _rows = ( - digitalio.DigitalInOut(board._R1), - digitalio.DigitalInOut(board._R2), - digitalio.DigitalInOut(board._R3), - digitalio.DigitalInOut(board._R4), - digitalio.DigitalInOut(board._R5), - digitalio.DigitalInOut(board._R6), - digitalio.DigitalInOut(board._R7), - digitalio.DigitalInOut(board._R8), - ) - - _cols = ( - digitalio.DigitalInOut(board._C1), - digitalio.DigitalInOut(board._C2), - digitalio.DigitalInOut(board._C3), - digitalio.DigitalInOut(board._C4), - digitalio.DigitalInOut(board._C5), - digitalio.DigitalInOut(board._C6), - digitalio.DigitalInOut(board._C7), - digitalio.DigitalInOut(board._C8), - ) - _buttons = digitalio.DigitalInOut(board._BUTTONS) - _pew.PewPew(_screen.buffer, _rows, _cols, _buttons) - keys = _pew.get_pressed diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk index eeb5632ef..0c20b4010 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk @@ -10,7 +10,7 @@ LONGINT_IMPL = NONE CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 -FROZEN_MPY_DIRS += $(TOP)/frozen/pewpew10 +FROZEN_MPY_DIRS += $(TOP)/frozen/pew-pewpew-standalone-10.x CIRCUITPY_PEW = 1 CIRCUITPY_ANALOGIO = 1 diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index d0803e0a9..26b060188 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -75,7 +75,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, mp_obj_get_array(args[ARG_cols].u_obj, &cols_size, &cols); if (bufinfo.len != rows_size * cols_size) { - mp_raise_TypeError(translate("")); + mp_raise_ValueError(translate("")); } for (size_t i = 0; i < rows_size; ++i) { -- cgit v1.2.3 From 76dc8e1ac861b11d01c2e82ecfdbaea761c84fd0 Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Fri, 1 Mar 2019 07:32:46 -0800 Subject: fixed typo --- shared-module/displayio/OnDiskBitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c index 92735e53c..d710bdae0 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -133,7 +133,7 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s // We don't cache here because the underlying FS caches sectors. f_lseek(&self->file->fp, location); UINT bytes_read; - uint32_t pixel_data = 0; // this name is stale + uint32_t pixel_data = 0; uint32_t result = f_read(&self->file->fp, &pixel_data, bytes_per_pixel, &bytes_read); if (result == FR_OK) { uint32_t tmp = 0; -- cgit v1.2.3 From ea78417f7fe80cc870fd6bef24a4938bddfa4f37 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 16:36:29 +0100 Subject: Improve documentation --- shared-bindings/_pew/PewPew.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 26b060188..50647488c 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -37,17 +37,30 @@ //| .. currentmodule:: _pew //| -//| :class:`PewPew` -- LED Matrix driver -//| ==================================== +//| :class:`PewPew` -- LED matrix and button driver +//| =============================================== +//| +//| This is an internal module to be used by the ``pew.py`` library from +//| https://github.com/pewpew-game/pew-pewpew-standalone-10.x to handle the +//| LED matrix display and buttons on the ``pewpew10`` board. //| //| Usage:: //| +//| This singleton class is instantiated by the ``pew`` library, and +//| used internally by it. All user-visible interactions are done through +//| that library. //| -//| .. class:: PewPew(buffer, rows, cols) +//| .. class:: PewPew(buffer, rows, cols, buttons) //| //| Initializes matrix scanning routines. //| +//| The ``buffer`` is a 64 byte long ``bytearray`` that stores what should +//| be displayed on the matrix. ``rows`` and ``cols`` are both lists of +//| eight ``DigitalInputOutput`` objects that are connected to the matrix +//| rows and columns. ``buttons`` is a ``DigitalInputOutput`` object that +//| is connected to the common side of all buttons (the other sides of the +//| buttons are connected to rows of the matrix). //| STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { -- cgit v1.2.3 From 7afbfc70038201fdea5fa2601be4d3235ffca7d6 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 16:46:59 +0100 Subject: Use find_free_timer() --- shared-module/_pew/PewPew.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index 755b88394..c1d6aa5c3 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -74,17 +74,11 @@ void pew_init() { } if (pewpew_tc_index == 0xff) { // Find a spare timer. - Tc *tc = NULL; - int8_t index = TC_INST_NUM - 1; - for (; index >= 0; index--) { - if (tc_insts[index]->COUNT16.CTRLA.bit.ENABLE == 0) { - tc = tc_insts[index]; - break; - } - } - if (tc == NULL) { + uint8_t index = find_free_timer(); + if (index == 0xff) { mp_raise_RuntimeError(translate("")); } + Tc *tc = tc_insts[index]; pewpew_tc_index = index; set_timer_handler(true, index, TC_HANDLER_PEW); -- cgit v1.2.3 From 2bfafd1fc953a874e86aba0e55e89174449ab3ca Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 16:55:54 +0100 Subject: Enable math for pewpew10 --- ports/atmel-samd/boards/pewpew10/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk index 0c20b4010..983e48e21 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk @@ -14,7 +14,7 @@ FROZEN_MPY_DIRS += $(TOP)/frozen/pew-pewpew-standalone-10.x CIRCUITPY_PEW = 1 CIRCUITPY_ANALOGIO = 1 -CIRCUITPY_MATH = 0 +CIRCUITPY_MATH = 1 CIRCUITPY_NEOPIXEL_WRITE = 1 CIRCUITPY_RTC = 0 CIRCUITPY_SAMD = 0 -- cgit v1.2.3 From 263134dcd3e1d0151be081a2ba04b358f732035e Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 18:50:00 +0100 Subject: Add more guards for CIRCUITPYTHON_PEW --- ports/atmel-samd/supervisor/port.c | 2 +- ports/atmel-samd/timer_handler.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index b3f4a2e89..8d25806b7 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -226,7 +226,7 @@ void reset_port(void) { #if CIRCUITPY_GAMEPAD gamepad_reset(); #endif -#ifdef CIRCUITPY_PEW +#if CIRCUITPY_PEW pew_reset(); #endif diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index ac162329e..059d4330e 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -50,7 +50,9 @@ void shared_timer_handler(bool is_tc, uint8_t index) { pulseout_interrupt_handler(index); break; case TC_HANDLER_PEW: +#if CIRCUITPY_PEW pewpew_interrupt_handler(index); +#endif break; default: break; -- cgit v1.2.3