Add Protomatter and FramebufferDisplay

This commit is contained in:
Jeff Epler 2020-03-10 13:12:01 -05:00
parent a51d4f7a45
commit 09dc46a984
61 changed files with 1954 additions and 50 deletions

3
.gitmodules vendored
View File

@ -119,3 +119,6 @@
[submodule "ports/stm/st_driver"]
path = ports/stm/st_driver
url = https://github.com/hathach/st_driver.git
[submodule "lib/protomatter"]
path = lib/protomatter
url = https://github.com/adafruit/Adafruit_Protomatter

1
lib/protomatter Submodule

@ -0,0 +1 @@
Subproject commit c3a3e35731d641cb5a21ae7319634afc419f5afe

View File

@ -97,6 +97,7 @@ void board_init(void) {
false, // Pixels in a byte share a row. Only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -77,6 +77,7 @@ void board_init(void) {
false, // Pixels in a byte share a row. Only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -11,8 +11,10 @@ LONGINT_IMPL = MPZ
# Not needed.
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_NETWORK = 0
CIRCUITPY_PROTOMATTER = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_AUDIOMP3 = 0

View File

@ -78,6 +78,7 @@ void board_init(void) {
false, // pixels in a byte share a row. Only valid for depths < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -128,6 +128,7 @@ void board_init(void) {
false, // pixels in byte share row. only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -100,6 +100,7 @@ void board_init(void) {
false, // pixels in byte share row. only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -78,6 +78,7 @@ void board_init(void) {
false, // pixels in byte share row. Only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -15,7 +15,9 @@ LONGINT_IMPL = MPZ
# Not needed.
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_GAMEPAD = 0
CIRCUITPY_PROTOMATTER = 0
CIRCUITPY_PS2IO = 0
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice

View File

@ -100,6 +100,7 @@ void board_init(void) {
false, // pixels in a byte share a row. Only valid for depths < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -78,6 +78,7 @@ void board_init(void) {
false, // pixels in a byte share a row. Only valid for depths < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -87,6 +87,7 @@ void board_init(void) {
false, // pixels_in_byte_share_row (unused for depths > 8)
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -101,9 +101,10 @@ void board_init(void) {
0, // rotation
16, // Color depth
false, // grayscale
false, // pixels_in_byte_share_row (unused for depths > 8)
false, // pixels_i|n_byte_share_row (unused for depths > 8)
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -17,7 +17,9 @@ LONGINT_IMPL = MPZ
CIRCUITPY_AUDIOBUSIO = 0
# Make room for more stuff
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_PROTOMATTER = 0
# Include these Python libraries in firmware.
#FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice

View File

@ -97,6 +97,7 @@ void board_init(void) {
false, // pixels in byte share row. Only used with depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -18,6 +18,7 @@ CIRCUITPY_AUDIOIO = 1
# Disable modules that are unusable on this special-purpose board.
CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_AUDIOBUSIO = 0
@ -27,6 +28,7 @@ CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_NETWORK = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_PROTOMATTER = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_RTC = 0

View File

@ -21,10 +21,12 @@ CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_BLEIO = 0
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_NETWORK = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_PROTOMATTER = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_USB_HID = 0

View File

@ -0,0 +1,77 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jeff Epler 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 <stddef.h>
#include "common-hal/_protomatter/Protomatter.h"
#include "samd/timers.h"
#include "timer_handler.h"
void *common_hal_protomatter_timer_allocate() {
uint8_t timer_index = find_free_timer();
if (timer_index == 0xff) {
return NULL;
}
timer_never_reset(timer_index, true);
return tc_insts[timer_index];
}
static uint8_t tc_index_from_ptr(void* ptr) {
for (uint8_t i = TC_INST_NUM; i > 0; i--) {
if (tc_insts[i] == ptr) {
return i;
}
}
return 0xff;
}
void common_hal_protomatter_timer_enable(void* ptr) {
uint8_t timer_index = tc_index_from_ptr(ptr);
if (timer_index == 0xff) {
return;
}
set_timer_handler(true, timer_index, TC_HANDLER_PROTOMATTER);
turn_on_clocks(true, timer_index, 1);
}
void common_hal_protomatter_timer_disable(void* ptr) {
uint8_t timer_index = tc_index_from_ptr(ptr);
if (timer_index == 0xff) {
return;
}
set_timer_handler(true, timer_index, TC_HANDLER_NO_INTERRUPT);
}
void common_hal_protomatter_timer_free(void* ptr) {
uint8_t timer_index = tc_index_from_ptr(ptr);
if (timer_index == 0xff) {
return;
}
tc_set_enable(ptr, false);
tc_reset(ptr);
timer_reset_ok(timer_index, true);
}

View File

@ -0,0 +1,35 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jeff Epler 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_ATMEL_SAMD_COMMON_HAL_PROTOMATTER_PROTOMATTER_H
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PROTOMATTER_PROTOMATTER_H
void *common_hal_protomatter_timer_allocate(void);
void common_hal_protomatter_timer_enable(void*);
void common_hal_protomatter_timer_disable(void*);
void common_hal_protomatter_timer_free(void*);
#endif

View File

@ -240,3 +240,15 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) {
return pin_number_is_free(pin->number);
}
uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t* pin) {
return pin->number;
}
void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
return claim_pin(pin);
}
void common_hal_mcu_pin_reset_number(uint8_t pin_no) {
reset_pin_number(pin_no);
}

View File

@ -61,22 +61,31 @@ uint8_t tcc_channels[5]; // Set by pwmout_reset() to {0xc0, 0xf0, 0xf8, 0xfc,
static uint8_t never_reset_tc_or_tcc[TC_INST_NUM + TCC_INST_NUM];
void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
if (self->timer->is_tc) {
never_reset_tc_or_tcc[self->timer->index] += 1;
STATIC void timer_refcount(int index, bool is_tc, int increment) {
if (is_tc) {
never_reset_tc_or_tcc[index] += increment;
} else {
never_reset_tc_or_tcc[TC_INST_NUM + self->timer->index] += 1;
never_reset_tc_or_tcc[TC_INST_NUM + index] += increment;
}
}
void timer_never_reset(int index, bool is_tc) {
timer_refcount(index, is_tc, 1);
}
void timer_reset_ok(int index, bool is_tc) {
timer_refcount(index, is_tc, -1);
}
void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
timer_never_reset(self->timer->index, self->timer->is_tc);
never_reset_pin_number(self->pin->number);
}
void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
if (self->timer->is_tc) {
never_reset_tc_or_tcc[self->timer->index] -= 1;
} else {
never_reset_tc_or_tcc[TC_INST_NUM + self->timer->index] -= 1;
}
timer_reset_ok(self->timer->index, self->timer->is_tc);
}
void pwmout_reset(void) {

View File

@ -70,6 +70,18 @@ CIRCUITPY_ULAB = 1
endif
endif
ifndef CIRCUITPY_PROTOMATTER
ifneq ($(CIRCUITPY_SMALL_BUILD),1)
CIRCUITPY_PROTOMATTER = 1
endif
endif
ifndef CIRCUITPY_FRAMEBUFFERIO
ifneq ($(CIRCUITPY_SMALL_BUILD),1)
CIRCUITPY_FRAMEBUFFERIO = 1
endif
endif
endif # samd51
INTERNAL_LIBM = 1

@ -1 +1 @@
Subproject commit b89811f22a24ac350079ceaf0cdf0e62aa03f4f4
Subproject commit f528240c2a4c2d7a39de786f1aa56895c12227b4

View File

@ -33,6 +33,8 @@
#include "shared-module/_pew/PewPew.h"
#include "common-hal/frequencyio/FrequencyIn.h"
extern void _PM_IRQ_HANDLER(void);
static uint8_t tc_handler[TC_INST_NUM];
void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler) {
@ -62,6 +64,11 @@ void shared_timer_handler(bool is_tc, uint8_t index) {
frequencyin_interrupt_handler(index);
#endif
break;
case TC_HANDLER_PROTOMATTER:
#if CIRCUITPY_PROTOMATTER
_PM_IRQ_HANDLER();
#endif
break;
default:
break;
}

View File

@ -30,8 +30,13 @@
#define TC_HANDLER_PULSEOUT 0x1
#define TC_HANDLER_PEW 0x2
#define TC_HANDLER_FREQUENCYIN 0x3
#define TC_HANDLER_PROTOMATTER 0x4
void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler);
void shared_timer_handler(bool is_tc, uint8_t index);
// implementation of these functions is in PWMOut.c
void timer_never_reset(int index, bool is_tc);
void timer_reset_ok(int index, bool is_tc);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_TIMER_HANDLER_H

View File

@ -77,6 +77,7 @@ void board_init(void) {
false, // Pixels in a byte share a row. Only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -77,6 +77,7 @@ void board_init(void) {
false, // Pixels in a byte share a row. Only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -98,6 +98,7 @@ void board_init(void) {
false, // Pixels in a byte share a row. Only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command

View File

@ -142,6 +142,9 @@ endif
ifeq ($(CIRCUITPY_DISPLAYIO),1)
SRC_PATTERNS += displayio/% terminalio/% fontio/%
endif
ifeq ($(CIRCUITPY_FRAMEBUFFERIO),1)
SRC_PATTERNS += framebufferio/%
endif
ifeq ($(CIRCUITPY_FREQUENCYIO),1)
SRC_PATTERNS += frequencyio/%
endif
@ -178,6 +181,9 @@ endif
ifeq ($(CIRCUITPY_PIXELBUF),1)
SRC_PATTERNS += _pixelbuf/%
endif
ifeq ($(CIRCUITPY_PROTOMATTER),1)
SRC_PATTERNS += _protomatter/%
endif
ifeq ($(CIRCUITPY_PULSEIO),1)
SRC_PATTERNS += pulseio/%
endif
@ -242,6 +248,8 @@ SRC_COMMON_HAL_ALL = \
_bleio/PacketBuffer.c \
_bleio/Service.c \
_bleio/UUID.c \
_protomatter/Protomatter.c \
_protomatter/__init__.c \
analogio/AnalogIn.c \
analogio/AnalogOut.c \
analogio/__init__.c \
@ -315,6 +323,8 @@ SRC_SHARED_MODULE_ALL = \
_bleio/ScanResults.c \
_pixelbuf/PixelBuf.c \
_pixelbuf/__init__.c \
_protomatter/Protomatter.c \
_protomatter/__init__.c \
_stage/Layer.c \
_stage/Text.c \
_stage/__init__.c \
@ -348,6 +358,8 @@ SRC_SHARED_MODULE_ALL = \
displayio/__init__.c \
fontio/BuiltinFont.c \
fontio/__init__.c \
framebufferio/FramebufferDisplay.c \
framebufferio/__init__.c \
gamepad/GamePad.c \
gamepad/__init__.c \
gamepadshift/GamePadShift.c \
@ -401,6 +413,12 @@ SRC_MOD += $(addprefix lib/mp3/src/, \
)
$(BUILD)/lib/mp3/src/buffers.o: CFLAGS += -include "py/misc.h" -D'MPDEC_ALLOCATOR(x)=m_malloc(x,0)' -D'MPDEC_FREE(x)=m_free(x)'
endif
ifeq ($(CIRCUITPY_PROTOMATTER),1)
SRC_MOD += $(addprefix lib/protomatter/, \
core.c \
)
$(BUILD)/lib/protomatter/core.o: CFLAGS += -include "shared-module/_protomatter/allocator.h" -DCIRCUITPY -Wno-missing-braces
endif
# All possible sources are listed here, and are filtered by SRC_PATTERNS.
SRC_SHARED_MODULE_INTERNAL = \

View File

@ -345,6 +345,13 @@ extern const struct _mp_obj_module_t terminalio_module;
#define CIRCUITPY_DISPLAY_LIMIT (0)
#endif
#if CIRCUITPY_FRAMEBUFFERIO
extern const struct _mp_obj_module_t framebufferio_module;
#define FRAMEBUFFERIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_framebufferio), (mp_obj_t)&framebufferio_module },
#else
#define FRAMEBUFFERIO_MODULE
#endif
#if CIRCUITPY_FREQUENCYIO
extern const struct _mp_obj_module_t frequencyio_module;
#define FREQUENCYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_frequencyio), (mp_obj_t)&frequencyio_module },
@ -454,6 +461,13 @@ extern const struct _mp_obj_module_t pixelbuf_module;
#define PIXELBUF_MODULE
#endif
#if CIRCUITPY_PROTOMATTER
extern const struct _mp_obj_module_t protomatter_module;
#define PROTOMATTER_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR__protomatter),(mp_obj_t)&protomatter_module },
#else
#define PROTOMATTER_MODULE
#endif
#if CIRCUITPY_PULSEIO
extern const struct _mp_obj_module_t pulseio_module;
#define PULSEIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module },
@ -628,6 +642,7 @@ extern const struct _mp_obj_module_t ustack_module;
FONTIO_MODULE \
TERMINALIO_MODULE \
ERRNO_MODULE \
FRAMEBUFFERIO_MODULE \
FREQUENCYIO_MODULE \
GAMEPAD_MODULE \
GAMEPADSHIFT_MODULE \
@ -643,6 +658,7 @@ extern const struct _mp_obj_module_t ustack_module;
PEW_MODULE \
PIXELBUF_MODULE \
PS2IO_MODULE \
PROTOMATTER_MODULE \
PULSEIO_MODULE \
RANDOM_MODULE \
RE_MODULE \

View File

@ -149,6 +149,11 @@ CIRCUITPY_DISPLAYIO = $(CIRCUITPY_FULL_BUILD)
endif
CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO)
ifndef CIRCUITPY_FRAMEBUFFERIO
CIRCUITPY_FRAMEBUFFERIO = 0
endif
CFLAGS += -DCIRCUITPY_FRAMEBUFFERIO=$(CIRCUITPY_FRAMEBUFFERIO)
ifndef CIRCUITPY_FREQUENCYIO
CIRCUITPY_FREQUENCYIO = $(CIRCUITPY_FULL_BUILD)
endif
@ -210,6 +215,12 @@ CIRCUITPY_PIXELBUF = $(CIRCUITPY_FULL_BUILD)
endif
CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF)
# Only for SAMD boards for the moment
ifndef CIRCUITPY_PROTOMATTER
CIRCUITPY_PROTOMATTER = 0
endif
CFLAGS += -DCIRCUITPY_PROTOMATTER=$(CIRCUITPY_PROTOMATTER)
ifndef CIRCUITPY_PULSEIO
CIRCUITPY_PULSEIO = $(CIRCUITPY_DEFAULT_BUILD)
endif

