Skip to content

Commit e72a61a

Browse files
rootroot
root
authored and
root
committed
Port Display and Camera driver for WebAI board
1 parent 68a6b75 commit e72a61a

File tree

5 files changed

+112
-27
lines changed

5 files changed

+112
-27
lines changed

k210-freertos/mpy_support/modules/board.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,30 @@ def __init__(self):
3434
self.I2S_WS = 33
3535
self.I2S_DA = 34
3636
self.I2S_BCK = 35
37+
#self.LCD_CS = 36
38+
#self.LCD_RST = 37
39+
#self.LCD_DC = 38
40+
#self.LCD_WR = 39
41+
#self.DVP_SDA = 40
42+
#self.DVP_SCL = 41
43+
#self.DVP_RST = 42
44+
#self.DVP_VSYNC = 43
45+
#self.DVP_PWDN = 44
46+
#self.DVP_HSYNC = 45
47+
#self.DVP_XCLK = 46
48+
#self.DVP_PCLK = 47
3749
self.LCD_CS = 36
38-
self.LCD_RST = 37
50+
self.LCD_RST = 39
3951
self.LCD_DC = 38
40-
self.LCD_WR = 39
41-
self.DVP_SDA = 40
42-
self.DVP_SCL = 41
43-
self.DVP_RST = 42
44-
self.DVP_VSYNC = 43
45-
self.DVP_PWDN = 44
46-
self.DVP_HSYNC = 45
47-
self.DVP_XCLK = 46
48-
self.DVP_PCLK = 47
52+
self.LCD_WR = 37
53+
self.DVP_SDA = 47
54+
self.DVP_SCL = 46
55+
self.DVP_RST = 45
56+
self.DVP_VSYNC = 44
57+
self.DVP_PWDN = 43
58+
self.DVP_HSYNC = 42
59+
self.DVP_XCLK = 41
60+
self.DVP_PCLK = 40
4961
self.pin_name=['WIFI_TX ','WIFI_RX ','WIFI_EN ','PIN9','PIN10','PIN11','LED_B','LED_G','LED_R','PIN15','BOOT_KEY','PIN17','MIC_ARRAY_BCK','MIC_ARRAY_WS ','MIC_ARRAY_DATA3','MIC_ARRAY_DATA2','MIC_ARRAY_DATA1','MIC_ARRAY_DATA0','MIC_ARRAY_LED','SPI0_CS1','SPI0_MISO','SPI0_CLK ','SPI0_MOSI','SPI0_CS0','MIC0_WS','MIC0_DATA','MIC0_BCK','I2S_WS','I2S_DA','I2S_BCK','LCD_CS','LCD_RST','LCD_DC','LCD_WR ','DVP_SDA','DVP_SCL','DVP_RST','DVP_VSYNC','DVP_PWDN','DVP_HSYNC','DVP_XCLK','DVP_PCLK']
5062
def pin_map(self,Pin = None):
5163
if Pin == None:

k210-freertos/mpy_support/standard_lib/display/moddisplay_tft.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ STATIC mp_obj_t display_tft_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
224224
TFT_drawRect(0, 0, active_dstate->_width, active_dstate->_height, TFT_CYAN);
225225
int fhight = TFT_getfontheight();
226226
active_dstate->_fg = TFT_GREEN;
227-
TFT_print("MicroPython", CENTER, (active_dstate->_height/2) - (fhight/2));
227+
TFT_print("MicroPython G", CENTER, (active_dstate->_height/2) - (fhight/2));
228228
active_dstate->_fg = TFT_BLUE;
229-
TFT_print("MicroPython", CENTER, (active_dstate->_height/2) + (fhight/2));
229+
TFT_print("MicroPython B", CENTER, (active_dstate->_height/2) + (fhight/2));
230230
active_dstate->_fg = TFT_RED;
231-
TFT_print("MicroPython", CENTER, (active_dstate->_height/2) - fhight - (fhight/2));
231+
TFT_print("MicroPython R", CENTER, (active_dstate->_height/2) - fhight - (fhight/2));
232232
active_dstate->_fg = TFT_GREEN;
233233
active_dstate->_bg = TFT_BLACK;
234234
}

k210-freertos/mpy_support/standard_lib/display/tftspi.c

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353

5454

5555
#define WAIT_CYCLE 0U
56-
#define LCD_X_MAX 240
57-
#define LCD_Y_MAX 320
56+
#define LCD_X_MAX 320
57+
#define LCD_Y_MAX 240
5858
#define TFT_BGR 8
5959
// RGB to GRAYSCALE constants
6060
// 0.2989 0.5870 0.1140
@@ -63,8 +63,10 @@
6363
#define GS_FACT_B 0.2140
6464

