collab/PineapplePad

git clone https://git.julia.blue/collab/PineapplePad

Vivek Malneedifinal competition14d8b4f

master
943 B47 linesraw
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){
12    SYSCTL_RCGCTIMER_R |= 0x01;
13    TIMER0_CTL_R = 0;
14    TIMER0_CFG_R = 0;
15    TIMER0_TAMR_R = 0x02;
16    TIMER0_TAPR_R = 0;
17    TIMER0_ICR_R = 0x01;
18    TIMER0_IMR_R = 0x01;
19    NVIC_PRI4_R = (NVIC_PRI4_R & 0x00FFFFFF) | 0x40000000;
20    NVIC_EN0_R = 1 << 19;
21    TIMER0_CTL_R = 1;
22}
23
24void Sound_Init(void){
25    Timer0A_Init();
26}
27
28extern "C" void TIMER0A_Handler(void);
29
30void TIMER0A_Handler(void){
31    TIMER0_ICR_R = TIMER_ICR_TATOCINT;
32    static uint8_t i = 0;
33    DAC_Out(instrument[i++]);
34    i &= 0x3F;
35}
36
37void Sound_Play(uint32_t period){
38    if (!period) {
39        TIMER0_TAILR_R = 0;
40    }else {
41        TIMER0_TAILR_R = period - 1;
42    }
43}
44
45void Sound_Stop(){
46    Sound_Play(0);
47}