/*
 * LCD.H
 *
 *  Created on: 26.4.2010
 *      Author: hudo
 */

#ifndef LCD_H_
#define LCD_H_

#include "MCF52233_PE.h"
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "FreeRTOS.h"
#include "queue.h"
#include "semphr.h"
#include "task.h"

/*
** ===================================================================
**     Method      :  E_GetVal (component BitIO)
**
**     Description :
**         This method returns an input value.
**           a) direction = Input  : reads the input value from the
**                                   pin and returns it
**           b) direction = Output : returns the last written value
**         Note: This component is set to work in Output direction only.
**     Parameters  : None
**     Returns     :
**         ---             - Input value. Possible values:
**                           FALSE - logical "0" (Low level)
**                           TRUE - logical "1" (High level)

** ===================================================================
*/
#define E_GetVal() ( \
    (bool)((getReg8(PORTAN) & 0x20))   /* Return port output data */ \
  )

/*
** ===================================================================
**     Method      :  E_PutVal (component BitIO)
**
**     Description :
**         This method writes the new output value.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Val             - Output value. Possible values:
**                           FALSE - logical "0" (Low level)
**                           TRUE - logical "1" (High level)
**     Returns     : Nothing
** ===================================================================
*/
void E_PutVal(bool Val);

/*
** ===================================================================
**     Method      :  E_ClrVal (component BitIO)
**
**     Description :
**         This method clears (sets to zero) the output value.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
#define E_ClrVal() ( \
    (void)setReg8(CLRAN, 0xDF)         /* CLRAN5=0x00 */ \
  )

/*
** ===================================================================
**     Method      :  E_SetVal (component BitIO)
**
**     Description :
**         This method sets (sets to one) the output value.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
#define E_SetVal() ( \
    (void)setReg8(SETAN, 0x20)         /* SETAN5=0x01 */ \
  )

/*
** ===================================================================
**     Method      :  RS_GetVal (component BitIO)
**
**     Description :
**         This method returns an input value.
**           a) direction = Input  : reads the input value from the
**                                   pin and returns it
**           b) direction = Output : returns the last written value
**         Note: This component is set to work in Output direction only.
**     Parameters  : None
**     Returns     :
**         ---             - Input value. Possible values:
**                           FALSE - logical "0" (Low level)
**                           TRUE - logical "1" (High level)

** ===================================================================
*/
#define RS_GetVal() ( \
    (bool)((getReg8(PORTAN) & 0x80))   /* Return port output data */ \
  )

/*
** ===================================================================
**     Method      :  RS_PutVal (component BitIO)
**
**     Description :
**         This method writes the new output value.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Val             - Output value. Possible values:
**                           FALSE - logical "0" (Low level)
**                           TRUE - logical "1" (High level)
**     Returns     : Nothing
** ===================================================================
*/
void RS_PutVal(bool Val);

/*
** ===================================================================
**     Method      :  RS_ClrVal (component BitIO)
**
**     Description :
**         This method clears (sets to zero) the output value.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
#define RS_ClrVal() ( \
    (void)setReg8(CLRAN, 0x7F)         /* CLRAN7=0x00 */ \
  )

/*
** ===================================================================
**     Method      :  RS_SetVal (component BitIO)
**
**     Description :
**         This method sets (sets to one) the output value.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
#define RS_SetVal() ( \
    (void)setReg8(SETAN, 0x80)         /* SETAN7=0x01 */ \
  )

/*
** ===================================================================
**     Method      :  RW_GetVal (component BitIO)
**
**     Description :
**         This method returns an input value.
**           a) direction = Input  : reads the input value from the
**                                   pin and returns it
**           b) direction = Output : returns the last written value
**         Note: This component is set to work in Output direction only.
**     Parameters  : None
**     Returns     :
**         ---             - Input value. Possible values:
**                           FALSE - logical "0" (Low level)
**                           TRUE - logical "1" (High level)

** ===================================================================
*/
#define RW_GetVal() ( \
    (bool)((getReg8(PORTAN) & 0x40))   /* Return port output data */ \
  )

/*
** ===================================================================
**     Method      :  RW_PutVal (component BitIO)
**
**     Description :
**         This method writes the new output value.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Val             - Output value. Possible values:
**                           FALSE - logical "0" (Low level)
**                           TRUE - logical "1" (High level)
**     Returns     : Nothing
** ===================================================================
*/
void RW_PutVal(bool Val);

/*
** ===================================================================
**     Method      :  RW_ClrVal (component BitIO)
**
**     Description :
**         This method clears (sets to zero) the output value.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
#define RW_ClrVal() ( \
    (void)setReg8(CLRAN, 0xBF)         /* CLRAN6=0x00 */ \
  )

