Skip to content

Commit ef2a4c9

Browse files
committed
Simulator more close to actual ADVi3++ mainboard (Wanhao i3 Plus)
1 parent 3302028 commit ef2a4c9

File tree

8 files changed

+261
-3
lines changed

8 files changed

+261
-3
lines changed

Marlin/Configuration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ constexpr uint8_t DIMMING_BRIGHTNESS_DEFAULT = 5;
7070

7171
#endif
7272

73+
#define DEFAULT_MACHINE_NAME "ADVi3++ Simulator"
7374
#define EXTUI_EEPROM_DATA_SIZE 0
7475
#define EXTENSIBLE_UI
7576
#define ADVi3PP_UI
@@ -79,14 +80,14 @@ constexpr uint8_t DIMMING_BRIGHTNESS_DEFAULT = 5;
7980
#define LCD_BRIGHTNESS_DEFAULT LCD_BRIGHTNESS_MAX
8081
#define TONE_FREQUENCY_DEFAULT 260 // not used
8182
#define TONE_DURATION_DEFAULT 10 // 10 ms
83+
//#define BLTOUCH
8284

8385
#if defined(BLTOUCH) || defined(ADVi3PP_54)
8486
#define ADVi3PP_PROBE 1
8587
#endif
8688

8789
#if defined(__PLAT_NATIVE_SIM__)
8890
#define ADV_STD_SIZE_T
89-
#define PL_PIN 1
9091
#endif
9192

9293
//===========================================================================

Marlin/src/HAL/NATIVE_SIM/HAL.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ uint8_t _getc();
6161
#define CPU_ST7920_DELAY_2 750
6262
#define CPU_ST7920_DELAY_3 750
6363

64+
// ------------------------
65+
// Types
66+
// ------------------------
67+
68+
#define SHARED_SERVOS HAS_SERVOS // Use shared/servos.cpp
69+
70+
class Servo;
71+
typedef Servo hal_servo_t;
72+
6473
// ------------------------
6574
// Serial ports
6675
// ------------------------

