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

Replace embedded-time with fugit #54

Closed

Conversation

andresv
Copy link
Contributor

@andresv andresv commented Nov 2, 2021

This PR replaces embedded-time with more lightweight const generics based time library called fugit which is for example going to be used in RTIC.

embedded-time had some dependencies that did not work well on ESP32, this PR fixes this particular problem.

And use ublox-sockets that support fugit time crate.
`embedded-time` has some serious issues and moves too slowly and tries to do too much in single lib. Fugit is a time library that was built because some people were not happy to use embedded-time on embedded systems.
Fugit only deals with time conversions and those conversions are done using const generics. So most of the stuff is  happening during compilation.
This is very light weight compared to embedded-time.
ublox-cellular/src/lib.rs Outdated Show resolved Hide resolved
@andresv
Copy link
Contributor Author

andresv commented Nov 3, 2021

Ahaa, I think I know why I did not see these errors. I added std to:

atat = { version = "0.13.1", features = ["std", "derive", "defmt", "bytes"] }

Edit: nope that wasn't the problem

@andresv
Copy link
Contributor Author

andresv commented Nov 3, 2021

I just realized that atat uses embedded-hal CountDown trait (https://github.com/BlackbirdHQ/atat/blob/master/atat/src/client.rs#L58), but at the moment here we are using our own Clock trait.

It would be actually better if we use CountDown also here, but we also need now() method to get current time and I guess there is also problem with time conversion. Typically CountDown is implemented for u32, but here we would like to use it more like for fugit::MillisDurationU32.

Lemme think about it some more.

@MathiasKoch
Copy link
Member

MathiasKoch commented Nov 3, 2021

Yeah . The timer stuff across the stack is not ideal, so i am very much open to solutions that would make it easier to use..

It is very much affected by the currently bad shape of the timer traits in embedded Hal.. also the requirement on into 🥲

the same is used in rtic and it is more clear what it is
@andresv
Copy link
Contributor Author

andresv commented Nov 4, 2021

@MathiasKoch
Copy link
Member

This looks amazing! Awesome job so far! Hope i can find the time to review both atat & this tomorrow 🤞👌

andresv and others added 3 commits November 4, 2021 21:32
FactbirdHQ#53)

* Make sure the embedded-nal implementations only makes use of error-types from ublox-sockets

* Add embedded-hal-driver keyword to crates.io
# Conflicts:
#	ublox-cellular/Cargo.toml
#	ublox-cellular/src/services/data/tcp_stack.rs
#	ublox-cellular/src/services/data/udp_stack.rs
@andresv
Copy link
Contributor Author

andresv commented Nov 5, 2021

Clock in atat was changed to use WouldBlock for wait. This is not yet updated here.

@andresv
Copy link
Contributor Author

andresv commented Nov 5, 2021

Hmm, I guess cherry-picking your latest commit was not right thing to do (this conflict message here).

@andresv
Copy link
Contributor Author

andresv commented Nov 5, 2021

Clock is now updated.

@andresv
Copy link
Contributor Author

andresv commented Nov 5, 2021

It makes most sense if Format is implemented for fugit types: korken89/fugit#6

@andresv
Copy link
Contributor Author

andresv commented Nov 6, 2021

@MathiasKoch
Copy link
Member

Can you update this PR to make use of atat 0.14.0 & ublox-sockets 0.1.0 releases as well?

@andresv
Copy link
Contributor Author

andresv commented Nov 9, 2021

Yes. Adding those and starting to use fmt.rs file for logging.

@andresv
Copy link
Contributor Author

andresv commented Nov 9, 2021

I wonder how to enable log or defmt feature for atat and ublox-sockets based on if log or defmt feature is selected for this crate.
For example here log is at the moment hardcoded.

[dependencies]
atat = { version = "0.14", features = ["derive", "log", "bytes"] }
ublox-sockets = { version = "0.1", features = ["log"] }

log = { version = "^0.4", default-features = false, optional = true }
defmt = { version = "^0.2", optional = true }

[features]
default = ['log", "toby-r2", "socket-udp", "socket-tcp"]

lara-r2 = []
leon-g1 = []
lisa-u2 = []
mpci-l2 = []
sara-g3 = []
sara-g4 = []
sara-u1 = []
sara-u2 = ["upsd-context-activation"]
toby-l2 = []
toby-r2 = []
topy-l4 = []

upsd-context-activation = []

socket-tcp = ["ublox-sockets/socket-tcp"]
socket-udp = ["ublox-sockets/socket-udp"]

defmt-default = ["defmt"]
defmt-trace = ["defmt"]
defmt-debug = ["defmt"]
defmt-info = ["defmt"]
defmt-warn = ["defmt"]
defmt-error = ["defmt"]

EDIT: https://stackoverflow.com/questions/61090286/cargo-toml-how-do-i-select-a-dependencys-feature-based-on-my-crates-features

@andresv
Copy link
Contributor Author

andresv commented Dec 22, 2021

FYI: this is not dropped, I am continuing with it quite soon.

@MathiasKoch
Copy link
Member

No problem 👍
I have not had a chance to replace our own embedded-time stuff with fugit yet, so i am not in a rush.. Hopefully i'll find the time in the beginning of the new year.

Let med know if you need anything from me :)

Merry Christmas 🎄

@andresv
Copy link
Contributor Author

andresv commented Jan 12, 2022

Finally back in hacking with it. At the moment I am working on SARA-N310 support.
I think actually embedded-time replacement with fugit was successful.
I can confirm if everything works if I got N310 working.

@MathiasKoch
Copy link
Member

FactbirdHQ/atat#113 merged

Copy link
Member

@MathiasKoch MathiasKoch left a comment

Choose a reason for hiding this comment

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

Would you mind updating this to embedded-hal: "^1.0.0-alpha.6" and `defmt: "^0.3", now that FactbirdHQ/atat#113 is merged?

@andresv
Copy link
Contributor Author

andresv commented Jan 24, 2022

Updated, but waiting for new atat release: FactbirdHQ/atat#116.

@MathiasKoch
Copy link
Member

Yeah, i also have a few PRs blocked on that, so it will be out during today.

Just want to check if FactbirdHQ/atat#115 makes any significant code-size changes first

@MathiasKoch
Copy link
Member

atat v0.15.0 & ublox-sockets v0.2.0 released 🎉

MathiasKoch added a commit that referenced this pull request Jan 28, 2022
* Cargo.toml: replace embedded-time with fugit

And use ublox-sockets that support fugit time crate.

* lib: introduce new Clock trait and Instant alias

* replace embedded-time with fugit

`embedded-time` has some serious issues and moves too slowly and tries to do too much in single lib. Fugit is a time library that was built because some people were not happy to use embedded-time on embedded systems.
Fugit only deals with time conversions and those conversions are done using const generics. So most of the stuff is  happening during compilation.
This is very light weight compared to embedded-time.

* rename FREQ_HZ to TIMER_HZ

the same is used in rtic and it is more clear what it is

* lib: export Clock from atat

* use Clock trait from atat lib

* examples: update common_lib to latest

* examples: linux wip

* Make sure the embedded-nal implementations only makes use of error-ty… (#53)

* Make sure the embedded-nal implementations only makes use of error-types from ublox-sockets

* Add embedded-hal-driver keyword to crates.io
# Conflicts:
#	ublox-cellular/Cargo.toml
#	ublox-cellular/src/services/data/tcp_stack.rs
#	ublox-cellular/src/services/data/udp_stack.rs

* test_helpers: update to WouldBlock based Clock

* error: add helper to convert Clock error to Error::Generic

From trait cannot be used here because Clock error is associated type

* client: use nb::block to wait for timer

* import atat from blackbirdhq master

* use fugit defmt feature to get Format impl

* linux: set_socket_storage

* add IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr to prelude

* linux example: add socket read/write

* reexport fugit

fugit is needed for implementing Clock trait therefore it makes sense to reexport it here

* add some general documentation about the crate

* make first examples buildable also on macos

on macos dummy gpio support is used

* rename linux example to sockets, add args support

* power: add nb::block! for blocking timer.waits

without those it returns immediately without blocking in place

* use atat and ublox-sockets from crates.io

* use fmt.rs to support log or defmt

* examples: add better logging

* update to embedded-hal 1.0.0-alpha.6

* add .DS_Store to .gitignore

macOS creates those nasty files

* update atat and ublox-sockets

* Update ublox-cellular/Cargo.toml

* Replace CharVec with Bytes, following deprecation warning in ATAT

* Fix tests & add defmt-impl feature

Co-authored-by: Andres Vahter <[email protected]>
Co-authored-by: Andres Vahter <[email protected]>
@MathiasKoch
Copy link
Member

Merged here: #57

@andresv andresv deleted the replace-embedded-time-with-fugit branch October 21, 2022 12:43
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