Exemple #1
0
void audio_init() {

  if (audio_initialized) {
    return;
  }

  // Check EEPROM
  #if defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
    if (!eeconfig_is_enabled()) {
      eeconfig_init();
    }
    audio_config.raw = eeconfig_read_audio();
#else // ARM EEPROM
    audio_config.enable = true;
  #ifdef AUDIO_CLICKY_ON
    audio_config.clicky_enable = true;
  #endif
#endif // ARM EEPROM

  /*
   * Starting DAC1 driver, setting up the output pin as analog as suggested
   * by the Reference Manual.
   */
  palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
  palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
  dacStart(&DACD1, &dac1cfg1);
  dacStart(&DACD2, &dac1cfg2);

  /*
   * Starting GPT6/7 driver, it is used for triggering the DAC.
   */
  START_CHANNEL_1();
  START_CHANNEL_2();

  /*
   * Starting a continuous conversion.
   */
  dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE);
  dacStartConversion(&DACD2, &dacgrpcfg2, (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE);

  audio_initialized = true;

  if (audio_config.enable) {
    PLAY_SONG(startup_song);
  } else {
    stop_all_notes();
  }

}
Exemple #2
0
/*
 * Application entry point.
 */
int main(void) {
  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Starting the DAC driver.
   */
  dacStart(&DACD1, &daccfg1);

  /*
   * Sending the dac_buffer
   */
  dacStartConversion(&DACD1, &dacconvgrp1, sine_wave, NSAMPLES);

  while (TRUE) {

  chThdSleepMilliseconds(1000);

  }
}
Exemple #3
0
/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Starting DAC1 driver, setting up the output pins as analog as suggested
   * by the Reference Manual.
   */
  palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
  palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
  dacStart(&DACD1, &dac1cfg1);

  /*
   * Starting GPT6 driver, it is used for triggering the DAC.
   */
  gptStart(&GPTD6, &gpt6cfg1);

  /*
   * Starting a continuous conversion.
   * Note, the buffer size is divided by two because two elements are fetched
   * for each transfer.
   */
  dacStartConversion(&DACD1, &dacgrpcfg1,
                     (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE / 2U);
  gptStartContinuous(&GPTD6, 2U);

  /*
   * Normal main() thread activity, if the button is pressed then the DAC
   * transfer is stopped.
   */
  while (true) {
    if (palReadPad(GPIOA, GPIOA_BUTTON)) {
      gptStopTimer(&GPTD6);
      dacStopConversion(&DACD1);
    }
    chThdSleepMilliseconds(500);
  }
  return 0;
}
Exemple #4
0
static void adctodac(void *arg)
{
    uint16_t temp = 0;
    adcStart(&ADCD1, &adccfg);
    dacStart(&DACD1, &dac1cfg1);

    gptStart(&GPTD6, &gpt6cfg1);

    while(!0)
    {
        adcStartConversion(&ADCD1, &adccg, samples_buf, ADC_BUF_DEPTH);
        temp = samples_buf[0];
        //dacPutChannelX(&DACD1, 1U, temp);
        dacStartConversion(&DACD1, &dacgrpcfg1, samples_buf, ADC_BUF_DEPTH);
        gptStartContinuous(&GPTD6, 2U);
        chThdSleepMilliseconds(1);
    }
}
Exemple #5
0
/*
 * Application entry point.
 */
