예제 #1
0
파일: main.c 프로젝트: szymon2103/Stm32
/**
  * @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_stm32f2xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f2xx.c file
     */

  /* Preconfiguration before using DAC----------------------------------------*/
  GPIO_InitTypeDef GPIO_InitStructure;

  /* DMA1 clock and GPIOA clock enable (to be used with DAC) */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_GPIOA, ENABLE);

  /* DAC Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

  /* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* TIM6 Configuration ------------------------------------------------------*/
  TIM6_Config();

  /* Configures Key Button */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

  while (1)
  {
    /* If the Key is pressed */
    if (KeyPressed != RESET)
    {
      DAC_DeInit();

      /* select waves forms according to the Key Button status */
      if (SelectedWavesForm == 1)
      {
        /* The sine wave and the escalator wave has been selected */

        /* Escalator Wave generator ------------------------------------------*/
        DAC_Ch1_EscalatorConfig();

        /* Sine Wave generator -----------------------------------------------*/
        DAC_Ch2_SineWaveConfig();

      }
      else
      {
        /* The triangle wave and the noise wave has been selected */

        /* Noise Wave generator ----------------------------------------------*/
        DAC_Ch1_NoiseConfig();

        /* Triangle Wave generator -------------------------------------------*/
        DAC_Ch2_TriangleConfig();
      }

      KeyPressed = RESET;
    }
  }
}
예제 #2
0
파일: main.c 프로젝트: EQ4/SMR
void main(void)
{
	int32_t t_spread;
	uint32_t i;

    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);

	LED_ON(LED_RING_OE); //actually turns the LED ring off
	LEDDriver_Init(5);
	for (i=0;i<26;i++)	LEDDriver_setRGBLED(i,0);
	LED_OFF(LED_RING_OE); //actually turns the LED ring on

	flag_update_LED_ring=1;


	init_inouts();
	init_rotary();
	init_envout_pwm();

	ADC1_Init((uint16_t *)adc_buffer);
	ADC3_Init((uint16_t *)potadc_buffer);

	Codec_Init(SAMPLERATE);

	delay();

	set_default_param_values();

	set_default_color_scheme();

	set_default_user_scalebank();

	//overwrite default parameters if a startup bank exists
	cur_param_bank = load_startup_params();

	if (cur_param_bank == 0xFF){
		factory_reset();
		cur_param_bank=0;
	}

	I2S_Block_Init();

	TIM6_Config();
	DAC_Ch1_NoiseConfig();

	spread=(adc_buffer[SPREAD_ADC] >> 8) + 1;

	I2S_Block_PlayRec();

	//update_spread(1);

	while(1){

		check_errors();

		param_read_switches();

		update_ENVOUT_PWM();

		update_LED_ring();

		update_lock_leds();

		t_spread=read_spread();

		if (t_spread!=-1) update_spread(t_spread);

		process_lock_jacks();

		process_lock_buttons();

		param_read_q();

		param_read_freq_nudge();

		param_read_channel_level();

		process_rotary_button();

		process_rotary_rotation();

		if (ui_mode==PLAY)
			check_rotary_pressed_repeatedly();

		if (ui_mode==EDIT_SCALES)
			handle_edit_scale();

		if (ui_mode==EDIT_COLORS)
			handle_edit_colors();

		if (ui_mode==SELECT_PARAMS){
			handle_freqpot_changing_filtermode();
			handle_slider_changing_clipmode();
		}

		if (do_ROTUP){
			do_ROTUP=0;
			rotate_up();
		}


		if (do_ROTDOWN){
			do_ROTDOWN=0;
			rotate_down();
		}

		process_rotateCV();

		process_scaleCV();

	} //end main loop


} //end main()