Subversion Repositories svn.mios32

Rev

Rev 1919 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
713 tk 1
// $Id: app.c 1920 2014-01-08 19:29:35Z 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
  // initialize all LEDs
45
  MIOS32_BOARD_LED_Init(0xffffffff);
46
 
47
  // initialise SysEx parser
48
  SYSEX_Init(0);
49
 
50
  // initialize patch structure
51
  PATCH_Init(0);
52
 
53
  // init local patch/bank
54
  patch = bank = 0;
55
 
56
  // print first message
57
  print_msg = PRINT_MSG_INIT;
58
}
59
 
60
 
61
/////////////////////////////////////////////////////////////////////////////
62
// This task is running endless in background
63
/////////////////////////////////////////////////////////////////////////////
64
void APP_Background(void)
65
{
66
  // clear LCD screen
67
  MIOS32_LCD_Clear();
68
 
69
  // endless loop: print status information on LCD
70
  while( 1 ) {
71
    // new message requested?
72
    // TODO: add FreeRTOS specific queue handling!
73
    u8 new_msg = PRINT_MSG_NONE;
74
    portENTER_CRITICAL(); // port specific FreeRTOS function to disable IRQs (nested)
75
    if( print_msg ) {
76
      new_msg = print_msg;
77
      print_msg = PRINT_MSG_NONE; // clear request
78
    }
79
    portEXIT_CRITICAL(); // port specific FreeRTOS function to enable IRQs (nested)
80
 
81
    switch( new_msg ) {
82
      case PRINT_MSG_INIT:
83
        MIOS32_LCD_CursorSet(0, 0);
84
        MIOS32_LCD_PrintString("see README.txt   ");
85
        MIOS32_LCD_CursorSet(0, 1);
86
        MIOS32_LCD_PrintString("for details     ");
87
    break;
88
 
89
      case PRINT_MSG_PATCH_AND_BANK:
90
        MIOS32_LCD_CursorSet(0, 0);
91
        MIOS32_LCD_PrintFormattedString("Patch: %3d B:%d%c ", patch, bank, MIOS32_IIC_BS_CheckAvailable(bank) ? ' ' : '*');
92
        MIOS32_LCD_CursorSet(0, 1);
93
        MIOS32_LCD_PrintString("                ");
94
    break;
95
 
96
      case PRINT_MSG_DUMP_SENT:
97
        MIOS32_LCD_CursorSet(0, 0);
98
        MIOS32_LCD_PrintFormattedString("Patch: %3d B:%d%c ", patch, bank, MIOS32_IIC_BS_CheckAvailable(bank) ? ' ' : '*');
99
        MIOS32_LCD_CursorSet(0, 1);
100
        MIOS32_LCD_PrintString("Dump sent!      ");
101
    break;
102
 
103
      case PRINT_MSG_DUMP_RECEIVED:
104
        MIOS32_LCD_CursorSet(0, 0);
105
        MIOS32_LCD_PrintFormattedString("Patch: %3d B:%d%c ", patch, bank, MIOS32_IIC_BS_CheckAvailable(bank) ? ' ' : '*');
106
        MIOS32_LCD_CursorSet(0, 1);
107
        MIOS32_LCD_PrintString("Dump received!  ");
108
    break;
109
    }
110
  }
111
}
112
 
113
 
114
/////////////////////////////////////////////////////////////////////////////
1919 tk 115
// This hook is called each mS from the main task which also handles DIN, ENC
116
// and AIN events. You could add more jobs here, but they shouldn't consume
117
// more than 300 uS to ensure the responsiveness of buttons, encoders, pots.
118
// Alternatively you could create a dedicated task for application specific
119
// jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks
120
/////////////////////////////////////////////////////////////////////////////
121
void APP_Tick(void)
122
{
1920 tk 123
  // PWM modulate the status LED (this is a sign of life)
124
  u32 timestamp = MIOS32_TIMESTAMP_Get();
125
  MIOS32_BOARD_LED_Set(1, (timestamp % 20) <= ((timestamp / 100) % 10));
1919 tk 126
}
127
 
