Skip to content

Commit fa03e53

Browse files
committed
cores/psoc: GPIO Deinit added.
Signed-off-by: IFX-Anusha <Anusha.TR@infineon.com>
1 parent 529dee1 commit fa03e53

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cores/psoc6/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C" {
3939
// ****************************************************************************
4040
extern const cyhal_gpio_t mapping_gpio_pin[];
4141
extern const uint8_t GPIO_PIN_COUNT;
42+
extern bool gpio_initialized[];
4243

4344
#define GPIO_INTERRUPT_PRIORITY 3 // GPIO interrupt priority
4445
#define digitalPinToInterrupt(p) ((p) < GPIO_PIN_COUNT ? (p) : -1)

cores/psoc6/digital_io.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ extern "C" {
2323
#endif
2424

2525
void pinMode(pin_size_t pinNumber, PinMode pinMode) {
26+
27+
2628
if (pinNumber > GPIO_PIN_COUNT) {
2729
return; // Invalid pin number
2830
}
2931

32+
// check if pinNumber is initialized before
33+
if (gpio_initialized[pinNumber]) {
34+
cyhal_gpio_free(mapping_gpio_pin[pinNumber]);
35+
gpio_initialized[pinNumber] = false;
36+
}
37+
3038
cyhal_gpio_direction_t direction;
3139
cyhal_gpio_drive_mode_t drive_mode;
3240
bool initPinValue = false;
@@ -65,6 +73,8 @@ void pinMode(pin_size_t pinNumber, PinMode pinMode) {
6573

6674
// Initialize the GPIO pin with the specified direction, drive mode and set initial value
6775
(void)cyhal_gpio_init(mapping_gpio_pin[pinNumber], direction, drive_mode, initPinValue);
76+
77+
gpio_initialized[pinNumber] = true;
6878
}
6979

7080
PinStatus digitalRead(pin_size_t pinNumber) {

0 commit comments

Comments
 (0)