Skip to content

Commit b65788b

Browse files
committed
hw/mcu/da1469x: Add UART driver to MCU peripherals
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.
1 parent d4b7ca6 commit b65788b

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

hw/mcu/dialog/da1469x/pkg.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ pkg.deps.TRNG:
3939
pkg.deps.CRYPTO:
4040
- "@apache-mynewt-core/hw/drivers/crypto/crypto_da1469x"
4141

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

45+
pkg.deps.'(UART_0 || UART_1 || UART_2) && !HAL_UART':
46+
- "@apache-mynewt-core/hw/drivers/uart/uart_da1469x"
47+
4548
pkg.deps.'(I2C_0 || I2C_1) && BUS_DRIVER_PRESENT':
4649
- "@apache-mynewt-core/hw/bus/drivers/i2c_hal"
4750

hw/mcu/dialog/da1469x/src/da1469x_periph.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727

2828
#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2)
2929
#include "uart/uart.h"
30+
#if MYNEWT_VAL(HAL_UART)
3031
#include "uart_hal/uart_hal.h"
32+
#else
33+
#include "uart_da1469x/uart_da1469x.h"
34+
#endif
3135
#endif
3236
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
3337
#include "bus/bus.h"
@@ -89,7 +93,11 @@ static struct crypto_dev os_bsp_crypto;
8993
#endif
9094

9195
#if MYNEWT_VAL(UART_0)
96+
#if MYNEWT_VAL(UART_HAL)
9297
static struct uart_dev os_bsp_uart0;
98+
#else
99+
static struct da1469x_uart_dev os_bsp_uart0;
100+
#endif
93101
static const struct da1469x_uart_cfg os_bsp_uart0_cfg = {
94102
.pin_tx = MYNEWT_VAL(UART_0_PIN_TX),
95103
.pin_rx = MYNEWT_VAL(UART_0_PIN_RX),
@@ -99,7 +107,11 @@ static const struct da1469x_uart_cfg os_bsp_uart0_cfg = {
99107
};
100108
#endif
101109
#if MYNEWT_VAL(UART_1)
110+
#if MYNEWT_VAL(UART_HAL)
102111
static struct uart_dev os_bsp_uart1;
112+
#else
113+
static struct da1469x_uart_dev os_bsp_uart1;
114+
#endif
103115
static const struct da1469x_uart_cfg os_bsp_uart1_cfg = {
104116
.pin_tx = MYNEWT_VAL(UART_1_PIN_TX),
105117
.pin_rx = MYNEWT_VAL(UART_1_PIN_RX),
@@ -109,7 +121,11 @@ static const struct da1469x_uart_cfg os_bsp_uart1_cfg = {
109121
};
110122
#endif
111123
#if MYNEWT_VAL(UART_2)
124+
#if MYNEWT_VAL(UART_HAL)
112125
static struct uart_dev os_bsp_uart2;
126+
#else
127+
static struct da1469x_uart_dev os_bsp_uart2;
128+
#endif
113129
static const struct da1469x_uart_cfg os_bsp_uart2_cfg = {
114130
.pin_tx = MYNEWT_VAL(UART_2_PIN_TX),
115131
.pin_rx = MYNEWT_VAL(UART_2_PIN_RX),
@@ -334,6 +350,20 @@ da1469x_periph_create_adc(void)
334350
#endif
335351
}
336352

353+
static int
354+
da1469x_uart_create(struct da1469x_uart_dev *dev, const char *name, uint8_t priority,
355+
const struct da1469x_uart_cfg *cfg)
356+
{
357+
#if MYNEWT_VAL(HAL_UART)
358+
return os_dev_create(&dev->ud_dev, "uart0",
359+
OS_DEV_INIT_PRIMARY, priority, uart_hal_init,
360+
(void *)&os_bsp_uart0_cfg);
361+
#else
362+
(void)priority;
363+
return da1469x_uart_dev_create(dev, name, priority, cfg);
364+
#endif
365+
}
366+
337367
static void
338368
da1469x_periph_create_uart(void)
339369
{
@@ -342,21 +372,15 @@ da1469x_periph_create_uart(void)
342372
(void)rc;
343373

344374
#if MYNEWT_VAL(UART_0)
345-
rc = os_dev_create(&os_bsp_uart0.ud_dev, "uart0",
346-
OS_DEV_INIT_PRIMARY, 0, uart_hal_init,
347-
(void *)&os_bsp_uart0_cfg);
375+
rc = da1469x_uart_create(&os_bsp_uart0, "uart0", 0, &os_bsp_uart0_cfg);
348376
assert(rc == 0);
349377
#endif
350378
#if MYNEWT_VAL(UART_1)
351-
rc = os_dev_create(&os_bsp_uart1.ud_dev, "uart1",
352-
OS_DEV_INIT_PRIMARY, 1, uart_hal_init,
353-
(void *)&os_bsp_uart1_cfg);
379+
rc = da1469x_uart_create(&os_bsp_uart1, "uart1", 1, &os_bsp_uart1_cfg);
354380
assert(rc == 0);
355381
#endif
356382
#if MYNEWT_VAL(UART_2)
357-
rc = os_dev_create(&os_bsp_uart1.ud_dev, "uart2",
358-
OS_DEV_INIT_PRIMARY, 2, uart_hal_init,
359-
(void *)&os_bsp_uart2_cfg);
383+
rc = da1469x_uart_create(&os_bsp_uart2, "uart2", 2, &os_bsp_uart2_cfg);
360384
assert(rc == 0);
361385
#endif
362386
}

hw/mcu/dialog/da1469x/syscfg.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ syscfg.defs:
336336
description: 'SS pin for SPI_1_SLAVE'
337337
value: ''
338338

339+
HAL_UART:
340+
description: 'Use hal_uart driver instead of da1469x_uart.'
341+
value: 0
342+
339343
UART_0:
340344
description: Enable DA1469x UART 0 (UART peripheral)
341345
value: 1

0 commit comments

Comments
 (0)