1 /*!
2  * \file      sx1509.h
3  *
4  * \brief     SX1509 IO expander driver implementation
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2017 Semtech
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  *
21  * \author    Gregory Cristian ( Semtech )
22  */
23 #ifndef __SX1509_H__
24 #define __SX1509_H__
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdint.h>
32 #include "utilities.h"
33 
34 #define SX1509_I2C_ADDRESS                          0x3E
35 
36 /*!
37  * SX1509 registers addresses
38  */
39 #define RegReset                                    0x7D
40 
41 #define RegInputDisableB                            0x00
42 #define RegInputDisableA                            0x01
43 #define RegLongSlewB                                0x02
44 #define RegLongSlewA                                0x03
45 #define RegLowDriveB                                0x04
46 #define RegLowDriveA                                0x05
47 #define RegPullUpB                                  0x06
48 #define RegPullUpA                                  0x07
49 #define RegPullDownB                                0x08
50 #define RegPullDownA                                0x09
51 #define RegOpenDrainB                               0x0A
52 #define RegOpenDrainA                               0x0B
53 #define RegPolarityB                                0x0C
54 #define RegPolarityA                                0x0D
55 #define RegDirB                                     0x0E
56 #define RegDirA                                     0x0F
57 #define RegDataB                                    0x10
58 #define RegDataA                                    0x11
59 #define RegInterruptMaskB                           0x12
60 #define RegInterruptMaskA                           0x13
61 #define RegSenseHighB                               0x14
62 #define RegSenseLowB                                0x15
63 #define RegSenseHighA                               0x16
64 #define RegSenseLowA                                0x17
65 #define RegInterruptSourceB                         0x18
66 #define RegInterruptSourceA                         0x19
67 #define RegEventStatusB                             0x1A
68 #define RegEventStatusA                             0x1B
69 #define RegLevelShifter1                            0x1C
70 #define RegLevelShifter2                            0x1D
71 #define RegClock                                    0x1E
72 #define RegMisc                                     0x1F
73 #define RegLEDDriverEnableB                         0x20
74 #define RegLEDDriverEnableA                         0x21
75 #define RegDebounceConfig                           0x22
76 #define RegDebounceEnableB                          0x23
77 #define RegDebounceEnableA                          0x24
78 #define RegKeyConfig1                               0x25
79 #define RegKeyConfig2                               0x26
80 #define RegKeyData1                                 0x27
81 #define RegKeyData2                                 0x28
82 #define RegTOn0                                     0x29
83 #define RegIOn0                                     0x2A
84 #define RegOff0                                     0x2B
85 #define RegTOn1                                     0x2C
86 #define RegIOn1                                     0x2D
87 #define RegOff1                                     0x2E
88 #define RegTOn2                                     0x2F
89 #define RegIOn2                                     0x30
90 #define RegOff2                                     0x31
91 #define RegTOn3                                     0x32
92 #define RegIOn3                                     0x33
93 #define RegOff3                                     0x34
94 #define RegTOn4                                     0x35
95 #define RegIOn4                                     0x36
96 #define RegOff4                                     0x37
97 #define RegTRise4                                   0x38
98 #define RegTFall4                                   0x39
99 #define RegTOn5                                     0x3A
100 #define RegIOn5                                     0x3B
101 #define RegOff5                                     0x3C
102 #define RegTRise5                                   0x3D
103 #define RegTFall5                                   0x3E
104 #define RegTOn6                                     0x3F
105 #define RegIOn6                                     0x40
106 #define RegOff6                                     0x41
107 #define RegTRise6                                   0x42
108 #define RegTFall6                                   0x43
109 #define RegTOn7                                     0x44
110 #define RegIOn7                                     0x45
111 #define RegOff7                                     0x46
112 #define RegTRise7                                   0x47
113 #define RegTFall7                                   0x48
114 #define RegTOn8                                     0x49
115 #define RegIOn8                                     0x4A
116 #define RegOff8                                     0x4B
117 #define RegTOn9                                     0x4C
118 #define RegIOn9                                     0x4D
119 #define RegOff9                                     0x4E
120 #define RegTOn10                                    0x4F
121 #define RegIOn10                                    0x50
122 #define RegOff10                                    0x51
123 #define RegTOn11                                    0x52
124 #define RegIOn11                                    0x53
125 #define RegOff11                                    0x54
126 #define RegTOn12                                    0x55
127 #define RegIOn12                                    0x56
128 #define RegOff12                                    0x57
129 #define RegTRise12                                  0x58
130 #define RegTFall12                                  0x59
131 #define RegTOn13                                    0x5A
132 #define RegIOn13                                    0x5B
133 #define RegOff13                                    0x5C
134 #define RegTRise13                                  0x5D
135 #define RegTFall13                                  0x5E
136 #define RegTOn14                                    0x5F
137 #define RegIOn14                                    0x60
138 #define RegOff14                                    0x61
139 #define RegTRise14                                  0x62
140 #define RegTFall14                                  0x63
141 #define RegTOn15                                    0x64
142 #define RegIOn15                                    0x65
143 #define RegOff15                                    0x66
144 #define RegTRise15                                  0x67
145 #define RegTFall15                                  0x68
146 #define RegHighInputB                               0x69
147 #define RegHighInputA                               0x6A
148 
149 /*!
150  * \brief Mask to select correct data from the registers
151  */
152 #define REG_SENSE_PIN_MASK_1                        0xFC
153 #define REG_SENSE_PIN_MASK_2                        0xF3
154 #define REG_SENSE_PIN_MASK_3                        0xCF
155 #define REG_SENSE_PIN_MASK_4                        0x3F
156 
157 /*!
158  * \brief Initializes the device
159  */
160 void SX1509Init( void );
161 
162 /*!
163  * \brief Resets the device
164  *
165  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
166  */
167 LmnStatus_t SX1509Reset( void );
168 
169 /*!
170  * \brief Writes a byte at specified address in the device
171  *
172  * \param [IN]: addr
173  * \param [IN]: data
174  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
175  */
176 LmnStatus_t SX1509Write( uint8_t addr, uint8_t data );
177 
178 /*!
179  * \brief Writes a buffer at specified address in the device
180  *
181  * \param [IN]: addr
182  * \param [IN]: data
183  * \param [IN]: size
184  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
185  */
186 LmnStatus_t SX1509WriteBuffer( uint8_t addr, uint8_t *data, uint8_t size );
187 
188 /*!
189  * \brief Reads a byte at specified address in the device
190  *
191  * \param [IN]: addr
192  * \param [OUT]: data
193  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
194  */
195 LmnStatus_t SX1509Read( uint8_t addr, uint8_t *data );
196 
197 /*!
198  * \brief Reads a buffer at specified address in the device
199  *
200  * \param [IN]: addr
201  * \param [OUT]: data
202  * \param [IN]: size
203  * \retval status [LMN_STATUS_OK, LMN_STATUS_ERROR]
204  */
205 LmnStatus_t SX1509ReadBuffer( uint8_t addr, uint8_t *data, uint8_t size );
206 
207 /*!
208  * \brief Sets the I2C device slave address
209  *
210  * \param [IN]: addr
211  */
212 void SX1509SetDeviceAddr( uint8_t addr );
213 
214 /*!
215  * \brief Gets the I2C device slave address
216  *
217  * \retval: addr Current device slave address
218  */
219 uint8_t SX1509GetDeviceAddr( void );
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 
225 #endif // __SX1509_H__
226