From b0795821a1f467c458b1f62af88695fb7c01b10d Mon Sep 17 00:00:00 2001 From: mjm2017 Date: Mon, 1 Jul 2019 21:18:43 +0200 Subject: [PATCH 1/6] Deinitialize the pin definition Without freeing the DAC, the pin will continue to be configured as DAC. Which make it impossible to change it from Analogout to anything else. Check this code that allow you to change the AnalogOut to DigitalOut <> #include "mbed.h" class myAnalog : public AnalogOut{ public: myAnalog(PinName myname); ~myAnalog(); PinName _myname; }; myAnalog::myAnalog(PinName myname):AnalogOut(myname), _myname(myname){ ; } myAnalog::~myAnalog(){ analogout_free(&this->_dac); } myAnalog *x=0; DigitalOut *xx=0; void do_something_analog() { x=new myAnalog(PA_4); double g=0.0; while(g<0.5){ x->write(g); g=g+0.1; wait_ms(50); } if (x!=0){ delete x; x=0; } } void do_something_digital() { xx=new DigitalOut(PA_4); for(int i=0;i<10;i++){ *xx = 1; wait_ms(50); *xx = 0; wait_ms(50); } if (xx!=0){ delete xx; xx=0; } } int main() { printf("\nAnalog loop example\n"); while(1) { do_something_digital(); do_something_analog(); } } <> --- drivers/AnalogOut.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/AnalogOut.h b/drivers/AnalogOut.h index d12cbafcc4d..e82602ceb2d 100644 --- a/drivers/AnalogOut.h +++ b/drivers/AnalogOut.h @@ -138,7 +138,8 @@ class AnalogOut { virtual ~AnalogOut() { - // Do nothing + // deinitialize the pin configuration totally. This should allow chaining the definition of the pin + analogout_free(&this->_dac); } protected: From c6fbcb4efe40093c20a3bce44c2d687d49323746 Mon Sep 17 00:00:00 2001 From: mjm2017 Date: Wed, 3 Jul 2019 06:51:04 +0200 Subject: [PATCH 2/6] Update AnalogOut.h --- drivers/AnalogOut.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/AnalogOut.h b/drivers/AnalogOut.h index e82602ceb2d..9829e3c6ed9 100644 --- a/drivers/AnalogOut.h +++ b/drivers/AnalogOut.h @@ -138,7 +138,8 @@ class AnalogOut { virtual ~AnalogOut() { - // deinitialize the pin configuration totally. This should allow chaining the definition of the pin + /* Deinitialize the pin configuration totally. + This should allow changing the definition of the pin */ analogout_free(&this->_dac); } From 656f4b8adfaf9d9f09ccb84945d8ec9108e9b864 Mon Sep 17 00:00:00 2001 From: Mariwan Date: Mon, 12 Aug 2019 20:12:36 +0200 Subject: [PATCH 3/6] Update AnalogOut.h --- drivers/AnalogOut.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/AnalogOut.h b/drivers/AnalogOut.h index 9829e3c6ed9..35a095cb405 100644 --- a/drivers/AnalogOut.h +++ b/drivers/AnalogOut.h @@ -138,8 +138,9 @@ class AnalogOut { virtual ~AnalogOut() { - /* Deinitialize the pin configuration totally. - This should allow changing the definition of the pin */ + /** Deinitialize the pin configuration totally. + *\ This should allow changing the definition of the pin + */ analogout_free(&this->_dac); } From 358df27c30e9b3e09481065bbb82027e495c61c7 Mon Sep 17 00:00:00 2001 From: Mariwan Date: Mon, 16 Sep 2019 21:46:12 +0200 Subject: [PATCH 4/6] Remove Note as requested --- hal/analogout_api.h | 1 - 1 file changed, 1 deletion(-) diff --git a/hal/analogout_api.h b/hal/analogout_api.h index 95531cc7cc4..4983e43c37c 100644 --- a/hal/analogout_api.h +++ b/hal/analogout_api.h @@ -48,7 +48,6 @@ void analogout_init(dac_t *obj, PinName pin); /** Release the analogout object * - * Note: This is not currently used in the mbed-drivers * @param obj The analogout object */ void analogout_free(dac_t *obj); From 47c3083bddfa7d2015ff49c62f2908fc75c70d4e Mon Sep 17 00:00:00 2001 From: Mariwan Date: Mon, 16 Sep 2019 21:57:56 +0200 Subject: [PATCH 5/6] remove extra space --- drivers/AnalogOut.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/AnalogOut.h b/drivers/AnalogOut.h index 35a095cb405..784290ca685 100644 --- a/drivers/AnalogOut.h +++ b/drivers/AnalogOut.h @@ -141,7 +141,7 @@ class AnalogOut { /** Deinitialize the pin configuration totally. *\ This should allow changing the definition of the pin */ - analogout_free(&this->_dac); + analogout_free(&this->_dac); } protected: From 5b951d4ef4116a1b34d04ae94bd354d3f543aec9 Mon Sep 17 00:00:00 2001 From: Mariwan Date: Mon, 16 Sep 2019 22:06:04 +0200 Subject: [PATCH 6/6] Update AnalogOut.h --- drivers/AnalogOut.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/AnalogOut.h b/drivers/AnalogOut.h index 784290ca685..0e29a718875 100644 --- a/drivers/AnalogOut.h +++ b/drivers/AnalogOut.h @@ -138,10 +138,9 @@ class AnalogOut { virtual ~AnalogOut() { - /** Deinitialize the pin configuration totally. - *\ This should allow changing the definition of the pin + /** Deinitialize pin configuration. */ - analogout_free(&this->_dac); + analogout_free(&_dac); } protected: