Ejemplo n.º 1
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
 uint32_t random32bit = 0;
 uint32_t counter = 0;

  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */

  /* Display init (LCD or/and USART)*/
  Display_Init();
  
  /* Key Button configuration */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
  
  /* RNG configuration */
  RNG_Config();

  while (1)
  {
    /* Wait until Key button is pressed */
    while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET)
    {
    }
    /* Loop while Key button is maintained pressed */
    while(STM_EVAL_PBGetState(BUTTON_KEY) == RESET)
    {
    }

    for(counter = 0; counter < 8; counter++)
    {
      /* Wait until one RNG number is ready */
      while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET)
      {
      }

      /* Get a 32bit Random number */       
      random32bit = RNG_GetRandomNumber();

      /* Display the Random number value on the LCD or/and USART */
      Display(random32bit, counter+1);
    }
  }
}
Ejemplo n.º 2
0
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
	
//initiate user button
  PB_Config();

	//initiate LEDs and turn them on
  LED_Config();	
	
 

  /* -----------------------------------------------------------------------
    TIM3 Configuration: Output Compare Timing Mode:
    
    In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), 
    since APB1 prescaler is different from 1.   
      TIM3CLK = 2 * PCLK1  
      PCLK1 = HCLK / 4 
      => TIM3CLK = HCLK / 2 = SystemCoreClock /2
          
    To get TIM3 counter clock at 50 MHz, the prescaler is computed as follows:
       Prescaler = (TIM3CLK / TIM3 counter clock) - 1
       Prescaler = ((SystemCoreClock /2) /0.5 MHz) - 1
                                              
    CC1 update rate = TIM3 counter clock / CCR1_Val = 10.0 Hz
    ==> Toggling frequency = 5 Hz

    Note: 
     SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
     Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
     function to update SystemCoreClock variable value. Otherwise, any configuration
     based on this variable will be incorrect.    
		 ----------------------------------------------------------------------- */ 	
	
	//=======================Configure and init Timer======================
  /* Compute the prescaler value */
  PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 500000) - 1;

 /* TIM Configuration */
  TIM3_Config();

	// configure the output compare
	TIM3_OCConfig();

  /* TIM Interrupts enable */
  TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);

  /* TIM3 enable counter */
  TIM_Cmd(TIM3, ENABLE);
	
//======================================configure and init LCD  ======================	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
	
//================EEPROM init====================================

/* Unlock the Flash Program Erase controller */
		FLASH_Unlock();
		/* EEPROM Init */
		EE_Init();
		

