Subversion Repositories svn.mios32

Rev

Rev 2644 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2644 Rev 2649
Line 1... Line 1...
1
// $Id: mios32_midi.c 2560 2018-01-15 22:08:29Z Antichambre $
1
// $Id: mios32_midi.c 2649 2019-01-08 11:45:19Z Antichambre $
2
//! \defgroup MIOS32_MIDI
2
//! \defgroup MIOS32_MIDI
3
//!
3
//!
4
//! MIDI layer functions for MIOS32
4
//! MIDI layer functions for MIOS32
5
//!
5
//!
6
//! the mios32_midi_package_t format complies with USB MIDI spec (details see there)
6
//! the mios32_midi_package_t format complies with USB MIDI spec (details see there)
Line 223... Line 223...
223
#endif
223
#endif
224
224
225
#if !defined(MIOS32_DONT_USE_SPI) && !defined(MIOS32_DONT_USE_SPI_MIDI)
225
#if !defined(MIOS32_DONT_USE_SPI) && !defined(MIOS32_DONT_USE_SPI_MIDI)
226
  if( MIOS32_SPI_MIDI_Init(0) < 0 )
226
  if( MIOS32_SPI_MIDI_Init(0) < 0 )
227
    ret |= (1 << 3);
227
    ret |= (1 << 3);
-
 
228
#endif
-
 
229
-
 
230
#if defined(MIOS32_USE_CAN) && defined(MIOS32_USE_CAN_MIDI)
-
 
231
  if( MIOS32_CAN_MIDI_Init(0) < 0 )
-
 
232
    ret |= (1 << 4);
228
#endif
233
#endif
229
234
 
230
  last_sysex_port = DEFAULT;
235
  last_sysex_port = DEFAULT;
231
  sysex_state.ALL = 0;
236
  sysex_state.ALL = 0;
232
237
Line 287... Line 292...
287
#if !defined(MIOS32_DONT_USE_SPI) && !defined(MIOS32_DONT_USE_SPI_MIDI)
292
#if !defined(MIOS32_DONT_USE_SPI) && !defined(MIOS32_DONT_USE_SPI_MIDI)
288
      return MIOS32_SPI_MIDI_CheckAvailable(port & 0xf);
293
      return MIOS32_SPI_MIDI_CheckAvailable(port & 0xf);
289
#else
294
#else
290
      return 0; // IIC_MIDI has been disabled
295
      return 0; // IIC_MIDI has been disabled
291
#endif
296
#endif
-
 
297
-
 
298
    case MCAN0 ://..15
-
 
299
#if defined(MIOS32_USE_CAN) && defined(MIOS32_USE_CAN_MIDI)
-
 
300
      return MIOS32_CAN_MIDI_CheckAvailable(port & 0xf);
-
 
301
#else
-
 
302
      return 0; // IIC_MIDI has been disabled
-
 
303
#endif
-
 
304
292
  }
305
  }
293
306
294
  return 0; // invalid port
307
  return 0; // invalid port
295
}
308
}
296
309
Line 332... Line 345...
332
      return -1; // IIC_MIDI has been disabled
345
      return -1; // IIC_MIDI has been disabled
333
#endif
346
#endif
334
347
335
    case SPIM0://..15
348
    case SPIM0://..15
336
      return -1; // not required for SPI
349
      return -1; // not required for SPI
-
 
350
-
 
351
    case MCAN0://..15
-
 
352
      return -1; // not required for CAN
337
353
     
338
  }
354
  }
339
355
340
  return -1; // invalid port
356
  return -1; // invalid port
341
}
357
}
Line 375... Line 391...
375
      return -1; // IIC_MIDI has been disabled
391
      return -1; // IIC_MIDI has been disabled
376
#endif
392
#endif
377
393
378
    case SPIM0://..15
394
    case SPIM0://..15
379
      return -1; // not required for SPI
