From 29cebd42bf2f748c23018cc64a102ca3e589526c Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Tue, 19 Jan 2021 00:34:24 -0500 Subject: Currently segfaults. Maybe because serial is in use? --- 3rd-party/LCDHD44780.c | 128 ------------------------------------------------- 3rd-party/LCDHD44780.h | 15 +++--- src/ct1986.c | 4 ++ 3 files changed, 10 insertions(+), 137 deletions(-) diff --git a/3rd-party/LCDHD44780.c b/3rd-party/LCDHD44780.c index 32c8ce2..e7837d0 100644 --- a/3rd-party/LCDHD44780.c +++ b/3rd-party/LCDHD44780.c @@ -29,7 +29,6 @@ void init_gpio(void) { // Set all pins to output bcm2835_gpio_fsel(LCD_RS, BCM2835_GPIO_FSEL_OUTP); - bcm2835_gpio_fsel(LCD_RW, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(LCD_D4, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(LCD_D5, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(LCD_D6, BCM2835_GPIO_FSEL_OUTP); @@ -40,7 +39,6 @@ void init_gpio(void) // Set all pins to LOW bcm2835_gpio_clr(LCD_RS); - bcm2835_gpio_clr(LCD_RW); bcm2835_gpio_clr(LCD_D4); bcm2835_gpio_clr(LCD_D5); bcm2835_gpio_clr(LCD_D5); @@ -78,65 +76,6 @@ void pulse_e(void) (LCD_DATA) ? bcm2835_delayMicroseconds(E_DATA_PULSE) :bcm2835_delayMicroseconds(E_CMD_PULSE); } -uint8_t busy_wait(void) -{ - // FIXME: this function does not work! - // With RW grounded it shouldn't work. - // But as long as the display is driven - // by 5V the GPIO ports on a raspberry pi - // would get to much voltage - - uint8_t addr; - bool wait = true; - uint16_t counter = 0; - - set_data_pins_to_input(); - - bcm2835_gpio_clr(LCD_RS); - bcm2835_gpio_set(LCD_RW); - - while(wait && (counter < MAX_WAIT)) - { - addr = 0; - pulse_e(); - - // read high bits - if (bcm2835_gpio_lev(LCD_D4)) - addr = (addr | 0x10); - if (bcm2835_gpio_lev(LCD_D5)) - addr = (addr | 0x20); - if (bcm2835_gpio_lev(LCD_D6)) - addr = (addr | 0x40); - if (bcm2835_gpio_lev(LCD_D7)) - addr = (addr | 0x80); - - // Toogle ENABLE pin in us - pulse_e(); - - // read low bits - if (bcm2835_gpio_lev(LCD_D4)) - addr = (addr | 0x01); - if (bcm2835_gpio_lev(LCD_D5)) - addr = (addr | 0x02); - if (bcm2835_gpio_lev(LCD_D6)) - addr = (addr | 0x04); - if (bcm2835_gpio_lev(LCD_D7)) - addr = (addr | 0x08); - - wait = (addr & 0x80); - counter += 1; - - bcm2835_delay(1); - } - - bcm2835_gpio_clr(LCD_RW); - set_data_pins_to_output(); - - // return address but mask out highest bit (busy flag) - // 0x7F = 0 1 1 1 1 1 1 1 - return (addr & 0x7F); -} - void init_lcd(void) { init_gpio(); @@ -435,72 +374,6 @@ void write_string(char *str) } } -uint8_t read_from_lcd(uint8_t mode) -{ - // FIXME: this function currently does not work! - // Assuming, the display is driven by 5V - // then the GPIO Ports on a Raspberry Pi - // would get 5V what definitly is too much - uint8_t addr = 0x00; - - bcm2835_gpio_clr(LCD_E); - - bcm2835_gpio_clr(LCD_D4); - bcm2835_gpio_clr(LCD_D5); - bcm2835_gpio_clr(LCD_D6); - bcm2835_gpio_clr(LCD_D7); - - switch (mode) { - case LCD_CMD: - bcm2835_gpio_clr(LCD_RS); - // fprintf(stdout, "Set RS to cmd mode\n"); - break; - case LCD_DATA: - bcm2835_gpio_set(LCD_RS); - // fprintf(stdout, "Set RS to data mode for '%c'\n", byte); - break; - default: - // fprintf(stderr, "mode for setting GPIO pin unknown: %i\n", mode); - exit(EXIT_FAILURE); - } - - set_data_pins_to_input(); - bcm2835_delay(5); - - bcm2835_gpio_set(LCD_RW); - - pulse_e(); - - // read high bits - if (bcm2835_gpio_lev(LCD_D4)) - addr = (addr | 0x10); - if (bcm2835_gpio_lev(LCD_D5)) - addr = (addr | 0x20); - if (bcm2835_gpio_lev(LCD_D6)) - addr = (addr | 0x40); - if (bcm2835_gpio_lev(LCD_D7)) - addr = (addr | 0x80); - - // Toogle ENABLE pin in us - pulse_e(); - - // read low bits - if (bcm2835_gpio_lev(LCD_D4)) - addr = (addr | 0x01); - if (bcm2835_gpio_lev(LCD_D5)) - addr = (addr | 0x02); - if (bcm2835_gpio_lev(LCD_D6)) - addr = (addr | 0x04); - if (bcm2835_gpio_lev(LCD_D7)) - addr = (addr | 0x08); - - bcm2835_gpio_clr(LCD_RW); - - set_data_pins_to_output(); - - return addr; -} - void gpio_reset(void) { // bcm2835_gpio_fsel(LCD_RS, BCM2835_GPIO_PUD_OFF); @@ -518,7 +391,6 @@ void gpio_reset(void) // bcm2835_gpio_fsel(LCD_D7, BCM2835_GPIO_FSEL_INPT); bcm2835_gpio_clr(LCD_RS); - bcm2835_gpio_clr(LCD_RW); bcm2835_gpio_clr(LCD_E); bcm2835_gpio_clr(LCD_D4); bcm2835_gpio_clr(LCD_D5); diff --git a/3rd-party/LCDHD44780.h b/3rd-party/LCDHD44780.h index d25f046..8e2e953 100644 --- a/3rd-party/LCDHD44780.h +++ b/3rd-party/LCDHD44780.h @@ -51,13 +51,12 @@ #include // Define GPIO pin to LCD pin mapping -#define LCD_RS RPI_V2_GPIO_P1_26 -#define LCD_RW RPI_V2_GPIO_P1_07 -#define LCD_E RPI_V2_GPIO_P1_24 -#define LCD_D4 RPI_V2_GPIO_P1_22 -#define LCD_D5 RPI_V2_GPIO_P1_18 -#define LCD_D6 RPI_V2_GPIO_P1_16 -#define LCD_D7 RPI_V2_GPIO_P1_12 +#define LCD_RS 21 +#define LCD_E 20 +#define LCD_D4 26 +#define LCD_D5 19 +#define LCD_D6 13 +#define LCD_D7 6 // Define some device constants // Maximum characters per line @@ -173,8 +172,6 @@ void clear_lcd(void); void set_cursor(uint8_t addr); -uint8_t busy_wait(void); - void display_off(void); void show_cursor(bool on); diff --git a/src/ct1986.c b/src/ct1986.c index 56c76b1..44e64e7 100644 --- a/src/ct1986.c +++ b/src/ct1986.c @@ -158,6 +158,10 @@ main(int argc, char **argv) { (void)(argc); (void)(argv); + puts("Init."); + init_lcd(); + puts("Starting up."); + // Set up output function for ct1986 ct1986_display_progress = ˙ -- cgit v1.2.3