From ce708a0d35cbdba5f5af94cc1af89a21724043b7 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 26 Mar 2013 01:43:44 +0000 Subject: improved volume settings git-svn-id: https://svn.spreadspace.org/mur.sat@711 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/rda1846dongle/rda1846.c | 67 +++++++++++++++++++++++----------- software/rda1846dongle/rda1846.h | 9 +++-- software/rda1846dongle/rda1846dongle.c | 29 +++++++++++++++ 3 files changed, 81 insertions(+), 24 deletions(-) (limited to 'software/rda1846dongle') diff --git a/software/rda1846dongle/rda1846.c b/software/rda1846dongle/rda1846.c index 6607ec8..921296c 100644 --- a/software/rda1846dongle/rda1846.c +++ b/software/rda1846dongle/rda1846.c @@ -326,6 +326,52 @@ rda1846_state_t rda1846_get_state(void) +uint16_t rda1846_get_dtmf(uint8_t* idx1, uint8_t* idx2, uint8_t* code, uint8_t* valid) +{ + uint16_t data; + if(rda1846_read_register(RDA1846_REG_DTMF_OUT, &data)) + return 0xFFFF; + + if(idx1) *idx1 = (uint8_t)((data & 0x0700)>>8); + if(idx2) *idx2 = (uint8_t)((data & 0x00E0)>>5); + if(code) *code = (uint8_t)(data & 0x000F); + if(valid) *valid = data & 0x0010 ? 0 : 1; + + return data; +} + +void rda1846_clear_int(void) +{ + rda1846_write_register(0x00, 0x1846); +} + + + +void rda1846_set_volume(int8_t vol) +{ + uint16_t data; + if(vol < -30 || vol > 0) + return; + + if(vol >= -15) + data = 0x000F | (((vol + 15)<<4) & 0xF0); + else + data = (vol + 30) & 0x0F; + + rda1846_write_register(RDA1846_REG_RX_VOICE, data); +} + +int8_t rda1846_get_volume(void) +{ + uint16_t data; + if(rda1846_read_register(RDA1846_REG_RX_VOICE, &data)) + return 1; + + return (int8_t)(((data & 0x00F0)>>4) + (data & 0x000F)) - 30; +} + + + void rda1846_gpio_default(void) { rda1846_write_register(RDA1846_REG_GPIO, RDA1846_GPIO_7_VOX | RDA1846_GPIO_6_SQ | @@ -388,27 +434,6 @@ uint16_t rda1846_get_flags(void) -uint16_t rda1846_get_dtmf(uint8_t* idx1, uint8_t* idx2, uint8_t* code, uint8_t* valid) -{ - uint16_t data; - if(rda1846_read_register(RDA1846_REG_DTMF_OUT, &data)) - return 0xFFFF; - - if(idx1) *idx1 = (uint8_t)((data & 0x0700)>>8); - if(idx2) *idx2 = (uint8_t)((data & 0x00E0)>>5); - if(code) *code = (uint8_t)(data & 0x000F); - if(valid) *valid = data & 0x0010 ? 0 : 1; - - return data; -} - -void rda1846_clear_int(void) -{ - rda1846_write_register(0x00, 0x1846); -} - - - static char* rda1846_regaddr_to_string(uint8_t addr) { switch(addr) { diff --git a/software/rda1846dongle/rda1846.h b/software/rda1846dongle/rda1846.h index fd6ac17..d3efa1e 100644 --- a/software/rda1846dongle/rda1846.h +++ b/software/rda1846dongle/rda1846.h @@ -57,6 +57,12 @@ channel_bw_t rda1846_get_bw(void); uint8_t rda1846_set_freq_kHz(int32_t freq); int32_t rda1846_get_freq_kHz(void); +uint16_t rda1846_get_dtmf(uint8_t*, uint8_t*, uint8_t*, uint8_t*); +void rda1846_clear_int(void); + +void rda1846_set_volume(int8_t); +int8_t rda1846_get_volume(void); + void rda1846_gpio_default(void); void rda1846_gpio_55(void); void rda1846_gpio_AA(void); @@ -66,9 +72,6 @@ int16_t rda1846_get_rssi(void); int16_t rda1846_get_vssi(void); uint16_t rda1846_get_flags(void); -uint16_t rda1846_get_dtmf(uint8_t*, uint8_t*, uint8_t*, uint8_t*); -void rda1846_clear_int(void); - void rda1846_dump_register(void); #endif diff --git a/software/rda1846dongle/rda1846dongle.c b/software/rda1846dongle/rda1846dongle.c index e058c9d..e0297a7 100644 --- a/software/rda1846dongle/rda1846dongle.c +++ b/software/rda1846dongle/rda1846dongle.c @@ -48,6 +48,7 @@ #define DEFAULT_FREQ_70CM 435000 int32_t default_freq = DEFAULT_FREQ_2M; int32_t current_freq_kHz = DEFAULT_FREQ_2M; +int8_t current_volume = 0; static void reset_rda(void) { @@ -150,7 +151,15 @@ static void print_status(void) else printf("flags: %04X\r\n", flags); + int8_t vol = rda1846_get_volume(); + if(vol > 0) + printf("volume: NaN dB\r\n"); + else + printf("volume: %d dB\r\n", vol); + + printf("rf band: %s\r\n", rda1846_rf_band_to_string(rda1846_get_band())); print_actual_freq(); + printf("bandwidth: %s\r\n", rda1846_channel_bw_to_string(rda1846_get_bw())); } static void print_dtmf(void) @@ -164,6 +173,23 @@ static void print_dtmf(void) rda1846_clear_int(); } +static void update_vol(void) +{ + printf("setting volume to %d dB\r\n", current_volume); + rda1846_set_volume(current_volume); +} + +static void inc_vol(void) +{ + current_volume = (current_volume >= 0) ? 0 : current_volume + 1; + update_vol(); +} + +static void dec_vol(void) +{ + current_volume = (current_volume <= -30) ? -30 : current_volume - 1; + update_vol(); +} static void handle_cmd(uint8_t cmd) { @@ -195,6 +221,9 @@ static void handle_cmd(uint8_t cmd) case 'R': rda1846_receive(); print_status(); break; case 'T': rda1846_transmit(); print_status(); break; + case 'v': dec_vol(); break; + case 'V': inc_vol(); break; + case 'g': rda1846_gpio_off(); printf("GPIO off\r\n"); break; case 'G': rda1846_gpio_default(); printf("GPIO to defaults\r\n"); break; case '5': rda1846_gpio_55(); break; -- cgit v1.2.3