pentabug/firmware/lib/bughal.c

95 lines
1.5 KiB
C
Raw Normal View History

#include <inttypes.h>
2012-09-02 23:49:57 +02:00
#include <avr/io.h>
#include "bughal.h"
/* Hardware abstraction layer for Pentabug hardware */
/*
* initialize LEDs on C0-C3
*/
void init_leds(void){
//enable LED channels as output
DDRC |= (1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3);
// both LEDs off
2012-09-06 23:09:20 +02:00
PORTC &= ~((1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3));
//TCCR2A = (1 << WGM21);
//TCCR2B = (1 << CS20)|(1 << CS21);
//OCR2A = 255; /* TOP */
// TCNT2 = 0;
// /*enable interrupt*/
// TIMSK2 |= (1<<OCIE2A);
2012-09-02 23:49:57 +02:00
return;
2012-10-01 05:06:42 +02:00
}
2012-10-01 04:32:00 +02:00
inline void led_on(int leds){
2012-09-06 23:09:20 +02:00
PORTC |= leds;
2012-10-01 05:06:42 +02:00
}
2012-10-01 04:32:00 +02:00
inline void led_off(int leds){
2012-09-06 23:09:20 +02:00
PORTC &= ~leds;
2012-10-01 05:06:42 +02:00
}
2012-09-06 23:09:20 +02:00
2012-10-01 05:06:42 +02:00
void init_buzzr(void){
2012-09-06 23:09:20 +02:00
//its on B2 and C5, for reasons
DDRC |= (1 << PORTC5);
DDRB |= (1 << PORTB2);
//switch it off
buzzr_off();
return;
2012-10-01 05:06:42 +02:00
}
2012-09-06 23:09:20 +02:00
2012-10-01 05:06:42 +02:00
void buzzr_up(void){
2012-09-06 23:09:20 +02:00
PORTC &= ~(1 << PORTC5);
PORTB |= (1 << PORTB2);
return;
2012-10-01 05:06:42 +02:00
}
2012-09-06 23:09:20 +02:00
2012-10-01 05:06:42 +02:00
void buzzr_down(void){
2012-09-06 23:09:20 +02:00
PORTC |= (1 << PORTC5);
PORTB &= ~(1 << PORTB2);
2012-10-01 05:06:42 +02:00
}
2012-09-06 23:09:20 +02:00
2012-10-01 05:06:42 +02:00
inline void buzzr_off(void){
2012-09-06 23:09:20 +02:00
PORTC &= ~(1 << PORTC5);
PORTB &= ~(1 << PORTB2);
2012-10-01 05:06:42 +02:00
}
void buzzr_inv(void){
2012-09-06 23:09:20 +02:00
PORTC ^= (1 << PORTC5);
PORTB ^= (1 << PORTB2);
2012-10-01 05:06:42 +02:00
}
2012-10-01 05:06:42 +02:00
void init_switch(void){
2012-10-01 21:39:25 +02:00
DDRD &= ~( (1 << PORTD1) | (1<<PORTD0));
PORTD |= (1 << PORTD1) | (1<<PORTD0); //Pullups FTW
2012-09-02 23:49:57 +02:00
return;
2012-10-01 05:06:42 +02:00
}
2012-10-01 22:11:28 +02:00
bool switch_l(void){
return !(PIND & 0b00000001);
2012-10-01 22:11:28 +02:00
};
bool switch_r(void){
return !(PIND & 0b00000010);
2012-10-01 22:11:28 +02:00
};
2012-09-02 23:49:57 +02:00
void init_motor(void)
{
/* vibration motor on B1, initially off: */
DDRB |= (1 << PORTB1);
PORTB &= ~( 1<<PORTB1);
return;
}
2012-09-06 23:09:20 +02:00
void set_motor(int val){
PORTB = ~(val);
return;
2012-10-01 05:06:42 +02:00
}
2012-09-06 23:09:20 +02:00