Skip to content

Commit

Permalink
Merge branch 'libiio-v1-support' into libiio-v1-support-more-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
dNechita authored Dec 11, 2024
2 parents 530f958 + 12af0c9 commit 5a238fc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
8 changes: 4 additions & 4 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ set(PLUGINS
ad9739a
AD5628_1
#AD7303
#cn0357
#cn0508
#cn0511
#cn0540
cn0357
cn0508
cn0511
cn0540
pr_config
#motor_control
#lidar
Expand Down
7 changes: 4 additions & 3 deletions plugins/cn0357.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "../iio_widget.h"
#include "../osc_plugin.h"
#include "../config.h"
#include "../iio_utils.h"

#define THIS_DRIVER "CN0357"

Expand Down Expand Up @@ -105,7 +106,7 @@ static int get_adc_voltage(double *out_data)
long long raw;
int ret;

ret = iio_channel_attr_read_longlong(adc_ch, "raw", &raw);
ret = chn_attr_read_longlong(adc_ch, "raw", &raw);
if (!ret)
*out_data = V_TO_MV(ad7790_voltage_conversion(raw, V_REF_ADC, GAIN_ADC));

Expand All @@ -117,7 +118,7 @@ static int get_adc_power_supply(double *out_data)
long long raw;
int ret;

ret = iio_channel_attr_read_longlong(pwr_ch, "raw", &raw);
ret = chn_attr_read_longlong(pwr_ch, "raw", &raw);
if (!ret)
*out_data = ad7790_voltage_conversion(raw, V_REF_PWR, GAIN_PWR);

Expand Down Expand Up @@ -230,7 +231,7 @@ static void program_rdac_clicked_cb(GtkButton *btn, gpointer data)
if (!rdac_ch)
return;

iio_channel_attr_write(rdac_ch, "raw", gtk_entry_get_text(GTK_ENTRY(rdac_val)));
chn_attr_write_string(rdac_ch, "raw", gtk_entry_get_text(GTK_ENTRY(rdac_val)));
}

static gboolean update_display(gpointer foo)
Expand Down
19 changes: 10 additions & 9 deletions plugins/cn0508.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "../iio_widget.h"
#include "../osc_plugin.h"
#include "../config.h"
#include "../iio_utils.h"

#define THIS_DRIVER "CN0508"

Expand Down Expand Up @@ -96,7 +97,7 @@ static int get_adc_voltage(struct iio_channel *adc_ch, double *out_data)
long long raw;
int ret;

ret = iio_channel_attr_read_longlong(adc_ch, "raw", &raw);
ret = chn_attr_read_longlong(adc_ch, "raw", &raw);
if (!ret)
*out_data = ad7124_voltage_conversion(raw, V_REF_ADC, GAIN_ADC);

