1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*
* Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net>
* Copyright (C) 2009 - 2013 Heiko Schocher <hs@denx.de>
* Changes for multibus/multiadapter I2C support.
*
* (C) Copyright 2001
* Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
*
* SPDX-License-Identifier: GPL-2.0+
*
* The original I2C interface was
* (C) 2000 by Paolo Scaffardi (arsenio@tin.it)
* AIRVENT SAM s.p.a - RIMINI(ITALY)
* but has been changed substantially.
*/
#ifndef _I2C_H_
#define _I2C_H_
/*
* Configuration items.
*/
/* TODO: config.h? */
#define I2C_RXTX_LEN 128 /* maximum tx/rx buffer length */
/*
* Initialization, must be called once on start up, may be called
* repeatedly to change the speed.
*/
void i2c_init(uint32_t speed);
/*
* Probe the given I2C chip address. Returns 0 if a chip responded,
* not 0 on failure.
*/
int i2c_probe(uint8_t chip);
/*
* Read/Write interface:
* chip: I2C chip address, range 0..127
* addr: Memory (register) address within the chip
* alen: Number of bytes to use for addr (typically 1, 2 for larger
* memories, 0 for register type devices with only one
* register)
* buffer: Where to read/write the data
* len: How many bytes to read/write
*
* Returns: 0 on success, not 0 on failure
*/
int i2c_read(uint8_t chip, unsigned int addr, uint_fast8_t alen,
uint8_t *buffer, uint_fast8_t len);
int i2c_write(uint8_t chip, unsigned int addr, uint_fast8_t alen,
uint8_t *buffer, uint_fast8_t len);
/*
* Utility routines to read/write registers.
*/
uint8_t i2c_reg_read(uint8_t addr, uint8_t reg);
void i2c_reg_write(uint8_t addr, uint8_t reg, uint8_t val);
#endif /* _I2C_H_*/
|