From 259637e8c200c3ef40b0aee1d2fa97d2f1f84415 Mon Sep 17 00:00:00 2001 From: Cristina Suteu Date: Fri, 22 Mar 2024 08:47:50 +0200 Subject: [PATCH] plugins/cf_axi_tdd: added support new version of tdd driver check for version attribute in the tdd driver(only exists in v2) if found, load the new plugin if version attr not found, the previous version of the plugin is loaded Signed-off-by: Cristina Suteu --- glade/cf_axi_tdd_v2.glade | 1055 +++++++++++++++++++++++++++++++++++++ plugins/cf_axi_tdd.c | 221 +++++--- 2 files changed, 1208 insertions(+), 68 deletions(-) create mode 100644 glade/cf_axi_tdd_v2.glade diff --git a/glade/cf_axi_tdd_v2.glade b/glade/cf_axi_tdd_v2.glade new file mode 100644 index 000000000..a756029b0 --- /dev/null +++ b/glade/cf_axi_tdd_v2.glade @@ -0,0 +1,1055 @@ + + + + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + 10000 + 1 + 10 + + + True + False + True + True + + + True + True + + + True + False + + + True + False + + + True + False + 0 + in + + + True + False + 12 + + + True + False + + + True + False + + + True + False + 0 + in + + + True + False + 12 + + + True + False + 5 + 2 + + + + + + + + + True + False + External Sync + 0.47999998927116394 + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + False + Internal Sync + 0.47999998927116394 + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + + + True + True + False + True + + + 1 + 2 + + + + + + + True + True + False + True + + + 1 + 2 + 1 + 2 + + + + + + + True + True + False + True + + + 1 + 2 + 2 + 3 + + + + + True + False + <b>Enable TDD</b> + True + + + GTK_FILL + GTK_FILL + + + + + Reset Sync + True + True + True + + + 3 + 4 + + + + + Soft Sync + True + True + True + + + 4 + 5 + + + + + + + + + + + + False + True + 0 + + + + + True + False + 0 + in + + + True + False + 12 + + + True + False + 4 + 2 + + + True + True + + False + False + adjustment1 + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + False + Frame Length (ms) + 0.47999998927116394 + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + True + + False + False + adjustment2 + 6 + + + 1 + 2 + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + False + Internal Sync Period (ms) + 0.47999998927116394 + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + True + + False + False + adjustment27 + 6 + + + 1 + 2 + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + False + Start-up Delay (ms) + 0.47999998927116394 + + + 3 + 4 + GTK_FILL + GTK_FILL + + + + + True + True + + 0 + False + False + adjustment9 + 6 + + + 1 + 2 + 3 + 4 + GTK_FILL + GTK_FILL + + + + + True + False + Burst Count + + + GTK_FILL + GTK_FILL + + + + + + + + + + + + False + True + 1 + + + + + + + + True + True + 0 + + + + + + + + + True + False + + + + + + True + False + <b>TDD Global Settings</b> + True + + + False + True + 1 + + + + + + + False + False + 0 + + + + + True + False + 0 + in + + + True + False + 12 + + + True + False + + + True + False + 0 + in + + + True + False + 12 + + + True + False + 4 + 2 + + + True + False + On (ms) + + + + + True + True + + False + False + adjustment3 + 6 + + + 1 + 2 + + + + + True + True + + False + False + adjustment6 + 6 + + + 1 + 2 + 1 + 2 + + + + + True + False + Off (ms) + + + 1 + 2 + + + + + True + False + <b>Enable </b> + True + + + 3 + 4 + + + + + + + True + True + False + True + + + 1 + 2 + 3 + 4 + + + + + True + False + Polarity + + + 2 + 3 + + + + + True + False + + Direct + Inverted + + + + 1 + 2 + 2 + 3 + + + + + + + + + True + False + <b>Channel 0</b> + True + + + + + False + True + 0 + + + + + True + False + 0 + in + + + True + False + 12 + + + True + False + 4 + 2 + + + True + False + On (ms) + + + + + True + True + + 0 + False + False + adjustment4 + 6 + + + 1 + 2 + + + + + True + True + + 0 + False + False + adjustment7 + 6 + + + 1 + 2 + 1 + 2 + + + + + True + False + Off (ms) + + + 1 + 2 + + + + + True + False + <b> Enable </b> + True + + + 3 + 4 + + + + + + + True + True + False + True + + + 1 + 2 + 3 + 4 + + + + + True + False + Polarity + + + 2 + 3 + + + + + True + False + + Direct + Inverted + + + + 1 + 2 + 2 + 3 + + + + + + + + + True + False + <b>Channel 1</b> + True + + + + + False + True + 1 + + + + + True + False + 0 + in + + + True + False + 12 + + + True + False + 4 + 2 + + + True + False + On (ms) + + + + + True + True + + 0 + False + False + adjustment5 + 6 + + + 1 + 2 + + + + + True + True + + 0 + False + False + adjustment8 + 6 + + + 1 + 2 + 1 + 2 + + + + + True + False + Off (ms) + + + 1 + 2 + + + + + True + False + <b> Enable </b> + True + + + 3 + 4 + + + + + + + True + True + False + True + + + 1 + 2 + 3 + 4 + + + + + True + False + Polarity + + + 2 + 3 + + + + + True + False + + Direct + Inverted + + + + 1 + 2 + 2 + 3 + + + + + + + + + True + False + <b>Channel 2</b> + True + + + + + False + True + 2 + + + + + + + + + True + False + + + + + + True + False + <b>Channel Settings</b> + True + + + False + True + 1 + + + + + + + False + False + 1 + + + + + + + + + + + + True + True + 0 + + + + + True + False + 15 + center + + + Reload Settings + True + True + True + + + False + False + 0 + + + + + False + True + end + 1 + + + + + + + + + + + 0 + + + 1 + + + + diff --git a/plugins/cf_axi_tdd.c b/plugins/cf_axi_tdd.c index fc8b892cf..54f5ab3b2 100644 --- a/plugins/cf_axi_tdd.c +++ b/plugins/cf_axi_tdd.c @@ -8,6 +8,7 @@ **/ #include #include +#include #include #include #include @@ -22,13 +23,13 @@ #define NUM_MAX_WIDGETS 32 struct plugin_private { - /* Associated GTK builder */ + /* Associated GTK builder */ GtkBuilder *builder; - /* plugin context */ + /* plugin context */ struct osc_plugin_context plugin_ctx; /* iio */ struct iio_context *ctx; - /* misc */ + /* misc */ gboolean plugin_detached; gint this_page; /* widgets */ @@ -99,8 +100,42 @@ static int cf_axi_tdd_chann_widgets_init(struct plugin_private *priv, struct iio return 0; } +static int cf_axi_tdd_v2_chann_widgets_init(struct plugin_private *priv, struct iio_device *dev) +{ + const unsigned int n_channels = iio_device_get_channels_count(dev); + struct iio_channel *chan; + unsigned int i; + char widget_str[32]; + + if (!n_channels) { + printf("Could not find any iio channel\n"); + return -ENODEV; + } + + for (i = 0; i < n_channels; i++) { + chan = iio_device_get_channel(dev, i); + if (!chan) + return -ENODEV; + + sprintf(widget_str, "%s_on", iio_channel_get_id(chan)); + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, chan, + "on_ms", priv->builder, widget_str, NULL); + sprintf(widget_str, "%s_off", iio_channel_get_id(chan)); + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, chan, + "off_ms", priv->builder, "off_ms", NULL); + sprintf(widget_str, "%s_polarity", iio_channel_get_id(chan)); + //iio_spin_button__init_from_builder(&priv->w[priv->n_w++], dev, chan, + // "polarity", priv->builder, widget_str, NULL); + sprintf(widget_str, "%s_enable", iio_channel_get_id(chan)); + iio_toggle_button_init_from_builder(&priv->w[priv->n_w++], dev, chan, + "enable", priv->builder, widget_str, NULL); + } + + return 0; +} + static GtkWidget *cf_axi_tdd_init(struct osc_plugin *plugin, GtkWidget *notebook, - const char *ini_fn) + const char *ini_fn) { GtkWidget *cf_axi_tdd_panel; struct plugin_private *priv = plugin->priv; @@ -123,70 +158,120 @@ static GtkWidget *cf_axi_tdd_init(struct osc_plugin *plugin, GtkWidget *notebook if (!dev) goto context_destroy; - if (osc_load_glade_file(priv->builder, "cf_axi_tdd") < 0) - goto context_destroy; - - cf_axi_tdd_panel = GTK_WIDGET(gtk_builder_get_object(priv->builder, "cf_axi_tdd_panel")); - if (!cf_axi_tdd_panel) - goto context_destroy; - - /* init device widgets */ - iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "burst_count", - priv->builder, "burst_count", NULL); - iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "frame_length_ms", - priv->builder, "frame_length", NULL); - iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "counter_int", - priv->builder, "counter_int", NULL); - iio_combo_box_init_no_avail_flush_from_builder(&priv->w[priv->n_w++], dev, NULL,"dma_gateing_mode", - "dma_gateing_mode_available", priv->builder, - "dma_gateing_mode", NULL); - iio_combo_box_init_no_avail_flush_from_builder(&priv->w[priv->n_w++], dev, NULL, "en_mode", - "en_mode_available", priv->builder, "enable_mode", NULL); - iio_toggle_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "sync_terminal_type", - priv->builder, "sync_terminal_type", false); - iio_toggle_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "en", priv->builder, - "enable", false); - iio_toggle_button_init_from_builder(&priv->secondary, dev, NULL, "secondary", priv->builder, - "secondary_frame", false); - /* init channel widgets */ - ret = cf_axi_tdd_chann_widgets_init(priv, dev); - if (ret) - goto context_destroy; - - /* handle sections buttons and reload settings */ - global = GTK_WIDGET(gtk_builder_get_object(priv->builder, "global_settings")); - global_btn = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(priv->builder, - "global_settings_toggle")); - primary = GTK_WIDGET(gtk_builder_get_object(priv->builder, "tdd_primary")); - primary_btn = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(priv->builder, - "tdd_primary_toggle")); - secondary = GTK_WIDGET(gtk_builder_get_object(priv->builder, "tdd_secondary")); - secondary_btn = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(priv->builder, - "tdd_secondary_toggle")); - - reload_btn = GTK_BUTTON(gtk_builder_get_object(priv->builder, "settings_reload")); - priv->secondary_frame = GTK_WIDGET(gtk_builder_get_object(priv->builder, - "tdd_secondary_frame")); - - g_signal_connect(G_OBJECT(global_btn), "clicked", G_CALLBACK(handle_toggle_section_cb), - global); - g_signal_connect(G_OBJECT(primary_btn), "clicked", G_CALLBACK(handle_toggle_section_cb), - primary); - g_signal_connect(G_OBJECT(secondary_btn), "clicked", G_CALLBACK(handle_toggle_section_cb), - secondary); - g_signal_connect(G_OBJECT(reload_btn), "clicked", G_CALLBACK(reload_settings), - priv); - - iio_update_widgets(priv->w, priv->n_w); - iio_widget_update(&priv->secondary); - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->secondary.widget))) - gtk_widget_set_sensitive(priv->secondary_frame, false); - - iio_make_widgets_update_signal_based(priv->w, priv->n_w, - G_CALLBACK(iio_widget_save_block_signals_by_data_cb)); - iio_make_widget_update_signal_based(&priv->secondary, G_CALLBACK(save_secondary), priv); - - return cf_axi_tdd_panel; + /*check for version device attribute , this only exists in v2 of the tdd driver + * if the attribute is not found , load the previous version of the tdd plugin */ + + if(!iio_device_find_attr(dev, "version")) { + if (osc_load_glade_file(priv->builder, "cf_axi_tdd") < 0) + goto context_destroy; + + cf_axi_tdd_panel = GTK_WIDGET(gtk_builder_get_object(priv->builder, "cf_axi_tdd_panel")); + if (!cf_axi_tdd_panel) + goto context_destroy; + + /* init device widgets */ + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "burst_count", + priv->builder, "burst_count", NULL); + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "frame_length_ms", + priv->builder, "frame_length", NULL); + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "counter_int", + priv->builder, "counter_int", NULL); + iio_combo_box_init_no_avail_flush_from_builder(&priv->w[priv->n_w++], dev, NULL,"dma_gateing_mode", + "dma_gateing_mode_available", priv->builder, + "dma_gateing_mode", NULL); + iio_combo_box_init_no_avail_flush_from_builder(&priv->w[priv->n_w++], dev, NULL, "en_mode", + "en_mode_available", priv->builder, "enable_mode", NULL); + iio_toggle_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "sync_terminal_type", + priv->builder, "sync_terminal_type", false); + iio_toggle_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "en", priv->builder, + "enable", false); + iio_toggle_button_init_from_builder(&priv->secondary, dev, NULL, "secondary", priv->builder, + "secondary_frame", false); + /* init channel widgets */ + ret = cf_axi_tdd_chann_widgets_init(priv, dev); + if (ret) + goto context_destroy; + + /* handle sections buttons and reload settings */ + global = GTK_WIDGET(gtk_builder_get_object(priv->builder, "global_settings")); + global_btn = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(priv->builder, + "global_settings_toggle")); + primary = GTK_WIDGET(gtk_builder_get_object(priv->builder, "tdd_primary")); + primary_btn = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(priv->builder, + "tdd_primary_toggle")); + secondary = GTK_WIDGET(gtk_builder_get_object(priv->builder, "tdd_secondary")); + secondary_btn = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(priv->builder, + "tdd_secondary_toggle")); + + reload_btn = GTK_BUTTON(gtk_builder_get_object(priv->builder, "settings_reload")); + priv->secondary_frame = GTK_WIDGET(gtk_builder_get_object(priv->builder, + "tdd_secondary_frame")); + + g_signal_connect(G_OBJECT(global_btn), "clicked", G_CALLBACK(handle_toggle_section_cb), + global); + g_signal_connect(G_OBJECT(primary_btn), "clicked", G_CALLBACK(handle_toggle_section_cb), + primary); + g_signal_connect(G_OBJECT(secondary_btn), "clicked", G_CALLBACK(handle_toggle_section_cb), + secondary); + g_signal_connect(G_OBJECT(reload_btn), "clicked", G_CALLBACK(reload_settings), + priv); + + iio_update_widgets(priv->w, priv->n_w); + iio_widget_update(&priv->secondary); + if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->secondary.widget))) + gtk_widget_set_sensitive(priv->secondary_frame, false); + + iio_make_widgets_update_signal_based(priv->w, priv->n_w, + G_CALLBACK(iio_widget_save_block_signals_by_data_cb)); + iio_make_widget_update_signal_based(&priv->secondary, G_CALLBACK(save_secondary), priv); + + return cf_axi_tdd_panel; + } + else { + + if (osc_load_glade_file(priv->builder, "cf_axi_tdd_v2") < 0) + goto context_destroy; + + cf_axi_tdd_panel = GTK_WIDGET(gtk_builder_get_object(priv->builder, "cf_axi_tdd_panel_v2")); + if (!cf_axi_tdd_panel) + goto context_destroy; + + /* init device widgets */ + + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "burst_count", + priv->builder, "burst_count", NULL); + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "frame_length_ms", + priv->builder, "frame_length", NULL); + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "internal_sync_period_ms", + priv->builder, "int_sync_period", NULL); + iio_spin_button_int_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "startup_delay_ms", + priv->builder, "startup_delay", NULL); + iio_toggle_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "enable", + priv->builder, "global_enable", false); + iio_toggle_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "sync_external", + priv->builder, "external_sync_enable", false); + iio_toggle_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "sync_internal", + priv->builder, "internal_sync_enable", false); + iio_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "sync_reset", + priv->builder, "reset_sync_button"); + iio_button_init_from_builder(&priv->w[priv->n_w++], dev, NULL, "sync_soft", + priv->builder, "soft_sync_button"); + + /* init channel widgets */ + ret = cf_axi_tdd_v2_chann_widgets_init(priv, dev); + if (ret) + goto context_destroy; + + reload_btn = GTK_BUTTON(gtk_builder_get_object(priv->builder, "settings_reload")); + g_signal_connect(G_OBJECT(reload_btn), "clicked", G_CALLBACK(reload_settings), + priv); + iio_update_widgets(priv->w, priv->n_w); + iio_make_widgets_update_signal_based(priv->w, priv->n_w, + G_CALLBACK(iio_widget_save_block_signals_by_data_cb)); + + return cf_axi_tdd_panel; + + } context_destroy: osc_destroy_context(priv->ctx);