![](/media/cache/profiles/P1050323.jpg.50x50_q85.jpg)
Nucleo Sequencer of my Base Machine
Dependencies: Amp AverageAnalogIn Envelope FilterController Sequence BaseMachineComon mbed-rtos mbed
Fork of SpiSequenceSender_Test by
Diff: main.cpp
- Revision:
- 0:21e39bc75e31
- Child:
- 1:a9cbde6ba5a5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 30 19:04:42 2016 +0000 @@ -0,0 +1,76 @@ +#include "mbed.h" +#include "Sequence.h" +#include "SequenceSender.h" + +#define SEQUENCE_N 16 + +#define SPI_RATE (8000000) +#define SPI_WAIT (wait_us(1)) +#define DCO_PACKET_HEADER (0x55) +#define DCO_WAVE_FORM (0x00) +#define DCO_PULSE_WIDTH (0x80) + +#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) {} + + 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(DCO_WAVE_FORM); + pSpiM->write(DCO_PULSE_WIDTH); + pSpiM->write(frequency16 >> 8); + pSpiM->write(frequency16 & 0xff); + SPI_WAIT; + DcoCS = 1; + } + +private: + SPI* pSpiM; + DigitalOut DcoCS; +}; + +SPI spiMaster(SPI_MOSI, SPI_MISO, SPI_SCK); + +Sequence sequence[SEQUENCE_N]; +SpiSequenceSender sequenceSender(&spiMaster, D10, sequence, SEQUENCE_N, 100); + +int main() +{ + spiMaster.format(8, 0); + spiMaster.frequency(SPI_RATE); + + // Test SequencerSender Run + // + sequenceSender.setBpm(20); + for (int i = 0; i < SEQUENCE_N; i++) { + Sequence& seq = sequenceSender.getSequences()[i]; + seq.setPitch(0); + seq.setOctave(0); + seq.tie = true; + } + + sequence[3].setOctave(1); + sequence[3].tie = false; + sequence[7].setOctave(1); + sequence[11].setOctave(1); + sequence[11].tie = false; + sequence[15].setOctave(1); + + sequenceSender.run(0); +}