シーケンサーのデータをSPIで送るテスト。UART出力停止

Dependencies:   Sequence mbed-rtos mbed Amp Envelope FilterController

Fork of SpiSequencerSender_Test by Ryo Od

Revision:
6:fc10eac60b91
Parent:
5:4abac408b827
Child:
7:ed01846ee0a5
--- a/main.cpp	Sun Jun 12 03:02:22 2016 +0000
+++ b/main.cpp	Thu Jun 23 09:41:18 2016 +0000
@@ -1,79 +1,27 @@
 #include "mbed.h"
 #include "rtos.h"
-#include "Sequence.h"
-#include "SequenceSender.h"
-
-#define SEQUENCE_N  16
-
-#define WAVESHAPE_SQUARE    0
-#define WAVESHAPE_SAW       1
-#define WAVESHAPE_N         2
-
-#define SPI_RATE            (8000000)
-#define SPI_WAIT            (wait_us(1))
-#define DCO_PACKET_HEADER   (0x55)
-
-#define DBG_TRACE   0
-
-class SpiSequenceSender : public SequenceSender {
-public:
-    SpiSequenceSender(SPI* _pSpim, PinName _DcoCS, Sequence* _sequences, int _sequenceNum, int _samplingRate=5, int _bpm=120) :
-        SequenceSender(_sequences, _sequenceNum, _samplingRate, _bpm),
-        pSpiM(_pSpim), DcoCS(_DcoCS), waveShape(WAVESHAPE_SQUARE), pulseWidth(127) {}
 
-    virtual void outDco(uint32_t frequency)
-    {
-        uint16_t frequency16 = frequency >> 16; 
-        
-        #if(DBG_TRACE)        
-        printf("%d\t", frequency16);
-        printf("%d\t", DCO_PACKET_HEADER);
-        printf("%d\t", DCO_WAVE_FORM);
-        printf("%d\t", DCO_PULSE_WIDTH);
-        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;
-    }
-    
-    void setWaveShape(uint8_t _waveShape) {
-        if (_waveShape < WAVESHAPE_N) {
-            waveShape = _waveShape;
-        }
-    }
-    
-    uint8_t getWaveShape() {
-        return waveShape;
-    }
-    
-    void setPulseWidth(uint8_t _pulseWidth) {
-        pulseWidth = _pulseWidth;
-    }
-    
-    uint8_t getPulseWidth() {
-        return pulseWidth;
-    }
+#define UART_TRACE  (0)
+#include "SpiSequenceSender.h"
+#include "Envelope.h"
 
-private:
-    SPI* pSpiM;
-    DigitalOut DcoCS;
-    uint8_t waveShape;
-    uint8_t pulseWidth;
-};
+#define SEQUENCE_N  (16)
+#define SPI_RATE    (8000000)
 
 SPI spiMaster(SPI_MOSI, SPI_MISO, SPI_SCK);
 
 Sequence sequence[SEQUENCE_N];
-SpiSequenceSender sequenceSender(&spiMaster, D10, sequence, SEQUENCE_N, 5);
+SpiSequenceSender sequenceSender(&spiMaster, D9, sequence, SEQUENCE_N, 5);
+
+Envelope envelope(4095, 25, 20, 10, 2047);
+
+class TestClass {
+public:
+    void callbackFunction(int ticks)
+    {
+        printf("%d\r\n", ticks);
+    }    
+} testClass;
 
 int main()
 {
@@ -85,7 +33,7 @@
     sequenceSender.setBpm(120);
     for (int i = 0; i < SEQUENCE_N; i++) {
         Sequence& seq = sequenceSender.getSequences()[i];
-        seq.setPitch(0);
+        seq.setPitch(i);
         seq.setOctave(-1);
         seq.tie = true;
     }
@@ -94,14 +42,16 @@
     sequence[7].setOctave(1);
     sequence[11].setOctave(0);
     sequence[15].setOctave(1);
+    
+    sequenceSender.attach(&testClass, &TestClass::callbackFunction);
 
     sequenceSender.run(0);
     
     for (;;) {
         sequenceSender.setPulseWidth(sequenceSender.getPulseWidth() + 4);
-        Thread::wait(100);
-        sequenceSender.setWaveShape(WAVESHAPE_SAW);
-        Thread::wait(100);
-        sequenceSender.setWaveShape(WAVESHAPE_SQUARE);
+        Thread::wait(500);
+        sequenceSender.setWaveShape(SpiSequenceSender::WAVESHAPE_SAW);
+        Thread::wait(500);
+        sequenceSender.setWaveShape(SpiSequenceSender::WAVESHAPE_SQUARE);
     }
 }