Subversion Repositories FlightCtrl

Rev

Rev 2110 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef _OUTPUT_H
#define _OUTPUT_H

#include <avr/io.h>

#define PD2HIGH   PORTD |= (1<<PORTD2)
#define PD2LOW    PORTD &= ~(1<<PORTD2)
#define PD2TOGGLE PORTD ^= (1<<PORTD2)

// invert means: An "1" bit in digital debug data make a LOW on the output.
#define DIGITAL_DEBUG_INVERT 0

#define OUTPUT_HIGH(num)        {PORTB |=  ((1<<4) << (num));}
#define OUTPUT_LOW(num)         {PORTB &= ~((1<<4) << (num));}
#define OUTPUT_TOGGLE(num) (    {PORTB ^=  ((1<<4) << (num));}

/*
 * Some digital debugs. A digital debug is 2 signals on the 2 LED outputs,
 * turned on and off depending on some condtions given in the code.
 * Only one can be selected, by defining DIGITAL_DEBUG_MASK to the value
 * of the debug.
 * In the code one can do like:
 * if (whatever_condition) {
 *      DebugOut.Digital[0] |= DEBUG_MYOWNDEBUGGER;
 * } else {
 *      DebugOut.Digital[0] &= ~DEBUG_MYOWNDEBUGGER;
 * }
 * ...
 * if (whatever_other_condition) {
 *      DebugOut.Digital[1] |= DEBUG_MYOWNDEBUGGER;
 * } else {
 *      DebugOut.Digital[1] &= ~DEBUG_MYOWNDEBUGGER;
 * }
 *
 * Digital debugs may be added as desired, and removed when the mystery
 * at hand is resolved.
 */


#define DEBUG_MAINLOOP_TIMER 1
#define DEBUG_HEIGHT_DIFF    2
#define DEBUG_FLIGHTCLIP     4
#define DEBUG_ACC0THORDER    8
#define DEBUG_COMPASS       16
#define DEBUG_PRESSURERANGE 32
#define DEBUG_CLIP          64
#define DEBUG_SENSORLIMIT  128

#define OUTPUTFLAGS_INVERT_0         1 // Inverted: 1 means low output on atmega. Does not affect on-board LED (if used with the OUTPUTOPTIONS_USE_ONBOARD_LEDS option)
#define OUTPUTFLAGS_INVERT_1         2 // Inverted: 1 means low output on atmega. Does not affect on-board LED (if used with the OUTPUTOPTIONS_USE_ONBOARD_LEDS option)
#define OUTPUTFLAGS_FLASH_0_AT_BEEP  4 // Flash LED when beeper beeps
#define OUTPUTFLAGS_FLASH_1_AT_BEEP  8 // Flash LED when beeper beeps
#define OUTPUTFLAGS_USE_ONBOARD_LEDS 16 // Control on-board LEDs in addition to outputs
#define OUTPUTFLAGS_TEST_OFF         32 // For testing: Turn off both outputs
#define OUTPUTFLAGS_TEST_ON          64 // For testing: Turn on both outputs

// For practical reasons put here instead of in uart0.h
typedef struct {
    uint8_t digital[2];
    uint16_t analog[32]; // debug values
}__attribute__((packed)) DebugOut_t;

extern DebugOut_t debugOut;

/*
 * Set to 0 for using outputs as the usual flashing lights.
 * Set to one of the DEBUG_... defines h for using the outputs as debug lights.
 */

#define DIGITAL_DEBUG_MASK 0

void output_init(void);
void outputSet(uint8_t num, uint8_t state);
void output_update(void);
void beep(uint16_t millis);
void beepNumber(uint8_t numbeeps);
void beepRCAlarm(void);
void beepBatteryAlarm(void);

#endif //_output_H