From 21e326829b209359ef4f77f222c8cd2708e11c1f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 20 Mar 2024 23:09:14 -0300 Subject: [PATCH] lora examples compiling, but gps is fudged and needs work, and does not compile on stm32f4xx because of serial resd problem. --- dev-testing/Cargo.toml | 6 ++++- examples/radio-sx127x/lora_spi_gps.rs | 33 +++++++++++------------ examples/radio-sx127x/lora_spi_receive.rs | 20 +++++--------- examples/radio-sx127x/lora_spi_send.rs | 15 +---------- src/lora_spi_gps_usart.rs | 6 ++--- 5 files changed, 32 insertions(+), 48 deletions(-) diff --git a/dev-testing/Cargo.toml b/dev-testing/Cargo.toml index 7327a7a..7076662 100644 --- a/dev-testing/Cargo.toml +++ b/dev-testing/Cargo.toml @@ -150,7 +150,11 @@ fugit = { version = "0.3.3", optional = true } #radio-sx127x = { git = "https://github.com/rust-iot/rust-radio-sx127x", default-features = false } #radio-sx127x = { version = "0.14.0", default-features = false } #radio = { version = "0.11.0" } -radio = { git = "https://github.com/rust-iot/radio-hal" } # eh-1 + +# NB seems important to use the same version of radio that is used by radio-sx127x + +radio = { version = "0.11.1", git = "https://github.com/rust-iot/radio-hal", rev = "7aade85b61c08161bf3422f7d148417bd38ecdc2" } +#radio = { git = "https://github.com/rust-iot/radio-hal" } # eh-1 radio-sx127x = { git = "https://github.com/matheo-lucak/rust-radio-sx127x", default-features = false } # check: diff dev-testing/Cargo.toml release-testing/Cargo.toml diff --git a/examples/radio-sx127x/lora_spi_gps.rs b/examples/radio-sx127x/lora_spi_gps.rs index 765d8cb..77bb456 100644 --- a/examples/radio-sx127x/lora_spi_gps.rs +++ b/examples/radio-sx127x/lora_spi_gps.rs @@ -14,12 +14,8 @@ use panic_halt as _; use cortex_m_rt::entry; use cortex_m_semihosting::*; -use nb::block; - -//use e_h_1a::delay::blocking::DelayUs; use embedded_hal::delay::DelayNs; - -use embedded_hal::serial::Read; +use embedded_io::{Read}; use radio::Transmit; @@ -39,9 +35,11 @@ fn main() -> ! { buffer.clear(); buf2.clear(); + let mut received: [u8; 80] = [0; 80]; + //hprintln!("going into write/read loop ^C to exit ...").unwrap(); - let e: u8 = 9; // replace char errors with "9" + //let e: u8 = 9; // replace char errors with "9" let mut good = false; // true while capturing a line //let mut size: usize; // buffer size should not be needed @@ -50,10 +48,17 @@ fn main() -> ! { hprintln!("entering transmit loop").unwrap(); loop { - let byte = match block!(rx_gps.read()) { - Ok(byt) => byt, - Err(_error) => e, - }; + let _len = rx_gps.read(&mut received); //stm32f4xx_hal fails here with + //method not found in `Rx` + //see https://github.com/stm32-rs/stm32f4xx-hal/issues/721 + + //let byte = match block!(rx_gps.read()) { + // Ok(byt) => byt, + // Err(_error) => e, + //}; + + // LOGIC OF THIS NEEDS FIXING + let byte = 1; //FAKE if byte == 36 { // $ is 36. start of a line @@ -128,13 +133,7 @@ fn main() -> ! { buffer.clear(); buf2.clear(); good = false; - match lora.delay_ms(5000u32) { - Ok(b) => b, // b is () - Err(_err) => { - hprintln!("Error returned from lora.try_delay_ms().").unwrap(); - panic!("should reset in release mode."); - } - }; + lora.delay_ms(5000); }; }; } diff --git a/examples/radio-sx127x/lora_spi_receive.rs b/examples/radio-sx127x/lora_spi_receive.rs index ce11bdb..7fc040e 100644 --- a/examples/radio-sx127x/lora_spi_receive.rs +++ b/examples/radio-sx127x/lora_spi_receive.rs @@ -14,7 +14,7 @@ use panic_halt as _; use cortex_m_rt::entry; use cortex_m_semihosting::*; -use e_h_1a::delay::blocking::DelayUs; +use embedded_hal::delay::DelayNs; use radio::Receive; use radio_sx127x::prelude::PacketInfo; @@ -36,8 +36,8 @@ fn main() -> ! { lora.start_receive().unwrap(); // should handle error let mut buff = [0u8; 1024]; - let mut n: usize; - let mut info = PacketInfo::default(); + let mut n: (usize, PacketInfo); + //let mut info = PacketInfo::default(); loop { let poll = lora.check_receive(false); @@ -46,11 +46,11 @@ fn main() -> ! { match poll { Ok(v) if v => { - n = lora.get_received(&mut info, &mut buff).unwrap(); + n = lora.get_received(&mut buff).unwrap(); //hprintln!("RX complete ({:?}, length: {})", info, n).unwrap(); - //hprintln!("{:?}", &buff[..n]).unwrap(); + //hprintln!("{:?}", &buff[..n.0]).unwrap(); // for some reason the next prints twice? - hprintln!("{}", to_str(&buff[..n])).unwrap() + hprintln!("{}", to_str(&buff[..n.0])).unwrap() } Ok(_v) => (), // hprint!(".").unwrap(), // print "." if nothing received @@ -58,12 +58,6 @@ fn main() -> ! { Err(err) => hprintln!("poll error {:?} ", err).unwrap(), }; - match lora.delay_ms(100u32) { - Ok(b) => b, // b is () - Err(_err) => { - hprintln!("Error returned from lora.try_delay_ms().").unwrap(); - panic!("should reset in release mode."); - } - }; + lora.delay_ms(100); } } diff --git a/examples/radio-sx127x/lora_spi_send.rs b/examples/radio-sx127x/lora_spi_send.rs index 2681076..b38d88c 100644 --- a/examples/radio-sx127x/lora_spi_send.rs +++ b/examples/radio-sx127x/lora_spi_send.rs @@ -39,13 +39,6 @@ // 'CH_13_868': 866.10, 'CH_14_868': 866.40, 'CH_15_868': 866.70, // 'CH_16_868': 867 , 'CH_17_868': 868 , -// The embedded_hal_compat crate is to smooth the transition for hal crates that are -// not yet based on embedded_hal 1.0.0-alpha while rust-radio-sx127x is. -// When passing the older hal crate objects to the newer rust-radio-sx127x methods -// the objects are appended with .forward(). - -// Development work on extensions are in repository https://github.com/pdgilbert/LoRaGPS-rust/ - #![no_std] #![no_main] @@ -114,12 +107,6 @@ fn main() -> ! { } }; - match lora.delay_ms(5000u32) { - Ok(b) => b, // b is () - Err(_err) => { - hprintln!("Error returned from lora.try_delay_ms().").unwrap(); - panic!("should reset in release mode."); - } - }; + lora.delay_ms(5000); } } diff --git a/src/lora_spi_gps_usart.rs b/src/lora_spi_gps_usart.rs index ae7fc8d..9048d0a 100644 --- a/src/lora_spi_gps_usart.rs +++ b/src/lora_spi_gps_usart.rs @@ -50,7 +50,7 @@ pub trait LED: OutputPin { // see The Rust Programming Language, section 19, Us } } -pub use crate::i2c::{setup_i2c1, I2c1Type as I2cType,}; +//use crate::i2c::{setup_i2c1, I2c1Type as I2cType,}; //use crate::delay::{Delay2Type as Delay}; @@ -75,12 +75,12 @@ use radio_sx127x::{ PayloadLength, SpreadingFactor, }, device::{Channel, Modem, PaConfig, PaSelect}, - Error as sx127xError, // Error name conflict with hals + //Error as sx127xError, // Error name conflict with hals prelude::*, // prelude has Sx127x, }; // trait needs to be in scope to find methods start_transmit and check_transmit. -use radio::{Receive, Transmit}; +pub use radio::{Receive, Transmit}; // lora and radio parameters