Expand Down Expand Up @@ -263,17 +264,17 @@ static GtkWidget* cn0508_init(struct osc_plugin *plugin, GtkWidget *notebook,
current_pot_pos_ch = iio_device_find_channel(adc, "voltage5-voltage19", false);
voltage_pot_pos_ch = iio_device_find_channel(adc, "voltage6-voltage19", false);

iio_channel_attr_write(u2_temp_ch, "sampling_frequency", "9600");
iio_channel_attr_write(u3_temp_ch, "sampling_frequency", "9600");
iio_channel_attr_write(out_current_ch, "sampling_frequency", "9600");
iio_channel_attr_write(in_v_attenuator_ch, "sampling_frequency", "9600");
iio_channel_attr_write(out_v_attenuator_ch, "sampling_frequency", "9600");
iio_channel_attr_write(current_pot_pos_ch, "sampling_frequency", "9600");
iio_channel_attr_write(voltage_pot_pos_ch, "sampling_frequency", "9600");
chn_attr_write_string(u2_temp_ch, "sampling_frequency", "9600");
chn_attr_write_string(u3_temp_ch, "sampling_frequency", "9600");
chn_attr_write_string(out_current_ch, "sampling_frequency", "9600");
chn_attr_write_string(in_v_attenuator_ch, "sampling_frequency", "9600");
chn_attr_write_string(out_v_attenuator_ch, "sampling_frequency", "9600");
chn_attr_write_string(current_pot_pos_ch, "sampling_frequency", "9600");
chn_attr_write_string(voltage_pot_pos_ch, "sampling_frequency", "9600");

dac_ch = iio_device_find_channel(dac, "voltage0", true);

iio_channel_attr_read_double(dac_ch, "scale", &val);
chn_attr_read_double(dac_ch, "scale", &val);

iio_spin_button_int_init_from_builder(&iio_widgets[num_widgets++], dac,
dac_ch, "raw", builder,
Expand Down
7 changes: 4 additions & 3 deletions plugins/cn0511.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#include <math.h>

#include <ad9166.h>
#include <iio.h>
#include <iio/iio.h>

#include "../osc.h"
#include "../osc_plugin.h"
#include "../iio_widget.h"
#include "../iio_utils.h"

#define THIS_DRIVER "CN0511"
#define DAC_DEVICE "ad9166"
Expand Down Expand Up @@ -146,12 +147,12 @@ static GtkWidget *cn0511_init(struct osc_plugin *plugin, GtkWidget *notebook,

dac_ch = iio_device_find_channel(dac, "altvoltage0", true);

ret = iio_device_attr_write_longlong(dac, "fir85_enable", 1);
ret = dev_attr_write_longlong(dac, "fir85_enable", 1);
if (ret < 0) {
fprintf(stderr, "Failed to enable FIR85. Error: %d\n", ret);
}

ret = iio_device_attr_write_longlong(dac, "sampling_frequency", 6000000000);
ret = dev_attr_write_longlong(dac, "sampling_frequency", 6000000000);
if (ret < 0) {
fprintf(stderr, "Failed to set sampling frequency. Error: %d\n", ret);
}
Expand Down
41 changes: 23 additions & 18 deletions plugins/cn0540.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "../iio_widget.h"
#include "../config.h"
#include "./block_diagram.h"
#include "../iio_utils.h"

#define THIS_DRIVER "CN0540"
#define ADC_DEVICE "ad7768-1"
Expand Down Expand Up @@ -52,6 +53,7 @@ static struct iio_context *ctx;
static struct iio_channel *adc_ch;
static struct iio_channel *dac_ch;
static struct iio_channel *analog_in[NUM_ANALOG_PINS];
static struct iio_channels_mask *adc_mask;
static struct iio_gpio gpio_ch[MAX_NUM_GPIOS];
static struct iio_widget iio_widgets[25];
static unsigned int num_widgets;
Expand Down Expand Up @@ -104,7 +106,7 @@ static gboolean cn0540_get_gpio_state(const char* gpio_name)

for(idx = 0; idx < MAX_NUM_GPIOS; idx++) {
if(strstr(gpio_ch[idx].label, gpio_name)) {
iio_channel_attr_read_longlong(gpio_ch[idx].gpio, "raw",
chn_attr_read_longlong(gpio_ch[idx].gpio, "raw",
&readback);
break;
}
Expand All @@ -122,7 +124,7 @@ static void cn0540_set_gpio_state(const char* gpio_name, gboolean state)

for(idx = 0; idx < MAX_NUM_GPIOS; idx++) {
if (strstr(gpio_ch[idx].label, gpio_name)) {
iio_channel_attr_write_longlong(gpio_ch[idx].gpio,
chn_attr_write_longlong(gpio_ch[idx].gpio,
"raw", (long long)state);
break;
}
Expand All @@ -134,22 +136,22 @@ static void monitor_shutdown(GtkCheckButton *btn)
struct extra_dev_info *info;

/* If the buffer is enabled */
if (iio_channel_is_enabled(adc_ch)) {
if (iio_channel_is_enabled(adc_ch, adc_mask)) {
info = iio_device_get_data(iio_adc);
if (info->buffer) {
iio_buffer_destroy(info->buffer);
info->buffer = NULL;
}

iio_channel_disable(adc_ch);
iio_channel_disable(adc_ch, adc_mask);
}
/* Shutdown pin is tied to active-low inputs */
cn0540_set_gpio_state("cn0540_shutdown_gpio",
!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tgbtn_shutdown)));
gtk_text_buffer_set_text(shutdown_buffer, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn))?
"ENABLED" : "DISABLED", -1);
/* Enable back the channel */
iio_channel_enable(adc_ch);
iio_channel_enable(adc_ch, adc_mask);
}

static void monitor_sw_ff(GtkButton *btn)
Expand All @@ -165,21 +167,21 @@ static void monitor_fda(GtkCheckButton *btn)
struct extra_dev_info *info;

/* If the buffer is enabled */
if (iio_channel_is_enabled(adc_ch)) {
if (iio_channel_is_enabled(adc_ch, adc_mask)) {
info = iio_device_get_data(iio_adc);
if (info->buffer) {
iio_buffer_destroy(info->buffer);
info->buffer = NULL;
}

iio_channel_disable(adc_ch);
iio_channel_disable(adc_ch, adc_mask);
}
/* FDA_DIS pin is tied to active-low inputs */
cn0540_set_gpio_state("cn0540_FDA_DIS",!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn)));
gtk_text_buffer_set_text(fda_buffer, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn)) ?
"ENABLED" : "DISABLED", -1);
/* Enable back the channel */
iio_channel_enable(adc_ch);
iio_channel_enable(adc_ch, adc_mask);
}

