3535
3636displayio_fourwire_obj_t board_display_obj ;
3737
38+ typedef struct {
39+ const uint32_t * config_data ;
40+ void * handoverHID ;
41+ void * handoverMSC ;
42+ const char * info_uf2 ;
43+ } UF2_BInfo ;
44+
45+ #define APP_START_ADDRESS 0x00004000
46+ #define UF2_BINFO ((UF2_BInfo *)(APP_START_ADDRESS - sizeof(UF2_BInfo)))
47+
48+ #define CFG_DISPLAY_CFG0 39
49+ #define CFG_MAGIC0 0x1e9e10f1
50+
3851#define DELAY 0x80
3952
53+ uint32_t lookupCfg (uint32_t key , uint32_t defl ) {
54+ const uint32_t * ptr = UF2_BINFO -> config_data ;
55+ if (!ptr || (((uint32_t )ptr ) & 3 ) || * ptr != CFG_MAGIC0 ) {
56+ // no config data!
57+ } else {
58+ ptr += 4 ;
59+ while (* ptr ) {
60+ if (* ptr == key )
61+ return ptr [1 ];
62+ ptr += 2 ;
63+ }
64+ }
65+ return defl ;
66+ }
67+
4068uint8_t display_init_sequence [] = {
4169 0x01 , 0 | DELAY , 150 , // SWRESET
4270 0x11 , 0 | DELAY , 255 , // SLPOUT
@@ -63,8 +91,6 @@ uint8_t display_init_sequence[] = {
6391 0x2E , 0x2C , 0x29 , 0x2D ,
6492 0x2E , 0x2E , 0x37 , 0x3F ,
6593 0x00 , 0x00 , 0x02 , 0x10 ,
66- 0x2a , 3 , 0x02 , 0x00 , 0x81 , // _CASET XSTART = 2, XEND = 129
67- 0x2b , 3 , 0x02 , 0x00 , 0x81 , // _RASET XSTART = 2, XEND = 129
6894 0x13 , 0 | DELAY , 10 , // _NORON
6995 0x29 , 0 | DELAY , 100 , // _DISPON
7096};
@@ -83,14 +109,17 @@ void board_init(void) {
83109 & pin_PA17 , // TFT_RST Reset
84110 60000000 );
85111
112+ uint32_t cfg0 = lookupCfg (CFG_DISPLAY_CFG0 , 0x000000 );
113+ uint32_t offX = (cfg0 >> 8 ) & 0xff ;
114+ uint32_t offY = (cfg0 >> 16 ) & 0xff ;
86115 displayio_display_obj_t * display = & displays [0 ].display ;
87116 display -> base .type = & displayio_display_type ;
88117 common_hal_displayio_display_construct (display ,
89118 bus ,
90119 160 , // Width (after rotation)
91120 128 , // Height (after rotation)
92- 0 , // column start
93- 0 , // row start
121+ offX , // column start
122+ offY , // row start
94123 0 , // rotation
95124 16 , // Color depth
96125 false, // grayscale
0 commit comments