/**
 * Marlin 3D Printer Firmware
 * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
 *
 * 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 <https://www.gnu.org/licenses/>.
 *
 */
#pragma once

#include "env_validate.h"

#if HAS_MULTI_HOTEND || E_STEPPERS > 1
  #error "Artillery Ruby only supports 1 hotend / E stepper."
#endif

#define BOARD_INFO_NAME      "Artillery Ruby"

#if NO_EEPROM_SELECTED
  #define FLASH_EEPROM_EMULATION
  //#define I2C_EEPROM
#endif
#define MARLIN_EEPROM_SIZE               0x1000U  // 4K

#define HAL_TIMER_RATE                     F_CPU

//
// Limit Switches
//
#define X_STOP_PIN                          PA2
#define Y_STOP_PIN                          PA1
#define Z_STOP_PIN                          PA0
#define Z_OTHR_PIN                          PC2

//
// Steppers
//
#define X_STEP_PIN                          PB14
#define X_DIR_PIN                           PB13
#define X_ENABLE_PIN                        PB15

#define Y_STEP_PIN                          PB10
#define Y_DIR_PIN                           PB2
#define Y_ENABLE_PIN                        PB12

#define Z_STEP_PIN                          PB0
#define Z_DIR_PIN                           PC5
#define Z_ENABLE_PIN                        PB1

#define E0_STEP_PIN                         PA7
#define E0_DIR_PIN                          PA6
#define E0_ENABLE_PIN                       PC4

#define E1_STEP_PIN                         PA4
#define E1_DIR_PIN                          PA3
#define E1_ENABLE_PIN                       PA5

//
// Temperature Sensors
//
#define TEMP_0_PIN                          PC0
#define TEMP_BED_PIN                        PC1

//
// Heaters / Fans
//
#ifndef HEATER_0_PIN
  #define HEATER_0_PIN                      PC9   // Heater0
#endif
#ifndef HEATER_BED_PIN
  #define HEATER_BED_PIN                    PA8   // Hotbed
#endif
#ifndef FAN0_PIN
  #define FAN0_PIN                          PC8   // Fan0
#endif
#ifndef FAN1_PIN
  #define FAN1_PIN                          PC7   // Fan1
#endif
#ifndef FAN2_PIN
  #define FAN2_PIN                          PC6   // Fan2
#endif

//
// Servos
//
#define SERVO0_PIN                          PC3

/**
 *        ------                ------
 *  PC13 | 1  2 | PC14    PC11 | 1  2 | PC10
 *  PB6  | 3  4 | PC15    PB4  | 3  4 | PA15
 *  PB5    5  6 | PB9     PB3    5  6 | PC12
 *  PB8  | 7  8 | PB7     PD2  | 7  8 | RESET
 *   GND | 9 10 | 5V       GND | 9 10 | --
 *        ------                ------
 *         EXP1                  EXP2
 */
#define EXP1_01_PIN                         PC13
#define EXP1_02_PIN                         PC14
#define EXP1_03_PIN                         PB6
#define EXP1_04_PIN                         PC15
#define EXP1_05_PIN                         PB5
#define EXP1_06_PIN                         PB9
#define EXP1_07_PIN                         PB8
#define EXP1_08_PIN                         PB7

#define EXP2_01_PIN                         PC11
#define EXP2_02_PIN                         PC10
#define EXP2_03_PIN                         PB4
#define EXP2_04_PIN                         PA15
#define EXP2_05_PIN                         PB3
#define EXP2_06_PIN                         PC12
#define EXP2_07_PIN                         PD2
#define EXP2_08_PIN                         -1    // RESET

//
// LCD / Controller
//

#if HAS_WIRED_LCD
  #if ANY(MKS_12864OLED, MKS_12864OLED_SSD1306)
    #define LCD_PINS_DC              EXP1_07_PIN  // Set as output on init
    #define LCD_PINS_RS              EXP1_06_PIN  // Pull low for 1s to init
    // DOGM SPI LCD Support
    #define DOGLCD_CS                EXP1_04_PIN
    #define DOGLCD_MOSI              EXP1_03_PIN
    #define DOGLCD_SCK               EXP1_05_PIN
    #define DOGLCD_A0                LCD_PINS_DC
  #elif ENABLED(FYSETC_MINI_12864)
    #define DOGLCD_CS                EXP1_03_PIN
    #define DOGLCD_A0                EXP1_04_PIN

    //#define FORCE_SOFT_SPI                      // Use this if default of hardware SPI causes display problems
                                                  //   results in LCD soft SPI mode 3, SD soft SPI mode 0

    #define LCD_RESET_PIN            EXP1_05_PIN  // Must be high or open for LCD to operate normally.

    #if ANY(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0)
      #ifndef RGB_LED_R_PIN
        #define RGB_LED_R_PIN        EXP1_06_PIN
      #endif
      #ifndef RGB_LED_G_PIN
        #define RGB_LED_G_PIN        EXP1_07_PIN
      #endif
      #ifndef RGB_LED_B_PIN
        #define RGB_LED_B_PIN        EXP1_08_PIN
      #endif
    #elif ENABLED(FYSETC_MINI_12864_2_1)
      #define NEOPIXEL_PIN           EXP1_06_PIN
    #endif

    #define LCD_CONTRAST_INIT                255
  #else
    #define LCD_PINS_RS              EXP1_04_PIN
    #define LCD_PINS_EN              EXP1_03_PIN
    #define LCD_PINS_D4              EXP1_05_PIN
    #define LCD_PINS_D5              EXP1_06_PIN
    #define LCD_PINS_D6              EXP1_07_PIN
  #endif

  #define LCD_PINS_D7                EXP1_08_PIN

  //
  // Beeper, SD Card, Encoder
  //
  #define BEEPER_PIN                 EXP1_01_PIN

  #if HAS_MEDIA
    #define SD_SS_PIN                EXP2_04_PIN
    #define SD_DETECT_PIN            EXP2_07_PIN
  #endif

  #define BTN_EN1                    EXP2_03_PIN
  #define BTN_EN2                    EXP2_05_PIN
  #define BTN_ENC                    EXP1_02_PIN
#endif
