diff --git a/dev-testing/Cargo.toml b/dev-testing/Cargo.toml index e0390ae..f337f0d 100644 --- a/dev-testing/Cargo.toml +++ b/dev-testing/Cargo.toml @@ -163,8 +163,13 @@ fugit = { version = "0.3.3", optional = true } #radio-sx127x = { git = "https://github.com/rust-iot/rust-radio-sx127x", default-features = false } # these two work together -radio = { version = "0.11.1", git = "https://github.com/rust-iot/radio-hal", rev = "7aade85b61c08161bf3422f7d148417bd38ecdc2" } -radio-sx127x = { git = "https://github.com/matheo-lucak/rust-radio-sx127x", default-features = false } +#radio = { version = "0.11.1", git = "https://github.com/rust-iot/radio-hal", rev = "7aade85b61c08161bf3422f7d148417bd38ecdc2" } +#radio-sx127x = { git = "https://github.com/matheo-lucak/rust-radio-sx127x", default-features = false } + + +# This radio-sx127 re-exports {Receive, Transmit} so looks after getting correct radio version. +radio-sx127x = { git = "https://github.com/pdgilbert/rust-radio-sx127x", default-features = false, branch = "ehal-1" } +#radio-sx127x = { path = "...rust-radio-sx127x", default-features = false } # not used yet #radio-sx1231 = { git = "https://github.com/rust-io/rust-radio-sx1231", default-features = false } diff --git a/examples/misc/spi.rs b/examples/misc/spi.rs index 574de5c..6e939c0 100644 --- a/examples/misc/spi.rs +++ b/examples/misc/spi.rs @@ -260,9 +260,10 @@ fn setup() -> ( #[cfg(feature = "stm32g4xx")] use stm32g4xx_hal::{ gpio::{gpioa::PA8, Output, PushPull}, - stm32::{Peripherals, SPI1}, + pac::{Peripherals, SPI1}, prelude::*, spi::{Pins, Spi, MODE_0}, + time::{RateExtU32}, }; #[cfg(feature = "stm32g4xx")] @@ -282,7 +283,7 @@ fn setup() -> ( gpioa.pa7.into_alternate(), // mosi on PA7 ), MODE_0, - 400.khz(), + 400.kHz(), &mut rcc, ); diff --git a/examples/radio-sx127x/lora_spi_gps.rs b/examples/radio-sx127x/lora_spi_gps.rs index c6cd4c8..f9d8a79 100644 --- a/examples/radio-sx127x/lora_spi_gps.rs +++ b/examples/radio-sx127x/lora_spi_gps.rs @@ -17,7 +17,8 @@ use cortex_m_semihosting::*; use embedded_hal::delay::DelayNs; use embedded_io::{Read}; -use radio::Transmit; +//use radio::Transmit; +use radio_sx127x::Transmit; use radio_sx127x::{ //Error as sx127xError, // Error name conflict with hals diff --git a/examples/radio-sx127x/lora_spi_receive.rs b/examples/radio-sx127x/lora_spi_receive.rs index dd2f52f..63877fa 100644 --- a/examples/radio-sx127x/lora_spi_receive.rs +++ b/examples/radio-sx127x/lora_spi_receive.rs @@ -16,7 +16,8 @@ use cortex_m_semihosting::*; use embedded_hal::delay::DelayNs; -use radio::Receive; +//use radio::Receive; +use radio_sx127x::Receive; use radio_sx127x::{ //Error as sx127xError, // Error name conflict with hals diff --git a/examples/radio-sx127x/lora_spi_send.rs b/examples/radio-sx127x/lora_spi_send.rs index 29f1e92..bbbe34e 100644 --- a/examples/radio-sx127x/lora_spi_send.rs +++ b/examples/radio-sx127x/lora_spi_send.rs @@ -1,11 +1,11 @@ //! Transmit a simple message with LoRa using crate radio_sx127x (on SPI). //! -//! The setup() functions make the application code common. They are in src/lora.rs. +//! The setup() functions make the application code common. They are in src/setup_all*. //! The specific function used will depend on the HAL setting (see README.md). -//! See the section of setup() corresponding to the HAL setting for details on pin connections. +//! See the setup() corresponding to the HAL for details on pin connections. //! The setup is using sck, miso, mosi, cs, reset and D00, D01. Not yet using D02, D03 //! -//! The same setup() function is used for examples lora_spi_send, lora_spi_receive, and +//! The same setup function is used for examples lora_spi_send, lora_spi_receive, and //! lora_spi_gps (if the HAL setting is the same). The following is for all examples. //! //! See FREQUENCY in src/lora.rs to set the channel. @@ -39,6 +39,10 @@ // 'CH_13_868': 866.10, 'CH_14_868': 866.40, 'CH_15_868': 866.70, // 'CH_16_868': 867 , 'CH_17_868': 868 , +// Errata https://semtech.my.salesforce.com/sfc/p/#E0000000JelG/a/2R000000HSPv/sqi9xX0gs6hgzl2LoPwCK0TS9GDPlMwsXmcNzJCMHjw +// Semtec stores value 0x12 at address 0x42 to indicate version V1b. +// V1a was pre-production engineering samples + #![no_std] #![no_main] @@ -54,7 +58,8 @@ use cortex_m_semihosting::*; use embedded_hal::delay::DelayNs; -use radio::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit. +//use radio::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit. +use radio_sx127x::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit. use radio_sx127x::{ //Error as sx127xError, // Error name conflict with hals @@ -77,24 +82,38 @@ fn main() -> ! { let (mut led, spi, spiext, delay) = setup::led_spi_spiext_delay_from_dp(dp); led.off(); - let mut lora = Sx127x::spi(spi, spiext.cs, spiext.busy, spiext.ready, spiext.reset, delay, &CONFIG_RADIO - ).unwrap(); // should handle error //delay is available in lora - + let lora = Sx127x::spi(spi, spiext.cs, spiext.busy, spiext.ready, spiext.reset, delay, + &CONFIG_RADIO ); + + let mut lora = match lora { + Ok(lr) => { hprintln!("lora setup completed.").unwrap(); + lr } + Err(e) => { hprintln!("Error in lora setup. {:?}", e).unwrap(); + panic!("{:?}", e) } + }; + + //let mut lora = lora.unwrap(); + + //delay is available in lora + + + // print out configuration (for debugging) - // let v = lora.lora_get_config(); - // hprintln!("configuration {}", v).unwrap(); - - // hprintln!("chammel {}", lora.get_chammel()).unwrap(); - - //hprintln!("mode {}", lora.get_mode()).unwrap(); - //hprintln!("mode {}", lora.read_register(Register::RegOpMode.addr())).unwrap(); - //hprintln!("bandwidth {:?}", lora.get_signal_bandwidth()).unwrap(); - //hprintln!("coding_rate {:?}", lora.get_coding_rate_4()).unwrap(); - //hprintln!("spreading_factor {:?}", lora.get_spreading_factor()).unwrap(); - //hprintln!("spreading_factor {:?}", - //hprintln!("invert_iq {:?}", lora.get_invert_iq()).unwrap(); - //hprintln!("tx_power {:?}", lora.get_tx_power()).unwrap(); + // use radio_sx127x::device::regs::Register; + // + // let v = lora.lora_get_config(); + // hprintln!("configuration {}", v).unwrap(); + // + // hprintln!("channel {}", lora.get_channel()).unwrap(); + // + // hprintln!("mode {}", lora.get_mode()).unwrap(); + // hprintln!("mode {}", lora.read_register(Register::RegOpMode.addr())).unwrap(); + // hprintln!("bandwidth {:?}", lora.get_signal_bandwidth()).unwrap(); + // hprintln!("coding_rate {:?}", lora.get_coding_rate_4()).unwrap(); + // hprintln!("spreading_factor {:?}", lora.get_spreading_factor()).unwrap(); + // hprintln!("invert_iq {:?}", lora.get_invert_iq()).unwrap(); + // hprintln!("tx_power {:?}", lora.get_tx_power()).unwrap(); // transmit something @@ -108,20 +127,20 @@ fn main() -> ! { // } loop { - lora.start_transmit(message).unwrap(); // should handle error + match lora.start_transmit(message) { + Ok(_b) => { hprintln!("start_transmit").unwrap() } + Err(_e) => { hprintln!("Error in lora.start_transmit()").unwrap() } + }; - match lora.check_transmit() { - Ok(b) => { - if b { - hprintln!("TX complete").unwrap() - } else { - hprintln!("TX not complete").unwrap() - } - } + lora.delay_ms(1); // without some delay next returns bad. (interrupt may also be an option) - Err(_err) => { + match lora.check_transmit() { + Ok(b) => {if b {hprintln!("TX good").unwrap() } + else {hprintln!("TX bad").unwrap() } + } + Err(_e) => { hprintln!("Error in lora.check_transmit(). Should return True or False.").unwrap() - } + } }; lora.delay_ms(5000); diff --git a/src/PinMap.txt b/src/PinMap.txt index 31960a3..3c0e242 100644 --- a/src/PinMap.txt +++ b/src/PinMap.txt @@ -140,8 +140,8 @@ PA7 mosi gpioa.pa7.into_alternate(), // mosi ), MODE_0, 400.kHz(), &mut rcc, ); PA11 CsPin Sx127x gpioa.pa11.into_push_pull_output(), //CsPin -PB4 BusyPin gpiob.pb8.into_floating_input(), //BusyPin DI00 CHANGED -PB5 ReadyPin gpiob.pb9.into_floating_input(), //ReadyPin DI01 CHANGED +PB4 BusyPin gpiob.pb4.into_floating_input(), //BusyPin DI00 +PB5 ReadyPin gpiob.pb5.into_floating_input(), //ReadyPin DI01 PA0 ResetPin gpioa.pa0.into_push_pull_output(), //ResetPin delay, &CONFIG_RADIO, ).unwrap(); // should handle error diff --git a/src/lora.rs b/src/lora.rs index bdb2bd1..1c1fa8c 100644 --- a/src/lora.rs +++ b/src/lora.rs @@ -38,7 +38,8 @@ use radio_sx127x::{ }; // trait needs to be in scope to find methods start_transmit and check_transmit. -pub use radio::{Receive, Transmit}; +//pub use radio::{Receive, Transmit}; +pub use radio_sx127x::{Receive, Transmit}; // lora and radio parameters