diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.cpp similarity index 90% rename from cores/arduino/WInterrupts.c rename to cores/arduino/WInterrupts.cpp index 6ea0f333a8..dbb3e71852 100644 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.cpp @@ -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)); @@ -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); diff --git a/cores/arduino/WInterrupts.h b/cores/arduino/WInterrupts.h index ce09703880..7294e90fbe 100644 --- a/cores/arduino/WInterrupts.h +++ b/cores/arduino/WInterrupts.h @@ -22,15 +22,15 @@ #include #ifdef __cplusplus -extern "C" { +#include + +typedef std::function 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_ */ diff --git a/cores/arduino/board.h b/cores/arduino/board.h index b1787550c4..194f4ebd7a 100644 --- a/cores/arduino/board.h +++ b/cores/arduino/board.h @@ -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" @@ -22,5 +25,7 @@ #endif //USBCON void init( void ) ; - +#ifdef __cplusplus +} +#endif // __cplusplus #endif /* _BOARD_H_ */ diff --git a/cores/arduino/stm32/interrupt.c b/cores/arduino/stm32/interrupt.cpp similarity index 97% rename from cores/arduino/stm32/interrupt.c rename to cores/arduino/stm32/interrupt.cpp index 745c61fcb3..f2a1e3e12e 100644 --- a/cores/arduino/stm32/interrupt.c +++ b/cores/arduino/stm32/interrupt.cpp @@ -49,9 +49,6 @@ #include "stm32_def.h" #include "interrupt.h" -#ifdef __cplusplus - extern "C" { -#endif /** * @} */ @@ -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 callback; uint32_t mode; }gpio_irq_conf_str; @@ -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); @@ -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 _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 @@ -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 @@ -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 @@ -379,6 +392,10 @@ void EXTI15_10_IRQHandler(void) HAL_GPIO_EXTI_IRQHandler(pin); } } + +#ifdef __cplusplus +} +#endif #endif /** * @} @@ -391,8 +408,4 @@ void EXTI15_10_IRQHandler(void) /** * @} */ -#ifdef __cplusplus -} -#endif - /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/interrupt.h b/cores/arduino/stm32/interrupt.h index 29ab3cba8b..dd95293c68 100644 --- a/cores/arduino/stm32/interrupt.h +++ b/cores/arduino/stm32/interrupt.h @@ -44,7 +44,10 @@ #include "PinNames.h" #ifdef __cplusplus - extern "C" { +#include + +typedef std::function callback_function_t; +void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, callback_function_t callback, uint32_t mode); #endif /* Exported types ------------------------------------------------------------*/ @@ -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 */ diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h index a3f13ee0c4..af6cc34621 100644 --- a/cores/arduino/wiring.h +++ b/cores/arduino/wiring.h @@ -38,13 +38,7 @@ #include "wiring_time.h" #include "WInterrupts.h" -#ifdef __cplusplus -extern "C"{ -#endif // __cplusplus #include -#ifdef __cplusplus -} -#endif #ifdef __cplusplus #include "HardwareSerial.h"