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

Stream x improve #666

Merged
merged 1 commit into from
Jul 29, 2023
Merged

Stream x improve #666

merged 1 commit into from
Jul 29, 2023

Conversation

YruamaLairba
Copy link
Contributor

@YruamaLairba YruamaLairba commented Jul 3, 2023

Hi, i'm trying to rewrite the stream struct API, here is the list modification i'm doing on stream:

  • implement missing feature (already discussed in another Draft Pull Request)
  • remove unecessary generics (lready discussed elsewhere)
  • replace "class" method by "object" method to follow "peripheral ownership pattern"
  • remove "get" prefix on getter to follow coding style of rust compiler
  • rename things, to give a more natural, shorter or less ambiguous name
  • replace some raw parameter by enum to make thing safer or more natural
  • disable method just write 0 to the enable bit. In my opinion, trying to handle thing when disabling the hardware is the
  • role of an higher level abstraction

This is what i'm doing on Transfer struct
-adapt to make it compile with the modified stream API
-put the "disable" logic i removed from Stream
-EDIT add or fix method for interrupt flags manipulations, this is required to make i2c/dma module to compile again

EDIT: i2c/dma module use transfer and stream, so fixing it to fit the change

src/dma/mod.rs Outdated Show resolved Hide resolved
@burrbull
Copy link
Contributor

burrbull commented Jul 5, 2023

rebase, please and update examples if it is needed

@YruamaLairba
Copy link
Contributor Author

can't rebase, there is conflicting change

@burrbull
Copy link
Contributor

first squash commits and then rebase
See https://github.com/stm32-rs/stm32f4xx-hal/commits/StreamX_improve

@YruamaLairba
Copy link
Contributor Author

will do, but ii need to fix examples first.

@YruamaLairba
Copy link
Contributor Author

@burrbull do you know a way to check all examples ? when i use cargo check --examples --feature="stm32f411" only examples that don't require additional feature are checked. For the moment i just manually checked examples that contain "dma" in the name.

@burrbull
Copy link
Contributor