Marlin/src/HAL/NATIVE_SIM/Servo.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
/**
24+
* servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
25+
* Copyright (c) 2009 Michael Margolis. All right reserved.
26+
*/
27+
28+
/**
29+
* A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method.
30+
* The servos are pulsed in the background using the value most recently written using the write() method
31+
*
32+
* Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached.
33+
* Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four.
34+
*
35+
* The methods are:
36+
*
37+
* Servo - Class for manipulating servo motors connected to Arduino pins.
38+
*
39+
* attach(pin) - Attach a servo motor to an i/o pin.
40+
* attach(pin, min, max) - Attach to a pin, setting min and max values in microseconds
41+
* Default min is 544, max is 2400
42+
*
43+
* write() - Set the servo angle in degrees. (Invalid angles —over MIN_PULSE_WIDTH— are treated as µs.)
44+
* writeMicroseconds() - Set the servo pulse width in microseconds.
45+
* move(pin, angle) - Sequence of attach(pin), write(angle), safe_delay(servo_delay[servoIndex]).
46+
* With DEACTIVATE_SERVOS_AFTER_MOVE it detaches after servo_delay[servoIndex].
47+
* read() - Get the last-written servo pulse width as an angle between 0 and 180.
48+
* readMicroseconds() - Get the last-written servo pulse width in microseconds.
49+
* attached() - Return true if a servo is attached.
50+
* detach() - Stop an attached servo from pulsing its i/o pin.
51+
*/
52+
53+
#include "../../inc/MarlinConfig.h"
54+
55+
#if HAS_SERVOS
56+
57+
#include "../shared/servo.h"
58+
#include "../shared/servo_private.h"
59+
60+
void initISR(const timer16_Sequence_t timer_index) {
61+
}
62+
63+
void finISR(const timer16_Sequence_t timer_index) {
64+
}
65+
66+
#endif // HAS_SERVOS
67+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
#define _useTimer1
3+
//#define _useTimer2
4+
//#define _useTimer3
5+
//#define _useTimer4
6+
//#define _useTimer5
7+
8+
#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
9+
#define SERVO_TIMER_PRESCALER 2 // timer prescaler
10+
11+
/*
12+
TC0, chan 0 => TC0_Handler
13+
TC0, chan 1 => TC1_Handler
14+
TC0, chan 2 => TC2_Handler
15+
TC1, chan 0 => TC3_Handler
16+
TC1, chan 1 => TC4_Handler
17+
TC1, chan 2 => TC5_Handler
18+
TC2, chan 0 => TC6_Handler
19+
TC2, chan 1 => TC7_Handler
20+
TC2, chan 2 => TC8_Handler
21+
*/
22+
23+
#ifdef _useTimer1
24+
#define TC_FOR_TIMER1 TC1
25+
#define CHANNEL_FOR_TIMER1 0
26+
#define ID_TC_FOR_TIMER1 ID_TC3
27+
#define IRQn_FOR_TIMER1 TC3_IRQn
28+
#define HANDLER_FOR_TIMER1 TC3_Handler
29+
#endif
30+
#ifdef _useTimer2
31+
#define TC_FOR_TIMER2 TC1
32+
#define CHANNEL_FOR_TIMER2 1
33+
#define ID_TC_FOR_TIMER2 ID_TC4
34+
#define IRQn_FOR_TIMER2 TC4_IRQn
35+
#define HANDLER_FOR_TIMER2 TC4_Handler
36+
#endif
37+
#ifdef _useTimer3
38+
#define TC_FOR_TIMER3 TC1
39+
#define CHANNEL_FOR_TIMER3 2
40+
#define ID_TC_FOR_TIMER3 ID_TC5
41+
#define IRQn_FOR_TIMER3 TC5_IRQn
42+
#define HANDLER_FOR_TIMER3 TC5_Handler
43+
#endif
44+
#ifdef _useTimer4
45+
#define TC_FOR_TIMER4 TC0
46+
#define CHANNEL_FOR_TIMER4 2
47+
#define ID_TC_FOR_TIMER4 ID_TC2
48+
#define IRQn_FOR_TIMER4 TC2_IRQn
49+
#define HANDLER_FOR_TIMER4 TC2_Handler
50+
#endif
51+
#ifdef _useTimer5
52+
#define TC_FOR_TIMER5 TC0
53+
#define CHANNEL_FOR_TIMER5 0
54+
#define ID_TC_FOR_TIMER5 ID_TC0
55+
#define IRQn_FOR_TIMER5 TC0_IRQn
56+
#define HANDLER_FOR_TIMER5 TC0_Handler
57+
#endif
58+
59+
typedef enum : unsigned char {
60+
#ifdef _useTimer1
61+
_timer1,
62+
#endif
63+
#ifdef _useTimer2
64+
_timer2,
65+
#endif
66+
#ifdef _useTimer3
67+
_timer3,
68+
#endif
69+
#ifdef _useTimer4
70+
_timer4,
71+
#endif
72+
#ifdef _useTimer5
73+
_timer5,
74+
#endif
75+
_Nbr_16timers
76+
} timer16_Sequence_t;

Marlin/src/HAL/shared/servo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
#else
8888
#include <stdint.h>
8989

90-
#if defined(__AVR__) || defined(ARDUINO_ARCH_SAM) || defined(__SAMD51__) || defined(__SAMD21__) || defined(__PLAT_RP2040__)
90+
#if defined(__AVR__) || defined(ARDUINO_ARCH_SAM) || defined(__SAMD51__) || defined(__SAMD21__) || defined(__PLAT_RP2040__) || defined(__PLAT_NATIVE_SIM__)
9191
// we're good to go
9292
#else
9393
#error "This library only supports boards with an AVR, SAM3X, SAMD21, SAMD51, or RP2040 processor."

