コード例 #1
0
ファイル: app.c プロジェクト: JKcompute/395_midi_controller
/////////////////////////////////////////////////////////////////////////////
// This hook is called after startup to initialize the application
/////////////////////////////////////////////////////////////////////////////
void APP_Init(void)
{
  // create semaphores
  xMIDIINSemaphore = xSemaphoreCreateRecursiveMutex();
  xMIDIOUTSemaphore = xSemaphoreCreateRecursiveMutex();

  // install SysEx callback
  MIOS32_MIDI_SysExCallback_Init(APP_SYSEX_Parser);

  // install MIDI Rx/Tx callback functions
  MIOS32_MIDI_DirectRxCallback_Init(&NOTIFY_MIDI_Rx);
  MIOS32_MIDI_DirectTxCallback_Init(&NOTIFY_MIDI_Tx);

  // install timeout callback function
  MIOS32_MIDI_TimeOutCallback_Init(&NOTIFY_MIDI_TimeOut);

  // limit the number of DIN/DOUT SRs which will be scanned for faster scan rate
  MIOS32_SRIO_ScanNumSet(2);

  // init keyboard functions
  KEYBOARD_Init(0);

  // read EEPROM content
  PRESETS_Init(0);

  // init MIDI port/router handling
  MIDI_PORT_Init(0);
  MIDI_ROUTER_Init(0);

  // initialize the AINSER module(s)
  AINSER_Init(0);
  AINSER_NumModulesSet(1); // 1 module
  AINSER_MuxedSet(0, 0);   // disable muxing
  AINSER_NumPinsSet(0, 8); // 8 pins

  // init terminal
  TERMINAL_Init(0);

  // init MIDImon
  MIDIMON_Init(0);

  // start uIP task
  UIP_TASK_Init(0);

  // 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");

  // speed up SPI transfer rate (was MIOS32_SPI_PRESCALER_128, initialized by MIOS32_SRIO_Init())
  MIOS32_SPI_TransferModeInit(MIOS32_SRIO_SPI, MIOS32_SPI_MODE_CLK1_PHASE1, MIOS32_SPI_PRESCALER_128);
  // prescaler 64 results into a transfer rate of 0.64 uS per bit
  // when 2 SRs are transfered, we are able to scan the whole 16x8 matrix in 300 uS

  // standard SRIO scan has been disabled in programming_models/traditional/main.c via MIOS32_DONT_SERVICE_SRIO_SCAN in mios32_config.h
  // start the scan here - and retrigger it whenever it's finished
  APP_SRIO_ServicePrepare();
  MIOS32_SRIO_ScanStart(APP_SRIO_ServiceFinish);

  // start tasks
  xTaskCreate(TASK_Period_1mS, (signed portCHAR *)"1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS, NULL);
}
コード例 #2
0
ファイル: mbng_patch.c プロジェクト: glocklueng/mios32-org
/////////////////////////////////////////////////////////////////////////////
//! This function initializes the patch structure
/////////////////////////////////////////////////////////////////////////////
s32 MBNG_PATCH_Init(u32 mode)
{
  if( mode != 0 )
    return -1; // only mode 0 supported

  MIOS32_SRIO_DebounceSet(20);
  MIOS32_SRIO_ScanNumSet(MIOS32_SRIO_NUM_SR);
  MBNG_MATRIX_SRIO_ParametersChanged();

  mbng_patch_cfg = mbng_patch_cfg_default;
  mbng_patch_scs = mbng_patch_scs_default;

  SCS_LCD_DeviceSet(0);
  SCS_LCD_OffsetXSet(0);
  SCS_LCD_OffsetYSet(0);
  SCS_NumMenuItemsSet(4); // for 2x20 LCD

  // MIDI router: disable all MIDI IN clocks by default to avoid feedback loops
  midi_router_mclk_in = 0;

  {
    int matrix;
    mbng_patch_matrix_din_entry_t *m = (mbng_patch_matrix_din_entry_t *)&mbng_patch_matrix_din[0];
    for(matrix=0; matrix<MBNG_PATCH_NUM_MATRIX_DIN; ++matrix, ++m) {
      m->num_rows = 8;
      m->flags.ALL = 0;
      m->button_emu_id_offset = 0;
      m->sr_dout_sel1 = 0;
      m->sr_dout_sel2 = 0;
      m->sr_din1  = 0;
      m->sr_din2  = 0;
    }
  }

  {
    int matrix;
    mbng_patch_matrix_dout_entry_t *m = (mbng_patch_matrix_dout_entry_t *)&mbng_patch_matrix_dout[0];
    for(matrix=0; matrix<MBNG_PATCH_NUM_MATRIX_DOUT; ++matrix, ++m) {
      m->num_rows = 8;
      m->flags.ALL = 0;
      m->led_emu_id_offset = 0;
      m->sr_dout_sel1  = 0;
      m->sr_dout_sel2 = 0;
      m->sr_dout_r1 = 0;
      m->sr_dout_r2 = 0;
      m->sr_dout_g1 = 0;
      m->sr_dout_g2 = 0;
      m->sr_dout_r1 = 0;
      m->sr_dout_r2 = 0;
      m->lc_meter_port = 0;
    }
  }

  {
    mbng_patch_ain.enable_mask = 0x0000;

    MIOS32_AIN_DeadbandSet(31); // matches with 7bit

    int pin;
    for(pin=0; pin<MBNG_PATCH_NUM_AIN; ++pin) {
      mbng_patch_ain.cali[pin].min = 0;
      mbng_patch_ain.cali[pin].max = MBNG_PATCH_AIN_MAX_VALUE;
      mbng_patch_ain.cali[pin].spread_center = 0;
    }
  }

  {
    int module;
    mbng_patch_ainser_entry_t *ainser = (mbng_patch_ainser_entry_t *)&mbng_patch_ainser[0];
    for(module=0; module<MBNG_PATCH_NUM_AINSER_MODULES; ++module, ++ainser) {
      ainser->flags.cs = module;
      ainser->flags.resolution = 7; // bit

      AINSER_EnabledSet(module, 0);
      AINSER_MuxedSet(module, 1);
      AINSER_DeadbandSet(module, 31); // matches with 7bit
      AINSER_NumPinsSet(module, AINSER_NUM_PINS);

      int pin;
      for(pin=0; pin<AINSER_NUM_PINS; ++pin) {
	ainser->cali[pin].min = 0;
	ainser->cali[pin].max = MBNG_PATCH_AINSER_MAX_VALUE;
	ainser->cali[pin].spread_center = 0;
      }
    }

    // MAX72xx CS pin
    mbng_patch_max72xx_spi_rc_pin = 0;
  }

  {
    // AOUT CS pin
    mbng_patch_aout_spi_rc_pin = 0;

    // disable module by default, only enable 8 channels by default
    aout_config_t config;
    config = AOUT_ConfigGet();
    config.if_type = AOUT_IF_NONE;
    config.num_channels = 8;
    AOUT_ConfigSet(config);
    AOUT_IF_Init(0);
  }

#if MBNG_PATCH_NUM_DIO > 0
  {
    int dio;

    for(dio=0; dio<MBNG_PATCH_NUM_DIO; ++dio) {
      mbng_patch_dio_cfg[dio].mode = MBNG_PATCH_DIO_CFG_MODE_Off;
      mbng_patch_dio_cfg[dio].emu_sr = 0;
    }
  }
#endif

  return 0; // no error
}