summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/_stage/__init__.c2
-rw-r--r--shared-module/board/__init__.c4
-rw-r--r--shared-module/canio/Match.c8
-rw-r--r--shared-module/canio/Match.h2
-rw-r--r--shared-module/canio/Message.c28
-rw-r--r--shared-module/canio/Message.h1
-rw-r--r--shared-module/canio/RemoteTransmissionRequest.c67
-rw-r--r--shared-module/canio/RemoteTransmissionRequest.h33
-rw-r--r--shared-module/displayio/Display.c24
-rw-r--r--shared-module/displayio/Display.h2
-rw-r--r--shared-module/displayio/EPaperDisplay.c5
-rw-r--r--shared-module/displayio/__init__.c10
-rw-r--r--shared-module/displayio/display_core.c35
-rw-r--r--shared-module/displayio/display_core.h8
-rw-r--r--shared-module/sharpdisplay/SharpMemoryFramebuffer.c8
15 files changed, 176 insertions, 61 deletions
diff --git a/shared-module/_stage/__init__.c b/shared-module/_stage/__init__.c
index 0323c32cb..6dfc18880 100644
--- a/shared-module/_stage/__init__.c
+++ b/shared-module/_stage/__init__.c
@@ -45,7 +45,7 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
area.y2 = y1;
displayio_display_core_set_region_to_update(
&display->core, display->set_column_command, display->set_row_command,
- NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area);
+ NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area, display->SH1107_addressing);
while (!displayio_display_core_begin_transaction(&display->core)) {
RUN_BACKGROUND_TASKS;
diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c
index fb4f731b8..39b68a0f1 100644
--- a/shared-module/board/__init__.c
+++ b/shared-module/board/__init__.c
@@ -167,7 +167,9 @@ void reset_board_busses(void) {
}
#endif
// make sure SPI lock is not held over a soft reset
- common_hal_busio_spi_unlock(&spi_obj);
+ if (spi_singleton != NULL) {
+ common_hal_busio_spi_unlock(spi_singleton);
+ }
if (!display_using_spi) {
spi_singleton = NULL;
}
diff --git a/shared-module/canio/Match.c b/shared-module/canio/Match.c
index 9e33b956f..b4e8616e9 100644
--- a/shared-module/canio/Match.c
+++ b/shared-module/canio/Match.c
@@ -26,14 +26,14 @@
#include "shared-module/canio/Match.h"
-void common_hal_canio_match_construct(canio_match_obj_t *self, int address, int mask, bool extended) {
- self->address = address;
+void common_hal_canio_match_construct(canio_match_obj_t *self, int id, int mask, bool extended) {
+ self->id = id;
self->mask = mask;
self->extended = extended;
}
-int common_hal_canio_match_get_address(const canio_match_obj_t *self) {
- return self->address;
+int common_hal_canio_match_get_id(const canio_match_obj_t *self) {
+ return self->id;
}
int common_hal_canio_match_get_mask(const canio_match_obj_t *self) {
return self->mask;
diff --git a/shared-module/canio/Match.h b/shared-module/canio/Match.h
index 25f047f37..b52191d7c 100644
--- a/shared-module/canio/Match.h
+++ b/shared-module/canio/Match.h
@@ -30,7 +30,7 @@
typedef struct {
mp_obj_base_t base;
- int address;
+ int id;
int mask;
bool extended;
} canio_match_obj_t;
diff --git a/shared-module/canio/Message.c b/shared-module/canio/Message.c
index b8ebb7859..a1df4f693 100644
--- a/shared-module/canio/Message.c
+++ b/shared-module/canio/Message.c
@@ -28,16 +28,13 @@
#include <string.h>
-void common_hal_canio_message_construct(canio_message_obj_t *self, int id, void *data, size_t size, bool rtr, bool extended)
+void common_hal_canio_message_construct(canio_message_obj_t *self, int id, void *data, size_t size, bool extended)
{
self->id = id;
self->size = size;
- self->rtr = rtr;
self->extended = extended;
if (data) {
memcpy(self->data, data, size);
- } else {
- memset(self->data, 0, size);
}
}
@@ -59,37 +56,16 @@ const void *common_hal_canio_message_get_data(const canio_message_obj_t *self)
const void common_hal_canio_message_set_data(canio_message_obj_t *self, const void *data, size_t size)
{
- self->rtr = false;
self->size = size;
memcpy(self->data, data, size);
}
-size_t common_hal_canio_message_get_size(const canio_message_obj_t *self)
+size_t common_hal_canio_message_get_length(const canio_message_obj_t *self)
{
return self->size;
}
-void common_hal_canio_message_set_size(canio_message_obj_t *self, size_t size)
-{
- memset(self->data, 0, size);
- self->size = size;
-}
-
-
-bool common_hal_canio_message_get_rtr(const canio_message_obj_t *self)
-{
- return self->rtr;
-}
-
-void common_hal_canio_message_set_rtr(canio_message_obj_t *self, bool rtr)
-{
- self->rtr = rtr;
- if (rtr) {
- memset(self->data, 0, self->size);
- }
-}
-
bool common_hal_canio_message_get_extended(const canio_message_obj_t *self)
{
return self->extended;
diff --git a/shared-module/canio/Message.h b/shared-module/canio/Message.h
index b99c5c48e..1ca0d42e2 100644
--- a/shared-module/canio/Message.h
+++ b/shared-module/canio/Message.h
@@ -33,6 +33,5 @@ typedef struct {
int id;
uint8_t data[8];
size_t size:4;
- bool rtr:1;
bool extended:1;
} canio_message_obj_t;
diff --git a/shared-module/canio/RemoteTransmissionRequest.c b/shared-module/canio/RemoteTransmissionRequest.c
new file mode 100644
index 000000000..9b4d5632f
--- /dev/null
+++ b/shared-module/canio/RemoteTransmissionRequest.c
@@ -0,0 +1,67 @@
+/*
+ * 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 "shared-module/canio/RemoteTransmissionRequest.h"
+#include "shared-bindings/canio/RemoteTransmissionRequest.h"
+
+#include <string.h>
+
+void common_hal_canio_remote_transmission_request_construct(canio_remote_transmission_request_obj_t *self, int id, size_t size, bool extended)
+{
+ self->id = id;
+ self->size = size;
+ self->extended = extended;
+}
+
+int common_hal_canio_remote_transmission_request_get_id(const canio_remote_transmission_request_obj_t *self)
+{
+ return self->id;
+}
+
+void common_hal_canio_remote_transmission_request_set_id(canio_remote_transmission_request_obj_t *self, int id)
+{
+ self->id = id;
+}
+
+size_t common_hal_canio_remote_transmission_request_get_length(const canio_remote_transmission_request_obj_t *self)
+{
+ return self->size;
+}
+
+void common_hal_canio_remote_transmission_request_set_length(canio_remote_transmission_request_obj_t *self, size_t size)
+{
+ self->size = size;
+}
+
+bool common_hal_canio_remote_transmission_request_get_extended(const canio_remote_transmission_request_obj_t *self)
+{
+ return self->extended;
+}
+
+void common_hal_canio_remote_transmission_request_set_extended(canio_remote_transmission_request_obj_t *self, bool extended)
+{
+ self->extended = extended;
+}
diff --git a/shared-module/canio/RemoteTransmissionRequest.h b/shared-module/canio/RemoteTransmissionRequest.h
new file mode 100644
index 000000000..2f09b19c6
--- /dev/null
+++ b/shared-module/canio/RemoteTransmissionRequest.h
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "py/obj.h"
+
+#include "shared-bindings/canio/Message.h"
+
+typedef canio_message_obj_t canio_remote_transmission_request_obj_t;
diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c
index 021159c0d..bb7e40f41 100644
--- a/shared-module/displayio/Display.c
+++ b/shared-module/displayio/Display.c
@@ -48,7 +48,9 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
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,
- bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high) {
+ bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
+ bool backlight_on_high, bool SH1107_addressing) {
+
// Turn off auto-refresh as we init.
self->auto_refresh = false;
uint16_t ram_width = 0x100;
@@ -68,6 +70,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
self->first_manual_refresh = !auto_refresh;
self->data_as_commands = data_as_commands;
self->backlight_on_high = backlight_on_high;
+ self->SH1107_addressing = SH1107_addressing;
self->native_frames_per_second = native_frames_per_second;
self->native_ms_per_frame = 1000 / native_frames_per_second;
@@ -240,11 +243,17 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
if (!displayio_display_core_clip_area(&self->core, area, &clipped)) {
return true;
}
- uint16_t subrectangles = 1;
uint16_t rows_per_buffer = displayio_area_height(&clipped);
uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / self->core.colorspace.depth;
uint16_t pixels_per_buffer = displayio_area_size(&clipped);
- if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) {
+
+ uint16_t subrectangles = 1;
+ // for SH1107 and other boundary constrained controllers
+ // write one single row at a time
+ if (self->SH1107_addressing) {
+ subrectangles = rows_per_buffer; // vertical (column mode) write each separately (height times)
+ rows_per_buffer = 1;
+ } else if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) {
rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped);
if (rows_per_buffer == 0) {
rows_per_buffer = 1;
@@ -286,7 +295,9 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
}
remaining_rows -= rows_per_buffer;
- displayio_display_core_set_region_to_update(&self->core, self->set_column_command, self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false, &subrectangle);
+ displayio_display_core_set_region_to_update(&self->core, self->set_column_command,
+ self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
+ &subrectangle, self->SH1107_addressing);
uint16_t subrectangle_size_bytes;
if (self->core.colorspace.depth >= 8) {
@@ -317,11 +328,10 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
}
STATIC void _refresh_display(displayio_display_obj_t* self) {
- if (!displayio_display_core_bus_free(&self->core)) {
- // Can't acquire display bus; skip updating this display. Try next display.
+ if (!displayio_display_core_start_refresh(&self->core)) {
+ // A refresh on this bus is already in progress. Try next display.
return;
}
- displayio_display_core_start_refresh(&self->core);
const displayio_area_t* current_area = _get_refresh_areas(self);
while (current_area != NULL) {
_refresh_area(self, current_area);
diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h
index bdb861aa0..cc9cd54c4 100644
--- a/shared-module/displayio/Display.h
+++ b/shared-module/displayio/Display.h
@@ -60,6 +60,8 @@ typedef struct {
bool auto_brightness;
bool updating_backlight;
bool backlight_on_high;
+ // new quirk for sh1107
+ bool SH1107_addressing;
} displayio_display_obj_t;
void displayio_display_background(displayio_display_obj_t* self);
diff --git a/shared-module/displayio/EPaperDisplay.c b/shared-module/displayio/EPaperDisplay.c
index 6d9e915b4..5b055e62e 100644
--- a/shared-module/displayio/EPaperDisplay.c
+++ b/shared-module/displayio/EPaperDisplay.c
@@ -238,8 +238,11 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
for (uint8_t pass = 0; pass < passes; pass++) {
uint16_t remaining_rows = displayio_area_height(&clipped);
+ // added false parameter at end for SH1107_addressing quirk
if (self->set_row_window_command != NO_COMMAND) {
- displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command, self->set_row_window_command, self->set_current_column_command, self->set_current_row_command, false, self->chip_select, &clipped);
+ displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command,
+ self->set_row_window_command, self->set_current_column_command, self->set_current_row_command,
+ false, self->chip_select, &clipped, false);
}
uint8_t write_command = self->write_black_ram_command;
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index 101dac4b3..a9bb3b21b 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -40,8 +40,6 @@ STATIC bool any_display_uses_this_framebuffer(mp_obj_base_t *obj) {
}
#endif
-// Check for recursive calls to displayio_background.
-bool displayio_background_in_progress = false;
void displayio_background(void) {
if (mp_hal_is_interrupted()) {
@@ -52,12 +50,6 @@ void displayio_background(void) {
return;
}
- if (displayio_background_in_progress) {
- // Don't allow recursive calls to this routine.
- return;
- }
-
- displayio_background_in_progress = true;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].display.base.type == NULL || displays[i].display.base.type == &mp_type_NoneType) {
@@ -75,8 +67,6 @@ void displayio_background(void) {
}
}
- // All done.
- displayio_background_in_progress = false;
}
void common_hal_displayio_release_displays(void) {
diff --git a/shared-module/displayio/display_core.c b/shared-module/displayio/display_core.c
index 43f2d1937..6975e0af1 100644
--- a/shared-module/displayio/display_core.c
+++ b/shared-module/displayio/display_core.c
@@ -208,7 +208,10 @@ void displayio_display_core_end_transaction(displayio_display_core_t* self) {
self->end_transaction(self->bus);
}
-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) {
+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) {
uint16_t x1 = area->x1;
uint16_t x2 = area->x2;
uint16_t y1 = area->y1;
@@ -253,8 +256,17 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
data[data_length++] = x2 >> 8;
data[data_length++] = x2 & 0xff;
}
+ // Quirk for SH1107 "SH1107_addressing"
+ // Note... column is y! page is x!
+ // Page address command = 0xB0
+ if (SH1107_addressing) {
+ // set the page to our x value
+ data[0] = 0xB0 | (x1 & 0x0F);
+ data_length = 1;
+ }
self->send(self->bus, data_type, chip_select, data, data_length);
displayio_display_core_end_transaction(self);
+
if (set_current_column_command != NO_COMMAND) {
uint8_t command = set_current_column_command;
displayio_display_core_begin_transaction(self);
@@ -283,7 +295,16 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
data[data_length++] = y2 >> 8;
data[data_length++] = y2 & 0xff;
}
+ // Quirk for SH1107 "SH1107_addressing"
+ // Note... column is y! page is x!
+ // Column lower command = 0x00, Column upper command = 0x10
+ if (SH1107_addressing) {
+ data[0] = y1 & 0x0F; // 0x00 to 0x0F
+ data[1] = (y1 >> 4 & 0x0F) | 0x10; // 0x10 to 0x17
+ data_length = 2;
+ }
self->send(self->bus, data_type, chip_select, data, data_length);
+
displayio_display_core_end_transaction(self);
if (set_current_row_command != NO_COMMAND) {
@@ -295,8 +316,17 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
}
}
-void displayio_display_core_start_refresh(displayio_display_core_t* self) {
+bool displayio_display_core_start_refresh(displayio_display_core_t* self) {
+ 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;
self->last_refresh = supervisor_ticks_ms64();
+ return true;
}
void displayio_display_core_finish_refresh(displayio_display_core_t* self) {
@@ -305,6 +335,7 @@ void displayio_display_core_finish_refresh(displayio_display_core_t* self) {
displayio_group_finish_refresh(self->current_group);
}
self->full_refresh = false;
+ self->refresh_in_progress = false;
self->last_refresh = supervisor_ticks_ms64();
}
diff --git a/shared-module/displayio/display_core.h b/shared-module/displayio/display_core.h
index e4fd62d4a..fe6cb6f3f 100644
--- a/shared-module/displayio/display_core.h
+++ b/shared-module/displayio/display_core.h
@@ -54,6 +54,7 @@ typedef struct {
int16_t colstart;
int16_t rowstart;
bool full_refresh; // New group means we need to refresh the whole display.
+ bool refresh_in_progress;
} displayio_display_core_t;
void displayio_display_core_construct(displayio_display_core_t* self,
@@ -74,11 +75,14 @@ bool displayio_display_core_bus_free(displayio_display_core_t *self);
bool displayio_display_core_begin_transaction(displayio_display_core_t* self);
void displayio_display_core_end_transaction(displayio_display_core_t* self);
-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);
+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);
void release_display_core(displayio_display_core_t* self);
-void displayio_display_core_start_refresh(displayio_display_core_t* self);
+bool displayio_display_core_start_refresh(displayio_display_core_t* self);
void displayio_display_core_finish_refresh(displayio_display_core_t* self);
void displayio_display_core_collect_ptrs(displayio_display_core_t* self);
diff --git a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
index 71e00d7f0..c23446828 100644
--- a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
+++ b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
@@ -90,10 +90,6 @@ bool common_hal_sharpdisplay_framebuffer_get_pixels_in_byte_share_row(sharpdispl
}
void common_hal_sharpdisplay_framebuffer_reset(sharpdisplay_framebuffer_obj_t *self) {
- if (!allocation_from_ptr(self->bufinfo.buf)) {
- self->bufinfo.buf = NULL;
- }
-
if (self->bus != &self->inline_bus
#if BOARD_SPI
&& self->bus != common_hal_board_get_spi()
@@ -105,7 +101,9 @@ void common_hal_sharpdisplay_framebuffer_reset(sharpdisplay_framebuffer_obj_t *s
}
void common_hal_sharpdisplay_framebuffer_reconstruct(sharpdisplay_framebuffer_obj_t *self) {
-
+ if (!allocation_from_ptr(self->bufinfo.buf)) {
+ self->bufinfo.buf = NULL;
+ }
}
void common_hal_sharpdisplay_framebuffer_get_bufinfo(sharpdisplay_framebuffer_obj_t *self, mp_buffer_info_t *bufinfo) {