Skip to content
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

epaperdisplay: fix delay when two_byte_sequence_length is true #9694

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

Sola85
Copy link

@Sola85 Sola85 commented Oct 8, 2024

When playing around with custom LUT waveforms on an epaperdisplay, I needed two_byte_sequence_length=True, in order to be able to send more than 128 bytes of start_sequence data. However, I noticed that the delays between commands were read incorrectly in this case.

When two_byte_sequence_length=True, the adress of the delay (if present) is shifted back by 1 byte as compared to when two_byte_sequence_length=False, but prior to this PR the delay was always read from the same adress.

The memory layout for one command is: "command (1 byte), data_size (1-2 bytes), data (data_size bytes), delay (0-1 bytes)".

Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkulinski you added support for two byte sequence lengths back in #5874 -- if you have a chance you might want to make sure this change is compatible with your displays & their control sequences.

@@ -157,7 +157,7 @@ static void send_command_sequence(epaperdisplay_epaperdisplay_obj_t *self,
uint16_t delay_length_ms = 0;
if (delay) {
data_size++;
delay_length_ms = *(cmd + 1 + data_size);
delay_length_ms = *(cmd + 1 + data_size + self->two_byte_sequence_length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks -- I think I understand why the existing code is wrong, but maybe you want to have it as delay_length_ms = *(data + data_size) so that it always refers to the next byte after the end of data. I think that's clearer overall, and might even result in smaller generated code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do *(data+datasize), but then I think we have to move the increment of data_size to after reading delay_length_ms. I can try this out this evening and update the PR.

@jepler
Copy link
Member

jepler commented Oct 8, 2024

I can't comment directly on this line of code because it's not touched by the change .. anyway, the position within the init sequence is advanced by i += 2 + data_size; and then an additional byte in the case of 2-byte lengths. This doesn't seem to take into account the presence of a delay value at all. I'm probably overlooking something, but just in case it jiggles someone's brain I wanted to mention it.

@Sola85
Copy link
Author

Sola85 commented Oct 8, 2024

I can't comment directly on this line of code because it's not touched by the change .. anyway, the position within the init sequence is advanced by i += 2 + data_size; and then an additional byte in the case of 2-byte lengths. This doesn't seem to take into account the presence of a delay value at all. I'm probably overlooking something, but just in case it jiggles someone's brain I wanted to mention it.

data_size in incremented half-way through the loop to include the delay byte conditionally. It also took me a while to understand what is going on here... This entire section would be a good canditate for refactoring, but I wanted to propose the minimal change possible to fix the issue.

@jepler
Copy link
Member

jepler commented Oct 8, 2024

Thanks, I missed that.

If you'd prefer not to tinker further with the code and call it good, I'm OK with that as well.

@dhalbert
Copy link
Collaborator

dhalbert commented Oct 8, 2024

I'll test on a MagTag, just to check for regression.

@Sola85
Copy link
Author

Sola85 commented Oct 8, 2024

Thanks, I missed that.

If you'd prefer not to tinker further with the code and call it good, I'm OK with that as well.

If you're ok with it and Dan's test is ok, then let's just leave it as it is for now.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works on a MagTag

@dhalbert dhalbert merged commit 44748ab into adafruit:main Oct 8, 2024
485 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants