Merge branch 'feature/e-endstop' into merge-abc-with-homing
[clinton/Smoothieware.git] / src / libs / MRI_Hooks.cpp
1 #include "MRI_Hooks.h"
2
3 #include <sLPC17xx.h>
4 #include <mri.h>
5
6 // This is used by MRI to turn pins on and off when entering and leaving MRI. Useful for not burning everything down
7 // See http://smoothieware.org/mri-debugging
8
9 extern "C" {
10 static uint32_t _set_high_on_debug[5] = {
11 // (1 << 4) | (1 << 10) | (1 << 19) | (1 << 21), // smoothieboard stepper EN pins
12 0,
13 0,
14 0,
15 0,
16 0
17 };
18 static uint32_t _set_low_on_debug[5] = {
19 0,
20 0,
21 // (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7), // smoothieboard heater outputs
22 0,
23 0,
24 0
25 };
26
27 static uint32_t _previous_state[5];
28
29 static LPC_GPIO_TypeDef* io;
30 static int i;
31
32 void __mriPlatform_EnteringDebuggerHook()
33 {
34 for (i = 0; i < 5; i++)
35 {
36 io = (LPC_GPIO_TypeDef*) (LPC_GPIO_BASE + (0x20 * i));
37 io->FIOMASK &= ~(_set_high_on_debug[i] | _set_low_on_debug[i]);
38
39 _previous_state[i] = io->FIOPIN;
40
41 io->FIOSET = _set_high_on_debug[i];
42 io->FIOCLR = _set_low_on_debug[i];
43 }
44 }
45
46 void __mriPlatform_LeavingDebuggerHook()
47 {
48 for (i = 0; i < 5; i++)
49 {
50 io = (LPC_GPIO_TypeDef*) (LPC_GPIO_BASE + (0x20 * i));
51 io->FIOMASK &= ~(_set_high_on_debug[i] | _set_low_on_debug[i]);
52 io->FIOSET = _previous_state[i] & (_set_high_on_debug[i] | _set_low_on_debug[i]);
53 io->FIOCLR = (~_previous_state[i]) & (_set_high_on_debug[i] | _set_low_on_debug[i]);
54 }
55 }
56
57 void set_high_on_debug(int port, int pin)
58 {
59 if ((port >= 5) || (port < 0))
60 return;
61 if ((pin >= 32) || (pin < 0))
62 return;
63 _set_high_on_debug[port] |= (1<<pin);
64 }
65
66 void set_low_on_debug(int port, int pin)
67 {
68 if ((port >= 5) || (port < 0))
69 return;
70 if ((pin >= 32) || (pin < 0))
71 return;
72 _set_low_on_debug[port] |= (1<<pin);
73 }
74 }