if you on linux you could run ./tools/check.py to check all chips. Although it is slightly outdated (for example doesn't have rtic feature).

@YruamaLairba
Copy link
Contributor Author

merging correctly will be difficult, there was many change since i started this PR, i fear Git will automatically resolve conflict in incoherent way. I have a example not working but I may forgot to check it earlier

@YruamaLairba YruamaLairba force-pushed the StreamX_improve branch 3 times, most recently from a4b8b13 to af0cc5e Compare July 16, 2023 16:19
@YruamaLairba YruamaLairba marked this pull request as ready for review July 16, 2023 16:27
@YruamaLairba
Copy link
Contributor Author

@burrbull ready for a review, i just didn't change the CHANGELOG, do know what description i should put. I'm very skeptical Transfer. The main problem is the ownership taking of the peripheral, this prevent to freely use the peripheral. But beyond that, it's seems some people already added some functionality to it just to make it usable for some peripheral, which is again the intend of being general purpose stuff.

@YruamaLairba
Copy link
Contributor Author

Sorry, I just found a typo i repeated many time because of automatic completion

src/dma/traits.rs Outdated Show resolved Hide resolved
src/i2c/dma.rs Outdated Show resolved Hide resolved
Copy link
Member

@therealprof therealprof left a comment

Choose a reason for hiding this comment

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

I can't really comment on the soundness of the DMA stuff but the approach looks good to me. 👍🏻

@YruamaLairba
Copy link
Contributor Author

Since i Just started to use bitflag, i wonder if i should use it for all structure containing a set of boolean to keep coherence

@YruamaLairba
Copy link
Contributor Author

crap, i missed the annoying "from_bits_retain" method in bitflags. This make my code unsound :(

@YruamaLairba
Copy link
Contributor Author

@burrbull is it ok ? i think there may a lack of coherency with flags, but i found bitflag! a bit deceiving. The "from_bit_retain" method have disastrous consequence, and using the "Flag::A|Flag::B|Flag::C" is actually very verbose with concrete case:
"DmaCommonInterrupt::TRANSFER_COMPLETE|DmaCommonInterrupt::HALF_TRANSFER ..."

@burrbull
Copy link
Contributor

ok lets leave bitflags for another PR.

@YruamaLairba
Copy link
Contributor Author

@burrbull i already commited thing using bitflags

@YruamaLairba
Copy link
Contributor Author

i may exaggerated a bit with "disastrous consequence" since i fixed the unsoundness. But i still think "from_bits_retain" is bad because of consequence it can have.

@burrbull burrbull mentioned this pull request Jul 18, 2023
@burrbull
Copy link
Contributor

@YruamaLairba could you look at/test #673 ?

@YruamaLairba
Copy link
Contributor Author

@burrbull what is missing to merge this PR ? do wait for having a good system to manipulate a set of flags ?

@burrbull
Copy link
Contributor

@burrbull what is missing to merge this PR ? do wait for having a good system to manipulate a set of flags ?

I'm fine to leave bit flags for some future PR.

But I don't see sense in duplicates (like DmaCommonInterrupts and DmaCommonInterrupts). It's confusing.
Or both DmaFlags and DmaCommonInterrupts are structs for read and write or both are bit flags.
Remove DmaCommonInterruptsMask.

@YruamaLairba
Copy link
Contributor Author

So finally, i should just ignore what you did in the Flags branch and use structure with boolean field to manipulate several interrupts or flags at once ?

@burrbull
Copy link
Contributor

So finally, i should just ignore what you did in the Flags branch and use structure with boolean field to manipulate several interrupts or flags at once ?

Yes

@YruamaLairba
Copy link
Contributor Author

done; i also changed clear_all_flags(&mut self) by clear_flags(&mut self, flags:DmaFlags) and added some all() method to structure

@burrbull
Copy link
Contributor

Ok. I'll merge this after fix release #674

@burrbull
Copy link
Contributor

burrbull commented Jul 25, 2023

Add to CHANGELOG.md, please and rebase

@YruamaLairba
Copy link
Contributor Author

Is it ok or a squash is required ?

@burrbull
Copy link
Contributor

better to squash

add stream methods to set pincos, circ and pfctrl

make Stream use dmaDirection instead generic direction

make streams use a new DmaChannel enum instead generic stuff

conditionnel compilation for DmaChannel enum

Redesign ISR API of Stream, this break transfer

redesign Stream trait API, break even more stuff

implement Stream trait, many thing still broken

fix most compile error in Transfer struct

handle DmaDataSize relatd stuff

stream_disable utility function

use utility function for gracefully disable the transfer

add/fix interrupt flag manipulation throught transfer type

fix Bits impl for PeeripeheralIncrmentOffset

fix bit impl of DmaFlowcontreoller

fix missing unsafe section

fix i2c dma to handle transfer API change.

use Dmaflag for more expressive API

dma common interrupts setter & getter

fix spi-dma example

fix rtic-spi-slave-dma.rs example

fix bad link in the doc

add number_of_transfer method on Transfer

fix an example

dma API, rename clear_smth_flag to clear_smth

dma stream rename smth_flag -> is_smth

dma stream rename set_smth_interrupt to listen/unlisten_smth, temporaly
break transfer

dma stream: listen/unlisten using mask, fix previous break

fix, using bitflags for masking require to "truncate"

some optimisation

oops forgot to remove a TODO mark

remove bitflags and mask stuff, use struct with bool field instead

update CHANGELOG.md
@YruamaLairba
Copy link
Contributor Author

squashed

@burrbull burrbull enabled auto-merge July 29, 2023 18:03
@burrbull burrbull added this pull request to the merge queue Jul 29, 2023
Merged via the queue into stm32-rs:master with commit d0f38e4 Jul 29, 2023
23 checks passed
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.

3 participants