39
39
// UartDev is defined and initialized in rom code.
40
40
extern UartDevice UartDev ;
41
41
42
- typedef struct _pyb_uart_obj_t {
42
+ typedef struct _machine_uart_obj_t {
43
43
mp_obj_base_t base ;
44
44
uint8_t uart_id ;
45
45
uint8_t bits ;
@@ -48,21 +48,21 @@ typedef struct _pyb_uart_obj_t {
48
48
uint32_t baudrate ;
49
49
uint16_t timeout ; // timeout waiting for first char (in ms)
50
50
uint16_t timeout_char ; // timeout waiting between chars (in ms)
51
- } pyb_uart_obj_t ;
51
+ } machine_uart_obj_t ;
52
52
53
53
STATIC const char * _parity_name [] = {"None" , "1" , "0" };
54
54
55
55
/******************************************************************************/
56
56
// MicroPython bindings for UART
57
57
58
- STATIC void pyb_uart_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
59
- pyb_uart_obj_t * self = MP_OBJ_TO_PTR (self_in );
58
+ STATIC void machine_uart_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
59
+ machine_uart_obj_t * self = MP_OBJ_TO_PTR (self_in );
60
60
mp_printf (print , "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, timeout=%u, timeout_char=%u)" ,
61
61
self -> uart_id , self -> baudrate , self -> bits , _parity_name [self -> parity ],
62
62
self -> stop , self -> timeout , self -> timeout_char );
63
63
}
64
64
65
- STATIC void pyb_uart_init_helper ( pyb_uart_obj_t * self , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
65
+ STATIC void machine_uart_init_helper ( machine_uart_obj_t * self , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
66
66
enum { ARG_baudrate , ARG_bits , ARG_parity , ARG_stop , ARG_timeout , ARG_timeout_char };
67
67
static const mp_arg_t allowed_args [] = {
68
68
{ MP_QSTR_baudrate , MP_ARG_INT , {.u_int = 0 } },
@@ -159,7 +159,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
159
159
uart_setup (self -> uart_id );
160
160
}
161
161
162
- STATIC mp_obj_t pyb_uart_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
162
+ STATIC mp_obj_t machine_uart_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
163
163
mp_arg_check_num (n_args , n_kw , 1 , MP_OBJ_FUN_ARGS_MAX , true);
164
164
165
165
// get uart id
@@ -169,8 +169,8 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
169
169
}
170
170
171
171
// create instance
172
- pyb_uart_obj_t * self = m_new_obj (pyb_uart_obj_t );
173
- self -> base .type = & pyb_uart_type ;
172
+ machine_uart_obj_t * self = m_new_obj (machine_uart_obj_t );
173
+ self -> base .type = & machine_uart_type ;
174
174
self -> uart_id = uart_id ;
175
175
self -> baudrate = 115200 ;
176
176
self -> bits = 8 ;
@@ -182,30 +182,30 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
182
182
// init the peripheral
183
183
mp_map_t kw_args ;
184
184
mp_map_init_fixed_table (& kw_args , n_kw , args + n_args );
185
- pyb_uart_init_helper (self , n_args - 1 , args + 1 , & kw_args );
185
+ machine_uart_init_helper (self , n_args - 1 , args + 1 , & kw_args );
186
186
187
187
return MP_OBJ_FROM_PTR (self );
188
188
}
189
189
190
- STATIC mp_obj_t pyb_uart_init (size_t n_args , const mp_obj_t * args , mp_map_t * kw_args ) {
191
- pyb_uart_init_helper (args [0 ], n_args - 1 , args + 1 , kw_args );
190
+ STATIC mp_obj_t machine_uart_init (size_t n_args , const mp_obj_t * args , mp_map_t * kw_args ) {
191
+ machine_uart_init_helper (args [0 ], n_args - 1 , args + 1 , kw_args );
192
192
return mp_const_none ;
193
193
}
194
- MP_DEFINE_CONST_FUN_OBJ_KW (pyb_uart_init_obj , 1 , pyb_uart_init );
194
+ MP_DEFINE_CONST_FUN_OBJ_KW (machine_uart_init_obj , 1 , machine_uart_init );
195
195
196
- STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table [] = {
197
- { MP_ROM_QSTR (MP_QSTR_init ), MP_ROM_PTR (& pyb_uart_init_obj ) },
196
+ STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table [] = {
197
+ { MP_ROM_QSTR (MP_QSTR_init ), MP_ROM_PTR (& machine_uart_init_obj ) },
198
198
199
199
{ MP_ROM_QSTR (MP_QSTR_read ), MP_ROM_PTR (& mp_stream_read_obj ) },
200
200
{ MP_ROM_QSTR (MP_QSTR_readline ), MP_ROM_PTR (& mp_stream_unbuffered_readline_obj ) },
201
201
{ MP_ROM_QSTR (MP_QSTR_readinto ), MP_ROM_PTR (& mp_stream_readinto_obj ) },
202
202
{ MP_ROM_QSTR (MP_QSTR_write ), MP_ROM_PTR (& mp_stream_write_obj ) },
203
203
};
204
204
205
- STATIC MP_DEFINE_CONST_DICT (pyb_uart_locals_dict , pyb_uart_locals_dict_table );
205
+ STATIC MP_DEFINE_CONST_DICT (machine_uart_locals_dict , machine_uart_locals_dict_table );
206
206
207
- STATIC mp_uint_t pyb_uart_read (mp_obj_t self_in , void * buf_in , mp_uint_t size , int * errcode ) {
208
- pyb_uart_obj_t * self = MP_OBJ_TO_PTR (self_in );
207
+ STATIC mp_uint_t machine_uart_read (mp_obj_t self_in , void * buf_in , mp_uint_t size , int * errcode ) {
208
+ machine_uart_obj_t * self = MP_OBJ_TO_PTR (self_in );
209
209
210
210
if (self -> uart_id == 1 ) {
211
211
nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError , "UART(1) can't read" ));
@@ -233,8 +233,8 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
233
233
}
234
234
}
235
235
236
- STATIC mp_uint_t pyb_uart_write (mp_obj_t self_in , const void * buf_in , mp_uint_t size , int * errcode ) {
237
- pyb_uart_obj_t * self = MP_OBJ_TO_PTR (self_in );
236
+ STATIC mp_uint_t machine_uart_write (mp_obj_t self_in , const void * buf_in , mp_uint_t size , int * errcode ) {
237
+ machine_uart_obj_t * self = MP_OBJ_TO_PTR (self_in );
238
238
const byte * buf = buf_in ;
239
239
240
240
/* TODO implement non-blocking
@@ -254,8 +254,8 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
254
254
return size ;
255
255
}
256
256
257
- STATIC mp_uint_t pyb_uart_ioctl (mp_obj_t self_in , mp_uint_t request , mp_uint_t arg , int * errcode ) {
258
- pyb_uart_obj_t * self = self_in ;
257
+ STATIC mp_uint_t machine_uart_ioctl (mp_obj_t self_in , mp_uint_t request , mp_uint_t arg , int * errcode ) {
258
+ machine_uart_obj_t * self = self_in ;
259
259
mp_uint_t ret ;
260
260
if (request == MP_STREAM_POLL ) {
261
261
mp_uint_t flags = arg ;
@@ -274,19 +274,19 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a
274
274
}
275
275
276
276
STATIC const mp_stream_p_t uart_stream_p = {
277
- .read = pyb_uart_read ,
278
- .write = pyb_uart_write ,
279
- .ioctl = pyb_uart_ioctl ,
277
+ .read = machine_uart_read ,
278
+ .write = machine_uart_write ,
279
+ .ioctl = machine_uart_ioctl ,
280
280
.is_text = false,
281
281
};
282
282
283
- const mp_obj_type_t pyb_uart_type = {
283
+ const mp_obj_type_t machine_uart_type = {
284
284
{ & mp_type_type },
285
285
.name = MP_QSTR_UART ,
286
- .print = pyb_uart_print ,
287
- .make_new = pyb_uart_make_new ,
286
+ .print = machine_uart_print ,
287
+ .make_new = machine_uart_make_new ,
288
288
.getiter = mp_identity_getiter ,
289
289
.iternext = mp_stream_unbuffered_iter ,
290
290
.protocol = & uart_stream_p ,
291
- .locals_dict = (mp_obj_dict_t * )& pyb_uart_locals_dict ,
291
+ .locals_dict = (mp_obj_dict_t * )& machine_uart_locals_dict ,
292
292
};
0 commit comments