395
      return -1; // not required for SPI
-
 
396
     
-
 
397
    case MCAN0://..15
-
 
398
      return -1; // not required for CAN
-
 
399
380
  }
400
  }
381
401
382
  return -1; // invalid port
402
  return -1; // invalid port
383
}
403
}
384
404
Line 417... Line 437...
417
      return -1; // IIC_MIDI has been disabled
437
      return -1; // IIC_MIDI has been disabled
418
#endif
438
#endif
419
439
420
    case SPIM0://..15
440
    case SPIM0://..15
421
      return -1; // not required for SPI
441
      return -1; // not required for SPI
-
 
442
     
-
 
443
    case MCAN0://..15
-
 
444
      return -1; // not required for CAN
-
 
445
422
  }
446
  }
423
447
424
  return -1; // invalid port
448
  return -1; // invalid port
425
}
449
}
426
450
Line 486... Line 510...
486
    case SPIM0://..15
510
    case SPIM0://..15
487
#if !defined(MIOS32_DONT_USE_SPI) && !defined(MIOS32_DONT_USE_SPI_MIDI)
511
#if !defined(MIOS32_DONT_USE_SPI) && !defined(MIOS32_DONT_USE_SPI_MIDI)
488
      return MIOS32_SPI_MIDI_PackageSend_NonBlocking(package);
512
      return MIOS32_SPI_MIDI_PackageSend_NonBlocking(package);
489
#else
513
#else
490
      return -1; // SPI_MIDI has been disabled
514
      return -1; // SPI_MIDI has been disabled
-
 
515
#endif
-
 
516
-
 
517
    case MCAN0://..15
-
 
518
#if defined(MIOS32_USE_CAN) && defined(MIOS32_USE_CAN_MIDI)
-
 
519
      return MIOS32_CAN_MIDI_PackageSend_NonBlocking(package);
-
 
520
#else
-
 
521
      return -1; // CAN_MIDI has been disabled
491
#endif
522
#endif
492
     
523
493
    default:
524
    default:
494
      // invalid port
525
      // invalid port
495
      return -1;
526
      return -1;
Line 550... Line 581...
550
    case SPIM0://..15
581
    case SPIM0://..15
551
#if !defined(MIOS32_DONT_USE_SPI) && !defined(MIOS32_DONT_USE_SPI_MIDI)
582
#if !defined(MIOS32_DONT_USE_SPI) && !defined(MIOS32_DONT_USE_SPI_MIDI)
552
      return MIOS32_SPI_MIDI_PackageSend(package);
583
      return MIOS32_SPI_MIDI_PackageSend(package);
553
#else
584
#else
554
      return -1; // SPI_MIDI has been disabled
585
      return -1; // SPI_MIDI has been disabled
-
 
586
#endif
-
 
587
-
 
588
    case MCAN0://..15
-
 
589
#if defined(MIOS32_USE_CAN) && defined(MIOS32_USE_CAN_MIDI)
-
 
590
      return MIOS32_CAN_MIDI_PackageSend(package);
-
 
591
#else
-
 
592
      return -1; // CAN_MIDI has been disabled
555
#endif
593
#endif
556
     
594
557
    default:
595
    default:
558
      // invalid port
596
      // invalid port
559
      return -1;
597
      return -1;