//============ Set up for random number generation==============
	RNG_Config();


	//with the default font, LCD can display  12 lines of chars, they are LINE(0), LINE(1)...LINE(11) 
	//with the default font, LCD can display  15 columns, they are COLUMN(0)....COLUMN(14)


		LCD_Clear(LCD_COLOR_WHITE);
			
	

		
		LCD_DisplayStringLine(LINE(0),  (uint8_t *) "Attempt");
		LCD_DisplayStringLine(LINE(2),  (uint8_t *) "Record");
		
		EE_WriteVariable(VirtAddVarTab[0],VarValue);
		EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
		sprintf(str, "%d", VarDataTab[0]);
		//LCD_DisplayStringLine(LINE(3),  (uint8_t *) str);
		//randomNumber = RNG_GetRandomNumber()/100000;

		//sprintf(str, "%d", randomNumber());
		//LCD_DisplayStringLine(LINE(5),  (uint8_t *) str);
		
		resetTimer();
		
		/*the following while loop is where the main part of the code is
		* it currently uses the userbutton on board since Mario forgot to bring along his
		* jumper cables to test out the push button part
		*/
		
		//if toggle = 0 lights are  blinking
		//if toggle = 1 2 second wait
		//if toggle = 2 LED toggle off, the lights stay on
		
		//@TODO add external push button to code
		externalButton();
  while (1){ 
			int num = TIM_GetCounter(TIM3);
		//This is for the start of the procedure 
		if(toggle==0){
			if(num == 3000){
					STM_EVAL_LEDOn(LED3);
				  STM_EVAL_LEDOn(LED4);
			}
			else if(num == 6000){
					STM_EVAL_LEDOff(LED3);
					STM_EVAL_LEDOff(LED4);
					resetTimer();
			}
		}
			//if the user button has been pressed and the lights are blinking
			if (UBPressed==1 && toggle==0) {
				STM_EVAL_LEDOff(LED3);
				STM_EVAL_LEDOff(LED4);
				UBPressed=0;
				PB_Config();
				resetTimerLong();
				toggle = 1;
				rand = randomNumber();//generate a random number 
			}

			//this is the to get the wait time for the reaction test.
			if(toggle==1){
					if(num == rand){ //if num is equal to the ramdom gened number turn on the LEDs and reset the timer
							STM_EVAL_LEDOn(LED3);
							STM_EVAL_LEDOn(LED4);
							resetTimerLong();
					}
			}
			//this is the code for when the reaction timer has gone off
			if (UBPressed==1 && toggle==1) {
				 
				//this if statement is to prevent cheating
				//if the number = 0 it means that the user cheated as someone should not be able to get 0
				if(num == 0){
					ExtButtonPressed=0;
					PB_Config();
					externalButton();
					resetTimer();
					toggle = 0;
				}else{
				sprintf(str, "%d", num);
				//this block of code writes to the LCD the lastest user reaction time.
				LCD_DisplayStringLine(LINE(1),  (uint8_t *) "          ");
				LCD_DisplayStringLine(LINE(1),  (uint8_t *) str);
				EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
				//this if statement determines wheter the user has beat their best reaction time
				if(num < VarDataTab[0]){
						VarValue = num;
						EE_WriteVariable(VirtAddVarTab[0],VarValue);
				}
				/*the following block of code writes to the LCD the record reaction time*/
				EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
				sprintf(str, "%d", VarDataTab[0]);
				LCD_DisplayStringLine(LINE(3),  (uint8_t *) "          ");
				LCD_DisplayStringLine(LINE(3),  (uint8_t *) str);
				UBPressed=0;
				PB_Config();
				resetTimerLong();
				toggle = 2; 
			}
			}
			//the user needs to press the button to get the reaction time game going again. 
			//to reset the reaction timer
			if (ExtButtonPressed==1) {
				ExtButtonPressed=0;
				PB_Config();
				externalButton();
				resetTimer();
				toggle = 0;
			}
			
	}
	
}
Ejemplo n.º 3
0
int main(void)
{
	RNG_Config();

	LCDTFT lcd = LCDTFT();

	/* Set LCD foreground layer */
	lcd.LCD_SetLayer(LCD_FOREGROUND_LAYER);
	lcd.LCD_SetTransparency(0);

	/* Set LCD background layer */
	lcd.LCD_SetLayer(LCD_BACKGROUND_LAYER);
	lcd.LCD_Clear(LCD_COLOR_WHITE);

	//int j = 0;

	//lcd.LCD_DrawStraigtLine(50,49, 150, 0, LCD_COLOR_BLACK);

	/*lcd.LCD_DrawLine(50,50,50,200,LCD_COLOR_BLUE);
	lcd.LCD_DrawLine(50,50,100,200,LCD_COLOR_BLUE);
	lcd.LCD_DrawLine(50,50,200,200,LCD_COLOR_RED);
	lcd.LCD_DrawLine(50,50,200,100,LCD_COLOR_BLACK);
	lcd.LCD_DrawLine(50,50,200,50,LCD_COLOR_BLACK);*/

	//uint32_t * u = ;



	int x = 0;
	int left = 0;
	int i,j,k,l;

	while(1)
	{
		if(left == 0)
		{
			x++;
			if(x>(240-50))
				left = 1;
		}
		else
		{
			x--;
			if(x==-100)
				left = 0;
		}

		lcd.LCD_DrawBMP(x, 50, (uint32_t)&image565);

		for(i = 0; i < 100000; i++);

		/*j++;
		while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET);
		int i1 = RNG_GetRandomNumber()%240;
		while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET);
		int i2 = RNG_GetRandomNumber()%360;
		while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET);
		int i3 = RNG_GetRandomNumber()%100;
		while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET);
		int i4 = RNG_GetRandomNumber()%2;

		while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET);
		//LCD_SetTextColor(RNG_GetRandomNumber());
		lcd.LCD_DrawLine(i1, i2, i3, i4, RNG_GetRandomNumber());

		while(RNG_GetFlagStatus(RNG_FLAG_DRDY)== RESET);
		int i = RNG_GetRandomNumber()%1000000;
		for(;i>0;i--);
		if(j>10)
			while(1);*/
	}
}
Ejemplo n.º 4
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);
    }


}
Ejemplo n.º 5
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
	
