Add tx/rx pin configuration to SerialConfig

This commit is contained in:
Fabio Utzig 2015-05-15 21:08:53 -03:00
parent 69d70de9b7
commit 343042d9d2
3 changed files with 23 additions and 9 deletions

View File

@ -37,6 +37,12 @@ static THD_FUNCTION(Thread1, arg) {
*/
int main(void) {
SerialConfig serial_config = {
.speed = 38400,
.tx_pin = UART_TX,
.rx_pin = UART_RX,
};
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
@ -50,7 +56,7 @@ int main(void) {
/*
* Activates UART0 using the driver default configuration.
*/
sdStart(&SD1, NULL);
sdStart(&SD1, &serial_config);
/*
* Creates the blinker thread.

View File

@ -33,6 +33,7 @@
/*===========================================================================*/
#define INVALID_BAUDRATE 0xFFFFFFFF
#define INVALID_PIN 0xFF
/*===========================================================================*/
/* Driver exported variables. */
@ -51,7 +52,9 @@ SerialDriver SD1;
* @brief Driver default configuration.
*/
static const SerialConfig default_config = {
38400
.speed = 38400,
.tx_pin = INVALID_PIN,
.rx_pin = INVALID_PIN,
};
/*===========================================================================*/
@ -131,8 +134,7 @@ OSAL_IRQ_HANDLER(Vector48) {
osalSysUnlockFromISR();
}
//TODO
//NRF_UART0->EVENTS_ERROR = 0;
/* TODO: Error handling for EVENTS_ERROR */
OSAL_IRQ_EPILOGUE();
}
@ -176,15 +178,19 @@ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
if (sdp == &SD1) {
uint32_t regval;
/* FIXME: some board specific, some hardcodeds! */
/* TODO: Add support for CTS/RTS! */
/* Configure PINs */
NRF_UART0->PSELRTS = ~0;
NRF_UART0->PSELCTS = ~0;
NRF_GPIO->PIN_CNF[9] = 1;
NRF_UART0->PSELTXD = 9;
NRF_UART0->PSELRXD = 11;
if (config->tx_pin != INVALID_PIN) {
palSetPadMode(IOPORT1, config->tx_pin, PAL_MODE_OUTPUT_PUSHPULL);
NRF_UART0->PSELTXD = config->tx_pin;
}
if (config->rx_pin != INVALID_PIN) {
palSetPadMode(IOPORT1, config->rx_pin, PAL_MODE_INPUT);
NRF_UART0->PSELRXD = config->rx_pin;
}
regval = regval_from_baudrate(config->speed);
osalDbgAssert(regval != INVALID_BAUDRATE, "invalid baudrate speed");

View File

@ -71,6 +71,8 @@ typedef struct {
*/
uint32_t speed;
/* End of the mandatory fields.*/
uint8_t tx_pin;
uint8_t rx_pin;
} SerialConfig;
/**