View File

@ -0,0 +1,293 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jeff Epler 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/objproperty.h"
#include "py/runtime.h"
#include "py/objarray.h"
#include "common-hal/_protomatter/Protomatter.h"
#include "shared-bindings/_protomatter/Protomatter.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/util.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/framebufferio/__init__.h"
#include "shared-module/framebufferio/FramebufferDisplay.h"
//| .. currentmodule:: _protomatter
//|
//| :class:`protomatter` -- Driver for HUB75-style RGB LED matrices
//| ================================================================
//|
extern Protomatter_core *_PM_protoPtr;
STATIC uint8_t validate_pin(mp_obj_t obj) {
mcu_pin_obj_t *result = validate_obj_is_free_pin(obj);
return common_hal_mcu_pin_number(result);
}
STATIC void validate_pins(qstr what, uint8_t* pin_nos, mp_int_t max_pins, mp_obj_t seq, uint8_t *count_out) {
mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(seq));
if (len > max_pins) {
mp_raise_ValueError_varg(translate("At most %d %q may be specified"), max_pins, what);
}
*count_out = len;
for (mp_int_t i=0; i<len; i++) {
pin_nos[i] = validate_pin(mp_obj_subscr(seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL));
}
}
STATIC void claim_pin_nr(mp_obj_t pin) {
common_hal_mcu_pin_claim(pin);
common_hal_never_reset_pin(pin);
}
STATIC void claim_pins_nr(mp_obj_t seq) {
mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(seq));
for (mp_int_t i=0; i<len; i++) {
claim_pin_nr(mp_obj_subscr(seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL));
}
}
//| :class:`~_protomatter.Protomatter` displays an in-memory framebuffer to an LED matrix.
//|
//| .. class:: Protomatter(width, bit_depth, rgb_pins, addr_pins, clock_pin, latch_pin, oe_pin, *, doublebuffer=True, framebuffer=None)
//|
//| Create a Protomatter object with the given attributes. The height of
//| the display is determined by the number of rgb and address pins:
//| len(rgb_pins)/3 * 2 ** len(address_pins). With 6 RGB pins and 4
//| address lines, the display will be 32 pixels tall.
//|
//| Up to 30 RGB pins and 8 address pins are supported.
//|
//| The RGB pins must be within a single "port" and performance and memory
//| usage are best when they are all within "close by" bits of the port.
//| The clock pin must also be on the same port as the RGB pins. See the
//| documentation of the underlying protomatter C library for more
//| information. Generally, Adafruit's interface boards are designed so
//| that these requirements are met when matched with the intended
//| microcontroller board. For instance, the Feather M4 Express works
//| together with the RGB Matrix Feather.
//|
//| When specified as True, double buffering can reduce some flickering of
//| the matrix; however, this increases memory usage.
//|
//| The framebuffer is in "RGB565" format. If a framebuffer is not
//| passed in, one is allocated and initialized to all black. To update
//| the content, modify the framebuffer and call swapbuffers.
//|
//| If doublebuffer is False, some memory is saved, but the display may
//| flicker during updates.
//|
//| If a framebuffer is not passed in, one is allocated internally. To
//| retrieve it, pass the protomatter object to memoryview().
//|
STATIC mp_obj_t protomatter_protomatter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_width, ARG_bit_depth, ARG_rgb_list, ARG_addr_list,
ARG_clock_pin, ARG_latch_pin, ARG_oe_pin, ARG_doublebuffer, ARG_framebuffer };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED },
{ MP_QSTR_bit_depth, MP_ARG_INT | MP_ARG_REQUIRED },
{ MP_QSTR_rgb_pins, MP_ARG_OBJ | MP_ARG_REQUIRED },
{ MP_QSTR_addr_pins, MP_ARG_OBJ | MP_ARG_REQUIRED },
{ MP_QSTR_clock_pin, MP_ARG_OBJ | MP_ARG_REQUIRED },
{ MP_QSTR_latch_pin, MP_ARG_OBJ | MP_ARG_REQUIRED },
{ MP_QSTR_oe_pin, MP_ARG_OBJ | MP_ARG_REQUIRED },
{ MP_QSTR_doublebuffer, MP_ARG_BOOL, { .u_bool = true } },
{ MP_QSTR_framebuffer, MP_ARG_OBJ, { .u_obj = mp_const_none } },
};
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);
// Because interrupt handlers point directly at protomatter objects,
// it is NOT okay to move them to the long-lived pool later. Allocate
// them there to begin with, since generally they'll be long-lived anyway.
protomatter_protomatter_obj_t *self = &allocate_display_bus_or_raise()->protomatter;
self->base.type = &protomatter_Protomatter_type;
uint8_t rgb_count, addr_count;
uint8_t rgb_pins[MP_ARRAY_SIZE(self->rgb_pins)];
uint8_t addr_pins[MP_ARRAY_SIZE(self->addr_pins)];
uint8_t clock_pin = validate_pin(args[ARG_clock_pin].u_obj);
uint8_t latch_pin = validate_pin(args[ARG_latch_pin].u_obj);
uint8_t oe_pin = validate_pin(args[ARG_oe_pin].u_obj);
validate_pins(MP_QSTR_rgb_pins, rgb_pins, MP_ARRAY_SIZE(self->rgb_pins), args[ARG_rgb_list].u_obj, &rgb_count);
validate_pins(MP_QSTR_addr_pins, addr_pins, MP_ARRAY_SIZE(self->addr_pins), args[ARG_addr_list].u_obj, &addr_count);
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
if (framebuffer == mp_const_none) {
int width = args[ARG_width].u_int;
int bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
framebuffer = mp_obj_new_bytearray_of_zeros(bufsize);
}
common_hal_protomatter_protomatter_construct(self,
args[ARG_width].u_int,
args[ARG_bit_depth].u_int,
rgb_count, rgb_pins,
addr_count, addr_pins,
clock_pin, latch_pin, oe_pin,
args[ARG_doublebuffer].u_bool,
framebuffer, NULL);
claim_pins_nr(args[ARG_rgb_list].u_obj);
claim_pins_nr(args[ARG_addr_list].u_obj);
claim_pin_nr(args[ARG_clock_pin].u_obj);
claim_pin_nr(args[ARG_oe_pin].u_obj);
claim_pin_nr(args[ARG_latch_pin].u_obj);
return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit
//|
//| Free the resources (pins, timers, etc.) associated with this
//| protomatter instance. After deinitialization, no further operations
//| may be performed.
//|
STATIC mp_obj_t protomatter_protomatter_deinit(mp_obj_t self_in) {
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
common_hal_protomatter_protomatter_deinit(self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_deinit_obj, protomatter_protomatter_deinit);
static void check_for_deinit(protomatter_protomatter_obj_t *self) {
if (!self->core.rgbPins) {
raise_deinited_error();
}
}
//| .. attribute:: paused
//|
//| When paused, the matrix is not driven and all its LEDs are unlit.
//|
STATIC mp_obj_t protomatter_protomatter_get_paused(mp_obj_t self_in) {
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
check_for_deinit(self);
return mp_obj_new_bool(self->paused);
}
MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_get_paused_obj, protomatter_protomatter_get_paused);
STATIC mp_obj_t protomatter_protomatter_set_paused(mp_obj_t self_in, mp_obj_t value_in) {
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
check_for_deinit(self);
bool paused = mp_obj_is_true(value_in);
if (paused && !self->paused) {
_PM_stop(&self->core);
} else if (!paused && self->paused) {
_PM_resume(&self->core);
}
self->paused = paused;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(protomatter_protomatter_set_paused_obj, protomatter_protomatter_set_paused);
const mp_obj_property_t protomatter_protomatter_paused_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&protomatter_protomatter_get_paused_obj,
(mp_obj_t)&protomatter_protomatter_set_paused_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| .. method:: write(buf)
//|
//| Transmits the color data in the buffer to the pixels so that they are shown.
//|
//| The data in the buffer must be in "RGB565" format. This means
//| that it is organized as a series of 16-bit numbers where the highest 5
//| bits are interpreted as red, the next 6 as green, and the final 5 as
//| blue. The object can be any buffer, but `array.array` and `ulab.array`
//| objects are most often useful.
//|
STATIC mp_obj_t protomatter_protomatter_swapbuffers(mp_obj_t self_in) {
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
check_for_deinit(self);
_PM_convert_565(&self->core, self->bufinfo.buf, self->width);
_PM_swapbuffer_maybe(&self->core);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_swapbuffers_obj, protomatter_protomatter_swapbuffers);
STATIC const mp_rom_map_elem_t protomatter_protomatter_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&protomatter_protomatter_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_paused), MP_ROM_PTR(&protomatter_protomatter_paused_obj) },
{ MP_ROM_QSTR(MP_QSTR_swapbuffers), MP_ROM_PTR(&protomatter_protomatter_swapbuffers_obj) },
};
STATIC MP_DEFINE_CONST_DICT(protomatter_protomatter_locals_dict, protomatter_protomatter_locals_dict_table);
STATIC void protomatter_protomatter_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *bufinfo) {
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
check_for_deinit(self);
*bufinfo = self->bufinfo;
}
STATIC void protomatter_protomatter_swapbuffers_void(mp_obj_t self_in) {
protomatter_protomatter_swapbuffers(self_in);
}
STATIC void protomatter_protomatter_deinit_void(mp_obj_t self_in) {
protomatter_protomatter_deinit(self_in);
}
STATIC void protomatter_protomatter_set_brightness(mp_obj_t self_in, mp_float_t value) {
protomatter_protomatter_set_paused(self_in, mp_obj_new_bool(value <= 0));
}
STATIC const framebuffer_p_t protomatter_protomatter_proto = {
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer)
.get_bufinfo = protomatter_protomatter_get_bufinfo,
.set_brightness = protomatter_protomatter_set_brightness,
.swapbuffers = protomatter_protomatter_swapbuffers_void,
.deinit = protomatter_protomatter_deinit_void,
};
STATIC mp_int_t protomatter_protomatter_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
// a readonly framebuffer would be unusual but not impossible
if((flags & MP_BUFFER_WRITE) && !(self->bufinfo.typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) {
return 1;
}
*bufinfo = self->bufinfo;
return 0;
}
const mp_obj_type_t protomatter_Protomatter_type = {
{ &mp_type_type },
.name = MP_QSTR_Protomatter,
.buffer_p = { .get_buffer = protomatter_protomatter_get_buffer, },
.make_new = protomatter_protomatter_make_new,
.protocol = &protomatter_protomatter_proto,
.locals_dict = (mp_obj_dict_t*)&protomatter_protomatter_locals_dict,
};

