/*
 * AS5048A_dma.h
 *
 * Created: 18/07/2021 14:38:15
 *  Author: Nick-XMG
 */ 

#ifndef AS5048A_DMA_H_
#define AS5048A_DMA_H_

#include <atmel_start.h>
#include <hpl_dma.h>

/* AS5048 Registers */
#define AS5048A_CMD_NOP						  0x0000
#define AS5048A_READ						  0x4000
#define AS5048A_CLEAR_ERROR_FLAG			  0x0001
#define AS5048A_PROGRAMMING_CONTROL           0x0003
#define AS5048A_OTP_REGISTER_ZERO_POS_HIGH    0x0016
#define AS5048A_OTP_REGISTER_ZERO_POS_LOW     0x0017
#define AS5048A_DIAG_AGC                      0x3FFD
#define AS5048A_MAGNITUDE                     0x3FFE
#define AS5048A_ANGLE                         0x3FFF

/* AS5048 parameters */
#define AS5048A_MAX_VALUE					  8191.0f

/* DMA channel for SPI Master TX and RX */
#define CONF_SERCOM_6_TRANSMIT_DMA_CHANNEL	  0
#define CONF_SERCOM_6_RECEIVE_DMA_CHANNEL	  1
#define AS5048A_SPI							  SERCOM4

void as5048a_init(void);
uint16_t as5048a_read(uint16_t registerAddress);
void as5048a_write(void);
uint8_t calcEvenParity(uint16_t value);
void DMA_add_channel(const int trigger_source, DmacDescriptor descriptor, const uint8_t channel);
void DMA_enable(void);




#endif /* AS5048A_DMA_H_ */