1
0
mirror of https://github.com/marqs85/ossc.git synced 2024-11-05 19:04:52 +00:00
ossc/software/sys_controller/spi_charlcd/lcd.c

106 lines
2.9 KiB
C
Raw Normal View History

2016-02-22 23:03:50 +00:00
//
// Copyright (C) 2015-2016 Markus Hiienkari <mhiienka@niksula.hut.fi>
2016-02-22 23:03:50 +00:00
//
// This file is part of Open Source Scan Converter project.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include <unistd.h>
#include <string.h>
2016-02-22 23:03:50 +00:00
#include "lcd.h"
#include "alt_types.h"
#include "altera_avalon_pio_regs.h"
#include "i2c_opencores.h"
2016-10-20 22:19:53 +00:00
#include "av_controller.h"
2016-02-22 23:03:50 +00:00
#define LCD_CMD 0x00
#define LCD_DATA 0x40
2016-02-22 23:03:50 +00:00
#define WRDELAY 20
#define CLEARDELAY 800
2016-02-22 23:03:50 +00:00
extern alt_u16 sys_ctrl;
2016-10-20 22:19:53 +00:00
static void lcd_cmd(alt_u8 cmd, alt_u16 postdelay) {
SPI_write(I2CA_BASE, &cmd, 1);
usleep(postdelay);
}
void lcd_init()
{
2016-10-20 22:19:53 +00:00
sys_ctrl &= ~(LCD_CS_N|LCD_RS);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
2016-02-22 23:03:50 +00:00
usleep(WRDELAY);
2016-10-20 22:19:53 +00:00
lcd_cmd(0x38,WRDELAY); // function set
lcd_cmd(0x39,WRDELAY); // function set, select extended table (IS=1)
lcd_cmd(0x14,WRDELAY); // osc freq
lcd_cmd(0x71,WRDELAY); // contrast set
lcd_cmd(0x5E,WRDELAY); // power/icon/cont
lcd_cmd(0x6D,WRDELAY); // follower control
lcd_cmd(0x0C,WRDELAY); // display on
lcd_cmd(0x01,CLEARDELAY); // clear display
lcd_cmd(0x06,WRDELAY); // entry mode set
lcd_cmd(0x02,CLEARDELAY); // return home
sys_ctrl |= LCD_CS_N;
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
2016-02-22 23:03:50 +00:00
}
void lcd_write(char *row1, char *row2)
{
alt_u8 i, rowlen;
2016-02-22 23:03:50 +00:00
2016-10-20 22:19:53 +00:00
sys_ctrl &= ~(LCD_CS_N|LCD_RS);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
2016-02-22 23:03:50 +00:00
2016-10-20 22:19:53 +00:00
lcd_cmd(0x01,CLEARDELAY); // clear display
2016-02-22 23:03:50 +00:00
// Set RS to enter data write mode
2016-10-20 22:19:53 +00:00
sys_ctrl |= LCD_RS;
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
2016-02-22 23:03:50 +00:00
//ensure no empty row
rowlen = strnlen(row1, LCD_ROW_LEN);
if (rowlen == 0) {
strncpy(row1, " ", LCD_ROW_LEN+1);
rowlen++;
}
2016-02-22 23:03:50 +00:00
2016-10-20 22:19:53 +00:00
for (i=0; i<rowlen; i++)
lcd_cmd(row1[i],WRDELAY);
2016-02-22 23:03:50 +00:00
// second row
2016-10-20 22:19:53 +00:00
sys_ctrl &= ~LCD_RS;
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
lcd_cmd((1<<7)|0x40,WRDELAY);
2016-02-22 23:03:50 +00:00
2016-10-20 22:19:53 +00:00
sys_ctrl |= LCD_RS;
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
2016-02-22 23:03:50 +00:00
//ensure no empty row
rowlen = strnlen(row2, LCD_ROW_LEN);
if (rowlen == 0) {
strncpy(row2, " ", LCD_ROW_LEN+1);
rowlen++;
}
2016-10-20 22:19:53 +00:00
for (i=0; i<rowlen; i++)
lcd_cmd(row2[i],WRDELAY);
2016-02-22 23:03:50 +00:00
2016-10-20 22:19:53 +00:00
sys_ctrl |= LCD_CS_N;
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
2016-02-22 23:03:50 +00:00
}