summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadomir Dopieralski <openstack@sheep.art.pl>2020-01-06 14:06:42 +0100
committerRadomir Dopieralski <openstack@sheep.art.pl>2020-01-06 14:24:30 +0100
commit59ded1131f5d247ffb64b86d99f3297e75fe6fe5 (patch)
tree989cfc6190c94ab5af97970f770ead452f2d435b
parent776c9b011c26f9833f392fcf8270d20a4bbc8031 (diff)
Take display offsets for PewPew M4 from the bootloader config
The PewPew M4 devices come with different displays, which require different offsets. Since the information about offsets is saved in the bootloader, we can take it from there.
-rw-r--r--ports/atmel-samd/boards/pewpew_m4/board.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c
index b684f5601..5f5a01e48 100644
--- a/ports/atmel-samd/boards/pewpew_m4/board.c
+++ b/ports/atmel-samd/boards/pewpew_m4/board.c
@@ -35,8 +35,36 @@
displayio_fourwire_obj_t board_display_obj;
+typedef struct {
+ const uint32_t *config_data;
+ void *handoverHID;
+ void *handoverMSC;
+ const char *info_uf2;
+} UF2_BInfo;
+
+#define APP_START_ADDRESS 0x00004000
+#define UF2_BINFO ((UF2_BInfo *)(APP_START_ADDRESS - sizeof(UF2_BInfo)))
+
+#define CFG_DISPLAY_CFG0 39
+#define CFG_MAGIC0 0x1e9e10f1
+
#define DELAY 0x80
+uint32_t lookupCfg(uint32_t key, uint32_t defl) {
+ const uint32_t *ptr = UF2_BINFO->config_data;
+ if (!ptr || (((uint32_t)ptr) & 3) || *ptr != CFG_MAGIC0) {
+ // no config data!
+ } else {
+ ptr += 4;
+ while (*ptr) {
+ if (*ptr == key)
+ return ptr[1];
+ ptr += 2;
+ }
+ }
+ return defl;
+}
+
uint8_t display_init_sequence[] = {
0x01, 0 | DELAY, 150, // SWRESET
0x11, 0 | DELAY, 255, // SLPOUT
@@ -63,8 +91,6 @@ uint8_t display_init_sequence[] = {
0x2E, 0x2C, 0x29, 0x2D,
0x2E, 0x2E, 0x37, 0x3F,
0x00, 0x00, 0x02, 0x10,
- 0x2a, 3, 0x02, 0x00, 0x81, // _CASET XSTART = 2, XEND = 129
- 0x2b, 3, 0x02, 0x00, 0x81, // _RASET XSTART = 2, XEND = 129
0x13, 0 | DELAY, 10, // _NORON
0x29, 0 | DELAY, 100, // _DISPON
};
@@ -83,14 +109,17 @@ void board_init(void) {
&pin_PA17, // TFT_RST Reset
60000000);
+ uint32_t cfg0 = lookupCfg(CFG_DISPLAY_CFG0, 0x000000);
+ uint32_t offX = (cfg0 >> 8) & 0xff;
+ uint32_t offY = (cfg0 >> 16) & 0xff;
displayio_display_obj_t* display = &displays[0].display;
display->base.type = &displayio_display_type;
common_hal_displayio_display_construct(display,
bus,
160, // Width (after rotation)
128, // Height (after rotation)
- 0, // column start
- 0, // row start
+ offX, // column start
+ offY, // row start
0, // rotation
16, // Color depth
false, // grayscale