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

The PD mini's PIO UART. More...

#include "pd_uart.h"
#include "hardware/gpio.h"
#include "hardware/clocks.h"
#include "hardware/pio.h"
#include "pd_uart.pio.h"

Data Structures

struct  [struct].s
 Driver state of the UART: the claimed machines and the pins. More...

Functions

static void rest (uint8_t pin)
 A pin at rest: an input with a pull-down, driven by nothing here.
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_close (void)
 Release them; the pins stay at rest.
static void reset_machines (void)
 Both machines stopped, emptied and back at their first instruction.
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_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.

Variables

static struct  s

Detailed Description

The PD mini's PIO UART.

See pd_uart.h.

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.

◆ rest()

void rest ( uint8_t pin)
static

A pin at rest: an input with a pull-down, driven by nothing here.

Parameters
pinGPIO number.