/*
 * arduino.c
 *
 * SysTick Timer
 *
 * Created: 24. 3. 2016
 * Author: Robo Ulbricht
 * www: http://www.arduinoslovakia.eu
 */ 

#include <asf.h>
#include "arduino.h"

const int led[]={PIN_PA11,PIN_PA10,PIN_PA16,PIN_PA17,27/*PIN_PA27*/,PIN_PA25,PIN_PA30,PIN_PA31};
const int ledsize=sizeof(led)/sizeof(int);
int pos=0;
int dir=1;
#define spd 100

///
/// Local setup
///
void rurInit(void)
{
struct port_config pin_conf;
port_get_config_defaults(&pin_conf);
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
for(int i=0;i<ledsize;i++)
  port_pin_set_config(led[i], &pin_conf);
}

///
/// Calculate next step
///
void nextStep(void)
{
for(int i=0;i<ledsize;i++)
  {
  // simple moving LED
  digitalWrite(led[i], i==pos ? HIGH : LOW);
  }

pos+=dir;
if(pos==0)
  dir=1; // move to the right
if(pos==ledsize-1)
  dir=-1; // move to the left
}


///
/// Logical true/false on a pin
///
void digitalWrite(int pin, bool value)
{
port_pin_set_output_level(pin, value);
}  