hardware flow control from nRF51
This commit is contained in:
parent
a8592bb3b1
commit
137836fb19
|
@ -52,6 +52,10 @@ static const SerialConfig default_config = {
|
||||||
.speed = 38400,
|
.speed = 38400,
|
||||||
.tx_pad = NRF51_SERIAL_PAD_DISCONNECTED,
|
.tx_pad = NRF51_SERIAL_PAD_DISCONNECTED,
|
||||||
.rx_pad = NRF51_SERIAL_PAD_DISCONNECTED,
|
.rx_pad = NRF51_SERIAL_PAD_DISCONNECTED,
|
||||||
|
#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
|
||||||
|
.rts_pad = NRF51_SERIAL_PAD_DISCONNECTED,
|
||||||
|
.cts_pad = NRF51_SERIAL_PAD_DISCONNECTED,
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -68,7 +72,6 @@ static const SerialConfig default_config = {
|
||||||
*/
|
*/
|
||||||
static void configure_uart(const SerialConfig *config)
|
static void configure_uart(const SerialConfig *config)
|
||||||
{
|
{
|
||||||
/* TODO: Add support for CTS/RTS! */
|
|
||||||
uint32_t speed = UART_BAUDRATE_BAUDRATE_Baud250000;
|
uint32_t speed = UART_BAUDRATE_BAUDRATE_Baud250000;
|
||||||
|
|
||||||
switch (config->speed) {
|
switch (config->speed) {
|
||||||
|
@ -100,6 +103,16 @@ static void configure_uart(const SerialConfig *config)
|
||||||
palSetPadMode(IOPORT1, config->rx_pad, PAL_MODE_INPUT);
|
palSetPadMode(IOPORT1, config->rx_pad, PAL_MODE_INPUT);
|
||||||
NRF_UART0->PSELRXD = config->rx_pad;
|
NRF_UART0->PSELRXD = config->rx_pad;
|
||||||
}
|
}
|
||||||
|
#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
|
||||||
|
if (config->rts_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
|
||||||
|
palSetPadMode(IOPORT1, config->rts_pad, PAL_MODE_OUTPUT_PUSHPULL);
|
||||||
|
NRF_UART0->PSELRTS = config->rts_pad;
|
||||||
|
}
|
||||||
|
if (config->cts_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
|
||||||
|
palSetPadMode(IOPORT1, config->cts_pad, PAL_MODE_INPUT);
|
||||||
|
NRF_UART0->PSELCTS = config->cts_pad;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
NRF_UART0->BAUDRATE = speed;
|
NRF_UART0->BAUDRATE = speed;
|
||||||
NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
|
NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
|
||||||
|
@ -107,10 +120,21 @@ static void configure_uart(const SerialConfig *config)
|
||||||
NRF_UART0->EVENTS_RXDRDY = 0;
|
NRF_UART0->EVENTS_RXDRDY = 0;
|
||||||
NRF_UART0->EVENTS_TXDRDY = 0;
|
NRF_UART0->EVENTS_TXDRDY = 0;
|
||||||
|
|
||||||
|
#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
|
||||||
|
if ((config->rts_pad < TOTAL_GPIO_PADS) ||
|
||||||
|
(config->cts_pad < TOTAL_GPIO_PADS)) {
|
||||||
|
NRF_UART0->CONFIG |= UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos;
|
||||||
|
} else {
|
||||||
|
NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
|
||||||
|
}
|
||||||
|
NRF_UART0->PSELRTS = config->rts_pad;
|
||||||
|
NRF_UART0->PSELCTS = config->cts_pad;
|
||||||
|
#else
|
||||||
NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
|
NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
|
||||||
|
|
||||||
NRF_UART0->PSELRTS = NRF51_SERIAL_PAD_DISCONNECTED;
|
NRF_UART0->PSELRTS = NRF51_SERIAL_PAD_DISCONNECTED;
|
||||||
NRF_UART0->PSELCTS = NRF51_SERIAL_PAD_DISCONNECTED;
|
NRF_UART0->PSELCTS = NRF51_SERIAL_PAD_DISCONNECTED;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (config->rx_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
|
if (config->rx_pad != NRF51_SERIAL_PAD_DISCONNECTED) {
|
||||||
while (NRF_UART0->EVENTS_RXDRDY != 0) {
|
while (NRF_UART0->EVENTS_RXDRDY != 0) {
|
||||||
|
|
|
@ -39,6 +39,16 @@
|
||||||
* @name PLATFORM configuration options
|
* @name PLATFORM configuration options
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @brief SD flow control enable switch.
|
||||||
|
* @details If set to @p TRUE the support for hardware flow control
|
||||||
|
* is included.
|
||||||
|
* @note The default is @p FALSE.
|
||||||
|
*/
|
||||||
|
#if !defined(NRF51_SERIAL_USE_HWFLOWCTRL) || defined(__DOXYGEN__)
|
||||||
|
#define NRF51_SERIAL_USE_HWFLOWCTRL FALSE
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SD1 driver enable switch.
|
* @brief SD1 driver enable switch.
|
||||||
* @details If set to @p TRUE the support for SD1 is included.
|
* @details If set to @p TRUE the support for SD1 is included.
|
||||||
|
@ -85,6 +95,10 @@ typedef struct {
|
||||||
/* End of the mandatory fields.*/
|
/* End of the mandatory fields.*/
|
||||||
uint32_t tx_pad;
|
uint32_t tx_pad;
|
||||||
uint32_t rx_pad;
|
uint32_t rx_pad;
|
||||||
|
#if (NRF51_SERIAL_USE_HWFLOWCTRL == TRUE)
|
||||||
|
uint32_t rts_pad;
|
||||||
|
uint32_t cts_pad;
|
||||||
|
#endif
|
||||||
} SerialConfig;
|
} SerialConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue