BaseMachine OscController Library

Revision:
0:d941144b13db
Child:
1:d3217569b33e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpiOscController.h	Mon Feb 13 16:00:16 2017 +0000
@@ -0,0 +1,54 @@
+/*
+ * BaseMachine SpiOscController
+ *
+ * mbed Rev 121 / mbed-rtos Rev 117
+ * 
+ * 2017.02.13
+ *
+ */
+#ifndef _SPI_OSC_CONTROLLER_H_
+#define _SPI_OSC_CONTROLLER_H_
+
+#include "mbed.h"
+#include "OscController.h"
+
+#define DCO_PACKET_HEADER   (0x55)
+#define SPI_WAIT            (wait_us(1))
+
+class SpiOscController : public OscController {
+public:
+    SpiOscController(SPI* _pSpim, PinName _DcoCS, uint8_t _waveShape=WAVESHAPE_SQUARE, uint8_t _pulseWidth=127) :
+        OscController(_waveShape, _pulseWidth),
+        pSpiM(_pSpim),
+        DcoCS(_DcoCS, 1) {}
+        
+    virtual void outDco(uint32_t frequency)
+    {
+        uint16_t frequency16 = frequency >> 16; 
+        
+        #if(UART_TRACE)        
+        printf("%d\t", frequency16);
+        printf("%d\t", DCO_PACKET_HEADER);
+        printf("%d\t", waveShape);
+        printf("%d\t", pulseWidth);
+        printf("%d\t", frequency16 >> 8);
+        printf("%d\t", frequency16 & 0xff);
+        printf("\r\n");
+        #endif
+        
+        DcoCS = 0;
+        pSpiM->write(DCO_PACKET_HEADER);
+        pSpiM->write(waveShape);
+        pSpiM->write(pulseWidth);
+        pSpiM->write(frequency16 >> 8);
+        pSpiM->write(frequency16 & 0xff);
+        SPI_WAIT;
+        DcoCS = 1;
+    }
+    
+private:
+    SPI* pSpiM;
+    DigitalOut DcoCS;
+};
+
+#endif //_SPI_OSC_CONTROLLER_H_