Skip to content

Refactor EPaperDisplay args into struct #10565

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Aug 11, 2025

Claude helped with initial prompt:

Refactor common_hal_epaperdisplay_epaperdisplay_construct so that the current arguments are struct fields and then the function only takes the struct. Also add a macro that initializes it to default values.

And one follow up prompt before minor manual cleanup and testing:

Clean up board files by removing settings that match the default. In particular bools that are false should be default, commands with NO_COMMAND and highlight color as 0.

For issue #10528

Claude helped with initial prompt:

> Refactor common_hal_epaperdisplay_epaperdisplay_construct so that the current arguments are struct fields and then the function only takes the struct. Also add a macro that initializes it to default values.

And one follow up prompt before minor manual cleanup and testing:

> Clean up board files by removing settings that match the default. In particular bools that are false should be default, commands with NO_COMMAND and highlight color as 0.

For issue micropython#10528
@tannewt tannewt marked this pull request as ready for review August 12, 2025 18:06
@tannewt tannewt requested a review from dhalbert August 12, 2025 18:06
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.

I'm suggesting a simpler way that is more like other code we have.

Comment on lines +56 to +92
#define EPAPERDISPLAY_CONSTRUCT_ARGS_DEFAULTS { \
.bus = mp_const_none, \
.start_sequence = NULL, \
.start_sequence_len = 0, \
.start_up_time = 0.0, \
.stop_sequence = NULL, \
.stop_sequence_len = 0, \
.width = 0, \
.height = 0, \
.ram_width = 0, \
.ram_height = 0, \
.colstart = 0, \
.rowstart = 0, \
.rotation = 0, \
.set_column_window_command = NO_COMMAND, \
.set_row_window_command = NO_COMMAND, \
.set_current_column_command = NO_COMMAND, \
.set_current_row_command = NO_COMMAND, \
.write_black_ram_command = NO_COMMAND, \
.black_bits_inverted = false, \
.write_color_ram_command = NO_COMMAND, \
.color_bits_inverted = false, \
.highlight_color = 0x000000, \
.highlight_color2 = 0x000000, \
.refresh_sequence = NULL, \
.refresh_sequence_len = 0, \
.refresh_time = 0.0, \
.busy_pin = NULL, \
.busy_state = false, \
.seconds_per_frame = 0.0, \
.always_toggle_chip_select = false, \
.grayscale = false, \
.acep = false, \
.spectra6 = false, \
.two_byte_sequence_length = false, \
.address_little_endian = false \
}
Copy link
Collaborator

@dhalbert dhalbert Aug 20, 2025

Choose a reason for hiding this comment

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

If everything in EPAPERDISPLAY_CONSTRUCT_ARGS_DEFAULTS is all zeros, then we could get away with not having this macro and instead using standard designated initializer syntax like below. I think this is easier to read.

epaperdisplay_construct_args_t construct_args = {
    .bus = display_bus,
    .start_sequence = display_start_sequence,
    .start_sequence_len = sizeof(display_start_sequence),
...
}

In C, if any fields are initialized, then the unmentioned fields in the initializers get "empty-initialized".

https://en.cppreference.com/w/c/language/struct_initialization.html
https://stackoverflow.com/questions/706030/are-uninitialized-struct-members-always-set-to-zero

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.

2 participants