c1wirei2c 2.1.0.0
c1wirei2c.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 C1WIREI2C_H
29#define C1WIREI2C_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 C1WIREI2C_CMD_WRITE_DATA_WITH_STOP 0x4B
74#define C1WIREI2C_CMD_WRITE_DATA_NO_STOP 0x5A
75#define C1WIREI2C_CMD_WRITE_DATA_ONLY 0x69
76#define C1WIREI2C_CMD_WRITE_DATA_ONLY_WITH_STOP 0x78
77#define C1WIREI2C_CMD_READ_DATA_WITH_STOP 0x87
78#define C1WIREI2C_CMD_WRITE_READ_DATA_WITH_STOP 0x2D
79#define C1WIREI2C_CMD_WRITE_CONFIGURATION 0xD2
80#define C1WIREI2C_CMD_READ_CONFIGURATION 0xE1
81#define C1WIREI2C_CMD_ENABLE_SLEEP_MODE 0x1E
82#define C1WIREI2C_CMD_READ_DEVICE_REVISION 0xC3
83
84 // c1wirei2c_cmd
85
100#define C1WIREI2C_CONFIGURATION_SPD_100KHZ 0x00
101#define C1WIREI2C_CONFIGURATION_SPD_400KHZ 0x01
102#define C1WIREI2C_CONFIGURATION_SPD_900KHZ 0x02
103#define C1WIREI2C_CONFIGURATION_SPD_MASK 0x03
104
109#define C1WIREI2C_FAMILY_CODE 0x19
110
115#define C1WIREI2C_ADDRESS_0 0x00
116#define C1WIREI2C_ADDRESS_ALL 0xFF
117
118 // c1wirei2c_set
119
134#define C1WIREI2C_MAP_MIKROBUS( cfg, mikrobus ) \
135 cfg.ow2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
136 cfg.ow1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
137 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
138
139 // c1wirei2c_map
140 // c1wirei2c
141
152
157typedef struct
158{
159 // Output pins
160 digital_out_t rst;
162 // Modules
163 one_wire_t ow;
165 one_wire_rom_address_t rom_addr;
166 uint8_t address;
169
174typedef struct
175{
176 // Communication gpio pins
177 pin_name_t ow1;
178 pin_name_t ow2;
180 // Additional gpio pins
181 pin_name_t rst;
186
197
214
230
245
259
272
285
299err_t c1wirei2c_write_data_stop ( c1wirei2c_t *ctx, uint8_t slave_addr, uint8_t *data_in, uint8_t len );
300
316err_t c1wirei2c_write_data ( c1wirei2c_t *ctx, uint8_t slave_addr, uint8_t *data_in, uint8_t len );
317
332err_t c1wirei2c_write_data_only ( c1wirei2c_t *ctx, uint8_t *data_in, uint8_t len );
333
347err_t c1wirei2c_write_data_only_stop ( c1wirei2c_t *ctx, uint8_t *data_in, uint8_t len );
348
362err_t c1wirei2c_read_data_stop ( c1wirei2c_t *ctx, uint8_t slave_addr, uint8_t *data_out, uint8_t len );
363
380err_t c1wirei2c_write_read_data_stop ( c1wirei2c_t *ctx, uint8_t slave_addr,
381 uint8_t *data_in, uint8_t in_len, uint8_t *data_out, uint8_t out_len );
382
394err_t c1wirei2c_write_configuration ( c1wirei2c_t *ctx, uint8_t config );
395
407err_t c1wirei2c_read_configuration ( c1wirei2c_t *ctx, uint8_t *config );
408
420
433err_t c1wirei2c_read_device_revision ( c1wirei2c_t *ctx, uint8_t *revision );
434
444void c1wirei2c_set_rst_pin ( c1wirei2c_t *ctx, uint8_t state );
445
455
456#ifdef __cplusplus
457}
458#endif
459#endif // C1WIREI2C_H
460
461 // c1wirei2c
462
463// ------------------------------------------------------------------------ END
c1wirei2c_gpio_sel_t
1-Wire I2C Click gpio selector.
Definition c1wirei2c.h:147
@ C1WIREI2C_GPIO_OW2
Definition c1wirei2c.h:149
@ C1WIREI2C_GPIO_OW1
Definition c1wirei2c.h:148
c1wirei2c_return_value_t
1-Wire I2C Click return value data.
Definition c1wirei2c.h:192
@ C1WIREI2C_OK
Definition c1wirei2c.h:193
@ C1WIREI2C_ERROR
Definition c1wirei2c.h:194
void c1wirei2c_gpio_selection(c1wirei2c_cfg_t *cfg, c1wirei2c_gpio_sel_t gpio_sel)
1-Wire I2C driver interface setup function.
err_t c1wirei2c_init(c1wirei2c_t *ctx, c1wirei2c_cfg_t *cfg)
1-Wire I2C initialization function.
err_t c1wirei2c_read_data_stop(c1wirei2c_t *ctx, uint8_t slave_addr, uint8_t *data_out, uint8_t len)
1-Wire I2C read data stop function.
err_t c1wirei2c_read_configuration(c1wirei2c_t *ctx, uint8_t *config)
1-Wire I2C read configuration function.
err_t c1wirei2c_write_data_only(c1wirei2c_t *ctx, uint8_t *data_in, uint8_t len)
1-Wire I2C write data only function.
err_t c1wirei2c_write_data_stop(c1wirei2c_t *ctx, uint8_t slave_addr, uint8_t *data_in, uint8_t len)
1-Wire I2C write data stop function.
void c1wirei2c_set_rst_pin(c1wirei2c_t *ctx, uint8_t state)
1-Wire I2C set rst pin function.
err_t c1wirei2c_select_device(c1wirei2c_t *ctx)
1-Wire I2C select device function.
err_t c1wirei2c_write_read_data_stop(c1wirei2c_t *ctx, uint8_t slave_addr, uint8_t *data_in, uint8_t in_len, uint8_t *data_out, uint8_t out_len)
1-Wire I2C write read data stop function.
void c1wirei2c_cfg_setup(c1wirei2c_cfg_t *cfg)
1-Wire I2C configuration object setup function.
err_t c1wirei2c_write_data_only_stop(c1wirei2c_t *ctx, uint8_t *data_in, uint8_t len)
1-Wire I2C write data only stop function.
void c1wirei2c_reset_device(c1wirei2c_t *ctx)
1-Wire I2C reset device function.
err_t c1wirei2c_read_device_revision(c1wirei2c_t *ctx, uint8_t *revision)
1-Wire I2C read device revision function.
err_t c1wirei2c_check_communication(c1wirei2c_t *ctx)
1-Wire I2C check communication function.
err_t c1wirei2c_enable_sleep_mode(c1wirei2c_t *ctx)
1-Wire I2C enable sleep mode function.
err_t c1wirei2c_default_cfg(c1wirei2c_t *ctx)
1-Wire I2C default configuration function.
err_t c1wirei2c_write_configuration(c1wirei2c_t *ctx, uint8_t config)
1-Wire I2C write configuration function.
err_t c1wirei2c_write_data(c1wirei2c_t *ctx, uint8_t slave_addr, uint8_t *data_in, uint8_t len)
1-Wire I2C write data function.
1-Wire I2C Click configuration object.
Definition c1wirei2c.h:175
pin_name_t ow2
Definition c1wirei2c.h:178
c1wirei2c_gpio_sel_t gpio_sel
Definition c1wirei2c.h:183
pin_name_t rst
Definition c1wirei2c.h:181
pin_name_t ow1
Definition c1wirei2c.h:177
1-Wire I2C Click context object.
Definition c1wirei2c.h:158
one_wire_rom_address_t rom_addr
Definition c1wirei2c.h:165
digital_out_t rst
Definition c1wirei2c.h:160
uint8_t address
Definition c1wirei2c.h:166
one_wire_t ow
Definition c1wirei2c.h:163