int main(void) {

  halInit();
  chSysInit();

  /*
  * Set PA3 - PA1 to Analog (DAC1_CH1, OPAMP1_INP)
  * You will have to connect these with a jumper wire
  */
  palSetPadMode(GPIOA, 3, PAL_MODE_INPUT_ANALOG);
  palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_ANALOG);

  /*
   * Start peripherals
   */
  dacStart(&DACD1, &dac1cfg1);
  opampStart(&OPAMPD1, &opamp1_conf);
  gptStart(&GPTD6, &gpt6cfg1);

  /*
   * Starting a continuous conversion.
   */
  dacStartConversion(&DACD1, &dacgrpcfg1, dac_buffer, DAC_BUFFER_SIZE);
  gptStartContinuous(&GPTD6, 2U);

  opampEnable(&OPAMPD1);
  opampCalibrate();

  /*
   * Normal main() thread activity.
   */
  while (true) {

    chThdSleepMilliseconds(250);
    palToggleLine(LINE_LED3_RED);
  }
  return 0;
}
Exemple #6
0
bool dacQueue(AudioBuffer *buffer)
{
  dacStart();
  return false;
}
Exemple #7
0
int main(void)
{
  /*
   * Start OS and HAL
   */

  halInit();
  chSysInit();
  setupIPC();

  DEBUGEN(printf("App Mode\n"));

  usbDisconnectBus(&USBD1);

  /*
   * Initialize extra driver objects.
   */
  sduObjectInit(&SDU1);
  sduObjectInit(&SDU2);

  /*
   * Start peripherals
   */
  sdStart(&SD1, &uart1Cfg);
  sdStart(&SD2, &uart2Cfg);
  sdStart(&SD3, &uart3Cfg);
  usbStart(&USBD1, &usbcfg);
  sduStart(&SDU1, &serusbcfg1);
  sduStart(&SDU2, &serusbcfg2);
  canStart(&CAND1, &cancfg);
  dacStart(&DACD1, &dac1cfg1);
  adcStart(&ADCD1, NULL);
  adcStart(&ADCD3, NULL);
  timcapStart(&TIMCAPD3, &tc_conf);
  pwmStart(&PWMD_LED2, &pwmcfg);

  eeInit();
  // Compare and update versions in EEprom if needed.
  version_t v;
  if (readVersionFromEE(VERSION_IDX_APP, &v) == 0 && memcmp(&versions, &v, sizeof(version_t)) != 0) {

    writeVersionToEE(VERSION_IDX_APP, &versions[VERSION_IDX_APP]);
  }
  if (readVersionFromEE(VERSION_IDX_BL, &v) == 0 ) {
    memcpy(&versions[VERSION_IDX_BL], &v, sizeof(version_t));
  }

  /*
   * Creates the threads.
   */
  chThdCreateStatic(waThreadBDU, sizeof(waThreadBDU), NORMALPRIO+5, ThreadBDU, NULL);
  chThdCreateStatic(waThreadSDU, sizeof(waThreadSDU), NORMALPRIO+2, ThreadSDU, NULL);
  chThdCreateStatic(waThreadADC, sizeof(waThreadADC), NORMALPRIO, ThreadADC, NULL);
  chThdCreateStatic(waThreadKnock, sizeof(waThreadKnock), NORMALPRIO, ThreadKnock, NULL);
  chThdCreateStatic(waThreadCAN, sizeof(waThreadCAN), NORMALPRIO, ThreadCAN, NULL);
  chThdCreateStatic(waThreadSER1, sizeof(waThreadSER1), NORMALPRIO, ThreadSER1, NULL);
  chThdCreateStatic(waThreadRecord, sizeof(waThreadRecord), NORMALPRIO+1, ThreadRecord, NULL);
  chThdCreateStatic(waThreadWdg, sizeof(waThreadWdg), HIGHPRIO, ThreadWdg, NULL);

  /* Create last as it uses pointers from above */
  chThdCreateStatic(waThreadMonitor, sizeof(waThreadMonitor), NORMALPRIO+10, ThreadMonitor, NULL);

  while (TRUE)
  {
    while(USBD1.state != USB_READY) chThdSleepMilliseconds(10);

    chThdSleepMilliseconds(100);

    if (usbConnected())
    {
      usbConnectBus(&USBD1);
    }
    else
    {
      usbDisconnectBus(&USBD1);
    }
  }
}
Exemple #8
0
/****************** Thread main loop ***********************************/
msg_t analogue_thread(void *args)
{
    (void)args;

    chRegSetThreadName("Analogue");
    chBSemObjectInit(&bsAnalogueInst, true);
    chBSemObjectInit(&bsAnalogueFX, true);

    adcInit();
    adcStart(&ADCD1, NULL);
    adcStart(&ADCD2, NULL);
    adcStartConversion(&ADCD1, &adc_con_group_1, (adcsample_t*)buffer1,
                       INST_BUF_DEPTH);
    adcStartConversion(&ADCD2, &adc_con_group_2, (adcsample_t*)fx_samples,
                       FX_BUF_DEPTH);

    dacInit();
    dacStart(&DACD1, &dac_cfg);
    dacStartConversion(&DACD1, &dac_conv_grp, (dacsample_t*)buffer3,
                       INST_BUF_DEPTH);
    // Enable DAC output buffer:
    DACD1.params->dac->CR |= DAC_CR_BOFF1;

    /* Start the GPT timers. They reload at after reaching 1 such that
     * TRGO frequency equals timer frequency. */
    gptStart(&GPTD3, &gpt_inst_config);
    GPTD3.tim->CR2 |= STM32_TIM_CR2_MMS(2);
    gptStartContinuous(&GPTD3, 2);
    GPTD3.tim->DIER &= ~STM32_TIM_DIER_UIE;

    gptStart(&GPTD8, &gpt_fx_config);
    GPTD8.tim->CR2 |= STM32_TIM_CR2_MMS(2);
    gptStartContinuous(&GPTD8, 2);
    GPTD8.tim->DIER &= ~STM32_TIM_DIER_UIE;

    state = 1;

    // States:
    // 1 - ADC:buf1, DSP:buf2, DAC:buf3
    // 2 - DSP:buf1, DAC:buf2, ADC:buf3
    // 3 - DAC:buf1, ADC:buf2, DSP:buf3

    /* Wait until the ADC callback boops the semaphore. */
    volatile uint16_t *dsp_buf;
    while(true) {
        chSysLock();
        chBSemWaitS(&bsAnalogueInst);
        chSysUnlock();

        state += 1;

        switch(state)
        {
            case 1:
                dmaSetOtherMemory(ADCD1.dmastp, buffer1);
                dsp_buf = buffer2;
                dmaSetOtherMemory(DACD1.params->dma, buffer3);
                break;
            case 2:
                dmaSetOtherMemory(ADCD1.dmastp, buffer3);
                dsp_buf = buffer1;
                dmaSetOtherMemory(DACD1.params->dma, buffer2);
                break;
            case 3:
                dmaSetOtherMemory(ADCD1.dmastp, buffer2);
                dsp_buf = buffer3;
                dmaSetOtherMemory(DACD1.params->dma, buffer1);
                break;
            default:
                state = 1;
                dmaSetOtherMemory(ADCD1.dmastp, buffer1);
                dsp_buf = buffer2;
                dmaSetOtherMemory(DACD1.params->dma, buffer3);
        }
        dsp_stuff(dsp_buf);
    }
}