Best practices for board definitions

Hi,

I am wondering what are the best practices to define pin outs and general board configurations in Rust.

In C projects it's pretty common to have a header file with these sort of definitions:

#define UART_RX_PIN				6
#define UART_TX_PIN				5

#define I2C_SDA_PIN				3
#define I2C_SCL_PIN				8

which are then used elsewhere in the project.

Is it possible to do something like this in Rust, compatible with the embedded-hal crates? If not, what do people usually do to define the hardware in a single place? Every project I've seen so far has everything crammed into the first lines of main.

I tend to use typedefs for this, though it's not a full solution since you still need to do intialisation elsewhere

But something like this at least

type Uart = hal::Serial<pac::UART1, gpioa::PA0, gpioa::PA1>
type I2c = hal::I2C<pac::I2C1, gpiob::Pb5, gpiob::PB6>
1 Like

I see. Have you seen how other people deal with this in their projects?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.