/*
** ===================================================================
**     Method      :  RW_SetVal (component BitIO)
**
**     Description :
**         This method sets (sets to one) the output value.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
#define RW_SetVal() ( \
    (void)setReg8(SETAN, 0x40)         /* SETAN6=0x01 */ \
  )

/*
** ===================================================================
**     Method      :  LCD_DATA_GetVal (component BitsIO)
**
**     Description :
**         This method returns an input value.
**           a) direction = Input  : reads the input value from the
**                                   pins and returns it
**           b) direction = Output : returns the last written value
**     Parameters  : None
**     Returns     :
**         ---        - Input value (0 to 15)
** ===================================================================
*/
byte LCD_DATA_GetVal(void);

/*
** ===================================================================
**     Method      :  LCD_DATA_PutVal (component BitsIO)
**
**     Description :
**         This method writes the new output value.
**         Note: If direction is set to input the method code may not
**               work properly.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Val        - Output value (0 to 15)
**     Returns     : Nothing
** ===================================================================
*/
void LCD_DATA_PutVal(byte Val);

/*
** ===================================================================
**     Method      :  LCD_DATA_GetBit (component BitsIO)
**
**     Description :
**         This method returns the specified bit of the input value.
**           a) direction = Input  : reads the input value from pins
**                                   and returns the specified bit
**           b) direction = Output : returns the specified bit
**                                   of the last written value
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to read (0 to 3)
**     Returns     :
**         ---        - Value of the specified bit (FALSE or TRUE)
**                      FALSE = "0" or "Low", TRUE = "1" or "High"
** ===================================================================
*/
bool LCD_DATA_GetBit(byte Bit);

/*
** ===================================================================
**     Method      :  LCD_DATA_PutBit (component BitsIO)
**
**     Description :
**         This method writes the new value to the specified bit
**         of the output value.
**         Note: If direction is set to input the method code may not
**               work properly.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit (0 to 3)
**         Val        - New value of the bit (FALSE or TRUE)
**                      FALSE = "0" or "Low", TRUE = "1" or "High"
**     Returns     : Nothing
** ===================================================================
*/
void LCD_DATA_PutBit(byte Bit, bool Val);

/*
** ===================================================================
**     Method      :  LCD_DATA_ClrBit (component BitsIO)
**
**     Description :
**         This method clears (sets to zero) the specified bit
**         of the output value.
**         [ It is the same as "PutBit(Bit,FALSE);" ]
**         Note: If direction is set to input the method code may not
**               work properly.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to clear (0 to 3)
**     Returns     : Nothing
** ===================================================================
*/
void LCD_DATA_ClrBit(byte Bit);

/*
** ===================================================================
**     Method      :  LCD_DATA_SetBit (component BitsIO)
**
**     Description :
**         This method sets (sets to one) the specified bit of the
**         output value.
**         [ It is the same as "PutBit(Bit,TRUE);" ]
**         Note: If direction is set to input the method code may not
**               work properly.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to set (0 to 3)
**     Returns     : Nothing
** ===================================================================
*/
void LCD_DATA_SetBit(byte Bit);

/*
** ===================================================================
**     Method      :  LCD_DATA_NegBit (component BitsIO)
**
**     Description :
**         This method negates (inverts) the specified bit of the
**         output value.
**         Note: If direction is set to input the method code may
**               not work properly.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Bit        - Number of the bit to invert (0 to 31)
**     Returns     : Nothing
** ===================================================================
*/
void LCD_DATA_NegBit(byte Bit);

/*
** ===================================================================
**     Method      :  LCD_DATA_GetDir (component BitsIO)
**
**     Description :
**         This method returns direction of the component.
**     Parameters  : None
**     Returns     :
**         ---        - Direction of the component (FALSE or TRUE)
**                      FALSE = Input, TRUE = Output
** ===================================================================
*/
#define LCD_DATA_GetDir() ( \
    (bool)((getReg8(DDRAN) & 0x01))    /* Return pin direction, 0==GPI, nonzero==GPO */ \
  )

/*
** ===================================================================
**     Method      :  LCD_DATA_SetDir (component BitsIO)
**
**     Description :
**         This method sets direction of the component.
**     Parameters  :
**         NAME       - DESCRIPTION
**         Dir        - Direction to set (FALSE or TRUE)
**                      FALSE = Input, TRUE = Output
**     Returns     : Nothing
** ===================================================================
*/
void LCD_DATA_SetDir(bool Dir);

void Cpu_Delay50US(word us50 ) ;

#endif /* LCD_H_ */