View File

@ -0,0 +1,56 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jeff Epler 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_PROTOMATTER_PROTOMATTER_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_PROTOMATTER_PROTOMATTER_H
#include "shared-module/_protomatter/Protomatter.h"
#include "lib/protomatter/core.h"
extern const mp_obj_type_t protomatter_Protomatter_type;
typedef struct {
mp_obj_base_t base;
mp_obj_t framebuffer;
mp_buffer_info_t bufinfo;
Protomatter_core core;
void *timer;
uint16_t bufsize, width;
uint8_t rgb_pins[30];
uint8_t addr_pins[10];
uint8_t clock_pin, latch_pin, oe_pin;
uint8_t rgb_count, addr_count;
uint8_t bit_depth;
bool core_is_initialized;
bool paused;
bool doublebuffer;
} protomatter_protomatter_obj_t;
void common_hal_protomatter_protomatter_construct(protomatter_protomatter_obj_t* self, int width, int bit_depth, uint8_t rgb_count, uint8_t* rgb_pins, uint8_t addr_count, uint8_t* addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, void* timer);
void common_hal_protomatter_protomatter_deinit(protomatter_protomatter_obj_t*);
void protomatter_protomatter_collect_ptrs(protomatter_protomatter_obj_t*);
void common_hal_protomatter_protomatter_reconstruct(protomatter_protomatter_obj_t* self, mp_obj_t framebuffer);
#endif

