From 3cb4b3689ee4a684b52ab3c511fe4a9dfd791200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 12 Dec 2019 19:00:13 +0100 Subject: [PATCH] application: add LCD initialisation --- application.c | 44 ++++++++++++++++++++++++++++++++++---------- lib/lcd_hd44780.h | 2 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/application.c b/application.c index 1d8562f..9cdabcc 100644 --- a/application.c +++ b/application.c @@ -45,6 +45,7 @@ #include "terminal.h" // handle the terminal interface #include "menu.h" // menu utilities #include "usb_cables.h" // USB cables definition +#include "lcd_hd44780.h" // LCD utilities /** watchdog period in ms */ #define WATCHDOG_PERIOD 10000 @@ -165,6 +166,15 @@ static void command_inter(void* argument) */ static void command_cables(void* argument) { + // get cable number + uint8_t cable_i = 0xff; + if (argument) { + cable_i = *(uint32_t*)argument; + if (cable_i >= LENGTH(usb_cables)) { + printf("cable number %u out of range 0-%u\n", cable_i, LENGTH(usb_cables) - 1); + return; + } + } (void)argument; // we won't use the argument usb_pins_float(); // start with all pins in safe floating state @@ -172,9 +182,11 @@ static void command_cables(void* argument) // step 2: check for known cable configuration printf("= cable check =\n"); for (uint8_t cable = 0; cable < LENGTH(usb_cables); cable++) { // test every cable - uint8_t pair_defined, pair_undefined; - bool result = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, false); - printf("%s: %s (defined=%u/%u, undefined=%u)\n", result ? "OK" : "KO", usb_cables[cable].name, pair_defined, usb_cables[cable].pin_pairs_nb, pair_undefined); + if (0xff == cable_i || cable == cable_i) { + uint8_t pair_defined, pair_undefined; + bool result = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, false); + printf("%02u %s: %s (defined=%u/%u, undefined=%u)\n", cable, result ? "OK" : "KO", usb_cables[cable].name, pair_defined, usb_cables[cable].pin_pairs_nb, pair_undefined); + } } usb_pins_float(); // put all pins back in safe floating state @@ -563,9 +575,9 @@ static const struct menu_command_t menu_commands[] = { { .shortcut = 'c', .name = "cables", - .command_description = "test cables", - .argument = MENU_ARGUMENT_NONE, - .argument_description = NULL, + .command_description = "test cable(s)", + .argument = MENU_ARGUMENT_UNSIGNED, + .argument_description = "[nb]", .command_handler = &command_cables, }, { @@ -797,6 +809,20 @@ void main(void) nvic_enable_irq(NVIC_RTC_IRQ); // allow the RTC to interrupt time_start = rtc_get_counter_val(); // get start time from internal RTC + // setup LCD display + printf("setup LCD: "); + led_on(); // this actually power the I²C backpack and display + lcd_hd44780_i2c_addr = 0x3f; + if (lcd_hd44780_setup(true, false)) { + lcd_hd44780_display_control(true, false, true); + lcd_hd44780_write_line(false, "USB cable tester", 16); + lcd_hd44780_write_line(true, "testing ...", 11); + printf("OK"); + } else { + printf("KO"); + } + putc('\n'); + // setup USB connectors gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0); // only use SWD and reuse JTAG pins rcc_periph_clock_enable(RCC_GPIOA); // enable clock to all GPIO port domains since we use them all @@ -819,16 +845,14 @@ void main(void) iwdg_reset(); // kick the dog if (user_input_available) { // user input is available action = true; // action has been performed - led_toggle(); // toggle LED + //led_toggle(); // toggle LED char c = user_input_get(); // store receive character terminal_send(c); // send received character to terminal } if (rtc_internal_tick_flag) { // the internal RTC ticked rtc_internal_tick_flag = false; // reset flag action = true; // action has been performed - if (0 == (rtc_get_counter_val() % RTC_TICKS_SECOND)) { // one seond has passed - led_toggle(); // toggle LED (good to indicate if main function is stuck) - } + //led_toggle(); // toggle LED (good to indicate if main function is stuck) } if (action) { // go to sleep if nothing had to be done, else recheck for activity action = false; diff --git a/lib/lcd_hd44780.h b/lib/lcd_hd44780.h index fc2f9b6..25450bf 100644 --- a/lib/lcd_hd44780.h +++ b/lib/lcd_hd44780.h @@ -25,7 +25,7 @@ * @{ */ /** set I²C peripheral if I²C backpack adapter(s) is(/are) used */ -//#define LCD_HD44780_I2C I2C1 +#define LCD_HD44780_I2C I2C1 /** @} */ #ifdef LCD_HD44780_I2C