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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_one_wire.h"
52 
73 #define EXPAND3_CMD_READ_PIO_REGISTERS 0xF0
74 #define EXPAND3_CMD_CHANNEL_ACCESS_READ 0xF5
75 #define EXPAND3_CMD_CHANNEL_ACCESS_WRITE 0x5A
76 #define EXPAND3_CMD_WRITE_CONDITIONAL 0xCC
77 #define EXPAND3_CMD_RESET_ACTIVITY_LATCHES 0xC3
78 
83 #define EXPAND3_REG_PIO_LOGIC 0x0088
84 #define EXPAND3_REG_PIO_OUT_LATCH 0x0089
85 #define EXPAND3_REG_PIO_ACTIVITY_LATCH 0x008A
86 #define EXPAND3_REG_CHANNEL_MASK 0x008B
87 #define EXPAND3_REG_CHANNEL_POLARITY 0x008C
88 #define EXPAND3_REG_CONTROL 0x008D
89  // expand3_cmd
91 
106 #define EXPAND3_STATUS_VCCP 0x80
107 #define EXPAND3_CONTROL_PORL 0x08
108 #define EXPAND3_CONTROL_ROS 0x04
109 #define EXPAND3_CONTROL_CT 0x02
110 #define EXPAND3_CONTROL_PLS 0x01
111 #define EXPAND3_CONTROL_DEFAULT 0x00
112 #define EXPAND3_MASK_DEFAULT 0x00
113 #define EXPAND3_POLARITY_DEFAULT 0x00
114 
119 #define EXPAND3_CONFIRMATION_BYTE 0xAA
120 
125 #define EXPAND3_PIN_0 0x01
126 #define EXPAND3_PIN_1 0x02
127 #define EXPAND3_PIN_2 0x04
128 #define EXPAND3_PIN_3 0x08
129 #define EXPAND3_PIN_4 0x10
130 #define EXPAND3_PIN_5 0x20
131 #define EXPAND3_PIN_6 0x40
132 #define EXPAND3_PIN_7 0x80
133 
138 #define EXPAND3_FAMILY_CODE 0x29
139 
144 #define EXPAND3_ADDRESS_0 0x00
145 #define EXPAND3_ADDRESS_ALL 0xFF
146  // expand3_set
148 
163 #define EXPAND3_MAP_MIKROBUS( cfg, mikrobus ) \
164  cfg.ow0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
165  cfg.ow1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
166  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
167  // expand3_map // expand3
170 
175 typedef enum
176 {
181 
186 typedef struct
187 {
188  // Output pins
189  digital_out_t rst;
191  // Modules
192  one_wire_t ow;
194  one_wire_rom_address_t rom_addr;
195  uint8_t address;
197 } expand3_t;
198 
203 typedef struct
204 {
205  // Communication gpio pins
206  pin_name_t ow0;
207  pin_name_t ow1;
209  // Additional gpio pins
210  pin_name_t rst;
214 } expand3_cfg_t;
215 
220 typedef enum
221 {
223  EXPAND3_ERROR = -1
224 
226 
243 
259 
273 err_t expand3_init ( expand3_t *ctx, expand3_cfg_t *cfg );
274 
288 
301 
314 
327 err_t expand3_read_register ( expand3_t *ctx, uint16_t reg, uint8_t *data_out );
328 
341 err_t expand3_write_register ( expand3_t *ctx, uint16_t reg, uint8_t data_in );
342 
354 err_t expand3_read_state ( expand3_t *ctx, uint8_t *state );
355 
368 err_t expand3_write_state ( expand3_t *ctx, uint8_t state );
369 
382 
395 err_t expand3_write_mask ( expand3_t *ctx, uint8_t mask );
396 
410 err_t expand3_write_polarity ( expand3_t *ctx, uint8_t polarity );
411 
424 err_t expand3_write_control ( expand3_t *ctx, uint8_t control );
425 
437 err_t expand3_read_control ( expand3_t *ctx, uint8_t *control );
438 
450 err_t expand3_read_current_state ( expand3_t *ctx, uint8_t *curr_state );
451 
464 err_t expand3_read_last_state ( expand3_t *ctx, uint8_t *last_state );
465 
477 err_t expand3_read_activity ( expand3_t *ctx, uint8_t *activity );
478 
488 void expand3_set_rst_pin ( expand3_t *ctx, uint8_t state );
489 
499 
500 #ifdef __cplusplus
501 }
502 #endif
503 #endif // EXPAND3_H
504  // expand3
506 
507 // ------------------------------------------------------------------------ END
expand3_cfg_t::ow0
pin_name_t ow0
Definition: expand3.h:206
expand3_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: expand3.h:194
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:204
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:222
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:212
expand3_cfg_t::rst
pin_name_t rst
Definition: expand3.h:210
expand3_t::rst
digital_out_t rst
Definition: expand3.h:189
expand3_t
Expand 3 Click context object.
Definition: expand3.h:187
expand3_t::ow
one_wire_t ow
Definition: expand3.h:192
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:177
expand3_return_value_t
expand3_return_value_t
Expand 3 Click return value data.
Definition: expand3.h:221
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:176
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:207
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:178
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:223
expand3_t::address
uint8_t address
Definition: expand3.h:195
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.