Skip to content

Commit

Permalink
reset me
Browse files Browse the repository at this point in the history
Signed-off-by: Nuno Sa <[email protected]>
  • Loading branch information
nunojsa committed May 21, 2024
1 parent ff14c6d commit 7fdabcc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 16 deletions.
59 changes: 46 additions & 13 deletions plugins/ad9739a.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static const char *dac_name;

#define LPC_DAC_DEVICE "axi-ad9739a-lpc"
#define HPC_DAC_DEVICE "axi-ad9739a-hpc"
#define DAC_DEVICE "ad9739a"

static struct dac_data_manager *dac_tx_manager;

Expand Down Expand Up @@ -77,6 +78,16 @@ static const char *hpc_ad9739a_sr_attribs[] = {
HPC_DAC_DEVICE".out_altvoltage1_1B_phase",
};

static const char *ad9739a_attribs[] = {
DAC_DEVICE".out_voltage0_operating_mode",
DAC_DEVICE".out_altvoltage0_frequency0",
DAC_DEVICE".out_altvoltage0_frequency1",
DAC_DEVICE".out_altvoltage0_scale0",
DAC_DEVICE".out_altvoltage0_scale1",
DAC_DEVICE".out_altvoltage0_phase0",
DAC_DEVICE".out_altvoltage0_phase1",
};

static const char * ad9739a_driver_attribs[] = {
"dds_mode",
"tx_channel_0",
Expand All @@ -91,6 +102,7 @@ static void reload_button_clicked(GtkButton *btn, gpointer data)

static int ad9739a_handle_driver(struct osc_plugin *plugin, const char *attrib, const char *value)
{

if (MATCH_ATTRIB("dds_mode")) {
dac_data_manager_set_dds_mode(dac_tx_manager,
dac_name, 1, atoi(value));
Expand Down Expand Up @@ -135,11 +147,28 @@ static void load_profile(struct osc_plugin *plugin, const char *ini_fn)

update_from_ini(ini_fn, THIS_DRIVER, dac, ad9739a_sr_attribs,
sr_attribs_array_size);

if (can_update_widgets)
reload_button_clicked(NULL, NULL);
}

static void ad9739a_new_driver_handle(GtkBuilder *builder)
{
struct iio_channel *chan;

chan = iio_device_find_channel(dac, "voltage0", true);
if (!chan) {
printf("[ERROR]: Could not find voltage0 channel\n");
return;
}

iio_combo_box_init_no_avail_flush_from_builder(&tx_widgets[num_tx++], dac, chan,
"operating_mode", "operating_mode_available",
builder, "operation_modes_combo", NULL);

gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object(builder, "full_scale_spin")));
gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object(builder, "full_scale_current_label")));
}