static void monitor_cc(GtkCheckButton *btn)
Expand All @@ -194,20 +196,20 @@ static void monitor_fda_mode(GtkCheckButton *btn)
struct extra_dev_info *info;

/* If the buffer is enabled */
if (iio_channel_is_enabled(adc_ch)) {
if (iio_channel_is_enabled(adc_ch, adc_mask)) {
info = iio_device_get_data(iio_adc);
if (info->buffer) {
iio_buffer_destroy(info->buffer);
info->buffer = NULL;
}

iio_channel_disable(adc_ch);
iio_channel_disable(adc_ch, adc_mask);
}
cn0540_set_gpio_state("cn0540_FDA_MODE",gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn)));
gtk_text_buffer_set_text(fda_mode_buffer, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn)) ?
"FULL POWER" : "LOW POWER", -1);
/* Enable back the channel */
iio_channel_enable(adc_ch);
iio_channel_enable(adc_ch, adc_mask);
}

static gboolean update_voltages(struct iio_device *voltage_mon)
Expand All @@ -218,8 +220,8 @@ static gboolean update_voltages(struct iio_device *voltage_mon)
int idx;

for(idx = 0; idx < NUM_ANALOG_PINS; idx++) {
iio_channel_attr_read_longlong(analog_in[idx], "raw", &raw);
iio_channel_attr_read_double(analog_in[idx], "scale", &scale);
chn_attr_read_longlong(analog_in[idx], "raw", &raw);
chn_attr_read_double(analog_in[idx], "scale", &scale);
result = raw * scale;
if(!strcmp(iio_device_get_name(voltage_mon),VOLTAGE_MONITOR_1))
result *= XADC_VREF;
Expand All @@ -235,17 +237,17 @@ static double get_voltage(struct iio_channel *ch)
double scale;
long long raw;

iio_channel_attr_read_longlong(ch,"raw",&raw);
iio_channel_attr_read_double(ch,"scale",&scale);
chn_attr_read_longlong(ch,"raw",&raw);
chn_attr_read_double(ch,"scale",&scale);
return raw * scale;
}

static void set_voltage(struct iio_channel *ch, double voltage_mv)
{
double scale;

iio_channel_attr_read_double(ch,"scale",&scale);
iio_channel_attr_write_longlong(ch,"raw",
chn_attr_read_double(ch,"scale",&scale);
chn_attr_write_longlong(ch,"raw",
(long long)(voltage_mv / scale));
}

Expand Down Expand Up @@ -350,6 +352,8 @@ static void cn0540_get_channels()
int idx = -1;
char label[10] = "voltage0";

adc_mask = iio_create_channels_mask(1);

adc_ch = iio_device_find_channel(iio_adc, ADC_DEVICE_CH, FALSE);
dac_ch = iio_device_find_channel(iio_dac, DAC_DEVICE_CH, TRUE);

Expand All @@ -362,7 +366,7 @@ static void cn0540_get_channels()
gpio_ch[++idx].gpio = iio_device_find_channel(iio_gpio, label,
direction);
if (gpio_ch[idx].gpio != NULL){
iio_channel_attr_read(gpio_ch[idx].gpio, "label",
chn_attr_read_raw(gpio_ch[idx].gpio, "label",
gpio_ch[idx].label, 30);
label[7]++;
} else if (direction && (gpio_ch[idx].gpio == NULL)) {
Expand Down Expand Up @@ -570,6 +574,7 @@ static bool cn0540_identify(const struct osc_plugin *plugin)

static void context_destroy(struct osc_plugin *plugin, const char *ini_fn)
{
iio_channels_mask_destroy(adc_mask);
g_source_remove_by_user_data(iio_voltage_mon);
osc_destroy_context(ctx);
}
Expand Down

0 comments on commit 5a238fc

Please sign in to comment.