diff options
author | Peter Hinch <peter@hinch.me.uk> | 2016-05-26 07:39:04 +0100 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-05-31 13:10:35 +0300 |
commit | 641300dccb0a68e4ede07323aabeed564a892a8f (patch) | |
tree | 25b585f97ddefa0c9837e5db08f56106ea54ce28 | |
parent | ee009d713a40e710bd6c7d5e98b47f5825fd3e69 (diff) | |
download | micropython-641300dccb0a68e4ede07323aabeed564a892a8f.tar.gz micropython-641300dccb0a68e4ede07323aabeed564a892a8f.zip |
stmhal/dac: DAC deinit() method added.
-rw-r--r-- | docs/library/pyb.DAC.rst | 4 | ||||
-rw-r--r-- | stmhal/dac.c | 16 |
2 files changed, 20 insertions, 0 deletions
diff --git a/docs/library/pyb.DAC.rst b/docs/library/pyb.DAC.rst index 6041151b0f..7b5b1a6821 100644 --- a/docs/library/pyb.DAC.rst +++ b/docs/library/pyb.DAC.rst @@ -66,6 +66,10 @@ Methods Reinitialise the DAC. ``bits`` can be 8 or 12. +.. method:: dac.deinit() + + De-initialise the DAC making its pin available for other uses. + .. method:: dac.noise(freq) Generate a pseudo-random noise signal. A new random sample is written diff --git a/stmhal/dac.c b/stmhal/dac.c index bb700883db..7493bb59ab 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -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 } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_init_obj, 1, pyb_dac_init); +/// \method deinit() +/// Turn off the DAC, enable other use of pin. +STATIC mp_obj_t pyb_dac_deinit(mp_obj_t self_in) { + pyb_dac_obj_t *self = self_in; + if (self->dac_channel == DAC_CHANNEL_1) { + DAC_Handle.Instance->CR &= ~DAC_CR_EN1; + DAC_Handle.Instance->CR |= DAC_CR_BOFF1; + } else { + DAC_Handle.Instance->CR &= ~DAC_CR_EN2; + DAC_Handle.Instance->CR |= DAC_CR_BOFF2; + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_dac_deinit_obj, pyb_dac_deinit); + #if defined(TIM6) /// \method noise(freq) /// 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 STATIC const mp_map_elem_t pyb_dac_locals_dict_table[] = { // instance methods { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_dac_init_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_dac_deinit_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&pyb_dac_write_obj }, #if defined(TIM6) { MP_OBJ_NEW_QSTR(MP_QSTR_noise), (mp_obj_t)&pyb_dac_noise_obj }, |