Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / alld_pca9544a.h @ f125ae07

History | View | Annotate | Download (4.26 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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
/**
20
 * @file    alld_pca9544a.h
21
 * @brief   I2C Multiplexer macros and structures.
22
 *
23
 * @addtogroup lld_multi
24
 * @{
25
 */
26

    
27
#ifndef _AMIROLLD_PCA9544A_H_
28
#define _AMIROLLD_PCA9544A_H_
29

    
30
#include <amiro-lld.h>
31

    
32
#if defined(AMIROLLD_CFG_USE_PCA9544A) || defined(__DOXYGEN__)
33

    
34
/**
35
 * @brief Maximum I2C frequency.
36
 */
37
#define PCA9544A_LLD_I2C_MAXFREQUENCY   400000
38

    
39
/**
40
 * @brief The PCA9544ADriver struct
41
 */
42
typedef struct {
43
  apalI2CDriver_t* i2cd;  /**< @brief The I²C driver to use. */
44
  apalI2Caddr_t addr;     /**< @brief The address of the PCA9544A for I2C communication, which is defined by the wiring of the A0, A1, A2 pins */
45
} PCA9544ADriver;
46

    
47
/**
48
 * @brief The fixed address prefix of any PCA9544A.
49
 */
50
enum {
51
  PCA9544A_LLD_I2C_ADDR_FIXED   = 0x0070u,
52
  PCA9544A_LLD_I2C_ADDR_A0      = 0x0001u,
53
  PCA9544A_LLD_I2C_ADDR_A1      = 0x0002u,
54
  PCA9544A_LLD_I2C_ADDR_A2      = 0x0004u,
55
};
56

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

    
74
/**
75
 * @brief Interrupt identifiers for external use.
76
 */
77
typedef enum {
78
  PCA9544A_LLD_INT0 = 0x01u, /**< interrupt 0 identifier */
79
  PCA9544A_LLD_INT1 = 0x02u, /**< interrupt 1 identifier */
80
  PCA9544A_LLD_INT2 = 0x04u, /**< interrupt 2 identifier */
81
  PCA9544A_LLD_INT3 = 0x08u, /**< interrupt 3 identifier */
82
} pca9544a_lld_intid_t;
83

    
84
/**
85
 * @brief Channel selection identifier for external use.
86
 */
87
typedef enum {
88
  PCA9544A_LLD_CH0      = 0x00u, /**< identifier to select channel 0 */
89
  PCA9544A_LLD_CH1      = 0x01u, /**< identifier to select channel 1*/
90
  PCA9544A_LLD_CH2      = 0x02u, /**< identifier to select channel 2 */
91
  PCA9544A_LLD_CH3      = 0x03u, /**< identifier to select channel 3 */
92
  PCA9544A_LLD_CH_NONE  = 0xFFu, /**< identifier to select no channel */
93
} pca9544a_lld_chid_t;
94

    
95
typedef uint8_t pca9544a_lld_intstatus_t;
96

    
97
#ifdef __cplusplus
98
extern "C" {
99
#endif
100
  apalExitStatus_t pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const data, const apalTime_t timeout);
101
  apalExitStatus_t pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout);
102
  apalExitStatus_t pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const  status, const apalTime_t timeout);
103
  apalExitStatus_t pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout);
104
  apalExitStatus_t pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout);
105
#ifdef __cplusplus
106
}
107
#endif
108

    
109
#endif /* defined(AMIROLLD_CFG_USE_PCA9544A) */
110

    
111
#endif /* _AMIROLLD_PCA9544A_H_ */
112

    
113
/** @} */