@@ -54,6 +54,7 @@ typedef struct _mp_framebuf_p_t {
5454// constants for formats
5555#define FRAMEBUF_MVLSB (0)
5656#define FRAMEBUF_RGB565 (1)
57+ #define FRAMEBUF_GS2_HMSB (5)
5758#define FRAMEBUF_GS4_HMSB (2)
5859#define FRAMEBUF_MHLSB (3)
5960#define FRAMEBUF_MHMSB (4)
@@ -130,6 +131,30 @@ STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, i
130131 }
131132}
132133
134+ // Functions for GS2_HMSB format
135+
136+ STATIC void gs2_hmsb_setpixel (const mp_obj_framebuf_t * fb , int x , int y , uint32_t col ) {
137+ uint8_t * pixel = & ((uint8_t * )fb -> buf )[(x + y * fb -> stride ) >> 2 ];
138+ uint8_t shift = (x & 0x3 ) << 1 ;
139+ uint8_t mask = 0x3 << shift ;
140+ uint8_t color = (col & 0x3 ) << shift ;
141+ * pixel = color | (* pixel & (~mask ));
142+ }
143+
144+ STATIC uint32_t gs2_hmsb_getpixel (const mp_obj_framebuf_t * fb , int x , int y ) {
145+ uint8_t pixel = ((uint8_t * )fb -> buf )[(x + y * fb -> stride ) >> 2 ];
146+ uint8_t shift = (x & 0x3 ) << 1 ;
147+ return (pixel >> shift ) & 0x3 ;
148+ }
149+
150+ STATIC void gs2_hmsb_fill_rect (const mp_obj_framebuf_t * fb , int x , int y , int w , int h , uint32_t col ) {
151+ for (int xx = x ; xx < x + w ; xx ++ ) {
152+ for (int yy = y ; yy < y + h ; yy ++ ) {
153+ gs2_hmsb_setpixel (fb , xx , yy , col );
154+ }
155+ }
156+ }
157+
133158// Functions for GS4_HMSB format
134159
135160STATIC void gs4_hmsb_setpixel (const mp_obj_framebuf_t * fb , int x , int y , uint32_t col ) {
@@ -184,6 +209,7 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
184209STATIC mp_framebuf_p_t formats [] = {
185210 [FRAMEBUF_MVLSB ] = {mvlsb_setpixel , mvlsb_getpixel , mvlsb_fill_rect },
186211 [FRAMEBUF_RGB565 ] = {rgb565_setpixel , rgb565_getpixel , rgb565_fill_rect },
212+ [FRAMEBUF_GS2_HMSB ] = {gs2_hmsb_setpixel , gs2_hmsb_getpixel , gs2_hmsb_fill_rect },
187213 [FRAMEBUF_GS4_HMSB ] = {gs4_hmsb_setpixel , gs4_hmsb_getpixel , gs4_hmsb_fill_rect },
188214 [FRAMEBUF_MHLSB ] = {mono_horiz_setpixel , mono_horiz_getpixel , mono_horiz_fill_rect },
189215 [FRAMEBUF_MHMSB ] = {mono_horiz_setpixel , mono_horiz_getpixel , mono_horiz_fill_rect },
@@ -240,6 +266,9 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
240266 case FRAMEBUF_MHMSB :
241267 o -> stride = (o -> stride + 7 ) & ~7 ;
242268 break ;
269+ case FRAMEBUF_GS2_HMSB :
270+ o -> stride = (o -> stride + 3 ) & ~3 ;
271+ break ;
243272 case FRAMEBUF_GS4_HMSB :
244273 o -> stride = (o -> stride + 1 ) & ~1 ;
245274 break ;
@@ -579,6 +608,7 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = {
579608 { MP_ROM_QSTR (MP_QSTR_MVLSB ), MP_ROM_INT (FRAMEBUF_MVLSB ) },
580609 { MP_ROM_QSTR (MP_QSTR_MONO_VLSB ), MP_ROM_INT (FRAMEBUF_MVLSB ) },
581610 { MP_ROM_QSTR (MP_QSTR_RGB565 ), MP_ROM_INT (FRAMEBUF_RGB565 ) },
611+ { MP_ROM_QSTR (MP_QSTR_GS2_HMSB ), MP_ROM_INT (FRAMEBUF_GS2_HMSB ) },
582612 { MP_ROM_QSTR (MP_QSTR_GS4_HMSB ), MP_ROM_INT (FRAMEBUF_GS4_HMSB ) },
583613 { MP_ROM_QSTR (MP_QSTR_MONO_HLSB ), MP_ROM_INT (FRAMEBUF_MHLSB ) },
584614 { MP_ROM_QSTR (MP_QSTR_MONO_HMSB ), MP_ROM_INT (FRAMEBUF_MHMSB ) },
0 commit comments