2017-06-17 21:19:42 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
|
|
|
|
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-02-22 00:43:42 +00:00
|
|
|
* HAL_LPC1768/HAL.h
|
|
|
|
* Hardware Abstraction Layer for NXP LPC1768
|
2017-06-17 21:19:42 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-22 00:43:42 +00:00
|
|
|
#ifndef _HAL_LPC1768_H_
|
|
|
|
#define _HAL_LPC1768_H_
|
2017-06-17 21:19:42 +00:00
|
|
|
|
2018-04-13 01:25:08 +00:00
|
|
|
#define CPU_32_BIT
|
2018-08-23 00:08:39 +00:00
|
|
|
#define HAL_INIT
|
2018-04-13 01:25:08 +00:00
|
|
|
|
2018-08-23 00:08:39 +00:00
|
|
|
void HAL_init();
|
2017-06-17 21:19:42 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2017-10-24 22:28:33 +00:00
|
|
|
extern "C" volatile uint32_t _millis;
|
2017-06-17 21:19:42 +00:00
|
|
|
|
2018-02-23 06:52:52 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <pinmapping.h>
|
2018-08-23 00:08:39 +00:00
|
|
|
#include <CDCSerial.h>
|
2017-11-19 20:01:05 +00:00
|
|
|
|
2018-08-14 08:28:52 +00:00
|
|
|
#include "../shared/math_32bit.h"
|
|
|
|
#include "../shared/HAL_SPI.h"
|
2017-06-17 21:19:42 +00:00
|
|
|
#include "fastio.h"
|
2018-08-23 00:08:39 +00:00
|
|
|
#include <adc.h>
|
2017-06-17 21:19:42 +00:00
|
|
|
#include "watchdog.h"
|
|
|
|
#include "HAL_timers.h"
|
2018-08-23 00:08:39 +00:00
|
|
|
#include "MarlinSerial.h"
|
2017-06-17 21:19:42 +00:00
|
|
|
|
2018-09-28 20:57:21 +00:00
|
|
|
//
|
|
|
|
// Default graphical display delays
|
|
|
|
//
|
2018-07-27 04:33:13 +00:00
|
|
|
#ifndef ST7920_DELAY_1
|
|
|
|
#define ST7920_DELAY_1 DELAY_NS(600)
|
|
|
|
#endif
|
|
|
|
#ifndef ST7920_DELAY_2
|
|
|
|
#define ST7920_DELAY_2 DELAY_NS(750)
|
|
|
|
#endif
|
|
|
|
#ifndef ST7920_DELAY_3
|
|
|
|
#define ST7920_DELAY_3 DELAY_NS(750)
|
|
|
|
#endif
|
2017-06-17 21:19:42 +00:00
|
|
|
|
2017-11-05 14:49:38 +00:00
|
|
|
#if !WITHIN(SERIAL_PORT, -1, 3)
|
|
|
|
#error "SERIAL_PORT must be from -1 to 3"
|
|
|
|
#endif
|
|
|
|
|
2017-10-24 22:28:33 +00:00
|
|
|
#if SERIAL_PORT == -1
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL0 UsbSerial
|
2017-10-24 22:28:33 +00:00
|
|
|
#elif SERIAL_PORT == 0
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL0 MSerial
|
2017-10-24 22:28:33 +00:00
|
|
|
#elif SERIAL_PORT == 1
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL0 MSerial1
|
2017-10-24 22:28:33 +00:00
|
|
|
#elif SERIAL_PORT == 2
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL0 MSerial2
|
2017-10-24 22:28:33 +00:00
|
|
|
#elif SERIAL_PORT == 3
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL0 MSerial3
|
2017-11-05 14:49:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SERIAL_PORT_2
|
|
|
|
#if !WITHIN(SERIAL_PORT_2, -1, 3)
|
|
|
|
#error "SERIAL_PORT_2 must be from -1 to 3"
|
|
|
|
#elif SERIAL_PORT_2 == SERIAL_PORT
|
|
|
|
#error "SERIAL_PORT_2 must be different than SERIAL_PORT"
|
|
|
|
#endif
|
|
|
|
#define NUM_SERIAL 2
|
|
|
|
#if SERIAL_PORT_2 == -1
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL1 UsbSerial
|
2017-11-05 14:49:38 +00:00
|
|
|
#elif SERIAL_PORT_2 == 0
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL1 MSerial
|
2017-11-05 14:49:38 +00:00
|
|
|
#elif SERIAL_PORT_2 == 1
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL1 MSerial1
|
2017-11-05 14:49:38 +00:00
|
|
|
#elif SERIAL_PORT_2 == 2
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL1 MSerial2
|
2017-11-05 14:49:38 +00:00
|
|
|
#elif SERIAL_PORT_2 == 3
|
2018-08-23 00:08:39 +00:00
|
|
|
#define MYSERIAL1 MSerial3
|
2017-11-05 14:49:38 +00:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define NUM_SERIAL 1
|
2017-10-24 22:28:33 +00:00
|
|
|
#endif
|
2017-06-17 21:19:42 +00:00
|
|
|
|
2018-09-28 20:57:21 +00:00
|
|
|
//
|
|
|
|
// Interrupts
|
|
|
|
//
|
2018-06-02 00:02:22 +00:00
|
|
|
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
|
|
|
|
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
|
|
|
#define ISRS_ENABLED() (!__get_PRIMASK())
|
|
|
|
#define ENABLE_ISRS() __enable_irq()
|
|
|
|
#define DISABLE_ISRS() __disable_irq()
|
2017-06-17 21:19:42 +00:00
|
|
|
|
2018-09-28 20:57:21 +00:00
|
|
|
//
|
|
|
|
// Utility functions
|
|
|
|
//
|
2017-06-17 21:19:42 +00:00
|
|
|
int freeMemory(void);
|
|
|
|
|
2018-09-28 20:57:21 +00:00
|
|
|
//
|
|
|
|
// SPI: Extended functions taking a channel number (Hardware SPI only)
|
|
|
|
//
|
|
|
|
|
|
|
|
// Write single byte to specified SPI channel
|
2017-06-17 21:19:42 +00:00
|
|
|
void spiSend(uint32_t chan, byte b);
|
2018-09-28 20:57:21 +00:00
|
|
|
// Write buffer to specified SPI channel
|
2017-06-17 21:19:42 +00:00
|
|
|
void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
|
2018-09-28 20:57:21 +00:00
|
|
|
// Read single byte from specified SPI channel
|
2017-06-17 21:19:42 +00:00
|
|
|
uint8_t spiRec(uint32_t chan);
|
|
|
|
|
2018-09-28 20:57:21 +00:00
|
|
|
//
|
2018-08-23 00:08:39 +00:00
|
|
|
// ADC API
|
2018-09-28 20:57:21 +00:00
|
|
|
//
|
2018-08-23 00:08:39 +00:00
|
|
|
|
|
|
|
#define ADC_MEDIAN_FILTER_SIZE (23) // Higher values increase step delay (phase shift),
|
|
|
|
// (ADC_MEDIAN_FILTER_SIZE + 1) / 2 sample step delay (12 samples @ 500Hz: 24ms phase shift)
|
|
|
|
// Memory usage per ADC channel (bytes): (6 * ADC_MEDIAN_FILTER_SIZE) + 16
|
|
|
|
// 8 * ((6 * 23) + 16 ) = 1232 Bytes for 8 channels
|
|
|
|
|
|
|
|
#define ADC_LOWPASS_K_VALUE (6) // Higher values increase rise time
|
|
|
|
// Rise time sample delays for 100% signal convergence on full range step
|
|
|
|
// (1 : 13, 2 : 32, 3 : 67, 4 : 139, 5 : 281, 6 : 565, 7 : 1135, 8 : 2273)
|
|
|
|
// K = 6, 565 samples, 500Hz sample rate, 1.13s convergence on full range step
|
|
|
|
// Memory usage per ADC channel (bytes): 4 (32 Bytes for 8 channels)
|
|
|
|
|
|
|
|
using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
|
|
|
|
#define HAL_adc_init() FilteredADC::init()
|
|
|
|
#define HAL_ANALOG_SELECT(pin) FilteredADC::enable_channel(pin)
|
|
|
|
#define HAL_START_ADC(pin) FilteredADC::start_conversion(pin)
|
|
|
|
#define HAL_READ_ADC() FilteredADC::get_result()
|
|
|
|
#define HAL_ADC_READY() FilteredADC::finished_conversion()
|
|
|
|
|
|
|
|
// Parse a G-code word into a pin index
|
|
|
|
int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
|
2018-09-21 10:24:53 +00:00
|
|
|
// P0.6 thru P0.9 are for the onboard SD card
|
|
|
|
#define HAL_SENSITIVE_PINS P0_06, P0_07, P0_08, P0_09
|
2017-06-17 21:19:42 +00:00
|
|
|
|
2018-09-19 17:33:20 +00:00
|
|
|
#define HAL_IDLETASK 1
|
|
|
|
void HAL_idletask(void);
|
|
|
|
|
2018-02-22 00:43:42 +00:00
|
|
|
#endif // _HAL_LPC1768_H_
|