rockbox/firmware/tuner.c
Michael Sevakis fc9695eb47 Improve radio RDS driver and framework
* Remove unused bits like the radio event and simplify basic
radio interface. It can be more self-contained with rds.h only
required by radio and tuner code.

* Add post-processing to text a-la Silicon Labs AN243. The chip's
error correction can only do so much; additional checks are highly
recommended. Simply testing for two identical messages in a row
is extremely effective and I've never seen corrupted text since
doing that, even with mediocre reception.

Groups segments must arrive in order, not randomly; logic change
only accepts them in order, starting at 0.

Time readout was made a bit better but really we'd need to use
verbose mode and ensure that no errors were seen during receiving
of time and more checks would be need to have a stable PI. The
text is the important bit anyway.

* Time out of stale text.

* Text is no longer updated until a complete group has been
received, as is specified in the standard. Perhaps go back to
scrolling text lines in the radio screen?

* Add proper character conversion to UTF-8. Only the default G0
table for the moment. The other two could be added in.

* Add variants "RDS_CFG_PROCESS" and "RDS_CFG_PUSH" to allow
the option for processed RDS data to be pushed to the driver and
still do proper post-processing (only text conversion for now for
the latter).

Change-Id: I4d83f8b2e89a209a5096d15ec266477318c66925
2017-02-11 22:19:32 -05:00

128 lines
4.1 KiB
C

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
* General tuner functions
*
* Copyright (C) 2007 by Michael Sevakis
*
* 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdlib.h>
#include "config.h"
#include "kernel.h"
#include "tuner.h"
#include "fmradio.h"
#ifdef HAVE_RDS_CAP
#include "rds.h"
#endif /* HAVE_RDS_CAP */
/* General region information */
const struct fm_region_data fm_region_data[TUNER_NUM_REGIONS] =
{
[REGION_EUROPE] = { 87500000, 108000000, 100000, 50 },
[REGION_US_CANADA] = { 87900000, 107900000, 200000, 75 },
[REGION_JAPAN] = { 76000000, 90000000, 100000, 50 },
[REGION_KOREA] = { 87500000, 108000000, 200000, 50 },
[REGION_ITALY] = { 87500000, 108000000, 50000, 50 },
[REGION_OTHER] = { 87500000, 108000000, 50000, 50 }
};
#ifndef SIMULATOR
#ifdef CONFIG_TUNER_MULTI
int (*tuner_set)(int setting, int value);
int (*tuner_get)(int setting);
#define TUNER_TYPE_CASE(type, set, get, ...) \
case type: \
tuner_set = set; \
tuner_get = get; \
__VA_ARGS__; \
break;
#else
#define TUNER_TYPE_CASE(type, set, get, ...) \
__VA_ARGS__;
#endif /* CONFIG_TUNER_MULTI */
void tuner_init(void)
{
#ifdef CONFIG_TUNER_MULTI
switch (tuner_detect_type())
#endif
{
#if (CONFIG_TUNER & LV24020LP)
TUNER_TYPE_CASE(LV24020LP,
lv24020lp_set,
lv24020lp_get,
lv24020lp_init())
#endif
#if (CONFIG_TUNER & TEA5760)
TUNER_TYPE_CASE(TEA5760,
tea5760_set,
tea5760_get,
tea5760_init())
#endif
#if (CONFIG_TUNER & TEA5767)
TUNER_TYPE_CASE(TEA5767,
tea5767_set,
tea5767_get,
tea5767_init())
#endif
#if (CONFIG_TUNER & S1A0903X01)
TUNER_TYPE_CASE(S1A0903X01,
s1a0903x01_set,
s1a0903x01_get)
#endif
#if (CONFIG_TUNER & SI4700)
TUNER_TYPE_CASE(SI4700,
si4700_set,
si4700_get,
si4700_init())
#endif
#if (CONFIG_TUNER & RDA5802)
TUNER_TYPE_CASE(RDA5802,
rda5802_set,
rda5802_get,
rda5802_init())
#endif
#if (CONFIG_TUNER & STFM1000)
TUNER_TYPE_CASE(STFM1000,
stfm1000_set,
stfm1000_get,
stfm1000_init())
#endif
}
}
#ifdef HAVE_RDS_CAP
size_t tuner_get_rds_info(int setting, void *dst, size_t dstsize)
{
/* TODO: integrate this into tuner_get/set */
static const unsigned char info_id_tbl[] =
{
[RADIO_RDS_NAME] = RDS_INFO_PS,
[RADIO_RDS_TEXT] = RDS_INFO_RT,
[RADIO_RDS_PROGRAM_INFO] = RDS_INFO_PI,
[RADIO_RDS_CURRENT_TIME] = RDS_INFO_CT,
};
if ((unsigned int)setting >= ARRAYLEN(info_id_tbl))
return 0;
return rds_pull_info(info_id_tbl[setting], (uintptr_t)dst, dstsize);
}
#endif /* HAVE_RDS_CAP */
#endif /* SIMULATOR */