mp working

This commit is contained in:
Gee Bartlett 2022-11-03 13:30:07 +00:00
parent 7be5376abf
commit 9085c48a62
7 changed files with 192 additions and 5 deletions

View File

@ -0,0 +1,60 @@
import time
import random
from picographics import PicoGraphics, DISPLAY_GFX_PACK, PEN_P8
display = PicoGraphics(display=DISPLAY_GFX_PACK)
display.set_backlight(1.0)
WIDTH, HEIGHT = display.get_bounds()
class Ball:
def __init__(self, x, y, r, dx, dy, pen):
self.x = x
self.y = y
self.r = r
self.dx = dx
self.dy = dy
self.pen = pen
# initialise shapes
balls = []
for i in range(0, 10):
r = random.randint(0, 10) + 3
balls.append(
Ball(
random.randint(r, r + (WIDTH - 2 * r)),
random.randint(r, r + (HEIGHT - 2 * r)),
r,
(14 - r) / 2,
(14 - r) / 2,
random.randint(0, 15),
)
)
while True:
display.set_pen(0)
display.clear()
for ball in balls:
ball.x += ball.dx
ball.y += ball.dy
xmax = WIDTH - ball.r
xmin = ball.r
ymax = HEIGHT - ball.r
ymin = ball.r
if ball.x < xmin or ball.x > xmax:
ball.dx *= -1
if ball.y < ymin or ball.y > ymax:
ball.dy *= -1
display.set_pen(ball.pen)
display.circle(int(ball.x), int(ball.y), int(ball.r))
display.update()
time.sleep(0.05)

View File

@ -0,0 +1,110 @@
include(pimoroni_i2c/micropython)
include(pimoroni_bus/micropython)
#include(breakout_dotmatrix/micropython)
#include(breakout_encoder/micropython)
#include(breakout_ioexpander/micropython)
#include(breakout_ltr559/micropython)
#include(breakout_as7262/micropython)
#include(breakout_rgbmatrix5x5/micropython)
#include(breakout_matrix11x7/micropython)
#include(breakout_msa301/micropython)
#include(breakout_pmw3901/micropython)
#include(breakout_mics6814/micropython)
#include(breakout_potentiometer/micropython)
#include(breakout_rtc/micropython)
#include(breakout_trackball/micropython)
#include(breakout_sgp30/micropython)
#include(breakout_bh1745/micropython)
#include(breakout_bme68x/micropython)
#include(breakout_bme280/micropython)
#include(breakout_bmp280/micropython)
#include(breakout_icp10125/micropython)
#include(breakout_scd41/micropython)
#include(breakout_vl53l5cx/micropython)
#include(pico_scroll/micropython)
#include(pico_rgb_keypad/micropython)
#include(pico_unicorn/micropython)
#include(pico_wireless/micropython)
#include(pico_explorer/micropython)
include(hershey_fonts/micropython)
include(bitmap_fonts/micropython)
#include(plasma/micropython)
#include(hub75/micropython)
include(pwm/micropython)
#include(servo/micropython)
#include(encoder/micropython)
#include(motor/micropython)
#include(qrcode/micropython/micropython)
#include(adcfft/micropython)
#include(pcf85063a/micropython)
include(picographics/micropython)
include(jpegdec/micropython)
include(galactic_unicorn/micropython)
include(modules_py/modules_py)
function(enable_ulab)
include(ulab/code/micropython)
target_compile_definitions(usermod_ulab INTERFACE
# Support for complex ndarrays
ULAB_SUPPORTS_COMPLEX=0
# Determines, whether scipy is defined in ulab. The sub-modules and functions
# of scipy have to be defined separately
ULAB_HAS_SCIPY=0
# The maximum number of dimensions the firmware should be able to support
# Possible values lie between 1, and 4, inclusive
ULAB_MAX_DIMS=2
# By setting this constant to 1, iteration over array dimensions will be implemented
# as a function (ndarray_rewind_array), instead of writing out the loops in macros
# This reduces firmware size at the expense of speed
ULAB_HAS_FUNCTION_ITERATOR=1
# If NDARRAY_IS_ITERABLE is 1, the ndarray object defines its own iterator function
# This option saves approx. 250 bytes of flash space
NDARRAY_IS_ITERABLE=1
# Slicing can be switched off by setting this variable to 0
NDARRAY_IS_SLICEABLE=1
# The default threshold for pretty printing. These variables can be overwritten
# at run-time via the set_printoptions() function
ULAB_HAS_PRINTOPTIONS=1
NDARRAY_PRINT_THRESHOLD=10
NDARRAY_PRINT_EDGEITEMS=3
# determines, whether the dtype is an object, or simply a character
# the object implementation is numpythonic, but requires more space
ULAB_HAS_DTYPE_OBJECT=0
# the ndarray binary operators
NDARRAY_HAS_BINARY_OPS=0
# Firmware size can be reduced at the expense of speed by using function
# pointers in iterations. For each operator, the function pointer saves around
# 2 kB in the two-dimensional case, and around 4 kB in the four-dimensional case.
NDARRAY_BINARY_USES_FUN_POINTER=1
NDARRAY_HAS_BINARY_OP_ADD=1
NDARRAY_HAS_BINARY_OP_EQUAL=1
NDARRAY_HAS_BINARY_OP_LESS=1
NDARRAY_HAS_BINARY_OP_LESS_EQUAL=1
NDARRAY_HAS_BINARY_OP_MORE=1
NDARRAY_HAS_BINARY_OP_MORE_EQUAL=1
NDARRAY_HAS_BINARY_OP_MULTIPLY=1
NDARRAY_HAS_BINARY_OP_NOT_EQUAL=1
NDARRAY_HAS_BINARY_OP_POWER=1
NDARRAY_HAS_BINARY_OP_SUBTRACT=1
NDARRAY_HAS_BINARY_OP_TRUE_DIVIDE=1
)
endfunction()

