Typo.
[bertos.git] / bertos / drv / i2c.h
index c7fa9587f8aa960767a375c059c53b23af41f54d..d934497bc684d470df6d0f572425c30d55130210 100644 (file)
@@ -37,6 +37,7 @@
  * $WIZ$ module_name = "i2c"
  * $WIZ$ module_configuration = "bertos/cfg/cfg_i2c.h"
  * $WIZ$ module_hw = "bertos/hw/hw_i2c_bitbang.h"
+ * $WIZ$ module_depends = "i2c_bitbang"
  * $WIZ$ module_supports = "not atmega103 and not atmega168 and not at91"
  */
 
        #define i2c_start_r(args...)    PP_CAT(i2c_start_r ## _, COUNT_PARMS(args)) (args)
 #endif
 
+
+#if !CONFIG_I2C_DISABLE_OLD_API
 /**
  * I2C Backends.
  * Sometimes your cpu does not have a builtin
  * i2c driver or you don't want, for some reason, to
  * use that.
  * With this you can choose, at compile time, which backend to use.
- *
- * $WIZ$ i2c_backend = "I2C_BACKEND_BUILTIN", "I2C_BACKEND_BITBANG"
  */
 #define I2C_BACKEND_BUILTIN 0 ///< Uses cpu builtin i2c driver
 #define I2C_BACKEND_BITBANG 1 ///< Uses emulated bitbang driver
@@ -107,6 +108,10 @@ bool i2c_bitbang_put(uint8_t _data);
 int i2c_bitbang_get(bool ack);
 /*\}*/
 
+#ifndef CONFIG_I2C_BACKEND
+#define  CONFIG_I2C_BACKEND  I2C_BACKEND_BUILTIN
+#endif
+
 #if CONFIG_I2C_BACKEND == I2C_BACKEND_BUILTIN
        #define i2c_init_0      i2c_builtin_init
        #define i2c_start_w_1   i2c_builtin_start_w
@@ -129,11 +134,31 @@ int i2c_bitbang_get(bool ack);
 bool i2c_send(const void *_buf, size_t count);
 bool i2c_recv(void *_buf, size_t count);
 
+#endif
 
 /*
  * I2c new api
  */
 
+/**
+ * \name I2C bitbang devices enum
+ */
+enum
+{
+       I2C_BITBANG0 = 1000,
+       I2C_BITBANG1,
+       I2C_BITBANG2,
+       I2C_BITBANG3,
+       I2C_BITBANG4,
+       I2C_BITBANG5,
+       I2C_BITBANG6,
+       I2C_BITBANG7,
+       I2C_BITBANG8,
+       I2C_BITBANG9,
+
+       I2C_BITBANG_CNT  /**< Number of serial ports */
+};
+
  /*
   * I2C error flags
   */
@@ -190,6 +215,7 @@ typedef struct I2c
  * Low level i2c  init implementation prototype.
  */
 void i2c_hw_init(I2c *i2c, int dev, uint32_t clock);
+void i2c_hw_bitbangInit(I2c *i2c, int dev);
 
 void i2c_genericWrite(I2c *i2c, const void *_buf, size_t count);
 void i2c_genericRead(I2c *i2c, void *_buf, size_t count);
@@ -301,9 +327,7 @@ INLINE int i2c_error(I2c *i2c)
        return err;
 }
 
-INLINE void i2c_init_3(I2c *i2c, int dev, uint32_t clock)
-{
-       i2c_hw_init(i2c, dev, clock);
-}
+#define i2c_init_3(i2c, dev, clock)   (dev > I2C_BITBANG0) ?  i2c_hw_bitbangInit(i2c, dev) : i2c_hw_init(i2c, dev, clock)
+
 
 #endif