Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / alld_pca9544a.h @ cf1f756b

History | View | Annotate | Download (4.131 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
#ifndef _AMIROLLD_PCA9544A_H_
20
#define _AMIROLLD_PCA9544A_H_
21

    
22
#include <amiro-lld.h>
23

    
24
#if defined(AMIROLLD_CFG_USE_PCA9544A) || defined(__DOXYGEN__)
25

    
26
/**
27
 * @brief Maximum I2C frequency.
28
 */
29
#define PCA9544A_LLD_I2C_MAXFREQUENCY   400000
30

    
31
/**
32
 * @brief The PCA9544ADriver struct
33
 */
34
typedef struct {
35
  apalI2CDriver_t* i2cd;  /**< @brief The I²C driver to use. */
36
  apalI2Caddr_t addr;     /**< @brief The address of the PCA9544A for I2C communication, which is defined by the wiring of the A0, A1, A2 pins */
37
} PCA9544ADriver;
38

    
39
/**
40
 * @brief The fixed address prefix of any PCA9544A.
41
 */
42
enum {
43
  PCA9544A_LLD_I2C_ADDR_FIXED   = 0x0070u,
44
  PCA9544A_LLD_I2C_ADDR_A0      = 0x0001u,
45
  PCA9544A_LLD_I2C_ADDR_A1      = 0x0002u,
46
  PCA9544A_LLD_I2C_ADDR_A2      = 0x0004u,
47
};
48

    
49
/**
50
 * @brief The control register of the PCA9544A.
51
 */
52
typedef enum {
53
  PCA9544A_LLD_CTRLREG_INT3     = 0x80u, /**< interrupt 3 flag (1 = active) */
54
  PCA9544A_LLD_CTRLREG_INT2     = 0x40u, /**< interrupt 2 flag (1 = active) */
55
  PCA9544A_LLD_CTRLREG_INT1     = 0x20u, /**< interrupt 1 flag (1 = active) */
56
  PCA9544A_LLD_CTRLREG_INT0     = 0x10u, /**< interrupt 0 flag (1 = active) */
57
  PCA9544A_LLD_CTRLREG_EN       = 0x04u, /**< multiplexing enable flag (1 = enabled) */
58
  PCA9544A_LLD_CTRLREG_CH_MASK  = 0x03u, /**< bitmask for all channel selection bits */
59
  PCA9544A_LLD_CTRLREG_CH0      = 0x00u, /**< channel 0 selection mask */
60
  PCA9544A_LLD_CTRLREG_CH1      = 0x01u, /**< channel 1 selection mask */
61
  PCA9544A_LLD_CTRLREG_CH2      = 0x02u, /**< channel 2 selection mask */
62
  PCA9544A_LLD_CTRLREG_CH3      = 0x03u, /**< channel 3 selection mask */
63
  PCA9544A_LLD_CTRLREG_DEFAULT  = 0x00u, /**< default register value after power-up */
64
} pca9544a_lld_ctrlreg_t;
65

    
66
/**
67
 * @brief Interrupt identifiers for external use.
68
 */
69
typedef enum {
70
  PCA9544A_LLD_INT0 = 0x01u, /**< interrupt 0 identifier */
71
  PCA9544A_LLD_INT1 = 0x02u, /**< interrupt 1 identifier */
72
  PCA9544A_LLD_INT2 = 0x04u, /**< interrupt 2 identifier */
73
  PCA9544A_LLD_INT3 = 0x08u, /**< interrupt 3 identifier */
74
} pca9544a_lld_intid_t;
75

    
76
/**
77
 * @brief Channel selection identifier for external use.
78
 */
79
typedef enum {
80
  PCA9544A_LLD_CH0      = 0x00u, /**< identifier to select channel 0 */
81
  PCA9544A_LLD_CH1      = 0x01u, /**< identifier to select channel 1*/
82
  PCA9544A_LLD_CH2      = 0x02u, /**< identifier to select channel 2 */
83
  PCA9544A_LLD_CH3      = 0x03u, /**< identifier to select channel 3 */
84
  PCA9544A_LLD_CH_NONE  = 0xFFu, /**< identifier to select no channel */
85
} pca9544a_lld_chid_t;
86

    
87
typedef uint8_t pca9544a_lld_intstatus_t;
88

    
89
#ifdef __cplusplus
90
extern "C" {
91
#endif
92
  apalExitStatus_t pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const data, const apalTime_t timeout);
93
  apalExitStatus_t pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout);
94
  apalExitStatus_t pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const  status, const apalTime_t timeout);
95
  apalExitStatus_t pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout);
96
  apalExitStatus_t pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout);
97
#ifdef __cplusplus
98
}
99
#endif
100

    
101
#endif /* defined(AMIROLLD_CFG_USE_PCA9544A) */
102

    
103
#endif /* _AMIROLLD_PCA9544A_H_ */