2017-06-17 16:19:42 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 15:06:53 -06:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-06-17 16:19:42 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-11-04 02:25:55 -06:00
|
|
|
#pragma once
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/**
|
2017-11-18 02:08:03 -06:00
|
|
|
* Fast I/O Routines for LPC1768/9
|
|
|
|
* Use direct port manipulation to save scads of processor time.
|
|
|
|
* Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
|
|
|
|
*/
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Description: Fast IO functions LPC1768
|
|
|
|
*
|
|
|
|
* For TARGET LPC1768
|
|
|
|
*/
|
|
|
|
|
2018-02-23 00:52:52 -06:00
|
|
|
#include <Arduino.h>
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2019-03-12 20:39:55 -05:00
|
|
|
#define PWM_PIN(P) true // all pins are PWM capable
|
|
|
|
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
|
2017-06-17 18:36:10 -05:00
|
|
|
|
2019-03-12 20:39:55 -05:00
|
|
|
#define LPC_PIN(pin) gpio_pin(pin)
|
|
|
|
#define LPC_GPIO(port) gpio_port(port)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2019-03-12 20:39:55 -05:00
|
|
|
#define SET_DIR_INPUT(IO) gpio_set_input(IO)
|
|
|
|
#define SET_DIR_OUTPUT(IO) gpio_set_output(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2019-03-12 20:39:55 -05:00
|
|
|
#define SET_MODE(IO, mode) pinMode(IO, mode)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2019-03-12 20:39:55 -05:00
|
|
|
#define WRITE_PIN_SET(IO) gpio_set(IO)
|
|
|
|
#define WRITE_PIN_CLR(IO) gpio_clear(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2019-03-12 20:39:55 -05:00
|
|
|
#define READ_PIN(IO) gpio_get(IO)
|
|
|
|
#define WRITE_PIN(IO,V) gpio_set(IO, V)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/**
|
2017-11-18 02:08:03 -06:00
|
|
|
* Magic I/O routines
|
|
|
|
*
|
|
|
|
* Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
|
|
|
|
*
|
|
|
|
* Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
|
|
|
|
*/
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// Read a pin
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _READ(IO) READ_PIN(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// Write to a pin
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _WRITE_VAR(IO,V) digitalWrite(IO,V)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _WRITE(IO,V) WRITE_PIN(IO,V)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// toggle a pin
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _TOGGLE(IO) _WRITE(IO, !READ(IO))
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// set pin as input
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _SET_INPUT(IO) SET_DIR_INPUT(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// set pin as output
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _SET_OUTPUT(IO) SET_DIR_OUTPUT(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// set pin as input with pullup mode
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _PULLUP(IO,V) pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2018-02-18 19:26:23 -06:00
|
|
|
/// set pin as input with pulldown mode
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _PULLDOWN(IO,V) pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT)
|
2018-02-18 19:26:23 -06:00
|
|
|
|
2017-06-17 16:19:42 -05:00
|
|
|
/// check if pin is an input
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _GET_INPUT(IO) (!gpio_get_dir(IO))
|
2017-12-01 15:18:28 -06:00
|
|
|
|
2017-06-17 16:19:42 -05:00
|
|
|
/// check if pin is an output
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _GET_OUTPUT(IO) (gpio_get_dir(IO))
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2018-04-02 03:03:37 -05:00
|
|
|
/// check if pin is a timer
|
2018-07-01 23:02:38 -05:00
|
|
|
/// all gpio pins are pwm capable, either interrupt or hardware pwm controlled
|
2019-03-12 20:39:55 -05:00
|
|
|
#define _GET_TIMER(IO) true
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// Read a pin wrapper
|
2019-03-12 20:39:55 -05:00
|
|
|
#define READ(IO) _READ(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// Write to a pin wrapper
|
2019-03-12 20:39:55 -05:00
|
|
|
#define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
|
|
|
|
#define WRITE(IO,V) _WRITE(IO,V)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// toggle a pin wrapper
|
2019-03-12 20:39:55 -05:00
|
|
|
#define TOGGLE(IO) _TOGGLE(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// set pin as input wrapper
|
2019-03-12 20:39:55 -05:00
|
|
|
#define SET_INPUT(IO) _SET_INPUT(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
/// set pin as input with pullup wrapper
|
2019-03-12 20:39:55 -05:00
|
|
|
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
2018-02-18 19:26:23 -06:00
|
|
|
/// set pin as input with pulldown wrapper
|
2019-03-12 20:39:55 -05:00
|
|
|
#define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
|
2017-12-22 11:03:22 -06:00
|
|
|
/// set pin as output wrapper - reads the pin and sets the output to that value
|
2019-03-12 20:39:55 -05:00
|
|
|
#define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
|
2019-03-13 06:51:15 -05:00
|
|
|
// set pin as PWM
|
|
|
|
#define SET_PWM(IO) SET_OUTPUT(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
/// check if pin is an input wrapper
|
2019-03-12 20:39:55 -05:00
|
|
|
#define GET_INPUT(IO) _GET_INPUT(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
/// check if pin is an output wrapper
|
2019-03-12 20:39:55 -05:00
|
|
|
#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
2018-04-02 03:03:37 -05:00
|
|
|
/// check if pin is a timer (wrapper)
|
2019-03-12 20:39:55 -05:00
|
|
|
#define GET_TIMER(IO) _GET_TIMER(IO)
|
2017-06-17 16:19:42 -05:00
|
|
|
|
|
|
|
// Shorthand
|
2019-03-12 20:39:55 -05:00
|
|
|
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
|
2019-03-05 00:41:31 -06:00
|
|
|
|
|
|
|
// digitalRead/Write wrappers
|
|
|
|
#define extDigitalRead(IO) digitalRead(IO)
|
|
|
|
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|