From 9e317ce9f3c69a4b000e793cb6f5a143fd1b43c1 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Tue, 21 Jan 2025 16:59:34 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D1=83?= =?UTF-8?q?=20=D1=81=D0=B8=D0=B3=D0=BD=D0=B0=D0=BB=D0=B0.=20=D1=87=D1=82?= =?UTF-8?q?=D0=BE-=D1=82=D0=BE=20=D1=80=D0=B8=D1=81=D1=83=D1=8E=D1=82=20?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=BE=D0=B3=D0=B0=D0=BC=D0=B8,=20=D0=B8=20?= =?UTF-8?q?=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D0=A8=D0=98=D0=9C,=20=D0=B2?= =?UTF-8?q?=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BF=D0=BE=D1=85=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=8B=20=D1=81=20=D1=83=D0=BD=D0=BE,=20=D0=BD?= =?UTF-8?q?=D0=BE=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D1=88=D0=B8=D0=BC=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=B0=D1=83=D0=B7=D0=B5=20=D0=B8=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=B2=20=D0=B2=D0=B5=D1=80=D1=85?= =?UTF-8?q?=D0=BD=D0=B5=D0=BC=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BE=D1=81=D1=82=D0=B0=D0=B5=D0=BC=D1=81=D1=8F?= =?UTF-8?q?,=20=D0=B0=20=D0=BD=D0=B5=20=D0=B2=20=D0=BD=D0=B8=D0=B6=D0=BD?= =?UTF-8?q?=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/IRremote/src/private/IRTimer.hpp | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/libraries/IRremote/src/private/IRTimer.hpp b/libraries/IRremote/src/private/IRTimer.hpp index 16cb0af..1dae488 100644 --- a/libraries/IRremote/src/private/IRTimer.hpp +++ b/libraries/IRremote/src/private/IRTimer.hpp @@ -2072,6 +2072,65 @@ extern "C" void __attribute__((noinline, section(".ram_text"), optimize("O3"))) TIM16_CLEAR_INT_MASK(htimer16_0, 0xFFFFFFFF); // reset timer interrupt flags } +# if defined(SEND_PWM_BY_TIMER) +#include "pins_arduino.h" +#define IR_SEND_PIN 3 + +static TIMER32_HandleTypeDef ir_sender_htimer; +static TIMER32_CHANNEL_HandleTypeDef ir_sender_htimer_channel; + +/* + * timerConfigForSend() is used exclusively by IRsend::enableIROut() + * Set output pin mode and disable receive interrupt if it uses the same resource + */ +void timerConfigForSend(uint16_t aFrequencyKHz) +{ + uint32_t pwmTopVal = 0; + if ((aFrequencyKHz*1000) <= PWM_FREQUENCY_MAX) + pwmTopVal = F_CPU/(aFrequencyKHz*1000)-3; + else + ErrorMsgHandler("timerConfigForSend(): invalid frequency for IR sending"); + + // initialization of the required timer + ir_sender_htimer.Instance = pwmPinToTimer(IR_SEND_PIN); + ir_sender_htimer.Top = pwmTopVal; + ir_sender_htimer.State = TIMER32_STATE_DISABLE; + ir_sender_htimer.Clock.Source = TIMER32_SOURCE_PRESCALER; + ir_sender_htimer.Clock.Prescaler = 0; // Prescaler = 1 + ir_sender_htimer.InterruptMask = 0; + ir_sender_htimer.CountMode = TIMER32_COUNTMODE_FORWARD; + HAL_Timer32_Init(&ir_sender_htimer); + + // gpio init as timer channel pin + HAL_GPIO_PinConfig(digitalPinToPort(IR_SEND_PIN), digitalPinToBitMask(IR_SEND_PIN), + HAL_GPIO_MODE_TIMER_SERIAL, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA); + + ir_sender_htimer_channel.TimerInstance = ir_sender_htimer.Instance; + ir_sender_htimer_channel.ChannelIndex = pwmPinToTimerChannel(IR_SEND_PIN); + ir_sender_htimer_channel.PWM_Invert = TIMER32_CHANNEL_NON_INVERTED_PWM; + ir_sender_htimer_channel.Mode = TIMER32_CHANNEL_MODE_PWM; + ir_sender_htimer_channel.CaptureEdge = TIMER32_CHANNEL_CAPTUREEDGE_RISING; + ir_sender_htimer_channel.OCR = ((pwmTopVal * IR_SEND_DUTY_CYCLE_PERCENT)/100); + ir_sender_htimer_channel.Noise = TIMER32_CHANNEL_FILTER_OFF; + HAL_Timer32_Channel_Init(&ir_sender_htimer_channel); + + HAL_Timer32_Start(&ir_sender_htimer); +} + +void enableSendPWMByTimer() +{ + // start timer with initialized channel + HAL_Timer32_Value_Clear(&ir_sender_htimer); + HAL_Timer32_Channel_Enable(&ir_sender_htimer_channel); +} + +void disableSendPWMByTimer() +{ + HAL_Timer32_Channel_Disable(&ir_sender_htimer_channel); + digitalWriteFast(IR_SEND_PIN, 1); +} +# endif // defined(SEND_PWM_BY_TIMER) + /*************************************** * Unknown CPU board ***************************************/