-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*!\file GPIO_ex.c | ||
** \author SMFSW | ||
** \version v0.2 | ||
** \date 2017 | ||
** \copyright MIT (c) 2017, SMFSW | ||
** \brief Simple extension for GPIOs | ||
**/ | ||
#include <string.h> | ||
|
||
#include "GPIO_ex.h" | ||
|
||
#define MAX_PINS_PORT 16 | ||
|
||
|
||
int str_GPIO_name(char * name, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) | ||
{ | ||
const char *port, prt[][7] = { "GPIOA", "GPIOB", "GPIOC", "GPIOD", "GPIOF", "GPIO?" }; | ||
char pin; | ||
|
||
if (!name) { return -1; } // pointer for storage is not defined | ||
|
||
// Find port comparing address | ||
if (GPIOx == GPIOA) { port = prt[0]; } | ||
else if (GPIOx == GPIOB) { port = prt[1]; } | ||
else if (GPIOx == GPIOC) { port = prt[2]; } | ||
else if (GPIOx == GPIOD) { port = prt[3]; } | ||
else if (GPIOx == GPIOF) { port = prt[4]; } | ||
else { port = prt[5]; } | ||
|
||
// Find pin shifting values to get pin index | ||
for (pin = 0 ; pin < MAX_PINS_PORT ; pin++) | ||
{ | ||
if (1U << pin == GPIO_Pin) | ||
{ | ||
sprintf(name, "%s%i", port, pin); | ||
return 0; // Match, return 0 | ||
} | ||
} | ||
sprintf(name, "%s%s", port, "xx"); | ||
return -1; // No match, return -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*!\file GPIO_ex.h | ||
** \author SMFSW | ||
** \version v0.2 | ||
** \date 2017 | ||
** \copyright MIT (c) 2017, SMFSW | ||
** \brief Simple extension for GPIOs | ||
**/ | ||
/****************************************************************/ | ||
#ifndef __GPIO_EX_H | ||
#define __GPIO_EX_H | ||
/****************************************************************/ | ||
#include <string.h> | ||
|
||
#include "sarmfsw.h" | ||
#include CMSIS_INC | ||
|
||
/*!\enum enActOut | ||
** \brief Enum des pilotages possibles de sorties logiques | ||
**/ | ||
typedef enum enActOut{ | ||
Reset = 0, //!< Reset Output | ||
Set, //!< Set Output | ||
Toggle //!< Toggle Output | ||
} ActOut; | ||
|
||
|
||
int str_GPIO_name(char * name, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); | ||
|
||
|
||
/*!\brief Write GPIO | ||
** \param[in] GPIOx - port to write to | ||
** \param[in] GPIO_Pin - pin to write to | ||
** \param[in] Act - type of write | ||
** \return Nothing | ||
**/ | ||
__INLINE void __attribute__((always_inline)) write_GPIO(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, ActOut Act) | ||
{ | ||
if (Act > Toggle) { return; } | ||
else | ||
{ | ||
if (Act == Reset) { HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_RESET); } | ||
if (Act == Set) { HAL_GPIO_WritePin(GPIOx, GPIO_Pin, GPIO_PIN_SET); } | ||
if (Act == Toggle) { HAL_GPIO_TogglePin(GPIOx, GPIO_Pin); } | ||
#if defined(VERBOSE) | ||
char port[10] = ""; | ||
str_GPIO_name(port, GPIOx, GPIO_Pin); | ||
printf("Written %s to %u at: %lums\n", port, HAL_GPIO_ReadPin(GPIOx, GPIO_Pin), HAL_GetTick()); | ||
#endif | ||
} | ||
} | ||
|
||
/*!\brief Read GPIO | ||
** \param[in] GPIOx - port to read from | ||
** \param[in] GPIO_Pin - pin to read from | ||
** \return Nothing | ||
**/ | ||
__INLINE GPIO_PinState __attribute__((always_inline)) read_GPIO(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) | ||
{ | ||
#if defined(VERBOSE) | ||
GPIO_PinState pin = HAL_GPIO_ReadPin(GPIOx, GPIO_Pin); | ||
char port[10] = ""; | ||
str_GPIO_name(port, GPIOx, GPIO_Pin); | ||
printf("Read %s is %u at: %lums\n", port, pin, HAL_GetTick()); | ||
return pin; | ||
#else | ||
return HAL_GPIO_ReadPin(GPIOx, GPIO_Pin); | ||
#endif | ||
} | ||
|
||
/****************************************************************/ | ||
#endif /* __GPIO_EX_H */ | ||
/****************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.