128
 
129
/////////////////////////////////////////////////////////////////////////////
130
// This hook is called each mS from the MIDI task which checks for incoming
131
// MIDI events. You could add more MIDI related jobs here, but they shouldn't
132
// consume more than 300 uS to ensure the responsiveness of incoming MIDI.
133
/////////////////////////////////////////////////////////////////////////////
134
void APP_MIDI_Tick(void)
135
{
136
}
137
 
138
 
139
/////////////////////////////////////////////////////////////////////////////
713 tk 140
// This hook is called when a MIDI package has been received
141
/////////////////////////////////////////////////////////////////////////////
142
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
143
{
144
#if 0
145
  EEPROM_Init(0);
146
  // optional for debugging: send EEPROM and flash content when a note is played
147
  if( midi_package.type == NoteOn && midi_package.velocity > 0 )
148
    EEPROM_SendDebugMessage(2);
149
#endif
150
}
151
 
152
 
153
/////////////////////////////////////////////////////////////////////////////
154
// This hook is called before the shift register chain is scanned
155
/////////////////////////////////////////////////////////////////////////////
156
void APP_SRIO_ServicePrepare(void)
157
{
158
}
159
 
160
 
161
/////////////////////////////////////////////////////////////////////////////
162
// This hook is called after the shift register chain has been scanned
163
/////////////////////////////////////////////////////////////////////////////
164
void APP_SRIO_ServiceFinish(void)
165
{
166
}
167
 
168
 
169
/////////////////////////////////////////////////////////////////////////////
170
// This hook is called when a button has been toggled
171
// pin_value is 1 when button released, and 0 when button pressed
172
/////////////////////////////////////////////////////////////////////////////
173
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
174
{
175
  // ignore if button has been depressed
176
  if( pin_value )
177
    return;
178
 
179
  // call function depending on button number
180
  switch( pin ) {
181
    case DIN_NUMBER_EXEC: // Exec button
182
      // load patch (again)
183
      PATCH_Load(bank, patch);
184
 
185
      // send dump
186
      SYSEX_Send(DEFAULT, bank, patch);
187
 
188
      // print patch as temporary message + print "Dump sent"
189
      print_msg = PRINT_MSG_DUMP_SENT;
190
      break;
191
 
192
    case DIN_NUMBER_INC: // Inc button
193
      // increment patch, wrap on overflow
194
      if( ++patch >= 0x80 )
195
    patch = 0x00;
196
 
197
      // load patch
198
      PATCH_Load(bank, patch);
199
 
200
      // print patch as temporary message
201
      print_msg = PRINT_MSG_PATCH_AND_BANK;
202
      break;
203
 
204
    case DIN_NUMBER_DEC: // Dec button
205
      // decrement patch, wrap on underflow
206
      if( --patch >= 0x80 ) // patch is an unsigned number...
207
    patch = 0x7f;
208
 
209
      // load patch
210
      PATCH_Load(bank, patch);
211
 
212
      // print patch as temporary message
213
      print_msg = PRINT_MSG_PATCH_AND_BANK;
214
      break;
215
 
216
    case DIN_NUMBER_SNAPSHOT: // Snapshot button
217
      // increment bank, wrap at 8
218
      if( ++bank >= 8 )
219
    bank = 0;
220
 
221
      // load patch
222
      PATCH_Load(bank, patch);
223
 
224
      // print patch as temporary message
225
      print_msg = PRINT_MSG_PATCH_AND_BANK;
226
      break;
227
  }
228
}
229
 
230
 
231
/////////////////////////////////////////////////////////////////////////////
232
// This hook is called when an encoder has been moved
233
// incrementer is positive when encoder has been turned clockwise, else
234
// it is negative
235
/////////////////////////////////////////////////////////////////////////////
236
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
237
{
238
}
239
 
240
 
241
/////////////////////////////////////////////////////////////////////////////
242
// This hook is called when a pot has been moved
243
/////////////////////////////////////////////////////////////////////////////
244
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
245
{
246
}