|
|
|
|
#ifndef ENCODER_H_
|
|
|
|
|
#define ENCODER_H_
|
|
|
|
|
|
|
|
|
|
// Art des Drehencoders definieren
|
|
|
|
|
// #define SingleStep
|
|
|
|
|
// #define TwoStep
|
|
|
|
|
#define TwoStep
|
|
|
|
|
|
|
|
|
|
#define ENC_A_PORT PORTB /**< port for line A */
|
|
|
|
|
#define ENC_A_PIN PB1 /**< pin for line A */
|
|
|
|
|
#define ENC_B_PORT PORTB /**< port for line B */
|
|
|
|
|
#define ENC_B_PIN PB0 /**< pin for line B */
|
|
|
|
|
#define ENC_T_PORT PORTB /**< port for button */
|
|
|
|
|
#define ENC_T_PIN PB2 /**< pin for button */
|
|
|
|
|
|
|
|
|
|
#define DDR(x) (*(&x-1))
|
|
|
|
|
#define Port(x) (*(&x))
|
|
|
|
|
#define PIN(x) (*(&x-2))
|
|
|
|
|
|
|
|
|
|
#define PHASE_A PIN(ENC_A_PORT) & (1<<ENC_A_PIN)
|
|
|
|
|
#define PHASE_B PIN(ENC_B_PORT) & (1<<ENC_B_PIN)
|
|
|
|
|
#define BUTTONPRESSED (!(PIN(ENC_T_PORT) & (1<<ENC_T_PIN)))
|
|
|
|
|
|
|
|
|
|
#define BUTTON_DEBOUNCETIME_MS 30
|
|
|
|
|
#define BUTTON_PRESSEDLONG_MS 250
|
|
|
|
|
|
|
|
|
|
typedef enum EButtonPressedState
|
|
|
|
|
{
|
|
|
|
|
ButtonPressed_Unpressed,
|
|
|
|
|
ButtonPressed_Short,
|
|
|
|
|
ButtonPressed_Long
|
|
|
|
|
}tEButtonPressedState;
|
|
|
|
|
|
|
|
|
|
// Initialisiert den Encoder und aktiviert den Interrupt + Timer
|
|
|
|
|
void EncoderInit( void );
|
|
|
|
|
// Liest die Position des Encoders aus
|
|
|
|
|
// Wenn Ueberlauf=1 dann z<>hlt der Encoder nach Max
|
|
|
|
|
// wieder von Min und umgekehrt
|
|
|
|
|
int8_t EncoderRead(char Ueberlauf);
|
|
|
|
|
// Ruft den Status des Encoder-Knopfes
|
|
|
|
|
tEButtonPressedState EncoderGetButtonState(void);
|
|
|
|
|
// Setzt die aktuelle Drehencoderposition
|
|
|
|
|
void EncoderWrite(int8_t EncoderPos);
|
|
|
|
|
// Setzt Min- und Max-Werte f<>r die Drehgeberposition
|
|
|
|
|
void EncoderMinMax(int8_t EncoderMin,int8_t EncoderMax);
|
|
|
|
|
void EncoderPolling(void);
|
|
|
|
|
#endif /* ENCODER_H_ */
|