summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted/ypr0/radio-ypr0.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/ypr0/radio-ypr0.c')
-rw-r--r--firmware/target/hosted/ypr0/radio-ypr0.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/firmware/target/hosted/ypr0/radio-ypr0.c b/firmware/target/hosted/ypr0/radio-ypr0.c
index c3597bd18c..14d56826c1 100644
--- a/firmware/target/hosted/ypr0/radio-ypr0.c
+++ b/firmware/target/hosted/ypr0/radio-ypr0.c
@@ -25,8 +25,12 @@
#include <sys/ioctl.h>
#include "stdint.h"
#include "string.h"
+#include "kernel.h"
#include "radio-ypr0.h"
+#include "rds.h"
+#include "si4700.h"
+#include "power.h"
static int radio_dev = -1;
@@ -63,4 +67,59 @@ int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
(void)address;
sSi4709_i2c_t r = { .size = count, .buf = buf };
return ioctl(radio_dev, IOCTL_SI4709_I2C_READ, &r);
-} \ No newline at end of file
+}
+
+#ifdef HAVE_RDS_CAP
+
+/* Register we are going to poll */
+#define STATUSRSSI 0xA
+#define STATUSRSSI_RDSR (0x1 << 15)
+
+/* Low-level RDS Support */
+static struct event_queue rds_queue;
+static uint32_t rds_stack[DEFAULT_STACK_SIZE / sizeof(uint32_t)];
+static uint16_t rds_data[4];
+
+enum {
+ Q_POWERUP,
+};
+
+static void NORETURN_ATTR rds_thread(void)
+{
+ /* start up frozen */
+ int timeout = TIMEOUT_BLOCK;
+ struct queue_event ev;
+
+ while (true) {
+ queue_wait_w_tmo(&rds_queue, &ev, timeout);
+ switch (ev.id) {
+ case Q_POWERUP:
+ /* power up: timeout after 1 tick, else block indefinitely */
+ timeout = ev.data ? 1 : TIMEOUT_BLOCK;
+ break;
+ case SYS_TIMEOUT:
+ /* Captures RDS data and processes it */
+ if ((si4709_read_reg(STATUSRSSI) & STATUSRSSI_RDSR) >> 8) {
+ if (si4700_rds_read_raw(rds_data) && rds_process(rds_data))
+ si4700_rds_set_event();
+ }
+ break;
+ }
+ }
+}
+
+/* true after full radio power up, and false before powering down */
+void si4700_rds_powerup(bool on)
+{
+ queue_post(&rds_queue, Q_POWERUP, on);
+}
+
+/* One-time RDS init at startup */
+void si4700_rds_init(void)
+{
+ queue_init(&rds_queue, false);
+ create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
+ IF_PRIO(, PRIORITY_PLAYBACK) IF_COP(, CPU));
+ rds_init();
+}
+#endif /* HAVE_RDS_CAP */