summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c
index ee63cd35f6..7988c4cb28 100644
--- a/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c
+++ b/firmware/target/arm/imx233/sansa-fuzeplus/fmradio-i2c-fuzeplus.c
@@ -24,12 +24,15 @@
24#include "fmradio_i2c.h" 24#include "fmradio_i2c.h"
25#include "pinctrl-imx233.h" 25#include "pinctrl-imx233.h"
26#include "generic_i2c.h" 26#include "generic_i2c.h"
27#include "rds.h"
28#include "si4700.h"
27 29
28/** 30/**
29 * Sansa Fuze+ fmradio uses the following pins: 31 * Sansa Fuze+ fmradio uses the following pins:
30 * - B0P29 as CE apparently (active high) 32 * - B0P29 as CE apparently (active high)
31 * - B1P24 as SDA 33 * - B1P24 as SDA
32 * - B1P22 as SCL 34 * - B1P22 as SCL
35 * - B2P27 as STC/RDS
33 */ 36 */
34static int fmradio_i2c_bus = -1; 37static int fmradio_i2c_bus = -1;
35 38
@@ -103,3 +106,60 @@ int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
103{ 106{
104 return i2c_read_data(fmradio_i2c_bus, address, -1, buf, count); 107 return i2c_read_data(fmradio_i2c_bus, address, -1, buf, count);
105} 108}
109
110#ifdef HAVE_RDS_CAP
111/* Low-level RDS Support */
112static struct semaphore rds_sema;
113static uint32_t rds_stack[DEFAULT_STACK_SIZE / sizeof(uint32_t)];
114
115/* RDS GPIO interrupt handler */
116static void stc_rds_callback(int bank, int pin)
117{
118 (void) bank;
119 (void) pin;
120
121 semaphore_release(&rds_sema);
122}
123
124/* Captures RDS data and processes it */
125static void NORETURN_ATTR rds_thread(void)
126{
127 uint16_t rds_data[4];
128
129 while(true)
130 {
131 semaphore_wait(&rds_sema, TIMEOUT_BLOCK);
132 if(si4700_rds_read_raw(rds_data) && rds_process(rds_data))
133 si4700_rds_set_event();
134 /* renable callback */
135 imx233_setup_pin_irq(2, 27, true, true, false, &stc_rds_callback);
136 }
137}
138
139/* true after full radio power up, and false before powering down */
140void si4700_rds_powerup(bool on)
141{
142 if(on)
143 {
144 imx233_pinctrl_acquire_pin(2, 27, "tuner stc/rds");
145 imx233_set_pin_function(2, 27, PINCTRL_FUNCTION_GPIO);
146 imx233_enable_gpio_output(2, 27, false);
147 /* pin is set to 0 when an RDS packet has arrived */
148 imx233_setup_pin_irq(2, 27, true, true, false, &stc_rds_callback);
149 }
150 else
151 {
152 imx233_setup_pin_irq(2, 27, false, false, false, NULL);
153 imx233_pinctrl_release_pin(2, 27, "tuner stc/rds");
154 }
155}
156
157/* One-time RDS init at startup */
158void si4700_rds_init(void)
159{
160 semaphore_init(&rds_sema, 1, 0);
161 rds_init();
162 create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
163 IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU));
164}
165#endif /* HAVE_RDS_CAP */