Nucleo SPI Sequencer

Dependencies:   AverageAnalogIn N5110 Nucleo_rtos_UI_Test PinDetect RotaryEncoder Sequence mbed-rtos mbed FilterController

Fork of Nucleo_rtos_UI_Test by Ryo Od

Revision:
3:8c8020dfd82f
Parent:
2:8cc6dff1d7fd
Child:
4:d9a72e07749f
--- a/main.cpp	Wed May 25 07:08:12 2016 +0000
+++ b/main.cpp	Wed May 25 08:14:42 2016 +0000
@@ -16,12 +16,22 @@
 RotaryEncoder RotEnc1(D2, D3, 0, SEQUENCE_N - 1, 0);
 RotaryEncoder RotEnc2(D4, D5, 0, PITCH_MAX, 0);
 
+AnalogIn Pots[] = {
+    AnalogIn(A0),
+    AnalogIn(A1),
+    AnalogIn(A2),
+    AnalogIn(A3),
+    AnalogIn(A4),
+};
+
 PinDetect Pins[] = {
-    PinDetect(D8,  PullUp),
-    PinDetect(D9,  PullUp),
-    PinDetect(D10, PullUp),
-    PinDetect(D11, PullUp),
-    PinDetect(D12, PullUp)
+    PinDetect(PA_13, PullUp),
+    PinDetect(PA_14, PullUp),
+    PinDetect(PA_15, PullUp),
+    PinDetect(PB_7,  PullUp),
+    PinDetect(PC_13, PullUp),
+    PinDetect(PB_10, PullUp),
+    PinDetect(PA_8,  PullUp),
 };
 
 DigitalOut Led1(LED1);
@@ -35,8 +45,10 @@
     bool accent;
 } Sequence[SEQUENCE_N];
 
-int currentNote;
-bool isDirty;
+int currentNote = 0;
+int waveForm = 0;
+bool isRunning = true;
+bool isDirty = true;
 
 void ledThread(void const *argument)
 {
@@ -58,8 +70,9 @@
     Lcd.printString(buff, 0, 2);
     sprintf(buff, "octave: %d" ,Sequence[currentNote].octave);
     Lcd.printString(buff, 0, 3);
-    sprintf(buff, "%d %d %d", 
-        Sequence[currentNote].noteOn, Sequence[currentNote].tie, Sequence[currentNote].accent);
+    sprintf(buff, "%d %d %d %d %d", 
+        Sequence[currentNote].noteOn, Sequence[currentNote].tie, Sequence[currentNote].accent,
+        isRunning, waveForm);
     Lcd.printString(buff, 0, 4);
     Lcd.refresh();
 }
@@ -100,6 +113,38 @@
     printf("swAccentPressed\r\n");
 }
 
+void swRunStopPressed()
+{
+    isRunning = !isRunning;
+    isDirty = true;
+    printf("swRunStopPressed\r\n");
+}
+
+void swWaveFormPressed()
+{
+    waveForm++;
+    isDirty = true;
+    printf("swWaveFormPressed\r\n");
+}
+
+void pollingRotEncs()
+{
+    int _note = RotEnc1.getVal();
+    if (_note != currentNote) {
+        currentNote = _note;
+        isDirty = true;
+    }
+    int _pitch = RotEnc2.getVal();
+    if (_pitch != Sequence[currentNote].pitch) {
+        Sequence[currentNote].pitch = _pitch;
+        isDirty = true;
+    }
+}
+
+void pollingPots()
+{
+}
+
 int main()
 {
     printf("\n\n\r*** RTOS UI Test ***\r\n");
@@ -113,7 +158,9 @@
     Pins[2].attach_asserted(&swNoteOnOffPressed);
     Pins[3].attach_asserted(&swTiePressed);
     Pins[4].attach_asserted(&swAccentPressed);
-    for (int i = 0; i < 5; i++) {
+    Pins[5].attach_asserted(&swRunStopPressed);
+    Pins[6].attach_asserted(&swWaveFormPressed);
+    for (int i = 0; i < 7; i++) {
         Pins[i].setAssertValue(0);
         Pins[i].setSampleFrequency();
     }
@@ -126,18 +173,9 @@
     Thread thread1(ledThread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
     
     // Main loop
-    isDirty = true;
     while (true) {
-        int note = RotEnc1.getVal();
-        if (note != currentNote) {
-            currentNote = note;
-            isDirty = true;
-        }
-        int pitch = RotEnc2.getVal();
-        if (pitch != Sequence[currentNote].pitch) {
-            Sequence[currentNote].pitch = pitch;
-            isDirty = true;
-        }
+        pollingRotEncs();
+        pollingPots();
         if (isDirty) {
             updateLCD();
             isDirty = false;