6565
#define SPI_CHANNEL (0)
66-
#define DCX_IO (38)
67-
#define TFT_RST (37)
66+
#define LCD_CS (36)
67+
#define LCD_RST (39)
68+
#define LCD_DC (38)
69+
#define LCD_WR (37)
6870

6971
enum _instruction_length
7072
{
@@ -115,7 +117,7 @@ static mp_fpioa_cfg_item_t disp_pin_func[DISP_NUM_FUNC];
115117
static uint32_t tft_spi_speed = SPI_DEFAULT_SPEED;
116118

117119
static const char TAG[] = "[TFTSPI]";
118-
static uint8_t invertrot = 1;
120+
static uint8_t invertrot = 0;
119121

120122
// ==== Functions =====================
121123

@@ -186,10 +188,10 @@ static bool tft_hard_init(void)
186188
return false;
187189
}
188190

189-
disp_pin_func[0] = (mp_fpioa_cfg_item_t){tft_dc_gpionum, DCX_IO, GPIO_USEDAS_DCX, FUNC_GPIOHS0 + tft_dc_gpionum};
190-
disp_pin_func[1] = (mp_fpioa_cfg_item_t){-1, 36, GPIO_USEDAS_CS, FUNC_SPI0_SS3};
191-
disp_pin_func[2] = (mp_fpioa_cfg_item_t){-1, 39, GPIO_USEDAS_CLK, FUNC_SPI0_SCLK};
192-
disp_pin_func[3] = (mp_fpioa_cfg_item_t){tft_rst_gpionum, TFT_RST, GPIO_USEDAS_RST, FUNC_GPIOHS0 + tft_rst_gpionum};
191+
disp_pin_func[0] = (mp_fpioa_cfg_item_t){tft_dc_gpionum, LCD_DC, GPIO_USEDAS_DCX, FUNC_GPIOHS0 + tft_dc_gpionum};
192+
disp_pin_func[1] = (mp_fpioa_cfg_item_t){-1, LCD_CS, GPIO_USEDAS_CS, FUNC_SPI0_SS3};
193+
disp_pin_func[2] = (mp_fpioa_cfg_item_t){-1, LCD_WR, GPIO_USEDAS_CLK, FUNC_SPI0_SCLK};
194+
disp_pin_func[3] = (mp_fpioa_cfg_item_t){tft_rst_gpionum, LCD_RST, GPIO_USEDAS_RST, FUNC_GPIOHS0 + tft_rst_gpionum};
193195

