/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2020-10-24 thread-liu first version * 2023-05-05 yuanjie add test method */ #include #include #include #include "drv_rs485.h" #ifdef BSP_USING_RS485 #define RS485_OUT rt_pin_write(BSP_RS485_RTS_PIN, PIN_HIGH) #define RS485_IN rt_pin_write(BSP_RS485_RTS_PIN, PIN_LOW) rt_device_t rs485_serial = {0}; struct rt_semaphore rs485_rx_sem = {0}; /* uart send data callback function */ static rt_err_t rs485_output(rt_device_t dev, void * buffer) { return RT_EOK; } /* uart receive data callback function */ static rt_err_t rs485_input(rt_device_t dev, rt_size_t size) { rt_sem_release(&rs485_rx_sem); return RT_EOK; } /* send string */ int rs485_send_data(char *tbuf, rt_uint16_t t_len) { /* change rs485 mode */ RS485_OUT; /* send data */ rt_device_write(rs485_serial, 0, tbuf, t_len); /* change rs485 mode */ RS485_IN; rt_kprintf("\nsend:"); for(int i =0;i