Merge branch 'master' of https://github.com/adafruit/circuitpython into new_freq_in
commit
a44bfc2730
@ -0,0 +1 @@
|
||||
Subproject commit 87755e088150cc9bce42f4104cbd74d91b923c6f
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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) {
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
#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
|
||||
|
||||
#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
|
@ -0,0 +1,22 @@
|
||||
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/pew-pewpew-standalone-10.x
|
||||
|
||||
CIRCUITPY_PEW = 1
|
||||
CIRCUITPY_ANALOGIO = 1
|
||||
CIRCUITPY_MATH = 1
|
||||
CIRCUITPY_NEOPIXEL_WRITE = 1
|
||||
CIRCUITPY_RTC = 0
|
||||
CIRCUITPY_SAMD = 0
|
||||
CIRCUITPY_USB_MIDI = 0
|
||||
CIRCUITPY_SMALL_BUILD = 1
|
@ -0,0 +1,35 @@
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
#include "supervisor/shared/board_busses.h"
|
||||
|
||||
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR__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);
|
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* 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
|
||||
* 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"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
|
||||
//| .. currentmodule:: _pew
|
||||
//|
|
||||
//| :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, 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) {
|
||||
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 },
|
||||
{ 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),
|
||||
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_ValueError(translate(""));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < rows_size; ++i) {
|
||||
if (!MP_OBJ_IS_TYPE(rows[i], &digitalio_digitalinout_type)) {
|
||||
mp_raise_TypeError(translate(""));
|
||||
}
|
||||
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(translate(""));
|
||||
}
|
||||
digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(cols[i]);
|
||||
raise_error_if_deinited(
|
||||
common_hal_digitalio_digitalinout_deinited(pin));
|
||||
}
|
||||
|
||||
if (!MP_OBJ_IS_TYPE(args[ARG_buttons].u_obj,
|
||||
&digitalio_digitalinout_type)) {
|
||||
mp_raise_TypeError(translate(""));
|
||||
}
|
||||
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) {
|
||||
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->buttons = buttons;
|
||||
pew->pressed = 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,
|
||||
};
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* 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
|
||||
* 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
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* 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
|
||||
* 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"
|
||||
#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
|
||||
//| ==================================
|
||||
//|
|
||||
//| .. 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)},
|
||||
{ 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);
|
||||
|
||||
const mp_obj_module_t pew_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&pew_module_globals,
|
||||
};
|
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* 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
|
||||
* 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 <stdbool.h>
|
||||
|
||||
#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"
|
||||
#include "supervisor/shared/translate.h"
|
||||
#include "timer_handler.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 = 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->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);
|
||||
}
|
||||
if (pewpew_tc_index == 0xff) {
|
||||
// Find a spare timer.
|
||||
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);
|
||||
|
||||
// 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.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) {
|
||||
if (pewpew_tc_index != 0xff) {
|
||||
tc_reset(tc_insts[pewpew_tc_index]);
|
||||
pewpew_tc_index = 0xff;
|
||||
}
|
||||
MP_STATE_VM(pew_singleton) = NULL;
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* 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
|
||||
* 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 <stdint.h>
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||