} pb_client_info_s;
typedef struct {
- /* gpio info */
int pin;
- int direction;
- int edge;
- /* interrupt variable */
- int irq_en;
- int value_fd;
- GIOChannel *io;
- guint io_id;
- /* gdbus variable */
- PeripheralIoGdbusGpio *gpio_skeleton;
} peripheral_bus_gpio_s;
typedef struct {
- /* i2c device information */
int bus;
int address;
int fd;
- /* data buffer */
- uint8_t *buffer;
- int buffer_size;
} peripheral_bus_i2c_s;
typedef struct {
typedef struct {
int port;
int fd;
- uint8_t *buffer;
- int buffer_size;
} peripheral_bus_uart_s;
typedef struct {
int bus;
int cs;
int fd;
- /* data buffer */
- uint8_t *rx_buf;
- uint8_t *tx_buf;
- int rx_buf_size;
- int tx_buf_size;
} peripheral_bus_spi_s;
typedef struct {
gpio_handle->type = PERIPHERAL_BUS_TYPE_GPIO;
gpio_handle->list = &pb_data->gpio_list;
gpio_handle->dev.gpio.pin = pin;
- gpio_handle->dev.gpio.gpio_skeleton = pb_data->gpio_skeleton;
*handle = gpio_handle;
i2c_handle->dev.i2c.fd = fd;
i2c_handle->dev.i2c.bus = bus;
i2c_handle->dev.i2c.address = address;
- i2c_handle->dev.i2c.buffer = malloc(INITIAL_BUFFER_SIZE);
-
- if (!(i2c_handle->dev.i2c.buffer)) {
- peripheral_bus_data_free(i2c_handle);
- _E("Failed to allocate data buffer");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
- goto err;
- }
- i2c_handle->dev.i2c.buffer_size = INITIAL_BUFFER_SIZE;
*handle = i2c_handle;
uart_handle->dev.uart.fd = fd;
uart_handle->dev.uart.port = port;
- uart_handle->dev.uart.buffer = (uint8_t*)calloc(1, INITIAL_BUFFER_SIZE);
- if (!uart_handle->dev.uart.buffer) {
- _E("Failed to allocate buffer");
- peripheral_bus_data_free(uart_handle);
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
- goto err;
- }
-
- uart_handle->dev.uart.buffer_size = INITIAL_BUFFER_SIZE;
*handle = uart_handle;
return PERIPHERAL_ERROR_NONE;
*handle->list = g_list_remove_link(list, link);
- switch (handle->type) {
- case PERIPHERAL_BUS_TYPE_I2C:
- if (handle->dev.i2c.buffer)
- free(handle->dev.i2c.buffer);
- break;
- case PERIPHERAL_BUS_TYPE_UART:
- if (handle->dev.uart.buffer)
- free(handle->dev.uart.buffer);
- break;
- case PERIPHERAL_BUS_TYPE_SPI:
- if (handle->dev.spi.rx_buf)
- free(handle->dev.spi.rx_buf);
- if (handle->dev.spi.tx_buf)
- free(handle->dev.spi.tx_buf);
- break;
- default:
- break;
- }
-
free(handle);
g_list_free(link);