Skip to content

Commit

Permalink
Merge pull request #355 from synthetos/issue-347-gpio-enhancements
Browse files Browse the repository at this point in the history
gpio enhancements (issue #347)
  • Loading branch information
giseburt authored Jun 18, 2018
2 parents 1cb13ba + fbad7f5 commit a1155a4
Show file tree
Hide file tree
Showing 69 changed files with 5,494 additions and 1,297 deletions.
File renamed without changes.
108 changes: 108 additions & 0 deletions g2core/board/Archim/board_gpio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* gpio.cpp - digital IO handling functions
* This file is part of the g2core project
*
* Copyright (c) 2015 - 2107 Alden S. Hart, Jr.
* Copyright (c) 2015 - 2017 Robert Giseburt
*
* 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/>.
*
* As a special exception, you may use this file as part of a software library without
* restriction. Specifically, if other files instantiate templates or use macros or
* inline functions from this file, or you compile this file and link it with other
* files to produce an executable, this file does not by itself cause the resulting
* executable to be covered by the GNU General Public License. This exception does not
* however invalidate any other reasons why the executable file might be covered by the
* GNU General Public License.
*
* THE SOFTWARE IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
* SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Switch Modes
*
* The switches are considered to be homing switches when cycle_state is
* CYCLE_HOMING. At all other times they are treated as limit switches:
* - Hitting a homing switch puts the current move into feedhold
* - Hitting a limit switch causes the machine to shut down and go into lockdown until reset
*
* The normally open switch modes (NO) trigger an interrupt on the falling edge
* and lockout subsequent interrupts for the defined lockout period. This approach
* beats doing debouncing as an integration as switches fire immediately.
*
* The normally closed switch modes (NC) trigger an interrupt on the rising edge
* and lockout subsequent interrupts for the defined lockout period. Ditto on the method.
*/

#include "../../g2core.h" // #1
#include "config.h" // #2
#include "gpio.h"
#include "hardware.h"
#include "canonical_machine.h"

#include "text_parser.h"
#include "controller.h"
#include "util.h"
#include "report.h"
#include "xio.h"

#include "MotateTimers.h"

/**** Setup Actual Objects ****/

gpioDigitalInputPin<IRQPin<Motate::kInput1_PinNumber>> din1 {DI1_MODE, 1};
gpioDigitalInputPin<IRQPin<Motate::kInput2_PinNumber>> din2 {DI2_MODE, 2};
gpioDigitalInputPin<IRQPin<Motate::kInput3_PinNumber>> din3 {DI3_MODE, 3};
gpioDigitalInputPin<IRQPin<Motate::kInput4_PinNumber>> din4 {DI4_MODE, 4};
gpioDigitalInputPin<IRQPin<Motate::kInput5_PinNumber>> din5 {DI5_MODE, 5};
gpioDigitalInputPin<IRQPin<Motate::kInput6_PinNumber>> din6 {DI6_MODE, 6};
gpioDigitalInputPin<IRQPin<Motate::kInput7_PinNumber>> din7 {DI7_MODE, 7};
gpioDigitalInputPin<IRQPin<Motate::kInput8_PinNumber>> din8 {DI8_MODE, 8};
gpioDigitalInputPin<IRQPin<Motate::kInput9_PinNumber>> din9 {DI9_MODE, 9};
// gpioDigitalInputPin<IRQPin<Motate::kInput10_PinNumber>> din10 {DI10_MODE, 10};
// gpioDigitalInputPin<IRQPin<Motate::kInput11_PinNumber>> din11 {DI11_MODE, 11};
// gpioDigitalInputPin<IRQPin<Motate::kInput12_PinNumber>> din12 {DI12_MODE, 12};

gpioDigitalOutputPin<OutputType<OUTPUT1_PWM, Motate::kOutput1_PinNumber>> dout1 { DO1_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT2_PWM, Motate::kOutput2_PinNumber>> dout2 { DO2_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT3_PWM, Motate::kOutput3_PinNumber>> dout3 { DO3_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT4_PWM, Motate::kOutput4_PinNumber>> dout4 { DO4_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT5_PWM, Motate::kOutput5_PinNumber>> dout5 { DO5_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT6_PWM, Motate::kOutput6_PinNumber>> dout6 { DO6_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT7_PWM, Motate::kOutput7_PinNumber>> dout7 { DO7_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT8_PWM, Motate::kOutput8_PinNumber>> dout8 { DO8_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT9_PWM, Motate::kOutput9_PinNumber>> dout9 { DO9_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT10_PWM, Motate::kOutput10_PinNumber>> dout10 { DO10_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT11_PWM, Motate::kOutput11_PinNumber>> dout11 { DO11_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT12_PWM, Motate::kOutput12_PinNumber>> dout12 { DO12_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT13_PWM, Motate::kOutput13_PinNumber>> dout13 { DO13_MODE, (uint32_t)200000 };

/**** Setup Arrays - these are extern and MUST match the board_gpio.h ****/

gpioDigitalInput* const d_in[] = {&din1, &din2, &din3, &din4, &din5, &din6, &din7, &din8, &din9};
gpioDigitalOutput* const d_out[] = {&dout1, &dout2, &dout3, &dout4, &dout5, &dout6, &dout7, &dout8, &dout9, &dout10, &dout11, &dout12, &dout13};
// not yet used
// gpioAnalogInput* a_in[A_IN_CHANNELS];
// gpioAnalogOutput* a_out[A_OUT_CHANNELS];

/************************************************************************************
**** CODE **************************************************************************
************************************************************************************/
/*
* gpio_reset() - reset inputs and outputs (no initialization)
*/


void outputs_reset(void) {
// nothing to do
}

void inputs_reset(void) {
// nothing to do
}
90 changes: 90 additions & 0 deletions g2core/board/Archim/board_gpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* gpio.h - Digital IO handling functions
* This file is part of the g2core project
*
* Copyright (c) 2015 - 2017 Alden S. Hart, Jr.
* Copyright (c) 2015 - 2017 Robert Giseburt
*
* 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/>.
*
* As a special exception, you may use this file as part of a software library without
* restriction. Specifically, if other files instantiate templates or use macros or
* inline functions from this file, or you compile this file and link it with other
* files to produce an executable, this file does not by itself cause the resulting
* executable to be covered by the GNU General Public License. This exception does not
* however invalidate any other reasons why the executable file might be covered by the
* GNU General Public License.
*
* THE SOFTWARE IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
* SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef BOARD_GPIO_H_ONCE
#define BOARD_GPIO_H_ONCE

// this file is included from the bottom of gpio.h, but we do this for completeness
#include "../../gpio.h"

/*
* GPIO defines
*/
//--- change as required for board and switch hardware ---//

#define D_IN_CHANNELS 9 // v9 // number of digital inputs supported
#define D_OUT_CHANNELS 13 // number of digital outputs supported
#define A_IN_CHANNELS 0 // number of analog inputs supported
#define A_OUT_CHANNELS 0 // number of analog outputs supported

#define INPUT_LOCKOUT_MS 10 // milliseconds to go dead after input firing

/*
* The GPIO objects themselves - this must match up with board_gpio.cpp!
*/

extern gpioDigitalInput* const d_in[D_IN_CHANNELS];
extern gpioDigitalOutput* const d_out[D_OUT_CHANNELS];
// extern gpioAnalogInput* a_in[A_IN_CHANNELS];
// extern gpioAnalogOutput* a_out[A_OUT_CHANNELS];

// prepare the objects as externs (for config_app to not bloat)
using Motate::IRQPin;
using Motate::PWMOutputPin;
using Motate::PWMLikeOutputPin;
template<bool can_pwm, pin_number... V>
using OutputType = typename std::conditional<can_pwm, PWMOutputPin<V...>, PWMLikeOutputPin<V...>>::type;

extern gpioDigitalInputPin<IRQPin<Motate::kInput1_PinNumber>> din1;
extern gpioDigitalInputPin<IRQPin<Motate::kInput2_PinNumber>> din2;
extern gpioDigitalInputPin<IRQPin<Motate::kInput3_PinNumber>> din3;
extern gpioDigitalInputPin<IRQPin<Motate::kInput4_PinNumber>> din4;
extern gpioDigitalInputPin<IRQPin<Motate::kInput5_PinNumber>> din5;
extern gpioDigitalInputPin<IRQPin<Motate::kInput6_PinNumber>> din6;
extern gpioDigitalInputPin<IRQPin<Motate::kInput7_PinNumber>> din7;
extern gpioDigitalInputPin<IRQPin<Motate::kInput8_PinNumber>> din8;
extern gpioDigitalInputPin<IRQPin<Motate::kInput9_PinNumber>> din9;
// extern gpioDigitalInputPin<IRQPin<Motate::kInput10_PinNumber>> din10;
// extern gpioDigitalInputPin<IRQPin<Motate::kInput11_PinNumber>> din11;
// extern gpioDigitalInputPin<IRQPin<Motate::kInput12_PinNumber>> din12;

extern gpioDigitalOutputPin<OutputType<OUTPUT1_PWM, Motate::kOutput1_PinNumber>> dout1;
extern gpioDigitalOutputPin<OutputType<OUTPUT2_PWM, Motate::kOutput2_PinNumber>> dout2;
extern gpioDigitalOutputPin<OutputType<OUTPUT3_PWM, Motate::kOutput3_PinNumber>> dout3;
extern gpioDigitalOutputPin<OutputType<OUTPUT4_PWM, Motate::kOutput4_PinNumber>> dout4;
extern gpioDigitalOutputPin<OutputType<OUTPUT5_PWM, Motate::kOutput5_PinNumber>> dout5;
extern gpioDigitalOutputPin<OutputType<OUTPUT6_PWM, Motate::kOutput6_PinNumber>> dout6;
extern gpioDigitalOutputPin<OutputType<OUTPUT7_PWM, Motate::kOutput7_PinNumber>> dout7;
extern gpioDigitalOutputPin<OutputType<OUTPUT8_PWM, Motate::kOutput8_PinNumber>> dout8;
extern gpioDigitalOutputPin<OutputType<OUTPUT9_PWM, Motate::kOutput9_PinNumber>> dout9;
extern gpioDigitalOutputPin<OutputType<OUTPUT10_PWM, Motate::kOutput10_PinNumber>> dout10;
extern gpioDigitalOutputPin<OutputType<OUTPUT11_PWM, Motate::kOutput11_PinNumber>> dout11;
extern gpioDigitalOutputPin<OutputType<OUTPUT12_PWM, Motate::kOutput12_PinNumber>> dout12;
extern gpioDigitalOutputPin<OutputType<OUTPUT13_PWM, Motate::kOutput13_PinNumber>> dout13;


#endif // End of include guard: BOARD_GPIO_H_ONCE
4 changes: 2 additions & 2 deletions g2core/board/Archim/board_xio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
#include "MotateUSBCDC.h"

#if USB_SERIAL_PORTS_EXPOSED == 1
typedef Motate::USBDevice< Motate::USBCDC > XIOUSBDevice_t;
typedef Motate::USBDevice< USBDeviceHardware, Motate::USBCDC > XIOUSBDevice_t;
#endif
#if USB_SERIAL_PORTS_EXPOSED == 2
typedef Motate::USBDevice<Motate::USBCDC, Motate::USBCDC> XIOUSBDevice_t;
typedef Motate::USBDevice< USBDeviceHardware, Motate::USBCDC, Motate::USBCDC > XIOUSBDevice_t;
#endif

extern XIOUSBDevice_t usb;
Expand Down
File renamed without changes.
108 changes: 108 additions & 0 deletions g2core/board/ArduinoDue/board_gpio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* gpio.cpp - digital IO handling functions
* This file is part of the g2core project
*
* Copyright (c) 2015 - 2107 Alden S. Hart, Jr.
* Copyright (c) 2015 - 2017 Robert Giseburt
*
* 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/>.
*
* As a special exception, you may use this file as part of a software library without
* restriction. Specifically, if other files instantiate templates or use macros or
* inline functions from this file, or you compile this file and link it with other
* files to produce an executable, this file does not by itself cause the resulting
* executable to be covered by the GNU General Public License. This exception does not
* however invalidate any other reasons why the executable file might be covered by the
* GNU General Public License.
*
* THE SOFTWARE IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
* SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Switch Modes
*
* The switches are considered to be homing switches when cycle_state is
* CYCLE_HOMING. At all other times they are treated as limit switches:
* - Hitting a homing switch puts the current move into feedhold
* - Hitting a limit switch causes the machine to shut down and go into lockdown until reset
*
* The normally open switch modes (NO) trigger an interrupt on the falling edge
* and lockout subsequent interrupts for the defined lockout period. This approach
* beats doing debouncing as an integration as switches fire immediately.
*
* The normally closed switch modes (NC) trigger an interrupt on the rising edge
* and lockout subsequent interrupts for the defined lockout period. Ditto on the method.
*/

#include "../../g2core.h" // #1
#include "config.h" // #2
#include "gpio.h"
#include "hardware.h"
#include "canonical_machine.h"

#include "text_parser.h"
#include "controller.h"
#include "util.h"
#include "report.h"
#include "xio.h"

#include "MotateTimers.h"

/**** Setup Actual Objects ****/

gpioDigitalInputPin<IRQPin<Motate::kInput1_PinNumber>> din1 {DI1_MODE, 1};
gpioDigitalInputPin<IRQPin<Motate::kInput2_PinNumber>> din2 {DI2_MODE, 2};
gpioDigitalInputPin<IRQPin<Motate::kInput3_PinNumber>> din3 {DI3_MODE, 3};
gpioDigitalInputPin<IRQPin<Motate::kInput4_PinNumber>> din4 {DI4_MODE, 4};
gpioDigitalInputPin<IRQPin<Motate::kInput5_PinNumber>> din5 {DI5_MODE, 5};
gpioDigitalInputPin<IRQPin<Motate::kInput6_PinNumber>> din6 {DI6_MODE, 6};
gpioDigitalInputPin<IRQPin<Motate::kInput7_PinNumber>> din7 {DI7_MODE, 7};
gpioDigitalInputPin<IRQPin<Motate::kInput8_PinNumber>> din8 {DI8_MODE, 8};
gpioDigitalInputPin<IRQPin<Motate::kInput9_PinNumber>> din9 {DI9_MODE, 9};
// gpioDigitalInputPin<IRQPin<Motate::kInput10_PinNumber>> din10 {DI10_MODE, 10};
// gpioDigitalInputPin<IRQPin<Motate::kInput11_PinNumber>> din11 {DI11_MODE, 11};
// gpioDigitalInputPin<IRQPin<Motate::kInput12_PinNumber>> din12 {DI12_MODE, 12};

gpioDigitalOutputPin<OutputType<OUTPUT1_PWM, Motate::kOutput1_PinNumber>> dout1 { DO1_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT2_PWM, Motate::kOutput2_PinNumber>> dout2 { DO2_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT3_PWM, Motate::kOutput3_PinNumber>> dout3 { DO3_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT4_PWM, Motate::kOutput4_PinNumber>> dout4 { DO4_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT5_PWM, Motate::kOutput5_PinNumber>> dout5 { DO5_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT6_PWM, Motate::kOutput6_PinNumber>> dout6 { DO6_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT7_PWM, Motate::kOutput7_PinNumber>> dout7 { DO7_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT8_PWM, Motate::kOutput8_PinNumber>> dout8 { DO8_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT9_PWM, Motate::kOutput9_PinNumber>> dout9 { DO9_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT10_PWM, Motate::kOutput10_PinNumber>> dout10 { DO10_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT11_PWM, Motate::kOutput11_PinNumber>> dout11 { DO11_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT12_PWM, Motate::kOutput12_PinNumber>> dout12 { DO12_MODE, (uint32_t)200000 };
gpioDigitalOutputPin<OutputType<OUTPUT13_PWM, Motate::kOutput13_PinNumber>> dout13 { DO13_MODE, (uint32_t)200000 };

/**** Setup Arrays - these are extern and MUST match the board_gpio.h ****/

gpioDigitalInput* const d_in[] = {&din1, &din2, &din3, &din4, &din5, &din6, &din7, &din8, &din9};
gpioDigitalOutput* const d_out[] = {&dout1, &dout2, &dout3, &dout4, &dout5, &dout6, &dout7, &dout8, &dout9, &dout10, &dout11, &dout12, &dout13};
// not yet used
// gpioAnalogInput* a_in[A_IN_CHANNELS];
// gpioAnalogOutput* a_out[A_OUT_CHANNELS];

/************************************************************************************
**** CODE **************************************************************************
************************************************************************************/
/*
* gpio_reset() - reset inputs and outputs (no initialization)
*/


void outputs_reset(void) {
// nothing to do
}

void inputs_reset(void) {
// nothing to do
}
Loading

0 comments on commit a1155a4

Please sign in to comment.