Subversion Repositories svn.mios32

Rev

Rev 1118 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
713 tk 1
// $Id: app.c 713 2009-08-16 15:50:20Z tk $
2
/*
3
 * MIOS32 Tutorial #025: SysEx Parser and EEPROM Emulation
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
8
 *  Licensed for personal non-commercial use only.
9
 *  All other rights reserved.
10
 *
11
 * ==========================================================================
12
 */
13
 
14
/////////////////////////////////////////////////////////////////////////////
15
// Include files
16
/////////////////////////////////////////////////////////////////////////////
17
 
18
#include <mios32.h>
19
#include "app.h"
20
 
21
#include "patch.h"
22
#include "sysex.h"
23
 
24
#include <FreeRTOS.h>
25
#include <portmacro.h>
26
 
27
#include <eeprom.h>
28
 
29
 
30
/////////////////////////////////////////////////////////////////////////////
31
// Global Variables
32
/////////////////////////////////////////////////////////////////////////////
33
 
34
volatile u8 patch;
35
volatile u8 bank;
36
volatile u8 print_msg;
37
 
38
 
39
/////////////////////////////////////////////////////////////////////////////
40
// This hook is called after startup to initialize the application
41
/////////////////////////////////////////////////////////////////////////////
42
void APP_Init(void)
43
{
44
  s32 i;
45
 
46
  // initialize all LEDs
47
  MIOS32_BOARD_LED_Init(0xffffffff);
48
 
49
  // initialise SysEx parser
50
  SYSEX_Init(0);
51
 
52
  // initialize patch structure
53
  PATCH_Init(0);
54
 
55
  // init local patch/bank
56
  patch = bank = 0;
57
 
58
  // print first message
59
  print_msg = PRINT_MSG_INIT;
60
}
61
 
62
 
63
/////////////////////////////////////////////////////////////////////////////
64
// This task is running endless in background
65
/////////////////////////////////////////////////////////////////////////////
66
void APP_Background(void)
67
{
68
  // clear LCD screen
69
  MIOS32_LCD_Clear();
70
 
71
  // endless loop: print status information on LCD
72
  while( 1 ) {
73
    // toggle the state of all LEDs (allows to measure the execution speed with a scope)
74
    MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get());
75
 
76
    // new message requested?
77
    // TODO: add FreeRTOS specific queue handling!
78
    u8 new_msg = PRINT_MSG_NONE;
79
    portENTER_CRITICAL(); // port specific FreeRTOS function to disable IRQs (nested)
80
    if( print_msg ) {
81
      new_msg = print_msg;
82
      print_msg = PRINT_MSG_NONE; // clear request
83
    }
84
    portEXIT_CRITICAL(); // port specific FreeRTOS function to enable IRQs (nested)
85
 
86
    switch( new_msg ) {
87
      case PRINT_MSG_INIT:
88
        MIOS32_LCD_CursorSet(0, 0);
89
        MIOS32_LCD_PrintString("see README.txt   ");
90
        MIOS32_LCD_CursorSet(0, 1);
91
        MIOS32_LCD_PrintString("for details     ");
92
    break;
93
 
94
      case PRINT_MSG_PATCH_AND_BANK:
95
        MIOS32_LCD_CursorSet(0, 0);
96
        MIOS32_LCD_PrintFormattedString("Patch: %3d B:%d%c ", patch, bank, MIOS32_IIC_BS_CheckAvailable(bank) ? ' ' : '*');
97
        MIOS32_LCD_CursorSet(0, 1);
98
        MIOS32_LCD_PrintString("                ");
99
    break;
100
 
101
      case PRINT_MSG_DUMP_SENT:
102
        MIOS32_LCD_CursorSet(0, 0);
103
        MIOS32_LCD_PrintFormattedString("Patch: %3d B:%d%c ", patch, bank, MIOS32_IIC_BS_CheckAvailable(bank) ? ' ' : '*');
104
        MIOS32_LCD_CursorSet(0, 1);
105
        MIOS32_LCD_PrintString("Dump sent!      ");
106
    break;
107
 
108
      case PRINT_MSG_DUMP_RECEIVED:
109
        MIOS32_LCD_CursorSet(0, 0);
110
        MIOS32_LCD_PrintFormattedString("Patch: %3d B:%d%c ", patch, bank, MIOS32_IIC_BS_CheckAvailable(bank) ? ' ' : '*');
111
        MIOS32_LCD_CursorSet(0, 1);
112
        MIOS32_LCD_PrintString("Dump received!  ");
113
    break;
114
    }
115
  }
