Skip to content

Added ability to bind std:function on interrupts #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cores/arduino/WInterrupts.c → cores/arduino/WInterrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
#include "WInterrupts.h"
#include "Arduino.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "PinAF_STM32F1.h"
#include "interrupt.h"

void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
{
void attachInterrupt(uint32_t pin, callback_function_t callback, uint32_t mode){
uint32_t it_mode;
PinName p = digitalPinToPinName(pin);
GPIO_TypeDef* port = set_GPIO_Port_Clock(STM_PORT(p));
Expand Down Expand Up @@ -57,6 +53,12 @@ void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
stm32_interrupt_enable(port, STM_GPIO_PIN(p), callback, it_mode);
}

void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
{
callback_function_t _c = callback;
attachInterrupt(pin,_c,mode);
}

void detachInterrupt(uint32_t pin)
{
PinName p = digitalPinToPinName(pin);
Expand Down
10 changes: 5 additions & 5 deletions cores/arduino/WInterrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#include <functional>

typedef std::function<void(void)> callback_function_t;
void attachInterrupt(uint32_t pin, callback_function_t callback, uint32_t mode);

#endif

void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode);

void detachInterrupt(uint32_t pin);

#ifdef __cplusplus
}
#endif

#endif /* _WIRING_INTERRUPTS_ */
11 changes: 8 additions & 3 deletions cores/arduino/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

/*
* Core and peripherals registers definitions
*/
*/
#include "interrupt.h"
#ifdef __cplusplus
extern "C"{
#endif // __cplusplus
#include "analog.h"
#include "clock.h"
#include "core_callback.h"
#include "digital_io.h"
#include "hal_uart_emul.h"
#include "hw_config.h"
#include "interrupt.h"
#include "spi_com.h"
#include "stm32_eeprom.h"
#include "timer.h"
Expand All @@ -22,5 +25,7 @@
#endif //USBCON

void init( void ) ;

#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* _BOARD_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
#include "stm32_def.h"
#include "interrupt.h"

#ifdef __cplusplus
extern "C" {
#endif
/**
* @}
*/
Expand All @@ -62,8 +59,8 @@

/*As we can have only one interrupt/pin id, don't need to get the port info*/
typedef struct {
uint32_t irqnb;
void (*callback)(void);
IRQn_Type irqnb;
std::function<void(void)> callback;
uint32_t mode;
}gpio_irq_conf_str;

Expand Down Expand Up @@ -156,16 +153,7 @@ uint8_t get_pin_id(uint16_t pin)

return id;
}
/**
* @brief This function enable the interruption on the selected port/pin
* @param port : one of the gpio port
* @param pin : one of the gpio pin
**@param callback : callback to call when the interrupt falls
* @param mode : one of the supported interrupt mode defined in stm32_hal_gpio
* @retval None
*/
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(void), uint32_t mode)
{
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, callback_function_t callback, uint32_t mode){
GPIO_InitTypeDef GPIO_InitStruct;
uint8_t id = get_pin_id(pin);

Expand Down Expand Up @@ -227,6 +215,21 @@ void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(v
HAL_NVIC_EnableIRQ(gpio_irq_conf[id].irqnb);
}

/**
* @brief This function enable the interruption on the selected port/pin
* @param port : one of the gpio port
* @param pin : one of the gpio pin
**@param callback : callback to call when the interrupt falls
* @param mode : one of the supported interrupt mode defined in stm32_hal_gpio
* @retval None
*/
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(void), uint32_t mode)
{
std::function<void(void)> _c = callback;
stm32_interrupt_enable(port,pin,_c,mode);

}

/**
* @brief This function disable the interruption on the selected port/pin
* @param port : one of the gpio port
Expand Down Expand Up @@ -263,6 +266,10 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
}

#if defined (STM32F0xx) || defined (STM32L0xx)
#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief This function handles external line 0 to 1 interrupt request.
* @param None
Expand Down Expand Up @@ -302,7 +309,13 @@ void EXTI4_15_IRQHandler(void)
HAL_GPIO_EXTI_IRQHandler(pin);
}
}
#ifdef __cplusplus
}
#endif
#else
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief This function handles external line 0 interrupt request.
* @param None
Expand Down Expand Up @@ -379,6 +392,10 @@ void EXTI15_10_IRQHandler(void)
HAL_GPIO_EXTI_IRQHandler(pin);
}
}

#ifdef __cplusplus
}
#endif
#endif
/**
* @}
Expand All @@ -391,8 +408,4 @@ void EXTI15_10_IRQHandler(void)
/**
* @}
*/
#ifdef __cplusplus
}
#endif

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
8 changes: 4 additions & 4 deletions cores/arduino/stm32/interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
#include "PinNames.h"

#ifdef __cplusplus
extern "C" {
#include <functional>

typedef std::function<void(void)> callback_function_t;
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, callback_function_t callback, uint32_t mode);
#endif

/* Exported types ------------------------------------------------------------*/
Expand All @@ -53,9 +56,6 @@
/* Exported functions ------------------------------------------------------- */
void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(void), uint32_t mode);
void stm32_interrupt_disable(GPIO_TypeDef *port, uint16_t pin);
#ifdef __cplusplus
}
#endif

#endif /* __INTERRUPT_H */

Expand Down
6 changes: 0 additions & 6 deletions cores/arduino/wiring.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@
#include "wiring_time.h"
#include "WInterrupts.h"

#ifdef __cplusplus
extern "C"{
#endif // __cplusplus
#include <board.h>
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
#include "HardwareSerial.h"
Expand Down