summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-05-06 10:28:27 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2024-05-06 10:28:27 -0400
commit30482bd9087444c434ee4c4cc1756ca9a402f5ad (patch)
tree61c2df6847884ff478bdcac98ab39c021a047eac
parent1189006a4bcda9d5283f525a7d83de085e568c03 (diff)
downloadrockbox-30482bd908.tar.gz
rockbox-30482bd908.zip
[BugFix] Radio make sure resume frequency is in range
out of range frequencies hang the device (clip zip, others?) Change-Id: I0d3af83a05479f70a958168f57c8cc305195b06b
-rw-r--r--apps/radio/radio.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/apps/radio/radio.c b/apps/radio/radio.c
index bf8ad865dd..bf36f1d32d 100644
--- a/apps/radio/radio.c
+++ b/apps/radio/radio.c
@@ -167,6 +167,24 @@ bool in_radio_screen(void)
return in_screen;
}
+/* Keep freq on the grid for the current region */
+int snap_freq_to_grid(int freq)
+{
+ const struct fm_region_data * const fmr =
+ &fm_region_data[global_settings.fm_region];
+
+ /* Range clamp if out of range or just round to nearest */
+ if (freq < fmr->freq_min)
+ freq = fmr->freq_min;
+ else if (freq > fmr->freq_max)
+ freq = fmr->freq_max;
+ else
+ freq = (freq - fmr->freq_min + fmr->freq_step/2) /
+ fmr->freq_step * fmr->freq_step + fmr->freq_min;
+
+ return freq;
+}
+
/* TODO: Move some more of the control functionality to firmware
and clean up the mess */
@@ -186,7 +204,8 @@ void radio_start(void)
/* clear flag before any yielding */
radio_status &= ~FMRADIO_START_PAUSED;
- curr_freq = global_status.last_frequency * fmr->freq_step + fmr->freq_min;
+ /* ensure the frequency is in range otherwise bad things happen --Bilgus */
+ curr_freq = snap_freq_to_grid(global_status.last_frequency * fmr->freq_step + fmr->freq_min);
tuner_set(RADIO_SLEEP, 0); /* wake up the tuner */
@@ -261,24 +280,6 @@ bool radio_hardware_present(void)
return tuner_get(RADIO_PRESENT);
}
-/* Keep freq on the grid for the current region */
-int snap_freq_to_grid(int freq)
-{
- const struct fm_region_data * const fmr =
- &fm_region_data[global_settings.fm_region];
-
- /* Range clamp if out of range or just round to nearest */
- if (freq < fmr->freq_min)
- freq = fmr->freq_min;
- else if (freq > fmr->freq_max)
- freq = fmr->freq_max;
- else
- freq = (freq - fmr->freq_min + fmr->freq_step/2) /
- fmr->freq_step * fmr->freq_step + fmr->freq_min;
-
- return freq;
-}
-
void remember_frequency(void)
{
const struct fm_region_data * const fmr =