Skip to content

Commit 3dea206

Browse files
committed
【修改】printf 输出统一使用 MicroPython 的 mp_printf 。
Signed-off-by: armink <[email protected]>
1 parent 3d45664 commit 3dea206

File tree

11 files changed

+36
-36
lines changed

11 files changed

+36
-36
lines changed

port/machine_hw_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
8383
struct rt_i2c_bus_device *i2c_bus = rt_i2c_bus_device_find(iic_device);
8484

8585
if (i2c_bus == RT_NULL) {
86-
rt_kprintf("can't find %s device\r\n", iic_device);
86+
mp_printf(&mp_plat_print, "can't find %s device\r\n", iic_device);
8787
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "I2C(%s) doesn't exist", iic_device));
8888
}
8989

port/machine_hw_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
5656

5757
struct rt_spi_device *rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name);
5858
if (rt_spi_device == RT_NULL || rt_spi_device->parent.type != RT_Device_Class_SPIDevice) {
59-
rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name);
59+
mp_printf(&mp_plat_print, "ERROR: SPI device %s not found!\n", spi_dev_name);
6060
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "SPI(%s) doesn't exist", spi_dev_name));
6161
}
6262

port/machine_uart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
6363

6464
struct rt_serial_device *rt_serial_device = (struct rt_serial_device *) rt_device_find(uart_dev_name);
6565
if (rt_serial_device == RT_NULL || rt_serial_device->parent.type != RT_Device_Class_Char) {
66-
rt_kprintf("ERROR: UART device %s not found!\n", uart_dev_name);
66+
mp_printf(&mp_plat_print, "ERROR: UART device %s not found!\n", uart_dev_name);
6767
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) doesn't exist", uart_dev_name));
6868
}
6969

7070
rt_err_t result;
7171
result = rt_device_open((rt_device_t)rt_serial_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX );
7272
if (result != RT_EOK)
7373
{
74-
rt_kprintf("ERROR: UART device %s can't open!\n", uart_dev_name);
74+
mp_printf(&mp_plat_print, "ERROR: UART device %s can't open!\n", uart_dev_name);
7575
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "UART(%s) can't open", uart_dev_name));
7676
}
7777

port/modmachine.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
5555
#endif
5656
// RT-Thread info
5757
{
58-
rt_kprintf("---------------------------------------------\n");
59-
rt_kprintf("RT-Thread\n");
60-
rt_kprintf("---------------------------------------------\n");
58+
mp_printf(&mp_plat_print, "---------------------------------------------\n");
59+
mp_printf(&mp_plat_print, "RT-Thread\n");
60+
mp_printf(&mp_plat_print, "---------------------------------------------\n");
6161

6262
#ifdef RT_USING_FINSH
6363
extern void list_mem(void);
@@ -71,25 +71,25 @@ STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) {
7171

7272
list_thread();
7373
#endif
74-
rt_kprintf("---------------------------------------------\n");
74+
mp_printf(&mp_plat_print, "---------------------------------------------\n");
7575
}
7676

