Skip to content

Commit 4f804e4

Browse files
Remove hard dependency on ArduinoGraphics
1 parent 4b25a81 commit 4f804e4

File tree

7 files changed

+66
-19
lines changed

7 files changed

+66
-19
lines changed

libraries/Arduino_H7_Video/examples/ArduinoLogo/ArduinoLogo.ino

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "Arduino_H7_Video.h"
9+
#include "ArduinoGraphics.h"
910

1011
#include "img_arduinologo.h"
1112
// Alternatively, any raw RGB565 image can be included on demand using this macro

libraries/Arduino_H7_Video/examples/ArduinoLogoDrawing/ArduinoLogoDrawing.ino

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "Arduino_H7_Video.h"
9+
#include "ArduinoGraphics.h"
910

1011
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
1112
//Arduino_H7_Video Display(1024, 768, USBCVideo);

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

+29-10
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@ void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color
2727
#endif
2828

2929
/* Functions -----------------------------------------------------------------*/
30-
Arduino_H7_Video::Arduino_H7_Video(int width, int heigth, H7DisplayShield &shield) :
31-
ArduinoGraphics(width, heigth) {
30+
Arduino_H7_Video::Arduino_H7_Video(int width, int height, H7DisplayShield &shield)
31+
#ifdef HAS_ARDUINOGRAPHICS
32+
: ArduinoGraphics(width, height)
33+
#endif
34+
{
35+
_height = height;
36+
_width = width;
3237
_shield = &shield;
33-
_edidMode = _shield->getEdidMode(width, heigth);
38+
_edidMode = _shield->getEdidMode(width, height);
3439

3540
switch(_edidMode) {
3641
case EDID_MODE_640x480_60Hz ... EDID_MODE_800x600_59Hz:
3742
case EDID_MODE_1024x768_60Hz ... EDID_MODE_1920x1080_60Hz:
38-
_rotated = (width < heigth) ? true : false;
43+
_rotated = (width < height) ? true : false;
3944
break;
4045
case EDID_MODE_480x800_60Hz:
41-
_rotated = (width >= heigth) ? true : false;
46+
_rotated = (width >= height) ? true : false;
4247
break;
4348
default:
4449
_rotated = false;
@@ -50,14 +55,13 @@ Arduino_H7_Video::~Arduino_H7_Video() {
5055
}
5156

5257
int Arduino_H7_Video::begin() {
58+
#ifdef HAS_ARDUINOGRAPHICS
5359
if (!ArduinoGraphics::begin()) {
54-
return H7V_ERR_UNKNOWN;
60+
return 1; /* Unknown err */
5561
}
5662

5763
textFont(Font_5x7);
58-
59-
/* Configure SDRAM */
60-
SDRAM.begin();
64+
#endif
6165

6266
/* Video controller/bridge init */
6367
_shield->init(_edidMode);
@@ -71,7 +75,7 @@ int Arduino_H7_Video::begin() {
7175
static lv_color_t * buf1;
7276
buf1 = (lv_color_t*)malloc((width() * height() / 10) * sizeof(lv_color_t)); /* Declare a buffer for 1/10 screen size */
7377
if (buf1 == NULL) {
74-
return H7V_ERR_INSUFFMEM;
78+
return 2; /* Insuff memory err */
7579
}
7680
lv_disp_draw_buf_init(&draw_buf, buf1, NULL, width() * height() / 10); /* Initialize the display buffer. */
7781

@@ -93,13 +97,27 @@ int Arduino_H7_Video::begin() {
9397
lv_disp_drv_register(&disp_drv); /* Finally register the driver */
9498
#endif
9599

100+
/* Configure SDRAM */
101+
SDRAM.begin(dsi_getFramebufferEnd());
102+
96103
return 0;
97104
}
98105

106+
int Arduino_H7_Video::width() {
107+
return _width;
108+
}
109+
110+
int Arduino_H7_Video::height() {
111+
return _height;
112+
}
113+
99114
void Arduino_H7_Video::end() {
115+
#ifdef HAS_ARDUINOGRAPHICS
100116
ArduinoGraphics::end();
117+
#endif
101118
}
102119

120+
#ifdef HAS_ARDUINOGRAPHICS
103121
void Arduino_H7_Video::beginDraw() {
104122
ArduinoGraphics::beginDraw();
105123

@@ -150,6 +168,7 @@ void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
150168
uint32_t color = (uint32_t)((uint32_t)(r << 16) | (uint32_t)(g << 8) | (uint32_t)(b << 0));
151169
dsi_lcdFillArea((void *)(dsi_getCurrentFrameBuffer() + ((x_rot + (dsi_getDisplayXSize() * y_rot)) * sizeof(uint16_t))), 1, 1, color);
152170
}
171+
#endif
153172

154173
#if __has_include("lvgl.h")
155174
void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {

libraries/Arduino_H7_Video/src/Arduino_H7_Video.h

+19-7
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,50 @@
1212
#define _ARDUINO_H7_VIDEO_H
1313

1414
/* Includes ------------------------------------------------------------------*/
15-
#include <ArduinoGraphics.h>
1615
#include "H7DisplayShield.h"
16+
#if __has_include ("HasIncludeArduinoGraphics.h")
17+
#include "ArduinoGraphics.h"
18+
#define HAS_ARDUINOGRAPHICS
19+
#endif
1720

1821
/* Exported defines ----------------------------------------------------------*/
19-
#define H7V_ERR_UNKNOWN 1
20-
#define H7V_ERR_INSUFFMEM 2
2122

2223
/* Exported enumeration ------------------------------------------------------*/
2324

2425
/* Class ----------------------------------------------------------------------*/
25-
class Arduino_H7_Video : public ArduinoGraphics {
26+
class Arduino_H7_Video
27+
#ifdef HAS_ARDUINOGRAPHICS
28+
: public ArduinoGraphics
29+
#endif
30+
{
2631
public:
2732
#if defined(ARDUINO_PORTENTA_H7_M7)
28-
Arduino_H7_Video(int width = 1024, int heigth = 768, H7DisplayShield &shield = USBCVideo);
33+
Arduino_H7_Video(int width = 1024, int height = 768, H7DisplayShield &shield = USBCVideo);
2934
#elif defined(ARDUINO_GIGA)
30-
Arduino_H7_Video(int width = 800, int heigth = 480, H7DisplayShield &shield = GigaDisplayShield);
35+
Arduino_H7_Video(int width = 800, int height = 480, H7DisplayShield &shield = GigaDisplayShield);
3136
#endif
3237
~Arduino_H7_Video();
3338

3439
int begin();
3540
void end();
3641

42+
int width();
43+
int height();
44+
45+
#ifdef HAS_ARDUINOGRAPHICS
3746
void clear();
38-
47+
3948
virtual void beginDraw();
4049
virtual void endDraw();
4150

4251
virtual void set(int x, int y, uint8_t r, uint8_t g, uint8_t b);
52+
#endif
4353
private:
4454
H7DisplayShield* _shield;
4555
bool _rotated;
4656
int _edidMode;
57+
uint32_t _width;
58+
uint32_t _height;
4759
};
4860

4961
#endif /* _ARDUINO_H7_VIDEO_H */

libraries/Arduino_H7_Video/src/H7DisplayShield.h

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#pragma once
2+
#include "Arduino.h"
3+
14
class H7DisplayShield {
25
public:
36
virtual int init(int edidmode) = 0;

libraries/Arduino_H7_Video/src/dsi.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ int dsi_init(uint8_t bus, struct edid *edid, struct display_timing *dt) {
244244
HAL_DSI_Refresh(&dsi);
245245

246246
dsi_layerInit(0, FB_ADDRESS_0);
247-
dsi_layerInit(1, FB_ADDRESS_1);
247+
dsi_layerInit(1, FB_ADDRESS_0 + (lcd_x_size * lcd_y_size * BYTES_PER_PIXEL));
248248

249249
HAL_DSI_PatternGeneratorStop(&dsi);
250250

@@ -321,6 +321,16 @@ uint32_t dsi_getFramebufferEnd(void) {
321321
return (FB_BASE_ADDRESS + 2 * (lcd_x_size * lcd_y_size * BYTES_PER_PIXEL));
322322
}
323323

324+
uint32_t dsi_getNextFrameBuffer() {
325+
int fb = pend_buffer++ % 2;
326+
327+
__HAL_LTDC_LAYER_ENABLE(&(ltdc), fb);
328+
__HAL_LTDC_LAYER_DISABLE(&(ltdc), !fb);
329+
__HAL_LTDC_VERTICAL_BLANKING_RELOAD_CONFIG(&(ltdc));
330+
331+
return fb ? ltdc.LayerCfg[0].FBStartAdress : ltdc.LayerCfg[1].FBStartAdress;
332+
}
333+
324334
void dsi_drawCurrentFrameBuffer(void) {
325335
int fb = pend_buffer++ % 2;
326336

@@ -402,7 +412,7 @@ extern "C" void LTDC_IRQHandler(void) {
402412
}
403413

404414
/* Reload LTDC event callback */
405-
void HAL_LTDC_ReloadEventCallback(LTDC_HandleTypeDef *hltdc) {
415+
extern "C" void HAL_LTDC_ReloadEventCallback(LTDC_HandleTypeDef *hltdc) {
406416
reloadLTDC_status = 1;
407417
}
408418

libraries/Arduino_H7_Video/src/dsi.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void dsi_lcdDrawImage(void *pSrc, void *pDst, uint32_t xSize, uint32_t ySize, u
3737
void dsi_lcdFillArea(void *pDst, uint32_t xSize, uint32_t ySize, uint32_t ColorMode);
3838
void dsi_configueCLUT(uint32_t* clut);
3939
void dsi_drawCurrentFrameBuffer(void);
40+
uint32_t dsi_getNextFrameBuffer(void);
4041
uint32_t dsi_getCurrentFrameBuffer(void);
4142
uint32_t dsi_getActiveFrameBuffer(void);
4243
uint32_t dsi_getFramebufferEnd(void);

0 commit comments

Comments
 (0)