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_ */
* @{
*/
-/**
- * @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);
/**
}
-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;
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,
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) {
#include "peripheral_io.h"
#include "peripheral_dbus.h"
#include "peripheral_common.h"
+#include "peripheral_internal.h"
#ifdef __cplusplus
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