Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/drivers/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,11 @@ void IOToggle(IO_t io)
IO_GPIO(io)->BSRRL = mask;
}
#elif defined(AT32F43x)
if (IO_GPIO(io)->odt & mask)
mask <<= 16; // bit is set, shift mask to reset half

IO_GPIO(io)->scr = IO_Pin(io);
if (IO_GPIO(io)->odt & mask) {
IO_GPIO(io)->clr = mask;
} else {
IO_GPIO(io)->scr = mask;
}
Comment on lines +247 to +251
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Refactor the AT32F43x GPIO toggle logic to use the scr register for both setting and clearing pins in a single atomic write, which improves efficiency by removing the if/else branch. [general, importance: 6]

Suggested change
if (IO_GPIO(io)->odt & mask) {
IO_GPIO(io)->clr = mask;
} else {
IO_GPIO(io)->scr = mask;
}
#elif defined(AT32F43x)
uint32_t toggleMask = mask;
if (IO_GPIO(io)->odt & mask) {
toggleMask <<= 16;
}
IO_GPIO(io)->scr = toggleMask;

#else
if (IO_GPIO(io)->ODR & mask)
mask <<= 16; // bit is set, shift mask to reset half
Expand Down