Exemplo n.º 1
0
/////////////////////////////////////////////////////////////////////////////
// This hook is called when a MIDI package has been received
/////////////////////////////////////////////////////////////////////////////
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
{
  // toggle Status LED on each incoming MIDI package
  MIOS32_BOARD_LED_Set(0x0001, ~MIOS32_BOARD_LED_Get());

  // 1) the LED should be turned on whenever a Note On Event with velocity > 0
  // has been received
  if( midi_package.type == NoteOn && midi_package.velocity > 0 ) {
    // determine LED number (one of 12, each octave)
    u8 led = midi_package.note % 12;
    // turn on LED
    MIOS32_BOARD_J5_PinSet(led, 1);
  }

  // 2) the LED should be turned off whenever a Note Off Event or a Note On
  // event with velocity == 0 has been received (the MIDI spec says, that velocity 0
  // should be handled like Note Off)
  else if( (midi_package.type == NoteOff) ||
	   (midi_package.type == NoteOn && midi_package.velocity == 0) ) {
    // determine LED number (one of 12, each octave)
    u8 led = midi_package.note % 12;
    // turn off LED
    MIOS32_BOARD_J5_PinSet(led, 0);
  }
}
Exemplo n.º 2
0
/////////////////////////////////////////////////////////////////////////////
// This timer function is periodically called each 100 uS
/////////////////////////////////////////////////////////////////////////////
static void APP_Periodic_100uS(void)
{
  // this is a very simple way to generate a nice PWM based flashing effect
  // for multiple LEDs from a single timer

  u8 *led_trigger_ptr = (u8 *)&led_trigger[0];
  u8 *led_pwm_counter_ptr = (u8 *)&led_pwm_counter[0];
  int i;
  for(i=0; i<NUM_LED_TRIGGERS; ++i, ++led_trigger_ptr, ++led_pwm_counter_ptr) {
    if( *led_trigger_ptr ) {
      if( --*led_pwm_counter_ptr ) {
	if( *led_pwm_counter_ptr == *led_trigger_ptr ) {
	  if( i == 0 )
	    MIOS32_BOARD_LED_Set(1, 1);
	  else
	    MIOS32_BOARD_J5_PinSet(i-1, 1);
	}
      } else {
	*led_pwm_counter_ptr = LED_PWM_PERIOD;
	--*led_trigger_ptr;

	if( i == 0 )
	  MIOS32_BOARD_LED_Set(1, 0);
	else
	  MIOS32_BOARD_J5_PinSet(i-1, 0);
      }
    }
  }
}
Exemplo n.º 3
0
/////////////////////////////////////////////////////////////////////////////
// This hook is called before an AIN channel scan
// It has been installed in APP_Init()
/////////////////////////////////////////////////////////////////////////////
s32 AIN_ServicePrepare(void)
{
  // increment counter, skip on the first 9 invocations (= 9 mS setup time)
  if( ++setup_time_ctr < 10 )
    return 1; // skip scan (see documentation of MIOS32_AIN_ServicePrepareCallback_Init())

  // scan with the 10th invocation
  if( setup_time_ctr++ == 10 )
    return 0; // allow scan, value changes will be forwarded to APP_AIN_NotifyChange()

  // reset counter
  setup_time_ctr = 0;

  // toggle scan direction
  scan_x ^= 1;

  // re-initialize AIN pins at J5A (Pin C0..C3)
  // Touchpanel connections:
  // J5.A0: Right
  // J5.A1: Top
  // J5.A2: Left
  // J5.A3: Bottom

  if( scan_x ) {
    // X Scan

    // A2 (Left) = 0V
    MIOS32_BOARD_J5_PinInit(2, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
    MIOS32_BOARD_J5_PinSet(2, 0);

    // A0 (Right) = 3.3V
    MIOS32_BOARD_J5_PinInit(0, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
    MIOS32_BOARD_J5_PinSet(0, 1);

    // A1 (Top) used as ADC Input
    MIOS32_BOARD_J5_PinInit(1, MIOS32_BOARD_PIN_MODE_ANALOG);

    // switch A3 (Bottom) to high impedance state
    MIOS32_BOARD_J5_PinInit(3, MIOS32_BOARD_PIN_MODE_ANALOG);
  } else {
    // Y Scan

    // A1 (Top) = 0V
    MIOS32_BOARD_J5_PinInit(1, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
    MIOS32_BOARD_J5_PinSet(1, 0);

    // A3 (Bottom) = 3.3V
    MIOS32_BOARD_J5_PinInit(3, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
    MIOS32_BOARD_J5_PinSet(3, 1);

    // A0 (Right) used as ADC Input
    MIOS32_BOARD_J5_PinInit(0, MIOS32_BOARD_PIN_MODE_ANALOG);

    // switch A2 (Left) to high impedance state
    MIOS32_BOARD_J5_PinInit(2, MIOS32_BOARD_PIN_MODE_ANALOG);
  }

  return 1; // skip conversion
}
Exemplo n.º 4
0
/////////////////////////////////////////////////////////////////////////////
// This hook is called after startup to initialize the application
/////////////////////////////////////////////////////////////////////////////
void APP_Init(void)
{
  int i;

  // create semaphores
  xMIDIINSemaphore = xSemaphoreCreateRecursiveMutex();
  xMIDIOUTSemaphore = xSemaphoreCreateRecursiveMutex();

  // clear SysEx buffers
  for(i=0; i<NUM_SYSEX_BUFFERS; ++i)
    sysex_buffer_len[i] = 0;

  // install SysEx callback
  MIOS32_MIDI_SysExCallback_Init(APP_SYSEX_Parser);

  // read EEPROM content
  PRESETS_Init(0);

  // init terminal
  TERMINAL_Init(0);

  // init MIDImon
  MIDIMON_Init(0);

  // start uIP task
  UIP_TASK_Init(0);

  // initialize status LED
  MIOS32_BOARD_LED_Init(0xffffffff);
  MIOS32_BOARD_LED_Set(1, 0);
  led_pwm_counter[0] = LED_PWM_PERIOD;
  led_trigger[0] = LED_PWM_PERIOD; // trigger LED on startup for complete PWM cycle

  // initialize additional LEDs connected to J5A
  for(i=1; i<NUM_LED_TRIGGERS; ++i) {
    led_pwm_counter[i] = LED_PWM_PERIOD;
    led_trigger[i] = LED_PWM_PERIOD; // trigger LED on startup for complete PWM cycle
    MIOS32_BOARD_J5_PinInit(i-1, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
    MIOS32_BOARD_J5_PinSet(i-1, 0);
  }

  // initialize J5B/J5C pins as inputs with pull-up enabled
  // these pins control diagnostic options of the MIDI monitor
  for(i=4; i<12; ++i)
    MIOS32_BOARD_J5_PinInit(i, MIOS32_BOARD_PIN_MODE_INPUT_PU);

  // install timer function which is called each 100 uS
  MIOS32_TIMER_Init(0, 100, APP_Periodic_100uS, MIOS32_IRQ_PRIO_MID);

  // print welcome message on MIOS terminal
  MIOS32_MIDI_SendDebugMessage("\n");
  MIOS32_MIDI_SendDebugMessage("=====================\n");
  MIOS32_MIDI_SendDebugMessage("%s\n", MIOS32_LCD_BOOT_MSG_LINE1);
  MIOS32_MIDI_SendDebugMessage("=====================\n");
  MIOS32_MIDI_SendDebugMessage("\n");
}