|
36 | 36 | #include "atmel_start_pins.h"
|
37 | 37 | #include "hal/include/hal_dac_sync.h"
|
38 | 38 | #include "hpl/gclk/hpl_gclk_base.h"
|
| 39 | +#include "peripheral_clk_config.h" |
39 | 40 |
|
40 | 41 | #ifdef SAMD21
|
41 | 42 | #include "hpl/pm/hpl_pm_base.h"
|
@@ -65,14 +66,16 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
|
65 | 66 |
|
66 | 67 | #ifdef SAMD51
|
67 | 68 | hri_mclk_set_APBDMASK_DAC_bit(MCLK);
|
68 |
| - hri_gclk_write_PCHCTRL_reg(GCLK, DAC_GCLK_ID, GCLK_PCHCTRL_GEN_GCLK5_Val | (1 << GCLK_PCHCTRL_CHEN_Pos)); |
69 | 69 | #endif
|
70 | 70 |
|
71 | 71 | #ifdef SAMD21
|
72 | 72 | _pm_enable_bus_clock(PM_BUS_APBC, DAC);
|
73 |
| - _gclk_enable_channel(DAC_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK0_Val); |
74 | 73 | #endif
|
75 | 74 |
|
| 75 | + // SAMD21: This clock should be <= 12 MHz, per datasheet section 47.6.3. |
| 76 | + // SAMD51: This clock should be <= 350kHz, per datasheet table 37-6. |
| 77 | + _gclk_enable_channel(DAC_GCLK_ID, CONF_GCLK_DAC_SRC); |
| 78 | + |
76 | 79 | // Don't double init the DAC on the SAMD51 when both outputs are in use. We use the free state
|
77 | 80 | // of each output pin to determine DAC state.
|
78 | 81 | int32_t result = ERR_NONE;
|
@@ -123,7 +126,7 @@ void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
123 | 126 |
|
124 | 127 | void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
|
125 | 128 | uint16_t value) {
|
126 |
| - // Input is 16 bit so make sure and set LEFTADJ to 1 to it takes the top |
| 129 | + // Input is 16 bit so make sure and set LEFTADJ to 1 so it takes the top |
127 | 130 | // bits. This is currently done in asf4_conf/*/hpl_dac_config.h.
|
128 | 131 | dac_sync_write(&self->descriptor, self->channel, &value, 1);
|
129 | 132 | }
|
|
0 commit comments