Skip to content
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

Uart set custom speed of 100kbs or 100000 #58

Open
alex5250 opened this issue Oct 18, 2020 · 2 comments
Open

Uart set custom speed of 100kbs or 100000 #58

alex5250 opened this issue Oct 18, 2020 · 2 comments

Comments

@alex5250
Copy link

alex5250 commented Oct 18, 2020

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");
}
 
@golemparts
Copy link
Owner

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.

@golemparts golemparts self-assigned this Feb 14, 2021
@alex5250
Copy link
Author

alex5250 commented Feb 16, 2021

Maybee this snippet of code will be helpful.
Here is also discussion of stack overflow
And one more link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Feature requests
  
Awaiting triage
Development

No branches or pull requests

2 participants