Skip to content

Commit f64f392

Browse files
leonardocavagnisfacchinm
authored andcommitted
Adding singleton classes to manage anx and st7701 controller
1 parent 58cac74 commit f64f392

File tree

7 files changed

+94
-72
lines changed

7 files changed

+94
-72
lines changed

libraries/Arduino_H7_Video/examples/ArduinoLogo/ArduinoLogo.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
ArduinoLogo
33
4-
created DD MMM YYYY
4+
created 17 Apr 2023
55
by Leonardo Cavagnis
66
*/
77

@@ -16,8 +16,8 @@
1616
INCBIN(test, "/home/user/Downloads/test.bin");
1717
*/
1818

19-
Arduino_H7_Video Display(800, 480, GIGA_DISPLAY_SHIELD);
20-
//Arduino_H7_Video Display(720, 480);
19+
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
20+
//Arduino_H7_Video Display(1024, 768, USBCVideo);
2121

2222
Image img_arduinologo(ENCODING_RGB16, (uint8_t *) texture_raw, 300, 300);
2323

libraries/Arduino_H7_Video/examples/ArduinoLogoDrawing/ArduinoLogoDrawing.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
ArduinoLogoDrawing
33
4-
created DD MMM YYYY
4+
created 17 Apr 2023
55
by Leonardo Cavagnis
66
*/
77

88
#include "Arduino_H7_Video.h"
99

10-
Arduino_H7_Video Display(800, 480, GIGA_DISPLAY_SHIELD);
11-
//Arduino_H7_Video Display(720, 480);
10+
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
11+
//Arduino_H7_Video Display(1024, 768, USBCVideo);
1212

