expand9  2.0.0.0
expand9.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef EXPAND9_H
29 #define EXPAND9_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define EXPAND9_REG_INPUT_DISABLE_B 0x00
70 #define EXPAND9_REG_INPUT_DISABLE_A 0x01
71 #define EXPAND9_REG_LONG_SLEW_B 0x02
72 #define EXPAND9_REG_LONG_SLEW_A 0x03
73 #define EXPAND9_REG_LOW_DRIVE_B 0x04
74 #define EXPAND9_REG_LOW_DRIVE_A 0x05
75 #define EXPAND9_REG_PULL_UP_B 0x06
76 #define EXPAND9_REG_PULL_UP_A 0x07
77 #define EXPAND9_REG_PULL_DOWN_B 0x08
78 #define EXPAND9_REG_PULL_DOWN_A 0x09
79 #define EXPAND9_REG_OPEN_DRAIN_B 0x0A
80 #define EXPAND9_REG_OPEN_DRAIN_A 0x0B
81 #define EXPAND9_REG_POLARITY_B 0x0C
82 #define EXPAND9_REG_POLARITY_A 0x0D
83 #define EXPAND9_REG_DIR_B 0x0E
84 #define EXPAND9_REG_DIR_A 0x0F
85 #define EXPAND9_REG_DATA_B 0x10
86 #define EXPAND9_REG_DATA_A 0x11
87 #define EXPAND9_REG_INTERRUPT_MASK_B 0x12
88 #define EXPAND9_REG_INTERRUPT_MASK_A 0x13
89 #define EXPAND9_REG_SENSE_HIGH_B 0x14
90 #define EXPAND9_REG_SENSE_LOW_B 0x15
91 #define EXPAND9_REG_SENSE_HIGH_A 0x16
92 #define EXPAND9_REG_SENSE_LOW_A 0x17
93 #define EXPAND9_REG_INTERRUPT_SOURCE_B 0x18
94 #define EXPAND9_REG_INTERRUPT_SOURCE_A 0x19
95 #define EXPAND9_REG_EVENT_STATUS_B 0x1A
96 #define EXPAND9_REG_EVENT_STATUS_A 0x1B
97 #define EXPAND9_REG_LEVEL_SHIFTER_1 0x1C
98 #define EXPAND9_REG_LEVEL_SHIFTER_2 0x1D
99 #define EXPAND9_REG_CLOCK 0x1E
100 #define EXPAND9_REG_MISC 0x1F
101 #define EXPAND9_REG_LED_DRIVER_ENABLE_B 0x20
102 #define EXPAND9_REG_LED_DRIVER_ENABLE_A 0x21
103 #define EXPAND9_REG_DEBOUNCE_CONFIG 0x22
104 #define EXPAND9_REG_DEBOUNCE_ENABLE_B 0x23
105 #define EXPAND9_REG_DEBOUNCE_ENABLE_A 0x24
106 #define EXPAND9_REG_KEY_CONFIG_1 0x25
107 #define EXPAND9_REG_KEY_CONFIG_2 0x26
108 #define EXPAND9_REG_KEY_DATA_1 0x27
109 #define EXPAND9_REG_KEY_DATA_2 0x28
110 #define EXPAND9_REG_T_ON_0 0x29
111 #define EXPAND9_REG_I_ON_0 0x2A
112 #define EXPAND9_REG_OFF_0 0x2B
113 #define EXPAND9_REG_T_ON_1 0x2C
114 #define EXPAND9_REG_I_ON_1 0x2D
115 #define EXPAND9_REG_OFF_1 0x2E
116 #define EXPAND9_REG_T_ON_2 0x2F
117 #define EXPAND9_REG_I_ON_2 0x30
118 #define EXPAND9_REG_OFF_2 0x31
119 #define EXPAND9_REG_T_ON_3 0x32
120 #define EXPAND9_REG_I_ON_3 0x33
121 #define EXPAND9_REG_OFF_3 0x34
122 #define EXPAND9_REG_T_ON_4 0x35
123 #define EXPAND9_REG_I_ON_4 0x36
124 #define EXPAND9_REG_OFF_4 0x37
125 #define EXPAND9_REG_T_RISE_4 0x38
126 #define EXPAND9_REG_T_FALL_4 0x39
127 #define EXPAND9_REG_T_ON_5 0x3A
128 #define EXPAND9_REG_I_ON_5 0x3B
129 #define EXPAND9_REG_OFF_5 0x3C
130 #define EXPAND9_REG_T_RISE_5 0x3D
131 #define EXPAND9_REG_T_FALL_5 0x3E
132 #define EXPAND9_REG_T_ON_6 0x3F
133 #define EXPAND9_REG_I_ON_6 0x40
134 #define EXPAND9_REG_OFF_6 0x41
135 #define EXPAND9_REG_T_RISE_6 0x42
136 #define EXPAND9_REG_T_FALL_6 0x43
137 #define EXPAND9_REG_T_ON_7 0x44
138 #define EXPAND9_REG_I_ON_7 0x45
139 #define EXPAND9_REG_OFF_7 0x46
140 #define EXPAND9_REG_T_RISE_7 0x47
141 #define EXPAND9_REG_T_FALL_7 0x48
142 #define EXPAND9_REG_T_ON_8 0x49
143 #define EXPAND9_REG_I_ON_8 0x4A
144 #define EXPAND9_REG_OFF_8 0x4B
145 #define EXPAND9_REG_T_ON_9 0x4C
146 #define EXPAND9_REG_I_ON_9 0x4D
147 #define EXPAND9_REG_OFF_9 0x4E
148 #define EXPAND9_REG_T_ON_10 0x4F
149 #define EXPAND9_REG_I_ON_10 0x50
150 #define EXPAND9_REG_OFF_10 0x51
151 #define EXPAND9_REG_T_ON_11 0x52
152 #define EXPAND9_REG_I_ON_11 0x53
153 #define EXPAND9_REG_OFF_11 0x54
154 #define EXPAND9_REG_T_ON_12 0x55
155 #define EXPAND9_REG_I_ON_12 0x56
156 #define EXPAND9_REG_OFF_12 0x57
157 #define EXPAND9_REG_T_RISE_12 0x58
158 #define EXPAND9_REG_T_FALL_12 0x59
159 #define EXPAND9_REG_T_ON_13 0x5A
160 #define EXPAND9_REG_I_ON_13 0x5B
161 #define EXPAND9_REG_OFF_13 0x5C
162 #define EXPAND9_REG_T_RISE_13 0x5D
163 #define EXPAND9_REG_T_FALL_13 0x5E
164 #define EXPAND9_REG_T_ON_14 0x5F
165 #define EXPAND9_REG_I_ON_14 0x60
166 #define EXPAND9_REG_OFF_14 0x61
167 #define EXPAND9_REG_T_RISE_14 0x62
168 #define EXPAND9_REG_T_FALL_14 0x63
169 #define EXPAND9_REG_T_ON_15 0x64
170 #define EXPAND9_REG_I_ON_15 0x65
171 #define EXPAND9_REG_OFF_15 0x66
172 #define EXPAND9_REG_T_RISE_15 0x67
173 #define EXPAND9_REG_T_FALL_15 0x68
174 #define EXPAND9_REG_HIGH_INPUT_B 0x69
175 #define EXPAND9_REG_HIGH_INPUT_A 0x6A
176 #define EXPAND9_REG_RESET 0x7D
177 #define EXPAND9_REG_TEST_1 0x7E
178 #define EXPAND9_REG_TEST_2 0x7F
179  // expand9_reg
181 
196 #define EXPAND9_CHANGE 0x01
197 #define EXPAND9_FALLING 0x02
198 #define EXPAND9_RISING 0x03
199 #define EXPAND9_FREQ_DIV_1 0x01
200 #define EXPAND9_FREQ_DIV_2 0x02
201 #define EXPAND9_FREQ_DIV_3 0x03
202 #define EXPAND9_FREQ_DIV_4 0x04
203 #define EXPAND9_FREQ_DIV_5 0x05
204 #define EXPAND9_FREQ_DIV_6 0x06
205 #define EXPAND9_FREQ_DIV_7 0x07
206 #define EXPAND9_LED_MODE_LINEAR 0x00
207 #define EXPAND9_LED_MODE_LOGARITHMIC 0x01
208 
214 #define EXPAND9_SET_DEV_ADDR_GND 0x3E
215 #define EXPAND9_SET_DEV_ADDR_VCC 0x70
216  // expand9_set
218 
233 #define EXPAND9_MAP_MIKROBUS( cfg, mikrobus ) \
234  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
235  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
236  cfg.add = MIKROBUS( mikrobus, MIKROBUS_AN ); \
237  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
238  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
239  // expand9_map // expand9
242 
247 typedef struct
248 {
249  // Output pins
250  digital_out_t add;
251  digital_out_t rst;
254  // Input pins
255  digital_in_t int_pin;
257  // Modules
258  i2c_master_t i2c;
260  // I2C slave address
261  uint8_t slave_address;
263 } expand9_t;
264 
269 typedef struct
270 {
271  pin_name_t scl;
272  pin_name_t sda;
274  pin_name_t add;
275  pin_name_t rst;
276  pin_name_t int_pin;
278  uint32_t i2c_speed;
279  uint8_t i2c_address;
281 } expand9_cfg_t;
282 
287 typedef enum
288 {
290  EXPAND9_ERROR = -1
291 
293 
298 typedef enum
299 {
301  DIRECTION_OUTPUT = 1
302 
304 
309 typedef enum
310 {
312  CH_OUTPUT_ON = 1
313 
315 
332 
347 err_t expand9_init ( expand9_t *ctx, expand9_cfg_t *cfg );
348 
363 
379 err_t expand9_set_slave_address ( expand9_t *ctx, uint8_t slave_addr );
380 
396 err_t expand9_generic_write ( expand9_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
397 
413 err_t expand9_generic_read ( expand9_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
414 
429 
444 err_t expand9_set_ch_direction ( expand9_t *ctx, uint8_t ch_pos, expand9_direction_value_t direction );
445 
460 
475 
491 err_t expand9_set_ch_output_state ( expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t ch_state );
492 
508 err_t expand9_get_ch_output_state ( expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t *ch_state );
509 
528 err_t expand9_write_ch ( expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t ch_state );
529 
545 err_t expand9_read_ch ( expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t *ch_state );
546 
567 err_t expand9_led_driver_config ( expand9_t *ctx, uint8_t ch_pos, uint8_t freq_div, uint8_t lin_log );
568 
585 err_t expand9_set_intensity ( expand9_t *ctx, uint8_t ch_pos, uint8_t intensity );
586 
601 err_t expand9_sync ( expand9_t *ctx );
602 
627 err_t expand9_debounce_config ( expand9_t *ctx, uint8_t config_val );
628 
648 err_t expand9_enable_ch_interrupt ( expand9_t *ctx, uint8_t ch_pos, uint8_t rise_fall );
649 
665 
681 err_t expand9_check_ch_interrupt ( expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t *int_state );
682 
697 
698 #ifdef __cplusplus
699 }
700 #endif
701 #endif // EXPAND9_H
702  // expand9
704 
705 // ------------------------------------------------------------------------ END
expand9_cfg_t::int_pin
pin_name_t int_pin
Definition: expand9.h:276
expand9_cfg_t
Expand 9 Click configuration object.
Definition: expand9.h:270
expand9_cfg_setup
void expand9_cfg_setup(expand9_cfg_t *cfg)
Expand 9 configuration object setup function.
expand9_set_intensity
err_t expand9_set_intensity(expand9_t *ctx, uint8_t ch_pos, uint8_t intensity)
Expand 9 set intensity function.
expand9_set_ch_output_state
err_t expand9_set_ch_output_state(expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t ch_state)
Expand 9 set channel output state function.
expand9_t::rst
digital_out_t rst
Definition: expand9.h:251
expand9_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand9.h:279
expand9_cfg_t::scl
pin_name_t scl
Definition: expand9.h:271
expand9_t
Expand 9 Click context object.
Definition: expand9.h:248
expand9_set_all_ch_output
err_t expand9_set_all_ch_output(expand9_t *ctx)
Expand 9 set all channel output function.
expand9_set_ch_direction
err_t expand9_set_ch_direction(expand9_t *ctx, uint8_t ch_pos, expand9_direction_value_t direction)
Expand 9 set channel direction function.
DIRECTION_OUTPUT
@ DIRECTION_OUTPUT
Definition: expand9.h:301
expand9_check_interrupt_pin
uint8_t expand9_check_interrupt_pin(expand9_t *ctx)
Expand 9 check interrupt pin function.
expand9_cfg_t::sda
pin_name_t sda
Definition: expand9.h:272
EXPAND9_ERROR
@ EXPAND9_ERROR
Definition: expand9.h:290
expand9_cfg_t::rst
pin_name_t rst
Definition: expand9.h:275
expand9_t::add
digital_out_t add
Definition: expand9.h:250
expand9_set_all_ch_input
err_t expand9_set_all_ch_input(expand9_t *ctx)
Expand 9 set all channel input function.
expand9_get_ch_output_state
err_t expand9_get_ch_output_state(expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t *ch_state)
Expand 9 get channel output state function.
expand9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand9.h:278
expand9_return_value_t
expand9_return_value_t
Expand 9 Click return value data.
Definition: expand9.h:288
expand9_debounce_config
err_t expand9_debounce_config(expand9_t *ctx, uint8_t config_val)
Expand 9 sync function.
expand9_ch_state_value_t
expand9_ch_state_value_t
Expand 9 Click channel state value data.
Definition: expand9.h:310
expand9_led_driver_config
err_t expand9_led_driver_config(expand9_t *ctx, uint8_t ch_pos, uint8_t freq_div, uint8_t lin_log)
Expand 9 LED driver configuration function.
expand9_generic_write
err_t expand9_generic_write(expand9_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Expand 9 I2C writing function.
DIRECTION_INPUT
@ DIRECTION_INPUT
Definition: expand9.h:300
expand9_direction_value_t
expand9_direction_value_t
Expand 9 Click direction value data.
Definition: expand9.h:299
expand9_default_cfg
err_t expand9_default_cfg(expand9_t *ctx)
Expand 9 default configuration function.
expand9_t::int_pin
digital_in_t int_pin
Definition: expand9.h:255
expand9_read_ch
err_t expand9_read_ch(expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t *ch_state)
Expand 9 read channel function.
expand9_soft_reset
err_t expand9_soft_reset(expand9_t *ctx)
Expand 9 software reset function.
expand9_clear_interrupt
err_t expand9_clear_interrupt(expand9_t *ctx)
Expand 9 clear all interrupt function.
expand9_init
err_t expand9_init(expand9_t *ctx, expand9_cfg_t *cfg)
Expand 9 initialization function.
CH_OUTPUT_ON
@ CH_OUTPUT_ON
Definition: expand9.h:312
expand9_check_ch_interrupt
err_t expand9_check_ch_interrupt(expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t *int_state)
Expand 9 check channel interrupt function.
expand9_set_slave_address
err_t expand9_set_slave_address(expand9_t *ctx, uint8_t slave_addr)
Expand 9 set I2C Slave address function.
expand9_t::i2c
i2c_master_t i2c
Definition: expand9.h:258
EXPAND9_OK
@ EXPAND9_OK
Definition: expand9.h:289
expand9_t::slave_address
uint8_t slave_address
Definition: expand9.h:261
expand9_generic_read
err_t expand9_generic_read(expand9_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Expand 9 I2C reading function.
expand9_sync
err_t expand9_sync(expand9_t *ctx)
Expand 9 sync function.
expand9_write_ch
err_t expand9_write_ch(expand9_t *ctx, uint8_t ch_pos, expand9_ch_state_value_t ch_state)
Expand 9 write channel function.
CH_OUTPUT_OFF
@ CH_OUTPUT_OFF
Definition: expand9.h:311
expand9_cfg_t::add
pin_name_t add
Definition: expand9.h:274
expand9_enable_ch_interrupt
err_t expand9_enable_ch_interrupt(expand9_t *ctx, uint8_t ch_pos, uint8_t rise_fall)
Expand 9 enable channel interrupt function.