2020-04-21 18:16:59 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Linumiz
|
|
|
|
* Author: Parthiban Nallathambi <parthiban@linumiz.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DT_DRV_COMPAT infineon_xmc4xxx_uart
|
|
|
|
|
|
|
|
#include <xmc_gpio.h>
|
|
|
|
#include <xmc_uart.h>
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/uart.h>
|
2020-04-21 18:16:59 +08:00
|
|
|
|
2022-01-26 03:25:48 +08:00
|
|
|
struct uart_xmc4xx_config {
|
|
|
|
XMC_USIC_CH_t *uart;
|
|
|
|
};
|
|
|
|
|
2020-04-21 18:16:59 +08:00
|
|
|
struct uart_xmc4xxx_data {
|
|
|
|
XMC_UART_CH_CONFIG_t config;
|
|
|
|
};
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int uart_xmc4xxx_poll_in(const struct device *dev, unsigned char *c)
|
2020-04-21 18:16:59 +08:00
|
|
|
{
|
2022-01-26 03:25:48 +08:00
|
|
|
const struct uart_xmc4xx_config *config = dev->config;
|
2020-04-21 18:16:59 +08:00
|
|
|
|
2022-05-16 02:49:22 +08:00
|
|
|
if (!XMC_USIC_CH_GetReceiveBufferStatus(config->uart)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-05-16 02:34:59 +08:00
|
|
|
*c = (unsigned char)XMC_UART_CH_GetReceivedData(config->uart);
|
2020-04-21 18:16:59 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static void uart_xmc4xxx_poll_out(const struct device *dev, unsigned char c)
|
2020-04-21 18:16:59 +08:00
|
|
|
{
|
2022-01-26 03:25:48 +08:00
|
|
|
const struct uart_xmc4xx_config *config = dev->config;
|
2020-04-21 18:16:59 +08:00
|
|
|
|
2022-05-16 03:54:20 +08:00
|
|
|
XMC_UART_CH_Transmit(config->uart, c);
|
2020-04-21 18:16:59 +08:00
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int uart_xmc4xxx_init(const struct device *dev)
|
2020-04-21 18:16:59 +08:00
|
|
|
{
|
2022-01-26 03:25:48 +08:00
|
|
|
const struct uart_xmc4xx_config *config = dev->config;
|
2022-01-18 23:58:32 +08:00
|
|
|
struct uart_xmc4xxx_data *data = dev->data;
|
2020-04-21 18:16:59 +08:00
|
|
|
|
|
|
|
data->config.data_bits = 8U;
|
|
|
|
data->config.stop_bits = 1U;
|
|
|
|
|
|
|
|
/* configure PIN 0.0 and 0.1 as UART */
|
2022-01-26 03:25:48 +08:00
|
|
|
XMC_UART_CH_Init(config->uart, &(data->config));
|
2020-04-21 18:16:59 +08:00
|
|
|
XMC_GPIO_SetMode(P0_0, XMC_GPIO_MODE_INPUT_TRISTATE);
|
2022-01-26 03:25:48 +08:00
|
|
|
XMC_UART_CH_SetInputSource(config->uart, XMC_UART_CH_INPUT_RXD,
|
2020-04-21 18:16:59 +08:00
|
|
|
USIC1_C1_DX0_P0_0);
|
2022-01-26 03:25:48 +08:00
|
|
|
XMC_UART_CH_Start(config->uart);
|
2020-04-21 18:16:59 +08:00
|
|
|
|
|
|
|
XMC_GPIO_SetMode(P0_1,
|
|
|
|
XMC_GPIO_MODE_OUTPUT_PUSH_PULL | P0_1_AF_U1C1_DOUT0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct uart_driver_api uart_xmc4xxx_driver_api = {
|
|
|
|
.poll_in = uart_xmc4xxx_poll_in,
|
|
|
|
.poll_out = uart_xmc4xxx_poll_out,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define XMC4XXX_INIT(index) \
|
|
|
|
static struct uart_xmc4xxx_data xmc4xxx_data_##index = { \
|
|
|
|
.config.baudrate = DT_INST_PROP(index, current_speed) \
|
|
|
|
}; \
|
|
|
|
\
|
2022-01-26 03:25:48 +08:00
|
|
|
static const struct uart_xmc4xx_config xmc4xxx_config_##index = { \
|
|
|
|
.uart = (XMC_USIC_CH_t *)DT_INST_REG_ADDR(index), \
|
2020-04-21 18:16:59 +08:00
|
|
|
}; \
|
|
|
|
\
|
2020-12-12 00:12:30 +08:00
|
|
|
DEVICE_DT_INST_DEFINE(index, &uart_xmc4xxx_init, \
|
2021-04-28 18:01:21 +08:00
|
|
|
NULL, \
|
2020-12-12 00:12:30 +08:00
|
|
|
&xmc4xxx_data_##index, \
|
2020-04-21 18:16:59 +08:00
|
|
|
&xmc4xxx_config_##index, PRE_KERNEL_1, \
|
2021-10-14 22:38:10 +08:00
|
|
|
CONFIG_SERIAL_INIT_PRIORITY, \
|
2020-04-21 18:16:59 +08:00
|
|
|
&uart_xmc4xxx_driver_api);
|
|
|
|
|
|
|
|
DT_INST_FOREACH_STATUS_OKAY(XMC4XXX_INIT)
|