The friendly Operating System for the Internet of Things
i2c.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
54 #ifndef I2C_H
55 #define I2C_H
56 
57 #include <stdint.h>
58 #include <limits.h>
59 
60 #include "periph_cpu.h"
65 #include "periph/dev_enums.h"
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
74 #define I2C_FLAG_WRITE 0
75 
79 #define I2C_FLAG_READ 1
80 
85 #ifndef I2C_DEV
86 #define I2C_DEV(x) (x)
87 #endif
88 
94 #ifndef I2C_UNDEF
95 #define I2C_UNDEF (UINT_MAX)
96 #endif
97 
103 #ifndef HAVE_I2C_T
104 typedef unsigned int i2c_t;
105 #endif
106 
112 #ifndef HAVE_I2C_SPEED_T
113 typedef enum {
119 } i2c_speed_t;
120 #endif
121 
133 int i2c_init_master(i2c_t dev, i2c_speed_t speed);
134 
146 int i2c_acquire(i2c_t dev);
147 
156 int i2c_release(i2c_t dev);
157 
169 int i2c_read_byte(i2c_t dev, uint8_t address, void *data);
170 
182 int i2c_read_bytes(i2c_t dev, uint8_t address, void *data, int length);
183 
196 int i2c_read_reg(i2c_t dev, uint8_t address, uint8_t reg, void *data);
197 
211 int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg,
212  void *data, int length);
213 
224 int i2c_write_byte(i2c_t dev, uint8_t address, uint8_t data);
225 
237 int i2c_write_bytes(i2c_t dev, uint8_t address, const void *data, int length);
238 
250 int i2c_write_reg(i2c_t dev, uint8_t address, uint8_t reg, uint8_t data);
251 
265 int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg,
266  const void *data, int length);
267 
273 void i2c_poweron(i2c_t dev);
274 
280 void i2c_poweroff(i2c_t dev);
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 
286 #endif /* I2C_H */
287 
fast mode: ~400kbit/sj
Definition: i2c.h:116
high speed mode: ~3.4Mbit/s
Definition: i2c.h:118
int i2c_init_master(i2c_t dev, i2c_speed_t speed)
Initialize an I2C device to run as bus master.
int i2c_read_reg(i2c_t dev, uint8_t address, uint8_t reg, void *data)
Read one byte from a register at the I2C slave with the given address.
int i2c_read_bytes(i2c_t dev, uint8_t address, void *data, int length)
Read multiple bytes from an I2C device with the given address.
int i2c_release(i2c_t dev)
Release the given I2C device to be used by others.
int i2c_acquire(i2c_t dev)
Get mutually exclusive access to the given I2C bus.
i2c_speed_t
Default mapping of I2C bus speed values.
Definition: i2c.h:113
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:104
int i2c_write_bytes(i2c_t dev, uint8_t address, const void *data, int length)
Write multiple bytes to an I2C device with the given address.
Device enumerations for backward compatibility with existing peripheral driver implementations.
void i2c_poweroff(i2c_t dev)
Power off the given I2C peripheral.
int i2c_write_reg(i2c_t dev, uint8_t address, uint8_t reg, uint8_t data)
Write one byte to a register at the I2C slave with the given address.
int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg, void *data, int length)
Read multiple bytes from a register at the I2C slave with the given address.
void i2c_poweron(i2c_t dev)
Power on the given I2C peripheral.
int i2c_write_byte(i2c_t dev, uint8_t address, uint8_t data)
Write one byte to an I2C device with the given address.
low speed mode: ~10kbit/s
Definition: i2c.h:114
int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg, const void *data, int length)
Write multiple bytes to a register at the I2C slave with the given address.
normal mode: ~100kbit/s
Definition: i2c.h:115
fast plus mode: ~1Mbit/s
Definition: i2c.h:117
int i2c_read_byte(i2c_t dev, uint8_t address, void *data)
Read one byte from an I2C device with the given address.