Skip to content

Commit

Permalink
Merge pull request #20108 from benpicco/drivers/dose-uart_ondemand_tx
Browse files Browse the repository at this point in the history
drivers/periph/uart: add periph_uart_tx_ondemand feature
  • Loading branch information
benpicco authored Dec 14, 2023
2 parents 75c27f8 + 9cde80e commit 208790a
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions cpu/sam0_common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ config CPU_COMMON_SAM0
select HAS_PERIPH_UART_NONBLOCKING
select HAS_PERIPH_UART_RECONFIGURE
select HAS_PERIPH_UART_RXSTART_IRQ
select HAS_PERIPH_UART_TX_ONDEMAND
select HAS_PERIPH_WDT
select HAS_PERIPH_WDT_CB
select HAS_PERIPH_WDT_WARNING_PERIOD
Expand Down
1 change: 1 addition & 0 deletions cpu/sam0_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FEATURES_PROVIDED += periph_uart_modecfg
FEATURES_PROVIDED += periph_uart_nonblocking
FEATURES_PROVIDED += periph_uart_reconfigure
FEATURES_PROVIDED += periph_uart_rxstart_irq
FEATURES_PROVIDED += periph_uart_tx_ondemand
FEATURES_PROVIDED += periph_wdt periph_wdt_cb periph_wdt_warning_period

FEATURES_CONFLICT += periph_rtc:periph_rtt
Expand Down
1 change: 1 addition & 0 deletions cpu/sam0_common/include/periph_cpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ typedef enum {
UART_FLAG_NONE = 0x0, /**< No flags set */
UART_FLAG_RUN_STANDBY = 0x1, /**< run SERCOM in standby mode */
UART_FLAG_WAKEUP = 0x2, /**< wake from sleep on receive */
UART_FLAG_TX_ONDEMAND = 0x4, /**< Only enable TX pin on demand */
} uart_flag_t;

#ifndef DOXYGEN
Expand Down
19 changes: 18 additions & 1 deletion cpu/sam0_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ static void _set_baud(uart_t uart, uint32_t baudrate, uint32_t f_src)
#endif
}

void uart_enable_tx(uart_t uart)
{
/* configure RX pin */
if (uart_config[uart].tx_pin != GPIO_UNDEF) {
gpio_init_mux(uart_config[uart].tx_pin, uart_config[uart].mux);
}
}

void uart_disable_tx(uart_t uart)
{
/* configure RX pin */
if (uart_config[uart].tx_pin != GPIO_UNDEF) {
gpio_init_mux(uart_config[uart].tx_pin, GPIO_MUX_A);
}
}

static void _configure_pins(uart_t uart)
{
/* configure RX pin */
Expand All @@ -138,7 +154,8 @@ static void _configure_pins(uart_t uart)
}

/* configure TX pin */
if (uart_config[uart].tx_pin != GPIO_UNDEF) {
if (uart_config[uart].tx_pin != GPIO_UNDEF &&
!(uart_config[uart].flags & UART_FLAG_TX_ONDEMAND)) {
gpio_set(uart_config[uart].tx_pin);
gpio_init(uart_config[uart].tx_pin, GPIO_OUT);
gpio_init_mux(uart_config[uart].tx_pin, uart_config[uart].mux);
Expand Down
9 changes: 8 additions & 1 deletion drivers/dose/dose.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@ static void state(dose_t *ctx, dose_signal_t signal)
signal = state_transit_send(ctx, signal);
ctx->state = DOSE_STATE_SEND;
break;

default:
DEBUG("dose state(): unexpected state transition (STATE=0x%02x SIGNAL=0x%02x)\n", ctx->state, signal);

Check warning on line 321 in drivers/dose/dose.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
/* fall-through */
case DOSE_STATE_RECV + DOSE_SIGNAL_SEND:
signal = DOSE_SIGNAL_NONE;
}
} while (signal != DOSE_SIGNAL_NONE);
Expand Down Expand Up @@ -503,6 +504,9 @@ static int send_data_octet(dose_t *ctx, uint8_t c)

static inline void _send_start(dose_t *ctx)
{
#ifdef MODULE_PERIPH_UART_TX_ONDEMAND
uart_enable_tx(ctx->uart);
#endif
#ifdef MODULE_PERIPH_UART_COLLISION
uart_collision_detect_enable(ctx->uart);
#else
Expand All @@ -512,6 +516,9 @@ static inline void _send_start(dose_t *ctx)

static inline void _send_done(dose_t *ctx, bool collision)
{
#ifdef MODULE_PERIPH_UART_TX_ONDEMAND
uart_disable_tx(ctx->uart);
#endif
#ifdef MODULE_PERIPH_UART_COLLISION
uart_collision_detect_disable(ctx->uart);
if (collision) {
Expand Down
18 changes: 18 additions & 0 deletions drivers/include/periph/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,24 @@ void uart_poweron(uart_t uart);
*/
void uart_poweroff(uart_t uart);

/**
* @brief Enable the TX line one the given UART
*
* @note requires the `periph_uart_tx_ondemand` feature
*
* @param[in] uart the UART device start TX on
*/
void uart_enable_tx(uart_t uart);

/**
* @brief Disable the TX line one the given UART
*
* @note requires the `periph_uart_tx_ondemand` feature
*
* @param[in] uart the UART device to stop TX on
*/
void uart_disable_tx(uart_t uart);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions drivers/soft_uart/include/soft_uart_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef SOFT_UART_PARAMS_H
#define SOFT_UART_PARAMS_H

#include "board.h"
#include "soft_uart.h"
#include "macros/units.h"
#include "kernel_defines.h"
Expand Down
5 changes: 5 additions & 0 deletions kconfigs/Kconfig.features
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ config HAS_PERIPH_UART_MODECFG
help
Indicates that the UART peripheral allows mode configuration.

config HAS_PERIPH_UART_TX_ONDEMAND
bool
help
Indicates that the UART peripheral can enable the TX line on demmand.

config HAS_PERIPH_UART_NONBLOCKING
bool
help
Expand Down

0 comments on commit 208790a

Please sign in to comment.