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

Additional Features for USART Setup Function #4

Open
nixpulvis opened this issue Jul 26, 2020 · 0 comments
Open

Additional Features for USART Setup Function #4

nixpulvis opened this issue Jul 26, 2020 · 0 comments

Comments

@nixpulvis
Copy link

nixpulvis commented Jul 26, 2020

I'm trying to implement a USART setup function I had from C:

void uart_init(void) {
  UBRR0H = UBRRH_VALUE;
  UBRR0L = UBRRL_VALUE;
#if USE_2X
  // Double transmission speed.
  UCSR0A |= _BV(U2X0);
#else
  // Not double transmission speed.
  UCSR0A &= ~(_BV(U2X0));
#endif
  // 8-bit data.
  UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
  // Enable RX and TX.
  UCSR0B = _BV(RXEN0) | _BV(TXEN0);

  // The UART io.
  static FILE uart_io = FDEV_SETUP_STREAM(uart_put, uart_get, _FDEV_SETUP_RW);

  // Set this UART as stdout and stdin.
  stdout = &uart_io;
  stdin = &uart_io;
}

Seems like I need UBRRH_VALUE, UBRRL_VALUE from util/setbaud.h, which seems blacklisted to avoid preprocessor stuff.

libc/build.rs

Line 21 in 22322e0

"util/setbaud.h", // mostly made of preprocessor magic

It would be great if we could use things like cfg(USE_2X) (or something) to control this. Or is this possible somehow already?

Additionally, the IO hook fdev_setup_stream creates a stream I have set to STDIN and STDOUT, which would be nice to replicate. But the *io also seems blacklisted.

libc/build.rs

Line 139 in 22322e0

if stem.to_str().unwrap().starts_with("io") {

I'm not sure how the Rust AVR library organization is being planned, so this may be in the wrong place.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant