collab/PineapplePad
git clone https://git.julia.blue/collab/PineapplePad
ca230b6
master
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 ){ 15NVIC_ST_CTRL_R = 0 ; 16NVIC_ST_CURRENT_R = 0 ; 17NVIC_ST_RELOAD_R = 600000 ; 18NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R & 0x00FFFFFF ) |0x40000000 ;// priority 2 19NVIC_ST_CTRL_R = 0x06 ;// core clock and interrupts 20} 21 22void Song_Init (void ){ 23SysTick_Init (); 24PortF_Init (); 25} 26 27void Song_Play (const uint16_t * pitches ,const uint8_t * durs ,uint32_t speed ,uint16_t len ){ 28note = 0 ; 29pitch = pitches ; 30dur = durs ; 31limit = len ; 32NVIC_ST_RELOAD_R = speed ; 33counter = dur [note ]; 34Sound_Play (pitch [note ]); 35NVIC_ST_CTRL_R |=0x01 ; 36} 37 38void Song_Stop (void ){ 39NVIC_ST_CTRL_R &= ~0x01 ; 40Sound_Play (0 ); 41} 42 43extern "C" void SysTick_Handler (void ); 44 45void SysTick_Handler (void ){ 46if (-- counter ) { 47return ; 48 } 49if (++ note == limit ) { 50Song_Stop (); 51return ; 52 } 53Sound_Play (pitch [note ]); 54counter = dur [note ]; 55// toggle_red(); 56}