Subversion Repositories svn.mios32

Rev

Rev 1903 | Rev 1911 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1298 tk 1
// $Id: app.cpp 1905 2013-12-31 15:32:24Z tk $
2
/*
3
 * MIDIbox CV V2
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2011 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 <aout.h>
1887 tk 20
#include <glcd_font.h>
1334 tk 21
#include "tasks.h"
1298 tk 22
#include "app.h"
1334 tk 23
#include "MbCvEnvironment.h"
1298 tk 24
 
1334 tk 25
#include <file.h>
26
 
27
// include source of the SCS
28
#include <scs.h>
1887 tk 29
#include <scs_lcd.h>
1334 tk 30
#include "scs_config.h"
31
 
1492 tk 32
#include <midi_port.h>
33
#include <midi_router.h>
34
#include <midimon.h>
35
 
1895 tk 36
#include <app_lcd.h>
37
 
38
#include "terminal.h"
1298 tk 39
#include "mbcv_sysex.h"
40
#include "mbcv_patch.h"
1299 tk 41
#include "mbcv_map.h"
1901 tk 42
#include "mbcv_lre.h"
1298 tk 43
#include "mbcv_file.h"
44
#include "mbcv_file_p.h"
1453 tk 45
#include "mbcv_file_b.h"
1298 tk 46
#include "uip_task.h"
47
#include "osc_client.h"
48
 
1895 tk 49
 
1298 tk 50
/////////////////////////////////////////////////////////////////////////////
1334 tk 51
// for optional debugging messages via DEBUG_MSG (defined in mios32_config.h)
52
// should be at least 1 for sending error messages
1298 tk 53
/////////////////////////////////////////////////////////////////////////////
1334 tk 54
#define DEBUG_VERBOSE_LEVEL 2
1298 tk 55
 
1334 tk 56
// measure performance with the stopwatch
1903 tk 57
// 0: off
58
// 1: CV processing only
59
// 2: CV processing + mapping
1394 tk 60
//#define STOPWATCH_PERFORMANCE_MEASURING 2
1817 tk 61
#define STOPWATCH_PERFORMANCE_MEASURING 0
1298 tk 62
 
1903 tk 63
// output execution times at J5B:A4..A7
64
// 0: off
65
// 1: on -> J5.A4: CV processing (low-active)
66
//          J5.A5: CV processing + mapping (low-active)
67
//          J5.A6: Scope output (low-active)
1298 tk 68
 
1903 tk 69
#define J5_DEBUG_PINS 1
70
 
71
 
1298 tk 72
/////////////////////////////////////////////////////////////////////////////
73
// local variables
74
/////////////////////////////////////////////////////////////////////////////
75
static u8 hw_enabled;
76
 
1334 tk 77
static u32 ms_counter;
1298 tk 78
 
1334 tk 79
static u32 stopwatch_value;
1903 tk 80
static u32 stopwatch_value_min;
1334 tk 81
static u32 stopwatch_value_max;
82
static u32 stopwatch_value_accumulated;
1903 tk 83
static u32 stopwatch_value_accumulated_ctr;
1298 tk 84
 
1334 tk 85
static u32 cv_se_speed_factor;
1298 tk 86
 
1334 tk 87
/////////////////////////////////////////////////////////////////////////////
88
// C++ objects
89
/////////////////////////////////////////////////////////////////////////////
90
MbCvEnvironment mbCvEnvironment;
1298 tk 91
 
92
 
93
/////////////////////////////////////////////////////////////////////////////
94
// Local prototypes
95
/////////////////////////////////////////////////////////////////////////////
96
static void APP_Periodic_100uS(void);
1334 tk 97
extern void CV_TIMER_SE_Update(void);
1298 tk 98
static s32 NOTIFY_MIDI_Rx(mios32_midi_port_t port, u8 byte);
1299 tk 99
static s32 NOTIFY_MIDI_Tx(mios32_midi_port_t port, mios32_midi_package_t package);
100
static s32 NOTIFY_MIDI_TimeOut(mios32_midi_port_t port);
1298 tk 101
 
102
 
103
/////////////////////////////////////////////////////////////////////////////
1334 tk 104
// returns pointer to MbCv objects
105
/////////////////////////////////////////////////////////////////////////////
106
MbCvEnvironment *APP_GetEnv()
107
{
108
  return &mbCvEnvironment;
109
}
110
 
111
 
112
/////////////////////////////////////////////////////////////////////////////
1298 tk 113
// This hook is called after startup to initialize the application
114
/////////////////////////////////////////////////////////////////////////////
1334 tk 115
extern "C" void APP_Init(void)
1298 tk 116
{
117
  // initialize all LEDs
118
  MIOS32_BOARD_LED_Init(0xffffffff);
119
 
120
  // hardware will be enabled once configuration has been loaded from SD Card
121
  // (resp. no SD Card is available)
122
  hw_enabled = 0;
123
 
1334 tk 124
  // init Stopwatch
125
  APP_StopwatchInit();
126
 
1903 tk 127
#if J5_DEBUG_PINS
128
  // initialize debug pins J5B:A4..A7
129
  {
130
    int i;
131
    for(int i=4; i<7; ++i) {
132
      MIOS32_BOARD_J5_PinInit(i, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
133
      MIOS32_BOARD_J5_PinSet(i, 1);
134
    }
135
  }
136
#endif
137
 
1298 tk 138
  // initialize all J10 pins as inputs with internal Pull-Up
139
  int pin;
140
  for(pin=0; pin<8; ++pin)
141
    MIOS32_BOARD_J10_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU);
142
 
1895 tk 143
  // initialize OLED pins at J5
144
  {
145
    APP_SelectScopeLCDs();
1298 tk 146
 
1895 tk 147
    APP_LCD_Init(0);
148
 
149
    int lcd;
150
    for(lcd=0; lcd<4; ++lcd) {
151
      MIOS32_LCD_DeviceSet(lcd);
152
      MIOS32_LCD_Clear();
153
    }
154
 
155
    APP_SelectMainLCD();
156
  }
157
 
1298 tk 158
  // install SysEx callback
159
  MIOS32_MIDI_SysExCallback_Init(APP_SYSEX_Parser);
160
 
1299 tk 161
  // install MIDI Rx/Tx callback functions
162
  MIOS32_MIDI_DirectRxCallback_Init(&NOTIFY_MIDI_Rx);
163
  MIOS32_MIDI_DirectTxCallback_Init(&NOTIFY_MIDI_Tx);
1298 tk 164
 
1299 tk 165
  // install timeout callback function
166
  MIOS32_MIDI_TimeOutCallback_Init(&NOTIFY_MIDI_TimeOut);
1298 tk 167
 
168
  // initialize AOUT module
169
  AOUT_Init(0);
170
 
171
  // configure interface (will be changed again once config file has been loaded from SD Card, or via SCS)
172
  aout_config_t config;
173
  config = AOUT_ConfigGet();
174
  config.if_type = AOUT_IF_MAX525;
175
  config.if_option = 0;
176
  config.num_channels = 8;
177
  config.chn_inverted = 0;
178
  AOUT_ConfigSet(config);
179
  AOUT_IF_Init(0);
180
 
1299 tk 181
  // initialize code modules
1492 tk 182
  MIDI_PORT_Init(0);
1299 tk 183
  MBCV_SYSEX_Init(0);
184
  MBCV_MAP_Init(0);
1492 tk 185
  MIDI_ROUTER_Init(0);
1299 tk 186
  MBCV_PATCH_Init(0);
1901 tk 187
  MBCV_LRE_Init(0);
1299 tk 188
  UIP_TASK_Init(0);
1887 tk 189
 
1299 tk 190
  SCS_Init(0);
191
  SCS_CONFIG_Init(0);
1887 tk 192
 
193
  if( mios32_lcd_parameters.lcd_type == MIOS32_LCD_TYPE_GLCD_SSD1306 )
194
    SCS_LCD_OffsetYSet(6);
195
 
1299 tk 196
  TERMINAL_Init(0);
197
  MIDIMON_Init(0);
198
  MBCV_FILE_Init(0);
199
 
1298 tk 200
  // install timer function which is called each 100 uS
201
  MIOS32_TIMER_Init(1, 100, APP_Periodic_100uS, MIOS32_IRQ_PRIO_MID);
202
 
1334 tk 203
  // initialize MbCvEnvironment
1347 tk 204
  cv_se_speed_factor = 10;
1334 tk 205
  mbCvEnvironment.updateSpeedFactorSet(cv_se_speed_factor);
1298 tk 206
 
1334 tk 207
  // initialize tasks
208
  TASKS_Init(0);
209
 
210
  // start timer
211
  // TODO: increase  once performance has been evaluated
212
  MIOS32_TIMER_Init(2, 2000 / cv_se_speed_factor, CV_TIMER_SE_Update, MIOS32_IRQ_PRIO_MID);
1901 tk 213
 
214
#if MIOS32_DONT_SERVICE_SRIO_SCAN
215
  //MIOS32_SRIO_ScanNumSet(4);
216
 
217
  // standard SRIO scan has been disabled in programming_models/traditional/main.c via MIOS32_DONT_SERVICE_SRIO_SCAN in mios32_config.h
218
  // start the scan here - and retrigger it whenever it's finished
219
  APP_SRIO_ServicePrepare();
220
  MIOS32_SRIO_ScanStart(APP_SRIO_ServiceFinish);
221
#endif
1298 tk 222
}
223
 
224
 
225
/////////////////////////////////////////////////////////////////////////////
226
// This task is running endless in background
227
/////////////////////////////////////////////////////////////////////////////
1334 tk 228
extern "C" void APP_Background(void)
1298 tk 229
{
230
  // endless loop
231
  while( 1 ) {
232
    // toggle the state of all LEDs (allows to measure the execution speed with a scope)
233
    MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get());
234
  }
235
}
236
 
237
 
238
/////////////////////////////////////////////////////////////////////////////
239
// This hook is called when a MIDI package has been received
240
/////////////////////////////////////////////////////////////////////////////
1334 tk 241
extern "C" void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
1298 tk 242
{
1299 tk 243
  // -> CV MIDI handler
1334 tk 244
  mbCvEnvironment.midiReceive(port, midi_package);
1299 tk 245
 
1298 tk 246
  // -> MIDI Router
1492 tk 247
  MIDI_ROUTER_Receive(port, midi_package);
1298 tk 248
 
1299 tk 249
  // -> MIDI Port Handler (used for MIDI monitor function)
1492 tk 250
  MIDI_PORT_NotifyMIDIRx(port, midi_package);
1299 tk 251
 
1298 tk 252
  // forward to MIDI Monitor
253
  // SysEx messages have to be filtered for USB0 and UART0 to avoid data corruption
254
  // (the SysEx stream would interfere with monitor messages)
255
  u8 filter_sysex_message = (port == USB0) || (port == UART0);
256
  MIDIMON_Receive(port, midi_package, ms_counter, filter_sysex_message);
257
}
258
 
259
/////////////////////////////////////////////////////////////////////////////
260
// This function parses an incoming sysex stream for MIOS32 commands
261
/////////////////////////////////////////////////////////////////////////////
1334 tk 262
extern "C" s32 APP_SYSEX_Parser(mios32_midi_port_t port, u8 midi_in)
1298 tk 263
{
264
  // -> MBCV
265
  MBCV_SYSEX_Parser(port, midi_in);
266
 
267
  // -> MIDI Router
1492 tk 268
  MIDI_ROUTER_ReceiveSysEx(port, midi_in);
1298 tk 269
 
270
  return 0; // no error
271
}
272
 
273
/////////////////////////////////////////////////////////////////////////////
274
// This hook is called before the shift register chain is scanned
275
/////////////////////////////////////////////////////////////////////////////
1334 tk 276
extern "C" void APP_SRIO_ServicePrepare(void)
1298 tk 277
{
278
  // pass current pin state of J10
279
  // only available for LPC17xx, all others (like STM32) default to SRIO
280
  SCS_AllPinsSet(0xff00 | MIOS32_BOARD_J10_Get());
281
 
282
  // update encoders/buttons of SCS
283
  SCS_EncButtonUpdate_Tick();
284
}
285
 
286
 
287
/////////////////////////////////////////////////////////////////////////////
288
// This hook is called after the shift register chain has been scanned
289
/////////////////////////////////////////////////////////////////////////////
1334 tk 290
extern "C" void APP_SRIO_ServiceFinish(void)
1298 tk 291
{
1901 tk 292
#if MIOS32_DONT_SERVICE_SRIO_SCAN
293
  // update encoder states
294
  MIOS32_ENC_UpdateStates();
295
 
296
  // standard SRIO scan has been disabled in programming_models/traditional/main.c via MIOS32_DONT_SERVICE_SRIO_SCAN in mios32_config.h
297
  // start the scan here - and retrigger it whenever it's finished
298
  APP_SRIO_ServicePrepare();
299
  MIOS32_SRIO_ScanStart(APP_SRIO_ServiceFinish);
300
#endif
1298 tk 301
}
302
 
303
 
304
/////////////////////////////////////////////////////////////////////////////
305
// This hook is called when a button has been toggled
306
// pin_value is 1 when button released, and 0 when button pressed
307
/////////////////////////////////////////////////////////////////////////////
1334 tk 308
extern "C" void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
1298 tk 309
{
310
}
311
 
312
 
313
/////////////////////////////////////////////////////////////////////////////
314
// This hook is called when an encoder has been moved
315
// incrementer is positive when encoder has been turned clockwise, else
316
// it is negative
317
/////////////////////////////////////////////////////////////////////////////
1334 tk 318
extern "C" void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
1298 tk 319
{
320
  // pass encoder event to SCS handler
1901 tk 321
  if( encoder == SCS_ENC_MENU_ID ) // == 0 (assigned by SCS)
1298 tk 322
    SCS_ENC_MENU_NotifyChange(incrementer);
1901 tk 323
  else {
324
    // -> ENC Handler
1905 tk 325
    MBCV_LRE_NotifyChange(encoder-1, incrementer);
1901 tk 326
  }
1298 tk 327
}
328
 
329
 
330
/////////////////////////////////////////////////////////////////////////////
331
// This hook is called when a pot has been moved
332
/////////////////////////////////////////////////////////////////////////////
1334 tk 333
extern "C" void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
1298 tk 334
{
335
}
336
 
337
 
338
 
1334 tk 339
/////////////////////////////////////////////////////////////////////////////
340
// This timer interrupt periodically calls the sound engine update
341
/////////////////////////////////////////////////////////////////////////////
342
extern void CV_TIMER_SE_Update(void)
343
{
344
  if( !hw_enabled )
345
    return;
1298 tk 346
 
1903 tk 347
#if J5_DEBUG_PINS
348
    MIOS32_BOARD_J5_PinSet(4, 0);
349
    MIOS32_BOARD_J5_PinSet(5, 0);
350
#endif
351
 
352
#if STOPWATCH_PERFORMANCE_MEASURING == 1 || STOPWATCH_PERFORMANCE_MEASURING == 2
1334 tk 353
  APP_StopwatchReset();
354
#endif
355
 
1903 tk 356
  if( !mbCvEnvironment.tick() ) {
357
#if J5_DEBUG_PINS
358
    MIOS32_BOARD_J5_PinSet(4, 1);
359
    MIOS32_BOARD_J5_PinSet(5, 1);
360
#endif
1334 tk 361
    return; // no update required
1903 tk 362
  }
1334 tk 363
 
364
#if STOPWATCH_PERFORMANCE_MEASURING == 1
365
  APP_StopwatchCapture();
366
#endif
1903 tk 367
#if J5_DEBUG_PINS
368
    MIOS32_BOARD_J5_PinSet(4, 1);
369
#endif
1334 tk 370
 
371
  // update AOUTs
372
  MBCV_MAP_Update();
373
 
374
#if STOPWATCH_PERFORMANCE_MEASURING == 2
375
  APP_StopwatchCapture();
376
#endif
1903 tk 377
#if J5_DEBUG_PINS
378
    MIOS32_BOARD_J5_PinSet(5, 1);
379
#endif
1334 tk 380
}
381
 
382
 
383
 
384
 
1298 tk 385
/////////////////////////////////////////////////////////////////////////////
386
// This task handles the control surface
387
/////////////////////////////////////////////////////////////////////////////
1334 tk 388
void APP_TASK_Period_1mS_LP(void)
1298 tk 389
{
1887 tk 390
  static u8 clear_lcd = 1;
1334 tk 391
  static u16 performance_print_ctr = 0;
1298 tk 392
 
1905 tk 393
  MUTEX_LCD_TAKE;
394
 
1887 tk 395
  if( clear_lcd ) {
396
    clear_lcd = 0;
1905 tk 397
    MIOS32_LCD_Clear();    
1887 tk 398
  }
399
 
1334 tk 400
  // call SCS handler
401
  SCS_Tick();
1298 tk 402
 
1905 tk 403
  MUTEX_LCD_GIVE;
1885 tk 404
 
1334 tk 405
  // MIDI In/Out monitor
1492 tk 406
  MIDI_PORT_Period1mS();
1298 tk 407
 
1905 tk 408
  // LED rings
409
  MBCV_LRE_UpdateAllLedRings();
410
 
1334 tk 411
  // output and reset current stopwatch max value each second
412
  if( ++performance_print_ctr >= 1000 ) {
413
    performance_print_ctr = 0;
414
 
415
    MUTEX_MIDIOUT_TAKE;
416
    MIOS32_IRQ_Disable();
1903 tk 417
    u32 min_value = stopwatch_value_min;
418
    stopwatch_value_min = ~0;
1334 tk 419
    u32 max_value = stopwatch_value_max;
420
    stopwatch_value_max = 0;
421
    u32 acc_value = stopwatch_value_accumulated;
422
    stopwatch_value_accumulated = 0;
1903 tk 423
    u32 acc_ctr = stopwatch_value_accumulated_ctr;
424
    stopwatch_value_accumulated_ctr = 0;
1334 tk 425
    MIOS32_IRQ_Enable();
426
#if DEBUG_VERBOSE_LEVEL >= 2
427
    if( acc_value || max_value )
1903 tk 428
      DEBUG_MSG("%d uS (min: %d uS, max: %d uS)\n", acc_value / acc_ctr, min_value, max_value);
1334 tk 429
#endif
430
    MUTEX_MIDIOUT_GIVE;
1298 tk 431
  }
432
 
433
}
434
 
435
 
436
/////////////////////////////////////////////////////////////////////////////
1905 tk 437
// This task handles the scope displays with very low priority
438
/////////////////////////////////////////////////////////////////////////////
439
void APP_TASK_Period_1mS_LP2(void)
440
{
441
  {
442
#if J5_DEBUG_PINS
443
    MIOS32_BOARD_J5_PinSet(6, 0);
444
#endif
445
    // CV Scopes (note: mutex is taken inside function)
446
    mbCvEnvironment.tickScopes();
447
#if J5_DEBUG_PINS
448
    MIOS32_BOARD_J5_PinSet(6, 1);
449
#endif
450
  }
451
 
452
  // CV Bars (currently only for SSD1306)
453
  {
454
    MUTEX_LCD_TAKE;
455
 
456
    if( mios32_lcd_parameters.lcd_type == MIOS32_LCD_TYPE_GLCD_SSD1306 ) {
457
 
458
      MIOS32_LCD_DeviceSet(0);
459
      MIOS32_LCD_FontInit((u8 *)GLCD_FONT_METER_ICONS_V); // memo: 28 icons, 14 used, icon size: 8x32
460
 
461
      u16 *outMeter = mbCvEnvironment.cvOutMeter.first();
462
      for(int cv=0; cv<CV_SE_NUM; ++cv, ++outMeter) {
463
    MIOS32_LCD_CursorSet(0 + 2*cv, 4);
464
    MIOS32_LCD_PrintChar((*outMeter * 13) / 65535);
465
      }
466
 
467
      MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL);    
468
    }
469
 
470
    MUTEX_LCD_GIVE;
471
  }
472
}
473
 
474
 
475
/////////////////////////////////////////////////////////////////////////////
1298 tk 476
// This task handles the SD Card
477
/////////////////////////////////////////////////////////////////////////////
1334 tk 478
void APP_TASK_Period_1mS_SD(void)
1298 tk 479
{
1334 tk 480
  static u16 sdcard_check_ctr = 0;
1298 tk 481
 
1334 tk 482
  // each second: check if SD Card (still) available
483
  if( ++sdcard_check_ctr >= 1000 ) {
484
    sdcard_check_ctr = 0;
1298 tk 485
 
1334 tk 486
    MUTEX_SDCARD_TAKE;
487
    s32 status = FILE_CheckSDCard();
1298 tk 488
 
1334 tk 489
    hw_enabled = 1; // enable hardware after first read...
1298 tk 490
 
1334 tk 491
    if( status == 1 ) {
492
      DEBUG_MSG("SD Card connected: %s\n", FILE_VolumeLabel());
493
      // load all file infos
494
      MBCV_FILE_LoadAllFiles(1); // including HW info
495
    } else if( status == 2 ) {
496
      DEBUG_MSG("SD Card disconnected\n");
497
      // invalidate all file infos
498
      MBCV_FILE_UnloadAllFiles();
1298 tk 499
 
1334 tk 500
      // change status
501
      MBCV_FILE_StatusMsgSet("No SD Card");
502
    } else if( status == 3 ) {
503
      if( !FILE_SDCardAvailable() ) {
504
    DEBUG_MSG("SD Card not found\n");
1298 tk 505
    MBCV_FILE_StatusMsgSet("No SD Card");
1334 tk 506
      } else if( !FILE_VolumeAvailable() ) {
507
    DEBUG_MSG("ERROR: SD Card contains invalid FAT!\n");
508
    MBCV_FILE_StatusMsgSet("No FAT");
509
      } else {
1653 tk 510
    // create the default files if they don't exist on SD Card
511
    MBCV_FILE_CreateDefaultFiles();
1298 tk 512
 
1334 tk 513
    // disable status message and print patch
514
    MBCV_FILE_StatusMsgSet(NULL);
1298 tk 515
      }
516
    }
1334 tk 517
 
518
    MUTEX_SDCARD_GIVE;
1298 tk 519
  }
520
}
521
 
522
 
523
/////////////////////////////////////////////////////////////////////////////
1452 tk 524
// This task is called periodically each mS
1298 tk 525
/////////////////////////////////////////////////////////////////////////////
1334 tk 526
void APP_TASK_Period_1mS(void)
1298 tk 527
{
1452 tk 528
  // e.g. for synched pattern changes
529
  mbCvEnvironment.tick_1mS();
530
 
1334 tk 531
  if( hw_enabled ) {
532
    // nothing to do... yet
1298 tk 533
  }
534
}
535
 
536
 
537
/////////////////////////////////////////////////////////////////////////////
538
// This timer function is periodically called each 100 uS
539
/////////////////////////////////////////////////////////////////////////////
540
static void APP_Periodic_100uS(void)
541
{
542
  static u8 pre_ctr = 0;
543
 
544
  // increment the microsecond counter each 10th tick
545
  if( ++pre_ctr >= 10 ) {
546
    pre_ctr = 0;
547
    ++ms_counter;
548
  }
549
 
550
  // here we could do some additional high-prio jobs
551
  // (e.g. PWM LEDs)
552
}
553
 
554
/////////////////////////////////////////////////////////////////////////////
555
// Installed via MIOS32_MIDI_DirectRxCallback_Init
556
/////////////////////////////////////////////////////////////////////////////
557
static s32 NOTIFY_MIDI_Rx(mios32_midi_port_t port, u8 midi_byte)
558
{
1299 tk 559
  // filter MIDI In port which controls the MIDI clock
1895 tk 560
  if( MIDI_ROUTER_MIDIClockInGet(port) == 1 ) {
1408 tk 561
    if( midi_byte >= 0xf8 ) {
562
      mbCvEnvironment.midiReceiveRealTimeEvent(port, midi_byte);
563
    }
564
  }
565
 
1298 tk 566
  return 0; // no error, no filtering
567
}
568
 
1299 tk 569
/////////////////////////////////////////////////////////////////////////////
570
// Installed via MIOS32_MIDI_DirectTxCallback_Init
571
/////////////////////////////////////////////////////////////////////////////
572
static s32 NOTIFY_MIDI_Tx(mios32_midi_port_t port, mios32_midi_package_t package)
573
{
1492 tk 574
  return MIDI_PORT_NotifyMIDITx(port, package);
1299 tk 575
}
1298 tk 576
 
577
/////////////////////////////////////////////////////////////////////////////
1299 tk 578
// Installed via MIOS32_MIDI_TimeoutCallback_Init
579
/////////////////////////////////////////////////////////////////////////////
580
static s32 NOTIFY_MIDI_TimeOut(mios32_midi_port_t port)
581
{  
582
  // forward to SysEx parser
583
  MBCV_SYSEX_TimeOut(port);
584
 
585
  // print message on screen
586
  SCS_Msg(SCS_MSG_L, 2000, "MIDI Protocol", "TIMEOUT !!!");
587
 
588
  return 0;
589
}
590
 
591
 
592
/////////////////////////////////////////////////////////////////////////////
1895 tk 593
// Switches to the scope LCDs
594
/////////////////////////////////////////////////////////////////////////////
1905 tk 595
s32 APP_SelectScopeLCDs(void)
1895 tk 596
{
597
  // select the alternative pinning via J5A/J28
598
  APP_LCD_AltPinningSet(1);
599
 
600
  // select GLCD type and dimensions
601
  mios32_lcd_parameters.lcd_type = MIOS32_LCD_TYPE_GLCD_SSD1306; // TODO: get this from a configuration file
602
  mios32_lcd_parameters.num_x = 4;
603
  mios32_lcd_parameters.num_y = 1;
604
  mios32_lcd_parameters.width = 128;
605
  mios32_lcd_parameters.height = 64;
606
 
607
  return 0; // no error
608
}
609
 
610
/////////////////////////////////////////////////////////////////////////////
611
// Switches to the original LCD
612
/////////////////////////////////////////////////////////////////////////////
1905 tk 613
s32 APP_SelectMainLCD(void)
1895 tk 614
{
615
  // ensure that first LCD is selected
616
  MIOS32_LCD_DeviceSet(0);
617
 
618
  // select the original pinning
619
  APP_LCD_AltPinningSet(0);
620
 
621
  // retrieve original LCD parameters
622
  MIOS32_LCD_ParametersFetchFromBslInfoRange();
623
 
624
  return 0; // no error
625
}
626
 
627
 
628
/////////////////////////////////////////////////////////////////////////////
1334 tk 629
// For performance Measurements
1298 tk 630
/////////////////////////////////////////////////////////////////////////////
1334 tk 631
s32 APP_StopwatchInit(void)
1298 tk 632
{
1334 tk 633
  stopwatch_value = 0;
1903 tk 634
  stopwatch_value_min = ~0;
1334 tk 635
  stopwatch_value_max = 0;
636
  stopwatch_value_accumulated = 0;
1903 tk 637
  stopwatch_value_accumulated_ctr = 0;
1334 tk 638
  return MIOS32_STOPWATCH_Init(1); // 1 uS resolution
1298 tk 639
}
640
 
1334 tk 641
s32 APP_StopwatchReset(void)
1298 tk 642
{
1334 tk 643
  return MIOS32_STOPWATCH_Reset();
1298 tk 644
}
645
 
1334 tk 646
s32 APP_StopwatchCapture(void)
1298 tk 647
{
1334 tk 648
  u32 value = MIOS32_STOPWATCH_ValueGet();
649
  MIOS32_IRQ_Disable();
650
  stopwatch_value = value;
1903 tk 651
  if( value < stopwatch_value_min )
652
    stopwatch_value_min = value;
1334 tk 653
  if( value > stopwatch_value_max )
654
    stopwatch_value_max = value;
655
  stopwatch_value_accumulated += value;
1903 tk 656
  ++stopwatch_value_accumulated_ctr;
1334 tk 657
  MIOS32_IRQ_Enable();
1298 tk 658
 
659
  return 0; // no error
660
}
1895 tk 661