116
}
117
 
118
 
119
/////////////////////////////////////////////////////////////////////////////
120
// This hook is called when a MIDI package has been received
121
/////////////////////////////////////////////////////////////////////////////
122
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
123
{
124
#if 0
125
  EEPROM_Init(0);
126
  // optional for debugging: send EEPROM and flash content when a note is played
127
  if( midi_package.type == NoteOn && midi_package.velocity > 0 )
128
    EEPROM_SendDebugMessage(2);
129
#endif
130
}
131
 
132
 
133
/////////////////////////////////////////////////////////////////////////////
134
// This hook is called before the shift register chain is scanned
135
/////////////////////////////////////////////////////////////////////////////
136
void APP_SRIO_ServicePrepare(void)
137
{
138
}
139
 
140
 
141
/////////////////////////////////////////////////////////////////////////////
142
// This hook is called after the shift register chain has been scanned
143
/////////////////////////////////////////////////////////////////////////////
144
void APP_SRIO_ServiceFinish(void)
145
{
146
}
147
 
148
 
149
/////////////////////////////////////////////////////////////////////////////
150
// This hook is called when a button has been toggled
151
// pin_value is 1 when button released, and 0 when button pressed
152
/////////////////////////////////////////////////////////////////////////////
153
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
154
{
155
  // ignore if button has been depressed
156
  if( pin_value )
157
    return;
158
 
159
  // call function depending on button number
160
  switch( pin ) {
161
    case DIN_NUMBER_EXEC: // Exec button
162
      // load patch (again)
163
      PATCH_Load(bank, patch);
164
 
165
      // send dump
166
      SYSEX_Send(DEFAULT, bank, patch);
167
 
168
      // print patch as temporary message + print "Dump sent"
169
      print_msg = PRINT_MSG_DUMP_SENT;
170
      break;
171
 
172
    case DIN_NUMBER_INC: // Inc button
173
      // increment patch, wrap on overflow
174
      if( ++patch >= 0x80 )
175
    patch = 0x00;
176
 
177
      // load patch
178
      PATCH_Load(bank, patch);
179
 
180
      // print patch as temporary message
181
      print_msg = PRINT_MSG_PATCH_AND_BANK;
182
      break;
183
 
184
    case DIN_NUMBER_DEC: // Dec button
185
      // decrement patch, wrap on underflow
186
      if( --patch >= 0x80 ) // patch is an unsigned number...
187
    patch = 0x7f;
188
 
189
      // load patch
190
      PATCH_Load(bank, patch);
191
 
192
      // print patch as temporary message
193
      print_msg = PRINT_MSG_PATCH_AND_BANK;
194
      break;
195
 
196
    case DIN_NUMBER_SNAPSHOT: // Snapshot button
197
      // increment bank, wrap at 8
198
      if( ++bank >= 8 )
199
    bank = 0;
200
 
201
      // load patch
202
      PATCH_Load(bank, patch);
203
 
204
      // print patch as temporary message
205
      print_msg = PRINT_MSG_PATCH_AND_BANK;
206
      break;
207
  }
208
}
209
 
210
 
211
/////////////////////////////////////////////////////////////////////////////
212
// This hook is called when an encoder has been moved
213
// incrementer is positive when encoder has been turned clockwise, else
214
// it is negative
215
/////////////////////////////////////////////////////////////////////////////
216
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
217
{
218
}
219
 
220
 
221
/////////////////////////////////////////////////////////////////////////////
222
// This hook is called when a pot has been moved
223
/////////////////////////////////////////////////////////////////////////////
224
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
225
{
226
}