From 61b0cfe9df810db4fbca78e5f880d61c5063f324 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 23 Aug 2014 19:34:22 +0200 Subject: Add date rtc i2c --- include/i2c.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 include/i2c.h (limited to 'include/i2c.h') diff --git a/include/i2c.h b/include/i2c.h new file mode 100644 index 0000000..50b1fd0 --- /dev/null +++ b/include/i2c.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2009 Sergey Kubushyn + * Copyright (C) 2009 - 2013 Heiko Schocher + * 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_*/ -- cgit v1.2.3