Quellcode durchsuchen

Add support for Teensy-LC DAC

main
PaulStoffregen vor 9 Jahren
Ursprung
Commit
af89f7072e
3 geänderte Dateien mit 24 neuen und 0 gelöschten Zeilen
  1. +12
    -0
      teensy3/analog.c
  2. +1
    -0
      teensy3/kinetis.h
  3. +11
    -0
      teensy3/pins_teensy.c

+ 12
- 0
teensy3/analog.c Datei anzeigen

@@ -496,6 +496,18 @@ void analogWriteDAC0(int val)
if (val < 0) val = 0; // TODO: saturate instruction?
else if (val > 4095) val = 4095;
*(int16_t *)&(DAC0_DAT0L) = val;
#elif defined(__MKL26Z64__)
SIM_SCGC6 |= SIM_SCGC6_DAC0;
if (analog_reference_internal == 0) {
// use 3.3V VDDA power as the reference (this is the default)
DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS | DAC_C0_DACSWTRG; // 3.3V VDDA
} else {
// use whatever voltage is on the AREF pin
DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACSWTRG; // 3.3V VDDA
}
if (val < 0) val = 0;
else if (val > 4095) val = 4095;
*(int16_t *)&(DAC0_DAT0L) = val;
#endif
}


+ 1
- 0
teensy3/kinetis.h Datei anzeigen

@@ -505,6 +505,7 @@ enum IRQ_NUMBER_t {
#define SIM_SCGC5_TSI ((uint32_t)0x00000020) // Touch Sense Input TSI Clock Gate Control
#define SIM_SCGC5_LPTIMER ((uint32_t)0x00000001) // Low Power Timer Access Control
#define SIM_SCGC6 (*(volatile uint32_t *)0x4004803C) // System Clock Gating Control Register 6
#define SIM_SCGC6_DAC0 ((uint32_t)0x80000000) // DAC on Kinetis-L
#define SIM_SCGC6_RTC ((uint32_t)0x20000000) // RTC Access
#define SIM_SCGC6_ADC0 ((uint32_t)0x08000000) // ADC0 Clock Gate Control
#define SIM_SCGC6_FTM1 ((uint32_t)0x02000000) // FTM1 Clock Gate Control

+ 11
- 0
teensy3/pins_teensy.c Datei anzeigen

@@ -523,6 +523,17 @@ void analogWrite(uint8_t pin, int val)
analogWriteDAC0(val);
return;
}
#elif defined(__MKL26Z64__)
if (pin == A12) {
uint8_t res = analog_write_res;
if (res < 12) {
val <<= 12 - res;
} else if (res > 12) {
val >>= res - 12;
}
analogWriteDAC0(val);
return;
}
#endif

max = 1 << analog_write_res;

Laden…
Abbrechen
Speichern