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
32extern "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
90 // 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
147 // 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
168 // expand3_map
169 // expand3
170
181
186typedef 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
203typedef 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;
215
220typedef enum
221{
223 EXPAND3_ERROR = -1
224
226
243
259
274
288
301
314
327err_t expand3_read_register ( expand3_t *ctx, uint16_t reg, uint8_t *data_out );
328
341err_t expand3_write_register ( expand3_t *ctx, uint16_t reg, uint8_t data_in );
342
354err_t expand3_read_state ( expand3_t *ctx, uint8_t *state );
355
368err_t expand3_write_state ( expand3_t *ctx, uint8_t state );
369
382
395err_t expand3_write_mask ( expand3_t *ctx, uint8_t mask );
396
410err_t expand3_write_polarity ( expand3_t *ctx, uint8_t polarity );
411
424err_t expand3_write_control ( expand3_t *ctx, uint8_t control );
425
437err_t expand3_read_control ( expand3_t *ctx, uint8_t *control );
438
450err_t expand3_read_current_state ( expand3_t *ctx, uint8_t *curr_state );
451
464err_t expand3_read_last_state ( expand3_t *ctx, uint8_t *last_state );
465
477err_t expand3_read_activity ( expand3_t *ctx, uint8_t *activity );
478
488void expand3_set_rst_pin ( expand3_t *ctx, uint8_t state );
489
499
500#ifdef __cplusplus
501}
502#endif
503#endif // EXPAND3_H
504
505 // expand3
506
507// ------------------------------------------------------------------------ END
expand3_return_value_t
Expand 3 Click return value data.
Definition expand3.h:221
@ EXPAND3_OK
Definition expand3.h:222
@ EXPAND3_ERROR
Definition expand3.h:223
expand3_gpio_sel_t
Expand 3 Click gpio selector.
Definition expand3.h:176
@ EXPAND3_GPIO_OW0
Definition expand3.h:177
@ EXPAND3_GPIO_OW1
Definition expand3.h:178
void expand3_cfg_setup(expand3_cfg_t *cfg)
Expand 3 configuration object setup function.
err_t expand3_reset_activity(expand3_t *ctx)
Expand 3 reset activity function.
err_t expand3_select_device(expand3_t *ctx)
Expand 3 select device function.
err_t expand3_write_mask(expand3_t *ctx, uint8_t mask)
Expand 3 write mask function.
err_t expand3_write_polarity(expand3_t *ctx, uint8_t polarity)
Expand 3 write polarity function.
err_t expand3_read_state(expand3_t *ctx, uint8_t *state)
Expand 3 read state function.
err_t expand3_read_register(expand3_t *ctx, uint16_t reg, uint8_t *data_out)
Expand 3 read register function.
err_t expand3_write_register(expand3_t *ctx, uint16_t reg, uint8_t data_in)
Expand 3 write register function.
err_t expand3_write_control(expand3_t *ctx, uint8_t control)
Expand 3 write control function.
err_t expand3_check_communication(expand3_t *ctx)
Expand 3 check communication function.
err_t expand3_read_activity(expand3_t *ctx, uint8_t *activity)
Expand 3 read activity function.
err_t expand3_read_control(expand3_t *ctx, uint8_t *control)
Expand 3 read control function.
void expand3_gpio_selection(expand3_cfg_t *cfg, expand3_gpio_sel_t gpio_sel)
Expand 3 driver interface setup function.
void expand3_reset_device(expand3_t *ctx)
Expand 3 reset device function.
err_t expand3_default_cfg(expand3_t *ctx)
Expand 3 default configuration function.
err_t expand3_init(expand3_t *ctx, expand3_cfg_t *cfg)
Expand 3 initialization function.
err_t expand3_read_current_state(expand3_t *ctx, uint8_t *curr_state)
Expand 3 read current state function.
err_t expand3_write_state(expand3_t *ctx, uint8_t state)
Expand 3 write state function.
err_t expand3_read_last_state(expand3_t *ctx, uint8_t *last_state)
Expand 3 read last state function.
void expand3_set_rst_pin(expand3_t *ctx, uint8_t state)
Expand 3 set rst pin function.
Expand 3 Click configuration object.
Definition expand3.h:204
pin_name_t ow0
Definition expand3.h:206
pin_name_t rst
Definition expand3.h:210
expand3_gpio_sel_t gpio_sel
Definition expand3.h:212
pin_name_t ow1
Definition expand3.h:207
Expand 3 Click context object.
Definition expand3.h:187
one_wire_rom_address_t rom_addr
Definition expand3.h:194
digital_out_t rst
Definition expand3.h:189
uint8_t address
Definition expand3.h:195
one_wire_t ow
Definition expand3.h:192