From: PA3GSB Date: Sat, 28 Jan 2017 10:22:48 +0000 (+0100) Subject: added radioberry X-Git-Url: https://git.rkrishnan.org/pf/$rel_link?a=commitdiff_plain;h=2d2031d0bc12518b3be25869e5efdd62043bb1bc;p=pihpsdr.git added radioberry --- diff --git a/Makefile b/Makefile index 773c00b..d01912a 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GIT_VERSION := $(shell git describe --abbrev=0 --tags) PSK_INCLUDE=PSK # uncomment the line to below include support for FreeDV codec2 -FREEDV_INCLUDE=FREEDV +#FREEDV_INCLUDE=FREEDV # uncomment the line to below include support for sx1509 i2c expander #SX1509_INCLUDE=sx1509 @@ -31,6 +31,23 @@ LINK=gcc # uncomment the line below for LimeSDR (uncomment line below) #LIMESDR_INCLUDE=LIMESDR +# uncomment the line below when Radioberry radio cape is plugged in +RADIOBERRY_INCLUDE=RADIOBERRY + +ifeq ($(RADIOBERRY_INCLUDE),RADIOBERRY) +RADIOBERRY_OPTIONS=-D RADIOBERRY +RADIOBERRY_SOURCES= \ +radioberry_discovery.c \ +radioberry.c +RADIOBERRY_HEADERS= \ +radioberry_discovery.h \ +radioberry.h +RADIOBERRY_OBJS= \ +radioberry_discovery.o \ +radioberry.o +endif + + ifeq ($(LIMESDR_INCLUDE),LIMESDR) LIMESDR_OPTIONS=-D LIMESDR SOAPYSDRLIBS=-lSoapySDR @@ -102,8 +119,8 @@ ifeq ($(MRAA_INCLUDE),MRAA) gpio_mraa.o else ifeq ($(UNAME_N),raspberrypi) - GPIO_OPTIONS=-D GPIO - GPIO_LIBS=-lwiringPi -lpigpio + #GPIO_OPTIONS=-D GPIO + GPIO_LIBS=-lwiringPi -lpigpio -lbcm2835 endif ifeq ($(UNAME_N),odroid) GPIO_LIBS=-lwiringPi @@ -129,7 +146,7 @@ GTKLIBS=`pkg-config --libs gtk+-3.0` AUDIO_LIBS=-lasound -OPTIONS=-g -D $(UNAME_N) $(GPIO_OPTIONS) $(LIMESDR_OPTIONS) $(FREEDV_OPTIONS) $(LOCALCW_OPTIONS) $(PSK_OPTIONS) $(SHORT_FRAMES) -D GIT_DATE='"$(GIT_DATE)"' -D GIT_VERSION='"$(GIT_VERSION)"' $(DEBUG_OPTION) -O3 +OPTIONS=-g -D $(UNAME_N) $(GPIO_OPTIONS) $(LIMESDR_OPTIONS) $(RADIOBERRY_OPTIONS) $(FREEDV_OPTIONS) $(LOCALCW_OPTIONS) $(PSK_OPTIONS) $(SHORT_FRAMES) -D GIT_DATE='"$(GIT_DATE)"' -D GIT_VERSION='"$(GIT_VERSION)"' $(DEBUG_OPTION) -O3 LIBS=-lrt -lm -lwdsp -lpthread $(AUDIO_LIBS) $(PSKLIBS) $(GTKLIBS) $(GPIO_LIBS) $(SOAPYSDRLIBS) $(FREEDVLIBS) INCLUDES=$(GTKINCLUDES) @@ -316,13 +333,13 @@ vox.o \ update.o \ memory.o -all: prebuild $(PROGRAM) $(HEADERS) $(LIMESDR_HEADERS) $(FREEDV_HEADERS) $(LOCALCW_HEADERS) $(GPIO_HEADERS) $(PSK_HEADERS) $(SOURCES) $(LIMESDR_SOURCES) $(FREEDV_SOURCES) $(GPIO_SOURCES) $(PSK_SOURCES) +all: prebuild $(PROGRAM) $(HEADERS) $(LIMESDR_HEADERS) $(RADIOBERRY_HEADERS) $(FREEDV_HEADERS) $(LOCALCW_HEADERS) $(GPIO_HEADERS) $(PSK_HEADERS) $(SOURCES) $(LIMESDR_SOURCES) $(RADIOBERRY_SOURCES) $(FREEDV_SOURCES) $(GPIO_SOURCES) $(PSK_SOURCES) prebuild: rm -f version.o -$(PROGRAM): $(OBJS) $(LIMESDR_OBJS) $(FREEDV_OBJS) $(LOCALCW_OBJS) $(GPIO_OBJS) $(PSK_OBJS) - $(LINK) -o $(PROGRAM) $(OBJS) $(GPIO_OBJS) $(LIMESDR_OBJS) $(FREEDV_OBJS) $(LOCALCW_OBJS) $(PSK_OBJS) $(LIBS) +$(PROGRAM): $(OBJS) $(LIMESDR_OBJS) $(RADIOBERRY_OBJS) $(FREEDV_OBJS) $(LOCALCW_OBJS) $(GPIO_OBJS) $(PSK_OBJS) + $(LINK) -o $(PROGRAM) $(OBJS) $(GPIO_OBJS) $(LIMESDR_OBJS) $(RADIOBERRY_OBJS) $(FREEDV_OBJS) $(LOCALCW_OBJS) $(PSK_OBJS) $(LIBS) .c.o: $(COMPILE) -c -o $@ $< diff --git a/audio.c b/audio.c index 0b3ae13..0f2c576 100644 --- a/audio.c +++ b/audio.c @@ -35,6 +35,9 @@ #include "audio.h" #include "new_protocol.h" #include "old_protocol.h" +#ifdef RADIOBERRY +#include "radioberry.h" +#endif #include "radio.h" int audio = 0; @@ -180,6 +183,11 @@ fprintf(stderr,"audio_open_input: %d\n",n_selected_input_device); case NEW_PROTOCOL: mic_buffer_size = 64; break; +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + mic_buffer_size = 1024; + break; +#endif default: break; } @@ -350,6 +358,11 @@ fprintf(stderr,"mic_read_thread: mic_buffer_size=%d\n",mic_buffer_size); case NEW_PROTOCOL: new_protocol_process_local_mic(mic_buffer,1); break; +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + radioberry_protocol_process_local_mic(mic_buffer,1); + break; +#endif default: break; } diff --git a/discovered.h b/discovered.h index 28b41e0..3ea2b90 100644 --- a/discovered.h +++ b/discovered.h @@ -46,6 +46,10 @@ #define LIMESDR_USB_DEVICE 0 #endif +#ifdef RADIOBERRY +#define RADIOBERRY_SPI_DEVICE 0 +#endif + #define STATE_AVAILABLE 2 #define STATE_SENDING 3 @@ -54,6 +58,9 @@ #ifdef LIMESDR #define LIMESDR_PROTOCOL 2 #endif +#ifdef RADIOBERRY +#define RADIOBERRY_PROTOCOL 3 +#endif struct _DISCOVERED { int protocol; diff --git a/exit_menu.c b/exit_menu.c index 4a97099..c950646 100644 --- a/exit_menu.c +++ b/exit_menu.c @@ -56,6 +56,11 @@ static gboolean exit_cb (GtkWidget *widget, GdkEventButton *event, gpointer data case LIMESDR_PROTOCOL: lime_protocol_stop(); break; +#endif +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + radioberry_protocol_stop(); + break; #endif } radioSaveState(); @@ -77,6 +82,11 @@ static gboolean reboot_cb (GtkWidget *widget, GdkEventButton *event, gpointer da case LIMESDR_PROTOCOL: lime_protocol_stop(); break; +#endif +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + radioberry_protocol_stop(); + break; #endif } radioSaveState(); @@ -99,6 +109,11 @@ static gboolean shutdown_cb (GtkWidget *widget, GdkEventButton *event, gpointer case LIMESDR_PROTOCOL: lime_protocol_stop(); break; +#endif +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + radioberry_protocol_stop(); + break; #endif } radioSaveState(); diff --git a/main.c b/main.c index c0fd576..a395e6d 100644 --- a/main.c +++ b/main.c @@ -39,11 +39,17 @@ #ifdef LIMESDR #include "lime_discovery.h" #endif +#ifdef RADIOBERRY +#include "radioberry_discovery.h" +#endif #include "old_protocol.h" #include "new_protocol.h" #ifdef LIMESDR #include "lime_protocol.h" #endif +#ifdef RADIOBERRY +#include "radioberry.h" +#endif #include "wdsp.h" #include "vfo.h" //#include "menu.h" @@ -317,6 +323,11 @@ gboolean main_delete (GtkWidget *widget) { case LIMESDR_PROTOCOL: lime_protocol_stop(); break; +#endif +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + radioberry_protocol_stop(); + break; #endif } radioSaveState(); @@ -362,6 +373,10 @@ static void discover_devices() { #ifdef LIMESDR splash_status("LimeSDR ... Discovering Devices"); lime_discovery(); +#endif +#ifdef RADIOBERRY + splash_status("Radioberry SDR ... Discovering Device"); + radioberry_discovery(); #endif splash_status("Discovery"); if(devices==0) { @@ -494,6 +509,11 @@ fprintf(stderr,"%p protocol=%d name=%s\n",d,d->protocol,d->name); sprintf(text,"%s\n", d->name); break; +#endif +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + sprintf(text,"%s\n",d->name); + break; #endif } @@ -571,7 +591,12 @@ fprintf(stderr,"start: selected radio=%p device=%d\n",radio,radio->device); sprintf(property_path,"limesdr.props"); break; #endif - } +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + sprintf(property_path,"radioberry.props"); + break; +#endif + } radioRestoreState(); @@ -602,6 +627,12 @@ fprintf(stderr,"start: selected radio=%p device=%d\n",radio,radio->device); splash_status("Initializing lime protocol ..."); lime_protocol_init(0,display_width); break; +#endif +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: + splash_status("Initializing radioberry protocol ..."); + radioberry_protocol_init(0,display_width); + break; #endif } diff --git a/radio.c b/radio.c index 4698dd7..e25779e 100644 --- a/radio.c +++ b/radio.c @@ -357,6 +357,9 @@ void setFrequency(long long f) { switch(protocol) { case NEW_PROTOCOL: case ORIGINAL_PROTOCOL: +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: +#endif if(ctun) { long long minf=entry->frequencyA-(long long)(sample_rate/2); long long maxf=entry->frequencyA+(long long)(sample_rate/2); @@ -394,6 +397,9 @@ void setFrequency(long long f) { schedule_high_priority(5); break; case ORIGINAL_PROTOCOL: +#ifdef RADIOBERRY + case RADIOBERRY_PROTOCOL: +#endif schedule_frequency_changed(); break; #ifdef LIMESDR diff --git a/radioberry.c b/radioberry.c new file mode 100644 index 0000000..d888fab --- /dev/null +++ b/radioberry.c @@ -0,0 +1,405 @@ +/* Copyright (C) +* 2017 - Johan Maas, PA3GSB +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +*/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "audio.h" + +#include "band.h" +#include "channel.h" +#include "discovered.h" +#include "mode.h" +#include "filter.h" +#include "old_protocol.h" +#include "radio.h" +#include "toolbar.h" +#include "vox.h" +#include + +#define PI 3.1415926535897932F + +#define OUTPUT_BUFFER_SIZE 1024 +#define SPEED_48K 0x00 +#define SPEED_96K 0x01 +#define SPEED_192K 0x02 +#define SPEED_384K 0x03 + + +static int output_buffer_size; +static int buffer_size=BUFFER_SIZE; + +static int receiver; +static int display_width; + +static int running; + +static int samples=0; +static int txsamples=0; + +static short tx_sample; +static int left_tx_sample; +static int right_tx_sample; + +static int left_rx_sample; +static int right_rx_sample; + +static int sampleSpeed =0; + +static double iqinputbuffer[BUFFER_SIZE*2]; +static double micinputbuffer[BUFFER_SIZE*2]; +static double audiooutputbuffer[BUFFER_SIZE*2]; +static double micoutputbuffer[BUFFER_SIZE*2]; + +unsigned char iqdata[6]; +unsigned char tx_iqdata[6]; + +static pthread_t radioberry_thread_id; +static void start_radioberry_thread(); +static void *radioberry_thread(void* arg); + +static void setSampleSpeed(); +static void handleReceiveStream(); + +struct timeval t0; +struct timeval t1; +struct timeval t10; +struct timeval t11; +struct timeval t20; +struct timeval t21; +float elapsed; + +#define RADIOSTATE_RX 0 +#define RADIOSTATE_TX 1 +static int radiostate = RADIOSTATE_RX; + +void spiWriter(); +void spiReader(); + + +int prev_drive_level; + +static int rxcount =0; +static int txcount =0; + +sem_t mutex; + + + +float timedifference_msec(struct timeval t0, struct timeval t1) +{ + return (t1.tv_sec - t0.tv_sec) * 1000.0f + (t1.tv_usec - t0.tv_usec) / 1000.0f; +} + +void radioberry_protocol_init(int rx,int pixels) { + int i; + + fprintf(stderr,"radioberry_protocol_init\n"); + + sem_init(&mutex, 0, 1); //mutal exlusion + + receiver=rx; + display_width=pixels; + + switch(sample_rate) { + case 48000: + output_buffer_size=OUTPUT_BUFFER_SIZE; + break; + case 96000: + output_buffer_size=OUTPUT_BUFFER_SIZE/2; + break; + case 192000: + output_buffer_size=OUTPUT_BUFFER_SIZE/4; + break; + case 384000: + output_buffer_size=OUTPUT_BUFFER_SIZE/8; + break; + default: + fprintf(stderr,"Invalid sample rate: %d. Defaulting to 48K.\n",sample_rate); + break; + } + + fprintf(stderr,"radioberry_protocol: buffer size: =%d\n", buffer_size); + + if (!bcm2835_init()){ + fprintf(stderr,"radioberry_protocol: spi bus could not be initialized. \n"); + exit(-1); + } + + bcm2835_gpio_fsel(RPI_BPLUS_GPIO_J8_33 , BCM2835_GPIO_FSEL_INPT); + bcm2835_gpio_fsel(RPI_BPLUS_GPIO_J8_38, BCM2835_GPIO_FSEL_INPT); + bcm2835_gpio_fsel(RPI_BPLUS_GPIO_J8_40 , BCM2835_GPIO_FSEL_OUTP); + bcm2835_gpio_write(RPI_BPLUS_GPIO_J8_40, LOW); // ptt off + + bcm2835_spi_begin(); + bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_LSBFIRST); + bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); + bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16); + bcm2835_spi_chipSelect(BCM2835_SPI_CS0); + bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); + + printf("init done \n"); + + setSampleSpeed(); + local_audio=1; + if(audio_open_output()!=0) { + fprintf(stderr,"audio_open_output failed\n"); + local_audio=0; + } + + local_microphone = 1; + if(audio_open_input()!=0) { + fprintf(stderr,"audio_open_input failed\n"); + local_microphone=0; + } + + start_radioberry_thread(); +} + +static void start_radioberry_thread() { + int rc; + fprintf(stderr,"radioberry_protocol starting radioberry thread\n"); + rc=pthread_create(&radioberry_thread_id,NULL,radioberry_thread,NULL); + if(rc != 0) { + fprintf(stderr,"radioberry_protocol: pthread_create failed on radioberry_thread: rc=%d\n", rc); + exit(-1); + } +} + +static void *radioberry_thread(void* arg) { + unsigned char buffer[2048]; + fprintf(stderr, "radioberry_protocol: radioberry_thread\n"); + + samples = 0; + txsamples=0; + running=1; + + gettimeofday(&t20, 0); + gettimeofday(&t0, 0); + + bcm2835_gpio_fsel(RPI_BPLUS_GPIO_J8_33 , BCM2835_GPIO_FSEL_INPT); + bcm2835_gpio_fsel(RPI_BPLUS_GPIO_J8_38 , BCM2835_GPIO_FSEL_INPT); + bcm2835_gpio_fsel(RPI_BPLUS_GPIO_J8_40 , BCM2835_GPIO_FSEL_OUTP); + + while(running) { + + sem_wait(&mutex); + + if (isTransmitting()) + radiostate = RADIOSTATE_TX; + else + radiostate = RADIOSTATE_RX; + + if(radiostate == RADIOSTATE_TX) { + bcm2835_gpio_write(RPI_BPLUS_GPIO_J8_40, HIGH); // ptt on + } + else + { + bcm2835_gpio_write(RPI_BPLUS_GPIO_J8_40, LOW); // ptt off + spiReader(); + handleReceiveStream(); + sem_post(&mutex); + } + } +} + +int correctSampleValue(int value) { + + if(value>32767) { + value=32767; + } else if(value<-32767) { + value=-32767; + } + + return value; +} + +void *radioberry_protocol_process_local_mic(unsigned char *buffer,int le) { +int b; +int leftmicsample; +double mic_sample_double; +double leftmicsampledouble; +double gain=32767.0; // 2^16-1 + + b=0; + int i; + for(i=0;i<1024;i++) { + leftmicsample = (int)((unsigned char)buffer[b++] & 0xFF); + leftmicsample |= (int)((signed char) buffer[b++]) << 8; + //rightmicsample=leftmicsample; + + mic_sample_double=(1.0 / 2147483648.0) * (double)(leftmicsample<<16); + + micinputbuffer[i*2]=mic_sample_double; + micinputbuffer[(i*2)+1]=mic_sample_double; + } + + if(vox_enabled && (vox || local_microphone)) { + update_vox(micinputbuffer,BUFFER_SIZE); + } + + if(radiostate == RADIOSTATE_TX) { + + int error; + fexchange0(CHANNEL_TX, micinputbuffer, micoutputbuffer, &error); + if(error!=0) { + fprintf(stderr,"fexchange0 (CHANNEL_TX) returned error: %d\n", error); + } + Spectrum0(1, CHANNEL_TX, 0, 0, micoutputbuffer); + + int j; + for(j=0;j<1024;j++) { + left_tx_sample=(int)(micoutputbuffer[j*2]*gain); + left_tx_sample = correctSampleValue(left_tx_sample); + right_tx_sample=(int)(micoutputbuffer[(j*2)+1]*gain); + right_tx_sample = correctSampleValue(right_tx_sample); + + tx_iqdata[0] = 0; + tx_iqdata[1] = drive / 6.4; // convert drive level from 0-255 to 0-39 ) + if (prev_drive_level != drive) { + printf("drive level %d - corrected drive level %d \n", drive_level, tx_iqdata[1]); + prev_drive_level = drive; + } + tx_iqdata[2] = left_tx_sample>>8; + tx_iqdata[3] = left_tx_sample; + tx_iqdata[4] = right_tx_sample>>8; + tx_iqdata[5] = right_tx_sample; + + spiWriter(); + } + sem_post(&mutex); + } +} + +static void handleReceiveStream() { + int error; + int left_sample; + int right_sample; + int mic_sample; + float left_sample_float; + float right_sample_float; + + left_sample = (int)((signed char) iqdata[0]) << 16; + left_sample += (int)((unsigned char)iqdata[1]) << 8; + left_sample += (int)((unsigned char)iqdata[2]); + right_sample = (int)((signed char) iqdata[3]) << 16; + right_sample += (int)((unsigned char)iqdata[4]) << 8; + right_sample += (int)((unsigned char)iqdata[5]); + + left_sample_float=(float)left_sample/8388607.0; // 24 bit sample 2^23-1 + right_sample_float=(float)right_sample/8388607.0; // 24 bit sample 2^23-1 + iqinputbuffer[samples*2]=(double)left_sample_float; + iqinputbuffer[(samples*2)+1]=(double)right_sample_float; + samples++; + + if(samples==buffer_size) { + // process the input + fexchange0(CHANNEL_RX0, iqinputbuffer, audiooutputbuffer, &error); + if(error!=0) { + samples=0; + fprintf(stderr,"fexchange2 (CHANNEL_RX0) returned error: %d\n", error); + } + + if(local_audio) { + int j; + for(j=0;j> 24) & 0xFF); + iqdata[3] = ((ddsFrequency >> 16) & 0xFF); + iqdata[4] = ((ddsFrequency >> 8) & 0xFF); + iqdata[5] = (ddsFrequency & 0xFF); + + bcm2835_spi_transfern(iqdata, 6); + //firmware: tdata(56'h00010203040506) -> 0-1-2-3-4-5-6 (element 0 contains 0; second element contains 1) + rxcount ++; + if (rxcount == 48000) { + rxcount = 0; + gettimeofday(&t1, 0); + elapsed = timedifference_msec(t0, t1); + printf("Code rx mode spi executed in %f milliseconds.\n", elapsed); + gettimeofday(&t0, 0); + } +} + +void spiWriter() { + + while ( bcm2835_gpio_lev(RPI_BPLUS_GPIO_J8_38 ) == HIGH) {}; + + bcm2835_spi_transfern(tx_iqdata, 6); + + txcount ++; + if (txcount == 48000) { + txcount = 0; + gettimeofday(&t21, 0); + float elapsd = timedifference_msec(t20, t21); + printf("Code tx mode spi executed in %f milliseconds.\n", elapsd); + gettimeofday(&t20, 0); + } +} + diff --git a/radioberry.h b/radioberry.h new file mode 100644 index 0000000..4dd5844 --- /dev/null +++ b/radioberry.h @@ -0,0 +1,23 @@ +/* Copyright (C) +* 2017 - Johan Maas, PA3GSB +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +*/ + +#define BUFFER_SIZE 1024 +void radioberry_protocol_stop(); +void radioberry_protocol_init(int rx,int pixels); +void *radioberry_protocol_process_local_mic(unsigned char *buffer,int le); diff --git a/radioberry_discovery.c b/radioberry_discovery.c new file mode 100644 index 0000000..322f535 --- /dev/null +++ b/radioberry_discovery.c @@ -0,0 +1,39 @@ +/* Copyright (C) +* 2017 - Johan Maas, PA3GSB +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +*/ + +#include +#include +#include "discovered.h" +#include "radioberry_discovery.h" + +void radioberry_discovery() { + + //check availability of RADIOBERRY for instance by si570 i2c address; + //for initial version when compiling with radioberry option; select it. + + + // setting clock and loading rbf file..... done before starting + + discovered[devices].protocol=RADIOBERRY_PROTOCOL; + discovered[devices].device=RADIOBERRY_SPI_DEVICE; + strcpy(discovered[devices].name, "RadioBerry"); + discovered[devices].status=STATE_AVAILABLE; + discovered[devices].software_version=100; + devices++; +} diff --git a/radioberry_discovery.h b/radioberry_discovery.h new file mode 100644 index 0000000..5afe47a --- /dev/null +++ b/radioberry_discovery.h @@ -0,0 +1,24 @@ +/* Copyright (C) +* 2017 - Johan Maas, PA3GSB +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +*/ +#ifndef _RADIOBERRY_DISCOVERY_H +#define _RADIOBERRY_DISCOVERY_H + +void radioberry_discovery(); + +#endif \ No newline at end of file diff --git a/toolbar.c b/toolbar.c index 4409e3a..9e2284b 100644 --- a/toolbar.c +++ b/toolbar.c @@ -40,6 +40,9 @@ #include "radio.h" #include "property.h" #include "new_menu.h" +#ifdef RADIOBERRY +#include "radioberry.h" +#endif int function=0; @@ -663,6 +666,11 @@ void noise_cb(GtkWidget *widget, gpointer data) { } static void stop() { +#ifdef RADIOBERRY + if(protocol==RADIOBERRY_PROTOCOL) { + radioberry_protocol_stop(); + } +#endif if(protocol==ORIGINAL_PROTOCOL) { old_protocol_stop(); } else { diff --git a/wdsp_init.c b/wdsp_init.c index 6fafe3c..e890cf1 100644 --- a/wdsp_init.c +++ b/wdsp_init.c @@ -81,7 +81,7 @@ static int SPECTRUM_UPDATES_PER_SECOND=10; static void initAnalyzer(int channel,int buffer_size); static void calc_tx_buffer_size() { - if(protocol==ORIGINAL_PROTOCOL) { + if(protocol==ORIGINAL_PROTOCOL | protocol==RADIOBERRY_PROTOCOL) { switch(sample_rate) { case 48000: tx_buffer_size=BUFFER_SIZE; @@ -312,7 +312,7 @@ void wdsp_init(int rx,int pixels,int protocol) { fprintf(stderr,"wdsp_init: rx=%d pixels=%d protocol=%d\n",rx,pixels,protocol); - if(protocol==ORIGINAL_PROTOCOL) { + if(protocol==ORIGINAL_PROTOCOL | protocol==RADIOBERRY_PROTOCOL) { micSampleRate=sample_rate; micOutputRate=48000; } else { @@ -410,7 +410,7 @@ void wdsp_init(int rx,int pixels,int protocol) { void wdsp_new_sample_rate(int rate) { - if(protocol==ORIGINAL_PROTOCOL) { + if(protocol==ORIGINAL_PROTOCOL | protocol==RADIOBERRY_PROTOCOL) { SetChannelState(CHANNEL_TX,0,0); calc_tx_buffer_size(); initAnalyzer(CHANNEL_TX,tx_buffer_size);