Skip to content

Commit 96838e2

Browse files
committed
debug of i80_bus bitbang driver
1 parent 377ede3 commit 96838e2

File tree

2 files changed

+86
-57
lines changed

2 files changed

+86
-57
lines changed

ext_mod/lcd_bus/common_include/i80_bus.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
void *buf1;
8181
void *buf2;
8282

83+
/* buffer_flags is not used, but it needs to be here
84+
* otherwise function pointers are no more aligned
85+
* with the pointer use in _mp_lcd_bus_obj_t
86+
*/
87+
uint32_t buffer_flags;
88+
8389
bool trans_done;
8490
bool rgb565_byte_swap;
8591

ext_mod/lcd_bus/common_src/i80_bus.c

Lines changed: 80 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "py/obj.h"
1111
#include "py/runtime.h"
1212
#include "py/objarray.h"
13-
#include "mphalport.h" // for mp_hal_pin_output
1413

1514
//#include "mpconfigport.h"
1615
//#include "modmachine.h"
@@ -73,6 +72,11 @@
7372
mp_hal_pin_write(self->bus_config.data_gpio_nums[1], (buf[0] >> 1) & 1); \
7473
mp_hal_pin_write(self->bus_config.data_gpio_nums[0], buf[0] & 1); \
7574
}
75+
76+
// sleep_us(1) to ensure minimum WR pulse width, so that I can follow it with my logic analyzer
77+
// can be eliminated after debugging
78+
#define WR_PULSE() { mp_hal_pin_write(self->bus_config.wr_gpio_num, 0)/*; sleep_us(1)*/; mp_hal_pin_write(self->bus_config.wr_gpio_num, 1);; }
79+
7680
/* end macros */
7781

7882

@@ -103,7 +107,7 @@
103107
*/
104108
static mp_obj_t mp_lcd_i80_bus_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
105109
{
106-
enum {
110+
enum {
107111
ARG_dc,
108112
ARG_wr,
109113
ARG_data0,
@@ -128,8 +132,8 @@
128132
ARG_dc_cmd_high,
129133
ARG_dc_dummy_high,
130134
ARG_dc_data_high,
131-
ARG_cmd_bits,
132-
ARG_param_bits,
135+
//ARG_cmd_bits,
136+
//ARG_param_bits,
133137
ARG_cs_active_high,
134138
ARG_reverse_color_bits,
135139
ARG_swap_color_bytes,
@@ -199,7 +203,8 @@
199203

200204
self->callback = mp_const_none;
201205

202-
#if !defined(mp_hal_pin_output) && !defined(IDF_VER)
206+
// mp_hal_pin_output if a function for rp2, so I have added PICO_HEAP_SIZE
207+
#if !defined(mp_hal_pin_output) && !defined(IDF_VER) && !defined(PICO_HEAP_SIZE)
203208
mp_raise_msg(&mp_type_NotImplementedError, MP_ERROR_TEXT("LCD I80 but is not available for this MCU"));
204209
#else
205210
self->panel_io_config.user_ctx = self;
@@ -220,7 +225,7 @@
220225
#endif /* defined(MP_HAL_PIN_SPEED_VERY_HIGH) && !defined(MICROPY_INCLUDED_MIMXRT_MPHALPORT_H) */
221226

222227
mp_hal_pin_write(self->bus_config.dc_gpio_num, self->panel_io_config.dc_levels.dc_data_level);
223-
mp_hal_pin_write(self->bus_config.wr_gpio_num, 0);
228+
mp_hal_pin_write(self->bus_config.wr_gpio_num, !self->panel_io_config.flags.cs_active_high);
224229

225230
self->bus_config.data_gpio_nums[0] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data0].u_obj);
226231
self->bus_config.data_gpio_nums[1] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data1].u_obj);
@@ -285,51 +290,80 @@
285290

286291
CS_LOW();
287292
DC_CMD();
288-
293+
289294
if (self->bus_config.bus_width == 8) {
290-
uint8_t *buf = NULL;
295+
uint8_t buf[1];
291296
if (self->panel_io_config.lcd_cmd_bits == 8) {
292297
buf[0] = (uint8_t)lcd_cmd;
293298
WRITE8();
294299
} else {
295300
buf[0] = (uint8_t)((uint16_t)lcd_cmd >> 8);
296301
WRITE8();
297-
WR_LOW();
298-
WR_HIGH();
302+
WR_PULSE();
299303
buf[0] = (uint8_t)((uint16_t)lcd_cmd & 0xFF);
300304
WRITE8();
301305
}
302306
} else {
303-
uint16_t *buf = NULL;
307+
uint16_t buf[1];
304308
buf[0] = (uint16_t)lcd_cmd;
305309
WRITE16();
306310
}
307-
308-
WR_LOW();
309-
WR_HIGH();
311+
312+
WR_PULSE();
310313

311314
DC_DATA();
312315

