Skip to content

Commit 4de8848

Browse files
committed
bsp:ls2k: make uart init more flexible
1 parent 242530a commit 4de8848

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

bsp/ls2kdev/Kconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ config SOC_LS2K1000
2929
select RT_USING_USER_MAIN
3030
select RT_USING_DEVICE
3131
default y
32-
32+
33+
if RT_USING_SERIAL
34+
config RT_USING_UART0
35+
bool "Using RT_USING_UART0"
36+
default y
37+
38+
config RT_USING_UART4
39+
bool "Using RT_USING_UART4"
40+
default y
41+
endif

bsp/ls2kdev/drivers/drv_uart.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,32 @@ struct rt_serial_device serial, serial4;
156156

157157
void rt_hw_uart_init(void)
158158
{
159-
struct rt_uart_ls2k *uart, *uart4;
160159
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
161160

162-
uart = &uart_dev0;
163-
uart4 = &uart_dev4;
161+
#ifdef RT_USING_UART0
162+
struct rt_uart_ls2k *uart0;
163+
uart0 = &uart_dev0;
164164
serial.ops = &ls2k_uart_ops;
165165
serial.config = config_uart0;
166-
serial4.ops = &ls2k_uart_ops;
167-
serial4.config = config;
168166

169-
rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial, "UART0");
170-
rt_hw_interrupt_install(uart4->IRQ, uart_irq_handler, &serial4, "UART4");
167+
rt_hw_interrupt_install(uart0->IRQ, uart_irq_handler, &serial, "UART0");
171168
/* register UART device */
172169
rt_hw_serial_register(&serial,
173170
"uart0",
174171
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
175-
uart);
172+
uart0);
173+
#endif
174+
175+
#ifdef RT_USING_UART4
176+
struct rt_uart_ls2k *uart4;
177+
uart4 = &uart_dev4;
178+
serial4.ops = &ls2k_uart_ops;
179+
serial4.config = config;
180+
rt_hw_interrupt_install(uart4->IRQ, uart_irq_handler, &serial4, "UART4");
176181
rt_hw_serial_register(&serial4,
177182
"uart4",
178183
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
179184
&uart_dev4);
185+
#endif
180186
}
181187
/*@}*/

bsp/ls2kdev/rtconfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,7 @@
235235
/* games: games run on RT-Thread console */
236236

237237
#define SOC_LS2K1000
238+
#define RT_USING_UART0
239+
#define RT_USING_UART4
238240

239241
#endif

0 commit comments

Comments
 (0)