2019-08-16 21:34:00 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython 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/displayio/Display.h"
|
|
|
|
|
|
|
|
#include "py/gc.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "shared-bindings/displayio/FourWire.h"
|
|
|
|
#include "shared-bindings/displayio/I2CDisplay.h"
|
2021-08-29 12:49:47 -04:00
|
|
|
#if CIRCUITPY_PARALLELDISPLAY
|
2021-08-29 08:26:47 -04:00
|
|
|
#include "shared-bindings/paralleldisplay/ParallelBus.h"
|
2021-08-29 12:49:47 -04:00
|
|
|
#endif
|
2019-08-16 21:34:00 -04:00
|
|
|
#include "shared-bindings/microcontroller/Pin.h"
|
|
|
|
#include "shared-bindings/time/__init__.h"
|
|
|
|
#include "shared-module/displayio/__init__.h"
|
|
|
|
#include "supervisor/shared/display.h"
|
2019-11-18 09:22:41 -05:00
|
|
|
#include "supervisor/shared/tick.h"
|
2019-08-16 21:34:00 -04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-05-02 05:21:35 -04:00
|
|
|
#define DISPLAYIO_CORE_DEBUG(...) (void)0
|
2020-09-25 21:27:29 -04:00
|
|
|
// #define DISPLAYIO_CORE_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
|
2020-05-02 05:21:35 -04:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_display_core_construct(displayio_display_core_t *self,
|
|
|
|
mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_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 reverse_bytes_in_word) {
|
2019-08-16 21:34:00 -04:00
|
|
|
self->colorspace.depth = color_depth;
|
|
|
|
self->colorspace.grayscale = grayscale;
|
2020-10-26 19:58:00 -04:00
|
|
|
self->colorspace.grayscale_bit = 8 - color_depth;
|
2019-08-16 21:34:00 -04:00
|
|
|
self->colorspace.pixels_in_byte_share_row = pixels_in_byte_share_row;
|
|
|
|
self->colorspace.bytes_per_cell = bytes_per_cell;
|
|
|
|
self->colorspace.reverse_pixels_in_byte = reverse_pixels_in_byte;
|
2020-03-10 14:12:01 -04:00
|
|
|
self->colorspace.reverse_bytes_in_word = reverse_bytes_in_word;
|
2019-08-31 22:07:09 -04:00
|
|
|
self->colorspace.dither = false;
|
2019-08-16 21:34:00 -04:00
|
|
|
self->current_group = NULL;
|
|
|
|
self->colstart = colstart;
|
|
|
|
self->rowstart = rowstart;
|
2019-08-21 00:35:42 -04:00
|
|
|
self->last_refresh = 0;
|
2020-09-29 15:37:06 -04:00
|
|
|
|
2020-03-10 14:12:01 -04:00
|
|
|
// (framebufferdisplay already validated its 'bus' is a buffer-protocol object)
|
|
|
|
if (bus) {
|
2021-08-29 08:26:47 -04:00
|
|
|
#if CIRCUITPY_PARALLELDISPLAY
|
|
|
|
if (mp_obj_is_type(bus, ¶lleldisplay_parallelbus_type)) {
|
|
|
|
self->bus_reset = common_hal_paralleldisplay_parallelbus_reset;
|
|
|
|
self->bus_free = common_hal_paralleldisplay_parallelbus_bus_free;
|
|
|
|
self->begin_transaction = common_hal_paralleldisplay_parallelbus_begin_transaction;
|
|
|
|
self->send = common_hal_paralleldisplay_parallelbus_send;
|
|
|
|
self->end_transaction = common_hal_paralleldisplay_parallelbus_end_transaction;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (mp_obj_is_type(bus, &displayio_fourwire_type)) {
|
2020-03-10 14:12:01 -04:00
|
|
|
self->bus_reset = common_hal_displayio_fourwire_reset;
|
|
|
|
self->bus_free = common_hal_displayio_fourwire_bus_free;
|
|
|
|
self->begin_transaction = common_hal_displayio_fourwire_begin_transaction;
|
|
|
|
self->send = common_hal_displayio_fourwire_send;
|
|
|
|
self->end_transaction = common_hal_displayio_fourwire_end_transaction;
|
2021-04-22 20:55:39 -04:00
|
|
|
} else if (mp_obj_is_type(bus, &displayio_i2cdisplay_type)) {
|
2020-03-10 14:12:01 -04:00
|
|
|
self->bus_reset = common_hal_displayio_i2cdisplay_reset;
|
|
|
|
self->bus_free = common_hal_displayio_i2cdisplay_bus_free;
|
|
|
|
self->begin_transaction = common_hal_displayio_i2cdisplay_begin_transaction;
|
|
|
|
self->send = common_hal_displayio_i2cdisplay_send;
|
|
|
|
self->end_transaction = common_hal_displayio_i2cdisplay_end_transaction;
|
|
|
|
} else {
|
|
|
|
mp_raise_ValueError(translate("Unsupported display bus type"));
|
|
|
|
}
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
|
|
|
self->bus = bus;
|
|
|
|
|
|
|
|
|
2020-10-13 17:57:09 -04:00
|
|
|
// (offsetof core is equal in all display types)
|
|
|
|
if (self == &displays[0].display.core) {
|
|
|
|
supervisor_start_terminal(width, height);
|
|
|
|
}
|
2019-08-16 21:34:00 -04:00
|
|
|
|
|
|
|
self->width = width;
|
|
|
|
self->height = height;
|
2019-08-22 03:33:27 -04:00
|
|
|
self->ram_width = ram_width;
|
|
|
|
self->ram_height = ram_height;
|
2019-12-16 16:23:41 -05:00
|
|
|
|
|
|
|
displayio_display_core_set_rotation(self, rotation);
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_display_core_set_rotation(displayio_display_core_t *self,
|
|
|
|
int rotation) {
|
2019-12-16 16:23:41 -05:00
|
|
|
int height = self->height;
|
|
|
|
int width = self->width;
|
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
rotation = rotation % 360;
|
2019-09-03 12:35:41 -04:00
|
|
|
self->rotation = rotation;
|
2019-08-16 21:34:00 -04:00
|
|
|
self->transform.x = 0;
|
|
|
|
self->transform.y = 0;
|
|
|
|
self->transform.scale = 1;
|
|
|
|
self->transform.mirror_x = false;
|
|
|
|
self->transform.mirror_y = false;
|
|
|
|
self->transform.transpose_xy = false;
|
|
|
|
if (rotation == 0 || rotation == 180) {
|
|
|
|
if (rotation == 180) {
|
|
|
|
self->transform.mirror_x = true;
|
|
|
|
self->transform.mirror_y = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self->transform.transpose_xy = true;
|
|
|
|
if (rotation == 270) {
|
|
|
|
self->transform.mirror_y = true;
|
|
|
|
} else {
|
|
|
|
self->transform.mirror_x = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self->area.x1 = 0;
|
|
|
|
self->area.y1 = 0;
|
|
|
|
self->area.next = NULL;
|
|
|
|
|
|
|
|
self->transform.dx = 1;
|
|
|
|
self->transform.dy = 1;
|
|
|
|
if (self->transform.transpose_xy) {
|
|
|
|
self->area.x2 = height;
|
|
|
|
self->area.y2 = width;
|
|
|
|
if (self->transform.mirror_x) {
|
|
|
|
self->transform.x = height;
|
|
|
|
self->transform.dx = -1;
|
|
|
|
}
|
|
|
|
if (self->transform.mirror_y) {
|
|
|
|
self->transform.y = width;
|
|
|
|
self->transform.dy = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self->area.x2 = width;
|
|
|
|
self->area.y2 = height;
|
|
|
|
if (self->transform.mirror_x) {
|
|
|
|
self->transform.x = width;
|
|
|
|
self->transform.dx = -1;
|
|
|
|
}
|
|
|
|
if (self->transform.mirror_y) {
|
|
|
|
self->transform.y = height;
|
|
|
|
self->transform.dy = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 17:53:18 -05:00
|
|
|
bool displayio_display_core_set_root_group(displayio_display_core_t *self, displayio_group_t *root_group) {
|
2022-02-01 09:28:09 -05:00
|
|
|
|
2022-11-27 14:54:53 -05:00
|
|
|
if (root_group == NULL) {
|
|
|
|
// Show nothing on the display
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
|
|
|
if (root_group == self->current_group) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (root_group != NULL && root_group->in_group) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (self->current_group != NULL) {
|
|
|
|
self->current_group->in_group = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root_group != NULL) {
|
|
|
|
displayio_group_update_transform(root_group, &self->transform);
|
|
|
|
root_group->in_group = true;
|
|
|
|
}
|
|
|
|
self->current_group = root_group;
|
|
|
|
self->full_refresh = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
uint16_t displayio_display_core_get_width(displayio_display_core_t *self) {
|
2019-08-16 21:34:00 -04:00
|
|
|
return self->width;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
uint16_t displayio_display_core_get_height(displayio_display_core_t *self) {
|
2019-08-16 21:34:00 -04:00
|
|
|
return self->height;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_display_core_set_dither(displayio_display_core_t *self, bool dither) {
|
2019-08-31 22:07:09 -04:00
|
|
|
self->colorspace.dither = dither;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool displayio_display_core_get_dither(displayio_display_core_t *self) {
|
2019-08-31 22:07:09 -04:00
|
|
|
return self->colorspace.dither;
|
|
|
|
}
|
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
bool displayio_display_core_bus_free(displayio_display_core_t *self) {
|
2020-10-02 16:07:36 -04:00
|
|
|
return !self->bus || self->bus_free(self->bus);
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool displayio_display_core_begin_transaction(displayio_display_core_t *self) {
|
2019-08-16 21:34:00 -04:00
|
|
|
return self->begin_transaction(self->bus);
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_display_core_end_transaction(displayio_display_core_t *self) {
|
2019-08-16 21:34:00 -04:00
|
|
|
self->end_transaction(self->bus);
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_display_core_set_region_to_update(displayio_display_core_t *self, uint8_t column_command,
|
|
|
|
uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
|
|
|
|
bool data_as_commands, bool always_toggle_chip_select,
|
|
|
|
displayio_area_t *area, bool SH1107_addressing) {
|
2021-06-07 19:43:49 -04:00
|
|
|
uint16_t x1 = area->x1 + self->colstart;
|
|
|
|
uint16_t x2 = area->x2 + self->colstart;
|
|
|
|
uint16_t y1 = area->y1 + self->rowstart;
|
|
|
|
uint16_t y2 = area->y2 + self->rowstart;
|
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
// Collapse down the dimension where multiple pixels are in a byte.
|
|
|
|
if (self->colorspace.depth < 8) {
|
|
|
|
uint8_t pixels_per_byte = 8 / self->colorspace.depth;
|
|
|
|
if (self->colorspace.pixels_in_byte_share_row) {
|
|
|
|
x1 /= pixels_per_byte * self->colorspace.bytes_per_cell;
|
|
|
|
x2 /= pixels_per_byte * self->colorspace.bytes_per_cell;
|
|
|
|
} else {
|
|
|
|
y1 /= pixels_per_byte * self->colorspace.bytes_per_cell;
|
|
|
|
y2 /= pixels_per_byte * self->colorspace.bytes_per_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 19:43:49 -04:00
|
|
|
x2 -= 1;
|
|
|
|
y2 -= 1;
|
|
|
|
|
2019-08-23 18:27:21 -04:00
|
|
|
display_chip_select_behavior_t chip_select = CHIP_SELECT_UNTOUCHED;
|
|
|
|
if (always_toggle_chip_select || data_as_commands) {
|
|
|
|
chip_select = CHIP_SELECT_TOGGLE_EVERY_BYTE;
|
|
|
|
}
|
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
// Set column.
|
2019-08-23 18:27:21 -04:00
|
|
|
displayio_display_core_begin_transaction(self);
|
2019-08-16 21:34:00 -04:00
|
|
|
uint8_t data[5];
|
|
|
|
data[0] = column_command;
|
|
|
|
uint8_t data_length = 1;
|
2019-08-23 18:27:21 -04:00
|
|
|
display_byte_type_t data_type = DISPLAY_DATA;
|
2019-08-16 21:34:00 -04:00
|
|
|
if (!data_as_commands) {
|
2019-08-23 18:27:21 -04:00
|
|
|
self->send(self->bus, DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data, 1);
|
2019-08-16 21:34:00 -04:00
|
|
|
data_length = 0;
|
2019-08-23 18:27:21 -04:00
|
|
|
} else {
|
|
|
|
data_type = DISPLAY_COMMAND;
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
2021-06-07 19:43:49 -04:00
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
if (self->ram_width < 0x100) {
|
2021-06-07 19:43:49 -04:00
|
|
|
data[data_length++] = x1;
|
|
|
|
data[data_length++] = x2;
|
2019-08-16 21:34:00 -04:00
|
|
|
} else {
|
|
|
|
data[data_length++] = x1 >> 8;
|
|
|
|
data[data_length++] = x1 & 0xff;
|
|
|
|
data[data_length++] = x2 >> 8;
|
|
|
|
data[data_length++] = x2 & 0xff;
|
|
|
|
}
|
2021-06-06 18:25:40 -04:00
|
|
|
|
2020-09-24 22:07:33 -04:00
|
|
|
// Quirk for SH1107 "SH1107_addressing"
|
2021-06-06 18:25:40 -04:00
|
|
|
// Column lower command = 0x00, Column upper command = 0x10
|
2020-09-24 22:07:33 -04:00
|
|
|
if (SH1107_addressing) {
|
2021-06-06 18:25:40 -04:00
|
|
|
data[0] = ((x1 >> 4) & 0x0F) | 0x10; // 0x10 to 0x17
|
|
|
|
data[1] = x1 & 0x0F; // 0x00 to 0x0F
|
|
|
|
data_length = 2;
|
2020-09-21 21:07:42 -04:00
|
|
|
}
|
2021-06-06 18:25:40 -04:00
|
|
|
|
2019-08-23 18:27:21 -04:00
|
|
|
self->send(self->bus, data_type, chip_select, data, data_length);
|
|
|
|
displayio_display_core_end_transaction(self);
|
2020-09-21 21:07:42 -04:00
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
if (set_current_column_command != NO_COMMAND) {
|
|
|
|
uint8_t command = set_current_column_command;
|
2019-08-23 18:27:21 -04:00
|
|
|
displayio_display_core_begin_transaction(self);
|
|
|
|
self->send(self->bus, DISPLAY_COMMAND, chip_select, &command, 1);
|
|
|
|
self->send(self->bus, DISPLAY_DATA, chip_select, data, data_length / 2);
|
|
|
|
displayio_display_core_end_transaction(self);
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
|
|
|
|
2019-08-22 03:33:27 -04:00
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
// Set row.
|
2019-08-23 18:27:21 -04:00
|
|
|
displayio_display_core_begin_transaction(self);
|
2019-08-16 21:34:00 -04:00
|
|
|
data[0] = row_command;
|
|
|
|
data_length = 1;
|
|
|
|
if (!data_as_commands) {
|
2019-08-23 18:27:21 -04:00
|
|
|
self->send(self->bus, DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data, 1);
|
2019-08-16 21:34:00 -04:00
|
|
|
data_length = 0;
|
|
|
|
}
|
2021-06-07 19:43:49 -04:00
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
if (self->ram_height < 0x100) {
|
2021-06-07 19:43:49 -04:00
|
|
|
data[data_length++] = y1;
|
|
|
|
data[data_length++] = y2;
|
2019-08-16 21:34:00 -04:00
|
|
|
} else {
|
|
|
|
data[data_length++] = y1 >> 8;
|
|
|
|
data[data_length++] = y1 & 0xff;
|
|
|
|
data[data_length++] = y2 >> 8;
|
|
|
|
data[data_length++] = y2 & 0xff;
|
|
|
|
}
|
2021-06-06 18:25:40 -04:00
|
|
|
|
2020-09-24 22:07:33 -04:00
|
|
|
// Quirk for SH1107 "SH1107_addressing"
|
2021-06-06 18:25:40 -04:00
|
|
|
// Page address command = 0xB0
|
2020-09-24 22:07:33 -04:00
|
|
|
if (SH1107_addressing) {
|
2021-06-06 18:25:40 -04:00
|
|
|
// set the page to our y value
|
|
|
|
data[0] = 0xB0 | y1;
|
|
|
|
data_length = 1;
|
2020-09-21 21:07:42 -04:00
|
|
|
}
|
|
|
|
|
2021-06-06 18:25:40 -04:00
|
|
|
self->send(self->bus, data_type, chip_select, data, data_length);
|
2019-08-23 18:27:21 -04:00
|
|
|
displayio_display_core_end_transaction(self);
|
|
|
|
|
2019-08-16 21:34:00 -04:00
|
|
|
if (set_current_row_command != NO_COMMAND) {
|
|
|
|
uint8_t command = set_current_row_command;
|
2019-08-23 18:27:21 -04:00
|
|
|
displayio_display_core_begin_transaction(self);
|
|
|
|
self->send(self->bus, DISPLAY_COMMAND, chip_select, &command, 1);
|
|
|
|
self->send(self->bus, DISPLAY_DATA, chip_select, data, data_length / 2);
|
|
|
|
displayio_display_core_end_transaction(self);
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool displayio_display_core_start_refresh(displayio_display_core_t *self) {
|
2020-09-11 22:37:00 -04:00
|
|
|
if (!displayio_display_core_bus_free(self)) {
|
|
|
|
// Can't acquire display bus; skip updating this display. Try next display.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (self->refresh_in_progress) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
self->refresh_in_progress = true;
|
2019-11-18 09:22:41 -05:00
|
|
|
self->last_refresh = supervisor_ticks_ms64();
|
2020-09-11 22:37:00 -04:00
|
|
|
return true;
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_display_core_finish_refresh(displayio_display_core_t *self) {
|
2019-08-16 21:34:00 -04:00
|
|
|
if (self->current_group != NULL) {
|
2020-09-25 21:27:29 -04:00
|
|
|
DISPLAYIO_CORE_DEBUG("displayiocore group_finish_refresh\n");
|
2019-08-16 21:34:00 -04:00
|
|
|
displayio_group_finish_refresh(self->current_group);
|
|
|
|
}
|
|
|
|
self->full_refresh = false;
|
2020-09-11 22:37:00 -04:00
|
|
|
self->refresh_in_progress = false;
|
2019-11-18 09:22:41 -05:00
|
|
|
self->last_refresh = supervisor_ticks_ms64();
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void release_display_core(displayio_display_core_t *self) {
|
2019-08-16 21:34:00 -04:00
|
|
|
if (self->current_group != NULL) {
|
|
|
|
self->current_group->in_group = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_display_core_collect_ptrs(displayio_display_core_t *self) {
|
2019-08-16 21:34:00 -04:00
|
|
|
gc_collect_ptr(self->current_group);
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool displayio_display_core_fill_area(displayio_display_core_t *self, displayio_area_t *area, uint32_t *mask, uint32_t *buffer) {
|
2022-11-27 18:26:46 -05:00
|
|
|
if (self->current_group != NULL) {
|
|
|
|
return displayio_group_fill_area(self->current_group,&self->colorspace, area, mask, buffer);
|
2022-11-27 14:54:53 -05:00
|
|
|
}
|
|
|
|
return false;
|
2019-08-16 21:34:00 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool displayio_display_core_clip_area(displayio_display_core_t *self, const displayio_area_t *area, displayio_area_t *clipped) {
|
2019-08-16 21:34:00 -04:00
|
|
|
bool overlaps = displayio_area_compute_overlap(&self->area, area, clipped);
|
|
|
|
if (!overlaps) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Expand the area if we have multiple pixels per byte and we need to byte
|
|
|
|
// align the bounds.
|
|
|
|
if (self->colorspace.depth < 8) {
|
|
|
|
uint8_t pixels_per_byte = 8 / self->colorspace.depth * self->colorspace.bytes_per_cell;
|
|
|
|
if (self->colorspace.pixels_in_byte_share_row) {
|
|
|
|
if (clipped->x1 % pixels_per_byte != 0) {
|
|
|
|
clipped->x1 -= clipped->x1 % pixels_per_byte;
|
|
|
|
}
|
|
|
|
if (clipped->x2 % pixels_per_byte != 0) {
|
|
|
|
clipped->x2 += pixels_per_byte - clipped->x2 % pixels_per_byte;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (clipped->y1 % pixels_per_byte != 0) {
|
|
|
|
clipped->y1 -= clipped->y1 % pixels_per_byte;
|
|
|
|
}
|
|
|
|
if (clipped->y2 % pixels_per_byte != 0) {
|
|
|
|
clipped->y2 += pixels_per_byte - clipped->y2 % pixels_per_byte;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|