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

Add read and write impl for Serial, Irq flags functions and RTIC example #232

Merged
merged 2 commits into from
Jun 8, 2021

Conversation

brain113
Copy link
Contributor

@brain113 brain113 commented Jun 7, 2021

Hi,
This pull request adds Read and Write implementations to Serial and few functions to work with Irq flags.
This needed to add more control under communicaiton flow and timing.

Also I added an example how to use this with RTIC. The example uses DIR pin when transmiting (like RS485).

PS: This is my first pull request ever :)

Copy link
Member

@Sh3Rm4n Sh3Rm4n left a comment

Choose a reason for hiding this comment

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

PS: This is my first pull request ever :)

Whoooho. Pretty exciting stuff. I'm happy to be the reviewer of your first PR 🎉

This PR looks pretty good. One minor nit, and you also have to make rustfmt happy via cargo fmt --all and clippy has also some minor thing to say: https://github.com/stm32-rs/stm32f3xx-hal/runs/2765167229

Thanks for your PR. I'm pretty excited about this as well, as this comes with the first RTIC example for this project! 😄

Comment on lines 16 to 17
type SerialType = Serial<stm32f3xx_hal::pac::USART1, (gpio::Pin<gpio::Gpioa, U<9_u8>, Alternate<PushPull, 7_u8>>, gpio::Pin<gpio::Gpioa, U<10_u8>, Alternate<PushPull, 7_u8>>)>;
type DirType = stm32f3xx_hal::gpio::Pin<gpio::Gpioe, U<13_u8>, Output<PushPull>>;
Copy link
Member

Choose a reason for hiding this comment

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

Even though these are the correct types hinted by the compiler, there exists type aliases, which are easier to read. I'd recommend them:

Suggested change
type SerialType = Serial<stm32f3xx_hal::pac::USART1, (gpio::Pin<gpio::Gpioa, U<9_u8>, Alternate<PushPull, 7_u8>>, gpio::Pin<gpio::Gpioa, U<10_u8>, Alternate<PushPull, 7_u8>>)>;
type DirType = stm32f3xx_hal::gpio::Pin<gpio::Gpioe, U<13_u8>, Output<PushPull>>;
type SerialType = Serial<stm32f3xx_hal::pac::USART1, (gpio::gpioa::PA9<A7<PushPull>>, gpio::gpioa::PA10<A7<PushPull>>)>;
type DirType = stm32f3xx_hal::gpio::gpioe::PE13<Output<PushPull>>;

@brain113
Copy link
Contributor Author

brain113 commented Jun 8, 2021

Hi,
thank you for the warm welcome!
I added additional commit to make rustfmt and clippy happy.

Actually I don't understand why clippy make me to change
init::LateResources {serial, dir}
to
init::LateResources {dir, serial}
the struct definition is
struct Resources { serial: SerialType, dir: DirType, }
so the "serial" field is the first.

@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Jun 8, 2021

This is pretty strange indeed. A wild guess: Maybe it has something to do with the rtic #[resources] proc-macro, which reorders the fields under the hood and this makes clippy complain?
I don't know. Would be worth looking into, but it does not really matter right now.

Thank you really much for your contribution. Nice PR! 👍

@Sh3Rm4n Sh3Rm4n merged commit 2a4382e into stm32-rs:master Jun 8, 2021
This pull request was closed.
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