313-
if (param != NULL) {
314-
if (self->bus_config.bus_width == 8) {
315-
uint8_t *buf = (uint8_t *)param;
316-
uint16_t len = (uint16_t)param_size;
317-
while (len--) {
318-
WRITE8();
319-
WR_LOW();
320-
WR_HIGH();
321-
buf++;
322-
}
323-
} else {
324-
uint16_t *buf = (uint16_t *)param;
325-
uint16_t len = (uint16_t)(param_size / 2);
326-
while (len--) {
327-
WRITE16();
328-
WR_LOW();
329-
WR_HIGH();
330-
buf++;
316+
if (param_size > 0 ) {
317+
if (self->bus_config.bus_width == 8) {
318+
if (self->panel_io_config.lcd_cmd_bits == 8) {
319+
// 8 bit param over 8 bit bus
320+
uint8_t *buf = (uint8_t *)param;
321+
uint16_t len = (uint16_t)param_size;
322+
while (len--) {
323+
WRITE8();
324+
WR_PULSE();
325+
buf++;
326+
}
327+
} else {
328+
// 16 bit param over 8 bit bus
329+
uint16_t buf[1];
330+
uint16_t *p = (uint16_t *)param;
331+
uint16_t len = (uint16_t)(param_size / 2);
332+
while (len--) {
333+
buf[0] = (uint8_t)(*p >> 8);
334+
WRITE8();
335+
WR_PULSE();
336+
buf[0] = (uint8_t)(*p & 0xFF);
337+
WRITE8();
338+
WR_PULSE();
339+
p++;
340+
}
331341
}
332-
}
342+
} else {
343+
if (self->panel_io_config.lcd_cmd_bits == 8) {
344+
// 8 bit param over 16 bit bus
345+
uint16_t buf[1];
346+
uint8_t *p = (uint8_t *)param;
347+
uint16_t len = (uint16_t)param_size;
348+
while (len--) {
349+
buf[0] = (uint16_t)(*p);
350+
WRITE16();
351+
WR_PULSE();
352+
//WR_LOW();
353+
//WR_HIGH();
354+
p++;
355+
}
356+
} else {
357+
// 16 bit param over 16 bit bus
358+
uint16_t *buf = (uint16_t *)param;
359+
uint16_t len = (uint16_t)(param_size);
360+
while (len--) {
361+
WRITE16();
362+
WR_PULSE();
363+
buf++;
364+
}
365+
}
366+
}
333367
}
334368

335369
CS_HIGH();
@@ -361,25 +395,23 @@
361395
DC_CMD();
362396

363397
if (self->bus_config.bus_width == 8) {
364-
uint8_t *buf = NULL;
398+
uint8_t buf[1];
365399
if (self->panel_io_config.lcd_cmd_bits == 8) {
366400
buf[0] = (uint8_t)lcd_cmd;
367401
WRITE8();
368402
} else {
369403
buf[0] = (uint8_t)((uint16_t)lcd_cmd >> 8);
370404
WRITE8();
371-
WR_LOW();
372-
WR_HIGH();
405+
WR_PULSE();
373406
buf[0] = (uint8_t)((uint16_t)lcd_cmd & 0xFF);
374407
WRITE8();
375408
}
376409
} else {
377-
uint16_t *buf = NULL;
410+
uint16_t buf[1];
378411
buf[0] = (uint16_t)lcd_cmd;
379412
WRITE16();
380413
}
381-
WR_LOW();
382-
WR_HIGH();
414+
WR_PULSE();
383415
DC_DATA();
384416

385417
self->write_color(self, color, color_size);
@@ -464,8 +496,7 @@
464496
WRITE8();
465497
}
466498
buf++;
467-
WR_LOW();
468-
WR_HIGH();
499+
WR_PULSE();
469500
}
470501
}
471502

@@ -482,8 +513,7 @@
482513
WRITE16();
483514
}
484515
buf++;
485-
WR_LOW();
486-
WR_HIGH();
516+
WR_PULSE();
487517
}
488518
}
489519

@@ -501,17 +531,15 @@
501531
last = buf[0];
502532
WRITE8();
503533
}
504-
WR_LOW();
505-
WR_HIGH();
534+
WR_PULSE();
506535

507536
buf = &bd[i * 2];
508537

509538
if (buf[0] != last) {
510539
last = buf[0];
511540
WRITE8();
512541
}
513-
WR_LOW();
514-
WR_HIGH();
542+
WR_PULSE();
515543
}
516544
}
517545

@@ -529,17 +557,15 @@
529557
last = buf[0];
530558
WRITE16();
531559
}
532-
WR_LOW();
533-
WR_HIGH();
560+
WR_PULSE();
534561

535562
buf = &bd[i * 2];
536563

537564
if (buf[0] != last) {
538565
last = buf[0];
539566
WRITE16();
540567
}
541-
WR_LOW();
542-
WR_HIGH();
568+
WR_PULSE();
543569
}
544570
}
545571

@@ -556,15 +582,13 @@
556582
last = bd[0];
557583
*buf = bd[0] << 8;
558584
WRITE8();
559-
WR_LOW();
560-
WR_HIGH();
585+
WR_PULSE();
561586
*buf = bd[0] >> 8;
562587
WRITE8();
563588
WR_LOW();
564589
WR_HIGH();
565590
}
566-
WR_LOW();
567-
WR_HIGH();
591+
WR_PULSE();
568592
bd++;
569593
}
570594
}
@@ -582,8 +606,7 @@
582606
last = buf[0];
583607
WRITE16();
584608
}
585-
WR_LOW();
586-
WR_HIGH();
609+
WR_PULSE();
587610
buf++;
588611
}
589612
}

0 commit comments

Comments
 (0)