/***********************************************************************
 *
 * (C) Copyright 1999, 2000, 2001, 2002
 * DENX Software Engineering
 * Wolfgang Denk, wd@denx.de
 * All rights reserved.
 *
 ***********************************************************************/

#ifndef _LINUX_TRABIO_H
#define _LINUX_TRABIO_H

/***********************************************************************
 *  DIP switches status bit encoding:
 *   3    2    1    0
 *  SW4  SW3  SW2  SW1
 *	
 *  keyboard LED status bit encoding:
 *   3    2    1    0
 *  L4   L3   L2   L1
 *
 *  keyboard keys status bit encoding:
 *   3    2    1    0
 *  K4   K3   K2   K1
 *
 *  Motor control and status led bit encoding:
 *  3  2  1  0
 *  x  x  M  L 
 *
 *  Fill level sensor and stop position contact bit encoding:
 *  3  2  1  0
 *  x  x  C  S 
 ***********************************************************************/
/* Macros to get the current status */
#define IS_SW_ON(num,val) 	  (((val) & 0xf) & (1 << (num-1)))
#define IS_KEY_ON(num, val)   (((val) & 0xf) & (1 << (num-1)))
#define IS_LED_ON(num, val)   (((val) & 0xf) & (1 << (num-1)))
#define IS_LEVEL_SENSOR_ON(val)  (((val) & 0x3) & 0x1)
#define IS_STOP_CONTACT_ON(val)  (((val) & 0x3) & 0x2)
#define IS_STAUS_LED_ON(val)     (((val) & 0x3) & 0x1)
#define IS_MOTOR_ON(val)         (((val) & 0x3) & 0x2)

/* Macros to control the LEDs and device */
#define SET_LED(num, on, val)   ((on) ? ((val) |= (1 << ((num)-1))) : \
                                ((val) &= ~(1 << ((num)-1))))
#define SET_STATUS_LED(on, val) ((on) ? ((val) |= 1) : ((val) &= ~1))
#define SET_MOTOR(on, val)      ((on) ? ((val) |= 2) : ((val) &= ~2))

#endif /*_LINUX_TRABIO_H */
