Skip to content

Commit

Permalink
hw/mcu/da1469x: Add UART driver to MCU peripherals
Browse files Browse the repository at this point in the history
uart_hal driver was used for devices created in da1469x_periph_create().
Now da1469x_uart driver will be used by default.

When UART_HAL syscfg value is set to 1 original uart_hal driver
will be used instead.
  • Loading branch information
kasjer committed Feb 1, 2021
1 parent d4b7ca6 commit b65788b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
5 changes: 4 additions & 1 deletion hw/mcu/dialog/da1469x/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ pkg.deps.TRNG:
pkg.deps.CRYPTO:
- "@apache-mynewt-core/hw/drivers/crypto/crypto_da1469x"

pkg.deps.'UART_0 || UART_1 || UART_2':
pkg.deps.'(UART_0 || UART_1 || UART_2) && HAL_UART':
- "@apache-mynewt-core/hw/drivers/uart/uart_hal"

pkg.deps.'(UART_0 || UART_1 || UART_2) && !HAL_UART':
- "@apache-mynewt-core/hw/drivers/uart/uart_da1469x"

pkg.deps.'(I2C_0 || I2C_1) && BUS_DRIVER_PRESENT':
- "@apache-mynewt-core/hw/bus/drivers/i2c_hal"

Expand Down
42 changes: 33 additions & 9 deletions hw/mcu/dialog/da1469x/src/da1469x_periph.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2)
#include "uart/uart.h"
#if MYNEWT_VAL(HAL_UART)
#include "uart_hal/uart_hal.h"
#else
#include "uart_da1469x/uart_da1469x.h"
#endif
#endif
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
#include "bus/bus.h"
Expand Down Expand Up @@ -89,7 +93,11 @@ static struct crypto_dev os_bsp_crypto;
#endif

#if MYNEWT_VAL(UART_0)
#if MYNEWT_VAL(UART_HAL)
static struct uart_dev os_bsp_uart0;
#else
static struct da1469x_uart_dev os_bsp_uart0;
#endif
static const struct da1469x_uart_cfg os_bsp_uart0_cfg = {
.pin_tx = MYNEWT_VAL(UART_0_PIN_TX),
.pin_rx = MYNEWT_VAL(UART_0_PIN_RX),
Expand All @@ -99,7 +107,11 @@ static const struct da1469x_uart_cfg os_bsp_uart0_cfg = {
};
#endif
#if MYNEWT_VAL(UART_1)
#if MYNEWT_VAL(UART_HAL)
static struct uart_dev os_bsp_uart1;
#else
static struct da1469x_uart_dev os_bsp_uart1;
#endif
static const struct da1469x_uart_cfg os_bsp_uart1_cfg = {
.pin_tx = MYNEWT_VAL(UART_1_PIN_TX),
.pin_rx = MYNEWT_VAL(UART_1_PIN_RX),
Expand All @@ -109,7 +121,11 @@ static const struct da1469x_uart_cfg os_bsp_uart1_cfg = {
};
#endif
#if MYNEWT_VAL(UART_2)
#if MYNEWT_VAL(UART_HAL)
static struct uart_dev os_bsp_uart2;
#else
static struct da1469x_uart_dev os_bsp_uart2;
#endif
static const struct da1469x_uart_cfg os_bsp_uart2_cfg = {
.pin_tx = MYNEWT_VAL(UART_2_PIN_TX),
.pin_rx = MYNEWT_VAL(UART_2_PIN_RX),
Expand Down Expand Up @@ -334,6 +350,20 @@ da1469x_periph_create_adc(void)
#endif
}

static int
da1469x_uart_create(struct da1469x_uart_dev *dev, const char *name, uint8_t priority,
const struct da1469x_uart_cfg *cfg)
{
#if MYNEWT_VAL(HAL_UART)
return os_dev_create(&dev->ud_dev, "uart0",
OS_DEV_INIT_PRIMARY, priority, uart_hal_init,
(void *)&os_bsp_uart0_cfg);
#else
(void)priority;
return da1469x_uart_dev_create(dev, name, priority, cfg);
#endif
}

static void
da1469x_periph_create_uart(void)
{
Expand All @@ -342,21 +372,15 @@ da1469x_periph_create_uart(void)
(void)rc;

#if MYNEWT_VAL(UART_0)
rc = os_dev_create(&os_bsp_uart0.ud_dev, "uart0",
OS_DEV_INIT_PRIMARY, 0, uart_hal_init,
(void *)&os_bsp_uart0_cfg);
rc = da1469x_uart_create(&os_bsp_uart0, "uart0", 0, &os_bsp_uart0_cfg);
assert(rc == 0);
#endif
#if MYNEWT_VAL(UART_1)
rc = os_dev_create(&os_bsp_uart1.ud_dev, "uart1",
OS_DEV_INIT_PRIMARY, 1, uart_hal_init,
(void *)&os_bsp_uart1_cfg);
rc = da1469x_uart_create(&os_bsp_uart1, "uart1", 1, &os_bsp_uart1_cfg);
assert(rc == 0);
#endif
#if MYNEWT_VAL(UART_2)
rc = os_dev_create(&os_bsp_uart1.ud_dev, "uart2",
OS_DEV_INIT_PRIMARY, 2, uart_hal_init,
(void *)&os_bsp_uart2_cfg);
rc = da1469x_uart_create(&os_bsp_uart2, "uart2", 2, &os_bsp_uart2_cfg);
assert(rc == 0);
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions hw/mcu/dialog/da1469x/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ syscfg.defs:
description: 'SS pin for SPI_1_SLAVE'
value: ''

HAL_UART:
description: 'Use hal_uart driver instead of da1469x_uart.'
value: 0

UART_0:
description: Enable DA1469x UART 0 (UART peripheral)
value: 1
Expand Down

0 comments on commit b65788b

Please sign in to comment.