expand3  2.1.0.0
expand3.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 EXPAND3_H
29 #define EXPAND3_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_one_wire.h"
48 
69 #define EXPAND3_CMD_READ_PIO_REGISTERS 0xF0
70 #define EXPAND3_CMD_CHANNEL_ACCESS_READ 0xF5
71 #define EXPAND3_CMD_CHANNEL_ACCESS_WRITE 0x5A
72 #define EXPAND3_CMD_WRITE_CONDITIONAL 0xCC
73 #define EXPAND3_CMD_RESET_ACTIVITY_LATCHES 0xC3
74 
79 #define EXPAND3_REG_PIO_LOGIC 0x0088
80 #define EXPAND3_REG_PIO_OUT_LATCH 0x0089
81 #define EXPAND3_REG_PIO_ACTIVITY_LATCH 0x008A
82 #define EXPAND3_REG_CHANNEL_MASK 0x008B
83 #define EXPAND3_REG_CHANNEL_POLARITY 0x008C
84 #define EXPAND3_REG_CONTROL 0x008D
85  // expand3_cmd
87 
102 #define EXPAND3_STATUS_VCCP 0x80
103 #define EXPAND3_CONTROL_PORL 0x08
104 #define EXPAND3_CONTROL_ROS 0x04
105 #define EXPAND3_CONTROL_CT 0x02
106 #define EXPAND3_CONTROL_PLS 0x01
107 #define EXPAND3_CONTROL_DEFAULT 0x00
108 #define EXPAND3_MASK_DEFAULT 0x00
109 #define EXPAND3_POLARITY_DEFAULT 0x00
110 
115 #define EXPAND3_CONFIRMATION_BYTE 0xAA
116 
121 #define EXPAND3_PIN_0 0x01
122 #define EXPAND3_PIN_1 0x02
123 #define EXPAND3_PIN_2 0x04
124 #define EXPAND3_PIN_3 0x08
125 #define EXPAND3_PIN_4 0x10
126 #define EXPAND3_PIN_5 0x20
127 #define EXPAND3_PIN_6 0x40
128 #define EXPAND3_PIN_7 0x80
129 
134 #define EXPAND3_FAMILY_CODE 0x29
135 
140 #define EXPAND3_ADDRESS_0 0x00
141 #define EXPAND3_ADDRESS_ALL 0xFF
142  // expand3_set
144 
159 #define EXPAND3_MAP_MIKROBUS( cfg, mikrobus ) \
160  cfg.ow0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
161  cfg.ow1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
162  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
163  // expand3_map // expand3
166 
171 typedef enum
172 {
177 
182 typedef struct
183 {
184  // Output pins
185  digital_out_t rst;
187  // Modules
188  one_wire_t ow;
190  one_wire_rom_address_t rom_addr;
191  uint8_t address;
193 } expand3_t;
194 
199 typedef struct
200 {
201  // Communication gpio pins
202  pin_name_t ow0;
203  pin_name_t ow1;
205  // Additional gpio pins
206  pin_name_t rst;
210 } expand3_cfg_t;
211 
216 typedef enum
217 {
219  EXPAND3_ERROR = -1
220 
222 
239 
255 
269 err_t expand3_init ( expand3_t *ctx, expand3_cfg_t *cfg );
270 
284 
297 
310 
323 err_t expand3_read_register ( expand3_t *ctx, uint16_t reg, uint8_t *data_out );
324 
337 err_t expand3_write_register ( expand3_t *ctx, uint16_t reg, uint8_t data_in );
338 
350 err_t expand3_read_state ( expand3_t *ctx, uint8_t *state );
351 
364 err_t expand3_write_state ( expand3_t *ctx, uint8_t state );
365 
378 
391 err_t expand3_write_mask ( expand3_t *ctx, uint8_t mask );
392 
406 err_t expand3_write_polarity ( expand3_t *ctx, uint8_t polarity );
407 
420 err_t expand3_write_control ( expand3_t *ctx, uint8_t control );
421 
433 err_t expand3_read_control ( expand3_t *ctx, uint8_t *control );
434 
446 err_t expand3_read_current_state ( expand3_t *ctx, uint8_t *curr_state );
447 
460 err_t expand3_read_last_state ( expand3_t *ctx, uint8_t *last_state );
461 
473 err_t expand3_read_activity ( expand3_t *ctx, uint8_t *activity );
474 
484 void expand3_set_rst_pin ( expand3_t *ctx, uint8_t state );
485 
495 
496 #ifdef __cplusplus
497 }
498 #endif
499 #endif // EXPAND3_H
500  // expand3
502 
503 // ------------------------------------------------------------------------ END
expand3_cfg_t::ow0
pin_name_t ow0
Definition: expand3.h:202
expand3_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: expand3.h:190
expand3_set_rst_pin
void expand3_set_rst_pin(expand3_t *ctx, uint8_t state)
Expand 3 set rst pin function.
expand3_cfg_t
Expand 3 Click configuration object.
Definition: expand3.h:200
expand3_cfg_setup
void expand3_cfg_setup(expand3_cfg_t *cfg)
Expand 3 configuration object setup function.
expand3_write_register
err_t expand3_write_register(expand3_t *ctx, uint16_t reg, uint8_t data_in)
Expand 3 write register function.
EXPAND3_OK
@ EXPAND3_OK
Definition: expand3.h:218
expand3_select_device
err_t expand3_select_device(expand3_t *ctx)
Expand 3 select device function.
expand3_cfg_t::gpio_sel
expand3_gpio_sel_t gpio_sel
Definition: expand3.h:208
expand3_cfg_t::rst
pin_name_t rst
Definition: expand3.h:206
expand3_t::rst
digital_out_t rst
Definition: expand3.h:185
expand3_t
Expand 3 Click context object.
Definition: expand3.h:183
expand3_t::ow
one_wire_t ow
Definition: expand3.h:188
expand3_read_state
err_t expand3_read_state(expand3_t *ctx, uint8_t *state)
Expand 3 read state function.
expand3_reset_device
void expand3_reset_device(expand3_t *ctx)
Expand 3 reset device function.
expand3_gpio_selection
void expand3_gpio_selection(expand3_cfg_t *cfg, expand3_gpio_sel_t gpio_sel)
Expand 3 driver interface setup function.
expand3_default_cfg
err_t expand3_default_cfg(expand3_t *ctx)
Expand 3 default configuration function.
EXPAND3_GPIO_OW0
@ EXPAND3_GPIO_OW0
Definition: expand3.h:173
expand3_return_value_t
expand3_return_value_t
Expand 3 Click return value data.
Definition: expand3.h:217
expand3_read_current_state
err_t expand3_read_current_state(expand3_t *ctx, uint8_t *curr_state)
Expand 3 read current state function.
expand3_gpio_sel_t
expand3_gpio_sel_t
Expand 3 Click gpio selector.
Definition: expand3.h:172
expand3_write_control
err_t expand3_write_control(expand3_t *ctx, uint8_t control)
Expand 3 write control function.
expand3_read_activity
err_t expand3_read_activity(expand3_t *ctx, uint8_t *activity)
Expand 3 read activity function.
expand3_init
err_t expand3_init(expand3_t *ctx, expand3_cfg_t *cfg)
Expand 3 initialization function.
expand3_write_state
err_t expand3_write_state(expand3_t *ctx, uint8_t state)
Expand 3 write state function.
expand3_read_register
err_t expand3_read_register(expand3_t *ctx, uint16_t reg, uint8_t *data_out)
Expand 3 read register function.
expand3_check_communication
err_t expand3_check_communication(expand3_t *ctx)
Expand 3 check communication function.
expand3_write_mask
err_t expand3_write_mask(expand3_t *ctx, uint8_t mask)
Expand 3 write mask function.
expand3_cfg_t::ow1
pin_name_t ow1
Definition: expand3.h:203
expand3_read_last_state
err_t expand3_read_last_state(expand3_t *ctx, uint8_t *last_state)
Expand 3 read last state function.
EXPAND3_GPIO_OW1
@ EXPAND3_GPIO_OW1
Definition: expand3.h:174
expand3_write_polarity
err_t expand3_write_polarity(expand3_t *ctx, uint8_t polarity)
Expand 3 write polarity function.
EXPAND3_ERROR
@ EXPAND3_ERROR
Definition: expand3.h:219
expand3_t::address
uint8_t address
Definition: expand3.h:191
expand3_reset_activity
err_t expand3_reset_activity(expand3_t *ctx)
Expand 3 reset activity function.
expand3_read_control
err_t expand3_read_control(expand3_t *ctx, uint8_t *control)
Expand 3 read control function.