1313
void setup() {
1414
Display.begin();

libraries/Arduino_H7_Video/examples/LVGLDemo/LVGLDemo.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
LVGLDemo
44
5-
created DD MMM YYYY
5+
created 17 Apr 2023
66
by Leonardo Cavagnis
77
*/
88

@@ -11,10 +11,8 @@
1111
#include "lvgl.h"
1212
#include "giga_touch.h"
1313

14-
Arduino_H7_Video Display(800, 480, GIGA_DISPLAY_SHIELD);
15-
//Arduino_H7_Video Display(720, 480);
16-
17-
//@TODO: Complete demo with 4 main features
14+
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
15+
//Arduino_H7_Video Display(1024, 768, USBCVideo);
1816

1917
void my_touchpad_read(lv_indev_drv_t * indev, lv_indev_data_t * data) {
2018
data->state = (touchpad_pressed) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
#include "Arduino_H7_Video.h"
1313

1414
#include "dsi.h"
15-
#include "st7701.h"
1615
#include "SDRAM.h"
1716
extern "C" {
1817
#include "video_modes.h"
1918
}
20-
#include "anx7625.h"
2119

2220
#if __has_include ("lvgl.h")
2321
#include "lvgl.h"
@@ -29,19 +27,10 @@ void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color
2927
#endif
3028

3129
/* Functions -----------------------------------------------------------------*/
32-
Arduino_H7_Video::Arduino_H7_Video(int width, int heigth, DisplayShieldModel shield) :
30+
Arduino_H7_Video::Arduino_H7_Video(int width, int heigth, H7DisplayShield &shield) :
3331
ArduinoGraphics(width, heigth) {
34-
_shield = shield;
35-
36-
#if defined(ARDUINO_PORTENTA_H7_M7)
37-
if (_shield == NONE_SHIELD) {
38-
_edidMode = video_modes_get_edid(width, heigth);
39-
} else if (_shield == GIGA_DISPLAY_SHIELD) {
40-
_edidMode = EDID_MODE_480x800_60Hz;
41-
}
42-
#elif defined(ARDUINO_GIGA)
43-
_edidMode = EDID_MODE_480x800_60Hz;
44-
#endif
32+
_shield = &shield;
33+
_edidMode = _shield->getEdidMode(width, heigth);
4534

4635
switch(_edidMode) {
4736
case EDID_MODE_640x480_60Hz ... EDID_MODE_800x600_59Hz:
@@ -66,45 +55,12 @@ int Arduino_H7_Video::begin() {
6655
}
6756

6857
textFont(Font_5x7);
58+
59+
/* Video controller/bridge init */
60+
_shield->init(_edidMode);
6961

70-
#if defined(ARDUINO_PORTENTA_H7_M7)
71-
if (_shield == NONE_SHIELD) {
72-
struct edid recognized_edid;
73-
int err_code = 0;
74-
75-
//Initialization of ANX7625
76-
err_code = anx7625_init(0);
77-
if(err_code < 0) {
78-
return err_code;
79-
}
80-
81-
//Checking HDMI plug event
82-
anx7625_wait_hpd_event(0);
83-
84-
//Read EDID
85-
anx7625_dp_get_edid(0, &recognized_edid);
86-
87-
//DSI Configuration
88-
anx7625_dp_start(0, &recognized_edid, (enum edid_modes) _edidMode);
89-
90-
//Configure SDRAM
91-
SDRAM.begin(dsi_getFramebufferEnd());
92-
} else if (_shield == GIGA_DISPLAY_SHIELD) {
93-
//Init LCD Controller
94-
st7701_init((enum edid_modes) _edidMode);
95-
96-
//Configure SDRAM
97-
SDRAM.begin();
98-
}
99-
#elif defined(ARDUINO_GIGA)
100-
//Init LCD Controller
101-
st7701_init((enum edid_modes) _edidMode);
102-
103-
//Configure SDRAM
104-
SDRAM.begin();
105-
#else
106-
#error Board not compatible with this library
107-
#endif
62+
/* Configure SDRAM */
63+
SDRAM.begin();
10864

10965
dsi_lcdClear(0);
11066

libraries/Arduino_H7_Video/src/Arduino_H7_Video.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,22 @@
1313

1414
/* Includes ------------------------------------------------------------------*/
1515
#include <ArduinoGraphics.h>
16+
#include "H7DisplayShield.h"
1617

1718
/* Exported defines ----------------------------------------------------------*/
18-
#define H7_VIDEO_MAX_WIDTH 1280
19-
#define H7_VIDEO_MAX_HEIGHT 1024
20-
2119
#define H7V_OK 1
2220
#define H7V_ERR_INSUFFMEM 2
2321

2422
/* Exported enumeration ------------------------------------------------------*/
25-
enum DisplayShieldModel {
26-
NONE_SHIELD = 0,
27-
GIGA_DISPLAY_SHIELD = 1
28-
};
2923

3024
/* Class ----------------------------------------------------------------------*/
3125
class Arduino_H7_Video : public ArduinoGraphics {
3226
public:
33-
Arduino_H7_Video(int width = H7_VIDEO_MAX_WIDTH, int heigth = H7_VIDEO_MAX_HEIGHT, DisplayShieldModel shield = NONE_SHIELD);
27+
#if defined(ARDUINO_PORTENTA_H7_M7)
28+
Arduino_H7_Video(int width = 1024, int heigth = 768, H7DisplayShield &shield = USBCVideo);
29+
#elif defined(ARDUINO_GIGA)
30+
Arduino_H7_Video(int width = 800, int heigth = 480, H7DisplayShield &shield = GigaDisplayShield);
31+
#endif
3432
virtual ~Arduino_H7_Video();
3533

3634
int begin();
@@ -45,7 +43,7 @@ class Arduino_H7_Video : public ArduinoGraphics {
4543

4644
void attachLVGLTouchCb(void (*touch_cb)(void*,void*));
4745
private:
48-
DisplayShieldModel _shield;
46+
H7DisplayShield* _shield;
4947
bool _rotated;
5048
int _edidMode;
5149
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "H7DisplayShield.h"
2+
3+
#include "Arduino.h"
4+
#include "anx7625.h"
5+
#include "st7701.h"
6+
extern "C" {
7+
#include "video_modes.h"
8+
}
9+
10+
int GigaDisplayShieldClass::init(int edidmode) {
11+
//Init LCD Controller
12+
st7701_init((enum edid_modes) edidmode);
13+
14+
return 0;
15+
}
16+
17+
int GigaDisplayShieldClass::getEdidMode(int h, int v) {
18+
return EDID_MODE_480x800_60Hz;
19+
}
20+
21+
int USBCVideoClass::init(int edidmode) {
22+
struct edid recognized_edid;
23+
int err_code = 0;
24+
25+
//Initialization of ANX7625
26+
err_code = anx7625_init(0);
27+
if(err_code < 0) {
28+
return err_code;
29+
}
30+
31+
//Checking HDMI plug event
32+
anx7625_wait_hpd_event(0);
33+
34+
//Read EDID
35+
anx7625_dp_get_edid(0, &recognized_edid);
36+
37+
//DSI Configuration
38+
anx7625_dp_start(0, &recognized_edid, (enum edid_modes) edidmode);
39+
40+
return 0;
41+
}
42+
43+
int USBCVideoClass::getEdidMode(int h, int v) {
44+
int edidmode = video_modes_get_edid(h, v);
45+
46+
return edidmode;
47+
}
48+
49+
GigaDisplayShieldClass GigaDisplayShield;
50+
USBCVideoClass USBCVideo;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class H7DisplayShield {
2+
public:
3+
virtual int init(int edidmode) = 0;
4+
virtual int getEdidMode(int h, int v);
5+
};
6+
7+
class GigaDisplayShieldClass : public H7DisplayShield {
8+
public:
9+
int init(int edidmode);
10+
int getEdidMode(int h, int v);
11+
};
12+
13+
class USBCVideoClass : public H7DisplayShield {
14+
public:
15+
int init(int edidmode);
16+
int getEdidMode(int h, int v);
17+
};
18+
19+
extern GigaDisplayShieldClass GigaDisplayShield;
20+
extern USBCVideoClass USBCVideo;

0 commit comments

Comments
 (0)