Skip to content

@pamaury /fuzep_radio.diff
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
fuze+ radio
diff --git a/apps/radio/radio.c b/apps/radio/radio.c
index e9de69b..ad6071b 100644
--- a/apps/radio/radio.c
+++ b/apps/radio/radio.c
@@ -193,7 +193,7 @@ void radio_start(void)
radio_status &= ~FMRADIO_START_PAUSED;
if(radio_status == FMRADIO_OFF)
- tuner_power(true);
+ tuner_set(RADIO_POWER, 1);
curr_freq = global_status.last_frequency * fmr->freq_step + fmr->freq_min;
@@ -258,7 +258,7 @@ static void radio_off(void)
tuner_set(RADIO_MUTE, 1);
tuner_set(RADIO_SLEEP, 1); /* low power mode, if available */
radio_status = FMRADIO_OFF;
- tuner_power(false); /* status update, power off if avail. */
+ tuner_set(RADIO_POWER, 0); /* status update, power off if avail. */
}
void radio_stop(void)
diff --git a/firmware/drivers/tuner/si4700.c b/firmware/drivers/tuner/si4700.c
index 6966891..226cde3 100644
--- a/firmware/drivers/tuner/si4700.c
+++ b/firmware/drivers/tuner/si4700.c
@@ -342,38 +342,44 @@ static void si4700_sleep(int snooze)
}
}
-bool si4700_detect(void)
-{
- if (!tuner_present) {
- tuner_power(true);
- tuner_present = (si4700_read_reg(DEVICEID) == 0x1242);
- tuner_power(false);
- }
- return tuner_present;
-}
-
-void si4700_init(void)
+void si4700_power(bool enable)
{
- /* check device id */
- if (si4700_detect()) {
- mutex_init(&fmr_mutex);
-
+ if(enable == tuner_powered())
+ return;
+
+ if(enable)
+ {
tuner_power(true);
-
/* read all registers */
si4700_read(16);
- si4700_sleep(0);
-
#ifdef SI4700_USE_INTERNAL_OSCILLATOR
/* Enable the internal oscillator
(Si4702-16 needs this register to be initialised to 0x100) */
si4700_write_set(TEST1, TEST1_XOSCEN | 0x100);
sleep(HZ/2);
#endif
-
- si4700_sleep(1);
+ }
+ else
+ {
tuner_power(false);
+ }
+}
+bool si4700_detect(void)
+{
+ if (!tuner_present) {
+ si4700_power(true);
+ tuner_present = (si4700_read_reg(DEVICEID) == 0x1242);
+ si4700_power(false);
+ }
+ return tuner_present;
+}
+
+void si4700_init(void)
+{
+ mutex_init(&fmr_mutex);
+ /* check device id */
+ if (si4700_detect()) {
#ifdef HAVE_RDS_CAP
si4700_rds_init();
#endif
@@ -445,6 +451,9 @@ int si4700_set(int setting, int value)
{
int val = 1;
+ if(!tuner_powered() && setting != RADIO_POWER)
+ return -1;
+
mutex_lock(&fmr_mutex);
switch(setting)
@@ -484,6 +493,10 @@ int si4700_set(int setting, int value)
POWERCFG_MONO);
break;
+ case RADIO_POWER:
+ si4700_power(value);
+ break;
+
default:
val = -1;
break;
@@ -499,12 +512,15 @@ int si4700_get(int setting)
{
int val = -1; /* default for unsupported query */
+ if(!tuner_powered() && setting != RADIO_POWERED && setting != RADIO_PRESENT)
+ return -1;
+
mutex_lock(&fmr_mutex);
switch(setting)
{
case RADIO_PRESENT:
- val = tuner_present ? 1 : 0;
+ val = tuner_present;
break;
case RADIO_TUNED:
@@ -527,6 +543,10 @@ int si4700_get(int setting)
val = RSSI_MAX;
break;
+ case RADIO_POWERED:
+ val = tuner_powered();
+ break;
+
#ifdef HAVE_RDS_CAP
case RADIO_EVENT:
{
diff --git a/firmware/export/tuner.h b/firmware/export/tuner.h
index 694da7c..03069b4 100644
--- a/firmware/export/tuner.h
+++ b/firmware/export/tuner.h
@@ -34,6 +34,7 @@ enum
RADIO_MUTE,
RADIO_FORCE_MONO,
RADIO_SCAN_FREQUENCY,
+ RADIO_POWER,
/* Put new general-purpose settings above this line */
__RADIO_SET_STANDARD_LAST
@@ -50,6 +51,7 @@ enum
RADIO_RSSI,
RADIO_RSSI_MIN,
RADIO_RSSI_MAX,
+ RADIO_POWERED,
/* Put new general-purpose readback values above this line */
__RADIO_GET_STANDARD_LAST
diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c
index 1b72a4b..e6ca5a1 100644
--- a/firmware/target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c
+++ b/firmware/target/arm/imx233/sansa-fuzeplus/power-fuzeplus.c
@@ -38,6 +38,8 @@ bool tuner_power(bool enable)
imx233_enable_gpio_output(0, 29, enable);
imx233_set_gpio_output(0, 29, enable);
tuner_enable = enable;
+ /* very important delay to power up, the exact amount needed is unknown */
+ sleep(1);
//imx233_power_set_dcdc_freq(enable, HW_POWER_MISC__FREQSEL__24MHz);
}
return tuner_enable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.