Skip to content

Commit 05ecd6d

Browse files
committed
plugins: adrv9002: allow control RF state in pin mode
There's now the possibility of still controlling the port RF enable state mode even if the port mode is set to pin. That's possible in case the driver is in control of the pin controlling the port. Hence, let's check if the driver supports that at the plugin initialization and act accordingly. To check it we do the following: 1) Move the port to pin mode if in spi mod;. 2) Change the RF state mode to rf_enabled; 3) If success, then we allow changing the RF state even in pin mode; Signed-off-by: Nuno Sa <[email protected]>
1 parent fb948dc commit 05ecd6d

File tree

1 file changed

+76
-9
lines changed

1 file changed

+76
-9
lines changed

Diff for: plugins/adrv9002.c

+76-9
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ struct adrv9002_common {
221221
struct iio_widget w[NUM_MAX_WIDGETS];
222222
uint16_t num_widgets;
223223
bool enabled;
224+
bool enable_gpio;
224225
uint8_t idx;
225226
};
226227

@@ -499,24 +500,46 @@ static void save_orx_powerdown(GtkWidget *widget, struct adrv9002_orx *orx)
499500
g_free(t_ensm);
500501
}
501502

502-
static void save_ensm(GtkWidget *w, struct iio_widget *widget)
503+
static void save_ensm(GtkWidget *w, struct adrv9002_common *chann)
503504
{
504-
widget->save(widget);
505+
gchar *ensm = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(chann->ensm.widget));
506+
gchar *port_en = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(chann->port_en.widget));
507+
508+
if (!strcmp(port_en, "pin") && !strcmp(ensm, "calibrated")) {
509+
dialog_box_message_error(chann->ensm.widget, "Enable State Mode",
510+
"Only primed or rf_enabled possible when pin mode is enabled");
511+
goto out_free;
512+
}
513+
514+
chann->ensm.save(&chann->ensm);
505515
/*
506516
* If it is a transition to rf_enabled, it can take some time and so, we
507517
* can still get the old value if we do not wait a bit...
508518
*/
509519
usleep(2000);
510-
iio_widget_update_block_signals_by_data(widget);
520+
521+
out_free:
522+
iio_widget_update_block_signals_by_data(&chann->ensm);
523+
g_free(ensm);
524+
g_free(port_en);
511525
}
512526

513527
static void save_port_en(GtkWidget *widget, struct adrv9002_common *chann)
514528
{
515529
char *port_en;
516530

517531
iio_widget_save_block_signals_by_data(&chann->port_en);
518-
port_en = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widget));
532+
if (chann->enable_gpio) {
533+
/*
534+
* If we can control RF state when in pin mode, there's no need to
535+
* control the sensitivity. Hence, just update the RF state widget (as
536+
* it can change when moving from pin to spi and vice versa) and bail out.
537+
*/
538+
iio_widget_update_block_signals_by_data(&chann->ensm);
539+
return;
540+
}
519541

