Uart set custom speed of 100kbs or 100000
azaslavskis opened this issue · 2 comments
Using the S Bus protocol it required to use speed of 10000bps. Quick look in lib code make sure that all speeds are settings by macro. It will great to opportunity to add custom speeds in lib. Is it possible?
Uart::with_path("/dev/ttyAMA0", 100000, Parity::Even, 8, 2).expect("COULD SET UART");
Gives me error
thread 'main' panicked at 'COULD SET UART: InvalidValue', src/main.rs:8:69
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
All code
use rppal::uart::{Parity, Uart};
use std::time::Duration;
fn main() {
let mut uart =
Uart::with_path("/dev/ttyAMA0", 1000000, Parity::Even, 8, 2).expect("COULD SET UART");
uart.set_read_mode(1, Duration::default())
.expect("COULD SET UART MODE");
}
Thanks for the suggestion. Unfortunately this is a limitation of the underlying termios
functions cfsetispeed()
and cfsetospeed()
which are used to set the speed, and only support the currently available values. termios2
does support custom speeds, but isn't officially supported for musl
targets, which would cause incompatibility issues depending on which libc
is used. However, since things may have changed since I last worked on the uart code, I'll take another look after 0.12.0 has been released.