Subversion Repositories svn.mios32

Rev

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