collab/PineapplePad
git clone https://git.julia.blue/collab/PineapplePad
14d8b4f
master
1#include <stdint.h> 2#include "../inc/dac.h" 3#include "../inc/sound.h" 4#include "../inc/tm4c123gh6pm.h" 5#include "../inc/IO.h" 6 7const uint8_t * instruments []= {horn ,guitar ,basoon ,sine ,basoon }; 8 9const uint8_t * instrument ; 10 11void Timer0A_Init (void ){ 12SYSCTL_RCGCTIMER_R |=0x01 ; 13TIMER0_CTL_R = 0 ; 14TIMER0_CFG_R = 0 ; 15TIMER0_TAMR_R = 0x02 ; 16TIMER0_TAPR_R = 0 ; 17TIMER0_ICR_R = 0x01 ; 18TIMER0_IMR_R = 0x01 ; 19NVIC_PRI4_R = (NVIC_PRI4_R & 0x00FFFFFF ) |0x40000000 ; 20NVIC_EN0_R = 1 <<19 ; 21TIMER0_CTL_R = 1 ; 22} 23 24void Sound_Init (void ){ 25Timer0A_Init (); 26} 27 28extern "C" void TIMER0A_Handler (void ); 29 30void TIMER0A_Handler (void ){ 31TIMER0_ICR_R = TIMER_ICR_TATOCINT ; 32static uint8_t i = 0 ; 33DAC_Out (instrument [i ++ ]); 34i &=0x3F ; 35} 36 37void Sound_Play (uint32_t period ){ 38if (!period ) { 39TIMER0_TAILR_R = 0 ; 40 }else { 41TIMER0_TAILR_R = period - 1 ; 42 } 43} 44 45void Sound_Stop (){ 46Sound_Play (0 ); 47}