25
25
#include < zephyr/device.h>
26
26
#include < zephyr/drivers/display.h>
27
27
28
- Display::Display () : gdev(NULL ){
29
28
29
+ #ifdef HAS_ARDUINOGRAPHICS
30
+ Display::Display (int width, int height) : ArduinoGraphics(width, height), gdev(NULL )
31
+ #else
32
+ Display::Display (int width, int height) : gdev(NULL )
33
+ #endif
34
+ {
35
+ _height = height;
36
+ _width = width;
37
+ _rotated = (width >= height) ? true : false ;
38
+ printk (" height: %d, width: %d, rotated: %d\n " , _height, _width, _rotated);
30
39
}
31
40
32
- bool Display::begin (DisplayPixelFormat pixformat, int rotation ) {
41
+ bool Display::begin (DisplayPixelFormat pixformat) {
33
42
34
43
int ret = 0 ;
35
44
@@ -38,7 +47,7 @@ bool Display::begin(DisplayPixelFormat pixformat, int rotation) {
38
47
#endif
39
48
40
49
if (!this ->gdev || !device_is_ready (this ->gdev )) {
41
- Serial. println (" \t <err> Zephy Display Not Ready!..." );
50
+ printk (" \t <err> Zephy Display Not Ready!..." );
42
51
return false ;
43
52
}
44
53
@@ -77,7 +86,7 @@ bool Display::begin(DisplayPixelFormat pixformat, int rotation) {
77
86
return false ;
78
87
}
79
88
80
-
89
+ /*
81
90
display_orientation orientation;
82
91
switch(rotation){
83
92
case 0:
@@ -97,14 +106,15 @@ bool Display::begin(DisplayPixelFormat pixformat, int rotation) {
97
106
break;
98
107
}
99
108
//Rotation not supported
100
- // Serial.print("Orientation: "); Serial.println(orientation);
109
+ Serial.print("Orientation: "); Serial.println(orientation);
101
110
ret = display_set_orientation(this->gdev, orientation);
102
111
Serial.println(ret);
103
112
if(ret) {
104
113
Serial.println("\t<err> Failed to set display rotation");
105
114
//return false;
106
115
}
107
-
116
+ */
117
+
108
118
display_get_capabilities (this ->gdev , &capabilities);
109
119
110
120
printk (" - Capabilities:\n " );
@@ -113,9 +123,39 @@ bool Display::begin(DisplayPixelFormat pixformat, int rotation) {
113
123
capabilities.x_resolution , capabilities.y_resolution ,
114
124
capabilities.supported_pixel_formats , capabilities.current_pixel_format ,
115
125
capabilities.current_orientation );
116
-
126
+ # ifndef HAS_ARDUINOGRAPHICS
117
127
_height = capabilities.y_resolution ;
118
128
_width = capabilities.x_resolution ;
129
+ #endif
130
+
131
+ #ifdef HAS_ARDUINOGRAPHICS
132
+ #ifdef CONFIG_SHARED_MULTI_HEAP
133
+ void * ptrFB = getFrameBuffer ();
134
+ if (ptrFB == nullptr ){
135
+ printk (" Memory not allocated successfully." );
136
+ while (1 ){}
137
+ }
138
+ // Cast the void pointer to an int pointer to use it
139
+ buffer = static_cast <uint16_t *>(ptrFB);
140
+ // buffer = (uint16_t*)shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, (this->width() * this-> height() * sizeof(uint16_t)));
141
+ #else
142
+ SDRAM.begin ();
143
+ buffer = (uint16_t *)SDRAM.malloc (this ->width () * this -> height () * sizeof (uint16_t ));
144
+ #endif
145
+ sizeof_framebuffer = width () * height () * sizeof (uint16_t );
146
+ setFrameDesc (width (), height (), width (), sizeof_framebuffer);
147
+ Serial.print (" Buffer: 0x" ); Serial.println ((uint32_t )buffer, HEX);
148
+
149
+ // turn on the display backlight
150
+ pinMode (74 , OUTPUT);
151
+ digitalWrite (74 , HIGH);
152
+
153
+ if (!ArduinoGraphics::begin ()) {
154
+ return 1 ; /* Unknown err */
155
+ }
156
+
157
+ textFont (Font_5x7);
158
+ #endif // arduinoGraphics
119
159
120
160
return true ;
121
161
}
@@ -170,4 +210,78 @@ void* Display::getFrameBuffer() {
170
210
return fb;
171
211
}
172
212
213
+
214
+ #ifdef HAS_ARDUINOGRAPHICS
215
+ void Display::beginDraw () {
216
+ ArduinoGraphics::beginDraw ();
217
+ startFrameBuffering ();
218
+ lcdClear (0 );
219
+ }
220
+
221
+ void Display::endDraw () {
222
+ ArduinoGraphics::endDraw ();
223
+
224
+ endFrameBuffering ();
225
+ }
226
+
227
+ void Display::clear (){
228
+ uint32_t bg = ArduinoGraphics::background ();
229
+ uint32_t x_size, y_size;
230
+
231
+ if (_rotated) {
232
+ x_size = (height () <= getDisplayXSize ())? height () : getDisplayXSize ();
233
+ y_size = (width () <= getDisplayYSize ())? width () : getDisplayYSize ();
234
+ } else {
235
+ x_size = (width () <= getDisplayXSize ())? width () : getDisplayXSize ();
236
+ y_size = (height () <= getDisplayYSize ())? height () : getDisplayYSize ();
237
+ }
238
+
239
+ // lcdFillArea((void *)(dsi_getCurrentFrameBuffer()), x_size, y_size, bg);
240
+ lcdClear (bg);
241
+ }
242
+
243
+ void Display::set (int x, int y, uint8_t r, uint8_t g, uint8_t b) {
244
+ uint32_t x_rot, y_rot;
245
+
246
+ if ((x < 0 ) || (y < 0 ) || (x >= _width) || (y >= _height))
247
+ return ;
248
+
249
+ if (_rotated) {
250
+ x_rot = ((height ()-1 ) - y);
251
+ y_rot = x;
252
+
253
+ // if (x_rot >= height() || y_rot >= width())
254
+ // return;
255
+ } else {
256
+ x_rot = x;
257
+ y_rot = y;
258
+
259
+ // if (x_rot >= width() || y_rot >= height())
260
+ // return;
261
+ }
262
+
263
+ if (x_rot >= getDisplayXSize () || y_rot >= getDisplayYSize ())
264
+ return ;
265
+ // printk("%u, %u, %u, %u, %u\n", x, y, x_rot, y_rot, x_rot + (width() * y_rot));
266
+
267
+ uint16_t color = ((r & 0xF8 ) << 8 ) | ((g & 0xFC ) << 3 ) | (b >> 3 );
268
+ // uint32_t color = (uint32_t)((uint32_t)(r << 16) | (uint32_t)(g << 8) | (uint32_t)(b << 0));
269
+ buffer[(x_rot + (getDisplayXSize () * y_rot)) ] = color;
270
+
271
+ }
272
+
273
+ void Display::lcdClear (uint16_t Color) {
274
+ /* Clear the LCD */
275
+ uint8_t hi = Color >> 8 , lo = Color & 0xFF ;
276
+ if (hi == lo) {
277
+ memset (buffer, lo, width () * height () * 2 );
278
+ } else {
279
+ uint32_t i, pixels = width () * height ();
280
+ for (i = 0 ; i < pixels; i++)
281
+ buffer[i] = Color;
282
+ }
283
+
284
+ }
285
+ #endif // HAS_ARDUINOGRAPHICS
286
+
173
287
#endif // __ZEPHYR__
0 commit comments