瀏覽代碼

Merge pull request #245 from tni/fix-analogwrite

analogWrite() can fail with LTO. Fix casts with undefined behavior.
teensy4-core
Paul Stoffregen 7 年之前
父節點
當前提交
0400e066fd
共有 1 個檔案被更改,包括 7 行新增4 行删除
  1. +7
    -4
      teensy3/analog.c

+ 7
- 4
teensy3/analog.c 查看文件

@@ -501,7 +501,7 @@ startADC1:
#endif
}

typedef int16_t __attribute__((__may_alias__)) aliased_int16_t;

void analogWriteDAC0(int val)
{
@@ -514,7 +514,8 @@ void analogWriteDAC0(int val)
}
if (val < 0) val = 0; // TODO: saturate instruction?
else if (val > 4095) val = 4095;
*(int16_t *)&(DAC0_DAT0L) = val;

*(volatile aliased_int16_t *)&(DAC0_DAT0L) = val;
#elif defined(__MKL26Z64__)
SIM_SCGC6 |= SIM_SCGC6_DAC0;
if (analog_reference_internal == 0) {
@@ -526,7 +527,8 @@ void analogWriteDAC0(int val)
}
if (val < 0) val = 0;
else if (val > 4095) val = 4095;
*(int16_t *)&(DAC0_DAT0L) = val;

*(volatile aliased_int16_t *)&(DAC0_DAT0L) = val;
#endif
}

@@ -542,7 +544,8 @@ void analogWriteDAC1(int val)
}
if (val < 0) val = 0; // TODO: saturate instruction?
else if (val > 4095) val = 4095;
*(int16_t *)&(DAC1_DAT0L) = val;

*(volatile aliased_int16_t *)&(DAC1_DAT0L) = val;
}
#endif


Loading…
取消
儲存