Skip to content

Commit 4aff9b7

Browse files
committed
Add digitalToggle APIs
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 62fd276 commit 4aff9b7

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

cores/arduino/stm32/digital_io.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ static inline uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin)
8181
return LL_GPIO_IsInputPinSet(port, pin);
8282
}
8383

84+
/**
85+
* @brief This function toggle value of an IO
86+
* @param port : one of the gpio port
87+
* @param pin : one of the gpio pin
88+
* @retval None
89+
*/
90+
static inline void digital_io_toggle(GPIO_TypeDef *port, uint32_t pin)
91+
{
92+
LL_GPIO_TogglePin(port, pin);
93+
}
94+
8495
/**
8596
* @brief This function set a value to an IO
8697
* @param pn : Pin name
@@ -108,6 +119,19 @@ static inline int digitalReadFast( PinName pn )
108119
return (level)? HIGH : LOW;
109120
}
110121

122+
/**
123+
* @brief This function toggle value of an IO
124+
* @param port : one of the gpio port
125+
* @param pin : one of the gpio pin
126+
* @retval None
127+
*/
128+
static inline void digitalToggleFast(PinName pn)
129+
{
130+
if(pn != NC) {
131+
digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
132+
}
133+
}
134+
111135
#ifdef __cplusplus
112136
}
113137
#endif

cores/arduino/wiring_digital.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ int digitalRead( uint32_t ulPin )
7878
return digitalReadFast(digitalPinToPinName(ulPin));
7979
}
8080

81+
void digitalToggle( uint32_t ulPin )
82+
{
83+
digitalToggleFast(digitalPinToPinName(ulPin));
84+
}
85+
8186
#ifdef __cplusplus
8287
}
8388
#endif

cores/arduino/wiring_digital.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ;
6262
*/
6363
extern int digitalRead( uint32_t ulPin ) ;
6464

65+
/**
66+
* \brief Toggle the value from a specified digital pin.
67+
*
68+
* \param ulPin The number of the digital pin you want to toggle (int)
69+
*/
70+
extern void digitalToggle( uint32_t ulPin ) ;
71+
6572
#ifdef __cplusplus
6673
}
6774
#endif

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ digitalPinFirstOccurence KEYWORD2
352352
pinIsSerial KEYWORD2
353353
digitalReadFast KEYWORD2
354354
digitalWriteFast KEYWORD2
355+
digitalToggle KEYWORD2
356+
digitalToggleFast KEYWORD2
355357

356358
# Pin number
357359
PA0 LITERAL1

0 commit comments

Comments
 (0)