/* 
 * File:  sound.h
 * Author: Claire Chen and Mark Zhao
 *
 * Created on November 3, 2016, 2:13 PM
 */

#ifndef SOUND_H
#define	SOUND_H

#define _SUPPRESS_PLIB_WARNING 1
#include <plib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>

#define pb_clock 40000000
#define sine_table_size 256
#define sound_freq 440
#define two32 4294967296 // 2^32 
#define Fs 16000.0 // DDS sample frequency
//#define Fs 40000.0 // DDS sample frequency

#define MAX_TONE_DURATION_us 100000 
#define MAX_HEAD_DELAY_us  500.0
#define deg2rad 0.1745
#define PI 3.14159265

// Configurations for DAC channels
#define DAC_config_chan_A 0b0011000000000000 // Channel A, 1x, left, (right pin on jack)
#define DAC_config_chan_B 0b1011000000000000 // Channel B, 1x, right

// SPI uses channel 1 since channel 2 is used by radio
#define spi_channel 1

// Max SPI clock of DAC 20MHz = pb_clock / (2 * (spi_brg + 1))
#define spi_brg 1

void DAC_init(void);
void DAC_write(uint16_t DAC_data);
void config_sound_timer(void);


#endif	/* SOUND_H */