Added missing files, fixed switches interrupts
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 28 Jun 2016 12:28:17 +0000 (05:28 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 28 Jun 2016 12:28:17 +0000 (05:28 -0700)
src/pins.c [new file with mode: 0644]
src/pins.h [new file with mode: 0644]
src/switch.c

diff --git a/src/pins.c b/src/pins.c
new file mode 100644 (file)
index 0000000..99f8a55
--- /dev/null
@@ -0,0 +1,31 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+#include "pins.h"
+
+
+PORT_t *pin_ports[] = {&PORTA, &PORTB, &PORTC, &PORTD, &PORTE, &PORTF};
diff --git a/src/pins.h b/src/pins.h
new file mode 100644 (file)
index 0000000..14d29db
--- /dev/null
@@ -0,0 +1,56 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+#pragma once
+
+#include <avr/io.h>
+
+
+// Ports
+enum {
+  PORT_A,
+  PORT_B,
+  PORT_C,
+  PORT_D,
+  PORT_E,
+  PORT_F,
+};
+
+
+extern PORT_t *pin_ports[];
+
+
+#define PORT(PIN) pin_ports[PIN >> 3]
+#define BM(PIN) (1 << (PIN & 7))
+
+#define DIRSET_PIN(PIN) PORT(PIN)->DIRSET = BM(PIN)
+#define DIRCLR_PIN(PIN) PORT(PIN)->DIRCLR = BM(PIN)
+#define OUTCLR_PIN(PIN) PORT(PIN)->OUTCLR = BM(PIN)
+#define OUTSET_PIN(PIN) PORT(PIN)->OUTSET = BM(PIN)
+#define OUTTGL_PIN(PIN) PORT(PIN)->OUTTGL = BM(PIN)
+#define IN_PIN(PIN) (!!(PORT(PIN)->IN & BM(PIN)))
+#define PINCTRL_PIN(PIN) ((&PORT(PIN)->PIN0CTRL)[PIN & 7])
index ae60854dc9ccd4bf71ca22f9f2181fc9acb91f24..8e369b864cc5505ea976c6bdac949951f2afec9f 100644 (file)
@@ -123,7 +123,7 @@ swSingleton_t sw = {
       .min  = false,
     }, { // A min
       .type = SW_TYPE_NORMALLY_OPEN,
-      .mode = SW_MODE_HOMING,
+      .mode = SW_MODE_DISABLED, // SW_MODE_HOMING,
       .pin  = MIN_A_PIN,
       .min = true,
     }, { // A max
@@ -132,7 +132,7 @@ swSingleton_t sw = {
       .pin  = MAX_A_PIN,
       .min  = false,
     }, { // EStop
-      .type = SW_TYPE_NORMALLY_CLOSED,
+      .type = SW_TYPE_NORMALLY_OPEN,
       .mode = SW_ESTOP_BIT,
       .pin  = ESTOP_PIN,
     }, { // Probe
@@ -163,12 +163,15 @@ static void _switch_isr() {
     // reset deglitch count regardless of entry state
     s->count = -SW_DEGLITCH_TICKS;
     s->state = state;
+    PORT(s->pin)->INT0MASK &= ~BM(s->pin); // Disable INT0
   }
 }
 
 
 // Switch interrupt handler vectors
 ISR(PORTA_INT0_vect) {_switch_isr();}
+ISR(PORTB_INT0_vect) {_switch_isr();}
+ISR(PORTC_INT0_vect) {_switch_isr();}
 ISR(PORTD_INT0_vect) {_switch_isr();}
 ISR(PORTE_INT0_vect) {_switch_isr();}
 ISR(PORTF_INT0_vect) {_switch_isr();}
@@ -192,8 +195,6 @@ void _switch_enable(switch_t *s, bool enable) {
 
 
 void switch_init() {
-  return; // TODO
-
   for (int i = 0; i < SWITCHES; i++) {
     switch_t *s = &sw.switches[i];
 
@@ -216,6 +217,7 @@ void switch_rtc_callback() {
     // state is either lockout or deglitching
     if (++s->count == SW_LOCKOUT_TICKS) {
       s->debounce = SW_IDLE;
+      PORT(s->pin)->INT0MASK |= BM(s->pin);    // Enable INT0
 
       // check if the state has changed while we were in lockout
       if (s->state != _read_state(s)) {