7777
// qstr info
7878
{
7979
mp_uint_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
8080
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
81-
rt_kprintf("qstr:\n n_pool=" UINT_FMT "\n n_qstr=" UINT_FMT "\n n_str_data_bytes=" UINT_FMT "\n n_total_bytes=" UINT_FMT "\n", n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
81+
mp_printf(&mp_plat_print, "qstr:\n n_pool=" UINT_FMT "\n n_qstr=" UINT_FMT "\n n_str_data_bytes=" UINT_FMT "\n n_total_bytes=" UINT_FMT "\n", n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
8282
}
83-
rt_kprintf("---------------------------------------------\n");
83+
mp_printf(&mp_plat_print, "---------------------------------------------\n");
8484

8585
// GC info
8686
{
8787
gc_info_t info;
8888
gc_info(&info);
89-
rt_kprintf("GC:\n");
90-
rt_kprintf(" " UINT_FMT " total\n", info.total);
91-
rt_kprintf(" " UINT_FMT " : " UINT_FMT "\n", info.used, info.free);
92-
rt_kprintf(" 1=" UINT_FMT " 2=" UINT_FMT " m=" UINT_FMT "\n", info.num_1block, info.num_2block, info.max_block);
89+
mp_printf(&mp_plat_print, "GC:\n");
90+
mp_printf(&mp_plat_print, " " UINT_FMT " total\n", info.total);
91+
mp_printf(&mp_plat_print, " " UINT_FMT " : " UINT_FMT "\n", info.used, info.free);
92+
mp_printf(&mp_plat_print, " 1=" UINT_FMT " 2=" UINT_FMT " m=" UINT_FMT "\n", info.num_1block, info.num_2block, info.max_block);
9393
}
9494

9595
// free space on flash

port/modrtthread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ STATIC mp_obj_t mod_stacks_analyze(void) {
5555
extern long list_thread(void);
5656
list_thread();
5757
#else
58-
rt_kprintf("Not available when FINSH module disable\n");
58+
mp_printf(&mp_plat_print, "Not available when FINSH module disable\n");
5959
#endif
6060

6161
return mp_const_none;

port/moduos_file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_posix_mkfs_obj, 1, 2, mp_posix_mkfs);
7474
mp_obj_t mp_posix_chdir(mp_obj_t path_in) {
7575
const char *changepath = mp_obj_str_get_str(path_in);
7676
if (chdir(changepath) != 0) {
77-
rt_kprintf("No such directory: %s\n", changepath);
77+
mp_printf(&mp_plat_print, "No such directory: %s\n", changepath);
7878
}
7979
return mp_const_none;
8080
}
@@ -152,7 +152,7 @@ mp_obj_t mp_posix_listdir(size_t n_args, const mp_obj_t *args) {
152152
mp_obj_get_array_fixed_n(next, 3, &items);
153153
mp_obj_list_append(dir_list, items[0]);
154154
} else {
155-
rt_kprintf("BAD file: %s\n", dirent.d_name);
155+
mp_printf(&mp_plat_print, "BAD file: %s\n", dirent.d_name);
156156
}
157157
rt_free(fullpath);
158158
}
@@ -162,7 +162,7 @@ mp_obj_t mp_posix_listdir(size_t n_args, const mp_obj_t *args) {
162162
}
163163
else
164164
{
165-
// rt_kprintf("No such directory\n");
165+
// mp_printf(&mp_plat_print, "No such directory\n");
166166
}
167167
if (pathname == NULL)
168168
rt_free(path);
@@ -184,12 +184,12 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_posix_mkdir_obj, mp_posix_mkdir);
184184
mp_obj_t mp_posix_remove(uint n_args, const mp_obj_t *arg) {
185185
int index;
186186
if (n_args == 0) {
187-
rt_kprintf("Usage: rm FILE...\n");
188-
rt_kprintf("Remove (unlink) the FILE(s).\n");
187+
mp_printf(&mp_plat_print, "Usage: rm FILE...\n");
188+
mp_printf(&mp_plat_print, "Remove (unlink) the FILE(s).\n");
189189
return mp_const_none;
190190
}
191191
for (index = 0; index < n_args; index++) {
192-
//rt_kprintf("Remove %s.\n", mp_obj_str_get_str(arg[index]));
192+
//mp_printf(&mp_plat_print, "Remove %s.\n", mp_obj_str_get_str(arg[index]));
193193
unlink(mp_obj_str_get_str(arg[index]));
194194
}
195195
// TODO recursive deletion
@@ -211,12 +211,12 @@ MP_DEFINE_CONST_FUN_OBJ_2(mp_posix_rename_obj, mp_posix_rename);
211211
mp_obj_t mp_posix_rmdir(uint n_args, const mp_obj_t *arg) {
212212
int index;
213213
if (n_args == 0) {
214-
rt_kprintf("Usage: rm FILE...\n");
215-
rt_kprintf("Remove (unlink) the FILE(s).\n");
214+
mp_printf(&mp_plat_print, "Usage: rm FILE...\n");
215+
mp_printf(&mp_plat_print, "Remove (unlink) the FILE(s).\n");
216216
return mp_const_none;
217217
}
218218
for (index = 0; index < n_args; index++) {
219-
//rt_kprintf("Remove %s.\n", mp_obj_str_get_str(arg[index]));
219+
//mp_printf(&mp_plat_print, "Remove %s.\n", mp_obj_str_get_str(arg[index]));
220220
rmdir(mp_obj_str_get_str(arg[index]));
221221
}
222222
// TODO recursive deletion

port/modusocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(uint n_args, const mp_obj_t *arg) {
548548
ret = getaddrinfo(host, NULL, &hint, &res);
549549
MP_THREAD_GIL_ENTER();
550550
if (ret != 0) {
551-
rt_kprintf("getaddrinfo err: %d '%s'\n", ret, host);
551+
mp_printf(&mp_plat_print, "getaddrinfo err: %d '%s'\n", ret, host);
552552
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "no available netif"));
553553
}
554554

port/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,5 +512,5 @@ extern const struct _mp_obj_module_t mp_module_network;
512512
MODUZLIB_PORT_BUILTIN_MODULE_WEAK_LINKS \
513513
MODUSTRUCT_PORT_BUILTIN_MODULE_WEAK_LINKS \
514514

515-
#define MP_RTT_NOT_IMPL_PRINT rt_kprintf("Not implement on %s:%ld, Please add for your board!\n", __FILE__, __LINE__)
515+
#define MP_RTT_NOT_IMPL_PRINT mp_printf(&mp_plat_print, "Not implement on %s:%ld, Please add for your board!\n", __FILE__, __LINE__)
516516

port/mpy_main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void mpy_main(const char *filename) {
7474
mp_putsn_init();
7575

7676
if (rt_thread_self()->stack_size < 4096) {
77-
rt_kprintf("The stack (%.*s) size for executing MicroPython must be >=4096\n", RT_NAME_MAX, rt_thread_self()->name);
77+
mp_printf(&mp_plat_print, "The stack (%.*s) size for executing MicroPython must be >=4096\n", RT_NAME_MAX, rt_thread_self()->name);
7878
}
7979

8080
#if MICROPY_PY_THREAD
@@ -88,7 +88,7 @@ void mpy_main(const char *filename) {
8888
#if MICROPY_ENABLE_GC
8989
heap = rt_malloc(MICROPY_HEAP_SIZE);
9090
if (!heap) {
91-
rt_kprintf("No memory for MicroPython Heap!\n");
91+
mp_printf(&mp_plat_print, "No memory for MicroPython Heap!\n");
9292
return;
9393
}
9494
gc_init(heap, heap + MICROPY_HEAP_SIZE);
@@ -106,7 +106,7 @@ void mpy_main(const char *filename) {
106106

107107
if (filename) {
108108
#ifndef MICROPYTHON_USING_UOS
109-
rt_kprintf("Please enable uos module in sys module option first.\n");
109+
mp_printf(&mp_plat_print, "Please enable uos module in sys module option first.\n");
110110
#else
111111
pyexec_file(filename);
112112
#endif
@@ -129,7 +129,7 @@ void mpy_main(const char *filename) {
129129
}
130130
#endif /* MICROPYTHON_USING_UOS */
131131

132-
rt_kprintf("\n");
132+
mp_printf(&mp_plat_print, "\n");
133133
for (;;) {
134134
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
135135
if (pyexec_raw_repl() != 0) {
@@ -164,13 +164,13 @@ mp_import_stat_t mp_import_stat(const char *path) {
164164
#endif
165165

166166
NORETURN void nlr_jump_fail(void *val) {
167-
DEBUG_printf("nlr_jump_fail\n");
167+
mp_printf(MICROPY_ERROR_PRINTER, "nlr_jump_fail\n");
168168
while (1);
169169
}
170170

171171
#ifndef NDEBUG
172172
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
173-
rt_kprintf("Assertion '%s' failed, at file %s:%d\n", expr, file, line);
173+
mp_printf(MICROPY_ERROR_PRINTER, "Assertion '%s' failed, at file %s:%d\n", expr, file, line);
174174
RT_ASSERT(0);
175175
}
176176
#endif
@@ -186,7 +186,7 @@ int DEBUG_printf(const char *format, ...)
186186
va_start(args, format);
187187
/* must use vprintf to print */
188188
rt_vsprintf(log_buf, format, args);
189-
rt_kprintf("%s", log_buf);
189+
mp_printf(&mp_plat_print, "%s", log_buf);
190190
va_end(args);
191191

192192
return 0;

port/native/native_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*/
5151

5252
void native_module_show(const char *str) {
53-
rt_kprintf("Native module show: %s\n", str);
53+
mp_printf(&mp_plat_print, "Native module show: %s\n", str);
5454
}
5555
RTM_EXPORT(native_module_show)
5656

0 commit comments

Comments
 (0)