MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
touch_interface.h@18:881b5f2975bc, 2014-02-24 (annotated)
- Committer:
- MetropoliaMies
- Date:
- Mon Feb 24 11:14:08 2014 +0000
- Revision:
- 18:881b5f2975bc
- Parent:
- 16:f4d090f1e6ed
PowerControl lis?tty, slider v?ritys ei toimi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vekotin | 15:c297064a829b | 1 | #include "touch_tft.h" |
Vekotin | 15:c297064a829b | 2 | #include "SPI_TFT_ILI9341.h" |
Vekotin | 15:c297064a829b | 3 | #include "USBMIDI.h" |
MetropoliaMies | 16:f4d090f1e6ed | 4 | #include "PowerControl/PowerControl.h" |
MetropoliaMies | 16:f4d090f1e6ed | 5 | #include "PowerControl/EthernetPowerControl.h" |
MetropoliaMies | 16:f4d090f1e6ed | 6 | |
MetropoliaMies | 16:f4d090f1e6ed | 7 | // Function to power down magic USB interface chip with new firmware |
MetropoliaMies | 16:f4d090f1e6ed | 8 | #define USR_POWERDOWN (0x104) |
MetropoliaMies | 16:f4d090f1e6ed | 9 | int semihost_powerdown() { |
MetropoliaMies | 16:f4d090f1e6ed | 10 | uint32_t arg; |
MetropoliaMies | 16:f4d090f1e6ed | 11 | return __semihost(USR_POWERDOWN, &arg); |
MetropoliaMies | 16:f4d090f1e6ed | 12 | } |
MetropoliaMies | 16:f4d090f1e6ed | 13 | |
MetropoliaMies | 16:f4d090f1e6ed | 14 | void powerdown(void) |
MetropoliaMies | 16:f4d090f1e6ed | 15 | { |
MetropoliaMies | 16:f4d090f1e6ed | 16 | |
MetropoliaMies | 16:f4d090f1e6ed | 17 | PHY_PowerDown(); |
MetropoliaMies | 16:f4d090f1e6ed | 18 | semihost_powerdown(); |
MetropoliaMies | 16:f4d090f1e6ed | 19 | //Peripheral_PowerDown(0xFFFF7FFF); |
MetropoliaMies | 16:f4d090f1e6ed | 20 | |
MetropoliaMies | 16:f4d090f1e6ed | 21 | PHY_PowerDown(); //Ethernet disabled |
MetropoliaMies | 16:f4d090f1e6ed | 22 | semihost_powerdown(); //USB disabled |
MetropoliaMies | 16:f4d090f1e6ed | 23 | Peripheral_PowerDown(0x80080); //Unused I2C disabled |
MetropoliaMies | 16:f4d090f1e6ed | 24 | |
MetropoliaMies | 16:f4d090f1e6ed | 25 | } |
Vekotin | 15:c297064a829b | 26 | |
Vekotin | 15:c297064a829b | 27 | // short slider = 8192; |
Vekotin | 15:c297064a829b | 28 | extern unsigned short Oct = 36; //default octave C1 |
Vekotin | 15:c297064a829b | 29 | |
Vekotin | 15:c297064a829b | 30 | // the TFT is connected to SPI pin 5-7 |
Vekotin | 15:c297064a829b | 31 | // the touch is connected to 19,20,17,18 |
Vekotin | 15:c297064a829b | 32 | touch_tft tft(p20,p19,p18,p17,p5, p6, p7, p14, p15, p21, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc |
Vekotin | 15:c297064a829b | 33 | DigitalIn key[9] = {p22, p23, p24, p25, p26, p27, p28, p29, p30}; //inputit |
Vekotin | 15:c297064a829b | 34 | |
Vekotin | 15:c297064a829b | 35 | unsigned char i; |
Vekotin | 15:c297064a829b | 36 | bool pressed_keys[9] = {0}; |
Vekotin | 15:c297064a829b | 37 | |
Vekotin | 15:c297064a829b | 38 | USBMIDI midi; |
Vekotin | 15:c297064a829b | 39 | |
Vekotin | 15:c297064a829b | 40 | void Nine_keys(void) |
Vekotin | 15:c297064a829b | 41 | { |
Vekotin | 15:c297064a829b | 42 | for (i = 0; i < 9; i++) { |
Vekotin | 15:c297064a829b | 43 | if (!key[i].read() & !pressed_keys[i]) { |
Vekotin | 15:c297064a829b | 44 | midi.write(MIDIMessage::NoteOn(Oct + i)); |
Vekotin | 15:c297064a829b | 45 | pressed_keys[i] = true; |
Vekotin | 15:c297064a829b | 46 | } |
Vekotin | 15:c297064a829b | 47 | if (key[i].read() & pressed_keys[i]) { |
Vekotin | 15:c297064a829b | 48 | midi.write(MIDIMessage::NoteOff(Oct + i)); |
Vekotin | 15:c297064a829b | 49 | pressed_keys[i] = false; |
Vekotin | 15:c297064a829b | 50 | } |
Vekotin | 15:c297064a829b | 51 | } |
Vekotin | 15:c297064a829b | 52 | } |
Vekotin | 15:c297064a829b | 53 | |
Vekotin | 15:c297064a829b | 54 | void Buttons(unsigned char b, unsigned short color) //Button Field |
Vekotin | 15:c297064a829b | 55 | { |
Vekotin | 15:c297064a829b | 56 | if (b == 1) { //Slider |
Vekotin | 15:c297064a829b | 57 | tft.fillrect(3,96,78,318,color); |
Vekotin | 15:c297064a829b | 58 | } |
Vekotin | 15:c297064a829b | 59 | if (b == 2) { //Octave Reset |
Vekotin | 15:c297064a829b | 60 | tft.fillrect(163,163,238,238,color); |
Vekotin | 15:c297064a829b | 61 | } |
Vekotin | 15:c297064a829b | 62 | if (b == 3) { //Octave DOWN |
Vekotin | 15:c297064a829b | 63 | tft.fillrect(83,243,158,318,color); |
MetropoliaMies | 16:f4d090f1e6ed | 64 | tft.locate(90,275); |
MetropoliaMies | 16:f4d090f1e6ed | 65 | tft.foreground(Black); |
MetropoliaMies | 16:f4d090f1e6ed | 66 | tft.background(White); |
MetropoliaMies | 16:f4d090f1e6ed | 67 | printf("DOWN"); |
MetropoliaMies | 16:f4d090f1e6ed | 68 | tft.foreground(White); |
MetropoliaMies | 16:f4d090f1e6ed | 69 | tft.background(Black); |
MetropoliaMies | 16:f4d090f1e6ed | 70 | |
Vekotin | 15:c297064a829b | 71 | } |
Vekotin | 15:c297064a829b | 72 | if (b == 4) { //Octave UP |
Vekotin | 15:c297064a829b | 73 | tft.fillrect(163,243,238,318,color); |
MetropoliaMies | 16:f4d090f1e6ed | 74 | tft.locate(170,275); |
MetropoliaMies | 16:f4d090f1e6ed | 75 | tft.foreground(Black); |
MetropoliaMies | 16:f4d090f1e6ed | 76 | tft.background(White); |
MetropoliaMies | 16:f4d090f1e6ed | 77 | printf("UP"); |
MetropoliaMies | 16:f4d090f1e6ed | 78 | tft.foreground(White); |
MetropoliaMies | 16:f4d090f1e6ed | 79 | tft.background(Black); |
Vekotin | 15:c297064a829b | 80 | } |
Vekotin | 15:c297064a829b | 81 | } |
Vekotin | 15:c297064a829b | 82 | |
Vekotin | 15:c297064a829b | 83 | void Draw_buttons(unsigned short color) //Draws Button Field |
Vekotin | 15:c297064a829b | 84 | { |
Vekotin | 15:c297064a829b | 85 | unsigned char i = 0; |
Vekotin | 15:c297064a829b | 86 | |
Vekotin | 15:c297064a829b | 87 | for (i = 0; i<5; i++) { |
Vekotin | 15:c297064a829b | 88 | //tft.locate(10,50); |
Vekotin | 15:c297064a829b | 89 | Buttons(i, color); |
Vekotin | 15:c297064a829b | 90 | } |
Vekotin | 15:c297064a829b | 91 | } |
Vekotin | 15:c297064a829b | 92 | |
MetropoliaMies | 16:f4d090f1e6ed | 93 | |
MetropoliaMies | 16:f4d090f1e6ed | 94 | |
Vekotin | 15:c297064a829b | 95 | void Slider_action(point p) |
Vekotin | 15:c297064a829b | 96 | { |
Vekotin | 15:c297064a829b | 97 | if (p.x > 3 && p.x < 78) { //Slider |
Vekotin | 15:c297064a829b | 98 | if (p.y > 88 && p.y < 111) { |
MetropoliaMies | 16:f4d090f1e6ed | 99 | tft.fillrect(3,88,78,111,Red); |
Vekotin | 15:c297064a829b | 100 | midi.write(MIDIMessage::PitchWheel(8192)); |
Vekotin | 15:c297064a829b | 101 | } |
Vekotin | 15:c297064a829b | 102 | if (p.y > 111 && p.y < 134) { |
MetropoliaMies | 16:f4d090f1e6ed | 103 | tft.fillrect(3,111,78,134,Red); |
Vekotin | 15:c297064a829b | 104 | midi.write(MIDIMessage::PitchWheel(6400)); |
Vekotin | 15:c297064a829b | 105 | } |
Vekotin | 15:c297064a829b | 106 | if (p.y > 134 && p.y < 157) { |
MetropoliaMies | 16:f4d090f1e6ed | 107 | tft.fillrect(3,111,78,157,Red); |
Vekotin | 15:c297064a829b | 108 | midi.write(MIDIMessage::PitchWheel(4915)); |
Vekotin | 15:c297064a829b | 109 | } |
Vekotin | 15:c297064a829b | 110 | if (p.y > 157 && p.y < 180) { |
MetropoliaMies | 16:f4d090f1e6ed | 111 | tft.fillrect(3,111,78,180,Red); |
Vekotin | 15:c297064a829b | 112 | midi.write(MIDIMessage::PitchWheel(3277)); |
Vekotin | 15:c297064a829b | 113 | } |
Vekotin | 15:c297064a829b | 114 | if (p.y > 180 && p.y < 203) { |
MetropoliaMies | 16:f4d090f1e6ed | 115 | tft.fillrect(3,111,78,203,Red); |
Vekotin | 15:c297064a829b | 116 | midi.write(MIDIMessage::PitchWheel(1638)); |
Vekotin | 15:c297064a829b | 117 | } |
Vekotin | 15:c297064a829b | 118 | if (p.y > 203 && p.y < 226) { |
MetropoliaMies | 16:f4d090f1e6ed | 119 | tft.fillrect(3,111,78,226,Red); |
Vekotin | 15:c297064a829b | 120 | midi.write(MIDIMessage::PitchWheel(0)); |
Vekotin | 15:c297064a829b | 121 | } |
Vekotin | 15:c297064a829b | 122 | if (p.y > 226 && p.y < 249) { |
MetropoliaMies | 16:f4d090f1e6ed | 123 | tft.fillrect(3,111,78,249,Red); |
Vekotin | 15:c297064a829b | 124 | midi.write(MIDIMessage::PitchWheel(-1638)); |
Vekotin | 15:c297064a829b | 125 | } |
Vekotin | 15:c297064a829b | 126 | if (p.y > 249 && p.y < 272) { |
MetropoliaMies | 16:f4d090f1e6ed | 127 | tft.fillrect(3,111,78,272,Red); |
Vekotin | 15:c297064a829b | 128 | midi.write(MIDIMessage::PitchWheel(-3277)); |
Vekotin | 15:c297064a829b | 129 | } |
Vekotin | 15:c297064a829b | 130 | if (p.y > 272 && p.y < 295) { |
MetropoliaMies | 16:f4d090f1e6ed | 131 | tft.fillrect(3,111,78,295,Red); |
Vekotin | 15:c297064a829b | 132 | midi.write(MIDIMessage::PitchWheel(-4915)); |
Vekotin | 15:c297064a829b | 133 | } |
Vekotin | 15:c297064a829b | 134 | if (p.y > 295 && p.y < 318) { |
MetropoliaMies | 16:f4d090f1e6ed | 135 | tft.fillrect(3,111,78,318,Red); |
Vekotin | 15:c297064a829b | 136 | midi.write(MIDIMessage::PitchWheel(-8192)); |
Vekotin | 15:c297064a829b | 137 | } |
Vekotin | 15:c297064a829b | 138 | } |
Vekotin | 15:c297064a829b | 139 | } |
Vekotin | 15:c297064a829b | 140 | |
Vekotin | 15:c297064a829b | 141 | |
Vekotin | 15:c297064a829b | 142 | void Octave_buttons(unsigned short color, point p) |
Vekotin | 15:c297064a829b | 143 | { |
Vekotin | 15:c297064a829b | 144 | if (p.y > 243 && p.y < 318) { //ROW C |
Vekotin | 15:c297064a829b | 145 | if (p.x > 83 && p.x < 158) { //Octave down |
Vekotin | 15:c297064a829b | 146 | Buttons(3, color); |
Vekotin | 15:c297064a829b | 147 | Oct -= 12; |
MetropoliaMies | 16:f4d090f1e6ed | 148 | tft.locate(90,275); |
MetropoliaMies | 16:f4d090f1e6ed | 149 | tft.foreground(Black); |
MetropoliaMies | 16:f4d090f1e6ed | 150 | tft.background(Red); |
MetropoliaMies | 16:f4d090f1e6ed | 151 | printf("Down"); |
MetropoliaMies | 16:f4d090f1e6ed | 152 | tft.foreground(Black); |
MetropoliaMies | 16:f4d090f1e6ed | 153 | tft.background(White); |
Vekotin | 15:c297064a829b | 154 | wait(0.2); |
Vekotin | 15:c297064a829b | 155 | Buttons(3, White); |
Vekotin | 15:c297064a829b | 156 | } |
Vekotin | 15:c297064a829b | 157 | if (p.x > 163 && p.x < 238) { //Octave up |
Vekotin | 15:c297064a829b | 158 | Buttons(4, color); |
Vekotin | 15:c297064a829b | 159 | Oct += 12; |
MetropoliaMies | 16:f4d090f1e6ed | 160 | tft.locate(170,275); |
MetropoliaMies | 16:f4d090f1e6ed | 161 | tft.foreground(Black); |
MetropoliaMies | 16:f4d090f1e6ed | 162 | tft.background(Red); |
MetropoliaMies | 16:f4d090f1e6ed | 163 | printf("UP"); |
MetropoliaMies | 16:f4d090f1e6ed | 164 | tft.foreground(Black); |
MetropoliaMies | 16:f4d090f1e6ed | 165 | tft.background(White); |
Vekotin | 15:c297064a829b | 166 | wait(0.2); |
Vekotin | 15:c297064a829b | 167 | Buttons(4, White); |
MetropoliaMies | 16:f4d090f1e6ed | 168 | |
Vekotin | 15:c297064a829b | 169 | } |
Vekotin | 15:c297064a829b | 170 | } |
Vekotin | 15:c297064a829b | 171 | |
Vekotin | 15:c297064a829b | 172 | if (p.y > 163 && p.y < 238) { //ROW B |
Vekotin | 15:c297064a829b | 173 | if (p.x > 163 && p.x < 238) { //Octave reset |
Vekotin | 15:c297064a829b | 174 | Oct = 36; |
Vekotin | 15:c297064a829b | 175 | Buttons(2, Cyan); |
Vekotin | 15:c297064a829b | 176 | wait(0.2); |
Vekotin | 15:c297064a829b | 177 | Buttons(2, White); |
Vekotin | 15:c297064a829b | 178 | } |
Vekotin | 15:c297064a829b | 179 | } |
Vekotin | 15:c297064a829b | 180 | |
Vekotin | 15:c297064a829b | 181 | if (Oct > 120) Oct -=12; //Octave range 12-120. |
Vekotin | 15:c297064a829b | 182 | if (Oct < 12) Oct +=12; |
Vekotin | 15:c297064a829b | 183 | } |
Vekotin | 15:c297064a829b | 184 | |
Vekotin | 15:c297064a829b | 185 | |
Vekotin | 15:c297064a829b | 186 |