Add IR to HAL

This commit is contained in:
Thammi 2013-08-30 21:43:50 +02:00
parent 4de44b972d
commit 81373a2826
2 changed files with 46 additions and 1 deletions

View File

@ -51,6 +51,17 @@ void buzzer_inv(void);
// turns buzzer off, buzzer_inv() won't create a sound wave after this call // turns buzzer off, buzzer_inv() won't create a sound wave after this call
void buzzer_off(void); void buzzer_off(void);
// IR
// all this functions control whether a 38kHz modulated IR signal is sent
void ir_on(void);
void ir_off(void);
void ir_inv(void);
void ir_set(uint8_t state);
// returns 1 if a 38kHz modulated IR signal is received
uint8_t ir_recv(void);
// WAITING // WAITING
// waits the given amount of ms // waits the given amount of ms

View File

@ -99,7 +99,8 @@ void reset_hw(void) {
PORTC = (1 << 2) | (1 << 3); PORTC = (1 << 2) | (1 << 3);
DDRC = (1 << 0) | (1 << 2) | (1 << 3); DDRC = (1 << 0) | (1 << 2) | (1 << 3);
// 2: IR // 2: IRSEND
// 3: IRRECV
// 4: LED // 4: LED
PORTD = (1 << 4); PORTD = (1 << 4);
DDRD = (1 << 2) | (1 << 4); DDRD = (1 << 2) | (1 << 4);
@ -108,6 +109,10 @@ void reset_hw(void) {
button_pressed[0] = 0; button_pressed[0] = 0;
button_pressed[1] = 0; button_pressed[1] = 0;
// turn ir off
ir_off();
} }
uint8_t button_state(uint8_t btn) { uint8_t button_state(uint8_t btn) {
@ -220,3 +225,32 @@ void wait_ms(uint16_t ms) {
} }
} }
void ir_on(void) {
ir_active = 1;
}
void ir_off(void) {
ir_active = 0;
PORTD &= ~(1 << 2);
}
void ir_inv(void) {
if(ir_active) {
ir_off();
} else {
ir_on();
}
}
void ir_set(uint8_t state) {
if(state) {
ir_on();
} else {
ir_off();
}
}
uint8_t ir_recv(void) {
return !(PIND & (1 << 3));
}