Pārlūkot izejas kodu

Add support for Teensy-LC DAC

teensy4-core
PaulStoffregen pirms 10 gadiem
vecāks
revīzija
af89f7072e
3 mainītis faili ar 24 papildinājumiem un 0 dzēšanām
  1. +12
    -0
      teensy3/analog.c
  2. +1
    -0
      teensy3/kinetis.h
  3. +11
    -0
      teensy3/pins_teensy.c

+ 12
- 0
teensy3/analog.c Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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;

Notiek ielāde…
Atcelt
Saglabāt