2018-04-30 16:15:47 +02:00
|
|
|
#include <pthread.h>
|
2018-04-29 21:57:29 +02:00
|
|
|
#include <wiringPi.h>
|
|
|
|
#include <wiringPiI2C.h>
|
|
|
|
|
2018-04-30 16:15:47 +02:00
|
|
|
#include "lcd.h"
|
|
|
|
|
2018-04-29 21:57:29 +02:00
|
|
|
int lcdFd;
|
2018-04-30 16:15:47 +02:00
|
|
|
pthread_mutex_t sLCD;
|
2018-04-29 21:57:29 +02:00
|
|
|
|
|
|
|
void initLCD()
|
|
|
|
{
|
|
|
|
lcdFd = openI2C(LCD_ADDR);
|
|
|
|
|
|
|
|
// TODO More details
|
|
|
|
sendLCD(0x33, LCD_MODE_CMD); // Initialise
|
|
|
|
sendLCD(0x32, LCD_MODE_CMD); // Initialise
|
|
|
|
sendLCD(0x06, LCD_MODE_CMD); // Cursor move direction
|
|
|
|
sendLCD(0x0C, LCD_MODE_CMD); // Blink Off
|
|
|
|
sendLCD(0x28, LCD_MODE_CMD); // Data length, number of lines, font size
|
|
|
|
sendLCD(0x01, LCD_MODE_CMD); // Clear display
|
|
|
|
delayMicroseconds(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearLCD()
|
|
|
|
{
|
|
|
|
sendLCD(0x01, LCD_MODE_CMD);
|
|
|
|
sendLCD(0x02, LCD_MODE_CMD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gotoLCD(uint8_t line)
|
|
|
|
{
|
|
|
|
sendLCD(line, LCD_MODE_CMD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void charLCD(char c)
|
|
|
|
{
|
|
|
|
sendLCD(c, LCD_MODE_CHR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printLCD(char* s)
|
|
|
|
{
|
|
|
|
while (*s != '\0') {
|
|
|
|
charLCD(*s);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendLCD(uint8_t bits, uint8_t mode)
|
|
|
|
{
|
|
|
|
lockI2C();
|
|
|
|
// High bits
|
|
|
|
uint8_t part = mode | (bits & 0xF0) | LCD_BACKLIGHT;
|
|
|
|
wiringPiI2CReadReg8(lcdFd, part);
|
|
|
|
toggleEnableLCD(part);
|
|
|
|
|
|
|
|
// Low bits
|
|
|
|
part = mode | ((bits << 4) & 0xF0) | LCD_BACKLIGHT;
|
|
|
|
wiringPiI2CReadReg8(lcdFd, part);
|
|
|
|
toggleEnableLCD(part);
|
|
|
|
unlockI2C();
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleEnableLCD(uint8_t bits)
|
|
|
|
{
|
|
|
|
wiringPiI2CReadReg8(lcdFd, (bits | LCD_MASK_ENABLE));
|
|
|
|
delayMicroseconds(1);
|
|
|
|
wiringPiI2CReadReg8(lcdFd, (bits & ~LCD_MASK_ENABLE));
|
|
|
|
delayMicroseconds(50);
|
|
|
|
}
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
void lockLCD()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&sLCD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlockLCD()
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&sLCD);
|
|
|
|
}
|