542+
port_en = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widget));
520543
if (port_en && strcmp(port_en, "spi")) {
521544
gtk_widget_set_sensitive(chann->ensm.widget, false);
522545
} else {
@@ -653,7 +676,7 @@ static void update_special_widgets(struct adrv9002_common *chann, const char *en
653676
if (gain_ctl && strcmp(gain_ctl, "spi"))
654677
iio_widget_update_block_signals_by_data(&chann->gain);
655678

656-
if (port_en && strcmp(port_en, "spi")) {
679+
if (port_en && strcmp(port_en, "spi") && !chann->enable_gpio) {
657680
if (ensm)
658681
iio_widget_update_value(&chann->ensm, ensm, len);
659682
else
@@ -2777,7 +2800,7 @@ static void connect_special_signal_widgets(struct plugin_private *priv, const in
27772800
&priv->rx_widgets[chann].rx.nco_freq);
27782801
/* ensm mode and port en */
27792802
iio_make_widget_update_signal_based(&priv->rx_widgets[chann].rx.ensm,
2780-
G_CALLBACK(save_ensm), &priv->rx_widgets[chann].rx.ensm);
2803+
G_CALLBACK(save_ensm), &priv->rx_widgets[chann].rx);
27812804
iio_make_widget_update_signal_based(&priv->rx_widgets[chann].rx.port_en,
27822805
G_CALLBACK(save_port_en), &priv->rx_widgets[chann].rx);
27832806
/* digital gain control */
@@ -2805,7 +2828,7 @@ static void connect_special_signal_widgets(struct plugin_private *priv, const in
28052828
&priv->tx_widgets[chann].gain);
28062829
/* ensm mode and port en */
28072830
iio_make_widget_update_signal_based(&priv->tx_widgets[chann].ensm,
2808-
G_CALLBACK(save_ensm), &priv->tx_widgets[chann].ensm);
2831+
G_CALLBACK(save_ensm), &priv->tx_widgets[chann]);
28092832
iio_make_widget_update_signal_based(&priv->tx_widgets[chann].port_en,
28102833
G_CALLBACK(save_port_en), &priv->tx_widgets[chann]);
28112834
/* carrier frequency */
@@ -2929,15 +2952,59 @@ static int adrv9002_dds_init(struct plugin_private *priv)
29292952
return ret;
29302953
}
29312954

2932-
static void adrv9002_update_port_en_mode(const struct plugin_private *priv, const struct adrv9002_common *chan)
2955+
static void adrv9002_update_port_en_mode(const struct plugin_private *priv, struct adrv9002_common *chan)
29332956
{
29342957
gchar *port_en = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(chan->port_en.widget));
2958+
char pin_ensm[32];
2959+
int ret;
29352960

29362961
if (!port_en)
29372962
return;
2938-
if (!strcmp(port_en, "pin"))
2963+
if (!strcmp(port_en, "pin")) {
29392964
gtk_widget_set_sensitive(chan->ensm.widget, false);
2965+
} else {
2966+
/*
2967+
* Let's check if we can control the RF enable state mode even in pin mode. For
2968+
* that, we check which mode we're and if not in pin mode, we move to that mode
2969+
* and try to change the state. If we succeed, then it means the driver is
2970+
* in full control of the pin controlling the RF state.
2971+
*/
2972+
ret = iio_channel_attr_write(chan->port_en.chn, "port_en_mode", "pin");
2973+
if (ret < 0) {
2974+
printf("Could not set port to to pin (%d)\n", ret);
2975+
goto out;
2976+
}
2977+
}
2978+
2979+
ret = iio_channel_attr_read(chan->ensm.chn, "ensm_mode", pin_ensm, sizeof(pin_ensm));
2980+
if (ret < 0)
2981+
goto out;
2982+
2983+
/*
2984+
* If we get an error just assume we can't control the state and try to bring the device
2985+
* to the initial state.
2986+
*/
2987+
ret = iio_channel_attr_write(chan->ensm.chn, "ensm_mode", "primed");
2988+
if (ret > 0)
2989+
chan->enable_gpio = true;
2990+
2991+
/*
2992+
* Go back to the previous state and to spi mode if that was the port mode
2993+
* Not much to do in case of error, hence ignore them...
2994+
*/
2995+
if (chan->enable_gpio) {
2996+
iio_channel_attr_write(chan->ensm.chn, "ensm_mode", pin_ensm);
2997+
if (!strcmp(port_en, "pin"))
2998+
gtk_widget_set_sensitive(chan->ensm.widget, true);
2999+
}
3000+
/*
3001+
* If spi mode had a different ensm state than pin, it will automatically move to
3002+
* that state after changing port modes.
3003+
*/
3004+
if (strcmp(port_en, "pin"))
3005+
iio_channel_attr_write(chan->port_en.chn, "port_en_mode", "spi");
29403006

3007+
out:
29413008
g_free(port_en);
29423009
}
29433010

0 commit comments

Comments
 (0)