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 
94 #ifndef I2C_DEV
95 #define I2C_DEV(x) (x)
96 #endif
97 
103 #ifndef I2C_UNDEF
104 #define I2C_UNDEF (UINT_MAX)
105 #endif
106 
112 #ifndef HAVE_I2C_T
113 typedef unsigned int i2c_t;
114 #endif
115 
121 #ifndef HAVE_I2C_SPEED_T
122 typedef enum {
128 } i2c_speed_t;
129 #endif
130 
142 int i2c_init_master(i2c_t dev, i2c_speed_t speed);
143 
155 int i2c_acquire(i2c_t dev);
156 
165 int i2c_release(i2c_t dev);
166 
178 int i2c_read_byte(i2c_t dev, uint8_t address, void *data);
179 
191 int i2c_read_bytes(i2c_t dev, uint8_t address, void *data, int length);
192 
205 int i2c_read_reg(i2c_t dev, uint8_t address, uint8_t reg, void *data);
206 
220 int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg,
221  void *data, int length);
222 
233 int i2c_write_byte(i2c_t dev, uint8_t address, uint8_t data);
234 
246 int i2c_write_bytes(i2c_t dev, uint8_t address, const void *data, int length);
247 
259 int i2c_write_reg(i2c_t dev, uint8_t address, uint8_t reg, uint8_t data);
260 
274 int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg,
275  const void *data, int length);
276 
282 void i2c_poweron(i2c_t dev);
283 
289 void i2c_poweroff(i2c_t dev);
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 
295 #endif /* PERIPH_I2C_H */
296 
fast mode: ~400kbit/sj
Definition: i2c.h:125
high speed mode: ~3.4Mbit/s
Definition: i2c.h:127
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:122
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:113
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:123
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:124
fast plus mode: ~1Mbit/s
Definition: i2c.h:126
int i2c_read_byte(i2c_t dev, uint8_t address, void *data)
Read one byte from an I2C device with the given address.