diff --git a/hw/mcu/dialog/da1469x/pkg.yml b/hw/mcu/dialog/da1469x/pkg.yml index 13387200dc..ef753b1539 100644 --- a/hw/mcu/dialog/da1469x/pkg.yml +++ b/hw/mcu/dialog/da1469x/pkg.yml @@ -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" diff --git a/hw/mcu/dialog/da1469x/src/da1469x_periph.c b/hw/mcu/dialog/da1469x/src/da1469x_periph.c index 0e2945b7c0..c75483f4dc 100644 --- a/hw/mcu/dialog/da1469x/src/da1469x_periph.c +++ b/hw/mcu/dialog/da1469x/src/da1469x_periph.c @@ -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" @@ -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), @@ -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), @@ -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), @@ -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) { @@ -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 } diff --git a/hw/mcu/dialog/da1469x/syscfg.yml b/hw/mcu/dialog/da1469x/syscfg.yml index 6bfb1a7a93..aff011365e 100644 --- a/hw/mcu/dialog/da1469x/syscfg.yml +++ b/hw/mcu/dialog/da1469x/syscfg.yml @@ -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