X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=teensy3%2Fpins_teensy.c;h=a45fc84e794dbfa26e62e60a6e70be99617fb723;hb=a773ac06cdc55be51ebc0bc61aa6066b54746c7d;hp=e2d3c1d7333d338f918b43c48049a7c59c8db444;hpb=35f00b6caaac4a8b93247913f0863bcd8f419041;p=megadrive.git diff --git a/teensy3/pins_teensy.c b/teensy3/pins_teensy.c index e2d3c1d..a45fc84 100644 --- a/teensy3/pins_teensy.c +++ b/teensy3/pins_teensy.c @@ -30,7 +30,7 @@ #include "core_pins.h" #include "pins_arduino.h" -#include "HardwareSerial.h" +//#include "HardwareSerial.h" #if 0 // moved to pins_arduino.h @@ -116,6 +116,11 @@ void init_pin_interrupts(void) // fast interrupts will still be serviced quickly? } +void attachInterruptVector(enum IRQ_NUMBER_t irq, void (*function)(void)) +{ + _VectorsRam[irq + 16] = function; +} + void attachInterrupt(uint8_t pin, void (*function)(void), int mode) { volatile uint32_t *config; @@ -320,12 +325,37 @@ extern void usb_init(void); // create a default PWM at the same 488.28 Hz as Arduino Uno -#if F_BUS == 48000000 + +#if F_BUS == 60000000 +#define DEFAULT_FTM_MOD (61440 - 1) +#define DEFAULT_FTM_PRESCALE 1 +#elif F_BUS == 56000000 +#define DEFAULT_FTM_MOD (57344 - 1) +#define DEFAULT_FTM_PRESCALE 1 +#elif F_BUS == 48000000 #define DEFAULT_FTM_MOD (49152 - 1) #define DEFAULT_FTM_PRESCALE 1 -#else +#elif F_BUS == 40000000 +#define DEFAULT_FTM_MOD (40960 - 1) +#define DEFAULT_FTM_PRESCALE 1 +#elif F_BUS == 36000000 +#define DEFAULT_FTM_MOD (36864 - 1) +#define DEFAULT_FTM_PRESCALE 1 +#elif F_BUS == 24000000 #define DEFAULT_FTM_MOD (49152 - 1) #define DEFAULT_FTM_PRESCALE 0 +#elif F_BUS == 16000000 +#define DEFAULT_FTM_MOD (32768 - 1) +#define DEFAULT_FTM_PRESCALE 0 +#elif F_BUS == 8000000 +#define DEFAULT_FTM_MOD (16384 - 1) +#define DEFAULT_FTM_PRESCALE 0 +#elif F_BUS == 4000000 +#define DEFAULT_FTM_MOD (8192 - 1) +#define DEFAULT_FTM_PRESCALE 0 +#elif F_BUS == 2000000 +#define DEFAULT_FTM_MOD (4096 - 1) +#define DEFAULT_FTM_PRESCALE 0 #endif //void init_pins(void) @@ -359,13 +389,13 @@ void _init_Teensyduino_internal_(void) FTM2_SC = FTM_SC_CLKS(1) | FTM_SC_PS(DEFAULT_FTM_PRESCALE); #endif - analog_init(); + //analog_init(); //delay(100); // TODO: this is not necessary, right? delay(4); usb_init(); } - +#if 0 static uint8_t analog_write_res = 8; @@ -525,9 +555,17 @@ void analogWriteFrequency(uint8_t pin, uint32_t frequency) FTM0_MOD = mod; FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS(prescale); } +#if defined(__MK20DX256__) + else if (pin == 25 || pin == 32) { + FTM2_SC = 0; + FTM2_CNT = 0; + FTM2_MOD = mod; + FTM2_SC = FTM_SC_CLKS(1) | FTM_SC_PS(prescale); + } +#endif } - +#endif // TODO: startup code needs to initialize all pins to GPIO mode, input by default @@ -685,12 +723,29 @@ void delay(uint32_t ms) } } -#if F_CPU == 96000000 +// TODO: verify these result in correct timeouts... +#if F_CPU == 168000000 +#define PULSEIN_LOOPS_PER_USEC 25 +#elif F_CPU == 144000000 +#define PULSEIN_LOOPS_PER_USEC 21 +#elif F_CPU == 120000000 +#define PULSEIN_LOOPS_PER_USEC 18 +#elif F_CPU == 96000000 #define PULSEIN_LOOPS_PER_USEC 14 +#elif F_CPU == 72000000 +#define PULSEIN_LOOPS_PER_USEC 10 #elif F_CPU == 48000000 #define PULSEIN_LOOPS_PER_USEC 7 #elif F_CPU == 24000000 #define PULSEIN_LOOPS_PER_USEC 4 +#elif F_CPU == 16000000 +#define PULSEIN_LOOPS_PER_USEC 1 +#elif F_CPU == 8000000 +#define PULSEIN_LOOPS_PER_USEC 1 +#elif F_CPU == 4000000 +#define PULSEIN_LOOPS_PER_USEC 1 +#elif F_CPU == 2000000 +#define PULSEIN_LOOPS_PER_USEC 1 #endif