View File

@ -0,0 +1,55 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jeff Epler 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 <stdint.h>
#include "py/obj.h"
#include "py/runtime.h"
#include "shared-bindings/_protomatter/Protomatter.h"
//| :mod:`_protomatter` --- Low-level routines for bitbanged LED matrices
//| =====================================================================
//|
//| .. module:: _protomatter
//| :synopsis: Low-level routines for bitbanged LED matrices
//|
//| .. toctree::
//| :maxdepth: 3
//|
//| Protomatter
STATIC const mp_rom_map_elem_t protomatter_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__protomatter) },
{ MP_ROM_QSTR(MP_QSTR_Protomatter), MP_ROM_PTR(&protomatter_Protomatter_type) },
};
STATIC MP_DEFINE_CONST_DICT(protomatter_module_globals, protomatter_module_globals_table);
const mp_obj_module_t protomatter_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&protomatter_module_globals,
};

View File

@ -92,6 +92,7 @@
//| :param bool pixels_in_byte_share_row: True when pixels are less than a byte and a byte includes pixels from the same row of the display. When False, pixels share a column.
//| :param int bytes_per_cell: Number of bytes per addressable memory location when color_depth < 8. When greater than one, bytes share a row or column according to pixels_in_byte_share_row.
//| :param bool reverse_pixels_in_byte: Reverses the pixel order within each byte when color_depth < 8. Does not apply across multiple bytes even if there is more than one byte per cell (bytes_per_cell.)
//| :param bool reverse_bytes_in_word: Reverses the order of bytes within a word when color_depth == 16
//| :param int set_column_command: Command used to set the start and end columns to update
//| :param int set_row_command: Command used so set the start and end rows to update
//| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set.
@ -107,7 +108,7 @@
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on.
//|
STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high };
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@ -121,6 +122,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
{ MP_QSTR_pixels_in_byte_share_row, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
{ MP_QSTR_bytes_per_cell, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} },
{ MP_QSTR_reverse_pixels_in_byte, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
{ MP_QSTR_reverse_bytes_in_word, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
{ MP_QSTR_set_column_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2a} },
{ MP_QSTR_set_row_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2b} },
{ MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} },
@ -159,7 +161,10 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
self,
display_bus, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation,
args[ARG_color_depth].u_int, args[ARG_grayscale].u_bool,
args[ARG_pixels_in_byte_share_row].u_bool, args[ARG_bytes_per_cell].u_bool, args[ARG_reverse_pixels_in_byte].u_bool,
args[ARG_pixels_in_byte_share_row].u_bool,
args[ARG_bytes_per_cell].u_bool,
args[ARG_reverse_pixels_in_byte].u_bool,
args[ARG_reverse_bytes_in_word].u_bool,
args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int,
args[ARG_write_ram_command].u_int,
args[ARG_set_vertical_scroll].u_int,

