From 5f0b229f2f89dd924430c09adc6aef81aec5312e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Wed, 18 Sep 2019 03:17:52 +0200
Subject: [PATCH] Use TMR3 instead of TMR5 for interrupts from epicardium

Any reason to use TMR5 except preventing the use of PWM on the IR LED?

TMR4 is used for the LCD backlight it seems.
---
 epicardium/api/control.c            | 6 +++---
 epicardium/api/interrupt-receiver.c | 4 ++--
 epicardium/api/interrupt-sender.c   | 2 +-
 l0dables/lib/crt.s                  | 2 +-
 l0dables/lib/hardware.c             | 2 +-
 pycardium/mphalport.c               | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/epicardium/api/control.c b/epicardium/api/control.c
index deff4330..82f77074 100644
--- a/epicardium/api/control.c
+++ b/epicardium/api/control.c
@@ -74,7 +74,7 @@ void __core1_init(void)
 	/*
 	 * Clear any pending API interrupts.
 	 */
-	TMR_IntClear(MXC_TMR5);
+	TMR_IntClear(MXC_TMR3);
 
 	/*
 	 * Disable the SysTick
@@ -181,8 +181,8 @@ void __core1_init(void)
 	/*
 	 * Clear any pending API interrupts.
 	 */
-	TMR_IntClear(MXC_TMR5);
-	NVIC_ClearPendingIRQ(TMR5_IRQn);
+	TMR_IntClear(MXC_TMR3);
+	NVIC_ClearPendingIRQ(TMR3_IRQn);
 
 	/*
 	 * Jump to payload's reset handler
diff --git a/epicardium/api/interrupt-receiver.c b/epicardium/api/interrupt-receiver.c
index f9856423..e11d591d 100644
--- a/epicardium/api/interrupt-receiver.c
+++ b/epicardium/api/interrupt-receiver.c
@@ -6,9 +6,9 @@
 void __dispatch_isr(api_int_id_t);
 
 /* Timer Interrupt used for control char notification */
-void TMR5_IRQHandler(void)
+void TMR3_IRQHandler(void)
 {
-	TMR_IntClear(MXC_TMR5);
+	TMR_IntClear(MXC_TMR3);
 	__dispatch_isr(API_CALL_MEM->int_id);
 	API_CALL_MEM->int_id = (-1);
 }
diff --git a/epicardium/api/interrupt-sender.c b/epicardium/api/interrupt-sender.c
index fad7ed67..1d696fa8 100644
--- a/epicardium/api/interrupt-sender.c
+++ b/epicardium/api/interrupt-sender.c
@@ -18,5 +18,5 @@ void api_interrupt_trigger(api_int_id_t id)
 	assert(API_CALL_MEM->int_id == (api_int_id_t)(-1));
 
 	API_CALL_MEM->int_id = id;
-	TMR_TO_Start(MXC_TMR5, 1, 0);
+	TMR_TO_Start(MXC_TMR3, 1, 0);
 }
diff --git a/l0dables/lib/crt.s b/l0dables/lib/crt.s
index 79e32651..12e4f798 100644
--- a/l0dables/lib/crt.s
+++ b/l0dables/lib/crt.s
@@ -207,8 +207,8 @@ DefaultHandler:
 		def_irq_handler    TMR0_IRQHandler
 		def_irq_handler    TMR1_IRQHandler
 		def_irq_handler    TMR2_IRQHandler
-		def_irq_handler    TMR3_IRQHandler
 		def_irq_handler    TMR4_IRQHandler
+		def_irq_handler    TMR5_IRQHandler
 		def_irq_handler    RSV11_IRQHandler
 		def_irq_handler    RSV12_IRQHandler
 		def_irq_handler    I2C0_IRQHandler
diff --git a/l0dables/lib/hardware.c b/l0dables/lib/hardware.c
index 209ee97a..ef92eef3 100644
--- a/l0dables/lib/hardware.c
+++ b/l0dables/lib/hardware.c
@@ -77,7 +77,7 @@ __weak void SystemInit()
 	SystemCoreClockUpdate();
 
 	// Enable API interrupt.
-	NVIC_EnableIRQ(TMR5_IRQn);
+	NVIC_EnableIRQ(TMR3_IRQn);
 }
 
 // newlib syscall to allow printf to work.
diff --git a/pycardium/mphalport.c b/pycardium/mphalport.c
index 5ae9cee4..df7783e7 100644
--- a/pycardium/mphalport.c
+++ b/pycardium/mphalport.c
@@ -23,8 +23,8 @@
 /* Initialize everything for MicroPython */
 void pycardium_hal_init(void)
 {
-	/* TMR5 is used for interrupts from Epicardium */
-	NVIC_EnableIRQ(TMR5_IRQn);
+	/* TMR3 is used for interrupts from Epicardium */
+	NVIC_EnableIRQ(TMR3_IRQn);
 
 	/*
 	 * Enable UART RX Interrupt so Pycardium can sleep until
-- 
GitLab