FactbirdHQ / ublox-cellular-rs

A driver crate for the entire u-blox cellular family in Rust
21 stars 10 forks source link

Replace embedded-time with fugit #54

Closed andresv closed 2 years ago

andresv commented 2 years ago

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.

andresv commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 🥲

andresv commented 2 years ago

Clock trait now comes from atat: https://github.com/andresv/atat/blob/use-fugit-for-timing/atat/src/lib.rs#L278-L290

MathiasKoch commented 2 years ago

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

andresv commented 2 years ago

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

andresv commented 2 years ago

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

andresv commented 2 years ago

Clock is now updated.

andresv commented 2 years ago

It makes most sense if Format is implemented for fugit types: https://github.com/korken89/fugit/issues/6

andresv commented 2 years ago

Linux example builds now: https://github.com/andresv/ublox-cellular-rs/blob/replace-embedded-time-with-fugit/examples/linux/src/main.rs

MathiasKoch commented 2 years ago

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

andresv commented 2 years ago

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

andresv commented 2 years ago

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 commented 2 years ago

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

MathiasKoch commented 2 years ago

No problem :+1: 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 :christmas_tree:

andresv commented 2 years ago

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 commented 2 years ago

https://github.com/BlackbirdHQ/atat/pull/113 merged

andresv commented 2 years ago

Updated, but waiting for new atat release: https://github.com/BlackbirdHQ/atat/issues/116.

MathiasKoch commented 2 years ago

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

Just want to check if https://github.com/BlackbirdHQ/atat/pull/115 makes any significant code-size changes first

MathiasKoch commented 2 years ago

atat v0.15.0 & ublox-sockets v0.2.0 released :tada:

MathiasKoch commented 2 years ago

Merged here: https://github.com/BlackbirdHQ/ublox-cellular-rs/pull/57