BV: add pinout display functionnality

This commit is contained in:
King Kévin 2018-02-06 17:26:35 +01:00
parent 36e28c873f
commit f840b5f075
2 changed files with 175 additions and 9 deletions

View File

@ -45,9 +45,12 @@
/** @} */
/** blue LED status */
volatile bool busvoodoo_global_led_blue = false;
static volatile bool busvoodoo_global_led_blue = false;
/** red LED status */
volatile bool busvoodoo_global_led_red = false;
static volatile bool busvoodoo_global_led_red = false;
const char* busvoodoo_global_pinout_io[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
const char* busvoodoo_global_pinout_rscan[5] = {NULL, NULL, NULL, NULL, NULL};
const char* busvoodoo_io_names[13] = {"I2C_SMBA/SPI_NSS/I2S_WS", "SDIO_CMD", "USART_CTS/SPI_SCK/I2S_CK", "SDIO_D3/UART_RX", "I2C_SDA/USART_RX", "SDIO_D0", "SPI_MOSI/I2S_SD", "SDIO_CK/USART_CK", "I2C_SCL/USART_TX", "SDIO_D1", "I2S_MCK", "USART_RTS/SPI_MISO", "SDIO_D2/UART_TX"};
const uint32_t busvoodoo_io_ports[13] = {GPIOB, GPIOD, GPIOB, GPIOC, GPIOB, GPIOC, GPIOB, GPIOC, GPIOB, GPIOC, GPIOC, GPIOB, GPIOC};
@ -346,7 +349,8 @@ void busvoodoo_led_red(uint16_t ms)
/** switch 3V3 and 5V power rails on/off
* @param[in] argument string: "on" to switch on, "off" to switch off, NULL to get status
*/
static void busvoodoo_global_power(void* argument) {
static void busvoodoo_global_power(void* argument)
{
float voltage;
if (NULL==argument || 0==strlen(argument)) {
if (gpio_get(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN))) { // check if power rails are switch on (enable low)
@ -376,10 +380,11 @@ power_off:
}
}
/** set xV voltage
/** set lV linear drop-out voltage regulator voltage
* @param[in] argument voltage to set (0 to switch off, NULL to get voltage)
*/
static void busvoodoo_global_lv(void* argument) {
static void busvoodoo_global_lv(void* argument)
{
if (NULL==argument) {
if (!gpio_get(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN))) { // 5V input enabled
printf("5V power rail used");
@ -412,10 +417,11 @@ static void busvoodoo_global_lv(void* argument) {
}
}
/** set 12V voltage
/** set HV step-up voltage regulator voltage
* @param[in] argument voltage to set (0 to switch off, NULL to get voltage)
*/
static void busvoodoo_global_hv(void* argument) {
static void busvoodoo_global_hv(void* argument)
{
if (!busvoodoo_full) {
printf("function not available on BusVoodoo light");
return;
@ -447,6 +453,153 @@ static void busvoodoo_global_hv(void* argument) {
}
}
/** display I/O and RS/CAN connector pinouts
* @param[in] argument not used
*/
static void busvoodoo_global_pinout(void* argument)
{
(void)argument; // argument is not used
bool no_pinout = true; // it no pinout has been displays
// display RS/CAN connector pinout
if (busvoodoo_full) { // only display on full version of the board
bool pin_used = false; // if no pins are used
for (uint8_t i=0; i<LENGTH(busvoodoo_global_pinout_rscan); i++) { // verify if one of the pins is used
pin_used |= (NULL!=busvoodoo_global_pinout_rscan[i]); // verify if pin is used
}
if (pin_used) {
// count the space used to display the pins
uint8_t space = 0; // no integer overflow protected (it's only cosmetic)
for (uint8_t i=0; i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
if (NULL==busvoodoo_global_pinout_rscan[i]) {
space += 1; // only x will be shown
} else {
space += strlen(busvoodoo_global_pinout_rscan[i]); // add size of pin name
}
}
space += LENGTH(busvoodoo_global_pinout_rscan)-1; // add the spaces between the names
// display pinout
printf("RS/CAN connector pinout:\n");
// display top line
printf("+");
for (uint8_t i=0; i<space; i++) {
printf("-");
}
printf("+\n");
// display pin names
printf("|");
for (int8_t i=LENGTH(busvoodoo_global_pinout_rscan); i>=0; i--) {
if (NULL==busvoodoo_global_pinout_rscan[i]) {
printf("x"); // x stands for pin not used
} else {
printf("%s", busvoodoo_global_pinout_rscan[i]); // print pin name
}
if (i>0) {
printf(" "); // print space between the pin names
}
}
printf("|\n");
// display bottom line
printf("+");
for (uint8_t i=0; i<space; i++) {
printf("-");
}
printf("+\n");
no_pinout = false; // remember a pinout has been shown
}
}
// display I/O connector pinout
bool pin_used = false; // if no pins are used
for (uint8_t i=0; i<LENGTH(busvoodoo_global_pinout_io); i++) { // verify if one of the pins is used
pin_used |= (NULL!=busvoodoo_global_pinout_io[i]); // verify if pin is used
}
if (pin_used) {
// count the space used to display the pins (no integer overflow protected, it's only cosmetic)
uint8_t spaces[5] = {0}; // maximum spaces used by top and bottom pins
for (uint8_t i=0; i<LENGTH(spaces); i++) {
if (NULL==busvoodoo_global_pinout_io[i*2]) {
spaces[i] = 1; // only x will be shown
} else {
spaces[i] = strlen(busvoodoo_global_pinout_io[i*2]); // remember size of pin name
}
if (NULL==busvoodoo_global_pinout_io[i*2+1]) {
if (spaces[i]<1) {
spaces[i] = 1; // only x will be shown
}
} else {
if (spaces[i]<strlen(busvoodoo_global_pinout_io[i*2+1])) {
spaces[i] = strlen(busvoodoo_global_pinout_io[i*2+1]); // remember bigger size of pin name
}
}
}
// display pinout
printf("I/O connector pinout:\n");
// display top line
printf("+");
for (uint16_t i=0; i<(uint16_t)(spaces[4]+spaces[3]+1); i++) {
printf("-");
}
for (uint16_t i=0; i<(uint16_t)(spaces[2]+2); i++) {
printf(" ");
}
for (uint16_t i=0; i<(uint16_t)(spaces[1]+spaces[0]+1); i++) {
printf("-");
}
printf("+\n");
// display top pin names
printf("|");
for (int8_t i=4; i>=0; i--) {
if (NULL==busvoodoo_global_pinout_io[i*2]) {
printf("x"); // x stands for pin not used
for (int16_t j=0; j<spaces[i]-1; j++) {
printf(" "); // pad to match to bottom pin
}
} else {
printf("%s", busvoodoo_global_pinout_io[i*2]); // print pin name
for (int16_t j=0; j+strlen(busvoodoo_global_pinout_io[i*2])<spaces[i]; j++) {
printf(" "); // pad to match to bottom pin
}
}
if (i>0) {
printf(" "); // print space between the pin names
}
}
printf("|\n");
// display bottom pin names
printf("|");
for (int8_t i=4; i>=0; i--) {
if (NULL==busvoodoo_global_pinout_io[i*2+1]) {
printf("x"); // x stands for pin not used
for (int16_t j=0; j<spaces[i]-1; j++) {
printf(" "); // pad to match to bottom pin
}
} else {
printf("%s", busvoodoo_global_pinout_io[i*2+1]); // print pin name
for (int16_t j=0; j+strlen(busvoodoo_global_pinout_io[i*2+1])<spaces[i]; j++) {
printf(" "); // pad to match to bottom pin
}
}
if (i>0) {
printf(" "); // print space between the pin names
}
}
printf("|\n");
// display bottom line
printf("+");
for (uint16_t i=0; i<spaces[4]+1+spaces[3]+1+spaces[2]+1+spaces[1]+1+spaces[0]; i++) {
printf("-");
}
printf("+\n");
no_pinout = false; // remember a pinout has been shown
}
// in case nothing has been displayed
if (no_pinout) {
printf("no pins are used\n");
}
}
/** list of supported commands */
const struct menu_command_t busvoodoo_global_commands[] = {
{
@ -473,6 +626,14 @@ const struct menu_command_t busvoodoo_global_commands[] = {
"[voltage]",
&busvoodoo_global_hv,
},
{
'c',
"connector",
"show connector pinout",
MENU_ARGUMENT_NONE,
NULL,
&busvoodoo_global_pinout,
},
};
/** interrupt service routine called on LED timeout */

View File

@ -106,10 +106,15 @@ extern const uint32_t busvoodoo_io_pins[13]; /**< pin of individual signals */
extern const uint8_t busvoodoo_io_groups[13]; /**< which I/O pin (group) does the signal belong to */
/** @} */
/** is the BusVoodoo board fully populated (with 12V voltage regulator, RS-232, RS-485, CAN transceiver on the back side) */
/** is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side) */
extern bool busvoodoo_full;
/** list of supported commands */
extern const struct menu_command_t busvoodoo_global_commands[3];
extern const struct menu_command_t busvoodoo_global_commands[4];
/** I/O connector pinout */
extern const char* busvoodoo_global_pinout_io[10];
/** RS/CAN connector pinout */
extern const char* busvoodoo_global_pinout_rscan[5];
/** setup BusVoodoo board */
void busvoodoo_setup(void);