Marlin/src/HAL/shared/servo_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include "../SAMD51/ServoTimers.h"
5252
#elif defined(__SAMD21__)
5353
#include "../SAMD21/ServoTimers.h"
54+
#elif defined(__PLAT_NATIVE_SIM__)
55+
#include "../NATIVE_SIM/ServoTimers.h"
5456
#else
5557
#error "This library only supports boards with an AVR, SAM3X, SAMD21 or SAMD51 processor."
5658
#endif
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
/**
25+
* Native with a Wanhao i3 Plus like board.
26+
*/
27+
28+
#ifndef BOARD_INFO_NAME
29+
#define BOARD_INFO_NAME "ADVi3++ Simulator"
30+
#endif
31+
32+
#ifndef DEFAULT_MACHINE_NAME
33+
#define DEFAULT_MACHINE_NAME "ADVi3++ Simulator 1.0"
34+
#endif
35+
36+
#ifndef MARLIN_EEPROM_SIZE
37+
#define MARLIN_EEPROM_SIZE 0x1000U // 4K
38+
#endif
39+
40+
//
41+
// Servos
42+
//
43+
#define SERVO0_PIN 40
44+
45+
//
46+
// Limit Switches
47+
//
48+
#define X_STOP_PIN 54 // PF0 / A0 - D54
49+
#define Y_STOP_PIN 24 // PA2 / D24
50+
#define Z_STOP_PIN 25 // PA3 / D25
51+
#define Z_MIN_PROBE_PIN 25 // PA3 / D25
52+
53+
//
54+
// Steppers
55+
//
56+
#define X_STEP_PIN 61 // PF7 / A7 - D61
57+
#define X_DIR_PIN 62 // PK0 / A8 - D62
58+
#define X_ENABLE_PIN 60 // PF6 / A6 - D60
59+
60+
#define Y_STEP_PIN 64 // PK2 / A10 - D64
61+
#define Y_DIR_PIN 65 // PK3 / A11 - D65
62+
#define Y_ENABLE_PIN 63 // PK1 / A9 - D63
63+
64+
#define Z_STEP_PIN 67 // PK5 / A13 - D67
65+
#define Z_DIR_PIN 69 // PK7 / A15 - D69
66+
#define Z_ENABLE_PIN 66 // PK4 / A12 - D66
67+
68+
#define E0_STEP_PIN 58 // PF4 / A4 - D58
69+
#define E0_DIR_PIN 59 // PF5 / A5 - D59
70+
#define E0_ENABLE_PIN 57 // PF3 / A3 - D57
71+
72+
//
73+
// Temperature Sensors
74+
//
75+
#define TEMP_0_PIN 1 // PF1 / A1 - D55
76+
#define TEMP_BED_PIN 14 // PK6 / A14 - D68
77+
//
78+
// Heaters / Fans
79+
//
80+
#define HEATER_0_PIN 4 // PG5 / D4
81+
#define HEATER_BED_PIN 3 // PE5 / D3
82+
#define FAN0_PIN 5 // PE3 / D5
83+
84+
//
85+
// Filament Runout sensor
86+
//
87+
#define FIL_RUNOUT_PIN 36 // PC1 / D36 - EXT3
88+
89+
//
90+
// SD card
91+
//
92+
#define SD_DETECT_PIN 49 // PL0 / D49
93+
#define SD_MISO_PIN 50 // PB3 / D50
94+
#define SD_MOSI_PIN 51 // PB2 / D51
95+
#define SD_SCK_PIN 52 // PB1 / SCK - D52
96+
#define SD_SS_PIN 53 // PB0 / SS - D53
97+
98+
//
99+
// Misc. Functions
100+
//
101+
#define LED_PIN 13
102+
#define PS_ON_PIN 32 // PC5 / D32 - EXT7
103+
#define PL_PIN 34 // PC3 / D34 - EXT5

Marlin/src/pins/pins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@
996996
//
997997

998998
#elif MB(SIMULATED)
999-
#include "native/pins_RAMPS_NATIVE.h" // Native or Simulation mac:advi3pp_macos
999+
#include "advi3pp/pins_ADVI3PP_NATIVE.h" // Native or Simulation mac:advi3pp_macos
10001000

10011001
#else
10021002

0 commit comments

Comments
 (0)