diff --git a/firmware/drivers/tuner/ipod_remote_tuner.c b/firmware/drivers/tuner/ipod_remote_tuner.c index 25ad2d9845..52d93b8b34 100644 --- a/firmware/drivers/tuner/ipod_remote_tuner.c +++ b/firmware/drivers/tuner/ipod_remote_tuner.c @@ -177,8 +177,9 @@ void rmt_tuner_region(int region) { if (region != old_region) { + const struct fm_region_data *rd = &fm_region_data[region]; unsigned char data[] = {0x07, 0x08, 0x00}; - if (region == 2) + if (rd->freq_min == 76000000) { data[2] = 0x02; /* japan band */ } @@ -378,12 +379,14 @@ int ipod_rmt_tuner_set(int setting, int value) case RADIO_REGION: { - const struct rmt_tuner_region_data *rd = - &rmt_tuner_region_data[value]; + const struct fm_region_data *rd = &fm_region_data[value]; + int band = (rd->freq_min == 76000000) ? 2 : 0; + int spacing = (100000 / rd->freq_step); + int deemphasis = (rd->deemphasis == 50) ? 1 : 0; - rmt_tuner_region(rd->band); - set_deltafreq(rd->spacing); - set_deemphasis(rd->deemphasis); + rmt_tuner_region(band); + set_deltafreq(spacing); + set_deemphasis(deemphasis); rmt_tuner_set_param(tuner_param); break; } diff --git a/firmware/drivers/tuner/lv24020lp.c b/firmware/drivers/tuner/lv24020lp.c index 86f8c39593..0228888309 100644 --- a/firmware/drivers/tuner/lv24020lp.c +++ b/firmware/drivers/tuner/lv24020lp.c @@ -938,11 +938,14 @@ int lv24020lp_set(int setting, int value) break; case RADIO_REGION: - if (lv24020lp_region_data[value]) + { + const struct fm_region_data *rd = &fm_region_data[value]; + if (rd->deemphasis == 75) lv24020lp_write_set(AUDIO_CTRL2, DEEMP); else lv24020lp_write_clear(AUDIO_CTRL2, DEEMP); break; + } case RADIO_FORCE_MONO: if (value) diff --git a/firmware/drivers/tuner/rda5802.c b/firmware/drivers/tuner/rda5802.c index a505b6b382..8c78a9f243 100644 --- a/firmware/drivers/tuner/rda5802.c +++ b/firmware/drivers/tuner/rda5802.c @@ -59,16 +59,16 @@ #define CHANNEL_BAND (0x3 << 2) #define CHANNEL_BANDw(x) (((x) << 2) & CHANNEL_BAND) #define CHANNEL_BANDr(x) (((x) & CHANNEL_BAND) >> 2) - #define CHANNEL_BAND_875_1080 (0x0 << 2) /* tenth-megahertz */ - #define CHANNEL_BAND_760_1080 (0x1 << 2) - #define CHANNEL_BAND_760_900 (0x2 << 2) - #define CHANNEL_BAND_650_760 (0x3 << 2) + #define CHANNEL_BAND_870_1080 (0x0) /* tenth-megahertz */ + #define CHANNEL_BAND_760_1080 (0x1) + #define CHANNEL_BAND_760_900 (0x2) + #define CHANNEL_BAND_650_760 (0x3) #define CHANNEL_SPACE (0x3 << 0) #define CHANNEL_SPACEw(x) (((x) << 0) & CHANNEL_SPACE) #define CHANNEL_SPACEr(x) (((x) & CHANNEL_SPACE) >> 0) - #define CHANNEL_SPACE_100KHZ (0x0 << 0) - #define CHANNEL_SPACE_200KHZ (0x1 << 0) - #define CHANNEL_SPACE_50KHZ (0x2 << 0) + #define CHANNEL_SPACE_100KHZ (0x0) + #define CHANNEL_SPACE_200KHZ (0x1) + #define CHANNEL_SPACE_50KHZ (0x2) /* SYSCONFIG1 (0x4) */ #define SYSCONFIG1_DE (0x1 << 11) @@ -239,13 +239,16 @@ static int rda5802_tuned(void) static void rda5802_set_region(int region) { - const struct rda5802_region_data *rd = &rda5802_region_data[region]; - uint16_t bandspacing = CHANNEL_BANDw(rd->band) | + const struct fm_region_data *rd = &fm_region_data[region]; + int band = (rd->freq_min == 76000000) ? + CHANNEL_BAND_760_900 : CHANNEL_BAND_870_1080; + int deemphasis = (rd->deemphasis == 50) ? SYSCONFIG1_DE : 0; + + uint16_t bandspacing = CHANNEL_BANDw(band) | CHANNEL_SPACEw(CHANNEL_SPACE_50KHZ); uint16_t oldbs = cache[CHANNEL] & (CHANNEL_BAND | CHANNEL_SPACE); - rda5802_write_masked(SYSCONFIG1, rd->deemphasis ? SYSCONFIG1_DE : 0, - SYSCONFIG1_DE); + rda5802_write_masked(SYSCONFIG1, deemphasis, SYSCONFIG1_DE); rda5802_write_masked(CHANNEL, bandspacing, CHANNEL_BAND | CHANNEL_SPACE); rda5802_write_cache(); diff --git a/firmware/drivers/tuner/si4700.c b/firmware/drivers/tuner/si4700.c index f9b26be6f8..ea88dc9835 100644 --- a/firmware/drivers/tuner/si4700.c +++ b/firmware/drivers/tuner/si4700.c @@ -400,14 +400,17 @@ static int si4700_tuned(void) static void si4700_set_region(int region) { - const struct si4700_region_data *rd = &si4700_region_data[region]; - uint16_t bandspacing = SYSCONFIG2_BANDw(rd->band) | - SYSCONFIG2_SPACEw(rd->spacing); + const struct fm_region_data *rd = &fm_region_data[region]; + + int band = (rd->freq_min == 76000000) ? 2 : 0; + int spacing = (100000 / rd->freq_step); + int deemphasis = (rd->deemphasis == 50) ? SYSCONFIG1_DE : 0; + + uint16_t bandspacing = SYSCONFIG2_BANDw(band) | + SYSCONFIG2_SPACEw(spacing); uint16_t oldbs = cache[SYSCONFIG2] & (SYSCONFIG2_BAND | SYSCONFIG2_SPACE); - si4700_write_masked(SYSCONFIG1, - rd->deemphasis ? SYSCONFIG1_DE : 0, - SYSCONFIG1_DE); + si4700_write_masked(SYSCONFIG1, deemphasis, SYSCONFIG1_DE); si4700_write_masked(SYSCONFIG2, bandspacing, SYSCONFIG2_BAND | SYSCONFIG2_SPACE); diff --git a/firmware/drivers/tuner/tea5760uk.c b/firmware/drivers/tuner/tea5760uk.c index db07e20cf4..20234e28ed 100644 --- a/firmware/drivers/tuner/tea5760uk.c +++ b/firmware/drivers/tuner/tea5760uk.c @@ -91,11 +91,12 @@ int tea5760_set(int setting, int value) case RADIO_REGION: { - const struct tea5760_region_data *rd = - &tea5760_region_data[value]; + const struct fm_region_data *rd = &fm_region_data[value]; + int band = (rd->freq_min == 76000000) ? 1 : 0; + int deemphasis = (rd->deemphasis == 50) ? 1 : 0; - tea5760_set_clear(4, (1<<1), rd->deemphasis); - tea5760_set_clear(3, (1<<5), rd->band); + tea5760_set_clear(3, (1<<5), band); + tea5760_set_clear(4, (1<<1), deemphasis); } break; diff --git a/firmware/drivers/tuner/tea5767.c b/firmware/drivers/tuner/tea5767.c index 5888e00781..b16bb4b7c5 100644 --- a/firmware/drivers/tuner/tea5767.c +++ b/firmware/drivers/tuner/tea5767.c @@ -86,11 +86,12 @@ int tea5767_set(int setting, int value) case RADIO_REGION: { - const struct tea5767_region_data *rd = - &tea5767_region_data[value]; + const struct fm_region_data *rd = &fm_region_data[value]; + int deemphasis = (rd->deemphasis == 75) ? 1 : 0; + int band = (rd->freq_min == 76000000) ? 1 : 0; - tea5767_set_clear(4, (1<<6), rd->deemphasis); - tea5767_set_clear(3, (1<<5), rd->band); + tea5767_set_clear(4, (1<<6), deemphasis); + tea5767_set_clear(3, (1<<5), band); break; } case RADIO_FORCE_MONO: diff --git a/firmware/export/ipod_remote_tuner.h b/firmware/export/ipod_remote_tuner.h index 28fcfe1e93..2c866ad3d2 100644 --- a/firmware/export/ipod_remote_tuner.h +++ b/firmware/export/ipod_remote_tuner.h @@ -48,19 +48,6 @@ extern void rmt_tuner_signal_power(unsigned char value); extern void rmt_tuner_rds_data(void); -struct rmt_tuner_region_data -{ - /* 0: 50us, 1: 75us */ - unsigned char deemphasis; - /* 0: europe, 1: japan (BL in TEA spec)*/ - unsigned char band; - /* 0: us/australia (200kHz), 1: europe/japan (100kHz), 2: (50kHz) */ - unsigned char spacing; -} __attribute__((packed)); - -extern const struct rmt_tuner_region_data - rmt_tuner_region_data[TUNER_NUM_REGIONS]; - int ipod_rmt_tuner_set(int setting, int value); int ipod_rmt_tuner_get(int setting); char* ipod_get_rds_info(int setting); diff --git a/firmware/export/lv24020lp.h b/firmware/export/lv24020lp.h index 16a8856a3f..753949f361 100644 --- a/firmware/export/lv24020lp.h +++ b/firmware/export/lv24020lp.h @@ -37,8 +37,6 @@ #define LV24020LP_DEBUG_FIRST LV24020LP_CTRL_STAT #define LV24020LP_DEBUG_LAST LV24020LP_SD_SET -const unsigned char lv24020lp_region_data[TUNER_NUM_REGIONS]; - int lv24020lp_set(int setting, int value); int lv24020lp_get(int setting); void lv24020lp_power(bool status); diff --git a/firmware/export/rda5802.h b/firmware/export/rda5802.h index e61ecb40ae..87707966fd 100644 --- a/firmware/export/rda5802.h +++ b/firmware/export/rda5802.h @@ -27,14 +27,6 @@ #define HAVE_RADIO_REGION -struct rda5802_region_data -{ - unsigned char deemphasis; /* 0: 75us, 1: 50us */ - unsigned char band; /* 0: us/europe, 1: japan */ -} __attribute__((packed)); - -extern const struct rda5802_region_data rda5802_region_data[TUNER_NUM_REGIONS]; - struct rda5802_dbg_info { uint16_t regs[16]; /* Read registers */ diff --git a/firmware/export/si4700.h b/firmware/export/si4700.h index d6c4e73b6e..c4aff6ff30 100644 --- a/firmware/export/si4700.h +++ b/firmware/export/si4700.h @@ -27,15 +27,6 @@ #define HAVE_RADIO_REGION -struct si4700_region_data -{ - unsigned char deemphasis; /* 0: 75us, 1: 50us */ - unsigned char band; /* 0: us/europe, 1: japan */ - unsigned char spacing; /* 0: us/australia (200kHz), 1: europe/japan (100kHz), 2: (50kHz) */ -} __attribute__((packed)); - -extern const struct si4700_region_data si4700_region_data[TUNER_NUM_REGIONS]; - struct si4700_dbg_info { uint16_t regs[16]; /* Read registers */ diff --git a/firmware/export/tea5760.h b/firmware/export/tea5760.h index 8fa54dfa78..ea857dec3e 100644 --- a/firmware/export/tea5760.h +++ b/firmware/export/tea5760.h @@ -28,14 +28,6 @@ #define HAVE_RADIO_REGION -struct tea5760_region_data -{ - unsigned char deemphasis; /* 1: 50us, 0: 75us */ - unsigned char band; /* 0: europe, 1: japan (BL in TEA spec)*/ -} __attribute__((packed)); - -extern const struct tea5760_region_data tea5760_region_data[TUNER_NUM_REGIONS]; - struct tea5760_dbg_info { unsigned char read_regs[16]; diff --git a/firmware/export/tea5767.h b/firmware/export/tea5767.h index dceb0f4168..eee469d1ea 100644 --- a/firmware/export/tea5767.h +++ b/firmware/export/tea5767.h @@ -26,14 +26,6 @@ #define HAVE_RADIO_REGION #define HAVE_RADIO_MUTE_TIMEOUT -struct tea5767_region_data -{ - unsigned char deemphasis; /* 0: 50us, 1: 75us */ - unsigned char band; /* 0: europe, 1: japan (BL in TEA spec)*/ -} __attribute__((packed)); - -extern const struct tea5767_region_data tea5767_region_data[TUNER_NUM_REGIONS]; - struct tea5767_dbg_info { unsigned char read_regs[5]; diff --git a/firmware/export/tuner.h b/firmware/export/tuner.h index 461c9a3fcb..9263c08d90 100644 --- a/firmware/export/tuner.h +++ b/firmware/export/tuner.h @@ -84,6 +84,7 @@ struct fm_region_data int freq_min; int freq_max; int freq_step; + int deemphasis; /* in microseconds, usually 50 or 75 */ }; extern const struct fm_region_data fm_region_data[TUNER_NUM_REGIONS]; diff --git a/firmware/tuner.c b/firmware/tuner.c index 3232147bbb..e08cef46ff 100644 --- a/firmware/tuner.c +++ b/firmware/tuner.c @@ -28,92 +28,16 @@ /* General region information */ const struct fm_region_data fm_region_data[TUNER_NUM_REGIONS] = { - [REGION_EUROPE] = { 87500000, 108000000, 100000 }, - [REGION_US_CANADA] = { 87900000, 107900000, 200000 }, - [REGION_JAPAN] = { 76000000, 90000000, 100000 }, - [REGION_KOREA] = { 87500000, 108000000, 200000 }, - [REGION_ITALY] = { 87500000, 108000000, 50000 }, - [REGION_OTHER] = { 87500000, 108000000, 50000 } + [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 -/* Tuner-specific region information */ - -#if (CONFIG_TUNER & LV24020LP) -/* deemphasis setting for region */ -const unsigned char lv24020lp_region_data[TUNER_NUM_REGIONS] = -{ - [REGION_EUROPE] = 0, /* 50uS */ - [REGION_US_CANADA] = 1, /* 75uS */ - [REGION_JAPAN] = 0, /* 50uS */ - [REGION_KOREA] = 0, /* 50uS */ - [REGION_ITALY] = 0, /* 50uS */ - [REGION_OTHER] = 0, /* 50uS */ -}; -#endif /* (CONFIG_TUNER & LV24020LP) */ - -#if (CONFIG_TUNER & TEA5760) -const struct tea5760_region_data tea5760_region_data[TUNER_NUM_REGIONS] = -{ - [REGION_EUROPE] = { 1, 0 }, /* 50uS, US/Europe band */ - [REGION_US_CANADA] = { 0, 0 }, /* 75uS, US/Europe band */ - [REGION_JAPAN] = { 1, 1 }, /* 50uS, Japanese band */ - [REGION_KOREA] = { 1, 0 }, /* 50uS, US/Europe band */ - [REGION_ITALY] = { 1, 0 }, /* 50uS, US/Europe band */ - [REGION_OTHER] = { 1, 0 }, /* 50uS, US/Europe band */ -}; -#endif /* (CONFIG_TUNER & TEA5760) */ - -#if (CONFIG_TUNER & TEA5767) -const struct tea5767_region_data tea5767_region_data[TUNER_NUM_REGIONS] = -{ - [REGION_EUROPE] = { 0, 0 }, /* 50uS, US/Europe band */ - [REGION_US_CANADA] = { 1, 0 }, /* 75uS, US/Europe band */ - [REGION_JAPAN] = { 0, 1 }, /* 50uS, Japanese band */ - [REGION_KOREA] = { 0, 0 }, /* 50uS, US/Europe band */ - [REGION_ITALY] = { 0, 0 }, /* 50uS, US/Europe band */ - [REGION_OTHER] = { 0, 0 }, /* 50uS, US/Europe band */ -}; -#endif /* (CONFIG_TUNER & TEA5767) */ - -#if (CONFIG_TUNER & SI4700) -const struct si4700_region_data si4700_region_data[TUNER_NUM_REGIONS] = -{ - [REGION_EUROPE] = { 1, 0, 1 }, /* 50uS, US/Europe band, 100kHz spacing */ - [REGION_US_CANADA] = { 0, 0, 0 }, /* 75uS, US/Europe band, 200kHz spacing */ - [REGION_JAPAN] = { 1, 2, 1 }, /* 50uS, Japanese band, 100kHz spacing */ - [REGION_KOREA] = { 1, 0, 0 }, /* 50uS, US/Europe band, 200kHz spacing */ - [REGION_ITALY] = { 1, 0, 2 }, /* 50uS, US/Europe band, 50kHz spacing */ - [REGION_OTHER] = { 1, 0, 2 }, /* 50uS, US/Europe band, 50kHz spacing */ -}; -#endif /* (CONFIG_TUNER & SI4700) */ - -#if (CONFIG_TUNER & RDA5802) -const struct rda5802_region_data rda5802_region_data[TUNER_NUM_REGIONS] = -{ - [REGION_EUROPE] = { 1, 0 }, /* 50uS, US/Europe band */ - [REGION_US_CANADA] = { 0, 0 }, /* 75uS, US/Europe band */ - [REGION_JAPAN] = { 1, 1 }, /* 50uS, Japanese band */ - [REGION_KOREA] = { 1, 0 }, /* 50uS, US/Europe band */ - [REGION_ITALY] = { 1, 0 }, /* 50uS, US/Europe band */ - [REGION_OTHER] = { 1, 0 }, /* 50uS, US/Europe band */ -}; -#endif /* (CONFIG_TUNER & RDA5802) */ - -#if (CONFIG_TUNER & IPOD_REMOTE_TUNER) -const struct rmt_tuner_region_data - rmt_tuner_region_data[TUNER_NUM_REGIONS] = -{ - [REGION_EUROPE] = { 1, 0, 1 }, /* 50uS, US/Europe band, 100kHz spacing */ - [REGION_US_CANADA] = { 0, 0, 0 }, /* 75uS, US/Europe band, 200kHz spacing */ - [REGION_JAPAN] = { 1, 2, 1 }, /* 50uS, Japanese band, 100kHz spacing */ - [REGION_KOREA] = { 1, 0, 0 }, /* 50uS, US/Europe band, 200kHz spacing */ - [REGION_ITALY] = { 1, 0, 2 }, /* 50uS, US/Europe band, 50kHz spacing */ - [REGION_OTHER] = { 1, 0, 2 }, /* 50uS, US/Europe band, 50kHz spacing */ -}; -#endif /* (CONFIG_TUNER & IPOD_REMOTE_TUNER) */ - #ifdef CONFIG_TUNER_MULTI int (*tuner_set)(int setting, int value); int (*tuner_get)(int setting);