summaryrefslogtreecommitdiff
path: root/include/i2c.h
diff options
context:
space:
mode:
authorLeo C2014-08-23 19:34:22 +0200
committerLeo C2014-08-23 19:34:22 +0200
commit61b0cfe9df810db4fbca78e5f880d61c5063f324 (patch)
treeec9b73a87afa5fdd90acc3c7309104399db104b7 /include/i2c.h
parent21a24f90c5aaaaf13f91716208b32cde163c5918 (diff)
downloadz180-stamp-61b0cfe9df810db4fbca78e5f880d61c5063f324.zip
Add date rtc i2c
Diffstat (limited to 'include/i2c.h')
-rw-r--r--include/i2c.h63
1 files changed, 63 insertions, 0 deletions
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 <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_*/