Skip to content

Commit 641300d

Browse files
peterhinchpfalcon
authored andcommitted
stmhal/dac: DAC deinit() method added.
1 parent ee009d7 commit 641300d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

docs/library/pyb.DAC.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ Methods
6666

6767
Reinitialise the DAC. ``bits`` can be 8 or 12.
6868

69+
.. method:: dac.deinit()
70+
71+
De-initialise the DAC making its pin available for other uses.
72+
6973
.. method:: dac.noise(freq)
7074

7175
Generate a pseudo-random noise signal. A new random sample is written

stmhal/dac.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,21 @@ STATIC mp_obj_t pyb_dac_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *k
246246
}
247247
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_init_obj, 1, pyb_dac_init);
248248

249+
/// \method deinit()
250+
/// Turn off the DAC, enable other use of pin.
251+
STATIC mp_obj_t pyb_dac_deinit(mp_obj_t self_in) {
252+
pyb_dac_obj_t *self = self_in;
253+
if (self->dac_channel == DAC_CHANNEL_1) {
254+
DAC_Handle.Instance->CR &= ~DAC_CR_EN1;
255+
DAC_Handle.Instance->CR |= DAC_CR_BOFF1;
256+
} else {
257+
DAC_Handle.Instance->CR &= ~DAC_CR_EN2;
258+
DAC_Handle.Instance->CR |= DAC_CR_BOFF2;
259+
}
260+
return mp_const_none;
261+
}
262+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_dac_deinit_obj, pyb_dac_deinit);
263+
249264
#if defined(TIM6)
250265
/// \method noise(freq)
251266
/// Generate a pseudo-random noise signal. A new random sample is written
@@ -461,6 +476,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_write_timed_obj, 1, pyb_dac_write_time
461476
STATIC const mp_map_elem_t pyb_dac_locals_dict_table[] = {
462477
// instance methods
463478
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_dac_init_obj },
479+
{ MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_dac_deinit_obj },
464480
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&pyb_dac_write_obj },
465481
#if defined(TIM6)
466482
{ MP_OBJ_NEW_QSTR(MP_QSTR_noise), (mp_obj_t)&pyb_dac_noise_obj },

0 commit comments

Comments
 (0)