Skip to content

Commit 5c24023

Browse files
committed
use CONF_GCLK_DAC_SRC and refactor a bit
1 parent 4895a9d commit 5c24023

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ports/atmel-samd/common-hal/analogio/AnalogOut.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "atmel_start_pins.h"
3737
#include "hal/include/hal_dac_sync.h"
3838
#include "hpl/gclk/hpl_gclk_base.h"
39+
#include "peripheral_clk_config.h"
3940

4041
#ifdef SAMD21
4142
#include "hpl/pm/hpl_pm_base.h"
@@ -65,16 +66,16 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
6566

6667
#ifdef SAMD51
6768
hri_mclk_set_APBDMASK_DAC_bit(MCLK);
68-
// This clock should be <= 12 MHz, per datasheet section 47.6.3.
69-
hri_gclk_write_PCHCTRL_reg(GCLK, DAC_GCLK_ID, GCLK_PCHCTRL_GEN_GCLK5_Val | (1 << GCLK_PCHCTRL_CHEN_Pos));
7069
#endif
7170

7271
#ifdef SAMD21
7372
_pm_enable_bus_clock(PM_BUS_APBC, DAC);
74-
// This clock should be <= 350kHz, per datasheet table 37-6.
75-
_gclk_enable_channel(DAC_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK1_Val);
7673
#endif
7774

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+
7879
// Don't double init the DAC on the SAMD51 when both outputs are in use. We use the free state
7980
// of each output pin to determine DAC state.
8081
int32_t result = ERR_NONE;

0 commit comments

Comments
 (0)