summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s/fmradio-i2c-gigabeat-s.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/fmradio-i2c-gigabeat-s.c')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/fmradio-i2c-gigabeat-s.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/fmradio-i2c-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/fmradio-i2c-gigabeat-s.c
index 39a2cdab04..e0457e367a 100644
--- a/firmware/target/arm/imx31/gigabeat-s/fmradio-i2c-gigabeat-s.c
+++ b/firmware/target/arm/imx31/gigabeat-s/fmradio-i2c-gigabeat-s.c
@@ -23,8 +23,12 @@
23#include "system.h" 23#include "system.h"
24#include "mc13783.h" 24#include "mc13783.h"
25#include "iomuxc-imx31.h" 25#include "iomuxc-imx31.h"
26#include "gpio-imx31.h"
26#include "i2c-imx31.h" 27#include "i2c-imx31.h"
27#include "fmradio_i2c.h" 28#include "fmradio_i2c.h"
29#include "thread.h"
30#include "rds.h"
31#include "tuner.h"
28 32
29static struct i2c_node si4700_i2c_node = 33static struct i2c_node si4700_i2c_node =
30{ 34{
@@ -117,7 +121,57 @@ int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
117 return 0; 121 return 0;
118} 122}
119 123
120int si4700_st(void) 124bool si4700_st(void)
121{ 125{
122 return (GPIO1_DR & (1 << 28)) >> 28; 126 return (GPIO1_DR & (1 << 28)) >> 28;
123} 127}
128
129
130/* Low-level RDS Support */
131static struct semaphore rds_sema;
132static uint32_t rds_stack[DEFAULT_STACK_SIZE/sizeof(uint32_t)];
133
134/* RDS GPIO interrupt handler */
135void si4700_stc_rds_event(void)
136{
137 /* read and clear the interrupt */
138 SI4700_GPIO_STC_RDS_ISR = (1ul << SI4700_GPIO_STC_RDS_LINE);
139 semaphore_release(&rds_sema);
140}
141
142/* Called with on=true after full radio power up, and with on=false before
143 powering down */
144void si4700_rds_powerup(bool on)
145{
146 gpio_disable_event(SI4700_STC_RDS_EVENT_ID);
147
148 if (on)
149 {
150 SI4700_GPIO_STC_RDS_ISR = (1ul << SI4700_GPIO_STC_RDS_LINE);
151 gpio_enable_event(SI4700_STC_RDS_EVENT_ID);
152 }
153}
154
155/* Captures RDS data and processes it */
156/* Use of a thread here is likely temporary */
157static void NORETURN_ATTR rds_thread(void)
158{
159 uint16_t rds_data[4];
160
161 while (1)
162 {
163 semaphore_wait(&rds_sema, TIMEOUT_BLOCK);
164
165 if (si4700_rds_read_raw(rds_data) && rds_process(rds_data))
166 si4700_rds_set_event();
167 }
168}
169
170/* One-time RDS init at startup */
171void si4700_rds_init(void)
172{
173 semaphore_init(&rds_sema, 1, 0);
174 rds_init();
175 create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
176 IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU));
177}