]>
cloudbase.mooo.com Git - z180-stamp.git/blob - include/i2c.h
2 * Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net>
3 * Copyright (C) 2009 - 2013 Heiko Schocher <hs@denx.de>
4 * Changes for multibus/multiadapter I2C support.
7 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
9 * SPDX-License-Identifier: GPL-2.0+
11 * The original I2C interface was
12 * (C) 2000 by Paolo Scaffardi (arsenio@tin.it)
13 * AIRVENT SAM s.p.a - RIMINI(ITALY)
14 * but has been changed substantially.
21 * Configuration items.
24 #define I2C_RXTX_LEN 128 /* maximum tx/rx buffer length */
28 * Initialization, must be called once on start up, may be called
29 * repeatedly to change the speed.
31 void i2c_init(uint32_t speed
);
34 * Probe the given I2C chip address. Returns 0 if a chip responded,
37 int i2c_probe(uint8_t chip
);
40 * Read/Write interface:
41 * chip: I2C chip address, range 0..127
42 * addr: Memory (register) address within the chip
43 * alen: Number of bytes to use for addr (typically 1, 2 for larger
44 * memories, 0 for register type devices with only one
46 * buffer: Where to read/write the data
47 * len: How many bytes to read/write
49 * Returns: 0 on success, not 0 on failure
51 int i2c_read(uint8_t chip
, unsigned int addr
, uint_fast8_t alen
,
52 uint8_t *buffer
, uint_fast8_t len
);
53 int i2c_write(uint8_t chip
, unsigned int addr
, uint_fast8_t alen
,
54 uint8_t *buffer
, uint_fast8_t len
);
57 * Utility routines to read/write registers.
59 uint8_t i2c_reg_read(uint8_t addr
, uint8_t reg
);
61 void i2c_reg_write(uint8_t addr
, uint8_t reg
, uint8_t val
);