Tweak some u8g interface code

This commit is contained in:
Scott Lahteine 2019-02-20 04:01:07 -06:00
parent ba39186364
commit 50917ccda6
2 changed files with 22 additions and 30 deletions

View file

@ -68,23 +68,15 @@
static pin_t SCK_pin_ST7920_HAL, MOSI_pin_ST7920_HAL_HAL; static pin_t SCK_pin_ST7920_HAL, MOSI_pin_ST7920_HAL_HAL;
static uint8_t SPI_speed = 0; static uint8_t SPI_speed = 0;
static uint8_t rs_last_state = 255;
static void u8g_com_LPC1768_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) { static void u8g_com_LPC1768_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
static uint8_t rs_last_state = 255;
if (rs != rs_last_state) { // time to send a command/data byte if (rs != rs_last_state) {
// Transfer Data (FA) or Command (F8)
swSpiTransfer(rs ? 0x0FA : 0x0F8, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
rs_last_state = rs; rs_last_state = rs;
DELAY_US(40); // Give the controller time to process the data: 20 is bad, 30 is OK, 40 is safe
if (rs == 0)
/* command */
swSpiTransfer(0x0F8, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
else
/* data */
swSpiTransfer(0x0FA, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
DELAY_US(40); // give the controller some time to process the data: 20 is bad, 30 is OK, 40 is safe
} }
swSpiTransfer(val & 0x0F0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL); swSpiTransfer(val & 0x0F0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
swSpiTransfer(val << 4, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL); swSpiTransfer(val << 4, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
} }

View file

@ -71,23 +71,23 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
OUT_WRITE(ST7920_CLK_PIN, HIGH); OUT_WRITE(ST7920_CLK_PIN, HIGH);
ST7920_CS(); ST7920_CS();
u8g_Delay(120); //initial delay for boot up u8g_Delay(120); // Initial delay for boot up
ST7920_SET_CMD(); ST7920_SET_CMD();
ST7920_WRITE_BYTE(0x20); //non-extended mode ST7920_WRITE_BYTE(0x20); // Non-extended mode
ST7920_WRITE_BYTE(0x08); //display off, cursor+blink off ST7920_WRITE_BYTE(0x08); // Display off, cursor+blink off
ST7920_WRITE_BYTE(0x01); //clear DDRAM ram ST7920_WRITE_BYTE(0x01); // Clear DDRAM ram
u8g_Delay(15); //delay for DDRAM clear u8g_Delay(15); // Delay for DDRAM clear
ST7920_WRITE_BYTE(0x24); //extended mode ST7920_WRITE_BYTE(0x24); // Extended mode
ST7920_WRITE_BYTE(0x26); //extended mode + GDRAM active ST7920_WRITE_BYTE(0x26); // Extended mode + GDRAM active
for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { //clear GDRAM for (y = 0; y < (LCD_PIXEL_HEIGHT) / 2; y++) { // Clear GDRAM
ST7920_WRITE_BYTE(0x80 | y); //set y ST7920_WRITE_BYTE(0x80 | y); // Set y
ST7920_WRITE_BYTE(0x80); //set x = 0 ST7920_WRITE_BYTE(0x80); // Set x = 0
ST7920_SET_DAT(); ST7920_SET_DAT();
for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) // 2x width clears both segments for (i = 0; i < 2 * (LCD_PIXEL_WIDTH) / 8; i++) // 2x width clears both segments
ST7920_WRITE_BYTE(0); ST7920_WRITE_BYTE(0);
ST7920_SET_CMD(); ST7920_SET_CMD();
} }
ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off ST7920_WRITE_BYTE(0x0C); // Display on, cursor+blink off
ST7920_NCS(); ST7920_NCS();
} }
break; break;
@ -112,7 +112,7 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
ST7920_WRITE_BYTE(0x80 | 8); // x = 64 ST7920_WRITE_BYTE(0x80 | 8); // x = 64
} }
ST7920_SET_DAT(); ST7920_SET_DAT();
ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); //ptr is incremented inside of macro ST7920_WRITE_BYTES(ptr, (LCD_PIXEL_WIDTH) / 8); // ptr incremented inside of macro!
y++; y++;
} }
ST7920_NCS(); ST7920_NCS();