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 
63 #ifndef PERIPH_I2C_H
64 #define PERIPH_I2C_H
65 
66 #include <stdint.h>
67 #include <limits.h>
68 
69 #include "periph_cpu.h"
74 #include "periph/dev_enums.h"
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
83 #define I2C_FLAG_WRITE 0
84 
88 #define I2C_FLAG_READ 1
89 
93 #ifndef I2C_DEV
94 #define I2C_DEV(x) (x)
95 #endif
96 
100 #ifndef I2C_UNDEF
101 #define I2C_UNDEF (UINT_MAX)
102 #endif
103 
107 #ifndef HAVE_I2C_T
108 typedef unsigned int i2c_t;
109 #endif
110 
114 #ifndef HAVE_I2C_SPEED_T
115 typedef enum {
121 } i2c_speed_t;
122 #endif
123 
134 int i2c_init_master(i2c_t dev, i2c_speed_t speed);
135 
147 int i2c_acquire(i2c_t dev);
148 
157 int i2c_release(i2c_t dev);
158 
170 int i2c_read_byte(i2c_t dev, uint8_t address, void *data);
171 
183 int i2c_read_bytes(i2c_t dev, uint8_t address, void *data, int length);
184 
197 int i2c_read_reg(i2c_t dev, uint8_t address, uint8_t reg, void *data);
198 
212 int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg,
213  void *data, int length);
214 
225 int i2c_write_byte(i2c_t dev, uint8_t address, uint8_t data);
226 
238 int i2c_write_bytes(i2c_t dev, uint8_t address, const void *data, int length);
239 
251 int i2c_write_reg(i2c_t dev, uint8_t address, uint8_t reg, uint8_t data);
252 
266 int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg,
267  const void *data, int length);
268 
274 void i2c_poweron(i2c_t dev);
275 
281 void i2c_poweroff(i2c_t dev);
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif /* PERIPH_I2C_H */
288 
fast mode: ~400kbit/sj
Definition: i2c.h:118
high speed mode: ~3.4Mbit/s
Definition: i2c.h:120
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:115
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:108
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:116
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:117
fast plus mode: ~1Mbit/s
Definition: i2c.h:119
int i2c_read_byte(i2c_t dev, uint8_t address, void *data)
Read one byte from an I2C device with the given address.