rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
pd_uart.h File Reference

The PD mini's UART on two PIO (programmable input/output) state machines, on whichever two pins the caller names. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

bool pd_uart_open (uint8_t tx, uint8_t rx, uint32_t baud)
 Claim the state machines for tx and rx at baud.
void pd_uart_baud (uint32_t baud)
 Another rate for both machines, between transactions only: nothing happens while the UART is attached.
void pd_uart_close (void)
 Release them; the pins stay at rest.
void pd_uart_attach (void *ctx)
 Attach the UART to the pins for one transaction.
void pd_uart_detach (void *ctx)
 Detach the UART; the pins go back to pulled-down inputs.
void pd_uart_send (void *ctx, const uint8_t *p, size_t n)
 Send bytes on the attached UART.
bool pd_uart_getc (uint8_t *b)
 A received byte, or false for none.

Detailed Description

The PD mini's UART on two PIO (programmable input/output) state machines, on whichever two pins the caller names.

Implements the UART protocol of the WeAct PD Power Mini V1 Buck module. WeAct is a name or trademark of its owner; it is used here only to say which module this driver works with (NOTICE, "Trademarks").

pd_uart_open() claims the state machines and leaves the pins at rest: inputs with a pull-down. The driver attaches the UART for a transaction and detaches it after; pdmini_io_t's callbacks are the three below.

Received bytes wait in the receive machine's FIFO, 8 deep, until the main loop takes them: 4.2ms of reply at 19200 baud, 0.17ms at 460800. A pass longer than that loses bytes, and the transaction fails and is tried again. The pass time is not measured.

SPDX-License-Identifier: MIT

Function Documentation

◆ pd_uart_attach()

void pd_uart_attach ( void * ctx)

Attach the UART to the pins for one transaction.

Parameters
ctxUnused; passed by the driver's callback table.

◆ pd_uart_baud()

void pd_uart_baud ( uint32_t baud)

Another rate for both machines, between transactions only: nothing happens while the UART is attached.

Parameters
baudBaud rate.

◆ pd_uart_detach()

void pd_uart_detach ( void * ctx)

Detach the UART; the pins go back to pulled-down inputs.

Parameters
ctxUnused; passed by the driver's callback table.

◆ pd_uart_getc()

bool pd_uart_getc ( uint8_t * b)

A received byte, or false for none.

Parameters
bReceives the byte when true is returned.
Returns
true when a byte was taken from the FIFO.

◆ pd_uart_open()

bool pd_uart_open ( uint8_t tx,
uint8_t rx,
uint32_t baud )

Claim the state machines for tx and rx at baud.

False, and nothing held, when no PIO block can reach the pins or has room.

Parameters
txGPIO number of the transmit pin.
rxGPIO number of the receive pin.
baudBaud rate.
Returns
true when both state machines are claimed.

◆ pd_uart_send()

void pd_uart_send ( void * ctx,
const uint8_t * p,
size_t n )

Send bytes on the attached UART.

Parameters
ctxUnused; passed by the driver's callback table.
pBytes to send.
nNumber of bytes in p.