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

treewide: Apply changes for new svd2rust API #545

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

Rahix
Copy link
Owner

@Rahix Rahix commented May 4, 2024

As avr-device is upgrading to use svd2rust version 0.33.1 (see Rahix/avr-device#155), there are some significant changes in the generated API. We have to adapt the HAL code to use the new API whereever relevant. This PR is a preview of what will change.

The following major changes are necessary:

  • Registers are no longer accessed as struct-fields of the peripheral, but rather as methods of the peripheral.
  • Safe writing to a field or register is now done using a new .set() method instead of .bits().

Fortunately, these changes can be trivially automated from rustc error messages using the following script:

cargo build --message-format json 2>/dev/null \
  | jq '.message.children[].spans[] | {file: .file_name, line: .line_start, col: (.text[0].highlight_start - 1), insert: .suggested_replacement}' 2>/dev/null \
  | jq -r '"sed -ri '"'"'" + (.line | tostring) + "s/^(.{" + (.col | tostring) + "})/\\1" + .insert + "/'"'"' $(cd ../..; realpath " + .file + ")"' \
  | sort | uniq | bash

Rahix added 2 commits May 5, 2024 01:10
As avr-device is upgrading to use svd2rust version 0.33.1, there are
some significant changes in the generated API.  We have to adapt the HAL
code to use the new API whereever relevant.

This commit was mostly generated using the following command, which adds
the parentheses behind each register access to change it from
struct-field access to method call.

	cargo build --message-format json 2>/dev/null \
	  | jq '.message.children[].spans[] | {file: .file_name, line: .line_start, col: (.text[0].highlight_start - 1), insert: .suggested_replacement}' 2>/dev/null \
	  | jq -r '"sed -ri '"'"'" + (.line | tostring) + "s/^(.{" + (.col | tostring) + "})/\\1" + .insert + "/'"'"' $(cd ../..; realpath " + .file + ")"' \
	  | sort | uniq | bash

Shell magic for the win :)

Beyond this, .bits() had to be converted to .set() where safe accesses
are performed.
@Rahix Rahix mentioned this pull request May 4, 2024
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.

1 participant