From 88c3cfc66b2a78171750d57ddc5f45d93ed0e33c Mon Sep 17 00:00:00 2001 From: Hyeongsik Min Date: Wed, 19 Apr 2017 19:53:20 +0900 Subject: [PATCH] Rename peripheral_i2c_context_h to peripheral_i2c_h Change-Id: I533ee1772cdd9b055deac139226bdac3d04d5889 Signed-off-by: Hyeongsik Min --- include/peripheral_dbus.h | 2 +- include/peripheral_internal.h | 9 ++++++- include/peripheral_io.h | 18 +++++--------- src/peripheral_dbus.c | 6 ++--- src/peripheral_i2c.c | 45 ++++++++++++++++++----------------- test/peripheral-io-test.c | 2 +- 6 files changed, 42 insertions(+), 40 deletions(-) diff --git a/include/peripheral_dbus.h b/include/peripheral_dbus.h index c32b2cb..1136792 100644 --- a/include/peripheral_dbus.h +++ b/include/peripheral_dbus.h @@ -34,7 +34,7 @@ GDBusConnection *get_dbus_connection(void); int peripheral_dbus_gpio(peripheral_gpio_h gpio, char * sensorid, char *funcname, int write_value, int *read_value); -int peripheral_dbus_i2c(peripheral_i2c_context_h dev, char * sensorid, char *funcname, int value, unsigned char *data, int addr); +int peripheral_dbus_i2c(peripheral_i2c_h i2c, char * sensorid, char *funcname, int value, unsigned char *data, int addr); int peripheral_dbus_pwm(peripheral_pwm_context_h dev, char * sensorid, char *funcname); #endif /* __PERIPHERAL_DBUS_H_ */ diff --git a/include/peripheral_internal.h b/include/peripheral_internal.h index 8ab8cc5..f331b57 100644 --- a/include/peripheral_internal.h +++ b/include/peripheral_internal.h @@ -18,7 +18,7 @@ #define __PERIPHERAL_INTERNAL_H__ /** - * @brief Internal struct for keep gpio context information + * @brief Internal struct for gpio context */ struct _peripheral_gpio_s { int pin; @@ -26,4 +26,11 @@ struct _peripheral_gpio_s { peripheral_gpio_edge_e edge; }; +/** + * @brief Internal struct for i2c context + */ +struct _peripheral_i2c_s { + int fd; +}; + #endif /* __PERIPHERAL_INTERNAL_H__ */ diff --git a/include/peripheral_io.h b/include/peripheral_io.h index 7b164c0..44c9b59 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -286,23 +286,17 @@ int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin); * @{ */ -/** - * @brief Struct for peripheral_gpio_s - */ -struct _peripheral_i2c_s { - int fd; -}; -typedef struct _peripheral_i2c_s *peripheral_i2c_context_h; +typedef struct _peripheral_i2c_s *peripheral_i2c_h; -peripheral_i2c_context_h peripheral_i2c_init(int bus); +peripheral_i2c_h peripheral_i2c_init(int bus); -int peripheral_i2c_stop(peripheral_i2c_context_h hnd); +int peripheral_i2c_stop(peripheral_i2c_h i2c); -int peripheral_i2c_set_address(peripheral_i2c_context_h hnd, int address); +int peripheral_i2c_set_address(peripheral_i2c_h i2c, int address); -int peripheral_i2c_read(peripheral_i2c_context_h hnd, uint8_t *data, int length); +int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length); -int peripheral_i2c_write(peripheral_i2c_context_h hnd, uint8_t *data, int length); +int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length); /** diff --git a/src/peripheral_dbus.c b/src/peripheral_dbus.c index 83eb624..e90997a 100644 --- a/src/peripheral_dbus.c +++ b/src/peripheral_dbus.c @@ -101,7 +101,7 @@ int peripheral_dbus_gpio(peripheral_gpio_h gpio, char * sensorid, char *funcname } -int peripheral_dbus_i2c(peripheral_i2c_context_h dev, char * sensorid, char *funcname, int value, unsigned char * data, int addr) +int peripheral_dbus_i2c(peripheral_i2c_h i2c, char * sensorid, char *funcname, int value, unsigned char * data, int addr) { GError *error = NULL; GVariant *ret_value = NULL; @@ -126,7 +126,7 @@ int peripheral_dbus_i2c(peripheral_i2c_context_h dev, char * sensorid, char *fun PERIPHERAL_DBUS_PATH, PERIPHERAL_DBUS_INTERFACE, sensorid, - g_variant_new("(siiayi)", funcname, value, dev->fd, builder, addr), + g_variant_new("(siiayi)", funcname, value, i2c->fd, builder, addr), G_VARIANT_TYPE("(iayi)"), G_DBUS_CALL_FLAGS_NONE, -1, @@ -141,7 +141,7 @@ int peripheral_dbus_i2c(peripheral_i2c_context_h dev, char * sensorid, char *fun return PERIPHERAL_ERROR_UNKNOWN; } - g_variant_get(ret_value, "(iayi)", &(dev->fd), &ret_data, &ret); + g_variant_get(ret_value, "(iayi)", &(i2c->fd), &ret_data, &ret); g_variant_unref(ret_value); if (data != NULL) { diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 0ea2644..35c5d06 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -22,6 +22,7 @@ #include "peripheral_io.h" #include "peripheral_dbus.h" #include "peripheral_common.h" +#include "peripheral_internal.h" #ifdef __cplusplus extern "C" { @@ -30,68 +31,68 @@ extern "C" { #define I2C_NAME "i2c" int I2C_Addr = 0; -peripheral_i2c_context_h peripheral_i2c_init(int bus) +peripheral_i2c_h peripheral_i2c_init(int bus) { - peripheral_i2c_context_h dev; + peripheral_i2c_h i2c; int ret = PERIPHERAL_ERROR_NONE; assert(bus >= 0); - /* Initialize peripheral_i2c_context_h */ - dev = (peripheral_i2c_context_h)malloc(sizeof(struct _peripheral_i2c_s)); + /* Initialize peripheral_i2c_h */ + i2c = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s)); - if (dev == NULL) { - _E("Failed to allocate peripheral_i2c_context_h"); + if (i2c == NULL) { + _E("Failed to allocate peripheral_i2c_h"); return NULL; } if (!get_dbus_connection()) set_dbus_connection(); - ret = peripheral_dbus_i2c(dev, I2C_NAME, "INIT", bus, 0, I2C_Addr); + ret = peripheral_dbus_i2c(i2c, I2C_NAME, "INIT", bus, 0, I2C_Addr); if (ret != PERIPHERAL_ERROR_NONE) { - free(dev); + free(i2c); _E("[PERIPHERAL] I2C init error\n"); - dev = NULL; + i2c = NULL; } - return dev; + return i2c; } -int peripheral_i2c_stop(peripheral_i2c_context_h dev) +int peripheral_i2c_stop(peripheral_i2c_h i2c) { int ret = PERIPHERAL_ERROR_NONE; - /* Free peripheral_i2c_context_h */ + /* Free peripheral_i2c_h */ - if (dev != NULL) { - ret = peripheral_dbus_i2c(dev, I2C_NAME, "STOP", 0, 0, I2C_Addr); + if (i2c != NULL) { + ret = peripheral_dbus_i2c(i2c, I2C_NAME, "STOP", 0, 0, I2C_Addr); - free(dev); - dev = NULL; + free(i2c); + i2c = NULL; } return ret; } -int peripheral_i2c_set_address(peripheral_i2c_context_h dev, int address) +int peripheral_i2c_set_address(peripheral_i2c_h i2c, int address) { /* Set the i2c slave address */ //I2C_Addr = address; - return peripheral_dbus_i2c(dev, I2C_NAME, "SET_ADDR", address, 0, I2C_Addr); + return peripheral_dbus_i2c(i2c, I2C_NAME, "SET_ADDR", address, 0, I2C_Addr); } -int peripheral_i2c_read(peripheral_i2c_context_h dev, uint8_t *data, int length) +int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) { /* Read i2c data */ - return peripheral_dbus_i2c(dev, I2C_NAME, "READ", length, data, I2C_Addr); + return peripheral_dbus_i2c(i2c, I2C_NAME, "READ", length, data, I2C_Addr); } -int peripheral_i2c_write(peripheral_i2c_context_h dev, uint8_t *data, int length) +int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) { /* Write i2c data */ - return peripheral_dbus_i2c(dev, I2C_NAME, "WRITE", length, data, I2C_Addr); + return peripheral_dbus_i2c(i2c, I2C_NAME, "WRITE", length, data, I2C_Addr); } #ifdef __cplusplus diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index 928f09e..857fb66 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -78,7 +78,7 @@ int i2c_test(void) int cnt = 0; int bus_num; unsigned char buf[10]; - peripheral_i2c_context_h dev; + peripheral_i2c_h dev; printf(">> I2C bus number : "); if (scanf("%d", &bus_num) < 0) -- 2.34.1