-}
-
-int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_set_mode_sync(
- spi_proxy,
- spi->handle,
- (guchar)mode,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_set_bit_order_sync(
- spi_proxy,
- spi->handle,
- lsb,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_set_bits_per_word_sync(
- spi_proxy,
- spi->handle,
- bits,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_set_frequency_sync(
- spi_proxy,
- spi->handle,
- freq_hz,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- GVariant *data_array;
- GVariantIter *iter;
- guint8 str;
- int i = 0;
-
- if (spi_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- if (peripheral_io_gdbus_spi_call_read_sync(
- spi_proxy,
- spi->handle,
- length,
- &data_array,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- g_variant_get(data_array, "a(y)", &iter);
- while (g_variant_iter_loop(iter, "(y)", &str)) {
- data[i] = str;
- if (i++ == length) break;
- }
- g_variant_iter_free(iter);
- g_variant_unref(data_array);
-
- return ret;
-}
-
-int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- GVariantBuilder *builder;
- GVariant *data_array;
- int i = 0;
-
- if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
-
- for (i = 0; i < length; i++)
- g_variant_builder_add(builder, "(y)", data[i]);
- g_variant_builder_add(builder, "(y)", 0x00);
-
- data_array = g_variant_new("a(y)", builder);
- g_variant_builder_unref(builder);
-
- if (peripheral_io_gdbus_spi_call_write_sync(
- spi_proxy,
- spi->handle,
- length,
- data_array,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
-
-int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length)
-{
- GError *error = NULL;
- peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- GVariantBuilder *builder;
- GVariant *rx_data_array;
- GVariant *tx_data_array;
- GVariantIter *iter;
- guint8 str;
- int i = 0;
-
- if (spi_proxy == NULL || !rx_data || !tx_data) return PERIPHERAL_ERROR_UNKNOWN;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
-
- for (i = 0; i < length; i++)
- g_variant_builder_add(builder, "(y)", tx_data[i]);
- g_variant_builder_add(builder, "(y)", 0x00);
-
- tx_data_array = g_variant_new("a(y)", builder);
- g_variant_builder_unref(builder);
-
- if (peripheral_io_gdbus_spi_call_transfer_sync(
- spi_proxy,
- spi->handle,
- length,
- tx_data_array,
- &rx_data_array,
- &ret,
- NULL,
- &error) == FALSE) {
- _E("%s", error->message);
- g_error_free(error);
- return PERIPHERAL_ERROR_UNKNOWN;
- }
-
- i = 0;
- g_variant_get(rx_data_array, "a(y)", &iter);
- while (g_variant_iter_loop(iter, "(y)", &str)) {
- rx_data[i] = str;
- if (i++ == length) break;
- }
- g_variant_iter_free(iter);
- g_variant_unref(rx_data_array);
-
- return ret;
-}