From 18bcf61935b1d27d83ce03a490789365da799592 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 18 Dec 2020 10:43:40 +0100 Subject: LCD: fix setup and hold for I2C commands --- sw/deps/hd44780-driver/src/bus/i2c_mcp23008.rs | 5 ++++ sw/deps/hd44780-driver/src/lib.rs | 32 +++++++++++++++++++++++++- sw/picardy/src/main.rs | 8 +++++-- 3 files changed, 42 insertions(+), 3 deletions(-) (limited to 'sw') diff --git a/sw/deps/hd44780-driver/src/bus/i2c_mcp23008.rs b/sw/deps/hd44780-driver/src/bus/i2c_mcp23008.rs index 1ccb479..09a7f2b 100644 --- a/sw/deps/hd44780-driver/src/bus/i2c_mcp23008.rs +++ b/sw/deps/hd44780-driver/src/bus/i2c_mcp23008.rs @@ -84,6 +84,11 @@ impl DataBus for I2CMCP23008Bus { delay.delay_ms(1); + let pins = rs | backlight | (upper_nibble << 3); + self.set_pins(pins)?; + + delay.delay_ms(1); + let pins = rs | backlight | (lower_nibble << 3); self.set_pins(pins)?; diff --git a/sw/deps/hd44780-driver/src/lib.rs b/sw/deps/hd44780-driver/src/lib.rs index 5211346..44421ce 100644 --- a/sw/deps/hd44780-driver/src/lib.rs +++ b/sw/deps/hd44780-driver/src/lib.rs @@ -438,7 +438,37 @@ where // Wait for the command to be processed delay.delay_us(100); - self.bus.write(0x28, false, delay)?; + /* Taken from Arduino's LiquidCrystal.cpp + const LCD_FUNCTIONSET : u8 = 0x20; + const LCD_2LINE : u8 = 0x08; + const LCD_5X8DOTS : u8 = 0x00; + let display_function = LCD_FUNCTIONSET | LCD_2LINE | LCD_5X8DOTS; + self.bus.write(display_function, false, delay)?; + delay.delay_ms(2); + + // turn the display on with no cursor or blinking default + const LCD_DISPLAYCONTROL : u8 = 0x08; + const LCD_DISPLAYON : u8 = 0x04; + const LCD_BLINKOFF : u8 = 0x00; + const LCD_CURSOROFF : u8 = 0x00; + let display_control = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + self.bus.write(LCD_DISPLAYCONTROL | display_control, false, delay)?; + delay.delay_ms(2); + + const LCD_ENTRYLEFT : u8 = 0x02; + const LCD_ENTRYSHIFTDECREMENT : u8 = 0x00; + const LCD_ENTRYMODESET : u8 = 0x04; + self.bus.write(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT, false, delay)?; + delay.delay_ms(2); + + + // Clear Display + const LCD_CLEARDISPLAY : u8 = 0x01; + self.bus.write(LCD_CLEARDISPLAY, false, delay)?; + delay.delay_ms(2); + */ + + self.bus.write(0x28, false, delay)?; // Wait for the command to be processed delay.delay_us(100); diff --git a/sw/picardy/src/main.rs b/sw/picardy/src/main.rs index 04f8fa5..ba2452d 100644 --- a/sw/picardy/src/main.rs +++ b/sw/picardy/src/main.rs @@ -74,6 +74,8 @@ fn main() -> ! { .freeze(&mut flash.acr); let mut delay = Delay::new(cp.SYST, clocks); + delay.delay_ms(200u16); + let mut gpioa = dp.GPIOA.split(&mut rcc.apb2); let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); let mut gpioc = dp.GPIOC.split(&mut rcc.apb2); @@ -150,8 +152,10 @@ fn main() -> ! { }, &mut delay).unwrap(); lcd.set_cursor_pos(0, &mut delay).unwrap(); - lcd.write_str("HB9EGM", &mut delay).unwrap(); - delay.delay_ms(200u8); + lcd.write_str(" HB9EGM ", &mut delay).unwrap(); + lcd.set_cursor_pos(40, &mut delay).unwrap(); + lcd.write_str(" Picardy 2020 ", &mut delay).unwrap(); + delay.delay_ms(1_500u16); // Configure I2C1 to be used for Si5351 let scl = gpiob.pb6.into_alternate_open_drain(&mut gpiob.crl); -- cgit v1.2.3