/* Wtv020sd16p - Library to control a WTV020-SD-16P module Created by Diego J. Arevalo, August 6th, 2012 for Arduino plaform Modified by Kamil Kanas, 17/5/2017 for mbed platforms Tested with FRDM KL25Z board Released into the public domain 9/6/2017. */

Dependents:   WTV020SD16_Player_KL25

Files at this revision

API Documentation at this revision

Comitter:
kanatronics
Date:
Fri Jun 09 14:44:23 2017 +0000
Commit message:
/*; Wtv020sd16p - Library to control a WTV020-SD-16P module ; Created by Diego J. Arevalo, August 6th, 2012 for Arduino plaform; Modified by Kamil Kanas, 17/5/2017 for mbed platforms; Tested with FRDM KL25Z board; Released into the public domain 9/7/2...

Changed in this revision

WTV020SD16.cpp Show annotated file Show diff for this revision Revisions of this file
WTV020SD16.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 47be58458737 WTV020SD16.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WTV020SD16.cpp	Fri Jun 09 14:44:23 2017 +0000
@@ -0,0 +1,96 @@
+/*
+ Wtv020sd16p.cpp - Library to control a WTV020-SD-16P module 
+ Created by Diego J. Arevalo, August 6th, 2012 for  Arduino plaform
+ Modified by Kamil Kanas, 17/5/2017 for mbed platforms
+ Tested with FRDM KL25Z board
+ Released into the public domain 9/6/2017.
+ */
+
+#include "mbed.h"
+#include "WTV020SD16.h"
+
+const unsigned int PLAY_PAUSE = 0xFFFE;
+const unsigned int STOP = 0xFFFF;
+const unsigned int VOLUME_MIN = 0xFFF0;
+const unsigned int VOLUME_MAX = 0xFFF7;
+
+/*Pin definition*/
+DigitalOut _resetPin(PTB0);                             //reset pin   Output
+DigitalOut _clockPin(PTB1);                             //clock pin   Output
+DigitalOut _dataPin(PTB2);                              //data pin    Output
+DigitalIn  _busyPin(PTB3);                              //busy pin    Input 
+
+
+
+void Wtv020sd16p::reset(){
+  
+                                                           //Reset pulse.
+  _clockPin=0;
+  _resetPin=1;
+  _resetPin=0;
+  wait_ms(5);
+  _resetPin=1;                                               //Reset idle to start bit. 
+  _clockPin=1;
+  wait_ms(300);
+}
+
+void Wtv020sd16p::playVoice(int voiceNumber){  
+  sendCommand(voiceNumber);
+
+  _busyPinState= _busyPin;
+
+  while(_busyPinState==1){
+    _busyPinState=_busyPin;
+  }
+}
+
+void Wtv020sd16p::asyncPlayVoice(int voiceNumber){
+  sendCommand(voiceNumber);
+}
+
+void Wtv020sd16p::stopVoice(){
+  sendCommand(STOP);
+}
+
+void Wtv020sd16p::pauseVoice(){
+  sendCommand(PLAY_PAUSE);
+}
+
+void Wtv020sd16p::mute(){
+  sendCommand(VOLUME_MIN);
+}
+
+void Wtv020sd16p::unmute(){
+  sendCommand(VOLUME_MAX);
+}
+
+void Wtv020sd16p::sendCommand(unsigned int command) {
+  //Start bit Low level pulse.
+ _clockPin=0;
+  wait_ms(2);
+  for (unsigned int mask = 0x8000; mask > 0; mask >>= 1) {
+    //Clock low level pulse.
+    _clockPin=0;
+    wait_us(50);
+    //Write data setup.
+    if (command & mask) { 
+      _dataPin=1;
+    } else
+     {
+      
+       _dataPin=0;
+     }
+    //Write data hold.
+    wait_us(50);
+    //Clock high level pulse.
+    
+    _clockPin=1;
+    wait_us(100);
+    if (mask>0x0001){
+      //Stop bit high level pulse.
+      wait_ms(2);      
+    }
+  }
+  //Busy active high from last data bit latch.
+  wait_ms(20);
+}
diff -r 000000000000 -r 47be58458737 WTV020SD16.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WTV020SD16.h	Fri Jun 09 14:44:23 2017 +0000
@@ -0,0 +1,32 @@
+/*
+ Wtv020sd16p.cpp - Library to control a WTV020-SD-16P module 
+ Created by Diego J. Arevalo, August 6th, 2012 for  Arduino plaform
+ Modified by Kamil Kanas, 17/5/2017 for mbed platforms
+ Tested with FRDM KL25Z board
+ Released into the public domain 9/7/2017.
+ */
+
+#ifndef WTV020SD16_h
+#define WTV020SD16_h
+#include "mbed.h"
+
+  
+class Wtv020sd16p
+{
+public:
+  void reset();
+  void playVoice(int voiceNumber);
+  void asyncPlayVoice(int voiceNumber);
+  void stopVoice();
+  void pauseVoice();
+  void mute();
+  void unmute();
+private:
+  void sendCommand(unsigned int command);
+  int _busyPinState;
+  
+};
+
+#endif
+
+