Skip to content

Implement radio traits #248

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

Closed
wants to merge 30 commits into from
Closed

Implement radio traits #248

wants to merge 30 commits into from

Conversation

Tortoaster
Copy link

This is a work in progress implementation of the radio traits for the SX126x LoRa transceiver. These traits will allow easy interoperability with crates that use radios, such as https://github.com/Tortoaster/lorawan-device.

@newAM
Copy link
Member

newAM commented Nov 25, 2021

I hope you don't mind me pushing, just wanted to run rustfmt to remove some minor formatting difference from the diff.

Copy link
Member

@newAM newAM left a comment

Choose a reason for hiding this comment

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

I guess a lot of this depends on the discussion happening in rust-iot/radio-hal#24, I'm subscribed to that PR now so I'll keep an eye on that as well 👍

@Tortoaster Tortoaster requested a review from newAM December 3, 2021 11:09
Copy link
Member

@newAM newAM left a comment

Choose a reason for hiding this comment

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

Looks good so far!


/// Timer for delays.
#[derive(Debug)]
pub struct Tim2 {
Copy link
Member

Choose a reason for hiding this comment

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

Tim2 should probably be made more general as well, that can be done later though.

Comment on lines 16 to 31
const IRQ_CFG: CfgIrq = CfgIrq::new()
.irq_enable_all(Irq::RxDone)
.irq_enable_all(Irq::Timeout)
.irq_enable_all(Irq::TxDone)
.irq_enable_all(Irq::Err);

const PREAMBLE_LEN: u16 = 5 * 8;
const TX_BUF_OFFSET: u8 = 0;
const RX_BUF_OFFSET: u8 = 128;

const PA_CONFIG: PaConfig = PaConfig::LP_10;
const TX_PARAMS: TxParams = TxParams::LP_10.set_ramp_time(RampTime::Micros40);

const TCXO_MODE: TcxoMode = TcxoMode::new()
.set_txco_trim(TcxoTrim::Volts1pt7)
.set_timeout(Timeout::from_millis_sat(10));
Copy link
Member

Choose a reason for hiding this comment

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

What is the future plan for this? Leave it opinionated, make it configurable?

I am trying to keep the HAL generic, if opinionated this file would make more sense as a separate crate as it does not depend on the private types in the HAL.

Copy link
Author

Choose a reason for hiding this comment

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

I'll see if I can make this configurable! I could include these settings in the Sx126x struct. Would default settings be acceptable (with a builder pattern), or should the user specify all settings?

Copy link
Member

Choose a reason for hiding this comment

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

I'll see if I can make this configurable! I could include these settings in the Sx126x struct. Would default settings be acceptable (with a builder pattern), or should the user specify all settings?

I generally like to set things to sane defaults, and give the user the option to modify them.

One thing I try to do is make it so configuration can be made a const, because most applications will have a static configuration that doesn't need to be changed, and it is helpful to enable const for that usecase.

Copy link
Author

Choose a reason for hiding this comment

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

I updated it, is this better? I wasn't sure what to do with TX_BUF_OFFSET and RX_BUF_OFFSET, are those configurable? Also not sure what the default CalibrateImage should be. For LoRaWAN, there is EU863-870, US902-928, CN779-787, EU433, etc.

@Tortoaster
Copy link
Author

I cannot seem to get the LoRa-E5 Dev Board to receive a Join-Accept message from The Things Network, even though the gateway that transmits it is right next to it. Do you see anything that could be wrong with the Sx126x implementation? I'm running out of ideas. 😅

@newAM
Copy link
Member

newAM commented Dec 14, 2021

Do you have some sample code I could run? I don't have a gateway nearby, but I could give it a shot.

@Tortoaster
Copy link
Author

You could try the example in this repository, but it uses the EUIs from the device on my TTN account, so you won't see much unless it actually receives the Join-Accept. I can verify if the Join-Accept is being sent, though.

@Tortoaster
Copy link
Author

Looks like I destroyed the commit order there, sorry. 😬
The good news is that it's working now, and lorawan-device too! It's still quite fragile, especially with the receive delays, but the example linked above should now work properly.

@Tortoaster Tortoaster closed this by deleting the head repository Mar 23, 2023
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