Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
major merge and UART software serial fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DJScopeSOFM committed Dec 7, 2020
1 parent 7cdad09 commit 24d90c5
Show file tree
Hide file tree
Showing 924 changed files with 64,607 additions and 16,930 deletions.
5 changes: 4 additions & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@
//
#if MOTHERBOARD == BOARD_MKS_ROBIN_NANO_V2
#define MKS_TS35_V2_0
#define TFT_480X320
#endif

//
Expand All @@ -2373,13 +2374,15 @@
//
#if ANY(Bluer, Sapphire_Pro, Sapphire_Plus, Sapphire_Plus_Rotated_Screen) && MOTHERBOARD == BOARD_MKS_ROBIN_NANO
#define MKS_ROBIN_TFT35
#define TFT_480X320
#endif

//
// 480x272, 4.3", FSMC Display From MKS
//
#if ANY(Bluer_Plus) && MOTHERBOARD == BOARD_MKS_ROBIN_NANO
#define MKS_ROBIN_TFT43
#define TFT_480X272
#endif

//
Expand Down Expand Up @@ -2470,7 +2473,7 @@
#define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens
#define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus

//#define TOUCH_SCREEN_CALIBRATION
#define TOUCH_SCREEN_CALIBRATION

#if DISABLED(TOUCH_SCREEN_CALIBRATION)
#define XPT2046_X_CALIBRATION 12316
Expand Down
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@
#if HAS_BED_PROBE
#define PROBE_OFFSET_WIZARD
#if ENABLED(PROBE_OFFSET_WIZARD)
#define PROBE_OFFSET_START -4.0 // Estimated nozzle-to-probe Z offset, plus a little extra
#define PROBE_OFFSET_WIZARD_START_Z -4.0 // Estimated nozzle-to-probe Z offset, plus a little extra
#endif
#endif

Expand Down Expand Up @@ -2506,7 +2506,7 @@
* Use for drivers that do not use a dedicated enable pin, but rather handle the same
* function through a communication line such as SPI or UART.
*/
//#define SOFTWARE_DRIVER_ENABLE
#define SOFTWARE_DRIVER_ENABLE

/**
* TMC2130, TMC2160, TMC2208, TMC2209, TMC5130 and TMC5160 only
Expand Down
4 changes: 2 additions & 2 deletions Marlin/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ Enjoy!
// {03} What type of User Interface do you want to use?

//#define classic_stock_marlin // This is like the old interface with monotone screens and turn nob controls but with touch buttons
#define touch_colour_marlin // This is similar to above but with more touch friendly possitioning of buttons
//#define modern_touch_mks_interface // This is a modern full touch interface, but has some limitations in terms of features
//#define touch_colour_marlin // This is similar to above but with more touch friendly possitioning of buttons
#define modern_touch_mks_interface // This is a modern full touch interface, but has some limitations in terms of features

// Quick note about the MKS interface. I've got it runnings and setup as much as I could but because I don't like using it, I will not be looking at
// further developing/porting function to for it. My goal was to port it over and get it running. Hopefully, MKS will further develope this and give
Expand Down
78 changes: 78 additions & 0 deletions Marlin/src/HAL/AVR/HAL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 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/>.
*
*/
#ifdef __AVR__

#include "../../inc/MarlinConfig.h"
#include "HAL.h"

// ------------------------
// Public Variables
// ------------------------

//uint8_t MCUSR;

// ------------------------
// Public functions
// ------------------------

void HAL_init() {
// Init Servo Pins
#define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
#if HAS_SERVO_0
INIT_SERVO(0);
#endif
#if HAS_SERVO_1
INIT_SERVO(1);
#endif
#if HAS_SERVO_2
INIT_SERVO(2);
#endif
#if HAS_SERVO_3
INIT_SERVO(3);
#endif
}

#if ENABLED(SDSUPPORT)

#include "../../sd/SdFatUtil.h"
int freeMemory() { return SdFatUtil::FreeRam(); }

#else // !SDSUPPORT

extern "C" {
extern char __bss_end;
extern char __heap_start;
extern void* __brkval;

int freeMemory() {
int free_memory;
if ((int)__brkval == 0)
free_memory = ((int)&free_memory) - ((int)&__bss_end);
else
free_memory = ((int)&free_memory) - ((int)__brkval);
return free_memory;
}
}

#endif // !SDSUPPORT

#endif // __AVR__
195 changes: 195 additions & 0 deletions Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
*
* 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 "../shared/Marduino.h"
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
#include "math.h"

#ifdef USBCON
#include <HardwareSerial.h>
#else
#define HardwareSerial_h // Hack to prevent HardwareSerial.h header inclusion
#include "MarlinSerial.h"
#endif

#include <stdint.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/io.h>

