From 76ee8a1f5f851680ee237f1a7064b03c9de48aa2 Mon Sep 17 00:00:00 2001 From: asterix Date: Thu, 22 Jul 2010 16:49:59 +0000 Subject: [PATCH] Add implementation for oveloaded functions. git-svn-id: https://src.develer.com/svnoss/bertos/branches/i2c@4051 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/drv/i2c.h | 76 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/bertos/drv/i2c.h b/bertos/drv/i2c.h index bf5e12c0..60e40f18 100644 --- a/bertos/drv/i2c.h +++ b/bertos/drv/i2c.h @@ -48,6 +48,8 @@ #define I2C_READBIT BV(0) +#define i2c_init(FN_ARGS) CAT(fn ## _, COUNT_PARMS(FN_ARGS)) (FN_ARGS) + /** * I2C Backends. * Sometimes your cpu does not have a builtin @@ -94,19 +96,19 @@ int i2c_bitbang_get(bool ack); /*\}*/ #if CONFIG_I2C_BACKEND == I2C_BACKEND_BUILTIN - #define i2c_init i2c_builtin_init - #define i2c_start_w i2c_builtin_start_w - #define i2c_start_r i2c_builtin_start_r - #define i2c_stop i2c_builtin_stop - #define i2c_put i2c_builtin_put - #define i2c_get i2c_builtin_get + #define i2c_init_0 i2c_builtin_init + #define i2c_start_w i2c_builtin_start_w + #define i2c_start_r i2c_builtin_start_r + #define i2c_stop i2c_builtin_stop + #define i2c_put i2c_builtin_put + #define i2c_get i2c_builtin_get #elif CONFIG_I2C_BACKEND == I2C_BACKEND_BITBANG - #define i2c_init i2c_bitbang_init - #define i2c_start_w i2c_bitbang_start_w - #define i2c_start_r i2c_bitbang_start_r - #define i2c_stop i2c_bitbang_stop - #define i2c_put i2c_bitbang_put - #define i2c_get i2c_bitbang_get + #define i2c_init_0 i2c_bitbang_init + #define i2c_start_w i2c_bitbang_start_w + #define i2c_start_r i2c_bitbang_start_r + #define i2c_stop i2c_bitbang_stop + #define i2c_put i2c_bitbang_put + #define i2c_get i2c_bitbang_get #else #error Unsupported i2c backend. #endif @@ -136,7 +138,10 @@ typedef struct I2c struct I2cHardware* hw; } I2c; -void i2c_init(I2c *i2c, int dev, uint32_t clock); +void i2c_init_3(I2c *i2c, int dev, uint32_t clock) +{ + i2c_hw_init(I2c *i2c, int dev, uint32_t clock); +} #define i2c_write(FN_ARGS) CAT(fn ## _, COUNT_PARMS(FN_ARGS)) (FN_ARGS) #define i2c_read(FN_ARGS) CAT(fn ## _, COUNT_PARMS(FN_ARGS)) (FN_ARGS) @@ -144,29 +149,72 @@ void i2c_init(I2c *i2c, int dev, uint32_t clock); /* * Overloaded functions definition. */ -int i2c_write_5(I2c *i2c, uint16_t slave_addr, int flags, const void *buf, size_t len); +int i2c_write_5(I2c *i2c, uint16_t slave_addr, int flags, const void *buf, size_t len) +{ + return i2c->write(i2c, slave_addr, flags, buf, len, NULL); +} + int i2c_read_5(I2c *i2c, uint16_t slave_addr, int flags, void *buf, size_t len); +{ + return i2c->read(i2c, slave_addr, flags, buf, len, NULL); +} + int i2c_write_7(I2c *i2c, uint16_t slave_addr, int flags, const void *buf, size_t len, const void *buf1, size_t len1); +{ + return i2c->write(i2c, slave_addr, flags, buf, len, + buf1, len1, NULL); +} + int i2c_read_7(I2c *i2c, uint16_t slave_addr, int flags, void *buf, size_t len, void *buf1, size_t len1); +{ + return i2c->read(i2c, slave_addr, flags, buf, len, + buf1, len1, NULL); +} + + int i2c_write_9(I2c *i2c, uint16_t slave_addr, int flags, const void *buf, size_t len, const void *buf1, size_t len1, const void *buf2, size_t len2); +{ + return i2c->write(i2c, slave_addr, flags, buf, len, + buf1, len1, + buf2, len2, NULL); +} + int i2c_read_9(I2c *i2c, uint16_t slave_addr, int flags, void *buf, size_t len, void *buf1, size_t len1, void *buf2, size_t len2); +{ + return i2c->read(i2c, slave_addr, flags, buf, len, + buf1, len1, + buf2, len2, NULL); +} int i2c_write_11(I2c *i2c, uint16_t slave_addr, int flags, const void *buf, size_t len, const void *buf1, size_t len1, const void *buf2, size_t len2 const void *buf3, size_t len3); +{ + return i2c->write(i2c, slave_addr, flags, buf, len, + buf1, len1, + buf2, len2, + buf3, len3, NULL); +} + int i2c_read_11(I2c *i2c, uint16_t slave_addr, int flags, void *buf, size_t len, void *buf1, size_t len1, void *buf2, size_t len2 void *buf3, size_t len3); +{ + return i2c->read(i2c, slave_addr, flags, buf, len, + buf1, len1, + buf2, len2, + buf3, len3, NULL); +} #endif -- 2.25.1