-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: main
Are you sure you want to change the base?
Conversation
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
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 suggesting a simpler way that is more like other code we have.
#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 \ | ||
} |
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.
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
Claude helped with initial prompt:
And one follow up prompt before minor manual cleanup and testing:
For issue #10528