-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added option to allow Displays with Single Byte Boundaries #1708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c3329e2
cc96c39
a54493b
5f0e71c
f4cede4
2e0268c
8087cb4
e254597
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, | |
mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, | ||
uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, | ||
uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, | ||
const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle) { | ||
const mcu_pin_obj_t* backlight_pin, bool init_cs_toggle, bool single_byte_bounds) { | ||
self->color_depth = color_depth; | ||
self->set_column_command = set_column_command; | ||
self->set_row_command = set_row_command; | ||
|
@@ -55,6 +55,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, | |
self->rowstart = rowstart; | ||
self->auto_brightness = false; | ||
self->init_cs_toggle = init_cs_toggle; | ||
self->single_byte_bounds = single_byte_bounds; | ||
|
||
if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) { | ||
self->begin_transaction = common_hal_displayio_parallelbus_begin_transaction; | ||
|
@@ -85,6 +86,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, | |
uint8_t *data = cmd + 2; | ||
if (self->init_cs_toggle && self->set_cs != NULL) { | ||
self->set_cs(self->bus, true); | ||
common_hal_time_delay_ms(1); | ||
self->set_cs(self->bus, false); | ||
} | ||
self->send(self->bus, true, cmd, 1); | ||
|
@@ -218,16 +220,25 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) { | |
} | ||
|
||
void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { | ||
// TODO(tannewt): Handle displays with single byte bounds. | ||
uint16_t data[2]; | ||
self->send(self->bus, true, &self->set_column_command, 1); | ||
data[0] = __builtin_bswap16(x0 + self->colstart); | ||
data[1] = __builtin_bswap16(x1 - 1 + self->colstart); | ||
self->send(self->bus, false, (uint8_t*) data, 4); | ||
if (self->single_byte_bounds) { | ||
data[0] = __builtin_bswap16(((x0 + self->colstart) << 8) | ((x1 - 1 + self->colstart) & 0xFF)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using bswap and shifts here, put the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point on readability. I was just hoping it would make the program a little smaller when I did it this way. Thanks for merging it in. I can make the readability improvement for the next release. |
||
self->send(self->bus, false, (uint8_t*) data, 2); | ||
} else { | ||
data[0] = __builtin_bswap16(x0 + self->colstart); | ||
data[1] = __builtin_bswap16(x1 - 1 + self->colstart); | ||
self->send(self->bus, false, (uint8_t*) data, 4); | ||
} | ||
self->send(self->bus, true, &self->set_row_command, 1); | ||
data[0] = __builtin_bswap16(y0 + self->rowstart); | ||
data[1] = __builtin_bswap16(y1 - 1 + self->rowstart); | ||
self->send(self->bus, false, (uint8_t*) data, 4); | ||
if (self->single_byte_bounds) { | ||
data[0] = __builtin_bswap16(((y0 + self->rowstart) << 8) | ((y1 - 1 + self->rowstart) & 0xFF)); | ||
self->send(self->bus, false, (uint8_t*) data, 2); | ||
} else { | ||
data[0] = __builtin_bswap16(y0 + self->rowstart); | ||
data[1] = __builtin_bswap16(y1 - 1 + self->rowstart); | ||
self->send(self->bus, false, (uint8_t*) data, 4); | ||
} | ||
self->send(self->bus, true, &self->write_ram_command, 1); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is going to be reliable, especially on the faster MCUs and with longer wires going to the display — the voltage might have not enough time to grow to TTL levels. I wonder if it wouldn't be better to toggle the CS pin at the start and at the end of the delay later in this loop.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically leave the
self->set_cs(self->bus, false)
here, and move theself->set_cs(self->bus, true)
to right after the send commands. Of course then we will need one more just before the loop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason I have the toggle commands right next to each other is because that’s how it functions in the Arduino driver.
I originally had it after the send command and it required adding an additional reset for the ST7789 display to function for it to work, which is the main reason I added this. When I moved it to before the send commands based on the comments by @ladyada, it worked much better.
Also, I was testing with relatively long wires hooked up (about 6” or so) using an M4 processor and it worked consistently in this manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about it for a bit, I could dd an arbitrary amount of delay between (1-2ms) between the commands if that would make you feel more comfortable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. It's initialization code, so it doesn't hurt us much if it takes a few ms longer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked in the datasheet to see about minimum CS toggle times, and the minimum times for CS setup are in the tens of nanoseconds, so it seems like this will not be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, sorry for being paranoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was appropriate, and a small delay is good. Microcontrollers will only get faster.