i2c1wire 2.0.0.0
i2c1wire.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef I2C1WIRE_H
36#define I2C1WIRE_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define I2C1WIRE_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
75#define I2C1WIRE_OK 0
76#define I2C1WIRE_ERROR -1
83#define I2C1WIRE_RESULT_ERROR 0x00
84#define I2C1WIRE_RESULT_OK 0x01
85#define I2C1WIRE_WIRE_RESULT_OK 0xFF
86
87#define I2C1WIRE_I2C_ADDRESS_0 0x18
88#define I2C1WIRE_I2C_ADDRESS_1 0x19
89#define I2C1WIRE_I2C_ADDRESS_2 0x1A
90#define I2C1WIRE_I2C_ADDRESS_3 0x1B
91#define I2C1WIRE_I2C_ADDRESS_4 0x1C
92#define I2C1WIRE_I2C_ADDRESS_5 0x1D
93#define I2C1WIRE_I2C_ADDRESS_6 0x1E
94#define I2C1WIRE_I2C_ADDRESS_7 0x1F
95
96#define I2C1WIRE_COMMAND_RESET 0xF0
97#define I2C1WIRE_COMMAND_SRP 0xE1
98#define I2C1WIRE_POINTER_STATUS 0xF0
99#define I2C1WIRE_STATUS_BUSY 0x01
100#define I2C1WIRE_STATUS_PPD 0x02
101#define I2C1WIRE_STATUS_SD 0x04
102#define I2C1WIRE_STATUS_LL 0x08
103#define I2C1WIRE_STATUS_RST 0x10
104#define I2C1WIRE_STATUS_SBR 0x20
105#define I2C1WIRE_STATUS_TSB 0x40
106#define I2C1WIRE_STATUS_DIR 0x80
107#define I2C1WIRE_POINTER_DATA 0xE1
108#define I2C1WIRE_POINTER_CONFIG 0xC3
109#define I2C1WIRE_CONFIG_APU_HIGH 0x30
110#define I2C1WIRE_CONFIG_APU_LOW 0x01
111#define I2C1WIRE_CONFIG_SPU_HIGH 0x60
112#define I2C1WIRE_CONFIG_SPU_LOW 0x04
113#define I2C1WIRE_CONFIG_1WS_HIGH 0xA0
114#define I2C1WIRE_CONFIG_1WS_LOW 0x08
115#define I2C1WIRE_COMMAND_WRITECONFIG 0xD2
116#define I2C1WIRE_COMMAND_RESETWIRE 0xB4
117#define I2C1WIRE_COMMAND_WRITEBYTE 0xA5
118#define I2C1WIRE_COMMAND_READBYTE 0x96
119#define I2C1WIRE_COMMAND_SINGLEBIT 0x87
120#define I2C1WIRE_COMMAND_TRIPLET 0x78
121#define I2C1WIRE_WIRE_COMMAND_SKIP 0xCC
122#define I2C1WIRE_WIRE_COMMAND_SELECT 0x55
123#define I2C1WIRE_WIRE_COMMAND_READ_ROM 0x33
124#define I2C1WIRE_WIRE_COMMAND_SEARCH 0xF0
125#define I2C1WIRE_ERROR_TIMEOUT 0x01
126#define I2C1WIRE_ERROR_SHORT 0x02
127#define I2C1WIRE_ERROR_CONFIG 0x04
128#define I2C1WIRE_CMD_CHSL 0xC3
129#define I2C1WIRE_CH_IO0 0xF0
130#define I2C1WIRE_CH_IO1 0xE1
131#define I2C1WIRE_CH_IO2 0xD2
132#define I2C1WIRE_CH_IO3 0xC3
133#define I2C1WIRE_CH_IO4 0xB4
134#define I2C1WIRE_CH_IO5 0xA5
135#define I2C1WIRE_CH_IO6 0x96
136#define I2C1WIRE_CH_IO7 0x87
137#define I2C1WIRE_RCH_IO0 0xB8
138#define I2C1WIRE_RCH_IO1 0xB1
139#define I2C1WIRE_RCH_IO2 0xAA
140#define I2C1WIRE_RCH_IO3 0xA3
141#define I2C1WIRE_RCH_IO4 0x9C
142#define I2C1WIRE_RCH_IO5 0x95
143#define I2C1WIRE_RCH_IO6 0x8E
144#define I2C1WIRE_RCH_IO7 0x87
147 // End group macro
148// --------------------------------------------------------------- PUBLIC TYPES
157typedef struct
158{
159 // Modules
160 i2c_master_t i2c;
161
162 // ctx variable
164
165} i2c1wire_t;
166
170typedef struct
171{
172 // Communication gpio pins
173 pin_name_t scl;
174 pin_name_t sda;
175
176 // static variable
177 uint32_t i2c_speed;
178 uint8_t i2c_address;
179
181
182 // End types group
183// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184
190#ifdef __cplusplus
191extern "C"{
192#endif
193
203
213
224err_t i2c1wire_generic_write ( i2c1wire_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
225
236err_t i2c1wire_generic_read ( i2c1wire_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
237
246
255uint8_t i2c1wire_set_config ( i2c1wire_t *ctx, uint8_t cfg );
256
265uint8_t i2c1wire_set_channel ( i2c1wire_t *ctx, uint8_t chan );
266
275void i2c1wire_set_read_pointer ( i2c1wire_t *ctx, uint8_t ptr );
276
285
294void i2c1wire_write_byte_one_wire ( i2c1wire_t *ctx, uint8_t input );
295
304
305#ifdef __cplusplus
306}
307#endif
308#endif // _I2C1WIRE_H_
309
310 // End public_function group
312
313// ------------------------------------------------------------------------- END
uint8_t i2c1wire_read_byte_one_wire(i2c1wire_t *ctx)
Read byte function.
uint8_t i2c1wire_set_config(i2c1wire_t *ctx, uint8_t cfg)
Set configuration function.
void i2c1wire_write_byte_one_wire(i2c1wire_t *ctx, uint8_t input)
Write byte function.
err_t i2c1wire_init(i2c1wire_t *ctx, i2c1wire_cfg_t *cfg)
Initialization function.
void i2c1wire_soft_reset(i2c1wire_t *ctx)
Software reset function.
err_t i2c1wire_generic_read(i2c1wire_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Generic read function.
err_t i2c1wire_generic_write(i2c1wire_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Generic write function.
void i2c1wire_set_read_pointer(i2c1wire_t *ctx, uint8_t ptr)
Set read pointer function.
uint8_t i2c1wire_set_channel(i2c1wire_t *ctx, uint8_t chan)
Set channel function.
void i2c1wire_cfg_setup(i2c1wire_cfg_t *cfg)
Config Object Initialization function.
void i2c1wire_one_wire_reset(i2c1wire_t *ctx)
Reset function.
Click configuration structure definition.
Definition i2c1wire.h:171
uint32_t i2c_speed
Definition i2c1wire.h:177
pin_name_t scl
Definition i2c1wire.h:173
pin_name_t sda
Definition i2c1wire.h:174
uint8_t i2c_address
Definition i2c1wire.h:178
Click ctx object definition.
Definition i2c1wire.h:158
i2c_master_t i2c
Definition i2c1wire.h:160
uint8_t slave_address
Definition i2c1wire.h:163