Skip to content

Commit 2e82a46

Browse files
committed
Add digitalRead/WriteFast API
Use the PinName (PY_n) instead of the pin number (Pyn) Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 859634a commit 2e82a46

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

cores/arduino/stm32/digital_io.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
******************************************************************************
3737
*/
3838
#include "digital_io.h"
39-
#include "stm32_def.h"
40-
#include "hw_config.h"
4139
#include "PinAF_STM32F1.h"
4240

4341
#ifdef __cplusplus

cores/arduino/stm32/digital_io.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
#define __DIGITAL_IO_H
4141

4242
/* Includes ------------------------------------------------------------------*/
43-
#include "stm32_def.h"
44-
#include "PeripheralPins.h"
43+
#include "wiring_constants.h"
44+
#include "PinNames.h"
4545
#include "stm32yyxx_ll_gpio.h"
4646

4747
#ifdef __cplusplus
@@ -70,7 +70,6 @@ static inline void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t v
7070
}
7171
}
7272

73-
7473
/**
7574
* @brief This function set a value to an IO
7675
* @param port : one of the gpio port
@@ -82,6 +81,33 @@ static inline uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin)
8281
return LL_GPIO_IsInputPinSet(port, pin);
8382
}
8483

84+
/**
85+
* @brief This function set a value to an IO
86+
* @param pn : Pin name
87+
* @param val : 0 to set to low, any other value to set to high
88+
* @retval None
89+
*/
90+
static inline void digitalWriteFast( PinName pn, uint32_t ulVal )
91+
{
92+
if(pn != NC) {
93+
digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal);
94+
}
95+
}
96+
97+
/**
98+
* @brief This function read the value of an IO
99+
* @param pn : Pin name
100+
* @retval The pin state (LOW or HIGH)
101+
*/
102+
static inline int digitalReadFast( PinName pn )
103+
{
104+
uint8_t level = 0;
105+
if(pn != NC) {
106+
level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
107+
}
108+
return (level)? HIGH : LOW;
109+
}
110+
85111
#ifdef __cplusplus
86112
}
87113
#endif

cores/arduino/wiring_digital.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,12 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
7070

7171
void digitalWrite( uint32_t ulPin, uint32_t ulVal )
7272
{
73-
PinName p = digitalPinToPinName(ulPin);
74-
if(p != NC) {
75-
digital_io_write(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p), ulVal);
76-
}
73+
digitalWriteFast(digitalPinToPinName(ulPin), ulVal);
7774
}
7875

7976
int digitalRead( uint32_t ulPin )
8077
{
81-
uint8_t level = 0;
82-
PinName p = digitalPinToPinName(ulPin);
83-
if(p != NC) {
84-
level = digital_io_read(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p));
85-
}
86-
return (level)? HIGH : LOW;
78+
return digitalReadFast(digitalPinToPinName(ulPin));
8779
}
8880

8981
#ifdef __cplusplus

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ portConfigRegister KEYWORD2
350350
digitalPinIsValid KEYWORD2
351351
digitalPinFirstOccurence KEYWORD2
352352
pinIsSerial KEYWORD2
353+
digitalReadFast KEYWORD2
354+
digitalWriteFast KEYWORD2
353355

354356
# Pin number
355357
PA0 LITERAL1

0 commit comments

Comments
 (0)