From: Your Name Date: Tue, 8 Dec 2020 12:01:05 +0000 (+0000) Subject: merge in i2c controller code X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/readonly?a=commitdiff_plain;h=47f21badd3d49cab899bf5cfccb4e841f4fdeffa;p=pihpsdr.git merge in i2c controller code --- diff --git a/Makefile b/Makefile index bef6267..76f947e 100644 --- a/Makefile +++ b/Makefile @@ -10,12 +10,16 @@ endif # uncomment the following line to force 480x320 screen #SMALL_SCREEN_OPTIONS=-D SMALL_SCREEN -# uncomment the line below to include GPIO (For original piHPSDR Controller and Controller2 with i2c) +# uncomment the line below to include GPIO +# For support of: +# CONTROLLER1 (Original Controller) +# CONTROLLER2_V1 single encoders with MCP23017 switches +# CONTROLLER2_V2 dual encoders with MCP23017 switches +# CONTORLLER_I2C i2c controller using 7 I2C Encoder V2.1 boards from http://www.duppa.net/i2c-encoder-v2-1/ +# 7 encoders and 16 switches one LED +# GPIO_INCLUDE=GPIO -# uncomment the following line to include support for the new i2c controller -#I2C_CONTROLLER_INCLUDE=I2C_CONTROLLER - # uncomment the line below to include USB Ozy support # USBOZY_INCLUDE=USBOZY @@ -120,41 +124,35 @@ ifeq ($(PTT_INCLUDE),PTT) PTT_OPTIONS=-D PTT endif -ifeq ($(I2C_CONTROLLER_INCLUDE),I2C_CONTROLLER) - I2C_CONTROLLER_OPTIONS=-D I2C_CONTROLLER - I2C_CONTROLLER_LIBS=-lgpiod -li2c - I2C_CONTROLLER_SOURCES= \ - i2c_controller.c \ - i2c_controller_menu.c - I2C_CONTROLLER_HEADERS= \ - i2c_controller.h \ - i2c_controller_menu.h - I2C_CONTROLLER_OBJS= \ - i2c_controller.o \ - i2c_controller_menu.o -endif - ifeq ($(GPIO_INCLUDE),GPIO) - GPIO_OPTIONS=-D GPIO - GPIO_LIBS=-lgpiod -li2c - GPIO_SOURCES= \ +GPIO_OPTIONS=-D GPIO +GPIO_LIBS=-lgpiod -li2c +GPIO_SOURCES= \ configure.c \ i2c.c \ gpio.c \ encoder_menu.c \ - switch_menu.c - GPIO_HEADERS= \ + switch_menu.c \ + i2c_controller.c \ + i2c_controller_menu.c + +GPIO_HEADERS= \ configure.h \ i2c.h \ gpio.h \ encoder_menu.h \ - switch_menu.h - GPIO_OBJS= \ + switch_menu.h \ + i2c_controller.h \ + i2c_controller_menu.h + +GPIO_OBJS= \ configure.o \ i2c.o \ gpio.o \ encoder_menu.o \ - switch_menu.o + switch_menu.o \ + i2c_controller.o \ + i2c_controller_menu.o endif # @@ -198,14 +196,14 @@ AUDIO_LIBS=-lasound #AUDIO_LIBS=-lsoundio CFLAGS= -g -Wno-deprecated-declarations -O3 -OPTIONS=$(SMALL_SCREEN_OPTIONS) $(I2C_ENCODERS_OPTIONS) $(MIDI_OPTIONS) $(PURESIGNAL_OPTIONS) $(REMOTE_OPTIONS) $(USBOZY_OPTIONS) \ - $(I2C_CONTROLLER_OPTIONS) $(GPIO_OPTIONS) $(SOAPYSDR_OPTIONS) $(LOCALCW_OPTIONS) \ +OPTIONS=$(SMALL_SCREEN_OPTIONS) $(MIDI_OPTIONS) $(PURESIGNAL_OPTIONS) $(REMOTE_OPTIONS) $(USBOZY_OPTIONS) \ + $(GPIO_OPTIONS) $(SOAPYSDR_OPTIONS) $(LOCALCW_OPTIONS) \ $(STEMLAB_OPTIONS) \ $(PTT_OPTIONS) \ $(SERVER_OPTIONS) \ -D GIT_DATE='"$(GIT_DATE)"' -D GIT_VERSION='"$(GIT_VERSION)"' $(DEBUG_OPTION) $(OSFLAG) -LIBS=-lrt -lm -lwdsp -lpthread $(AUDIO_LIBS) $(USBOZY_LIBS) $(GTKLIBS) $(I2C_CONTROLLER_LIBS) $(GPIO_LIBS) $(SOAPYSDRLIBS) $(STEMLAB_LIBS) $(MIDI_LIBS) +LIBS=-lrt -lm -lwdsp -lpthread $(AUDIO_LIBS) $(USBOZY_LIBS) $(GTKLIBS) $(GPIO_LIBS) $(SOAPYSDRLIBS) $(STEMLAB_LIBS) $(MIDI_LIBS) INCLUDES=$(GTKINCLUDES) COMPILE=$(CC) $(CFLAGS) $(OPTIONS) $(INCLUDES) @@ -426,18 +424,18 @@ css.o \ actions.o $(PROGRAM): $(OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(SOAPYSDR_OBJS) \ - $(LOCALCW_OBJS) $(I2C_CONTROLLER_OBJS) $(GPIO_OBJS) $(PURESIGNAL_OBJS) \ + $(LOCALCW_OBJS) $(GPIO_OBJS) $(PURESIGNAL_OBJS) \ $(MIDI_OBJS) $(STEMLAB_OBJS) $(SERVER_OBJS) - $(LINK) -o $(PROGRAM) $(OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(I2C_CONTROLLER_OBJS) $(GPIO_OBJS) \ + $(LINK) -o $(PROGRAM) $(OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(GPIO_OBJS) \ $(SOAPYSDR_OBJS) $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \ $(MIDI_OBJS) $(STEMLAB_OBJS) $(SERVER_OBJS) $(LIBS) .PHONY: all all: prebuild $(PROGRAM) $(HEADERS) $(USBOZY_HEADERS) $(SOAPYSDR_HEADERS) \ - $(LOCALCW_HEADERS) $(I2C_CONTROLLER_HEADERS) $(GPIO_HEADERS) \ + $(LOCALCW_HEADERS) $(GPIO_HEADERS) \ $(PURESIGNAL_HEADERS) $(MIDI_HEADERS) $(STEMLAB_HEADERS) $(SERVER_HEADERS)\ $(SOURCES) \ - $(USBOZY_SOURCES) $(SOAPYSDR_SOURCES) $(LOCALCW_SOURCE) $(I2C_CONTROLLER_SOURCES) $(GPIO_SOURCES) \ + $(USBOZY_SOURCES) $(SOAPYSDR_SOURCES) $(LOCALCW_SOURCE) $(GPIO_SOURCES) \ $(PURESIGNAL_SOURCES) $(MIDI_SOURCES) $(STEMLAB_SOURCES) $(SERVER_SOURCES) .PHONY: prebuild @@ -456,7 +454,7 @@ CPPINCLUDES:=$(shell echo $(INCLUDES) | sed -e "s/-pthread / /" ) .PHONY: cppcheck cppcheck: cppcheck $(CPPOPTIONS) $(OPTIONS) $(CPPINCLUDES) $(SOURCES) $(REMOTE_SOURCES) \ - $(USBOZY_SOURCES) $(SOAPYSDR_SOURCES) $(I2C_CONTROLLER_SOURCES) $(GPIO_SOURCES) \ + $(USBOZY_SOURCES) $(SOAPYSDR_SOURCES) $(GPIO_SOURCES) \ $(PURESIGNAL_SOURCES) $(MIDI_SOURCES) $(STEMLAB_SOURCES) $(LOCALCW_SOURCES) \ $(SERVER_SOURCES) diff --git a/discovery.c b/discovery.c index 6110e3c..832b0bd 100644 --- a/discovery.c +++ b/discovery.c @@ -568,6 +568,7 @@ fprintf(stderr,"%p Protocol=%d name=%s\n",d,d->protocol,d->name); gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller1"); gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller2 V1"); gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller2 V2"); + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller I2C"); gtk_grid_attach(GTK_GRID(grid),gpio,0,row,1,1); gtk_combo_box_set_active(GTK_COMBO_BOX(gpio),controller); diff --git a/gpio.c b/gpio.c index 73f21fc..af29ca0 100644 --- a/gpio.c +++ b/gpio.c @@ -85,8 +85,6 @@ static struct gpiod_chip *chip=NULL; static GMutex encoder_mutex; static GThread *monitor_thread_id; -int controller=NO_CONTROLLER; - int I2C_INTERRUPT=15; #define MAX_LINES 32 diff --git a/gpio.h b/gpio.h index 855984e..822acec 100644 --- a/gpio.h +++ b/gpio.h @@ -24,15 +24,6 @@ #define MAX_SWITCHES 16 #define MAX_FUNCTIONS 6 -enum { - NO_CONTROLLER=0, - CONTROLLER1, - CONTROLLER2_V1, - CONTROLLER2_V2, -}; - -extern int controller; - typedef struct _encoder { gboolean bottom_encoder_enabled; gboolean bottom_encoder_pullup; diff --git a/i2c_controller.c b/i2c_controller.c index a589e65..8b56fee 100644 --- a/i2c_controller.c +++ b/i2c_controller.c @@ -29,6 +29,7 @@ #include #include #include +#include "actions.h" #include "i2c_controller.h" #include "vfo.h" #include "radio.h" @@ -37,6 +38,7 @@ #include "new_menu.h" +/* char *encoder_string[ENCODER_ACTIONS] = { "NO ACTION", "AF GAIN", @@ -130,8 +132,9 @@ char *sw_string[SWITCH_ACTIONS] = { "ZOOM -", "ZOOM +", }; +*/ -ENCODER encoder[MAX_ENCODERS]= +I2C_ENCODER encoder[MAX_I2C_ENCODERS]= { {TRUE,0x11,0,ENCODER_AF_GAIN,TRUE,MODE_MENU,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION}, {TRUE,0x12,0,ENCODER_AGC_GAIN,TRUE,FILTER_MENU,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION}, @@ -142,7 +145,7 @@ ENCODER encoder[MAX_ENCODERS]= {TRUE,0x10,0,ENCODER_VFO,TRUE,MENU_BAND,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION}, }; -char *gpio_device="/dev/gpiochip0"; +char *i2c_controller_gpio_device="/dev/gpiochip0"; int new_i2c_interrupt=4; static struct gpiod_chip *chip=NULL; @@ -151,7 +154,7 @@ static struct gpiod_line *line=NULL; static GMutex encoder_mutex; static GThread *monitor_thread_id; -char *i2c_device="/dev/i2c-1"; +char *i2c_controller_i2c_device="/dev/i2c-1"; static int fd=-1; @@ -159,7 +162,7 @@ static GThread *rotary_encoder_thread_id; static int vfo_encoder_changed(void *data) { if(!locked) { - gint pos=(gint)data; + gint pos=GPOINTER_TO_INT(data); vfo_step(pos); } return 0; @@ -168,7 +171,7 @@ static int vfo_encoder_changed(void *data) { static gpointer rotary_encoder_thread(gpointer data) { while(1) { g_mutex_lock(&encoder_mutex); - for(int i=0;i1.0) af_gain=1.0; double *dp=g_new(double,1); *dp=af_gain; - g_idle_add(ext_set_af_gain,(gpointer)dp); + g_idle_add(ext_set_af_gain,dp); } break; case ENCODER_AGC_GAIN: @@ -198,7 +201,7 @@ static gpointer rotary_encoder_thread(gpointer data) { if(agc_gain>120.0) agc_gain=120.0; double *dp=g_new(double,1); *dp=agc_gain; - g_idle_add(ext_set_agc_gain,(gpointer)dp); + g_idle_add(ext_set_agc_gain,dp); } break; case ENCODER_DRIVE: @@ -209,7 +212,7 @@ static gpointer rotary_encoder_thread(gpointer data) { if(drive>drive_max) drive=drive_max; double *dp=g_new(double,1); *dp=drive; - g_idle_add(ext_set_drive,(gpointer)dp); + g_idle_add(ext_set_drive,dp); } break; } @@ -222,20 +225,20 @@ static gpointer rotary_encoder_thread(gpointer data) { } } -int i2c_init() { +static int i2c_init() { int ret=0; g_mutex_init(&encoder_mutex); - g_print("%s: open i2c device %s\n",__FUNCTION__,i2c_device); - fd=open(i2c_device, O_RDWR); + g_print("%s: open i2c device %s\n",__FUNCTION__,i2c_controller_i2c_device); + fd=open(i2c_controller_i2c_device, O_RDWR); if(fd<0) { - g_print("%s: open i2c device %s failed: %s\n",__FUNCTION__,i2c_device,g_strerror(errno)); + g_print("%s: open i2c device %s failed: %s\n",__FUNCTION__,i2c_controller_i2c_device,g_strerror(errno)); goto end; } - g_print("%s: open i2c device %s fd=%d\n",__FUNCTION__,i2c_device,fd); + g_print("%s: open i2c device %s fd=%d\n",__FUNCTION__,i2c_controller_i2c_device,fd); - for(int i=0;i #include +#include "actions.h" #include "i2c_controller.h" #include "main.h" #include "new_menu.h" @@ -108,7 +109,7 @@ void i2c_controller_menu(GtkWidget *parent_window) { gtk_grid_set_column_spacing (GTK_GRID(grid),2); gtk_grid_set_row_spacing (GTK_GRID(grid),2); - for(int i=0;i extern struct utsname unameData; +enum { + NO_CONTROLLER, + CONTROLLER1, + CONTROLLER2_V1, + CONTROLLER2_V2, + CONTROLLER_I2C +}; + +extern gint controller; + extern gint display_width; extern gint display_height; extern gint full_screen; diff --git a/new_menu.c b/new_menu.c index b827564..0374e8b 100644 --- a/new_menu.c +++ b/new_menu.c @@ -60,15 +60,13 @@ #include "actions.h" #ifdef GPIO #include "gpio.h" +#include "i2c_controller_menu.h" #endif #include "old_protocol.h" #include "new_protocol.h" #ifdef CLIENT_SERVER #include "server_menu.h" #endif -#ifdef I2C_CONTROLLER -#include "i2c_controller_menu.h" -#endif static GtkWidget *menu_b=NULL; @@ -190,6 +188,7 @@ static gboolean rigctl_cb (GtkWidget *widget, GdkEventButton *event, gpointer da return TRUE; } +#ifdef GPIO static gboolean encoder_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { cleanup(); encoder_menu(top_window); @@ -202,6 +201,17 @@ static gboolean switch_cb (GtkWidget *widget, GdkEventButton *event, gpointer da return TRUE; } +void start_i2c_controller() { + cleanup(); + i2c_controller_menu(top_window); +} + +static gboolean i2c_controller_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { + start_i2c_controller(); + return TRUE; +} +#endif + static gboolean cw_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { cleanup(); cw_menu(top_window); @@ -411,47 +421,6 @@ static gboolean ps_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) } #endif -#ifdef GPIO -/* -void start_encoder(int encoder) { - int old_menu=active_menu; - cleanup(); - switch(encoder) { - case 2: - if(old_menu!=E2_MENU) { - encoder_menu(top_window,encoder); - active_menu=E2_MENU; - } - break; - case 3: - if(old_menu!=E3_MENU) { - encoder_menu(top_window,encoder); - active_menu=E3_MENU; - } - break; - case 4: - if(old_menu!=E4_MENU) { - encoder_menu(top_window,encoder); - active_menu=E4_MENU; - } - break; - case 5: - if(old_menu!=E5_MENU) { - encoder_menu(top_window,encoder); - active_menu=E5_MENU; - } - break; - } -} - -static gboolean encoder_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { - int encoder=(int)data; - start_encoder(encoder); - return TRUE; -} -*/ -#endif - void start_test() { cleanup(); test_menu(top_window); @@ -474,18 +443,6 @@ static gboolean server_cb (GtkWidget *widget, GdkEventButton *event, gpointer da } #endif -#ifdef I2C_CONTROLLER -void start_i2c_controller() { - cleanup(); - i2c_controller_menu(top_window); -} - -static gboolean i2c_controller_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { - start_i2c_controller(); - return TRUE; -} -#endif - void new_menu() { int i; @@ -634,26 +591,35 @@ void new_menu() i++; #ifdef GPIO - if(controller!=NO_CONTROLLER) { - GtkWidget *encoders_b=gtk_button_new_with_label("Encoders"); - g_signal_connect (encoders_b, "button-press-event", G_CALLBACK(encoder_cb), NULL); - gtk_grid_attach(GTK_GRID(grid),encoders_b,(i%5),i/5,1,1); - i++; + switch(controller) { + case NO_CONTROLLER: + break; + case CONTROLLER1: + case CONTROLLER2_V1: + case CONTROLLER2_V2: + { + GtkWidget *encoders_b=gtk_button_new_with_label("Encoders"); + g_signal_connect (encoders_b, "button-press-event", G_CALLBACK(encoder_cb), NULL); + gtk_grid_attach(GTK_GRID(grid),encoders_b,(i%5),i/5,1,1); + i++; - GtkWidget *switches_b=gtk_button_new_with_label("Switches"); - g_signal_connect (switches_b, "button-press-event", G_CALLBACK(switch_cb), NULL); - gtk_grid_attach(GTK_GRID(grid),switches_b,(i%5),i/5,1,1); - i++; + GtkWidget *switches_b=gtk_button_new_with_label("Switches"); + g_signal_connect (switches_b, "button-press-event", G_CALLBACK(switch_cb), NULL); + gtk_grid_attach(GTK_GRID(grid),switches_b,(i%5),i/5,1,1); + i++; + } + break; + case CONTROLLER_I2C: + { + GtkWidget *i2c_controller_b=gtk_button_new_with_label("I2C Controller"); + g_signal_connect (i2c_controller_b, "button-press-event", G_CALLBACK(i2c_controller_cb), NULL); + gtk_grid_attach(GTK_GRID(grid),i2c_controller_b,(i%5),i/5,1,1); + i++; + } + break; } #endif -#ifdef I2C_CONTROLLER - GtkWidget *i2c_controller_b=gtk_button_new_with_label("I2C Controller"); - g_signal_connect (i2c_controller_b, "button-press-event", G_CALLBACK(i2c_controller_cb), NULL); - gtk_grid_attach(GTK_GRID(grid),i2c_controller_b,(i%5),i/5,1,1); - i++; -#endif - // // We need at least two receivers and two ADCs to do DIVERSITY // diff --git a/oc_menu.c b/oc_menu.c index df51beb..5da076f 100644 --- a/oc_menu.c +++ b/oc_menu.c @@ -224,7 +224,7 @@ g_print("oc_menu: parent=%p\n",parent); BAND *band=band_get_band(i); if(strlen(band->title)>0) { GtkWidget *band_label=gtk_label_new(NULL); - char band_text[16]; + char band_text[32]; sprintf(band_text,"%s",band->title); gtk_label_set_markup(GTK_LABEL(band_label), band_text); //gtk_widget_override_font(band_label, pango_font_description_from_string("Arial 18")); diff --git a/radio.c b/radio.c index b445769..290481c 100644 --- a/radio.c +++ b/radio.c @@ -55,12 +55,8 @@ #include "soapy_protocol.h" #endif #include "actions.h" -#ifdef GPIO #include "gpio.h" -#endif -#ifdef I2C_CONTROLLER #include "i2c_controller.h" -#endif #include "vfo.h" #include "vox.h" #include "meter.h" @@ -100,6 +96,8 @@ void MIDIstartup(); #define TOOLBAR_HEIGHT (30) #define WATERFALL_HEIGHT (105) +gint controller=NO_CONTROLLER; + GtkWidget *fixed; static GtkWidget *vfo_panel; static GtkWidget *meter; @@ -603,9 +601,11 @@ if(!radio_is_remote) { #endif } -#ifdef I2C_CONTROLLER - if(i2c_controller_init()<0) { - g_print("%s: I2C_CONTROLLER failed to initialize i2c\n", __FUNCTION__); +#ifdef GPIO + if(controller==CONTROLLER_I2C) { + if(i2c_controller_init()<0) { + g_print("%s: I2C_CONTROLLER failed to initialize i2c\n", __FUNCTION__); + } } #endif diff --git a/radio_menu.c b/radio_menu.c index 75a3cdb..2602bcb 100644 --- a/radio_menu.c +++ b/radio_menu.c @@ -182,9 +182,11 @@ static void vfo_divisor_value_changed_cb(GtkWidget *widget, gpointer data) { vfo_encoder_divisor=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); } +#ifdef GPIO static void gpio_settle_value_changed_cb(GtkWidget *widget, gpointer data) { settle_time=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); } +#endif /* static void toolbar_dialog_buttons_cb(GtkWidget *widget, gpointer data) { diff --git a/toolbar.c b/toolbar.c index 1ed7d6f..d313fb7 100644 --- a/toolbar.c +++ b/toolbar.c @@ -23,10 +23,8 @@ #include #include #include -#ifdef GPIO #include "actions.h" #include "gpio.h" -#endif #include "toolbar.h" #include "mode.h" #include "filter.h"