diff --git a/libraries/IRremote/src/IRremoteInt.h b/libraries/IRremote/src/IRremoteInt.h index 7a35ffa..2f9bcc5 100644 --- a/libraries/IRremote/src/IRremoteInt.h +++ b/libraries/IRremote/src/IRremoteInt.h @@ -434,6 +434,9 @@ extern IRrecv IrReceiver; /* * The receiver interrupt handler for timer interrupt */ +#if defined (MIK32V2) +__attribute__((noinline, section(".ram_text"), optimize("O3"))) +# endif void IRReceiveTimerInterruptHandler(); /**************************************************** diff --git a/libraries/IRremote/src/digitalWriteFast.h b/libraries/IRremote/src/digitalWriteFast.h index 043ae71..c21b61e 100644 --- a/libraries/IRremote/src/digitalWriteFast.h +++ b/libraries/IRremote/src/digitalWriteFast.h @@ -314,6 +314,14 @@ #define __digitalPinToBit(P) (((P) <= 7) ? (P) : (P) - 8 ) # endif +#elif defined(MIK32V2) +#include "wiring_LL.h" + +#define pinModeFast(P, V) pinMode(P, V) +#define digitalWriteFast(P, V) ((V==1) ? GPIO_SET_PIN(digitalPinToPort(P), digitalPinToBitMask(P)) : GPIO_CLEAR_PIN(digitalPinToPort(P), digitalPinToBitMask(P))) +#define digitalReadFast(P) GPIO_READ_PIN(digitalPinToPort(P), digitalPinToBitMask(P)) +#define digitalToggleFast(P) GPIO_TOGGLE_PIN(digitalPinToPort(P), digitalPinToBitMask(P)) + #endif diff --git a/libraries/IRremote/src/private/IRTimer.hpp b/libraries/IRremote/src/private/IRTimer.hpp index aaf2ed9..16cb0af 100644 --- a/libraries/IRremote/src/private/IRTimer.hpp +++ b/libraries/IRremote/src/private/IRTimer.hpp @@ -2018,6 +2018,60 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { } # endif // defined(SEND_PWM_BY_TIMER) + +/*************************************** + * MIK32V2 based boards + ***************************************/ +#elif defined(MIK32V2) +#include "mik32_hal_timer16.h" +#include "mik32_hal_irq.h" +#include "wiring_LL.h" + +// -------------------------- receiving -------------------------- // +#define MIK32_IR_REC_TIMER_PERIOD ((F_CPU / MICROS_IN_ONE_SECOND) * MICROS_PER_TICK) +// use timer16_0 +Timer16_HandleTypeDef htimer16_0; + +void timerConfigForReceive() +{ + // init timer + htimer16_0.Instance = TIMER16_0; + htimer16_0.Clock.Source = TIMER16_SOURCE_INTERNAL_SYSTEM; + htimer16_0.Clock.Prescaler = 0; + htimer16_0.CountMode = TIMER16_COUNTMODE_INTERNAL; + htimer16_0.ActiveEdge = TIMER16_ACTIVEEDGE_RISING; + htimer16_0.Preload = TIMER16_PRELOAD_AFTERWRITE; + htimer16_0.Trigger.Source = 0; + htimer16_0.Trigger.ActiveEdge = TIMER16_TRIGGER_ACTIVEEDGE_SOFTWARE; + htimer16_0.Trigger.TimeOut = TIMER16_TIMEOUT_DISABLE; + htimer16_0.Filter.ExternalClock = TIMER16_FILTER_NONE; + htimer16_0.Filter.Trigger = TIMER16_FILTER_NONE; + htimer16_0.Waveform.Enable = TIMER16_WAVEFORM_GENERATION_DISABLE; + htimer16_0.Waveform.Polarity = TIMER16_WAVEFORM_POLARITY_NONINVERTED; + htimer16_0.EncoderMode = TIMER16_ENCODER_DISABLE; + HAL_Timer16_Init(&htimer16_0); + + HAL_EPIC_MaskLevelSet(HAL_EPIC_TIMER16_0_MASK); +} + +void timerEnableReceiveInterrupt() +{ + HAL_Timer16_Counter_Start_IT(&htimer16_0, MIK32_IR_REC_TIMER_PERIOD); +} + +void timerDisableReceiveInterrupt() +{ + HAL_Timer16_Stop_IT(&htimer16_0); +} + +extern "C" void __attribute__((noinline, section(".ram_text"), optimize("O3"))) IRremote_interrupt_handler(void) +{ + if (TIM16_GET_ARRM_INT_STATUS(htimer16_0)) + IRReceiveTimerInterruptHandler(); // timer period has passed, call interrupt handler + + TIM16_CLEAR_INT_MASK(htimer16_0, 0xFFFFFFFF); // reset timer interrupt flags +} + /*************************************** * Unknown CPU board ***************************************/