/*
 * spi.h
 *
 * Created: 25/09/2016 12:52:33
 *  Author: Ledo
 */ 


#ifndef SPI0_H_
#define SPI0_H_

#include <asf.h>
#include <avr32/io.h>
#include <stdbool.h>
#include "gpio.h"
#include "sysclk.h"
#include "globales.h"


// pines spi
#define SPI_MISO           AVR32_PIN_PD01
#define SPI_MOSI           AVR32_PIN_PD00
#define SPI_SCK            AVR32_PIN_PD02

// pines slave select
#define POTA_CS            AVR32_PIN_PD03        // NPCS2
#define POTB_CS            AVR32_PIN_PD11        // NPCS3

/* Definición de comandos al pot digital */
#define POTA_WR    0x11
#define POTB_WR    0x12


 static const gpio_map_t SPI_GPIO_MAP =
 {
	 //{AVR32_SPI0_NPCS_0_0_PIN , AVR32_SPI0_NPCS_0_0_FUNCTION},
	 {AVR32_SPI0_SCK_0_0_PIN  , AVR32_SPI0_SCK_0_0_FUNCTION },
	 {AVR32_SPI0_MISO_0_0_PIN , AVR32_SPI0_MISO_0_0_FUNCTION},
	 {AVR32_SPI0_MOSI_0_0_PIN , AVR32_SPI0_MOSI_0_0_FUNCTION}
 };
 
 static spi_options_t SPI_OPTIONS =
 {
	 .reg = 0,
	 .baudrate = 1000000,
	 .bits = 8,
	 .spck_delay = 0,
	 .trans_delay = 0,
	 .stay_act = 1,
	 .spi_mode = SPI_MODE_0,
	 .modfdis = 1
	 
 };
 
 struct spi_device SPI_DEVICE_0 = {
	 //! Board specific select id
	 .id = 0
 };
 

void SPI_init(void);
void AjustePot_A(uint8_t ch, uint8_t cursor);
void AjustePot_B(uint8_t cursor);


#endif /* SPI0_H_ */