parent
0a5c1c9402
commit
59f63eaef6
@ -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\x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\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
|
@ -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) {
|
||||
}
|
@ -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
|
@ -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
|
@ -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);
|
Loading…
Reference in new issue