c1wireswitch 2.1.0.0
c1wireswitch.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 C1WIRESWITCH_H
29#define C1WIRESWITCH_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_one_wire.h"
38
59#define C1WIRESWITCH_CMD_WRITE_SCRATCHPAD 0x5A
60#define C1WIRESWITCH_CMD_READ_SCRATCHPAD 0xF5
61
62#define C1WIRESWITCH_CMD_WRITE_PIO 0x5A
63#define C1WIRESWITCH_CMD_READ_PIO 0xF5
64
69#define C1WIRESWITCH_PIOB_STATE_MASK 0x04
70#define C1WIRESWITCH_PIOA_STATE_MASK 0x01
71#define C1WIRESWITCH_PIOB_LATCH_STATE_MASK 0x08
72#define C1WIRESWITCH_PIOA_LATCH_STATE_MASK 0x02
73
78#define C1WIRESWITCH_PIOA_HIGH 0x01
79#define C1WIRESWITCH_PIOA_LOW 0x00
80#define C1WIRESWITCH_PIOB_HIGH 0x04
81#define C1WIRESWITCH_PIOB_LOW 0x00
82
83#define C1WIRESWITCH_PIOB_ON 0x02
84#define C1WIRESWITCH_PIOB_OFF 0x00
85#define C1WIRESWITCH_PIOA_ON 0x00
86#define C1WIRESWITCH_PIOA_OFF 0x01
87
88#define C1WIRESWITCH_PIOB_LATCH_LOW 0x00
89#define C1WIRESWITCH_PIOB_LATCH_HIGH 0x08
90#define C1WIRESWITCH_PIOA_LATCH_LOW 0x00
91#define C1WIRESWITCH_PIOA_LATCH_HIGH 0x02
92 // c1wireswitch_cmd
94
109#define C1WIRESWITCH_FAMILY_CODE 0x3A
110
115#define C1WIRESWITCH_ADDRESS 0x33
116#define C1WIRESWITCH_ADDRESS_ALL 0xFF
117 // c1wireswitch_set
119
134#define C1WIRESWITCH_MAP_MIKROBUS( cfg, mikrobus ) \
135 cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
136 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN );
137 // c1wireswitch_map // c1wireswitch
140
145typedef enum
146{
151
156typedef struct
157{
158 // Modules
159 one_wire_t ow;
161 one_wire_rom_address_t rom_addr;
162 uint8_t address;
165
170typedef struct
171{
172 // Communication gpio pins
173 pin_name_t gp0;
174 pin_name_t gp1;
179
184typedef enum
185{
188
190
207
223
238
252
265
278
291err_t c1wireswitch_read_scratchpad ( c1wireswitch_t *ctx, uint8_t *scratchpad, uint8_t scratchpad_len );
292
305err_t c1wireswitch_write_scratchpad ( c1wireswitch_t *ctx, uint8_t *scratchpad, uint8_t scratchpad_len );
306
318err_t c1wireswitch_write_pio ( c1wireswitch_t *ctx, uint8_t state );
319
331err_t c1wireswitch_read_pio ( c1wireswitch_t *ctx, uint8_t *state );
332
345err_t c1wireswitch_set_pio_state ( c1wireswitch_t *ctx, uint8_t pio_a, uint8_t pio_b );
346
359err_t c1wireswitch_get_pio_state ( c1wireswitch_t *ctx, uint8_t *pio_a, uint8_t *pio_b );
360
373err_t c1wireswitch_get_pio_latch_state ( c1wireswitch_t *ctx, uint8_t *pio_a_latch, uint8_t *pio_b_latch );
374
375#ifdef __cplusplus
376}
377#endif
378#endif // C1WIRESWITCH_H
379 // c1wireswitch
381
382// ------------------------------------------------------------------------ END
c1wireswitch_return_value_t
1-Wire Switch Click return value data.
Definition: c1wireswitch.h:185
@ C1WIRESWITCH_OK
Definition: c1wireswitch.h:186
@ C1WIRESWITCH_ERROR
Definition: c1wireswitch.h:187
c1wireswitch_gpio_sel_t
1-Wire Switch Click gpio selector.
Definition: c1wireswitch.h:146
@ C1WIRESWITCH_GPIO_0
Definition: c1wireswitch.h:147
@ C1WIRESWITCH_GPIO_1
Definition: c1wireswitch.h:148
err_t c1wireswitch_set_pio_state(c1wireswitch_t *ctx, uint8_t pio_a, uint8_t pio_b)
1-Wire Switch write specific programmable I/O state function.
void c1wireswitch_gpio_selection(c1wireswitch_cfg_t *cfg, c1wireswitch_gpio_sel_t gpio_sel)
1-Wire Switch driver interface setup function.
err_t c1wireswitch_check_communication(c1wireswitch_t *ctx)
1-Wire Switch check communication function.
err_t c1wireswitch_read_scratchpad(c1wireswitch_t *ctx, uint8_t *scratchpad, uint8_t scratchpad_len)
1-Wire Switch read scratchpad function.
err_t c1wireswitch_init(c1wireswitch_t *ctx, c1wireswitch_cfg_t *cfg)
1-Wire Switch initialization function.
err_t c1wireswitch_get_pio_state(c1wireswitch_t *ctx, uint8_t *pio_a, uint8_t *pio_b)
1-Wire Switch read specific programmable I/O state function.
err_t c1wireswitch_default_cfg(c1wireswitch_t *ctx)
1-Wire Switch default configuration function.
err_t c1wireswitch_write_scratchpad(c1wireswitch_t *ctx, uint8_t *scratchpad, uint8_t scratchpad_len)
1-Wire Switch write scratchpad function.
err_t c1wireswitch_write_pio(c1wireswitch_t *ctx, uint8_t state)
1-Wire Switch write programmable I/O state function.
err_t c1wireswitch_select_device(c1wireswitch_t *ctx)
1-Wire Switch select device function.
void c1wireswitch_cfg_setup(c1wireswitch_cfg_t *cfg)
1-Wire Switch configuration object setup function.
err_t c1wireswitch_read_pio(c1wireswitch_t *ctx, uint8_t *state)
1-Wire Switch read programmable I/O state function.
err_t c1wireswitch_get_pio_latch_state(c1wireswitch_t *ctx, uint8_t *pio_a_latch, uint8_t *pio_b_latch)
1-Wire Switch read programmable I/O latch state function.
1-Wire Switch Click configuration object.
Definition: c1wireswitch.h:171
pin_name_t gp0
Definition: c1wireswitch.h:173
c1wireswitch_gpio_sel_t gpio_sel
Definition: c1wireswitch.h:176
pin_name_t gp1
Definition: c1wireswitch.h:174
1-Wire Switch Click context object.
Definition: c1wireswitch.h:157
one_wire_rom_address_t rom_addr
Definition: c1wireswitch.h:161
uint8_t address
Definition: c1wireswitch.h:162
one_wire_t ow
Definition: c1wireswitch.h:159