-
Notifications
You must be signed in to change notification settings - Fork 3k
Deinitialize the pin definition #10940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
<<code>>
#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();
}
}
<</code>>
|
@mjm2017, thank you for your changes. |
drivers/AnalogOut.h
Outdated
| { | ||
| // Do nothing | ||
| // deinitialize the pin configuration totally. This should allow chaining the definition of the pin | ||
| analogout_free(&this->_dac); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix the code style - see travis astyle failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, But this is my first pull request. Please feel free to change my patch to whatever works for you by that I learn also to not make that mistake again.
thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this with Nucleo-L476RG.
The example sent with the patch .. I re-write it again:
#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();
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, worth reading: https://os.mbed.com/docs/mbed-os/v5.13/contributing/style.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please align the comment and the code line 143? Otherwise looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear Martin,
I cannot find this note as you mentioned (" Note: This is not currently used in the mbed-drivers")
Please write down for me the link to the file.
Notice that My change is only for NUCLEO-L476RG
|
This should be fixed in few other drivers as well. There are implications - free is either not implemented or if it is, we do not know what can happen once it is invoked in drivers. This change should have tests with it. How did you test it (what target do you use) ? I would get this to the next minor release. Remove also the comment:
Initialization for different use should take care of it in this use case (if you do AnalogIn on the pin, it should be reconfigured). Still though free should be invoked. |
Still to do Travis fails , please review astyle job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments fixed
|
astyle job still fails, please review. @ARMmbed/mbed-os-hal Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drivers/AnalogOut.h
Outdated
| /** Deinitialize the pin configuration totally. | ||
| *\ This should allow changing the definition of the pin | ||
| */ | ||
| analogout_free(&this->_dac); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| analogout_free(&this->_dac); | |
| analogout_free(&_dac); |
Private members are already marked with a _ prefix; no need to use this pointer here.
|
@fkjagodzinski Please review |
|
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
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.
Description
Pull request type
Reviewers
Release Notes