Skip to content

Commit 4a598b2

Browse files
committed
lcd driver cleanup
1 parent 8edee5a commit 4a598b2

File tree

3 files changed

+15
-72
lines changed

3 files changed

+15
-72
lines changed

components/nofrendo-esp32/spi_lcd.c

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -285,69 +285,13 @@ static void spi_master_init()
285285

286286
#define U16x2toU32(m,l) ((((uint32_t)(l>>8|(l&0xFF)<<8))<<16)|(m>>8|(m&0xFF)<<8))
287287

288-
void ili9341_send_data(int x, int y, int width, int height, const uint16_t *data) {
289-
int i, l;
290-
uint16_t x1, y1;
291-
uint32_t xv, yv, dc, bv;
292-
l = height*width;
293-
x1 = x+(width-1);//287
294-
y1 = y+(height-1);//y
295-
xv = U16x2toU32(x,x1);//32,287
296-
yv = U16x2toU32(y,y1);//y,y
297-
298-
// x = 32, y = 8 - 231, width = 256, height = 1
299-
//ets_printf("%08X\n", xv);
300-
301-
dc = (1 << PIN_NUM_DC);
302-
GPIO.out_w1tc = dc;
303-
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 7, SPI_USR_MOSI_DBITLEN_S);
304-
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), 0x2A);
305-
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
306-
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
307-
GPIO.out_w1ts = dc;
308-
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 31, SPI_USR_MOSI_DBITLEN_S);
309-
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), xv);
310-
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
311-
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
312-
GPIO.out_w1tc = dc;
313-
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 7, SPI_USR_MOSI_DBITLEN_S);
314-
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), 0x2B);
315-
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
316-
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
317-
GPIO.out_w1ts = dc;
318-
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 31, SPI_USR_MOSI_DBITLEN_S);
319-
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), yv);
320-
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
321-
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
322-
GPIO.out_w1tc = dc;
323-
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 7, SPI_USR_MOSI_DBITLEN_S);
324-
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), 0x2C);
325-
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
326-
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
327-
GPIO.out_w1ts = dc;
328-
329-
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 511, SPI_USR_MOSI_DBITLEN_S);
330-
while(l) {
331-
for (i=0; i<32; i+=2) {
332-
x1 = data[i];
333-
y1 = data[i+1];
334-
bv = U16x2toU32(x1,y1);
335-
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM) + (i << 1)), bv);
336-
}
337-
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
338-
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
339-
l-=32;
340-
data+=32;
341-
}
342-
}
343-
344288
extern uint16_t myPalette[];
345289

346290
void ili9341_write_frame(const uint16_t xs, const uint16_t ys, const uint16_t width, const uint16_t height, const uint8_t * data[]){
347291
int x, y;
348292
int i;
349293
uint16_t x1, y1;
350-
uint32_t xv, yv, dc, bv;
294+
uint32_t xv, yv, dc;
351295
uint32_t temp[16];
352296
dc = (1 << PIN_NUM_DC);
353297

@@ -390,6 +334,11 @@ void ili9341_write_frame(const uint16_t xs, const uint16_t ys, const uint16_t wi
390334
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 511, SPI_USR_MOSI_DBITLEN_S);
391335
while (x<width) {
392336
for (i=0; i<16; i++) {
337+
if(data == NULL){
338+
temp[i] = 0;
339+
x += 2;
340+
continue;
341+
}
393342
x1 = myPalette[(unsigned char)(data[y][x])]; x++;
394343
y1 = myPalette[(unsigned char)(data[y][x])]; x++;
395344
temp[i] = U16x2toU32(x1,y1);

components/nofrendo-esp32/spi_lcd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ extern "C"
2727
#endif
2828

2929
void ili9341_write_frame(const uint16_t x, const uint16_t y, const uint16_t width, const uint16_t height, const uint8_t *data[]);
30-
void ili9341_send_data(int x, int y, int width, int height, const uint16_t *data);
3130
void ili9341_init();
3231

3332

components/nofrendo-esp32/video_audio.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ static void free_write(int num_dirties, rect_t *dirty_rects);
122122
static void custom_blit(bitmap_t *bmp, int num_dirties, rect_t *dirty_rects);
123123
static char fb[1]; //dummy
124124

125-
uint16 line[320];
126125
QueueHandle_t vidQueue;
127126

128127
viddriver_t sdlDriver =
@@ -277,8 +276,8 @@ void osd_getmouse(int *x, int *y, int *button)
277276
/* this is at the bottom, to eliminate warnings */
278277
void osd_shutdown()
279278
{
280-
osd_stopsound();
281-
osd_freeinput();
279+
osd_stopsound();
280+
osd_freeinput();
282281
}
283282

284283
static int logprint(const char *string)
@@ -292,19 +291,15 @@ static int logprint(const char *string)
292291

293292
int osd_init()
294293
{
295-
int y;
296-
log_chain_logfunc(logprint);
294+
log_chain_logfunc(logprint);
297295

298-
if (osd_init_sound())
299-
return -1;
296+
if (osd_init_sound())
297+
return -1;
300298

301299
ili9341_init();
302-
memset(line, 0, 320);
303-
for (y=0; y<240; y++) ili9341_send_data(0, y, 320, 1, line);
300+
ili9341_write_frame(0,0,320,240,NULL);
304301
vidQueue=xQueueCreate(1, sizeof(bitmap_t *));
305-
xTaskCreatePinnedToCore(&videoTask, "videoTask", 2048, NULL, 5, NULL, 1);
306-
osd_initinput();
307-
308-
309-
return 0;
302+
xTaskCreatePinnedToCore(&videoTask, "videoTask", 2048, NULL, 5, NULL, 1);
303+
osd_initinput();
304+
return 0;
310305
}

0 commit comments

Comments
 (0)