/*
 * hal_LCD.h
 *
 *  Created on: Nov 4, 2011
 *      Author: RomanM
 */
#ifndef HAL_LCD_H_
#define HAL_LCD_H_

#include <stdint.h>

#define	LCD_4bit								// Set 4-bit mode
#define	LCD_BL_MAX		5000					// Maximum value of backlight intensity

#define	LCD_PORT		GPIOC					// LCD port
#define	LCD_GPIO_CLOCK	RCC_APB2Periph_GPIOC

#define	LCD_E_PIN		GPIO_Pin_5
#define	LCD_RW_PIN		GPIO_Pin_6
#define	LCD_RS_PIN		GPIO_Pin_7

#define	LCD_DATA_ROT	8						// Rotation to be first byte at 0
#define	LCD_D0_PIN		0
#define	LCD_D1_PIN		0
#define	LCD_D2_PIN		0
#define	LCD_D3_PIN		0
#define	LCD_D4_PIN		GPIO_Pin_8
#define	LCD_D5_PIN		GPIO_Pin_9
#define	LCD_D6_PIN		GPIO_Pin_10
#define	LCD_D7_PIN		GPIO_Pin_11

#define hal_LCD_Wait15ms()	hal_LCD_Delay(360000);
#define hal_LCD_Wait4_1ms()	hal_LCD_Delay(98400);
#define	hal_LCD_Wait100us()	hal_LCD_Delay(2400);
#define	hal_LCD_Wait1us()	hal_LCD_Delay(30);

void hal_LCD_Init(void);
void hal_LCD_BL_Init(void);

void hal_LCD_Port_Out(void);
void hal_LCD_Port_In(void);

void hal_LCD_BL_Set(uint16_t value);

void hal_LCD_DataOut_4bit(uint8_t data);
void hal_LCD_DataOut_8bit(uint8_t data);

uint8_t hal_LCD_DataIn_4bit(void);
uint8_t hal_LCD_DataIn_8bit(void);

void hal_LCD_E(uint8_t state);
void hal_LCD_RW(uint8_t state);
void hal_LCD_RS(uint8_t state);

void hal_LCD_Delay(uint32_t nTick);

#endif /* HAL_LCD_H_ */
