collab/PineapplePad

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

Joseph RyanFinishing touchesca230b6

master
1.1 KiB56 linesraw
1#include <stdint.h>
2#include "../inc/tm4c123gh6pm.h"
3#include "../inc/song.h"
4#include "../inc/sound.h"
5#include "../inc/IO.h"
6
7uint16_t note;
8uint32_t counter;
9
10const uint16_t* pitch;
11const uint8_t* dur;
12uint16_t limit;
13
14void SysTick_Init(void){
15    NVIC_ST_CTRL_R = 0;
16    NVIC_ST_CURRENT_R = 0;
17    NVIC_ST_RELOAD_R = 600000;
18    NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R & 0x00FFFFFF) | 0x40000000; // priority 2
19    NVIC_ST_CTRL_R = 0x06; // core clock and interrupts
20}
21
22void Song_Init(void){
23    SysTick_Init();
24    PortF_Init();
25}
26
27void Song_Play(const uint16_t* pitches, const uint8_t* durs, uint32_t speed, uint16_t len){
28    note = 0;
29    pitch = pitches;
30    dur = durs;
31    limit = len;
32    NVIC_ST_RELOAD_R = speed;
33    counter = dur[note];
34    Sound_Play(pitch[note]);
35    NVIC_ST_CTRL_R |= 0x01;
36}
37
38void Song_Stop(void){
39    NVIC_ST_CTRL_R &= ~0x01;
40    Sound_Play(0);
41}
42
43extern "C" void SysTick_Handler(void);
44
45void SysTick_Handler(void){
46    if (--counter) {
47        return;
48    }
49    if (++note == limit) {
50        Song_Stop();
51        return;
52    }
53    Sound_Play(pitch[note]);
54    counter = dur[note];
55    // toggle_red();
56}