2017-10-08 11:38:10 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-10-08 11:38:10 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-10-08 11:38:10 -05:00
|
|
|
*
|
|
|
|
* 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
|
2020-07-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-10-08 11:38:10 -05:00
|
|
|
*
|
|
|
|
*/
|
2018-11-04 02:25:55 -06:00
|
|
|
#pragma once
|
2017-10-08 11:38:10 -05:00
|
|
|
|
2019-02-10 05:40:31 -06:00
|
|
|
#include "i2s.h"
|
|
|
|
|
2017-10-08 11:38:10 -05:00
|
|
|
/**
|
|
|
|
* Utility functions
|
|
|
|
*/
|
|
|
|
|
2019-04-20 13:41:17 -05:00
|
|
|
// I2S expander pin mapping.
|
|
|
|
#define IS_I2S_EXPANDER_PIN(IO) TEST(IO, 7)
|
|
|
|
#define I2S_EXPANDER_PIN_INDEX(IO) (IO & 0x7F)
|
|
|
|
|
2019-02-10 05:40:31 -06:00
|
|
|
// Set pin as input
|
2019-03-13 06:51:15 -05:00
|
|
|
#define _SET_INPUT(IO) pinMode(IO, INPUT)
|
2017-10-08 11:38:10 -05:00
|
|
|
|
2019-02-10 05:40:31 -06:00
|
|
|
// Set pin as output
|
2019-03-13 06:51:15 -05:00
|
|
|
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT)
|
2017-10-08 11:38:10 -05:00
|
|
|
|
2019-02-10 05:40:31 -06:00
|
|
|
// Set pin as input with pullup mode
|
2019-03-13 06:51:15 -05:00
|
|
|
#define _PULLUP(IO, v) pinMode(IO, v ? INPUT_PULLUP : INPUT)
|
2017-10-08 11:38:10 -05:00
|
|
|
|
|
|
|
// Read a pin wrapper
|
2019-04-20 13:41:17 -05:00
|
|
|
#define READ(IO) (IS_I2S_EXPANDER_PIN(IO) ? i2s_state(I2S_EXPANDER_PIN_INDEX(IO)) : digitalRead(IO))
|
2017-10-08 11:38:10 -05:00
|
|
|
|
|
|
|
// Write to a pin wrapper
|
2019-04-20 13:41:17 -05:00
|
|
|
#define WRITE(IO, v) (IS_I2S_EXPANDER_PIN(IO) ? i2s_write(I2S_EXPANDER_PIN_INDEX(IO), v) : digitalWrite(IO, v))
|
2017-10-08 11:38:10 -05:00
|
|
|
|
2019-02-10 05:40:31 -06:00
|
|
|
// Set pin as input wrapper
|
2019-03-13 06:51:15 -05:00
|
|
|
#define SET_INPUT(IO) _SET_INPUT(IO)
|
2017-10-08 11:38:10 -05:00
|
|
|
|
2019-02-10 05:40:31 -06:00
|
|
|
// Set pin as input with pullup wrapper
|
2019-03-13 06:51:15 -05:00
|
|
|
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
2017-10-08 11:38:10 -05:00
|
|
|
|
2020-11-11 00:39:23 -06:00
|
|
|
// Set pin as input with pulldown (substitution)
|
|
|
|
#define SET_INPUT_PULLDOWN SET_INPUT
|
|
|
|
|
2019-02-10 05:40:31 -06:00
|
|
|
// Set pin as output wrapper
|
2019-03-13 06:51:15 -05:00
|
|
|
#define SET_OUTPUT(IO) do{ _SET_OUTPUT(IO); }while(0)
|
2017-10-08 11:38:10 -05:00
|
|
|
|
2019-03-13 06:51:15 -05:00
|
|
|
// Set pin as PWM
|
2020-03-31 12:36:59 -05:00
|
|
|
#define SET_PWM SET_OUTPUT
|
2019-03-13 06:51:15 -05:00
|
|
|
|
|
|
|
// Set pin as output and init
|
|
|
|
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
|
2017-10-08 11:38:10 -05:00
|
|
|
|
2019-03-05 00:41:31 -06:00
|
|
|
// digitalRead/Write wrappers
|
2019-03-13 06:51:15 -05:00
|
|
|
#define extDigitalRead(IO) digitalRead(IO)
|
|
|
|
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|
|
|
|
|
2019-04-20 13:41:17 -05:00
|
|
|
// PWM outputs
|
2019-07-14 10:08:14 -05:00
|
|
|
#define PWM_PIN(P) (P < 34 || P > 127) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
|
2019-03-05 00:41:31 -06:00
|
|
|
|
2019-04-04 23:15:17 -05:00
|
|
|
// Toggle pin value
|
|
|
|
#define TOGGLE(IO) WRITE(IO, !READ(IO))
|
|
|
|
|
2017-10-08 11:38:10 -05:00
|
|
|
//
|
2019-02-10 05:40:31 -06:00
|
|
|
// Ports and functions
|
2017-10-08 11:38:10 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
// UART
|
|
|
|
#define RXD 3
|
|
|
|
#define TXD 1
|
|
|
|
|
|
|
|
// TWI (I2C)
|
|
|
|
#define SCL 5
|
|
|
|
#define SDA 4
|