44
55#include "py/runtime.h"
66#include "py/objstr.h"
7+ #include "machine.h"
78#include "mphalport.h"
89#include "syscall.h"
910
10- extern mp_obj_t signal_hook_obj ;
11- extern mp_obj_t stdin_hook_obj ;
12- extern mp_obj_t stdout_hook_obj ;
13-
1411int mp_hal_stdin_rx_chr (void ) {
15- if (stdin_hook_obj == mp_const_none ) {
12+ if (MP_STATE_PORT ( stdin_hook_obj ) == mp_const_none ) {
1613 return 0 ;
1714 } else {
18- mp_obj_t obj = mp_call_function_0 (stdin_hook_obj );
15+ mp_obj_t obj = mp_call_function_0 (MP_STATE_PORT ( stdin_hook_obj ) );
1916 return (int ) mp_obj_get_int (obj );
2017 }
2118}
@@ -25,11 +22,11 @@ void mp_hal_stdout_tx_str(const char *str) {
2522}
2623
2724void mp_hal_stdout_tx_strn (const char * str , mp_uint_t len ) {
28- if (stdout_hook_obj == mp_const_none ) {
25+ if (MP_STATE_PORT ( stdout_hook_obj ) == mp_const_none ) {
2926 __syscall2 (SYS_DEBUG , (int )str , (int )len );
3027 } else {
3128 mp_obj_t str_obj = mp_obj_new_str (str , len );
32- mp_call_function_1 (stdout_hook_obj , str_obj );
29+ mp_call_function_1 (MP_STATE_PORT ( stdout_hook_obj ) , str_obj );
3330 }
3431}
3532
@@ -44,7 +41,9 @@ void mp_hal_delay_ms(mp_uint_t ms) {
4441 mp_handle_pending ();
4542 int32_t ticks = (ms - elapsed ) / (1000 / 20 );
4643 mp_obj_t tick_obj = mp_obj_new_int (ticks < 0 ? 0 : ticks );
47- mp_call_function_1 (signal_hook_obj , tick_obj );
44+ if (MP_STATE_PORT (signal_hook_obj ) == mp_const_none )
45+ __fatal_error ("signal_hook is None" );
46+ mp_call_function_1 (MP_STATE_PORT (signal_hook_obj ), tick_obj );
4847 elapsed = mp_hal_ticks_ms () - start ;
4948 }
5049}
0 commit comments