/*
 * dac.h
 *
 * Created: 19/11/2016 13:58:23
 *  Author: Ledo
 */ 


#ifndef DAC_H_
#define DAC_H_
#include <asf.h>
#include "dacifb.h"
#include "globales.h"

#define SINUS_SAMPLES 60
uint16_t sin_table[SINUS_SAMPLES] = {
	2222,
	2412,
	2601,
	2785,
	2963,
	3133,
	3293,
	3441,
	3576,
	3696,
	3799,
	3886,
	3954,
	4003,
	4032,
	4042,
	4032,
	4002,
	3952,
	3883,
	3796,
	3692,
	3571,
	3436,
	3287,
	3127,
	2957,
	2778,
	2594,
	2405,
	2215,
	2024,
	1836,
	1652,
	1474,
	1305,
	1145,
	997,
	863,
	744,
	641,
	555,
	488,
	439,
	410,
	401,
	413,
	444,
	494,
	563,
	651,
	756,
	877,
	1013,
	1162,
	1323,
	1493,
	1672,
	1856,
	2045
};

uint8_t sinus_point;

/* Connection of the AUDIO sensor */
#define DAC_AUDIO_INSTANCE            0
#define DAC_AUDIO_CHANNEL             DACIFB_CHANNEL_SELECTION_A
#define DAC_AUDIO_PIN                 AVR32_DAC0A_PIN
#define DAC_AUDIO_FUNCTION            AVR32_DAC0A_FUNCTION
#define DAC_PRESCALER_CLOCK           48000000 / 2

/*Conexion del canal conectado al ADC*/
#define DAC_ADC_INSTANCE            1
#define DAC_ADC_CHANNEL             DACIFB_CHANNEL_SELECTION_B
#define DAC_ADC_PIN                 AVR32_DAC0B_PIN
#define DAC_ADC_FUNCTION            AVR32_DAC0B_FUNCTION


/* Assign the on-board sensors to their DAC channel. */
int16_t dac_value_audio   = -1;
uint8_t dac_channel_audio = DAC_AUDIO_CHANNEL;
uint8_t dac_channel_adc = DAC_ADC_CHANNEL;

/* DAC Configuration */
dacifb_opt_t dacifb_opt = {
	.reference            = DACIFB_REFERENCE_EXT,
	.channel_selection    = DACIFB_CHANNEL_SELECTION_A,
	.low_power            = false,
	.dual                 = false,
	.prescaler_clock_hz   = DAC_PRESCALER_CLOCK
};

/* DAC Channel Configuration */
dacifb_channel_opt_t dacifb_channel_opt = {
	.auto_refresh_mode    = false,
	.trigger_mode         = DACIFB_TRIGGER_MODE_MANUAL,
	.left_adjustment      = false,
	.data_shift           = 0,
	.data_round_enable    = false
};




void dac_init(void);
void dac_set_value(uint16_t value);
void dac1_set_value(uint16_t value);
void sinus(uint8_t volume,uint8_t signal);


#endif /* DAC_H_ */