summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2017-04-30 12:43:56 +0200
committerLeo C2017-04-30 12:43:56 +0200
commit54cbcce61b31454cc76ad2a75d4d5e479d896345 (patch)
tree3fa240748ce2f8b0abfbda17da867c0a45f1a66b
parenta8915151dc5ddd5342d4b8db48a563abf4369891 (diff)
downloadirmp-54cbcce61b31454cc76ad2a75d4d5e479d896345.zip
libopencm3 for IRSND
-rw-r--r--irmpprotocols.h2
-rw-r--r--irsnd.c75
-rw-r--r--irsnd.h12
-rw-r--r--irsndconfig.h25
4 files changed, 106 insertions, 8 deletions
diff --git a/irmpprotocols.h b/irmpprotocols.h
index 0ca55a6..72618d9 100644
--- a/irmpprotocols.h
+++ b/irmpprotocols.h
@@ -89,7 +89,7 @@
#define IRMP_TIMEOUT_TIME 15500.0e-6 // timeout after 15.5 ms darkness
#define IRMP_TIMEOUT_TIME_MS 15500L // timeout after 15.5 ms darkness
-#if IRMP_SUPPORT_NIKON_PROTOCOL == 1
+#if defined(IRMP_SUPPORT_NIKON_PROTOCOL) && (IRMP_SUPPORT_NIKON_PROTOCOL == 1)
# define IRMP_TIMEOUT_NIKON_TIME 29500.0e-6 // 2nd timeout after 29.5 ms darkness (only for NIKON!)
# define IRMP_TIMEOUT_NIKON_TIME_MS 29500L // 2nd timeout after 29.5 ms darkness
typedef uint16_t PAUSE_LEN;
diff --git a/irsnd.c b/irsnd.c
index 1656bde..f421731 100644
--- a/irsnd.c
+++ b/irsnd.c
@@ -181,6 +181,8 @@
//Nothing here to do here -> See irsndconfig.h
#elif defined (ARM_STM32) // STM32
//Nothing here to do here -> See irsndconfig.h
+#elif defined(LIBOPENCM3)
+ //Nothing here to do here -> See irsndconfig.h
#elif defined (__xtensa__) // ESP8266
//Nothing here to do here -> See irsndconfig.h
@@ -412,6 +414,15 @@
# define IRSND_FREQ_40_KHZ (IRSND_FREQ_TYPE) (40000)
# define IRSND_FREQ_56_KHZ (IRSND_FREQ_TYPE) (56000)
# define IRSND_FREQ_455_KHZ (IRSND_FREQ_TYPE) (455000)
+#elif defined(LIBOPENCM3)
+# define IRSND_FREQ_TYPE uint32_t
+# define IRSND_FREQ_30_KHZ (IRSND_FREQ_TYPE) (30000)
+# define IRSND_FREQ_32_KHZ (IRSND_FREQ_TYPE) (32000)
+# define IRSND_FREQ_36_KHZ (IRSND_FREQ_TYPE) (36000)
+# define IRSND_FREQ_38_KHZ (IRSND_FREQ_TYPE) (38000)
+# define IRSND_FREQ_40_KHZ (IRSND_FREQ_TYPE) (40000)
+# define IRSND_FREQ_56_KHZ (IRSND_FREQ_TYPE) (56000)
+# define IRSND_FREQ_455_KHZ (IRSND_FREQ_TYPE) (455000)
#elif defined (TEENSY_ARM_CORTEX_M4) // TEENSY
# define IRSND_FREQ_TYPE float
# define IRSND_FREQ_30_KHZ (IRSND_FREQ_TYPE) (30000)
@@ -544,6 +555,11 @@ irsnd_on (void)
TIM_CCxCmd(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_CCx_Enable); // enable OC-output (is being disabled in TIM_SelectOCxM())
TIM_Cmd(IRSND_TIMER, ENABLE); // enable counter
+# elif defined (LIBOPENCM3) // STM32 whit libopencm3
+ timer_set_oc_mode(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_OCM_PWM1);
+ timer_generate_event(IRSND_TIMER, TIM_EGR_UG);
+ timer_enable_counter(IRSND_TIMER);
+
# elif defined (TEENSY_ARM_CORTEX_M4) // TEENSY
analogWrite(IRSND_PIN, 33 * 255 / 100); // pwm 33%
@@ -619,6 +635,11 @@ irsnd_off (void)
TIM_CCxCmd(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_CCx_Enable); // enable OC-output (is being disabled in TIM_SelectOCxM())
TIM_SetCounter(IRSND_TIMER, 0); // reset counter value
+# elif defined (LIBOPENCM3) // STM32
+ timer_set_oc_mode(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_OCM_FORCE_LOW);
+ timer_disable_counter(IRSND_TIMER);
+ timer_set_counter(IRSND_TIMER, 0);
+
# elif defined (TEENSY_ARM_CORTEX_M4) // TEENSY
analogWrite(IRSND_PIN, 0); // pwm off, LOW level
@@ -743,6 +764,27 @@ irsnd_set_freq (IRSND_FREQ_TYPE freq)
/* Set duty cycle */
TIM_SetCompare1(IRSND_TIMER, (freq + 1) / 2);
+# elif defined(LIBOPENCM3)
+ static uint32_t TimeBaseFreq = 0;
+
+ if (TimeBaseFreq == 0)
+ {
+# if defined(STM32F0) || (IRSND_TIMER < PERIPH_BASE_APB2)
+ TimeBaseFreq = rcc_apb1_frequency;
+# else
+ TimeBaseFreq = rcc_apb2_frequency;
+# endif
+ /* Timer clock is doubled, if the APB prescaler is greater than 1 */
+ if (TimeBaseFreq != rcc_ahb_frequency)
+ TimeBaseFreq *= 2;
+ }
+ freq = TimeBaseFreq/freq;
+
+ /* Set frequency */
+ timer_set_period(IRSND_TIMER, freq - 1);
+ /* Set duty cycle */
+ timer_set_oc_value(IRSND_TIMER, IRSND_TIMER_CHANNEL, (freq + 1) / 2);
+
# elif defined (TEENSY_ARM_CORTEX_M4)
analogWriteResolution(8); // 8 bit
analogWriteFrequency(IRSND_PIN, freq);
@@ -851,6 +893,39 @@ irsnd_init (void)
irsnd_set_freq (IRSND_FREQ_36_KHZ); // set default frequency
+# elif defined (LIBOPENCM3)
+ /* GPIOx clock enable */
+ rcc_periph_clock_enable(IRSND_PORT_RCC);
+
+ /* GPIO Configuration */
+# if 0
+ gpio_set_mode(IRSND_PORT, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, IRSND_BIT);
+# else
+ gpio_set_mode(IRSND_PORT, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, IRSND_BIT);
+# endif
+ /* TIMx clock enable */
+ rcc_periph_clock_enable(IRSND_TIMER_RCC);
+
+ /* Time base configuration */
+ timer_reset(IRSND_TIMER);
+ timer_set_mode(IRSND_TIMER, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE,
+ TIM_CR1_DIR_UP);
+ timer_set_period(IRSND_TIMER, -1);
+ timer_enable_preload(IRSND_TIMER);
+
+ /* PWM1 Mode configuration */
+ timer_set_oc_mode(IRSND_TIMER, IRSND_TIMER_CHANNEL, TIM_OCM_FORCE_LOW);
+ timer_enable_oc_output(IRSND_TIMER, IRSND_TIMER_CHANNEL);
+ timer_enable_oc_preload(IRSND_TIMER, IRSND_TIMER_CHANNEL);
+ timer_enable_break_main_output(IRSND_TIMER);
+# if 0
+ timer_set_oc_polarity_high(IRSND_TIMER, IRSND_TIMER_CHANNEL);
+# else
+ timer_set_oc_polarity_low(IRSND_TIMER, IRSND_TIMER_CHANNEL);
+# endif
+
# elif defined (TEENSY_ARM_CORTEX_M4)
if (!digitalPinHasPWM(IRSND_PIN))
{
diff --git a/irsnd.h b/irsnd.h
index 748a4ea..b33dfd9 100644
--- a/irsnd.h
+++ b/irsnd.h
@@ -47,6 +47,18 @@
# warning The STM32 port of IRSND uses the ST standard peripheral drivers which are not enabled in your build configuration.
# endif
+#elif defined (LIBOPENCM3) // STM32 whith libopencm3
+# define _CONCAT(a,b) a##b
+# define CONCAT(a,b) _CONCAT(a,b)
+# define IRSND_PORT CONCAT(GPIO, IRSND_PORT_LETTER)
+# define IRSND_PORT_RCC CONCAT(RCC_GPIO, IRSND_PORT_LETTER)
+# define IRSND_BIT CONCAT(GPIO, IRSND_BIT_NUMBER)
+# define IRSND_TIMER CONCAT(TIM, IRSND_TIMER_NUMBER)
+# define IRSND_TIMER_CHANNEL CONCAT(TIM_OC, IRSND_TIMER_CHANNEL_NUMBER)
+# define IRSND_TIMER_ARR TIM_ARR(IRSND_TIMER)
+# define IRSND_TIMER_ARR TIM_ARR(IRSND_TIMER)
+# define IRSND_TIMER_RCC CONCAT(RCC_TIM, IRSND_TIMER_NUMBER)
+
#elif defined(PIC_C18)
# if defined(__12F1840)
diff --git a/irsndconfig.h b/irsndconfig.h
index 8ed36bf..4f58bda 100644
--- a/irsndconfig.h
+++ b/irsndconfig.h
@@ -152,19 +152,22 @@
# define IRSND_TIMER_CHANNEL_NUMBER 1 // only channel 1 can be used at the moment, others won't work
/*---------------------------------------------------------------------------------------------------------------------------------------------------
- * Teensy 3.x with teensyduino gcc compiler
+ * ARM STM32 with libopencm3 section:
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/
-#elif defined (TEENSY_ARM_CORTEX_M4)
-# define IRSND_PIN 5 // choose an arduino pin with PWM function!
+#elif defined (LIBOPENCM3) // use B6 as IR output on STM32 whith libopencm3
+# define IRSND_PORT_LETTER B
+# define IRSND_BIT_NUMBER 9
+# define IRSND_TIMER_NUMBER 4
+# define IRSND_TIMER_CHANNEL_NUMBER 4
+# define F_CPU // KLUDGE: make irsnd.c happy (TODO:)
/*---------------------------------------------------------------------------------------------------------------------------------------------------
- * Other target systems
+ * Teensy 3.x with teensyduino gcc compiler
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/
-#elif !defined (UNIX_OR_WINDOWS)
-# error target system not defined.
-#endif
+#elif defined (TEENSY_ARM_CORTEX_M4)
+# define IRSND_PIN 5 // choose an arduino pin with PWM function!
/*---------------------------------------------------------------------------------------------------------------------------------------------------
* ESP8266 (Arduino, see IRSEND.ino)
@@ -174,6 +177,14 @@
# define IRSND_PIN 0 // choose an arduino pin with PWM function!
/*---------------------------------------------------------------------------------------------------------------------------------------------------
+ * Other target systems
+ *---------------------------------------------------------------------------------------------------------------------------------------------------
+ */
+#elif !defined (UNIX_OR_WINDOWS)
+# error target system not defined.
+#endif
+
+/*---------------------------------------------------------------------------------------------------------------------------------------------------
* Use Callbacks to indicate output signal or something else
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/