#ifndef pgm_read_ptr
// Compatibility for avr-libc 1.8.0-4.1 included with Ubuntu for
// Windows Subsystem for Linux on Windows 10 as of 10/18/2019
#define pgm_read_ptr_far(address_long) (void*)__ELPM_word((uint32_t)(address_long))
#define pgm_read_ptr_near(address_short) (void*)__LPM_word((uint16_t)(address_short))
#define pgm_read_ptr(address_short) pgm_read_ptr_near(address_short)
#endif

// ------------------------
// Defines
// ------------------------

// AVR PROGMEM extension for sprintf_P
#define S_FMT "%S"

// AVR PROGMEM extension for string define
#define PGMSTR(NAM,STR) const char NAM[] PROGMEM = STR

#ifndef CRITICAL_SECTION_START
#define CRITICAL_SECTION_START() unsigned char _sreg = SREG; cli()
#define CRITICAL_SECTION_END() SREG = _sreg
#endif
#define ISRS_ENABLED() TEST(SREG, SREG_I)
#define ENABLE_ISRS() sei()
#define DISABLE_ISRS() cli()

// ------------------------
// Types
// ------------------------

typedef int8_t pin_t;

#define SHARED_SERVOS HAS_SERVOS
#define HAL_SERVO_LIB Servo

// ------------------------
// Public Variables
// ------------------------

//extern uint8_t MCUSR;

// Serial ports
#ifdef USBCON
#define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial)
#else
#if !WITHIN(SERIAL_PORT, -1, 3)
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#define MYSERIAL0 customizedSerial1

#ifdef SERIAL_PORT_2
#if !WITHIN(SERIAL_PORT_2, -1, 3)
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
#endif
#define MYSERIAL1 customizedSerial2
#endif
#endif

#ifdef LCD_SERIAL_PORT
#if !WITHIN(LCD_SERIAL_PORT, -1, 3)
#error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#define LCD_SERIAL lcdSerial
#if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.get_tx_buffer_free()
#endif
#endif

// ------------------------
// Public functions
// ------------------------

void HAL_init();

//void cli();

//void _delay_ms(const int delay);

inline void HAL_clear_reset_source() { MCUSR = 0; }
inline uint8_t HAL_get_reset_source() { return MCUSR; }

inline void HAL_reboot() {} // reboot the board or restart the bootloader

#if GCC_VERSION <= 50000
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#endif

extern "C" int freeMemory();

#if GCC_VERSION <= 50000
#pragma GCC diagnostic pop
#endif

// ADC
#ifdef DIDR2
#define HAL_ANALOG_SELECT(ind) do{ if (ind < 8) SBI(DIDR0, ind); else SBI(DIDR2, ind & 0x07); }while(0)
#else
#define HAL_ANALOG_SELECT(ind) SBI(DIDR0, ind);
#endif

inline void HAL_adc_init() {
ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADIF) | 0x07;
DIDR0 = 0;
#ifdef DIDR2
DIDR2 = 0;
#endif
}

#define SET_ADMUX_ADCSRA(ch) ADMUX = _BV(REFS0) | (ch & 0x07); SBI(ADCSRA, ADSC)
#ifdef MUX5
#define HAL_START_ADC(ch) if (ch > 7) ADCSRB = _BV(MUX5); else ADCSRB = 0; SET_ADMUX_ADCSRA(ch)
#else
#define HAL_START_ADC(ch) ADCSRB = 0; SET_ADMUX_ADCSRA(ch)
#endif

#define HAL_ADC_VREF 5.0
#define HAL_ADC_RESOLUTION 10
#define HAL_READ_ADC() ADC
#define HAL_ADC_READY() !TEST(ADCSRA, ADSC)

#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

#define HAL_SENSITIVE_PINS 0, 1

#ifdef __AVR_AT90USB1286__
#define JTAG_DISABLE() do{ MCUCR = 0x80; MCUCR = 0x80; }while(0)
#endif

// AVR compatibility
#define strtof strtod

#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment

/**
* set_pwm_frequency
* Sets the frequency of the timer corresponding to the provided pin
* as close as possible to the provided desired frequency. Internally
* calculates the required waveform generation mode, prescaler and
* resolution values required and sets the timer registers accordingly.
* NOTE that the frequency is applied to all pins on the timer (Ex OC3A, OC3B and OC3B)
* NOTE that there are limitations, particularly if using TIMER2. (see Configuration_adv.h -> FAST FAN PWM Settings)
*/
void set_pwm_frequency(const pin_t pin, int f_desired);

/**
* set_pwm_duty
* Sets the PWM duty cycle of the provided pin to the provided value
* Optionally allows inverting the duty cycle [default = false]
* Optionally allows changing the maximum size of the provided value to enable finer PWM duty control [default = 255]
*/
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);
Loading

0 comments on commit 24d90c5

Please sign in to comment.