-#if defined(PIC_C18)\r
- OpenTimer;\r
- irsnd_set_freq (IRSND_FREQ_36_KHZ); //default frequency\r
- IRSND_PIN = 1; //default PWM output pin off (0=PWM on, 1=PWM off)\r
-#else\r
- IRSND_PORT &= ~(1<<IRSND_BIT); // set IRSND_BIT to low\r
- IRSND_DDR |= (1<<IRSND_BIT); // set IRSND_BIT to output\r
-\r
-#if IRSND_OCx == IRSND_OC2 // use OC2\r
- TCCR2 = (1<<WGM21); // CTC mode\r
- TCCR2 |= (1<<CS20); // 0x01, start Timer 2, no prescaling\r
-#elif IRSND_OCx == IRSND_OC2A || IRSND_OCx == IRSND_OC2B // use OC2A or OC2B\r
- TCCR2A = (1<<WGM21); // CTC mode\r
- TCCR2B |= (1<<CS20); // 0x01, start Timer 2, no prescaling\r
-#elif IRSND_OCx == IRSND_OC0 // use OC0\r
- TCCR0 = (1<<WGM01); // CTC mode\r
- TCCR0 |= (1<<CS00); // 0x01, start Timer 0, no prescaling\r
-#elif IRSND_OCx == IRSND_OC0A || IRSND_OCx == IRSND_OC0B // use OC0A or OC0B\r
- TCCR0A = (1<<WGM01); // CTC mode\r
- TCCR0B |= (1<<CS00); // 0x01, start Timer 0, no prescaling\r
-#else\r
-#error wrong value of IRSND_OCx\r
-#endif\r
- irsnd_set_freq (IRSND_FREQ_36_KHZ); // default frequency\r
-#endif //PIC_C18\r
+# if defined(PIC_C18) // PIC C18\r
+ OpenTimer;\r
+ irsnd_set_freq (IRSND_FREQ_36_KHZ); //default frequency\r
+ IRSND_PIN = 1; //default PWM output pin off (0=PWM on, 1=PWM off)\r
+# elif defined (ARM_STM32) // STM32\r
+ GPIO_InitTypeDef GPIO_InitStructure;\r
+\r
+ /* GPIOx clock enable */\r
+# if defined (ARM_STM32L1XX)\r
+ RCC_AHBPeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
+# elif defined (ARM_STM32F10X)\r
+ RCC_APB2PeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
+# elif defined (ARM_STM32F4XX)\r
+ RCC_AHB1PeriphClockCmd(IRSND_PORT_RCC, ENABLE);\r
+# endif\r
+\r
+ /* GPIO Configuration */\r
+ GPIO_InitStructure.GPIO_Pin = IRSND_BIT;\r
+# if defined (ARM_STM32L1XX) || defined (ARM_STM32F4XX)\r
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\r
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;\r
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;\r
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;\r
+ GPIO_Init(IRSND_PORT, &GPIO_InitStructure);\r
+ GPIO_PinAFConfig(IRSND_PORT, (uint8_t)IRSND_BIT_NUMBER, IRSND_GPIO_AF);\r
+# elif defined (ARM_STM32F10X)\r
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;\r
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;\r
+ GPIO_Init(IRSND_PORT, &GPIO_InitStructure);\r
+ GPIO_PinRemapConfig(, ENABLE); // TODO: remapping required\r
+# endif\r
+\r
+ /* TIMx clock enable */\r
+# if ((IRSND_TIMER_NUMBER >= 2) && (IRSND_TIMER_NUMBER <= 5)) || ((IRSND_TIMER_NUMBER >= 12) && (IRSND_TIMER_NUMBER <= 14))\r
+ RCC_APB1PeriphClockCmd(IRSND_TIMER_RCC, ENABLE);\r
+# else\r
+ RCC_APB2PeriphClockCmd(IRSND_TIMER_RCC, ENABLE);\r
+# endif\r
+ irsnd_set_freq (IRSND_FREQ_36_KHZ); // default frequency\r
+\r
+ /* TIMx Configuration */\r
+ TIM_OC1PreloadConfig(IRSND_TIMER, TIM_OCPreload_Enable);\r
+ TIM_ARRPreloadConfig(IRSND_TIMER, ENABLE);\r
+ TIM_Cmd(IRSND_TIMER, ENABLE);\r
+# else // AVR\r
+ IRSND_PORT &= ~(1<<IRSND_BIT); // set IRSND_BIT to low\r
+ IRSND_DDR |= (1<<IRSND_BIT); // set IRSND_BIT to output\r
+\r
+# if IRSND_OCx == IRSND_OC2 // use OC2\r
+ TCCR2 = (1<<WGM21); // CTC mode\r
+ TCCR2 |= (1<<CS20); // 0x01, start Timer 2, no prescaling\r
+# elif IRSND_OCx == IRSND_OC2A || IRSND_OCx == IRSND_OC2B // use OC2A or OC2B\r
+ TCCR2A = (1<<WGM21); // CTC mode\r
+ TCCR2B |= (1<<CS20); // 0x01, start Timer 2, no prescaling\r
+# elif IRSND_OCx == IRSND_OC0 // use OC0\r
+ TCCR0 = (1<<WGM01); // CTC mode\r
+ TCCR0 |= (1<<CS00); // 0x01, start Timer 0, no prescaling\r
+# elif IRSND_OCx == IRSND_OC0A || IRSND_OCx == IRSND_OC0B // use OC0A or OC0B\r
+ TCCR0A = (1<<WGM01); // CTC mode\r
+ TCCR0B |= (1<<CS00); // 0x01, start Timer 0, no prescaling\r
+# else\r
+# error wrong value of IRSND_OCx\r
+# endif\r
+ irsnd_set_freq (IRSND_FREQ_36_KHZ); // default frequency\r
+# endif //PIC_C18\r