View File

@ -4,4 +4,5 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../")
include(micropython-common)
#include(micropython-common)
include(micropython-gfx)

View File

@ -10,6 +10,7 @@ target_sources(usermod_${MOD_NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/sh1107/sh1107.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/uc8151/uc8151.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/uc8159/uc8159.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7567/st7567.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics_pen_1bit.cpp
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics_pen_1bitY.cpp

View File

@ -126,6 +126,7 @@ STATIC const mp_map_elem_t picographics_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_INKY_FRAME), MP_ROM_INT(DISPLAY_INKY_FRAME) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_INKY_FRAME_4), MP_ROM_INT(DISPLAY_INKY_FRAME_4) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_GALACTIC_UNICORN), MP_ROM_INT(DISPLAY_GALACTIC_UNICORN) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_GFX_PACK), MP_ROM_INT(DISPLAY_GFX_PACK) },
{ MP_ROM_QSTR(MP_QSTR_PEN_1BIT), MP_ROM_INT(PEN_1BIT) },
{ MP_ROM_QSTR(MP_QSTR_PEN_P4), MP_ROM_INT(PEN_P4) },

View File

@ -3,6 +3,7 @@
#include "drivers/sh1107/sh1107.hpp"
#include "drivers/uc8151/uc8151.hpp"
#include "drivers/uc8159/uc8159.hpp"
#include "drivers/st7567/st7567.hpp"
#include "libraries/pico_graphics/pico_graphics.hpp"
#include "common/pimoroni_common.hpp"
#include "common/pimoroni_bus.hpp"
@ -120,6 +121,13 @@ bool get_display_settings(PicoGraphicsDisplay display, int &width, int &height,
if(rotate == -1) rotate = (int)Rotation::ROTATE_0;
if(pen_type == -1) pen_type = PEN_RGB888;
break;
case DISPLAY_GFX_PACK:
width = 128;
height = 64;
bus_type = BUS_SPI;
if(rotate == -1) rotate = (int)Rotation::ROTATE_0;
if(pen_type == -1) pen_type = PEN_1BIT;
break;
default:
return false;
}
@ -178,7 +186,7 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
PicoGraphicsBusType bus_type = BUS_SPI;
if(!get_display_settings(display, width, height, rotate, pen_type, bus_type)) mp_raise_ValueError("Unsupported display!");
if(rotate == -1) rotate = (int)Rotation::ROTATE_0;
pimoroni::SPIPins spi_bus = get_spi_pins(BG_SPI_FRONT);
pimoroni::ParallelPins parallel_bus = {10, 11, 12, 13, 14, 2}; // Default for Tufty 2040 parallel
pimoroni::I2C *i2c_bus = nullptr;
@ -208,6 +216,8 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
spi_bus = {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 28, PIN_UNUSED};
} else if (display == DISPLAY_INKY_PACK) {
spi_bus = {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 20, PIN_UNUSED};
} else if (display == DISPLAY_GFX_PACK) {
spi_bus = {PIMORONI_SPI_DEFAULT_INSTANCE, 17, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 20, 9};
}
}
}
@ -235,8 +245,11 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
} else if (display == DISPLAY_GALACTIC_UNICORN) {
self->display = m_new_class(DisplayDriver, width, height, (Rotation)rotate);
}
else {
} else if (display == DISPLAY_GFX_PACK) {
self->display = m_new_class(ST7567, width, height, spi_bus);
} else {
self->display = m_new_class(ST7789, width, height, (Rotation)rotate, round, spi_bus);
}

View File

@ -14,7 +14,8 @@ enum PicoGraphicsDisplay {
DISPLAY_INKY_PACK,
DISPLAY_INKY_FRAME,
DISPLAY_INKY_FRAME_4,
DISPLAY_GALACTIC_UNICORN
DISPLAY_GALACTIC_UNICORN,
DISPLAY_GFX_PACK
};
enum PicoGraphicsPenType {