예제 #1
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  uint32_t x;
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f072xb.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */

  /* initialization of the tables values for DAC signal generations */
  for (x = 0; x < SIN1_ARRAY_SIZE; x++)
  {
    sin1_data[x] = (uint32_t) GenerateWave(INCREMENT1, DAC_AMPL_MAX); /* as the DAC buffer are enabled */
    sin1_data[x] += sin1_data[x] << 16;
  }
  
  ConfigureGPIO();
  ConfigureGPIOasAnalog();
  ConfigureDAC();
  ConfigureDMA();
  ConfigureTIM7();
  __WFI(); /* If an error occurs or the execution is stop by debugger, the wait mode is exited */
  SysTick_Config(48000); /* 1ms config */
  while (1) /* Infinite loop only reach in case of error */
  {    
  }
}
예제 #2
0
파일: main.c 프로젝트: pyjhhh/stm32_f1x
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  uint32_t x;
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f072xb.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */

  /* initialization of the tables values for DAC signal generations */
  for (x = 0; x < SIN1_ARRAY_SIZE; x++)
  {
    sin1_data[x] = GenerateWave(INCREMENT1, DAC_AMPL_MAX); /* DAC 1 has its buffer enabled */
  }
  
  ConfigureGPIOasAnalog();
  ConfigureDAC();
  x = 0;
  while (1) /* Infinite loop only reach in case of error */
  {    
    DAC->DHR12RD = (uint32_t)((sin1_data[x] << 16) + sin1_data[x]);
    x++;
    if (x >= SIN1_ARRAY_SIZE)
    {
      x = 0;
    }
  }
}
예제 #3
0
// Initializes a background "wave" effect that affects scanlines startLine (inclusive) to endLine (exclusive).
// 'frequency' and 'amplitude' control the frequency and amplitude of the wave.
// 'delayInterval' controls how fast the wave travels up the screen. The wave will shift upwards one scanline every 'delayInterval'+1 frames.
// 'regOffset' is the offset of the video register to modify.
u8 ScanlineEffect_InitWave(u8 startLine, u8 endLine, u8 frequency, u8 amplitude, u8 delayInterval, u8 regOffset, bool8 applyBattleBgOffsets)
{
    int i;
    int offset;
    struct ScanlineEffectParams params;
    u8 taskId;

    ScanlineEffect_Clear();

    params.dmaDest = (void *)(REG_ADDR_BG0HOFS + regOffset);
    params.dmaControl = SCANLINE_EFFECT_DMACNT_16BIT;
    params.initState = 1;
    params.unused9 = 0;
    ScanlineEffect_SetParams(params);

    taskId = CreateTask(TaskFunc_UpdateWavePerFrame, 0);

    gTasks[taskId].tStartLine            = startLine;
    gTasks[taskId].tEndLine              = endLine;
    gTasks[taskId].tWaveLength           = 256 / frequency;
    gTasks[taskId].tSrcBufferOffset      = 0;
    gTasks[taskId].tFramesUntilMove      = delayInterval;
    gTasks[taskId].tDelayInterval        = delayInterval;
    gTasks[taskId].tRegOffset            = regOffset;
    gTasks[taskId].tApplyBattleBgOffsets = applyBattleBgOffsets;

    gScanlineEffect.waveTaskId = taskId;
    sShouldStopWaveTask = FALSE;

    GenerateWave(&gScanlineEffectRegBuffers[0][320], frequency, amplitude, endLine - startLine);

    offset = 320;
    for (i = startLine; i < endLine; i++)
    {
        gScanlineEffectRegBuffers[0][i] = gScanlineEffectRegBuffers[0][offset];
        gScanlineEffectRegBuffers[1][i] = gScanlineEffectRegBuffers[0][offset];
        offset++;
    }

    return taskId;
}