Skip to content

Commit 09ffb2b

Browse files
committed
drivers: console: add tccvcp console driver
Add console driver for tccvcp, required by TOPST VCP45. Signed-off-by: Hounjoung Rim <[email protected]>
1 parent 8e8013a commit 09ffb2b

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

drivers/console/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ zephyr_library_sources_ifdef(CONFIG_UART_MCUMGR uart_mcumgr.c)
1515
zephyr_library_sources_ifdef(CONFIG_XTENSA_SIM_CONSOLE xtensa_sim_console.c)
1616
zephyr_library_sources_ifdef(CONFIG_EFI_CONSOLE efi_console.c)
1717
zephyr_library_sources_ifdef(CONFIG_WINSTREAM_CONSOLE winstream_console.c)
18+
zephyr_library_sources_ifdef(CONFIG_TCCVCP_CONSOLE tccvcp_console.c)

drivers/console/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,11 @@ config WINSTREAM_CONSOLE_STATIC_SIZE
304304

305305
endif # WINSTREAM_CONSOLE
306306

307+
config TCCVCP_CONSOLE
308+
bool "Use TCCVCP console"
309+
depends on SERIAL && SERIAL_HAS_DRIVER && UART_TCCVCP
310+
select CONSOLE_HAS_DRIVER
311+
help
312+
Use tccvcp as a console.
313+
307314
endif # CONSOLE

drivers/console/tccvcp_console.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2024 Hounjoung Rim <[email protected]>
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
#include <zephyr/sys/printk.h>
8+
#include <zephyr/sys/printk-hooks.h>
9+
#include <zephyr/sys/libc-hooks.h>
10+
#include <zephyr/device.h>
11+
#include <zephyr/init.h>
12+
13+
static const struct device *const uart_console_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
14+
15+
void uart_tccvcp_poll_out(const struct device *dev, unsigned char c);
16+
17+
static int arch_printk_char_out(int c)
18+
{
19+
if (!device_is_ready(uart_console_dev)) {
20+
return -ENODEV;
21+
}
22+
23+
if ('\n' == c) {
24+
uart_tccvcp_poll_out(uart_console_dev, '\r');
25+
}
26+
uart_tccvcp_poll_out(uart_console_dev, c);
27+
28+
return c;
29+
}
30+
31+
static void tccvcp_console_hook_install(void)
32+
{
33+
#if defined(CONFIG_PRINTK)
34+
__printk_hook_install(arch_printk_char_out);
35+
#endif
36+
__stdout_hook_install(arch_printk_char_out);
37+
}
38+
39+
static int tccvcp_console_init(void)
40+
{
41+
if (!device_is_ready(uart_console_dev)) {
42+
return -ENODEV;
43+
}
44+
45+
tccvcp_console_hook_install();
46+
47+
return 0;
48+
}
49+
50+
SYS_INIT(tccvcp_console_init, POST_KERNEL, CONFIG_CONSOLE_INIT_PRIORITY);

0 commit comments

Comments
 (0)