Initial commit
This commit is contained in:
62
libs/led/led.c
Normal file
62
libs/led/led.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* led.c
|
||||
*
|
||||
* Created on: 26.07.2015
|
||||
* Author: Flo
|
||||
*/
|
||||
|
||||
#include "led.h"
|
||||
|
||||
// init default configuration
|
||||
volatile uint8_t led_flags = LED_ACTIVE_LOW;
|
||||
|
||||
void led_initPorts() {
|
||||
// define the following pins as OUTPUT
|
||||
LED_DDR |= ((1<<LED_BLUE)|(1<<LED_RED)|(1<<LED_GREEN));
|
||||
|
||||
if (led_flags & LED_ACTIVE_HIGH) {
|
||||
// set output state to LOW to disable all leds (leds are active high)
|
||||
LED_PORT &= ~((1<<LED_BLUE)|(1<<LED_RED)|(1<<LED_GREEN));
|
||||
}
|
||||
if (led_flags & LED_ACTIVE_LOW) {
|
||||
// set output state to HIGH to disable all leds (leds are active low)
|
||||
LED_PORT |= ((1<<LED_BLUE)|(1<<LED_RED)|(1<<LED_GREEN));
|
||||
}
|
||||
}
|
||||
|
||||
void led_config(uint8_t flags) {
|
||||
led_flags = flags;
|
||||
}
|
||||
|
||||
void led_init() {
|
||||
led_initPorts();
|
||||
}
|
||||
|
||||
|
||||
void led_off(uint8_t pin) {
|
||||
if (led_flags & LED_ACTIVE_HIGH) cbi(LED_PORT,pin);
|
||||
if (led_flags & LED_ACTIVE_LOW) sbi(LED_PORT,pin);
|
||||
|
||||
}
|
||||
|
||||
void led_on(uint8_t pin) {
|
||||
if (led_flags & LED_ACTIVE_HIGH) sbi(LED_PORT,pin);
|
||||
if (led_flags & LED_ACTIVE_LOW) cbi(LED_PORT,pin);
|
||||
}
|
||||
|
||||
void led_flash(uint8_t pin) {
|
||||
led_on(pin);
|
||||
_delay_ms(10);
|
||||
led_off(pin);
|
||||
_delay_ms(140);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void disco(){
|
||||
led_flash(LED_BLUE);
|
||||
led_flash(LED_RED);
|
||||
led_flash(LED_GREEN);
|
||||
}
|
||||
|
||||
64
libs/led/led.h
Normal file
64
libs/led/led.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* led.h
|
||||
*
|
||||
* Created on: 26.07.2015
|
||||
* Author: Flo
|
||||
*/
|
||||
|
||||
#include <util/delay.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
#ifndef LED_H_
|
||||
#define LED_H_
|
||||
|
||||
|
||||
#ifndef cbi
|
||||
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
||||
#endif
|
||||
#ifndef sbi
|
||||
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
||||
#endif
|
||||
|
||||
#define LED_PORT PORTD
|
||||
#define LED_DDR DDRD
|
||||
|
||||
#define LED_ACTIVE_LOW 0x01
|
||||
#define LED_ACTIVE_HIGH 0x02
|
||||
|
||||
|
||||
#if defined (__AVR_ATmega8__)
|
||||
#define LED_BLUE PD5
|
||||
#define LED_RED PD6
|
||||
#define LED_GREEN PD7
|
||||
#elif defined (__AVR_ATmega168P__)
|
||||
#define LED_BLUE PD5
|
||||
#define LED_RED PD6
|
||||
#define LED_GREEN PD7
|
||||
#elif defined (__AVR_ATtiny2313__)
|
||||
#define LED_BLUE PD3
|
||||
#define LED_RED PD4
|
||||
#define LED_GREEN PD5
|
||||
#else
|
||||
#if !defined(__COMPILING_AVR_LIBC__)
|
||||
#warning "device type not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
extern volatile uint8_t led_flags;
|
||||
|
||||
void led_init();
|
||||
void led_config(uint8_t flags);
|
||||
void led_initPorts();
|
||||
|
||||
void led_off(uint8_t pin);
|
||||
void led_on(uint8_t pin);
|
||||
void led_flash(uint8_t pin);
|
||||
|
||||
void disco();
|
||||
|
||||
|
||||
|
||||
#endif /* LED_H_ */
|
||||
Reference in New Issue
Block a user