summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorRoy Hooper <rhooper@toybox.ca>2019-01-19 16:33:59 -0500
committerRoy Hooper <rhooper@toybox.ca>2019-01-19 16:33:59 -0500
commit50af08a6f38f7bff3eb23e98f1c7e424db740eb2 (patch)
tree760c06b5497c225dd9945933484b8080ec21db26 /shared-module
parentbe9caeb9150df3ff8a30b2e7ab20f32b7fc9b5f7 (diff)
parentd2a7cd6c5aac4ef01b4503409a4bf47d4cdf31c3 (diff)
Merge branch 'master' into pixelbuf
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/displayio/Group.c7
-rw-r--r--shared-module/displayio/Shape.c90
-rw-r--r--shared-module/displayio/Shape.h46
-rw-r--r--shared-module/displayio/Sprite.c3
-rw-r--r--shared-module/displayio/__init__.c17
5 files changed, 160 insertions, 3 deletions
diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c
index 93ac35964..b9923128a 100644
--- a/shared-module/displayio/Group.c
+++ b/shared-module/displayio/Group.c
@@ -38,6 +38,13 @@ void common_hal_displayio_group_append(displayio_group_t* self, mp_obj_t layer)
if (self->size == self->max_size) {
mp_raise_RuntimeError(translate("Group full"));
}
+ mp_obj_t native_layer = mp_instance_cast_to_native_base(layer, &displayio_group_type);
+ if (native_layer == MP_OBJ_NULL) {
+ native_layer = mp_instance_cast_to_native_base(layer, &displayio_sprite_type);
+ }
+ if (native_layer == MP_OBJ_NULL) {
+ mp_raise_ValueError(translate("Layer must be a Group or Sprite subclass."));
+ }
self->children[self->size] = layer;
self->size++;
self->needs_refresh = true;
diff --git a/shared-module/displayio/Shape.c b/shared-module/displayio/Shape.c
new file mode 100644
index 000000000..2ae955a14
--- /dev/null
+++ b/shared-module/displayio/Shape.c
@@ -0,0 +1,90 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 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/Shape.h"
+
+#include <string.h>
+
+#include "py/runtime.h"
+
+void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t width,
+ uint32_t height, bool mirror_x, bool mirror_y) {
+ self->mirror_x = mirror_x;
+ self->mirror_y = mirror_y;
+ self->width = width;
+ if (self->mirror_x) {
+ width /= 2;
+ width += self->width % 2 - 1;
+ }
+ self->half_width = width;
+
+ self->height = height;
+ if (self->mirror_y) {
+ height /= 2;
+ height += self->height % 2 - 1;
+ }
+ self->half_height = height;
+
+ self->data = m_malloc(height * sizeof(uint32_t), false);
+ for (uint16_t i = 0; i <= height; i++) {
+ self->data[2 * i] = 0;
+ self->data[2 * i + 1] = width;
+ }
+}
+
+void common_hal_displayio_shape_set_boundary(displayio_shape_t *self, uint16_t y, uint16_t start_x, uint16_t end_x) {
+ if (y < 0 || y >= self->height || (self->mirror_y && y > self->half_height)) {
+ mp_raise_ValueError(translate("y value out of bounds"));
+ }
+ if (start_x < 0 || start_x > self->width || end_x < 0 || end_x > self->height) {
+ mp_raise_ValueError(translate("x value out of bounds"));
+ }
+ uint16_t half_width = self->width / 2 - 1 + self->width % 2;
+ if (self->mirror_x && (start_x > half_width || end_x > half_width)) {
+ mp_raise_ValueError_varg(translate("Maximum x value when mirrored is %d"), half_width);
+ }
+ self->data[2 * y] = start_x;
+ self->data[2 * y + 1] = end_x;
+}
+
+uint32_t common_hal_displayio_shape_get_pixel(void *obj, int16_t x, int16_t y) {
+ displayio_shape_t *self = obj;
+ if (x >= self->width || x < 0 || y >= self->height || y < 0) {
+ return 0;
+ }
+ if (self->mirror_x && x > self->half_width) {
+ x = self->width - 1 - x;
+ }
+ if (self->mirror_y && y > self->half_height) {
+ y = self->height - y - 1;
+ }
+ uint16_t start_x = self->data[2 * y];
+ uint16_t end_x = self->data[2 * y + 1];
+ if (x < start_x || x > end_x) {
+ return 0;
+ }
+ return 1;
+}
diff --git a/shared-module/displayio/Shape.h b/shared-module/displayio/Shape.h
new file mode 100644
index 000000000..ca054fe00
--- /dev/null
+++ b/shared-module/displayio/Shape.h
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 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.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SHAPE_H
+#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SHAPE_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ uint16_t width;
+ uint16_t height;
+ uint16_t half_width;
+ uint16_t half_height;
+ uint16_t* data;
+ bool mirror_x;
+ bool mirror_y;
+} displayio_shape_t;
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SHAPE_H
diff --git a/shared-module/displayio/Sprite.c b/shared-module/displayio/Sprite.c
index 87600f721..da6eff896 100644
--- a/shared-module/displayio/Sprite.c
+++ b/shared-module/displayio/Sprite.c
@@ -30,6 +30,7 @@
#include "shared-bindings/displayio/ColorConverter.h"
#include "shared-bindings/displayio/OnDiskBitmap.h"
#include "shared-bindings/displayio/Palette.h"
+#include "shared-bindings/displayio/Shape.h"
void common_hal_displayio_sprite_construct(displayio_sprite_t *self, mp_obj_t bitmap,
mp_obj_t pixel_shader, uint16_t width, uint16_t height, uint16_t x, uint16_t y) {
@@ -71,6 +72,8 @@ bool displayio_sprite_get_pixel(displayio_sprite_t *self, int16_t x, int16_t y,
uint32_t value = 0;
if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_bitmap_type)) {
value = common_hal_displayio_bitmap_get_pixel(self->bitmap, x, y);
+ } else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_shape_type)) {
+ value = common_hal_displayio_shape_get_pixel(self->bitmap, x, y);
} else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_ondiskbitmap_type)) {
value = common_hal_displayio_ondiskbitmap_get_pixel(self->bitmap, x, y);
}
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index df9c2963a..f1a00db9f 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -39,6 +39,8 @@ void displayio_refresh_display(void) {
return;
}
if (refresh_queued(display)) {
+ PORT->Group[1].DIRSET.reg = 1 << 22;
+
// We compute the pixels
uint16_t x0 = 0;
uint16_t y0 = 0;
@@ -53,10 +55,19 @@ void displayio_refresh_display(void) {
for (uint16_t x = x0; x < x1; ++x) {
uint16_t* pixel = &(((uint16_t*)buffer)[index]);
*pixel = 0;
- if (display->current_group != NULL) {
- displayio_group_get_pixel(display->current_group, x, y, pixel);
- }
+ PORT->Group[1].OUTTGL.reg = 1 << 22;
+
+ //if (index == 0) {
+ if (display->current_group != NULL) {
+ displayio_group_get_pixel(display->current_group, x, y, pixel);
+ }
+ // } else {
+ // *pixel = (((uint16_t*)buffer)[0]);
+ // }
+
+
+ PORT->Group[1].OUTTGL.reg = 1 << 22;
index += 1;
// The buffer is full, send it.