194196
if (!fpioa_check_pins(DISP_NUM_FUNC, disp_pin_func, GPIO_FUNC_DISP)) {
195197
gpiohs_set_free(tft_dc_gpionum);
@@ -256,6 +258,7 @@ static void tft_write_rgb565(uint16_t* data_buf, uint32_t length)
256258
{
257259
set_dcx_data();
258260
io_write(spi_dfs16, (const uint8_t *)(data_buf), length * 2);
261+
//io_write(spi_dfs8, (const uint8_t *)(data_buf), length * 2);
259262
}
260263

261264
/*
@@ -271,8 +274,12 @@ static void tft_write_32bit(uint32_t* data_buf, uint32_t length)
271274
//-------------------------------------------------------
272275
static void tft_fill_data(uint32_t data, uint32_t length)
273276
{
277+
uint32_t len = 0;
278+
LOGV(TAG, "tft_fill_data length = 0x%X", length);
279+
if (length > 1) len = length/2 - 1;
280+
else len = length;
274281
set_dcx_data();
275-
spi_dev_fill(spi_dfs32, 0, data, data, length/2 - 1);
282+
spi_dev_fill(spi_dfs32, 0, data, data, len);
276283
}
277284

278285

@@ -301,6 +308,41 @@ static bool tft_init(uint8_t hw_sw)
301308
tft_write_command(PIXEL_FORMAT_SET);
302309
data = 0x55;
303310
tft_write_byte(&data, 1);
311+
312+
/*
313+
// aibit LCM init
314+
tft_write_command(NORMAL_DISPALY_ON);
315+
mp_hal_delay_ms(10);
316+
tft_write_command(BACKLIGHT_CTL2);
317+
tft_write_byte((uint8_t *)"\xFF\x93\x42", 3);
318+
mp_hal_delay_ms(10);
319+
tft_write_command(INVERSION_DISPALY_ON);
320+
mp_hal_delay_ms(10);
321+
tft_write_command(MEMORY_ACCESS_CTL);
322+
tft_write_byte((uint8_t *)"\x01",1);
323+
mp_hal_delay_ms(10);
324+
tft_write_command(POWER_CTL1);
325+
tft_write_byte((uint8_t *)"\x1D\x0A", 2);
326+
mp_hal_delay_ms(10);
327+
tft_write_command(POWER_CTL2);
328+
tft_write_byte((uint8_t *)"\x02", 1);
329+
mp_hal_delay_ms(10);
330+
tft_write_command(VCOM_CTL1);
331+
tft_write_byte((uint8_t *)"\x2F\x27", 2);
332+
mp_hal_delay_ms(10);
333+
tft_write_command(VCOM_CTL2);
334+
tft_write_byte((uint8_t *)"\xA4", 1);
335+
tft_write_command(BACKLIGHT_CTL1);
336+
tft_write_byte((uint8_t *)"\x0B", 1);
337+
mp_hal_delay_ms(10);
338+
tft_write_command(POSITIVE_GAMMA_CORRECT);
339+
tft_write_byte((uint8_t *)"\x0F\x24\x21\x0C\x0F\x06\x50\x75\x3F\x07\x12\x05\x11\x0B\x08", 15);
340+
mp_hal_delay_ms(10);
341+
tft_write_command(NEGATIVE_GAMMA_CORRECT);
342+
tft_write_byte((uint8_t *)"\x08\x1D\x20\x02\x0E\x04\x31\x24\x42\x03\x0B\x09\x30\x36\x0F", 15);
343+
mp_hal_delay_ms(10);
344+
*/
345+
304346
tft_write_command(DISPALY_ON);
305347
return true;
306348
}
@@ -455,6 +497,7 @@ void send_frame_buffer()
455497
{
456498
if ((active_dstate->use_frame_buffer) && active_dstate->tft_frame_buffer) {
457499
LOGV(TAG, "Send frame buffer at %p", active_dstate->tft_frame_buffer);
500+
LOGV(TAG, "width:%d height:%d", active_dstate->_width, active_dstate->_height );
458501
// ** Send address window **
459502
disp_spi_transfer_addrwin(0, active_dstate->_width-1, 0, active_dstate->_height-1);
460503
// Send color buffer
@@ -519,12 +562,21 @@ void _tft_setRotation(uint8_t rot) {
519562
}
520563
else if (invertrot == 1) {
521564
switch (rotation) {
565+
/* ILI9341
522566
case PORTRAIT:
523567
madctl = (MADCTL_MY | MADCTL_MX | active_dstate->TFT_RGB_BGR);
524568
break;
525569
case LANDSCAPE:
526570
madctl = (MADCTL_MY | MADCTL_MV | active_dstate->TFT_RGB_BGR);
527571
break;
572+
*/
573+
// ILI9342
574+
case LANDSCAPE:
575+
madctl = (MADCTL_MY | MADCTL_MX | active_dstate->TFT_RGB_BGR);
576+
break;
577+
case PORTRAIT:
578+
madctl = (MADCTL_MY | MADCTL_MV | active_dstate->TFT_RGB_BGR);
579+
break;
528580
case PORTRAIT_FLIP:
529581
madctl = (active_dstate->TFT_RGB_BGR);
530582
break;
@@ -575,7 +627,7 @@ int TFT_display_init(display_config_t *dconfig)
575627
{
576628
TFT_display_setvars(dconfig);
577629

578-
if (!tft_init(3)) return -1;
630+
if (!tft_init(1)) return -1; // 0x01 soft reset, 0x2 hard reset, 0x3 both reset
579631
vTaskDelay(100);
580632

581633
return 0;

k210-freertos/mpy_support/standard_lib/display/tftspi.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,17 @@ typedef uint16_t color_t;
9090
#define DISP_TYPE_ST7735B 5
9191
#define DISP_TYPE_M5STACK 6
9292
#define DISP_TYPE_GENERIC 7
93+
#define DISP_TYPE_ILI9342 8
9394
// EPD types
9495
#define DISP_TYPE_EPD_2_9_GDEH 8
9596
#define DISP_TYPE_EPD_2_9_DEPG 9
9697
#define DISP_TYPE_EPD_4_2 10
9798
#define DISP_TYPE_EPD_4_2_C 11
9899
#define DISP_TYPE_MAX 12
99100

100-
#define DEFAULT_TFT_DISPLAY_WIDTH 240
101-
#define DEFAULT_TFT_DISPLAY_HEIGHT 320
102-
#define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341
101+
#define DEFAULT_TFT_DISPLAY_WIDTH 320
102+
#define DEFAULT_TFT_DISPLAY_HEIGHT 240
103+
#define DEFAULT_DISP_TYPE DISP_TYPE_ILI9342
103104

104105
#define SPI_DFS8_SPEED 4000000
105106
#define SPI_DEFAULT_SPEED 10000000

k210-freertos/mpy_support/standard_lib/machine/camera/mod_camera.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static bool cam_pins_init(void)
8484
if (!camera_pins_init) {
8585
mp_fpioa_cfg_item_t camera_pin_func[8];
8686
// FPIOA configuration
87+
/*
8788
camera_pin_func[0] = (mp_fpioa_cfg_item_t){-1, 42, GPIO_USEDAS_DVP_RST, FUNC_CMOS_RST};
8889
camera_pin_func[1] = (mp_fpioa_cfg_item_t){-1, 44, GPIO_USEDAS_DVP_PWDN, FUNC_CMOS_PWDN};
8990
camera_pin_func[2] = (mp_fpioa_cfg_item_t){-1, 46, GPIO_USEDAS_DVP_XCLK, FUNC_CMOS_XCLK};
@@ -92,6 +93,15 @@ static bool cam_pins_init(void)
9293
camera_pin_func[5] = (mp_fpioa_cfg_item_t){-1, 47, GPIO_USEDAS_DVP_PCLK, FUNC_CMOS_PCLK};
9394
camera_pin_func[6] = (mp_fpioa_cfg_item_t){-1, 41, GPIO_USEDAS_DVP_SCLK, FUNC_SCCB_SCLK};
9495
camera_pin_func[7] = (mp_fpioa_cfg_item_t){-1, 40, GPIO_USEDAS_DVP_SDA, FUNC_SCCB_SDA};
96+
*/
97+
camera_pin_func[0] = (mp_fpioa_cfg_item_t){-1, 45, GPIO_USEDAS_DVP_RST, FUNC_CMOS_RST};
98+
camera_pin_func[1] = (mp_fpioa_cfg_item_t){-1, 43, GPIO_USEDAS_DVP_PWDN, FUNC_CMOS_PWDN};
99+
camera_pin_func[2] = (mp_fpioa_cfg_item_t){-1, 41, GPIO_USEDAS_DVP_XCLK, FUNC_CMOS_XCLK};
100+
camera_pin_func[3] = (mp_fpioa_cfg_item_t){-1, 44, GPIO_USEDAS_DVP_VSYNC, FUNC_CMOS_VSYNC};
101+
camera_pin_func[4] = (mp_fpioa_cfg_item_t){-1, 42, GPIO_USEDAS_DVP_HREF, FUNC_CMOS_HREF};
102+
camera_pin_func[5] = (mp_fpioa_cfg_item_t){-1, 40, GPIO_USEDAS_DVP_PCLK, FUNC_CMOS_PCLK};
103+
camera_pin_func[6] = (mp_fpioa_cfg_item_t){-1, 46, GPIO_USEDAS_DVP_SCLK, FUNC_SCCB_SCLK};
104+
camera_pin_func[7] = (mp_fpioa_cfg_item_t){-1, 47, GPIO_USEDAS_DVP_SDA, FUNC_SCCB_SDA};
95105

96106
if (!fpioa_check_pins(8, camera_pin_func, GPIO_FUNC_DVP)) {
97107
return false;
@@ -115,6 +125,16 @@ static bool cam_pins_deinit(void)
115125
if (camera_pins_init) {
116126
mp_fpioa_cfg_item_t camera_pin_func[8];
117127
// FPIOA configuration
128+
/*
129+
camera_pin_func[0] = (mp_fpioa_cfg_item_t){-1, 45, GPIO_USEDAS_NONE, FUNC_RESV0};
130+
camera_pin_func[1] = (mp_fpioa_cfg_item_t){-1, 43, GPIO_USEDAS_NONE, FUNC_RESV0};
131+
camera_pin_func[2] = (mp_fpioa_cfg_item_t){-1, 41, GPIO_USEDAS_NONE, FUNC_RESV0};
132+
camera_pin_func[3] = (mp_fpioa_cfg_item_t){-1, 44, GPIO_USEDAS_NONE, FUNC_RESV0};
133+
camera_pin_func[4] = (mp_fpioa_cfg_item_t){-1, 42, GPIO_USEDAS_NONE, FUNC_RESV0};
134+
camera_pin_func[5] = (mp_fpioa_cfg_item_t){-1, 40, GPIO_USEDAS_NONE, FUNC_RESV0};
135+
camera_pin_func[6] = (mp_fpioa_cfg_item_t){-1, 46, GPIO_USEDAS_NONE, FUNC_RESV0};
136+
camera_pin_func[7] = (mp_fpioa_cfg_item_t){-1, 47, GPIO_USEDAS_NONE, FUNC_RESV0};
137+
*/
118138
camera_pin_func[0] = (mp_fpioa_cfg_item_t){-1, 42, GPIO_USEDAS_NONE, FUNC_RESV0};
119139
camera_pin_func[1] = (mp_fpioa_cfg_item_t){-1, 44, GPIO_USEDAS_NONE, FUNC_RESV0};
120140
camera_pin_func[2] = (mp_fpioa_cfg_item_t){-1, 46, GPIO_USEDAS_NONE, FUNC_RESV0};

0 commit comments

Comments
 (0)