static GtkWidget * ad9739a_init(struct osc_plugin *plugin, GtkWidget *notebook, const char *ini_fn)
{
GtkBuilder *builder;
Expand Down Expand Up @@ -168,15 +197,18 @@ static GtkWidget * ad9739a_init(struct osc_plugin *plugin, GtkWidget *notebook,
gtk_container_add(GTK_CONTAINER(dds_container), dac_data_manager_get_gui_container(dac_tx_manager));
gtk_widget_show_all(dds_container);

/* Bind the IIO device files to the GUI widgets */

iio_combo_box_init_from_builder(&tx_widgets[num_tx++],
dac, NULL, "operation_mode", "operation_modes_available",
builder, "operation_modes_combo", NULL);

iio_spin_button_int_init_from_builder(&tx_widgets[num_tx++],
dac, NULL, "full_scale_current", builder,
"full_scale_spin", NULL);
/* Handle the new driver ABI as is in upstream linux */
if (!strcmp(dac_name, DAC_DEVICE)) {
ad9739a_new_driver_handle(builder);
} else {
/* Bind the IIO device files to the GUI widgets */
iio_spin_button_int_init_from_builder(&tx_widgets[num_tx++],
dac, NULL, "full_scale_current", builder,
"full_scale_spin", NULL);
iio_combo_box_init_from_builder(&tx_widgets[num_tx++],
dac, NULL, "operation_mode", "operation_modes_available",
builder, "operation_modes_combo", NULL);
}

if (ini_fn)
load_profile(NULL, ini_fn);
Expand All @@ -190,11 +222,8 @@ static GtkWidget * ad9739a_init(struct osc_plugin *plugin, GtkWidget *notebook,
G_CALLBACK(reload_button_clicked), NULL);

dac_data_manager_freq_widgets_range_update(dac_tx_manager, 2E15 / 2);

dac_data_manager_update_iio_widgets(dac_tx_manager);

dac_data_manager_set_buffer_chooser_current_folder(dac_tx_manager, OSC_WAVEFORM_FILE_PATH);

can_update_widgets = true;

return ad9739a_panel;
Expand Down Expand Up @@ -243,6 +272,10 @@ static bool ad9739a_identify(const struct osc_plugin *plugin)
dac_name = HPC_DAC_DEVICE;
ad9739a_sr_attribs = hpc_ad9739a_sr_attribs;
sr_attribs_array_size = ARRAY_SIZE(hpc_ad9739a_sr_attribs);
} else if (iio_context_find_device(osc_ctx, DAC_DEVICE)) {
dac_name = DAC_DEVICE;
ad9739a_sr_attribs = ad9739a_attribs;
sr_attribs_array_size = ARRAY_SIZE(ad9739a_attribs);
} else {
dac_name="";
}
Expand Down
34 changes: 31 additions & 3 deletions plugins/dac_data_manager.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
Expand Down Expand Up @@ -1259,10 +1260,13 @@ static char * get_tone_name(struct iio_channel *ch)
char *name;
char tone_index;

printf("name %s %s\n", iio_channel_get_id(ch), iio_channel_get_name(ch) );
name = g_strdup( iio_channel_get_name(ch));
if (!name)
return NULL;

/* If name convention "TX*_I|Q_F* is missing */
if (name && strncmp(name, "TX", 2) != 0) {
if (strncmp(name, "TX", 2) != 0) {
g_free(name);
name = g_strdup(iio_channel_get_id(ch));
if (name && !strncmp(name, TONE_ID, TONE_ID_SIZE)) {
Expand Down Expand Up @@ -1296,6 +1300,25 @@ static unsigned get_iio_tones_count(struct iio_device *dev)
return count;
}

static unsigned int get_iio_tones_count_new(struct iio_device *dev)
{
struct iio_channel *chn;
unsigned int c, attr, count;
const char *id;

/*
* new upstream ABI is altvoltageX_frequency[0|1]. There's still no
* usecase for I/Q channels so not sure how it will look like...
*/
for (c = 0, count = 0; c < iio_device_get_channels_count(dev); i++) {
chn = iio_device_get_channel(dev, i);
id = iio_channel_get_id(chn);
if (strncmp(id, "altvoltage", TONE_ID_SIZE))
continue;
for (attr = 0; attr < )
}
}

static int dac_channels_assign(struct dds_dac *ddac)
{
struct dac_data_manager *manager;
Expand Down Expand Up @@ -1947,8 +1970,13 @@ static int dds_dac_init(struct dac_data_manager *manager,
ddac->name = iio_device_get_name(iio_dac);
ddac->tones_count = get_iio_tones_count(iio_dac);

if(!ddac->tones_count)
return 0;
printf("tone count: %d\n", ddac->tones_count);

if(!ddac->tones_count) {
ddac->tones_count = get_iio_tones_count_new(iio_dac);
if (!ddac->tones_count)
return 0;
}

guint tx_count = ddac->tones_count / TX_NB_TONES;
guint extra_tones = ddac->tones_count % TX_NB_TONES;
Expand Down

0 comments on commit 7fdabcc

Please sign in to comment.