Skip to content

Commit cd7979d

Browse files
committed
Clean up digital code after update
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 4aff9b7 commit cd7979d

File tree

4 files changed

+36
-57
lines changed

4 files changed

+36
-57
lines changed

cores/arduino/stm32/digital_io.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/**
22
******************************************************************************
33
* @file digital_io.c
4-
* @author WI6LABS
5-
* @version V1.0.0
6-
* @date 01-August-2016
74
* @brief Provide an interface to configure hw ios
85
*
96
******************************************************************************
@@ -39,7 +36,7 @@
3936
#include "PinAF_STM32F1.h"
4037

4138
#ifdef __cplusplus
42-
extern "C" {
39+
extern "C" {
4340
#endif
4441

4542
/**

cores/arduino/stm32/digital_io.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/**
22
******************************************************************************
33
* @file digital_io.h
4-
* @author WI6LABS
5-
* @version V1.0.0
6-
* @date 01-August-2016
74
* @brief Header for digital_io module
85
******************************************************************************
96
* @attention
@@ -45,12 +42,9 @@
4542
#include "stm32yyxx_ll_gpio.h"
4643

4744
#ifdef __cplusplus
48-
extern "C" {
45+
extern "C" {
4946
#endif
5047

51-
/* Exported types ------------------------------------------------------------*/
52-
/* Exported constants --------------------------------------------------------*/
53-
/* Exported macro ------------------------------------------------------------*/
5448
/* Exported functions ------------------------------------------------------- */
5549
void digital_io_init(PinName pin, uint32_t mode, uint32_t pull);
5650

