-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/sam0_common: enable static voltages #21555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,14 @@ | |||||
|
|
||||||
| #define DAC_VAL(in) (in >> (16 - DAC_RES_BITS)) | ||||||
|
|
||||||
| #ifndef CONFIG_SAM0_DAC_REFRESH | ||||||
| #define CONFIG_SAM0_DAC_REFRESH 2 | ||||||
| #endif | ||||||
|
|
||||||
| #ifndef CONFIG_SAM0_DAC_RUN_ON_STANDBY | ||||||
| #define CONFIG_SAM0_DAC_RUN_ON_STANDBY 0 | ||||||
| #endif | ||||||
|
|
||||||
| static void _dac_init_clock(dac_t line) | ||||||
| { | ||||||
| sam0_gclk_enable(DAC_CLOCK); | ||||||
|
|
@@ -110,13 +118,29 @@ | |||||
|
|
||||||
| _dac_init_clock(line); | ||||||
|
|
||||||
| /* Settings can only be changed when DAC is disabled, reset config */ | ||||||
| DAC->CTRLA.reg = DAC_CTRLA_SWRST; | ||||||
| /* Settings can only be changed when DAC is disabled */ | ||||||
| DAC->CTRLA.reg &= ~DAC_CTRLA_ENABLE; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there are only two bits, you could also just
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some CPUs there are three bits. One of them is the bit to enable operation during standby power mode:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But now you are writing the entire
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But 0 feels like a magic number to me and I like the fact that clearing the bit makes the intention clear.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well it saves two instructions - but yea, not really that much relevant on init. |
||||||
| _sync(); | ||||||
|
|
||||||
| #ifdef DAC_DACCTRL_ENABLE | ||||||
| DAC->DACCTRL[line].reg = DAC_DACCTRL_ENABLE | ||||||
| | _get_CCTRL(sam0_gclk_freq(DAC_CLOCK)); | ||||||
| | _get_CCTRL(sam0_gclk_freq(DAC_CLOCK)) | ||||||
| #endif | ||||||
| #if CONFIG_SAM0_DAC_RUN_ON_STANDBY && defined(DAC_DACCTRL_RUNSTDBY) | ||||||
| | DAC_DACCTRL_RUNSTDBY | ||||||
| #endif | ||||||
| ; | ||||||
|
|
||||||
| #ifdef DAC_DACCTRL_REFRESH | ||||||
| /** The DAC can only maintain its output on the desired value for approximately 100 μs. | ||||||
| * For static voltages the conversion must be refreshed periodically (see e.g. | ||||||
| * '47.6.9.3 Conversion Refresh' in the SAM D5xE5x family data sheet). | ||||||
| * | ||||||
| * Note: T_REFRESH = REFRESH * T_OSCULP32K | ||||||
| */ | ||||||
| static_assert(CONFIG_SAM0_DAC_REFRESH != 1, "DACCTRLx.REFRESH = 1 is reserved"); | ||||||
|
|
||||||
| DAC->DACCTRL[line].bit.REFRESH = CONFIG_SAM0_DAC_REFRESH; | ||||||
| #endif | ||||||
|
|
||||||
| /* Set Reference Voltage & enable Output if needed */ | ||||||
|
|
@@ -124,9 +148,13 @@ | |||||
| #ifdef DAC_CTRLB_EOEN | ||||||
| | DAC_CTRLB_EOEN | ||||||
| #endif | ||||||
| ; | ||||||
|
|
||||||
| DAC->CTRLA.reg = DAC_CTRLA_ENABLE; | ||||||
| DAC->CTRLA.reg = DAC_CTRLA_ENABLE | ||||||
| #if CONFIG_SAM0_DAC_RUN_ON_STANDBY && defined(DAC_CTRLA_RUNSTDBY) | ||||||
| | DAC_CTRLA_RUNSTDBY | ||||||
| #endif | ||||||
| ; | ||||||
| _sync(); | ||||||
|
|
||||||
| #ifdef DAC_STATUS_READY | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.