View File

@ -41,7 +41,7 @@ extern const mp_obj_type_t displayio_display_type;
void common_hal_displayio_display_construct(displayio_display_obj_t* self,
mp_obj_t bus, uint16_t width, uint16_t height,
int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, bool grayscale,
bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte,
bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word,
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command,
mp_float_t brightness, bool auto_brightness,

View File

@ -0,0 +1,452 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 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 "shared-bindings/framebufferio/FramebufferDisplay.h"
#include <stdint.h>
#include "lib/utils/context_manager_helpers.h"
#include "py/binary.h"
#include "py/objproperty.h"
#include "py/objtype.h"
#include "py/runtime.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/util.h"
#include "shared-module/displayio/__init__.h"
#include "supervisor/shared/translate.h"
//| .. currentmodule:: framebufferio
//|
//| :class:`FramebufferDisplay` -- Manage updating a display with framebuffer in RAM
//| ================================================================================
//|
//| This initializes a display and connects it into CircuitPython. Unlike other
//| objects in CircuitPython, Display objects live until `displayio.release_displays()`
//| is called. This is done so that CircuitPython can use the display itself.
//|
//| .. class:: FramebufferDisplay(framebuffer, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, bytes_per_cell=1, reverse_pixels_in_byte=False, backlight_pin=None, brightness=1.0, auto_brightness=False, auto_refresh=True, native_frames_per_second=60)
//|
//| Create a Display object with the given framebuffer (a buffer, array, ulab.array, etc)
//|
//| :param framebuffer: The framebuffer that the display is connected to
//| :type framebuffer: any core object implementing the framebuffer protocol
//| :param callback: Function or bound method to call when the framebuffer has been updated. The callback receives one argument, the framebuffer object.
//| :param int width: Width in pixels
//| :param int height: Height in pixels
//| :param int colstart: The index if the first visible column
//| :param int rowstart: The index if the first visible row
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
//| :param int color_depth: The number of bits of color per pixel transmitted. (Some displays
//| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.)
//| :param bool grayscale: True if the display only shows a single color.
//| :param bool pixels_in_byte_share_row: True when pixels are less than a byte and a byte includes pixels from the same row of the display. When False, pixels share a column.
//| :param int bytes_per_cell: Number of bytes per addressable memory location when color_depth < 8. When greater than one, bytes share a row or column according to pixels_in_byte_share_row.
//| :param bool reverse_pixels_in_byte: Reverses the pixel order within each byte when color_depth < 8. Does not apply across multiple bytes even if there is more than one byte per cell (bytes_per_cell.)
//| :param bool reverse_pixels_in_byte: Reverses the pixel order within each byte when color_depth < 8. Does not apply across multiple bytes even if there is more than one byte per cell (bytes_per_cell.)
//| :param bool reverse_bytes_in_word: Reverses the order of bytes within a word when color_depth == 16
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
//| :param bool brightness: Initial display brightness. This value is ignored if auto_brightness is True.
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
//| :param bool auto_refresh: Automatically refresh the screen
//| :param int native_frames_per_second: Number of display refreshes per second
//|
STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_framebuffer, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word, ARG_backlight_pin, ARG_brightness, ARG_auto_brightness, ARG_auto_refresh, ARG_native_frames_per_second, NUM_ARGS };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_framebuffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, },
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, },
{ MP_QSTR_colstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ MP_QSTR_rowstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ MP_QSTR_rotation, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} },
{ MP_QSTR_grayscale, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
{ MP_QSTR_pixels_in_byte_share_row, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
{ MP_QSTR_bytes_per_cell, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} },
{ MP_QSTR_reverse_pixels_in_byte, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
{ MP_QSTR_reverse_bytes_in_word, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
{ MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} },
{ MP_QSTR_auto_brightness, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
{ MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} },
};
MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS );
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_obj_t framebuffer = args[ARG_framebuffer].u_obj;
const mcu_pin_obj_t* backlight_pin = validate_obj_is_free_pin_or_none(args[ARG_backlight_pin].u_obj);
mp_float_t brightness = mp_obj_get_float(args[ARG_brightness].u_obj);
mp_int_t rotation = args[ARG_rotation].u_int;
if (rotation % 90 != 0) {
mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
}
primary_display_t *disp = allocate_display_or_raise();
framebufferio_framebufferdisplay_obj_t *self = &disp->framebuffer_display;
self->base.type = &framebufferio_framebufferdisplay_type;
common_hal_framebufferio_framebufferdisplay_construct(
self,
framebuffer,
args[ARG_width].u_int, args[ARG_height].u_int,
args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation,
args[ARG_color_depth].u_int, args[ARG_grayscale].u_bool,
args[ARG_pixels_in_byte_share_row].u_bool,
args[ARG_bytes_per_cell].u_bool,
args[ARG_reverse_pixels_in_byte].u_bool,
args[ARG_reverse_bytes_in_word].u_bool,
MP_OBJ_TO_PTR(backlight_pin),
brightness,
args[ARG_auto_brightness].u_bool,
args[ARG_auto_refresh].u_bool,
args[ARG_native_frames_per_second].u_int
);
return self;
}
// Helper to ensure we have the native super class instead of a subclass.
static framebufferio_framebufferdisplay_obj_t* native_display(mp_obj_t display_obj) {
mp_obj_t native_display = mp_instance_cast_to_native_base(display_obj, &framebufferio_framebufferdisplay_type);
mp_obj_assert_native_inited(native_display);
return MP_OBJ_TO_PTR(native_display);
}
//| .. method:: show(group)
//|
//| Switches to displaying the given group of layers. When group is None, the default
//| CircuitPython terminal will be shown.
//|
//| :param Group group: The group to show.
//|
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
displayio_group_t* group = NULL;
if (group_in != mp_const_none) {
group = MP_OBJ_TO_PTR(native_group(group_in));
}
bool ok = common_hal_framebufferio_framebufferdisplay_show(self, group);
if (!ok) {
mp_raise_ValueError(translate("Group already used"));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_show_obj, framebufferio_framebufferdisplay_obj_show);
//| .. method:: refresh(*, target_frames_per_second=60, minimum_frames_per_second=1)
//|
//| When auto refresh is off, waits for the target frame rate and then refreshes the display,
//| returning True. If the call has taken too long since the last refresh call for the given
//| target frame rate, then the refresh returns False immediately without updating the screen to
//| hopefully help getting caught up.
//|
//| If the time since the last successful refresh is below the minimum frame rate, then an
//| exception will be raised. Set minimum_frames_per_second to 0 to disable.
//|
//| When auto refresh is on, updates the display immediately. (The display will also update
//| without calls to this.)
//|
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second.
//|
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_refresh(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_target_frames_per_second, ARG_minimum_frames_per_second };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_target_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 60} },