@@ -63,15 +57,15 @@ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull);
6357
*/
6458
static inline void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t val)
6559
{
66-
if(val) {
60+
if (val) {
6761
LL_GPIO_SetOutputPin(port, pin);
6862
} else {
6963
LL_GPIO_ResetOutputPin(port, pin);
7064
}
7165
}
7266

7367
/**
74-
* @brief This function set a value to an IO
68+
* @brief This function read the value of an IO
7569
* @param port : one of the gpio port
7670
* @param pin : one of the gpio pin
7771
* @retval The pin state (LOW or HIGH)
@@ -98,9 +92,9 @@ static inline void digital_io_toggle(GPIO_TypeDef *port, uint32_t pin)
9892
* @param val : 0 to set to low, any other value to set to high
9993
* @retval None
10094
*/
101-
static inline void digitalWriteFast( PinName pn, uint32_t ulVal )
95+
static inline void digitalWriteFast(PinName pn, uint32_t ulVal)
10296
{
103-
if(pn != NC) {
97+
if (pn != NC) {
10498
digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal);
10599
}
106100
}
@@ -110,13 +104,13 @@ static inline void digitalWriteFast( PinName pn, uint32_t ulVal )
110104
* @param pn : Pin name
111105
* @retval The pin state (LOW or HIGH)
112106
*/
113-
static inline int digitalReadFast( PinName pn )
107+
static inline int digitalReadFast(PinName pn)
114108
{
115109
uint8_t level = 0;
116-
if(pn != NC) {
110+
if (pn != NC) {
117111
level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
118112
}
119-
return (level)? HIGH : LOW;
113+
return (level) ? HIGH : LOW;
120114
}
121115

122116
/**
@@ -127,7 +121,7 @@ static inline int digitalReadFast( PinName pn )
127121
*/
128122
static inline void digitalToggleFast(PinName pn)
129123
{
130-
if(pn != NC) {
124+
if (pn != NC) {
131125
digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
132126
}
133127
}

cores/arduino/wiring_digital.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "PinConfigured.h"
2121

2222
#ifdef __cplusplus
23-
extern "C" {
23+
extern "C" {
2424
#endif
2525

2626

@@ -29,56 +29,55 @@ uint32_t g_digPinConfigured[MAX_NB_PORT] = {0};
2929
extern uint32_t g_anOutputPinConfigured[MAX_NB_PORT];
3030

3131

32-
void pinMode( uint32_t ulPin, uint32_t ulMode )
32+
void pinMode(uint32_t ulPin, uint32_t ulMode)
3333
{
3434
PinName p = digitalPinToPinName(ulPin);
3535

36-
if(p != NC) {
36+
if (p != NC) {
3737
// If the pin that support PWM or DAC output, we need to turn it off
38-
if(is_pin_configured(p, g_anOutputPinConfigured)) {
38+
if (is_pin_configured(p, g_anOutputPinConfigured)) {
3939
#ifdef HAL_DAC_MODULE_ENABLED
40-
if(pin_in_pinmap(p, PinMap_DAC)) {
40+
if (pin_in_pinmap(p, PinMap_DAC)) {
4141
dac_stop(p);
4242
} else
4343
#endif //HAL_DAC_MODULE_ENABLED
44-
if(pin_in_pinmap(p, PinMap_PWM)) {
45-
pwm_stop(p);
46-
}
44+
if (pin_in_pinmap(p, PinMap_PWM)) {
45+
pwm_stop(p);
46+
}
4747
reset_pin_configured(p, g_anOutputPinConfigured);
4848
}
4949

50-
switch ( ulMode )
51-
{
50+
switch (ulMode) {
5251
case INPUT:
5352
digital_io_init(p, GPIO_MODE_INPUT, GPIO_NOPULL);
54-
break;
53+
break;
5554
case INPUT_PULLUP:
5655
digital_io_init(p, GPIO_MODE_INPUT, GPIO_PULLUP);
57-
break;
56+
break;
5857
case INPUT_PULLDOWN:
5958
digital_io_init(p, GPIO_MODE_INPUT, GPIO_PULLDOWN);
60-
break;
59+
break;
6160
case OUTPUT:
6261
digital_io_init(p, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL);
63-
break;
62+
break;
6463
default:
65-
break;
64+
break;
6665
}
6766
set_pin_configured(p, g_digPinConfigured);
6867
}
6968
}
7069

71-
void digitalWrite( uint32_t ulPin, uint32_t ulVal )
70+
void digitalWrite(uint32_t ulPin, uint32_t ulVal)
7271
{
7372
digitalWriteFast(digitalPinToPinName(ulPin), ulVal);
7473
}
7574

76-
int digitalRead( uint32_t ulPin )
75+
int digitalRead(uint32_t ulPin)
7776
{
7877
return digitalReadFast(digitalPinToPinName(ulPin));
7978
}
8079

81-
void digitalToggle( uint32_t ulPin )
80+
void digitalToggle(uint32_t ulPin)
8281
{
8382
digitalToggleFast(digitalPinToPinName(ulPin));
8483
}

cores/arduino/wiring_digital.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,27 @@
2020
#define _WIRING_DIGITAL_
2121

2222
#ifdef __cplusplus
23-
extern "C" {
23+
extern "C" {
2424
#endif
2525

2626
/**
27-
* \brief Configures the specified pin to behave either as an input or an output. See the description of digital pins for details.
27+
* \brief Configures the specified pin to behave either as an input or an output.
2828
*
29-
* \param ulPin The number of the pin whose mode you wish to set
30-
* \param ulMode Either INPUT or OUTPUT
29+
* \param dwPin The number of the pin whose mode you wish to set
30+
* \param dwMode Either INPUT, INPUT_PULLUP, INPUT_PULLDOWN or OUTPUT
3131
*/
32-
extern void pinMode( uint32_t dwPin, uint32_t dwMode ) ;
32+
extern void pinMode(uint32_t dwPin, uint32_t dwMode) ;
3333

3434
/**
3535
* \brief Write a HIGH or a LOW value to a digital pin.
3636
*
3737
* If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the
38-
* corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.
39-
*
40-
* If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal
41-
* 20K pullup resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup
42-
* resistor is enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely
43-
* cause. The remedy is to set the pin to an output with the pinMode() function.
44-
*
45-
* \note Digital pin PIN_LED is harder to use as a digital input than the other digital pins because it has an LED
46-
* and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up
47-
* resistor, it will hang at around 1.7 V instead of the expected 5V because the onboard LED and series resistor
48-
* pull the voltage level down, meaning it always returns LOW. If you must use pin PIN_LED as a digital input, use an
49-
* external pull down resistor.
38+
* corresponding value: 3.3V for HIGH, 0V (ground) for LOW.
5039
*
5140
* \param dwPin the pin number
5241
* \param dwVal HIGH or LOW
5342
*/
54-
extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ;
43+
extern void digitalWrite(uint32_t dwPin, uint32_t dwVal) ;
5544

5645
/**
5746
* \brief Reads the value from a specified digital pin, either HIGH or LOW.
@@ -60,14 +49,14 @@ extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ;
6049
*
6150
* \return HIGH or LOW
6251
*/
63-
extern int digitalRead( uint32_t ulPin ) ;
52+
extern int digitalRead(uint32_t ulPin) ;
6453

6554
/**
6655
* \brief Toggle the value from a specified digital pin.
6756
*
6857
* \param ulPin The number of the digital pin you want to toggle (int)
6958
*/
70-
extern void digitalToggle( uint32_t ulPin ) ;
59+
extern void digitalToggle(uint32_t ulPin) ;
7160

7261
#ifdef __cplusplus
7362
}

0 commit comments

Comments
 (0)