Subversion Repositories HomeAutomation

Rev

Rev 1461 | Rev 1463 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /**
  2.  * @defgroup pca95xx PCA95xx Library
  3.  * @code #include <drivers/io/pca95xx.h> @endcode
  4.  *
  5.  * @brief Functions for using a pca95xx I2C IO-expander.
  6.  *
  7.  * ...
  8.  *
  9.  * @author  Anders Runeson
  10.  * @date    2010-04-01
  11.  */
  12.  
  13. /**@{*/
  14.  
  15. #ifndef PCA95XX_H_
  16. #define PCA95XX_H_
  17.  
  18. #include <config.h>
  19.  
  20. #ifndef PCA95XX_NUM_CALLBACKS
  21. #define PCA95XX_NUM_CALLBACKS 0
  22. #endif
  23.  
  24. #ifndef PCA_INT_VECTOR
  25. #define PCA_INT_VECTOR  INT0_vect
  26. #endif
  27.  
  28.  
  29. #if defined(__AVR_ATmega8__)
  30.     #define INT1_REG GICR
  31. #elif defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
  32.     #define INT1_REG EIMSK
  33. #else
  34. #error AVR device not supported!
  35. #endif
  36.  
  37. #if PCA_INT_VECTOR==INT0_vect
  38.     #define PCA_INT_ENABLE()    INT1_REG |= _BV(INT0)
  39.     #define PCA_INT_DISABLE()   INT1_REG &= ~(_BV(INT0))
  40. #else
  41.     #define PCA_INT_ENABLE()    INT1_REG |= _BV(INT1)
  42.     #define PCA_INT_DISABLE()   INT1_REG &= ~(_BV(INT1))
  43. #endif
  44.  
  45.  
  46. /*-----------------------------------------------------------------------------
  47.  * Includes
  48.  *---------------------------------------------------------------------------*/
  49. #include <inttypes.h>
  50. #include <stdio.h>
  51.  
  52. /*-----------------------------------------------------------------------------
  53.  * Defines
  54.  *---------------------------------------------------------------------------*/
  55.  
  56.  
  57. /*-----------------------------------------------------------------------------
  58.  * Public Types
  59.  *---------------------------------------------------------------------------*/
  60.  
  61. /**
  62.  * @brief Type of the callback function pointer
  63.  */
  64. typedef void (*pca95xxCallback_t)(uint16_t);
  65.  
  66. /*-----------------------------------------------------------------------------
  67.  * Public Function Prototypes
  68.  *---------------------------------------------------------------------------*/
  69.  
  70. /**
  71.  * @brief Poll the PCA95xx for the input status.
  72.  *
  73.  * Reads the input status of the PCA95xx and returns the data.
  74.  *
  75.  * @param address
  76.  *      The address used when communicating with the device.
  77.  */
  78. void Pca95xx_Init(uint8_t address);
  79.  
  80. /**
  81.  * @brief Stores a callback for an io interrupt.
  82.  *
  83.  * @param callback
  84.  *      Pointer to optional callback function on the form
  85.  *      void callback(uint16_t inputs). The callback function is called with the
  86.  *      port status as the argument whenever the interrupt is thrown. It is called
  87.  *      from the interrupt handler and must be very short.
  88.  */
  89. void Pca95xx_SetCallback(pca95xxCallback_t callback);
  90.  
  91. /**
  92.  * @brief Poll the PCA95xx for the input status.
  93.  *
  94.  * Reads the input status of the PCA95xx and returns the data.
  95.  *
  96.  * @retval
  97.  *      The input registers.
  98.  */
  99. uint16_t Pca95xx_GetInputs(void);
  100.  
  101. /**
  102.  * @brief Sets the PCA95xx outputs.
  103.  *
  104.  * @param outputs
  105.  *      The data to be set as outputs.
  106.  * @param mask
  107.  *      Passing a mask makes it possible to set one or more output without
  108.  *      affecting the other ports. Set bit to 1 to set the corresponding
  109.  *      port bit to the value of the Output parameter bit.
  110.  */
  111. void Pca95xx_SetOutputs(uint16_t outputs, uint16_t mask);
  112.  
  113. /**
  114.  * @brief Sets the PCA95xx port direction.
  115.  *
  116.  * @param direction
  117.  *      The data to be used for setting port direction.
  118.  * @param mask
  119.  *      Passing a mask makes it possible to set direction for one or more
  120.  *      ports without affecting the others. Set bit to 1 to set the
  121.  *      corresponding direction bit to the value of the Direction parameter
  122.  *      bit.
  123.  */
  124. void Pca95xx_SetDirection(uint16_t direction, uint16_t mask);
  125.  
  126.  
  127. /**@}*/
  128. #endif /*PCA95XX_H_*/
  129.