5353//|
5454//| :param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only.
5555//| :param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only.
56+ //| :param ~microcontroller.Pin rts: the pin for rts, or ``None`` if rts not in use.
57+ //| :param ~microcontroller.Pin cts: the pin for cts, or ``None`` if cts not in use.
58+ //| :param ~microcontroller.Pin rs485_dir: the pin for rs485 direction setting, or ``None`` if rs485 not in use.
59+ //| :param bool rs485_invert: set to invert the sense of the rs485_dir pin.
5660//| :param int baudrate: the transmit and receive speed.
5761//| :param int bits: the number of bits per byte, 7, 8 or 9.
5862//| :param Parity parity: the parity used for error checking.
@@ -82,7 +86,8 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
8286 // https://github.com/adafruit/circuitpython/issues/1056)
8387 busio_uart_obj_t * self = m_new_ll_obj (busio_uart_obj_t );
8488 self -> base .type = & busio_uart_type ;
85- enum { ARG_tx , ARG_rx , ARG_baudrate , ARG_bits , ARG_parity , ARG_stop , ARG_timeout , ARG_receiver_buffer_size , ARG_rts , ARG_cts , ARG_rs485 };
89+ enum { ARG_tx , ARG_rx , ARG_baudrate , ARG_bits , ARG_parity , ARG_stop , ARG_timeout , ARG_receiver_buffer_size ,
90+ ARG_rts , ARG_cts , ARG_rs485_dir ,ARG_rs485_invert };
8691 static const mp_arg_t allowed_args [] = {
8792 { MP_QSTR_tx , MP_ARG_REQUIRED | MP_ARG_OBJ },
8893 { MP_QSTR_rx , MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -94,7 +99,8 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
9499 { MP_QSTR_receiver_buffer_size , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 64 } },
95100 { MP_QSTR_rts , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
96101 { MP_QSTR_cts , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
97- { MP_QSTR_rs485 , MP_ARG_KW_ONLY | MP_ARG_BOOL , {.u_bool = false } },
102+ { MP_QSTR_rs485_dir , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
103+ { MP_QSTR_rs485_invert , MP_ARG_KW_ONLY | MP_ARG_BOOL , {.u_bool = false } },
98104 };
99105 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
100106 mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
@@ -131,9 +137,10 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
131137
132138 const mcu_pin_obj_t * cts = MP_OBJ_TO_PTR (args [ARG_cts ].u_obj );
133139
134- bool rs485 = args [ARG_rs485 ].u_bool ;
140+ const mcu_pin_obj_t * rs485_dir = args [ARG_rs485_dir ].u_obj ;
141+ bool rs485_invert = args [ARG_rs485_invert ].u_bool ;
135142
136- common_hal_busio_uart_construct (self , tx , rx , rts , cts , rs485 ,
143+ common_hal_busio_uart_construct (self , tx , rx , rts , cts , rs485_dir , rs485_invert ,
137144 args [ARG_baudrate ].u_int , bits , parity , stop , timeout ,
138145 args [ARG_receiver_buffer_size ].u_int );
139146 return (mp_obj_t )self ;
0 commit comments