public
Created

fuze+ radio

  • Download Gist
fuzep_radio.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
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;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.