busvoodoo_uart.c
Go to the documentation of this file.
/* 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 <http://www.gnu.org/licenses/>.
*
*/
/* standard libraries */
#include <stdint.h> // standard integer types
#include <stdlib.h> // standard utilities
#include <string.h> // string utilities
/* STM32 (including CM3) libraries */
#include <libopencm3/stm32/gpio.h> // general purpose input output library
#include <libopencm3/stm32/rcc.h> // real-time control clock library
#include <libopencm3/stm32/usart.h> // USART utilities
/* own libraries */
#include "global.h" // board definitions
#include "print.h" // printing utilities
#include "menu.h" // menu definitions
#include "usart_enhanced.h" // utilities for USART enhancements
#include "busvoodoo_global.h" // BusVoodoo definitions
#include "busvoodoo_oled.h" // OLED utilities
#include "busvoodoo_uart_generic.h" // generic UART mode
#include "busvoodoo_uart.h" // own definitions
#define BUSVOODOO_UART_USART 3
static const struct busvoodoo_uart_generic_specific_t busvoodoo_uart_generic_uart = {
.usart = USART(BUSVOODOO_UART_USART),
.usart_rcc = RCC_USART(BUSVOODOO_UART_USART),
.usart_rst = RST_USART(BUSVOODOO_UART_USART),
.multidrive = true,
.tx_port = USART_TX_PORT(BUSVOODOO_UART_USART),
.tx_pin = USART_TX_PIN(BUSVOODOO_UART_USART),
.tx_rcc = RCC_USART_PORT(BUSVOODOO_UART_USART),
.tx_pre = NULL,
.tx_post = NULL,
.rx_port = USART_RX_PORT(BUSVOODOO_UART_USART),
.rx_pin = USART_RX_PIN(BUSVOODOO_UART_USART),
.rx_rcc = RCC_USART_PORT(BUSVOODOO_UART_USART),
.rx_pre = NULL,
.rx_post = NULL,
.hwflowctl = true,
.rts_port = USART_RTS_PORT(BUSVOODOO_UART_USART),
.rts_pin = USART_RTS_PIN(BUSVOODOO_UART_USART),
.rts_rcc = RCC_USART_PORT(BUSVOODOO_UART_USART),
.cts_port = USART_CTS_PORT(BUSVOODOO_UART_USART),
.cts_pin = USART_CTS_PIN(BUSVOODOO_UART_USART),
.cts_rcc = RCC_USART_PORT(BUSVOODOO_UART_USART),
};
static bool busvoodoo_uart_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_uart); // provide the UART specific information
}
complete = busvoodoo_uart_generic_setup(prefix, line); // configure underlying generic UART
if (complete) { // generic configuration finished
busvoodoo_led_blue_off(); // disable blue LED because there is no activity
*prefix = "UART"; // display mode
busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
const char* pinout_io[10] = {"GND", "5V", "3V3", "LV", "Rx", "Tx", "RTS", "CTS", NULL, NULL}; // UART mode pinout
for (uint8_t i=0; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
busvoodoo_global_pinout_io[i] = pinout_io[i]; // set pin names
}
if (busvoodoo_full) {
const char* pinout_rscan[5] = {"HV", NULL, NULL, NULL, NULL}; // HiZ mode RS/CAN pinout
for (uint8_t i=0; i<LENGTH(pinout_rscan) && i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
busvoodoo_global_pinout_rscan[i] = pinout_rscan[i]; // set pin names
}
}
busvoodoo_oled_text_pinout((const char**)pinout_io, true); // set pinout on display
busvoodoo_oled_update(); // update display to show text and pinout
}
return complete;
}
static void busvoodoo_uart_exit(void)
{
busvoodoo_uart_generic_exit(); // exiting the underlying generic UART does everything we need
}
const struct busvoodoo_mode_t busvoodoo_uart_mode = {
.name = "uart",
.description = "Universal Asynchronous Receiver-Transmitter",
.full_only = false,
.setup = &busvoodoo_uart_setup,
.commands = busvoodoo_uart_generic_commands,
.commands_nb = busvoodoo_uart_generic_commands_nb,
.exit = &busvoodoo_uart_exit,
};
USART_TX_PORT
#define USART_TX_PORT(x)
get port for USART transmit pin based on USART identifier
Definition: global.h:194
RCC_USART
#define RCC_USART(x)
get RCC for USART based on USART identifier
Definition: global.h:186
busvoodoo_uart_generic_setup
bool busvoodoo_uart_generic_setup(char **prefix, const char *line)
setup generic UART mode
Definition: busvoodoo_uart_generic.c:88
busvoodoo_global.h
BusVoodoo global definitions and methods (API)
busvoodoo_oled_text_pinout
void busvoodoo_oled_text_pinout(const char *pins[10], bool io_connector)
draw pin names on bottom (blue) part in display buffer
Definition: busvoodoo_oled.c:148
busvoodoo_mode_t::name
const char * name
name of the mode (i.e.
Definition: busvoodoo_global.h:114
RCC_USART_PORT
#define RCC_USART_PORT(x)
get RCC for USART port based on USART identifier
Definition: global.h:210
busvoodoo_oled_update
void busvoodoo_oled_update(void)
update OLED display RAM with current display buffer
Definition: busvoodoo_oled.c:289
busvoodoo_global_pinout_rscan
const char * busvoodoo_global_pinout_rscan[5]
RS/CAN connector pinout.
Definition: busvoodoo_global.c:63
global.h
global definitions and methods (API)
busvoodoo_full
bool busvoodoo_full
is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side)
Definition: busvoodoo_global.c:70
busvoodoo_uart_setup
static bool busvoodoo_uart_setup(char **prefix, const char *line)
setup UART mode
Definition: busvoodoo_uart.c:77
busvoodoo_led_blue_off
void busvoodoo_led_blue_off(void)
switch off blue LED
Definition: busvoodoo_global.c:426
USART_RX_PIN
#define USART_RX_PIN(x)
get pin for USART receive pin based on USART identifier
Definition: global.h:204
USART_TX_PIN
#define USART_TX_PIN(x)
get pin for USART transmit pin based on USART identifier
Definition: global.h:202
USART_CTS_PORT
#define USART_CTS_PORT(x)
get port for USART CTS pin based on USART identifier
Definition: global.h:200
BUSVOODOO_UART_USART
#define BUSVOODOO_UART_USART
USART peripheral.
Definition: busvoodoo_uart.c:44
RST_USART
#define RST_USART(x)
get RST for USART based on USART identifier
Definition: global.h:188
busvoodoo_uart_mode
const struct busvoodoo_mode_t busvoodoo_uart_mode
UART mode interface definition.
Definition: busvoodoo_uart.c:111
USART
#define USART(x)
get USART based on USART identifier
Definition: global.h:184
busvoodoo_uart_generic_exit
void busvoodoo_uart_generic_exit(void)
exit genetic UART mode
Definition: busvoodoo_uart_generic.c:274
busvoodoo_global_pinout_io
const char * busvoodoo_global_pinout_io[10]
I/O connector pinout.
Definition: busvoodoo_global.c:62
busvoodoo_uart.h
BusVoodoo UART mode (API)
busvoodoo_uart_generic_commands_nb
#define busvoodoo_uart_generic_commands_nb
number of commands supported by the generic UART mode
Definition: busvoodoo_uart_generic.h:64
USART_RX_PORT
#define USART_RX_PORT(x)
get port for USART receive pin based on USART identifier
Definition: global.h:196
busvoodoo_uart_generic_configure
bool busvoodoo_uart_generic_configure(const struct busvoodoo_uart_generic_specific_t *conf)
provide the generic USART with mode specific information
Definition: busvoodoo_uart_generic.c:69
USART_RTS_PIN
#define USART_RTS_PIN(x)
get pin for USART RTS pin based on USART identifier
Definition: global.h:206
USART_CTS_PIN
#define USART_CTS_PIN(x)
get pin for USART CTS pin based on USART identifier
Definition: global.h:208
busvoodoo_uart_generic.h
BusVoodoo generic UART mode (API)
print.h
printing utilities to replace the large printf from the standard library (API)
busvoodoo_oled_text_left
void busvoodoo_oled_text_left(char *text)
draw mode text on top (yellow) left side in display buffer
Definition: busvoodoo_oled.c:118
busvoodoo_uart_generic_commands
const struct menu_command_t busvoodoo_uart_generic_commands[busvoodoo_uart_generic_commands_nb]
commands supported by the generic UART mode
Definition: busvoodoo_uart_generic.c:655
busvoodoo_uart_generic_uart
static const struct busvoodoo_uart_generic_specific_t busvoodoo_uart_generic_uart
UART specific methods that will be called by the generic methods.
Definition: busvoodoo_uart.c:48
LENGTH
#define LENGTH(x)
get the length of an array
Definition: global.h:26
busvoodoo_oled.h
library to show BusVoodoo mode information on SSD1306 OLED display: name, activity, pinout (API)
busvoodoo_uart_exit
static void busvoodoo_uart_exit(void)
exit UART mode
Definition: busvoodoo_uart.c:106
busvoodoo_mode_t
BusVoodoo mode interface.
Definition: busvoodoo_global.h:113
USART_RTS_PORT
#define USART_RTS_PORT(x)
get port for USART RTS pin based on USART identifier
Definition: global.h:198
usart_enhanced.h
library for enhanced USART communication (API)