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(); } }
void audio_init() { /* check signature */ if (!eeconfig_is_enabled()) { eeconfig_init(); } audio_config.raw = eeconfig_read_audio(); #ifdef PWM_AUDIO PLLFRQ = _BV(PDIV2); PLLCSR = _BV(PLLE); while(!(PLLCSR & _BV(PLOCK))); PLLFRQ |= _BV(PLLTM0); /* PCK 48MHz */ /* Init a fast PWM on Timer4 */ TCCR4A = _BV(COM4A0) | _BV(PWM4A); /* Clear OC4A on Compare Match */ TCCR4B = _BV(CS40); /* No prescaling => f = PCK/256 = 187500Hz */ OCR4A = 0; /* Enable the OC4A output */ DDRC |= _BV(PORTC6); TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs TCCR3A = 0x0; // Options not needed TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback #else DDRC |= _BV(PORTC6); TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30); TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30); #endif inited = true; }
void audio_init() { // Check EEPROM if (!eeconfig_is_enabled()) { eeconfig_init(); } audio_config.raw = eeconfig_read_audio(); // Set port PC6 (OC3A and /OC4A) as output DDRC |= _BV(PORTC6); DISABLE_AUDIO_COUNTER_3_ISR; // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers // Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6 // Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14 (Period = ICR3, Duty Cycle = OCR3A) // Clock Select (CS3n) = 0b010 = Clock / 8 TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30); TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30); audio_initialized = true; }
void audio_init() { // Check EEPROM if (!eeconfig_is_enabled()) { eeconfig_init(); } audio_config.raw = eeconfig_read_audio(); if (!audio_initialized) { // Set audio ports as output #ifdef CPIN_AUDIO CPIN_SET_DIRECTION DISABLE_AUDIO_COUNTER_3_ISR; #endif #ifdef BPIN_AUDIO BPIN_SET_DIRECTION DISABLE_AUDIO_COUNTER_1_ISR; #endif // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers TCCR3A/TCCR3B, TCCR1A/TCCR1B // Compare Output Mode (COM3An and COM1An) = 0b00 = Normal port operation // OC3A -- PC6 // OC3B -- PC5 // OC3C -- PC4 // OC1A -- PB5 // OC1B -- PB6 // OC1C -- PB7 // Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14. Period = ICR3, Duty Cycle OCR3A) // OCR3A - PC6 // OCR3B - PC5 // OCR3C - PC4 // OCR1A - PB5 // OCR1B - PB6 // OCR1C - PB7 // Clock Select (CS3n) = 0b010 = Clock / 8 #ifdef CPIN_AUDIO INIT_AUDIO_COUNTER_3 TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30); TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER)); TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre); #endif #ifdef BPIN_AUDIO INIT_AUDIO_COUNTER_1 TCCR1B = (1 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (0 << CS10); TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER)); TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre); #endif audio_initialized = true; } if (audio_config.enable) { PLAY_SONG(startup_song); } }