示例#1
0
inline void delay_ms(unsigned int ms) {
    PreenFM2_uDelay(ms * 1000);
}
示例#2
0
// I2C configuration
static void codec_init()
{
  //uint32_t delaycount;
  uint8_t CodecCommandBuffer[5];

  uint8_t regValue = 0xFF;

  GPIO_SetBits(CODEC_RESET_PORT, CODEC_RESET_PIN);
  //delaycount = 10000000;
  //while (delaycount > 0)
  //{
  //	  delaycount--;
  //}
  PreenFM2_uDelay(100);

  //keep codec OFF
  CodecCommandBuffer[0] = CODEC_MAP_PLAYBACK_CTRL1;
  CodecCommandBuffer[1] = 0x01;
  send_codec_ctrl(CodecCommandBuffer, 2);

  //begin initialization sequence (p. 32)
  CodecCommandBuffer[0] = 0x00;
  CodecCommandBuffer[1] = 0x99;
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = 0x47;
  CodecCommandBuffer[1] = 0x80;
  send_codec_ctrl(CodecCommandBuffer, 2);

  regValue = read_codec_register(0x32);

  CodecCommandBuffer[0] = 0x32;
  CodecCommandBuffer[1] = regValue | 0x80;
  send_codec_ctrl(CodecCommandBuffer, 2);

  regValue = read_codec_register(0x32);

  CodecCommandBuffer[0] = 0x32;
  CodecCommandBuffer[1] = regValue & (~0x80);
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = 0x00;
  CodecCommandBuffer[1] = 0x00;
  send_codec_ctrl(CodecCommandBuffer, 2);
  //end of initialization sequence

  CodecCommandBuffer[0] = CODEC_MAP_PWR_CTRL2;
  CodecCommandBuffer[1] = 0xAF;
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = CODEC_MAP_PLAYBACK_CTRL1;
  CodecCommandBuffer[1] = 0x70;
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = CODEC_MAP_CLK_CTRL;
  CodecCommandBuffer[1] = 0x80; //0x81; //auto detect clock
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = CODEC_MAP_IF_CTRL1;
  CodecCommandBuffer[1] = 0x05; //24bit
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = 0x0A;
  CodecCommandBuffer[1] = 0x00;
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = 0x27;
  CodecCommandBuffer[1] = 0x00;
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = 0x1A | CODEC_MAPBYTE_INC;
  CodecCommandBuffer[1] = 0x0A;
  CodecCommandBuffer[2] = 0x0A;
  send_codec_ctrl(CodecCommandBuffer, 3);

  CodecCommandBuffer[0] = 0x1F;
  CodecCommandBuffer[1] = 0x0F;
  send_codec_ctrl(CodecCommandBuffer, 2);

  CodecCommandBuffer[0] = CODEC_MAP_PWR_CTRL1;
  CodecCommandBuffer[1] = 0x9E;
  send_codec_ctrl(CodecCommandBuffer, 2);
}
示例#3
0
void setup() {
    lcd.begin(20, 4);

    LCD_InitChars(&lcd);

    for (int r=0; r<20; r++) {
    	lcd.setCursor(r,0);
    	lcd.print((char)0);
    	lcd.setCursor(r,1);
    	lcd.print((char)0);
    	lcd.setCursor(r,2);
    	lcd.print((char)0);
    	lcd.setCursor(r,3);
    	lcd.print((char)0);
    }

    LED_Config();
	USART_Config();
	MCP4922_Config();
	RNG_Config();

	// Set flush to zero mode...
	// FPU will treat denormal value as 0

	//	You can avoid some of these support code requirements by:
	//enabling flush-to-zero mode, by setting the FZ bit, FPSCR[24], to 1
	//enabling default NaN mode, by setting the DN bit, FPSCR[25], to 1.
	//Some of the other support code requirements only occur when the appropriate feature is enabled. You enable:
	//Inexact exceptions by setting the IXE bit, FPSCR[12], to 1
	//Overflow exceptions by setting the OFE bit, FPSCR[10], to 1
	//Invalid Operation exceptions by setting the IOE bit, FPSCR[8], to 1.
	// Fast mode
	FPU->FPDSCR |= FPU_FPDSCR_FZ_Msk;
	FPU->FPDSCR |= FPU_FPDSCR_DN_Msk;
	FPU->FPDSCR &= ~(1UL << 12);
	FPU->FPDSCR &= ~(1UL << 10);
	FPU->FPDSCR &= ~(1UL << 8);
    // ---------------------------------------
    // Dependencies Injection

    // to SynthStateAware Class
    // MidiDecoder, Synth (Env,Osc, Lfo, Matrix, Voice ), FMDisplay, PresetUtil...

    synth.setSynthState(&synthState);
    fmDisplay.setSynthState(&synthState);
    midiDecoder.setSynthState(&synthState);
    midiDecoder.setVisualInfo(&fmDisplay);
    midiDecoder.setSynth(&synth);
    midiDecoder.setStorage(&usbKey);

    // ---------------------------------------
    // Register listener

    // synthstate is updated by encoder change
    encoders.insertListener(&synthState);

    // fmDisplay and synth needs to be aware of synthState changes
    // synth must be first one, can modify param new value
    /// order of param listener is important... synth must be called first so it's inserted last.
    synthState.insertParamListener(&fmDisplay);
    synthState.insertParamListener(&midiDecoder);
    synthState.insertParamListener(&synth);
    synthState.insertMenuListener(&fmDisplay);
    // Synth can check and modify param new value
    synthState.insertParamChecker(&synth);

    synthState.setStorage(&usbKey);
    synthState.setHexter(&hexter);

    usbKey.init(synth.getTimbre(0)->getParamRaw(), synth.getTimbre(1)->getParamRaw(), synth.getTimbre(2)->getParamRaw(), synth.getTimbre(3)->getParamRaw());
    usbKey.setSysexSender(&midiDecoder);
    // usbKey and hexter needs to know if arpeggiator must be loaded and saved
    usbKey.setArpeggiatorPartOfThePreset(&synthState.fullState.midiConfigValue[MIDICONFIG_ARPEGGIATOR_IN_PRESET]);
    hexter.setArpeggiatorPartOfThePreset(&synthState.fullState.midiConfigValue[MIDICONFIG_ARPEGGIATOR_IN_PRESET]);
    usbKey.loadConfig(synthState.fullState.midiConfigValue);



    SysTick_Config();
    synth.buildNewSampleBlock();
    synth.buildNewSampleBlock();

    // shorten the release value for init sound...
    ((OneSynthParams*)synth.getTimbre(0)->getParamRaw())->env1b.releaseTime = 1.1f;
    ((OneSynthParams*)synth.getTimbre(0)->getParamRaw())->env4b.releaseTime = 0.8f;

    bool displayline1 = true;
    for (int r=0; r<20; r++) {
    	if (r<10 && (r & 0x1) == 0) {
			GPIO_SetBits(GPIOB, GPIO_Pin_6);
    	} else {
    		GPIO_ResetBits(GPIOB, GPIO_Pin_6);
    	}

    	switch (r) {
    	case 0:
        	synth.noteOn(0, 40, 120);
        	break;
    	case 1:
    		synth.noteOff(0, 40);
    		break;
    	case 3:
        	synth.noteOn(0, 52, 120);
        	break;
    	case 4:
    		synth.noteOff(0,52);
    		break;
    	}

    	for (char s=1; s<6; s++) {
    	    fillSoundBuffer();
			lcd.setCursor(r,0);
			lcd.print(s);
		    fillSoundBuffer();
			lcd.setCursor(r,1);
			lcd.print(s);
		    fillSoundBuffer();
			lcd.setCursor(r,2);
			lcd.print(s);
		    fillSoundBuffer();
			lcd.setCursor(r,3);
			lcd.print(s);
		    for (int i=0; i<100; i++) {
		        fillSoundBuffer();
				PreenFM2_uDelay(50);
		    }
    	}

        fillSoundBuffer();


    	if (displayline1) {
    		if (line1[r] != 0) {
    			lcd.setCursor(r,1);
    			lcd.print(line1[r]);
    		} else {
    			displayline1 = false;
    		}
    	}

        fillSoundBuffer();
		lcd.setCursor(r,2);
		lcd.print(line2[r]);
	    fillSoundBuffer();
    }


    // launch the engine !!
    // Init DAC number
//    if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8) == Bit_SET) {
//		lcd.setCursor(17,3);
//		lcd.print("R4g");
//    } else {
//		lcd.setCursor(17,3);
//		lcd.print("R4f");
//    }


    for (int i=0; i<4000; i++) {
        fillSoundBuffer();
		PreenFM2_uDelay(250);
    }



    // FS = Full speed : midi
    // HS = high speed : USB Key
    // Init core FS as a midiStreaming device
    if (synthState.fullState.midiConfigValue[MIDICONFIG_USB] != USBMIDI_OFF) {
    	USBD_Init(&usbOTGDevice, USB_OTG_FS_CORE_ID, &usbdMidiDescriptor, &midiCallback, &midiStreamingUsrCallback);
    }

    if (usbKey.loadDefaultCombo()) {
    	synthState.propagateAfterNewComboLoad();
    }

    fmDisplay.init(&lcd, &usbKey);

    int bootOption = synthState.fullState.midiConfigValue[MIDICONFIG_BOOT_START];

    if (bootOption == 0) {
        fmDisplay.displayPreset();
        fmDisplay.setRefreshStatus(12);
    } else {
        // Menu
        synthState.buttonPressed(BUTTON_MENUSELECT);
        // Load
        synthState.buttonPressed(BUTTON_MENUSELECT);
        if (bootOption == 1) {
        	// Bank
            synthState.buttonPressed(BUTTON_MENUSELECT);
        } else if (bootOption == 2) {
        	// Combo
            synthState.encoderTurned(0, 1);
            synthState.buttonPressed(BUTTON_MENUSELECT);
        } else if (bootOption == 3) {
        	// DX7
            synthState.encoderTurned(0, 1);
            synthState.encoderTurned(0, 1);
            synthState.buttonPressed(BUTTON_MENUSELECT);
        }
        // First preset...
        synthState.buttonPressed(BUTTON_MENUSELECT);
    }


}