parent
773d773baa
commit
fa3c14fccf
@ -21,17 +21,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fast I/O Routines
|
* Fast I/O Routines for AVR
|
||||||
* Use direct port manipulation to save scads of processor time.
|
* Use direct port manipulation to save scads of processor time.
|
||||||
* Contributed by Triffid_Hunter. Modified by Kliment and the Marlin team.
|
* Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _FASTIO_ARDUINO_H
|
|
||||||
#define _FASTIO_ARDUINO_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef int8_t pin_t;
|
typedef int8_t pin_t;
|
||||||
|
#ifndef _FASTIO_ARDUINO_H_
|
||||||
|
#define _FASTIO_ARDUINO_H_
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
|
||||||
@ -169,6 +169,7 @@ enum ClockSource2 : char {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get interrupt bits in an orderly way
|
// Get interrupt bits in an orderly way
|
||||||
|
// Ex: cs = GET_CS(0); coma1 = GET_COM(A,1);
|
||||||
#define GET_WGM(T) (((TCCR##T##A >> WGM##T##0) & 0x3) | ((TCCR##T##B >> WGM##T##2 << 2) & 0xC))
|
#define GET_WGM(T) (((TCCR##T##A >> WGM##T##0) & 0x3) | ((TCCR##T##B >> WGM##T##2 << 2) & 0xC))
|
||||||
#define GET_CS(T) ((TCCR##T##B >> CS##T##0) & 0x7)
|
#define GET_CS(T) ((TCCR##T##B >> CS##T##0) & 0x7)
|
||||||
#define GET_COM(T,Q) ((TCCR##T##Q >> COM##T##Q##0) & 0x3)
|
#define GET_COM(T,Q) ((TCCR##T##Q >> COM##T##Q##0) & 0x3)
|
||||||
@ -183,6 +184,7 @@ enum ClockSource2 : char {
|
|||||||
#define GET_FOCC(T) GET_FOC(T,C)
|
#define GET_FOCC(T) GET_FOC(T,C)
|
||||||
|
|
||||||
// Set Wave Generation Mode bits
|
// Set Wave Generation Mode bits
|
||||||
|
// Ex: SET_WGM(5,CTC_ICRn);
|
||||||
#define _SET_WGM(T,V) do{ \
|
#define _SET_WGM(T,V) do{ \
|
||||||
TCCR##T##A = (TCCR##T##A & ~(0x3 << WGM##T##0)) | (( int(V) & 0x3) << WGM##T##0); \
|
TCCR##T##A = (TCCR##T##A & ~(0x3 << WGM##T##0)) | (( int(V) & 0x3) << WGM##T##0); \
|
||||||
TCCR##T##B = (TCCR##T##B & ~(0x3 << WGM##T##2)) | (((int(V) >> 2) & 0x3) << WGM##T##2); \
|
TCCR##T##B = (TCCR##T##B & ~(0x3 << WGM##T##2)) | (((int(V) >> 2) & 0x3) << WGM##T##2); \
|
||||||
@ -190,6 +192,7 @@ enum ClockSource2 : char {
|
|||||||
#define SET_WGM(T,V) _SET_WGM(T,WGM_##V)
|
#define SET_WGM(T,V) _SET_WGM(T,WGM_##V)
|
||||||
|
|
||||||
// Set Clock Select bits
|
// Set Clock Select bits
|
||||||
|
// Ex: SET_CS3(PRESCALER_64);
|
||||||
#define _SET_CS(T,V) (TCCR##T##B = (TCCR##T##B & ~(0x7 << CS##T##0)) | ((int(V) & 0x7) << CS##T##0))
|
#define _SET_CS(T,V) (TCCR##T##B = (TCCR##T##B & ~(0x7 << CS##T##0)) | ((int(V) & 0x7) << CS##T##0))
|
||||||
#define _SET_CS0(V) _SET_CS(0,V)
|
#define _SET_CS0(V) _SET_CS(0,V)
|
||||||
#define _SET_CS1(V) _SET_CS(1,V)
|
#define _SET_CS1(V) _SET_CS(1,V)
|
||||||
@ -214,6 +217,7 @@ enum ClockSource2 : char {
|
|||||||
#define SET_CS(T,V) SET_CS##T(V)
|
#define SET_CS(T,V) SET_CS##T(V)
|
||||||
|
|
||||||
// Set Compare Mode bits
|
// Set Compare Mode bits
|
||||||
|
// Ex: SET_COMS(4,CLEAR_SET,CLEAR_SET,CLEAR_SET);
|
||||||
#define _SET_COM(T,Q,V) (TCCR##T##Q = (TCCR##T##Q & ~(0x3 << COM##T##Q##0)) | (int(V) << COM##T##Q##0))
|
#define _SET_COM(T,Q,V) (TCCR##T##Q = (TCCR##T##Q & ~(0x3 << COM##T##Q##0)) | (int(V) << COM##T##Q##0))
|
||||||
#define SET_COM(T,Q,V) _SET_COM(T,Q,COM_##V)
|
#define SET_COM(T,Q,V) _SET_COM(T,Q,COM_##V)
|
||||||
#define SET_COMA(T,V) SET_COM(T,A,V)
|
#define SET_COMA(T,V) SET_COM(T,A,V)
|
||||||
@ -222,12 +226,15 @@ enum ClockSource2 : char {
|
|||||||
#define SET_COMS(T,V1,V2,V3) do{ SET_COMA(T,V1); SET_COMB(T,V2); SET_COMC(T,V3); }while(0)
|
#define SET_COMS(T,V1,V2,V3) do{ SET_COMA(T,V1); SET_COMB(T,V2); SET_COMC(T,V3); }while(0)
|
||||||
|
|
||||||
// Set Noise Canceler bit
|
// Set Noise Canceler bit
|
||||||
|
// Ex: SET_ICNC(2,1)
|
||||||
#define SET_ICNC(T,V) (TCCR##T##B = (V) ? TCCR##T##B | _BV(ICNC##T) : TCCR##T##B & ~_BV(ICNC##T))
|
#define SET_ICNC(T,V) (TCCR##T##B = (V) ? TCCR##T##B | _BV(ICNC##T) : TCCR##T##B & ~_BV(ICNC##T))
|
||||||
|
|
||||||
// Set Input Capture Edge Select bit
|
// Set Input Capture Edge Select bit
|
||||||
|
// Ex: SET_ICES(5,0)
|
||||||
#define SET_ICES(T,V) (TCCR##T##B = (V) ? TCCR##T##B | _BV(ICES##T) : TCCR##T##B & ~_BV(ICES##T))
|
#define SET_ICES(T,V) (TCCR##T##B = (V) ? TCCR##T##B | _BV(ICES##T) : TCCR##T##B & ~_BV(ICES##T))
|
||||||
|
|
||||||
// Set Force Output Compare bit
|
// Set Force Output Compare bit
|
||||||
|
// Ex: SET_FOC(3,A,1)
|
||||||
#define SET_FOC(T,Q,V) (TCCR##T##C = (V) ? TCCR##T##C | _BV(FOC##T##Q) : TCCR##T##C & ~_BV(FOC##T##Q))
|
#define SET_FOC(T,Q,V) (TCCR##T##C = (V) ? TCCR##T##C | _BV(FOC##T##Q) : TCCR##T##C & ~_BV(FOC##T##Q))
|
||||||
#define SET_FOCA(T,V) SET_FOC(T,A,V)
|
#define SET_FOCA(T,V) SET_FOC(T,A,V)
|
||||||
#define SET_FOCB(T,V) SET_FOC(T,B,V)
|
#define SET_FOCB(T,V) SET_FOC(T,B,V)
|
||||||
@ -251,7 +258,7 @@ enum ClockSource2 : char {
|
|||||||
#elif PIN_EXISTS(FAN1)
|
#elif PIN_EXISTS(FAN1)
|
||||||
#define PWM_CHK_FAN_A(p) (p == FAN_PIN || p == FAN1_PIN)
|
#define PWM_CHK_FAN_A(p) (p == FAN_PIN || p == FAN1_PIN)
|
||||||
#else
|
#else
|
||||||
#define PWM_CHK_FAN_A(p) p == FAN_PIN
|
#define PWM_CHK_FAN_A(p) (p == FAN_PIN)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define PWM_CHK_FAN_A(p) false
|
#define PWM_CHK_FAN_A(p) false
|
||||||
@ -269,15 +276,15 @@ enum ClockSource2 : char {
|
|||||||
#define PWM_CHK_MOTOR_CURRENT(p) false
|
#define PWM_CHK_MOTOR_CURRENT(p) false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(NUM_SERVOS)
|
#ifdef NUM_SERVOS
|
||||||
#if AVR_ATmega2560_FAMILY
|
#if AVR_ATmega2560_FAMILY
|
||||||
#define PWM_CHK_SERVO(p) ( p == 5 || NUM_SERVOS > 12 && p == 6 || NUM_SERVOS > 24 && p == 46) //PWMS 3A, 4A & 5A
|
#define PWM_CHK_SERVO(p) (p == 5 || (NUM_SERVOS > 12 && p == 6) || (NUM_SERVOS > 24 && p == 46)) // PWMS 3A, 4A & 5A
|
||||||
#elif AVR_ATmega2561_FAMILY
|
#elif AVR_ATmega2561_FAMILY
|
||||||
#define PWM_CHK_SERVO(p) p == 5 //PWM3A
|
#define PWM_CHK_SERVO(p) (p == 5) // PWM3A
|
||||||
#elif AVR_ATmega1284_FAMILY
|
#elif AVR_ATmega1284_FAMILY
|
||||||
#define PWM_CHK_SERVO(p) false
|
#define PWM_CHK_SERVO(p) false
|
||||||
#elif AVR_AT90USB1286_FAMILY
|
#elif AVR_AT90USB1286_FAMILY
|
||||||
#define PWM_CHK_SERVO(p) p == 16 //PWM3A
|
#define PWM_CHK_SERVO(p) (p == 16) // PWM3A
|
||||||
#elif AVR_ATmega328_FAMILY
|
#elif AVR_ATmega328_FAMILY
|
||||||
#define PWM_CHK_SERVO(p) false
|
#define PWM_CHK_SERVO(p) false
|
||||||
#endif
|
#endif
|
||||||
@ -317,4 +324,4 @@ enum ClockSource2 : char {
|
|||||||
// finally - the macro that tells us if a pin is an available hardware PWM
|
// finally - the macro that tells us if a pin is an available hardware PWM
|
||||||
#define USEABLE_HARDWARE_PWM(p) (PWM_PINS(p) && !PWM_CHK(p))
|
#define USEABLE_HARDWARE_PWM(p) (PWM_PINS(p) && !PWM_CHK(p))
|
||||||
|
|
||||||
#endif // _FASTIO_ARDUINO_H
|
#endif // _FASTIO_ARDUINO_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user