diff --git a/drivers/DigitalIn.h b/drivers/DigitalIn.h index 1dfddcd0cc46..df71fbaa2543 100644 --- a/drivers/DigitalIn.h +++ b/drivers/DigitalIn.h @@ -75,13 +75,20 @@ class DigitalIn { gpio_init_in_ex(&gpio, pin, mode); } + /** Class destructor, deinitialize the pin + */ + virtual ~DigitalIn() + { + gpio_free(&gpio); + } + /** Read the input, represented as 0 or 1 (int) * * @returns * An integer representing the state of the input pin, * 0 for logical 0, 1 for logical 1 */ - int read() + virtual int read() { // Thread safe / atomic HAL call return gpio_read(&gpio); @@ -91,7 +98,7 @@ class DigitalIn { * * @param pull PullUp, PullDown, PullNone, OpenDrain */ - void mode(PinMode pull); + virtual void mode(PinMode pull); /** Return the output setting, represented as 0 or 1 (int) * @@ -99,7 +106,7 @@ class DigitalIn { * Non zero value if pin is connected to uc GPIO * 0 if gpio object was initialized with NC */ - int is_connected() + virtual int is_connected() { // Thread safe / atomic HAL call return gpio_is_connected(&gpio); diff --git a/drivers/DigitalInOut.h b/drivers/DigitalInOut.h index 26fafcac51c7..65d60e6b5359 100644 --- a/drivers/DigitalInOut.h +++ b/drivers/DigitalInOut.h @@ -58,12 +58,19 @@ class DigitalInOut { gpio_init_inout(&gpio, pin, direction, mode, value); } + /** Class destructor, deinitialize the pin + */ + virtual ~DigitalInOut() + { + gpio_free(&gpio); + } + /** Set the output, specified as 0 or 1 (int) * * @param value An integer specifying the pin output value, * 0 for logical 0, 1 (or any other non-zero value) for logical 1 */ - void write(int value) + virtual void write(int value) { // Thread safe / atomic HAL call gpio_write(&gpio, value); @@ -75,7 +82,7 @@ class DigitalInOut { * an integer representing the output setting of the pin if it is an output, * or read the input if set as an input */ - int read() + virtual int read() { // Thread safe / atomic HAL call return gpio_read(&gpio); @@ -83,17 +90,17 @@ class DigitalInOut { /** Set as an output */ - void output(); + virtual void output(); /** Set as an input */ - void input(); + virtual void input(); /** Set the input pin mode * * @param pull PullUp, PullDown, PullNone, OpenDrain */ - void mode(PinMode pull); + virtual void mode(PinMode pull); /** Return the output setting, represented as 0 or 1 (int) * @@ -101,7 +108,7 @@ class DigitalInOut { * Non zero value if pin is connected to uc GPIO * 0 if gpio object was initialized with NC */ - int is_connected() + virtual int is_connected() { // Thread safe / atomic HAL call return gpio_is_connected(&gpio); diff --git a/drivers/DigitalOut.h b/drivers/DigitalOut.h index dd910cc4c8c2..4ea519a4e80b 100644 --- a/drivers/DigitalOut.h +++ b/drivers/DigitalOut.h @@ -70,12 +70,19 @@ class DigitalOut { gpio_init_out_ex(&gpio, pin, value); } + /** Class destructor, deinitialize the pin + */ + virtual ~DigitalOut() + { + gpio_free(&gpio); + } + /** Set the output, specified as 0 or 1 (int) * * @param value An integer specifying the pin output value, * 0 for logical 0, 1 (or any other non-zero value) for logical 1 */ - void write(int value) + virtual void write(int value) { // Thread safe / atomic HAL call gpio_write(&gpio, value); @@ -87,7 +94,7 @@ class DigitalOut { * an integer representing the output setting of the pin, * 0 for logical 0, 1 for logical 1 */ - int read() + virtual int read() { // Thread safe / atomic HAL call return gpio_read(&gpio); @@ -99,7 +106,7 @@ class DigitalOut { * Non zero value if pin is connected to uc GPIO * 0 if gpio object was initialized with NC */ - int is_connected() + virtual int is_connected() { // Thread safe / atomic HAL call return gpio_is_connected(&gpio);