//initiate user button
  //PB_Config();
	STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);

	//initiate LEDs and turn them on
  LED_Config();	
	
 

  /* -----------------------------------------------------------------------
    TIM3 Configuration: Output Compare Timing Mode:
    
    In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), 
    since APB1 prescaler is different from 1.   
      TIM3CLK = 2 * PCLK1  
      PCLK1 = HCLK / 4 
      => TIM3CLK = HCLK / 2 = SystemCoreClock /2
          
    To get TIM3 counter clock at 50 MHz, the prescaler is computed as follows:
       Prescaler = (TIM3CLK / TIM3 counter clock) - 1
       Prescaler = ((SystemCoreClock /2) /0.5 MHz) - 1
                                              
    CC1 update rate = TIM3 counter clock / CCR1_Val = 10.0 Hz
    ==> Toggling frequency = 5 Hz

    Note: 
     SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
     Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
     function to update SystemCoreClock variable value. Otherwise, any configuration
     based on this variable will be incorrect.    
		 ----------------------------------------------------------------------- */ 	
	
	//=======================Configure and init Timer======================
  /* Compute the prescaler value */
  PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 500000) - 1; //configures clock speed at 500 KHz. Both Tim2 and Tim3 use the same prescsaler and therefore run at the same speed.

 /* TIM Configuration */
  TIM3_Config();
	TIM2_Config();

	// configure the output compare
	TIM3_OCConfig();
	TIM2_OCConfig();

  /* TIM Interrupts enable */
  TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
	TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
	
  /* TIM3 enable counter */
  TIM_Cmd(TIM3, ENABLE);
	TIM_Cmd(TIM2, ENABLE); 
	
//======================================configure and init LCD  ======================	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
	
//================EEPROM init====================================

/* Unlock the Flash Program Erase controller */
		FLASH_Unlock();
		/* EEPROM Init */
		EE_Init();

//============ Set up for random number generation==============
	RNG_Config();
	Ext_PushButton_Interrupt(); //configures external push button

	//with the default font, LCD can display  12 lines of chars, they are LINE(0), LINE(1)...LINE(11) 
	//with the default font, LCD can display  15 columns, they are COLUMN(0)....COLUMN(14)


		LCD_Clear(LCD_COLOR_WHITE); //change the background colour of LCD 
			
		//Display a string in one line, on the first line (line=0)
		LCD_DisplayString(0, 2, (uint8_t *) "Best: ");  //the line will not wrap
		
  while (1){ 
		
			if (UBPressed==1) { //press user button
					if (pause==1){	//pause mode
						randnum = ((RNG_GetRandomNumber()%2000)+1000); //generates a random number between 1000 and 3000
						Pause_Random(randnum); //see below function to see how the pause is implemented
					}
					else { //measure time mode
						TIM_ITConfig(TIM2, TIM_IT_CC1, DISABLE); //turns off timer 2
						TIM_Cmd(TIM2, DISABLE);
						time = timer; //gets user's time
						if (initial == 1) { //sets initial best_time to first time 
						best_time = time; 
						initial = 0;
						LCD_DisplayInt((uint16_t) 0, (uint16_t) 7, best_time);
						} 
						LCD_DisplayString(2, 1, (uint8_t *) "Time: "); //print time
						LCD_DisplayString(2, 7, (uint8_t *) "                 "); //clears line
						LCD_DisplayInt((uint16_t) 2, (uint16_t) 7, time); //displays user's time
						LCD_DisplayString(2, 11, (uint8_t *) "ms"); //print ms
						if (time > 10 && time < best_time) { //set new best time
							best_time = time;
							LCD_DisplayString(0, 7, (uint8_t *) "          "); //clears line
							LCD_DisplayInt((uint16_t) 0, (uint16_t) 7, best_time);
						}
						TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE); //turns on timer 2
						TIM_Cmd(TIM2, ENABLE);
						pause = 1; //this makes it so that you can use the user button to repeat the cycle in case you don't have an external push button
					}
				UBPressed=0;				
			}

	}
}