Skip to content

Commit

Permalink
lora examples compiling, but gps is fudged and needs work, and does n…
Browse files Browse the repository at this point in the history
…ot compile on stm32f4xx because of serial resd problem.
  • Loading branch information
pdgilbert committed Mar 21, 2024
1 parent ec8cc18 commit 21e3268
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 48 deletions.
6 changes: 5 additions & 1 deletion dev-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 16 additions & 17 deletions examples/radio-sx127x/lora_spi_gps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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<USART2>`
//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
Expand Down Expand Up @@ -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);
};
};
}
Expand Down
20 changes: 7 additions & 13 deletions examples/radio-sx127x/lora_spi_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -46,24 +46,18 @@ 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

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);
}
}
15 changes: 1 addition & 14 deletions examples/radio-sx127x/lora_spi_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/lora_spi_gps_usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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

Expand Down

0 comments on commit 21e3268

Please sign in to comment.