CuVoodoo STM32F1 firmware template
busvoodoo_uart.c
Go to the documentation of this file.
1 /* This program is free software: you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation, either version 3 of the License, or
4  * (at your option) any later version.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program. If not, see <http://www.gnu.org/licenses/>.
13  *
14  */
21 /* standard libraries */
22 #include <stdint.h> // standard integer types
23 #include <stdlib.h> // standard utilities
24 #include <string.h> // string utilities
25 
26 /* STM32 (including CM3) libraries */
27 #include <libopencm3/stm32/gpio.h> // general purpose input output library
28 #include <libopencm3/stm32/rcc.h> // real-time control clock library
29 #include <libopencm3/stm32/usart.h> // USART utilities
30 
31 /* own libraries */
32 #include "global.h" // board definitions
33 #include "print.h" // printing utilities
34 #include "menu.h" // menu definitions
35 #include "usart_enhanced.h" // utilities for USART enhancements
36 #include "busvoodoo_global.h" // BusVoodoo definitions
37 #include "busvoodoo_oled.h" // OLED utilities
38 #include "busvoodoo_uart_generic.h" // generic UART mode
39 #include "busvoodoo_uart.h" // own definitions
40 
44 #define BUSVOODOO_UART_USART 3
48 static const struct busvoodoo_uart_generic_specific_t busvoodoo_uart_generic_uart = {
49  .usart = USART(BUSVOODOO_UART_USART),
50  .usart_rcc = RCC_USART(BUSVOODOO_UART_USART),
51  .usart_rst = RST_USART(BUSVOODOO_UART_USART),
52  .multidrive = true,
56  .tx_pre = NULL,
57  .tx_post = NULL,
61  .rx_pre = NULL,
62  .rx_post = NULL,
63  .hwflowctl = true,
70 };
71 
77 static bool busvoodoo_uart_setup(char** prefix, const char* line)
78 {
79  bool complete = false; // is the setup complete
80  if (NULL==line) { // first call
81  busvoodoo_uart_generic_configure(&busvoodoo_uart_generic_uart); // provide the UART specific information
82  }
83  complete = busvoodoo_uart_generic_setup(prefix, line); // configure underlying generic UART
84  if (complete) { // generic configuration finished
85  busvoodoo_led_blue_off(); // disable blue LED because there is no activity
86  *prefix = "UART"; // display mode
87  busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
88  const char* pinout_io[10] = {"GND", "5V", "3V3", "LV", "Rx", "Tx", "RTS", "CTS", NULL, NULL}; // UART mode pinout
89  for (uint8_t i=0; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
90  busvoodoo_global_pinout_io[i] = pinout_io[i]; // set pin names
91  }
92  if (busvoodoo_full) {
93  const char* pinout_rscan[5] = {"HV", NULL, NULL, NULL, NULL}; // HiZ mode RS/CAN pinout
94  for (uint8_t i=0; i<LENGTH(pinout_rscan) && i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
95  busvoodoo_global_pinout_rscan[i] = pinout_rscan[i]; // set pin names
96  }
97  }
98  busvoodoo_oled_text_pinout((const char**)pinout_io, true); // set pinout on display
99  busvoodoo_oled_update(); // update display to show text and pinout
100  }
101  return complete;
102 }
103 
106 static void busvoodoo_uart_exit(void)
107 {
108  busvoodoo_uart_generic_exit(); // exiting the underlying generic UART does everything we need
109 }
110 
112  .name = "uart",
113  .description = "Universal Asynchronous Receiver-Transmitter",
114  .full_only = false,
115  .setup = &busvoodoo_uart_setup,
117  .commands_nb = busvoodoo_uart_generic_commands_nb,
118  .exit = &busvoodoo_uart_exit,
119 };
#define USART_TX_PORT(x)
get port for USART transmit pin based on USART identifier
Definition: global.h:194
#define RCC_USART(x)
get RCC for USART based on USART identifier
Definition: global.h:186
bool busvoodoo_uart_generic_setup(char **prefix, const char *line)
setup generic UART mode
BusVoodoo global definitions and methods (API)
void busvoodoo_oled_text_pinout(const char *pins[10], bool io_connector)
draw pin names on bottom (blue) part in display buffer
const char * name
name of the mode (i.e.
#define RCC_USART_PORT(x)
get RCC for USART port based on USART identifier
Definition: global.h:210
void busvoodoo_oled_update(void)
update OLED display RAM with current display buffer
const char * busvoodoo_global_pinout_rscan[5]
RS/CAN connector pinout.
global definitions and methods (API)
bool busvoodoo_full
is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side)
static bool busvoodoo_uart_setup(char **prefix, const char *line)
setup UART mode
void busvoodoo_led_blue_off(void)
switch off blue LED
#define USART_RX_PIN(x)
get pin for USART receive pin based on USART identifier
Definition: global.h:204
#define USART_TX_PIN(x)
get pin for USART transmit pin based on USART identifier
Definition: global.h:202
#define USART_CTS_PORT(x)
get port for USART CTS pin based on USART identifier
Definition: global.h:200
#define BUSVOODOO_UART_USART
USART peripheral.
#define RST_USART(x)
get RST for USART based on USART identifier
Definition: global.h:188
const struct busvoodoo_mode_t busvoodoo_uart_mode
UART mode interface definition.
#define USART(x)
get USART based on USART identifier
Definition: global.h:184
void busvoodoo_uart_generic_exit(void)
exit genetic UART mode
const char * busvoodoo_global_pinout_io[10]
I/O connector pinout.
BusVoodoo UART mode (API)
#define busvoodoo_uart_generic_commands_nb
number of commands supported by the generic UART mode
#define USART_RX_PORT(x)
get port for USART receive pin based on USART identifier
Definition: global.h:196
bool busvoodoo_uart_generic_configure(const struct busvoodoo_uart_generic_specific_t *conf)
provide the generic USART with mode specific information
#define USART_RTS_PIN(x)
get pin for USART RTS pin based on USART identifier
Definition: global.h:206
#define USART_CTS_PIN(x)
get pin for USART CTS pin based on USART identifier
Definition: global.h:208
BusVoodoo generic UART mode (API)
void busvoodoo_oled_text_left(char *text)
draw mode text on top (yellow) left side in display buffer
const struct menu_command_t busvoodoo_uart_generic_commands[busvoodoo_uart_generic_commands_nb]
commands supported by the generic UART mode
static const struct busvoodoo_uart_generic_specific_t busvoodoo_uart_generic_uart
UART specific methods that will be called by the generic methods.
#define LENGTH(x)
get the length of an array
Definition: global.h:26
library to show BusVoodoo mode information on SSD1306 OLED display: name, activity, pinout (API)
static void busvoodoo_uart_exit(void)
exit UART mode
BusVoodoo mode interface.
#define USART_RTS_PORT(x)
get port for USART RTS pin based on USART identifier
Definition: global.h:198
library for enhanced USART communication (API)