Skip to content

Additional Features for USART Setup Function #4

Open
@nixpulvis

Description

@nixpulvis

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions