A mbed Port of 'Sparkfun Si4703 Arduino Library'.

Dependents:   projekt_Si4703

Fork of Si4703 by Moran Z.

Files at this revision

API Documentation at this revision

Comitter:
vodavprasku
Date:
Sat Jan 16 19:26:55 2016 +0000
Parent:
2:558ef02f39d0
Commit message:
hotovo

Changed in this revision

SparkFun-Si4703.cpp Show annotated file Show diff for this revision Revisions of this file
SparkFun-Si4703.h Show annotated file Show diff for this revision Revisions of this file
diff -r 558ef02f39d0 -r 9ac35cc4a0b0 SparkFun-Si4703.cpp
--- a/SparkFun-Si4703.cpp	Sat Aug 08 18:15:36 2015 +0000
+++ b/SparkFun-Si4703.cpp	Sat Jan 16 19:26:55 2016 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "SparkFun-Si4703.h"
+#include "millis.h"
 
 Si4703_Breakout::Si4703_Breakout(PinName sdioPin, PinName sclkPin, PinName resetPin, Serial *pc)
 {
@@ -22,8 +23,8 @@
 readRegisters();
 
 si4703_registers[POWERCFG] &= ~(1<<DMUTE); // 'Enable Mute'
-si4703_registers[POWERCFG] |= (1<<ENABLE); // 'Enable IC'
-si4703_registers[POWERCFG] |= (1<<DISABLE); // & 'Disable IC'
+//si4703_registers[POWERCFG] |= (1<<ENABLE); // 'Enable IC'
+//si4703_registers[POWERCFG] |= (1<<DISABLE); // & 'Disable IC'
 											// To Init. Power-Down Sequence
 
 updateRegisters();
@@ -32,10 +33,9 @@
 
 void Si4703_Breakout::setChannel(int channel)
 {
-  uint8_t ack;
-  //Freq(MHz) = 0.1 (in Europe) * Channel + 87.5MHz
-  //97.3 = 0.1 * Chan + 87.5
-  //9.8 / 0.1 = 98
+  //Freq(MHz) = 0.200(in USA) * Channel + 87.5MHz
+  //97.3 = 0.2 * Chan + 87.5
+  //9.8 / 0.2 = 49
   int newChannel = channel * 10; //973 * 10 = 9730
   newChannel -= 8750; //9730 - 8750 = 980
   newChannel /= 10; //980 / 10 = 98
@@ -47,13 +47,12 @@
   si4703_registers[CHANNEL] |= (1<<TUNE); //Set the TUNE bit to start
   updateRegisters();
 
-  wait_ms(60); //Wait 60ms - you can use or skip this delay
+  //delay(60); //Wait 60ms - you can use or skip this delay
 
   //Poll to see if STC is set
   while(1) {
-    ack = readRegisters();
-    wait_ms(1); // Just In Case...
-    if (( (si4703_registers[STATUSRSSI] & (1<<STC)) != 0) || (ack != SUCCESS)) break; //Tuning complete! (or FAILED)
+    readRegisters();
+    if( (si4703_registers[STATUSRSSI] & (1<<STC)) != 0) break; //Tuning complete!
   }
 
   readRegisters();
@@ -62,9 +61,8 @@
 
   //Wait for the si4703 to clear the STC as well
   while(1) {
-    ack = readRegisters();
-    wait_ms(1); // Just In Case...
-    if (( (si4703_registers[STATUSRSSI] & (1<<STC)) == 0) || (ack != SUCCESS)) break; //Tuning complete! (or FAILED)
+    readRegisters();
+    if( (si4703_registers[STATUSRSSI] & (1<<STC)) == 0) break; //Tuning complete!
   }
 }
 
@@ -95,15 +93,15 @@
   return (si4703_registers[SYSCONFIG2] & 0x000F);
 }
 
-/*
+
 void Si4703_Breakout::readRDS(char* buffer, long timeout)
 { 
 	long endTime = millis() + timeout;
-  boolean completed[] = {false, false, false, false};
-  int completedCount = 0;
-  while(completedCount < 4 && millis() < endTime) {
-	readRegisters();
-	if(si4703_registers[STATUSRSSI] & (1<<RDSR)){
+    bool completed[] = {false, false, false, false};
+    int completedCount = 0;
+  	while(completedCount < 4 && millis() < endTime) {
+		readRegisters();
+		if(si4703_registers[STATUSRSSI] & (1<<RDSR)){
 		// ls 2 bits of B determine the 4 letter pairs
 		// once we have a full set return
 		// if you get nothing after 20 readings return with empty string
@@ -123,10 +121,12 @@
 		// Serial.write(Dl);
 		// Serial.println();
       }
-      delay(40); //Wait for the RDS bit to clear
+      wait_ms(40);
+      /////delay(40); //Wait for the RDS bit to clear
 	}
 	else {
-	  delay(30); //From AN230, using the polling method 40ms should be sufficient amount of time between checks
+	  /////////delay(30); //From AN230, using the polling method 40ms should be sufficient amount of time between checks
+	  wait_ms(40);
 	}
   }
 	if (millis() >= endTime) {
@@ -136,7 +136,7 @@
 
   buffer[8] = '\0';
 }
-*/
+
 
 
 
@@ -177,9 +177,9 @@
   si4703_registers[SYSCONFIG2] |= 0x0001; //Set volume to lowest
 
   // SI AN230 page 40 - Table 23 ('Good Quality Stations Only' Settings)
-  si4703_registers[SYSCONFIG2] |= (0xC<<SEEKTH);
+/***********  si4703_registers[SYSCONFIG2] |= (0xC<<SEEKTH);
   si4703_registers[SYSCONFIG3] |= (0x7<<SKSNR);
-  si4703_registers[SYSCONFIG3] |= (0xF<<SKCNT);
+  si4703_registers[SYSCONFIG3] |= (0xF<<SKCNT);*************/
   ///
   updateRegisters(); //Update
 
diff -r 558ef02f39d0 -r 9ac35cc4a0b0 SparkFun-Si4703.h
--- a/SparkFun-Si4703.h	Sat Aug 08 18:15:36 2015 +0000
+++ b/SparkFun-Si4703.h	Sat Jan 16 19:26:55 2016 +0000
@@ -58,7 +58,7 @@
 	void setVolume(int volume); 	// 0 to 15
     uint8_t getVolume(); 	// Returns The Current Volume (0 .. 15)
 
-/*	void readRDS(char* message, long timeout);	 */
+	void readRDS(char* message, long timeout);	 
 									// message should be at least 9 chars
 									// result will be null terminated
 									// timeout in milliseconds
@@ -96,8 +96,6 @@
 	static const uint16_t  CHANNEL = 0x03;
 	static const uint16_t  SYSCONFIG1 = 0x04;
 	static const uint16_t  SYSCONFIG2 = 0x05;
-	static const uint16_t  SYSCONFIG3 = 0x06;
-	static const uint16_t  TEST1 = 0x07;
 	static const uint16_t  STATUSRSSI = 0x0A;
 	static const uint16_t  READCHAN = 0x0B;
 	static const uint16_t  RDSA = 0x0C;
@@ -114,8 +112,6 @@
 	static const uint16_t  SKMODE = 10;
 	static const uint16_t  SEEKUP = 9;
 	static const uint16_t  SEEK = 8;
-	static const uint16_t  DISABLE = 6;
-	static const uint16_t  ENABLE = 0;
 
 	//Register 0x03 - CHANNEL
 	static const uint16_t  TUNE = 15;
@@ -129,10 +125,6 @@
 	static const uint16_t  SPACE0 = 4;
 	static const uint16_t  SEEKTH = 8;
 
-	//Register 0x06 - SYSCONFIG3
-	static const uint16_t  SKSNR  = 4;
-	static const uint16_t  SKCNT  = 0;
-
 	//Register 0x0A - STATUSRSSI
 	static const uint16_t  RDSR = 15;
 	static const uint16_t  STC = 14;
@@ -141,7 +133,6 @@
 	static const uint16_t  RDSS = 11;
 	static const uint16_t  BLERA = 9;
 	static const uint16_t  STEREO = 8;
-	static const uint16_t  RSSI = 0;
 };
 
 #endif