Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / PCA9544A / v1 / alld_PCA9544A.h @ c9774bf5

History | View | Annotate | Download (5.887 KB)

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

5
This program is free software: you can redistribute it and/or modify
6 f0ca400f Thomas Schöpping
it under the terms of the GNU Lesser General Public License as published by
7 d6728c5b Thomas Schöpping
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 f0ca400f Thomas Schöpping
GNU Lesser General Public License for more details.
14 d6728c5b Thomas Schöpping

15 f0ca400f Thomas Schöpping
You should have received a copy of the GNU Lesser General Public License
16 d6728c5b Thomas Schöpping
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19 5e2f673b Marc Rothmann
/**
20 9466e34d Thomas Schöpping
 * @file    alld_PCA9544A.h
21 5e2f673b Marc Rothmann
 * @brief   I2C Multiplexer macros and structures.
22
 *
23
 * @addtogroup lld_multi
24
 * @{
25
 */
26
27 9466e34d Thomas Schöpping
#ifndef AMIROLLD_PCA9544A_H
28
#define AMIROLLD_PCA9544A_H
29 d6728c5b Thomas Schöpping
30
#include <amiro-lld.h>
31
32 ef078306 Thomas Schöpping
/******************************************************************************/
33
/* CONSTANTS                                                                  */
34
/******************************************************************************/
35
36 d6728c5b Thomas Schöpping
/**
37
 * @brief Maximum I2C frequency.
38
 */
39
#define PCA9544A_LLD_I2C_MAXFREQUENCY   400000
40
41 ef078306 Thomas Schöpping
/******************************************************************************/
42
/* SETTINGS                                                                   */
43
/******************************************************************************/
44
45
/******************************************************************************/
46
/* CHECKS                                                                     */
47
/******************************************************************************/
48
49
/******************************************************************************/
50
/* DATA STRUCTURES AND TYPES                                                  */
51
/******************************************************************************/
52
53 d6728c5b Thomas Schöpping
/**
54
 * @brief The PCA9544ADriver struct
55
 */
56
typedef struct {
57
  apalI2CDriver_t* i2cd;  /**< @brief The I²C driver to use. */
58 cf1f756b Thomas Schöpping
  apalI2Caddr_t addr;     /**< @brief The address of the PCA9544A for I2C communication, which is defined by the wiring of the A0, A1, A2 pins */
59 d6728c5b Thomas Schöpping
} PCA9544ADriver;
60
61
/**
62
 * @brief The fixed address prefix of any PCA9544A.
63
 */
64
enum {
65 cf1f756b Thomas Schöpping
  PCA9544A_LLD_I2C_ADDR_FIXED   = 0x0070u,
66
  PCA9544A_LLD_I2C_ADDR_A0      = 0x0001u,
67
  PCA9544A_LLD_I2C_ADDR_A1      = 0x0002u,
68
  PCA9544A_LLD_I2C_ADDR_A2      = 0x0004u,
69 d6728c5b Thomas Schöpping
};
70
71
/**
72
 * @brief The control register of the PCA9544A.
73
 */
74
typedef enum {
75
  PCA9544A_LLD_CTRLREG_INT3     = 0x80u, /**< interrupt 3 flag (1 = active) */
76
  PCA9544A_LLD_CTRLREG_INT2     = 0x40u, /**< interrupt 2 flag (1 = active) */
77
  PCA9544A_LLD_CTRLREG_INT1     = 0x20u, /**< interrupt 1 flag (1 = active) */
78
  PCA9544A_LLD_CTRLREG_INT0     = 0x10u, /**< interrupt 0 flag (1 = active) */
79
  PCA9544A_LLD_CTRLREG_EN       = 0x04u, /**< multiplexing enable flag (1 = enabled) */
80
  PCA9544A_LLD_CTRLREG_CH_MASK  = 0x03u, /**< bitmask for all channel selection bits */
81
  PCA9544A_LLD_CTRLREG_CH0      = 0x00u, /**< channel 0 selection mask */
82
  PCA9544A_LLD_CTRLREG_CH1      = 0x01u, /**< channel 1 selection mask */
83
  PCA9544A_LLD_CTRLREG_CH2      = 0x02u, /**< channel 2 selection mask */
84
  PCA9544A_LLD_CTRLREG_CH3      = 0x03u, /**< channel 3 selection mask */
85
  PCA9544A_LLD_CTRLREG_DEFAULT  = 0x00u, /**< default register value after power-up */
86
} pca9544a_lld_ctrlreg_t;
87
88
/**
89
 * @brief Interrupt identifiers for external use.
90
 */
91
typedef enum {
92
  PCA9544A_LLD_INT0 = 0x01u, /**< interrupt 0 identifier */
93
  PCA9544A_LLD_INT1 = 0x02u, /**< interrupt 1 identifier */
94
  PCA9544A_LLD_INT2 = 0x04u, /**< interrupt 2 identifier */
95
  PCA9544A_LLD_INT3 = 0x08u, /**< interrupt 3 identifier */
96
} pca9544a_lld_intid_t;
97
98
/**
99
 * @brief Channel selection identifier for external use.
100
 */
101
typedef enum {
102
  PCA9544A_LLD_CH0      = 0x00u, /**< identifier to select channel 0 */
103
  PCA9544A_LLD_CH1      = 0x01u, /**< identifier to select channel 1*/
104
  PCA9544A_LLD_CH2      = 0x02u, /**< identifier to select channel 2 */
105
  PCA9544A_LLD_CH3      = 0x03u, /**< identifier to select channel 3 */
106
  PCA9544A_LLD_CH_NONE  = 0xFFu, /**< identifier to select no channel */
107
} pca9544a_lld_chid_t;
108
109 21076167 Thomas Schöpping
/**
110
 * @brief Type holding a bit mask for the four channel interrupts.
111
 */
112 d6728c5b Thomas Schöpping
typedef uint8_t pca9544a_lld_intstatus_t;
113
114 ef078306 Thomas Schöpping
/******************************************************************************/
115
/* MACROS                                                                     */
116
/******************************************************************************/
117
118
/******************************************************************************/
119
/* EXTERN DECLARATIONS                                                        */
120
/******************************************************************************/
121
122 d6728c5b Thomas Schöpping
#ifdef __cplusplus
123
extern "C" {
124
#endif
125
  apalExitStatus_t pca9544a_lld_read(const PCA9544ADriver* const pca9544a, uint8_t* const data, const apalTime_t timeout);
126
  apalExitStatus_t pca9544a_lld_write(const PCA9544ADriver* const pca9544a, const uint8_t data, const apalTime_t timeout);
127
  apalExitStatus_t pca9544a_lld_getintstatus(const PCA9544ADriver* const pca9544a, pca9544a_lld_intstatus_t* const  status, const apalTime_t timeout);
128
  apalExitStatus_t pca9544a_lld_getcurrentchannel(const PCA9544ADriver* const pca9544a, pca9544a_lld_chid_t* const channel, const apalTime_t timeout);
129
  apalExitStatus_t pca9544a_lld_setchannel(const PCA9544ADriver* const pca9544a, const pca9544a_lld_chid_t channel, const apalTime_t timeout);
130
#ifdef __cplusplus
131
}
132
#endif
133
134 ef078306 Thomas Schöpping
/******************************************************************************/
135
/* INLINE FUNCTIONS                                                           */
136
/******************************************************************************/
137
138 9466e34d Thomas Schöpping
#endif /* AMIROLLD_PCA9544A_H */
139 5e2f673b Marc Rothmann
140
/** @} */