/* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ /** BusVoodoo RS-232 mode (code) * @file busvoodoo_rs232.c * @author King Kévin * @date 2018 * @note peripherals used: USART @ref busvoodoo_rs232_usart */ /* standard libraries */ #include // standard integer types #include // standard utilities #include // string utilities /* STM32 (including CM3) libraries */ #include // interrupt utilities #include // general purpose input output library #include // real-time control clock library #include // USART utilities /* own libraries */ #include "global.h" // board definitions #include "print.h" // printing utilities #include "menu.h" // menu definitions #include "busvoodoo_global.h" // BusVoodoo definitions #include "busvoodoo_oled.h" // OLED utilities #include "busvoodoo_uart_generic.h" // generic UART mode #include "busvoodoo_rs232.h" // own definitions /** @defgroup busvoodoo_rs232_usart USART peripheral used for RS-232 communication, using an RS-232 transceiver * @{ */ #define BUSVOODOO_RS232_USART 2 /**< USART peripheral */ /** @} */ #define BUSVOODOO_RS232_RX_TIMER 2 /**< timer ID to capture RX edges */ #define BUSVOODOO_RS232_RX_CHANNEL 4 /**< channel ID used as input capture to capture RX edges */ /** RS-232 specific methods that will be called by the generic methods */ static const struct busvoodoo_uart_generic_specific_t busvoodoo_uart_generic_rs232 = { .usart = USART(BUSVOODOO_RS232_USART), .usart_rcc = RCC_USART(BUSVOODOO_RS232_USART), .usart_rst = RST_USART(BUSVOODOO_RS232_USART), .multidrive = false, .tx_port = USART_TX_PORT(BUSVOODOO_RS232_USART), .tx_pin = USART_TX_PIN(BUSVOODOO_RS232_USART), .tx_rcc = RCC_USART_PORT(BUSVOODOO_RS232_USART), .tx_pre = NULL, .tx_post = NULL, .rx_port = USART_RX_PORT(BUSVOODOO_RS232_USART), .rx_pin = USART_RX_PIN(BUSVOODOO_RS232_USART), .rx_rcc = RCC_USART_PORT(BUSVOODOO_RS232_USART), .rx_pre = NULL, .rx_post = NULL, .hwflowctl = true, .rts_port = USART_RTS_PORT(BUSVOODOO_RS232_USART), .rts_pin = USART_RTS_PIN(BUSVOODOO_RS232_USART), .rts_rcc = RCC_USART_PORT(BUSVOODOO_RS232_USART), .cts_port = USART_CTS_PORT(BUSVOODOO_RS232_USART), .cts_pin = USART_CTS_PIN(BUSVOODOO_RS232_USART), .cts_rcc = RCC_USART_PORT(BUSVOODOO_RS232_USART), .timer = TIM(BUSVOODOO_RS232_RX_TIMER), .timer_rcc = RCC_TIM(BUSVOODOO_RS232_RX_TIMER), .timer_rst = RST_TIM(BUSVOODOO_RS232_RX_TIMER), .timer_port = TIM_CH_PORT(BUSVOODOO_RS232_RX_TIMER, BUSVOODOO_RS232_RX_CHANNEL), .timer_port_rcc = RCC_TIM_CH(BUSVOODOO_RS232_RX_TIMER, BUSVOODOO_RS232_RX_CHANNEL), .timer_pin = TIM_CH_PIN(BUSVOODOO_RS232_RX_TIMER, BUSVOODOO_RS232_RX_CHANNEL), .timer_ic = TIM_IC(BUSVOODOO_RS232_RX_CHANNEL), .timer_ic_in_ti = TIM_IC_IN_TI(BUSVOODOO_RS232_RX_CHANNEL), .timer_sr_ccif = TIM_SR_CCIF(BUSVOODOO_RS232_RX_CHANNEL), .timer_sr_ccof = TIM_SR_CCOF(BUSVOODOO_RS232_RX_CHANNEL), .timer_ccr = &TIM_CCR(BUSVOODOO_RS232_RX_TIMER, BUSVOODOO_RS232_RX_CHANNEL), .timer_dier_ccie = TIM_DIER_CCIE(BUSVOODOO_RS232_RX_CHANNEL), .timer_nvic_irq = NVIC_TIM_IRQ(BUSVOODOO_RS232_RX_TIMER), }; /** setup RS-232 mode * @param[out] prefix terminal prompt prefix * @param[in] line terminal prompt line to configure mode * @return if setup is complete */ static bool busvoodoo_rs232_setup(char** prefix, const char* line) { bool complete = false; // is the setup complete if (NULL==line) { // first call busvoodoo_uart_generic_configure(&busvoodoo_uart_generic_rs232); // provide the RS-232 specific information } complete = busvoodoo_uart_generic_setup(prefix, line); // configure underlying generic UART if (complete) { // generic configuration finished gpio_clear(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set low to enable RS-232 transceiver receiver gpio_set_mode(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_EN_PIN)); // setup RS-232 enable GPIO as output to enable the receiver (pulled high to disable by default) gpio_set(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set high to enable RS-232 transceiver transmitter gpio_set_mode(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_SHDN_PIN)); // setup RS-232 shutdwon GPIO as output to enable the transmitter (pulled low to disable by default) busvoodoo_led_blue_off(); // disable blue LED because there is no activity *prefix = "RS-232"; // display mode busvoodoo_oled_text_left(*prefix); // set mode title on OLED display const char* pinout_io[10] = {"GND", "5V", "3V3", "LV", NULL, NULL, NULL, NULL, NULL, NULL}; // RS-232 mode I/O pinout for (uint8_t i=0; i