From: Ramakrishnan Muthukrishnan Date: Sat, 31 Dec 2022 14:49:51 +0000 (+0530) Subject: software level control as a Makefile option X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/file/$top_link?a=commitdiff_plain;h=af65599d20cee6209d79f32e16ffa998a8b00f23;p=pihpsdr.git software level control as a Makefile option --- diff --git a/Makefile b/Makefile index 09cda29..6178e8d 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,9 @@ GIT_VERSION := $(shell git describe --abbrev=0 --tags --always) # GPIO_INCLUDE=GPIO +# uncomment if level control (power output) is software based +LEVEL_CTRL=SW_LEVEL_CTRL + # uncomment the line below to include Pure Signal support #PURESIGNAL_INCLUDE=PURESIGNAL @@ -42,6 +45,10 @@ LOCALCW_INCLUDE=LOCALCW CC=gcc LINK=gcc +ifeq ($(LEVEL_CTRL),SW_LEVEL_CTRL) +LEVEL_OPTIONS=-D SW_LEVEL_CTRL +endif + ifeq ($(MIDI_INCLUDE),MIDI) MIDI_OPTIONS=-D MIDI MIDI_HEADERS= midi.h midi_menu.h @@ -157,7 +164,7 @@ endif CFLAGS= -Wno-deprecated-declarations -O3 # CFLAGS= -Wno-deprecated-declarations -O3 -mcpu=cortex-a72 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -OPTIONS=$(SMALL_SCREEN_OPTIONS) $(MIDI_OPTIONS) $(PURESIGNAL_OPTIONS) $(REMOTE_OPTIONS) $(USBOZY_OPTIONS) \ +OPTIONS=$(SMALL_SCREEN_OPTIONS) $(MIDI_OPTIONS) $(LEVEL_OPTIONS) $(PURESIGNAL_OPTIONS) $(REMOTE_OPTIONS) $(USBOZY_OPTIONS) \ $(GPIO_OPTIONS) $(GPIOD_OPTIONS) $(LOCALCW_OPTIONS) \ $(PTT_OPTIONS) \ $(SERVER_OPTIONS) \ diff --git a/old_protocol.c b/old_protocol.c index b87b151..ede3788 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -1728,7 +1728,13 @@ void ozy_send_buffer() { /* } */ output_buffer[C0]=0x12; /* addr[6:1] = 001001b */ +#ifdef SW_LEVEL_CTRL + // highest power from hardware, but use software scaling to + // scale the level + output_buffer[C1]=255 & 0xFF; +#else output_buffer[C1]=power & 0xFF; +#endif output_buffer[C2]=0x00; output_buffer[C3]=0x00; output_buffer[C4]=0x00; diff --git a/transmitter.c b/transmitter.c index ac20520..7520e75 100644 --- a/transmitter.c +++ b/transmitter.c @@ -1028,8 +1028,12 @@ static void full_tx_buffer(TRANSMITTER *tx) { } if (isTransmitting()) { - +#ifdef SW_LEVEL_CTRL + if((radio->device==NEW_DEVICE_ATLAS && atlas_penelope) || + (radio->device == DEVICE_HERMES_LITE2)) { +#else if(radio->device==NEW_DEVICE_ATLAS && atlas_penelope) { +#endif // // On these boards, drive level changes are performed by // scaling the TX IQ samples. In the other cases, DriveLevel @@ -1086,6 +1090,10 @@ static void full_tx_buffer(TRANSMITTER *tx) { ramp=cw_shape_buffer48[j]; // between 0.0 and 1.0 qsample=floor(gain*ramp+0.5); // always non-negative, isample is just the pulse envelope sidetone=sidevol * ramp * getNextInternalSideToneSample(); + + isample = isample >= 0.0 ? (long)floor(isample * gain + 0.5) : (long)ceil(isample * gain - 0.5); + qsample = qsample >= 0.0 ? (long)floor(qsample * gain + 0.5) : (long)ceil(qsample * gain - 0.5); + old_protocol_iq_samples_with_sidetone(isample,qsample,sidetone); } break; @@ -1098,6 +1106,10 @@ static void full_tx_buffer(TRANSMITTER *tx) { for(j=0;joutput_samples;j++) { ramp=cw_shape_buffer192[j]; // between 0.0 and 1.0 qsample=floor(gain*ramp+0.5); // always non-negative, isample is just the pulse envelope + + isample = isample >= 0.0 ? (long)floor(isample * gain + 0.5) : (long)ceil(isample * gain - 0.5); + qsample = qsample >= 0.0 ? (long)floor(qsample * gain + 0.5) : (long)ceil(qsample * gain - 0.5); + new_protocol_iq_samples(isample,qsample); } break; @@ -1115,8 +1127,8 @@ static void full_tx_buffer(TRANSMITTER *tx) { is=tx->iq_output_buffer[j*2]; qs=tx->iq_output_buffer[(j*2)+1]; } - isample=is>=0.0?(long)floor(is*gain+0.5):(long)ceil(is*gain-0.5); - qsample=qs>=0.0?(long)floor(qs*gain+0.5):(long)ceil(qs*gain-0.5); + isample = is >= 0.0 ? (long)floor(is * gain + 0.5) : (long)ceil(is * gain - 0.5); + qsample = qs >= 0.0 ? (long)floor(qs * gain + 0.5) : (long)ceil(qs * gain - 0.5); switch(protocol) { case ORIGINAL_PROTOCOL: old_protocol_iq_samples(isample,qsample);