@ -163,19 +163,16 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
//|
//| If a framebuffer is not passed in, one is allocated and initialized
//| to all black. In any case, the framebuffer can be retrieved
//| by passing the protomatter object to memoryview().
//| by passing the RGBMatrix object to memoryview().
//|
//| 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().
//|
//| A RGBMatrix is often used in conjunction with a
//| `framebufferio.FramebufferDisplay`.
//|
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 ) {
STATIC mp_obj_t rgbmatrix_rgbmatrix _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_output_enable_pin , ARG_doublebuffer , ARG_framebuffer , ARG_height } ;
static const mp_arg_t allowed_args [ ] = {
@ -193,11 +190,11 @@ STATIC mp_obj_t protomatter_protomatter_make_new(const mp_obj_type_t *type, size
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,
// Because interrupt handlers point directly at rgbmatrix 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;
rgbmatrix_rgbmatrix _obj_t * self = & allocate_display_bus_or_raise ( ) - > rgbmatrix ;
self - > base . type = & rgbmatrix_RGBMatrix _type;
uint8_t rgb_count , addr_count ;
uint8_t rgb_pins [ MP_ARRAY_SIZE ( self - > rgb_pins ) ] ;
@ -231,7 +228,7 @@ STATIC mp_obj_t protomatter_protomatter_make_new(const mp_obj_type_t *type, size
framebuffer = mp_obj_new_bytearray_of_zeros ( bufsize ) ;
}
common_hal_ protomatter_protomatter _construct( self ,
common_hal_ rgbmatrix_rgbmatrix _construct( self ,
args [ ARG_width ] . u_int ,
args [ ARG_bit_depth ] . u_int ,
rgb_count , rgb_pins ,
@ -252,18 +249,18 @@ STATIC mp_obj_t protomatter_protomatter_make_new(const mp_obj_type_t *type, size
//| .. method:: deinit
//|
//| Free the resources (pins, timers, etc.) associated with this
//| protomatter instance. After deinitialization, no further operations
//| rgbmatrix 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 ) ;
STATIC mp_obj_t rgbmatrix_rgbmatrix _deinit( mp_obj_t self_in ) {
rgbmatrix_rgbmatrix_obj_t * self = ( rgbmatrix_rgbmatrix _obj_t* ) self_in ;
common_hal_ rgbmatrix_rgbmatrix _deinit( self ) ;
return mp_const_none ;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1 ( protomatter_protomatter_deinit_obj, protomatter_protomatter _deinit) ;
STATIC MP_DEFINE_CONST_FUN_OBJ_1 ( rgbmatrix_rgbmatrix_deinit_obj, rgbmatrix_rgbmatrix _deinit) ;
static void check_for_deinit ( protomatter_protomatter _obj_t * self ) {
static void check_for_deinit ( rgbmatrix_rgbmatrix _obj_t * self ) {
if ( ! self - > core . rgbPins ) {
raise_deinited_error ( ) ;
}
@ -274,30 +271,30 @@ static void check_for_deinit(protomatter_protomatter_obj_t *self) {
//| In the current implementation, 0.0 turns the display off entirely
//| and any other value up to 1.0 turns the display on fully.
//|
STATIC mp_obj_t protomatter_protomatter _get_brightness( mp_obj_t self_in ) {
protomatter_protomatter_obj_t * self = ( protomatter_protomatter _obj_t* ) self_in ;
STATIC mp_obj_t rgbmatrix_rgbmatrix _get_brightness( mp_obj_t self_in ) {
rgbmatrix_rgbmatrix_obj_t * self = ( rgbmatrix_rgbmatrix _obj_t* ) self_in ;
check_for_deinit ( self ) ;
return mp_obj_new_float ( common_hal_ protomatter_protomatter _get_paused( self ) ? 0.0f : 1.0f ) ;
return mp_obj_new_float ( common_hal_ rgbmatrix_rgbmatrix _get_paused( self ) ? 0.0f : 1.0f ) ;
}
MP_DEFINE_CONST_FUN_OBJ_1 ( protomatter_protomatter_get_brightness_obj, protomatter_protomatter _get_brightness) ;
MP_DEFINE_CONST_FUN_OBJ_1 ( rgbmatrix_rgbmatrix_get_brightness_obj, rgbmatrix_rgbmatrix _get_brightness) ;
STATIC mp_obj_t protomatter_protomatter _set_brightness( mp_obj_t self_in , mp_obj_t value_in ) {
protomatter_protomatter_obj_t * self = ( protomatter_protomatter _obj_t* ) self_in ;
STATIC mp_obj_t rgbmatrix_rgbmatrix _set_brightness( mp_obj_t self_in , mp_obj_t value_in ) {
rgbmatrix_rgbmatrix_obj_t * self = ( rgbmatrix_rgbmatrix _obj_t* ) self_in ;
check_for_deinit ( self ) ;
mp_float_t brightness = mp_obj_get_float ( value_in ) ;
if ( brightness < 0.0f | | brightness > 1.0f ) {
mp_raise_ValueError ( translate ( " Brightness must be 0-1.0 " ) ) ;
}
common_hal_ protomatter_protomatter _set_paused( self_in , brightness < = 0 ) ;
common_hal_ rgbmatrix_rgbmatrix _set_paused( self_in , brightness < = 0 ) ;
return mp_const_none ;
}
MP_DEFINE_CONST_FUN_OBJ_2 ( protomatter_protomatter_set_brightness_obj, protomatter_protomatter _set_brightness) ;
MP_DEFINE_CONST_FUN_OBJ_2 ( rgbmatrix_rgbmatrix_set_brightness_obj, rgbmatrix_rgbmatrix _set_brightness) ;
const mp_obj_property_t protomatter_protomatter _brightness_obj = {
const mp_obj_property_t rgbmatrix_rgbmatrix _brightness_obj = {
. base . type = & mp_type_property ,
. proxy = { ( mp_obj_t ) & protomatter_protomatter _get_brightness_obj,
( mp_obj_t ) & protomatter_protomatter _set_brightness_obj,
. proxy = { ( mp_obj_t ) & rgbmatrix_rgbmatrix _get_brightness_obj,
( mp_obj_t ) & rgbmatrix_rgbmatrix _set_brightness_obj,
( mp_obj_t ) & mp_const_none_obj } ,
} ;
@ -306,27 +303,27 @@ const mp_obj_property_t protomatter_protomatter_brightness_obj = {
//| Transmits the color data in the buffer to the pixels so that
//| they are shown.
//|
STATIC mp_obj_t protomatter_protomatter _refresh( mp_obj_t self_in ) {
protomatter_protomatter_obj_t * self = ( protomatter_protomatter _obj_t* ) self_in ;
STATIC mp_obj_t rgbmatrix_rgbmatrix _refresh( mp_obj_t self_in ) {
rgbmatrix_rgbmatrix_obj_t * self = ( rgbmatrix_rgbmatrix _obj_t* ) self_in ;
check_for_deinit ( self ) ;
common_hal_ protomatter_protomatter _refresh( self ) ;
common_hal_ rgbmatrix_rgbmatrix _refresh( self ) ;
return mp_const_none ;
}
MP_DEFINE_CONST_FUN_OBJ_1 ( protomatter_protomatter_refresh_obj, protomatter_protomatter _refresh) ;
MP_DEFINE_CONST_FUN_OBJ_1 ( rgbmatrix_rgbmatrix_refresh_obj, rgbmatrix_rgbmatrix _refresh) ;
//| .. attribute:: width
//|
//| The width of the display, in pixels
//|
STATIC mp_obj_t protomatter_protomatter _get_width( mp_obj_t self_in ) {
protomatter_protomatter_obj_t * self = ( protomatter_protomatter _obj_t* ) self_in ;
STATIC mp_obj_t rgbmatrix_rgbmatrix _get_width( mp_obj_t self_in ) {
rgbmatrix_rgbmatrix_obj_t * self = ( rgbmatrix_rgbmatrix _obj_t* ) self_in ;
check_for_deinit ( self ) ;
return MP_OBJ_NEW_SMALL_INT ( common_hal_ protomatter_protomatter _get_width( self ) ) ;
return MP_OBJ_NEW_SMALL_INT ( common_hal_ rgbmatrix_rgbmatrix _get_width( self ) ) ;
}
MP_DEFINE_CONST_FUN_OBJ_1 ( protomatter_protomatter_get_width_obj, protomatter_protomatter _get_width) ;
const mp_obj_property_t protomatter_protomatter _width_obj = {
MP_DEFINE_CONST_FUN_OBJ_1 ( rgbmatrix_rgbmatrix_get_width_obj, rgbmatrix_rgbmatrix _get_width) ;
const mp_obj_property_t rgbmatrix_rgbmatrix _width_obj = {
. base . type = & mp_type_property ,
. proxy = { ( mp_obj_t ) & protomatter_protomatter _get_width_obj,
. proxy = { ( mp_obj_t ) & rgbmatrix_rgbmatrix _get_width_obj,
( mp_obj_t ) & mp_const_none_obj ,
( mp_obj_t ) & mp_const_none_obj } ,
} ;
@ -335,31 +332,31 @@ const mp_obj_property_t protomatter_protomatter_width_obj = {
//|
//| The height of the display, in pixels
//|
STATIC mp_obj_t protomatter_protomatter _get_height( mp_obj_t self_in ) {
protomatter_protomatter_obj_t * self = ( protomatter_protomatter _obj_t* ) self_in ;
STATIC mp_obj_t rgbmatrix_rgbmatrix _get_height( mp_obj_t self_in ) {
rgbmatrix_rgbmatrix_obj_t * self = ( rgbmatrix_rgbmatrix _obj_t* ) self_in ;
check_for_deinit ( self ) ;
return MP_OBJ_NEW_SMALL_INT ( common_hal_ protomatter_protomatter _get_height( self ) ) ;
return MP_OBJ_NEW_SMALL_INT ( common_hal_ rgbmatrix_rgbmatrix _get_height( self ) ) ;
}
MP_DEFINE_CONST_FUN_OBJ_1 ( protomatter_protomatter_get_height_obj, protomatter_protomatter _get_height) ;
MP_DEFINE_CONST_FUN_OBJ_1 ( rgbmatrix_rgbmatrix_get_height_obj, rgbmatrix_rgbmatrix _get_height) ;
const mp_obj_property_t protomatter_protomatter _height_obj = {
const mp_obj_property_t rgbmatrix_rgbmatrix _height_obj = {
. base . type = & mp_type_property ,
. proxy = { ( mp_obj_t ) & protomatter_protomatter _get_height_obj,
. proxy = { ( mp_obj_t ) & rgbmatrix_rgbmatrix _get_height_obj,
( mp_obj_t ) & mp_const_none_obj ,
( mp_obj_t ) & mp_const_none_obj } ,
} ;
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_brightness ) , MP_ROM_PTR ( & protomatter_protomatter _brightness_obj) } ,
{ MP_ROM_QSTR ( MP_QSTR_refresh ) , MP_ROM_PTR ( & protomatter_protomatter _refresh_obj) } ,
{ MP_ROM_QSTR ( MP_QSTR_width ) , MP_ROM_PTR ( & protomatter_protomatter _width_obj) } ,
{ MP_ROM_QSTR ( MP_QSTR_height ) , MP_ROM_PTR ( & protomatter_protomatter _height_obj) } ,
STATIC const mp_rom_map_elem_t rgbmatrix_rgbmatrix _locals_dict_table[ ] = {
{ MP_ROM_QSTR ( MP_QSTR_deinit ) , MP_ROM_PTR ( & rgbmatrix_rgbmatrix _deinit_obj) } ,
{ MP_ROM_QSTR ( MP_QSTR_brightness ) , MP_ROM_PTR ( & rgbmatrix_rgbmatrix _brightness_obj) } ,
{ MP_ROM_QSTR ( MP_QSTR_refresh ) , MP_ROM_PTR ( & rgbmatrix_rgbmatrix _refresh_obj) } ,
{ MP_ROM_QSTR ( MP_QSTR_width ) , MP_ROM_PTR ( & rgbmatrix_rgbmatrix _width_obj) } ,
{ MP_ROM_QSTR ( MP_QSTR_height ) , MP_ROM_PTR ( & rgbmatrix_rgbmatrix _height_obj) } ,
} ;
STATIC MP_DEFINE_CONST_DICT ( protomatter_protomatter_locals_dict, protomatter_protomatter _locals_dict_table) ;
STATIC MP_DEFINE_CONST_DICT ( rgbmatrix_rgbmatrix_locals_dict, rgbmatrix_rgbmatrix _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 ;
STATIC void rgbmatrix_rgbmatrix _get_bufinfo( mp_obj_t self_in , mp_buffer_info_t * bufinfo ) {
rgbmatrix_rgbmatrix_obj_t * self = ( rgbmatrix_rgbmatrix _obj_t* ) self_in ;
check_for_deinit ( self ) ;
* bufinfo = self - > bufinfo ;
@ -367,60 +364,60 @@ STATIC void protomatter_protomatter_get_bufinfo(mp_obj_t self_in, mp_buffer_info
// These version exists so that the prototype matches the protocol,
// avoiding a type cast that can hide errors
STATIC void protomatter_protomatter _swapbuffers( mp_obj_t self_in ) {
common_hal_ protomatter_protomatter _refresh( self_in ) ;
STATIC void rgbmatrix_rgbmatrix _swapbuffers( mp_obj_t self_in ) {
common_hal_ rgbmatrix_rgbmatrix _refresh( self_in ) ;
}
STATIC void protomatter_protomatter _deinit_proto( mp_obj_t self_in ) {
common_hal_ protomatter_protomatter _deinit( self_in ) ;
STATIC void rgbmatrix_rgbmatrix _deinit_proto( mp_obj_t self_in ) {
common_hal_ rgbmatrix_rgbmatrix _deinit( self_in ) ;
}
STATIC float protomatter_protomatter _get_brightness_proto( mp_obj_t self_in ) {
return common_hal_ protomatter_protomatter _get_paused( self_in ) ? 0.0f : 1.0f ;
STATIC float rgbmatrix_rgbmatrix _get_brightness_proto( mp_obj_t self_in ) {
return common_hal_ rgbmatrix_rgbmatrix _get_paused( self_in ) ? 0.0f : 1.0f ;
}
STATIC bool protomatter_protomatter _set_brightness_proto( mp_obj_t self_in , mp_float_t value ) {
common_hal_ protomatter_protomatter _set_paused( self_in , value < = 0 ) ;
STATIC bool rgbmatrix_rgbmatrix _set_brightness_proto( mp_obj_t self_in , mp_float_t value ) {
common_hal_ rgbmatrix_rgbmatrix _set_paused( self_in , value < = 0 ) ;
return true ;
}
STATIC int protomatter_protomatter _get_width_proto( mp_obj_t self_in ) {
return common_hal_ protomatter_protomatter _get_width( self_in ) ;
STATIC int rgbmatrix_rgbmatrix _get_width_proto( mp_obj_t self_in ) {
return common_hal_ rgbmatrix_rgbmatrix _get_width( self_in ) ;
}
STATIC int protomatter_protomatter _get_height_proto( mp_obj_t self_in ) {
return common_hal_ protomatter_protomatter _get_height( self_in ) ;
STATIC int rgbmatrix_rgbmatrix _get_height_proto( mp_obj_t self_in ) {
return common_hal_ rgbmatrix_rgbmatrix _get_height( self_in ) ;
}
STATIC int protomatter_protomatter _get_color_depth_proto( mp_obj_t self_in ) {
STATIC int rgbmatrix_rgbmatrix _get_color_depth_proto( mp_obj_t self_in ) {
return 16 ;
}
STATIC int protomatter_protomatter _get_bytes_per_cell_proto( mp_obj_t self_in ) {
STATIC int rgbmatrix_rgbmatrix _get_bytes_per_cell_proto( mp_obj_t self_in ) {
return 1 ;
}
STATIC int protomatter_protomatter _get_native_frames_per_second_proto( mp_obj_t self_in ) {
STATIC int rgbmatrix_rgbmatrix _get_native_frames_per_second_proto( mp_obj_t self_in ) {
return 250 ;
}
STATIC const framebuffer_p_t protomatter_protomatter _proto = {
STATIC const framebuffer_p_t rgbmatrix_rgbmatrix _proto = {
MP_PROTO_IMPLEMENT ( MP_QSTR_protocol_framebuffer )
. get_bufinfo = protomatter_protomatter _get_bufinfo,
. set_brightness = protomatter_protomatter _set_brightness_proto,
. get_brightness = protomatter_protomatter _get_brightness_proto,
. get_width = protomatter_protomatter _get_width_proto,
. get_height = protomatter_protomatter _get_height_proto,
. get_color_depth = protomatter_protomatter _get_color_depth_proto,
. get_bytes_per_cell = protomatter_protomatter _get_bytes_per_cell_proto,
. get_native_frames_per_second = protomatter_protomatter _get_native_frames_per_second_proto,
. swapbuffers = protomatter_protomatter _swapbuffers,
. deinit = protomatter_protomatter _deinit_proto,
. get_bufinfo = rgbmatrix_rgbmatrix _get_bufinfo,
. set_brightness = rgbmatrix_rgbmatrix _set_brightness_proto,
. get_brightness = rgbmatrix_rgbmatrix _get_brightness_proto,
. get_width = rgbmatrix_rgbmatrix _get_width_proto,
. get_height = rgbmatrix_rgbmatrix _get_height_proto,
. get_color_depth = rgbmatrix_rgbmatrix _get_color_depth_proto,
. get_bytes_per_cell = rgbmatrix_rgbmatrix _get_bytes_per_cell_proto,
. get_native_frames_per_second = rgbmatrix_rgbmatrix _get_native_frames_per_second_proto,
. swapbuffers = rgbmatrix_rgbmatrix _swapbuffers,
. deinit = rgbmatrix_rgbmatrix _deinit_proto,
} ;
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 ;
STATIC mp_int_t rgbmatrix_rgbmatrix _get_buffer( mp_obj_t self_in , mp_buffer_info_t * bufinfo , mp_uint_t flags ) {
rgbmatrix_rgbmatrix_obj_t * self = ( rgbmatrix_rgbmatrix _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 ;
@ -429,11 +426,11 @@ STATIC mp_int_t protomatter_protomatter_get_buffer(mp_obj_t self_in, mp_buffer_i
return 0 ;
}
const mp_obj_type_t protomatter_Protomatter _type = {
const mp_obj_type_t rgbmatrix_RGBMatrix _type = {
{ & mp_type_type } ,
. name = MP_QSTR_RGBMatrix ,
. 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,
. buffer_p = { . get_buffer = rgbmatrix_rgbmatrix _get_buffer, } ,
. make_new = rgbmatrix_rgbmatrix _make_new,
. protocol = & rgbmatrix_rgbmatrix _proto,
. locals_dict = ( mp_obj_dict_t * ) & rgbmatrix_rgbmatrix _locals_dict,
} ;