Skip to content

Commit

Permalink
* Added GPIO_out_example
Browse files Browse the repository at this point in the history
* Minor corrections in GPIO_in_example
  • Loading branch information
SMFSW committed Nov 16, 2020
1 parent 09bd18b commit e80e8da
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Use it at your own risk!
- GPIO_in: GPIO input handling
- example [GPIO_in_example.c](templates/GPIO_in_example.c.txt)/[GPIO_in_example.h](templates/GPIO_in_example.h.txt): GPIO_in example
- GPIO_out: GPIO output handling
- example [GPIO_out_example.c](templates/GPIO_out_example.c.txt)/[GPIO_out_example.h](templates/GPIO_out_example.h.txt): GPIO_out example
- Logic_ex: Extensions for logic variable handling
- example [Logic_in_example.c](templates/Logic_in_example.c.txt)/[Logic_in_example.h](templates/Logic_in_example.h.txt): Logic_in example
- PWM_IC: PWM Input Capture handling
Expand Down
4 changes: 2 additions & 2 deletions templates/GPIO_in_example.c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
** \author SMFSW
** \copyright MIT (c) 2017-2020, SMFSW
** \brief GPIO_in example
** \note Simple GPIO_ex.c example to handle different GPIO inputs with callbacks (on STM32F3)
** \note Simple GPIO_in.c example to handle different GPIO inputs with callbacks
**/

#include "sarmfsw.h"

#include "GPIO_ex.h"
#include "GPIO_in.h"


#define IN_B0_GPIO_Port GPIOB
Expand Down
4 changes: 2 additions & 2 deletions templates/GPIO_in_example.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
** \author SMFSW
** \copyright MIT (c) 2017-2020, SMFSW
** \brief GPIO_in example
** \note Simple GPIO_ex.c example to handle different GPIO inputs with callbacks (on STM32F3)
** \note Simple GPIO_in.c example to handle different GPIO inputs with callbacks
**/
/****************************************************************/
#ifndef __GPIO_IN_EXAMPLE_H
Expand All @@ -14,7 +14,7 @@
/****************************************************************/


/*!\brief GPIO_ex_ample handler (handling acquisition of inputs and callbacks)
/*!\brief GPIO_in_example handler (handling acquisition of inputs and callbacks)
** \note Callbacks On declared with same function callback (to demonstrate use of passed argument GPIO_in *)
** \note Callbacks Off declared with different function callback (to demonstrate both possibilities)
**/
Expand Down
77 changes: 77 additions & 0 deletions templates/GPIO_out_example.c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*!\file GPIO_in_example.c
** \author SMFSW
** \copyright MIT (c) 2017-2020, SMFSW
** \brief GPIO_out example
** \note Simple GPIO_out.c example to handle different GPIO outputs
**/

#include "sarmfsw.h"

#include "GPIO_out.h"


#define OUT_B0_GPIO_Port GPIOB
#define OUT_B0_Pin GPIO_PIN_0
#define OUT_B1_GPIO_Port GPIOB
#define OUT_B1_Pin GPIO_PIN_1
#define OUT_B2_GPIO_Port GPIOB
#define OUT_B2_Pin GPIO_PIN_2
#define OUT_Bx_TIMER &htim6


static GPIO_out out_B0; //!< GPIO_out out_B0 instance structure declaration
static GPIO_out out_B1; //!< GPIO_out out_B1 instance structure declaration
static GPIO_out out_B2; //!< GPIO_out out_B2 instance structure declaration
static GPIO_out * const GPIOs[] = { &out_B0, &out_B1, &out_B2 }; //!< GPIO_out pointers array (for handler loop)


#ifndef GPIO_OUT_IT
void GPIO_out_example_handler(void)
#else
void GPIO_out_example_init(void)
#endif
{
static bool init_io = false;

if (!init_io)
{
// Init outputs
GPIO_out_init(&out_B0, GPIO(OUT_B0), GPIO_PIN_SET);
GPIO_out_init(&out_B1, GPIO(OUT_B1), GPIO_PIN_SET);
GPIO_out_init(&out_B2, GPIO(OUT_B2), GPIO_PIN_SET);

// Start logic outputs with different modes
GPIO_out_SetStatic(&out_B0, Toggle, 5000); // Set B0 after 5s
GPIO_out_StartBlink(&out_B1, Set, 0, 500, 250, 0); // Blink B1 500ms On / 250ms Off indefinitely
GPIO_out_StartPulse(&out_B2, Set, 3000, 2000); // Pulse on B2 after 3s, Set for 2s

init_io = true;
}

#ifndef GPIO_OUT_IT
for (unsigned int i = 0 ; i < SZ_OBJ(GPIOs, GPIO_out *) ; i++)
{
GPIO_out_handler(GPIOs[i]);
}
#endif
}


#ifdef GPIO_OUT_IT
/*!\brief Period elapsed callback in non blocking mode
** \note This function is called when TIM interrupt took place, inside HAL_TIM_IRQHandler().
** If multiple TIM peripheral use period callback interrupt, custom function is needed including code below.
** Another way is to use callback registration with proper function name.
** \param[in] htim - TIM handle
**/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim == OUT_Bx_TIMER)
{
for (unsigned int i = 0 ; i < SZ_OBJ(GPIOs, GPIO_out *) ; i++) // Needed if multiple PWM_GPIO instances using always same TIM peripheral
{
GPIO_out_handler(GPIOs[i]);
}
}
}
#endif
36 changes: 36 additions & 0 deletions templates/GPIO_out_example.h.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!\file GPIO_out_example.h
** \author SMFSW
** \copyright MIT (c) 2017-2020, SMFSW
** \brief GPIO_out example
** \note Simple GPIO_out.c example to handle different GPIO outputs
**/
/****************************************************************/
#ifndef __GPIO_OUT_EXAMPLE_H
#define __GPIO_OUT_EXAMPLE_H

#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************/


#ifndef GPIO_OUT_IT
/*!\brief GPIO_out_example handler (handling of GPIO logic outputs)
**/
void GPIO_out_example_handler(void);
#else
/*!\brief GPIO_out_example init (handling of GPIO logic outputs)
** \note Rest is done in TIM interrupts
**/
void GPIO_out_example_init(void);
#endif


/****************************************************************/
#ifdef __cplusplus
}
#endif

#endif /* __GPIO_OUT_EXAMPLE_H */
/****************************************************************/

0 comments on commit e80e8da

Please sign in to comment.