Line 697... Line 735...
697
//! \return 0 on success
735
//! \return 0 on success
698
/////////////////////////////////////////////////////////////////////////////
736
/////////////////////////////////////////////////////////////////////////////
699
s32 MIOS32_MIDI_SendSysEx(mios32_midi_port_t port, u8 *stream, u32 count)
737
s32 MIOS32_MIDI_SendSysEx(mios32_midi_port_t port, u8 *stream, u32 count)
700
{
738
{
701
  s32 res;
739
  s32 res;
-
 
740
#if 0
-
 
741
#if defined(MIOS32_USE_CAN) && defined(MIOS32_USE_CAN_MIDI)
-
 
742
#if defined(MIOS32_CAN_MIDI_SYSEX_DIRECT_STREAM)
-
 
743
  if((port & 0xf0) == MCAN0){
-
 
744
    mcan_header_t header;
-
 
745
    MIOS32_CAN_MIDI_DefaultHeaderInit(&header);
-
 
746
    header.cable = port & 0x0f;
-
 
747
    return MIOS32_CAN_MIDI_SysexSend(header, (u8*)stream, count);
-
 
748
  }
-
 
749
#endif
-
 
750
#endif
-
 
751
#endif
702
  u32 offset;
752
  u32 offset;
703
  mios32_midi_package_t package;
753
  mios32_midi_package_t package;
704
754
705
  // MEMO: have a look into the project.lss file - gcc optimizes this code pretty well :)
755
  // MEMO: have a look into the project.lss file - gcc optimizes this code pretty well :)
706
756
Line 1232... Line 1282...
1232
    while( (status=MIOS32_USB_MIDI_PackageReceive(&package)) >= 0 ) {
1282
    while( (status=MIOS32_USB_MIDI_PackageReceive(&package)) >= 0 ) {
1233
      MIOS32_MIDI_ReceivePackage(USB0 + package.cable, package, _callback_package);
1283
      MIOS32_MIDI_ReceivePackage(USB0 + package.cable, package, _callback_package);
1234
    }
1284
    }
1235
  }
1285
  }
1236
#endif
1286
#endif
-
 
1287
 
-
 
1288
#if defined(MIOS32_USE_CAN) && defined(MIOS32_USE_CAN_MIDI)
-
 
1289
#if MIOS32_CAN_NUM >= 1
-
 
1290
  {
-
 
1291
    s32 status;
-
 
1292
    //u32 get_ctr = 0;
-
 
1293
    mios32_midi_package_t package;
-
 
1294
    while( (status=MIOS32_CAN_MIDI_PackageReceive(&package)) >= 0 ) {
-
 
1295
      if(status == 1)MIOS32_MIDI_ReceivePackage(MCAN0 + package.cable, package, _callback_package);
-
 
1296
    }
-
 
1297
  }
-
 
1298
#endif
-
 
1299
#endif
-
 
1300
1237
1301
 
1238
  // handle all IIC and UART based MIDI packages (round robin, max 10 packages because of possible timeouts)
1302
  // handle all IIC and UART based MIDI packages (round robin, max 10 packages because of possible timeouts)
1239
  {
1303
  {
1240
    typedef struct {
1304
    typedef struct {
1241
      mios32_midi_port_t port;
1305
      mios32_midi_port_t port;
Line 1398... Line 1462...
1398
#endif
1462
#endif
1399
1463
1400
#ifndef MIOS32_DONT_USE_SPI_MIDI
1464
#ifndef MIOS32_DONT_USE_SPI_MIDI
1401
  status |= MIOS32_SPI_MIDI_Periodic_mS();
1465
  status |= MIOS32_SPI_MIDI_Periodic_mS();
1402
#endif
1466
#endif
-
 
1467
-
 
1468
  #if defined(MIOS32_USE_CAN_MIDI)
-
 
1469
  status |= MIOS32_CAN_MIDI_Periodic_mS();
-
 
1470
#endif
-
 
1471
  ///////////////////////////////////////////////////////////////////////////// End of CAN modification
1403
1472
 
1404
  // increment timeout counter for incoming packages
1473
  // increment timeout counter for incoming packages
1405
  // an incomplete event will be timed out after 1000 ticks (1 second)
1474
  // an incomplete event will be timed out after 1000 ticks (1 second)
1406
  if( sysex_timeout_ctr < 65535 )
1475
  if( sysex_timeout_ctr < 65535 )
1407
    ++sysex_timeout_ctr;
1476
    ++sysex_timeout_ctr;