Tweaks to HAL format and order

This commit is contained in:
Scott Lahteine 2018-09-28 15:57:21 -05:00
parent b682a1961a
commit ad21a4f07b
3 changed files with 61 additions and 52 deletions

View file

@ -41,26 +41,13 @@
#include "watchdog_Due.h" #include "watchdog_Due.h"
#include "HAL_timers_Due.h" #include "HAL_timers_Due.h"
//
// Defines
//
#define NUM_SERIAL 1 #define NUM_SERIAL 1
// Required before the include or compilation fails
#define MYSERIAL0 customizedSerial #define MYSERIAL0 customizedSerial
// We need the previous define before the include, or compilation bombs...
#include "MarlinSerial_Due.h" #include "MarlinSerial_Due.h"
#include "MarlinSerialUSB_Due.h" #include "MarlinSerialUSB_Due.h"
#ifndef analogInputToDigitalPin
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
#endif
#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()
// On AVR this is in math.h? // On AVR this is in math.h?
#define square(x) ((x)*(x)) #define square(x) ((x)*(x))
@ -86,19 +73,18 @@
#define RST_SOFTWARE 32 #define RST_SOFTWARE 32
#define RST_BACKUP 64 #define RST_BACKUP 64
// --------------------------------------------------------------------------
// Types
// --------------------------------------------------------------------------
typedef int8_t pin_t; typedef int8_t pin_t;
#define HAL_SERVO_LIB Servo #define HAL_SERVO_LIB Servo
// -------------------------------------------------------------------------- //
// Public Variables // Interrupts
// -------------------------------------------------------------------------- //
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
extern uint16_t HAL_adc_result; // result of last ADC conversion #define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_PRIMASK())
#define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq()
void cli(void); // Disable interrupts void cli(void); // Disable interrupts
void sei(void); // Enable interrupts void sei(void); // Enable interrupts
@ -106,13 +92,9 @@ void sei(void); // Enable interrupts
void HAL_clear_reset_source(void); // clear reset reason void HAL_clear_reset_source(void); // clear reset reason
uint8_t HAL_get_reset_source(void); // get reset reason uint8_t HAL_get_reset_source(void); // get reset reason
void _delay_ms(const int delay); //
// SPI: Extended functions taking a channel number (Hardware SPI only)
int freeMemory(void); //
/**
* SPI: Extended functions taking a channel number (hardware SPI only)
*/
// Write single byte to specified SPI channel // Write single byte to specified SPI channel
void spiSend(uint32_t chan, byte b); void spiSend(uint32_t chan, byte b);
@ -123,18 +105,22 @@ void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
// Read single byte from specified SPI channel // Read single byte from specified SPI channel
uint8_t spiRec(uint32_t chan); uint8_t spiRec(uint32_t chan);
/** //
* EEPROM // EEPROM
*/ //
void eeprom_write_byte(unsigned char *pos, unsigned char value); void eeprom_write_byte(unsigned char *pos, unsigned char value);
unsigned char eeprom_read_byte(unsigned char *pos); unsigned char eeprom_read_byte(unsigned char *pos);
void eeprom_read_block (void *__dst, const void *__src, size_t __n); void eeprom_read_block (void *__dst, const void *__src, size_t __n);
void eeprom_update_block (const void *__src, void *__dst, size_t __n); void eeprom_update_block (const void *__src, void *__dst, size_t __n);
/** //
* ADC // ADC
*/ //
extern uint16_t HAL_adc_result; // result of last ADC conversion
#ifndef analogInputToDigitalPin
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
#endif
#define HAL_ANALOG_SELECT(pin) #define HAL_ANALOG_SELECT(pin)
@ -154,16 +140,16 @@ uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
void HAL_enable_AdcFreerun(void); void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan); //void HAL_disable_AdcFreerun(uint8_t chan);
/** //
* Pin Map // Pin Map
*/ //
#define GET_PIN_MAP_PIN(index) index #define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin #define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval) #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
/** //
* Tone // Tone
*/ //
void toneInit(); void toneInit();
void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0); void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
void noTone(const pin_t _pin); void noTone(const pin_t _pin);
@ -174,6 +160,12 @@ void noTone(const pin_t _pin);
void HAL_idletask(void); void HAL_idletask(void);
void HAL_init(void); void HAL_init(void);
//
// Utility functions
//
void _delay_ms(const int delay);
int freeMemory(void);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View file

@ -64,10 +64,11 @@ extern "C" volatile uint32_t _millis;
#include "../shared/HAL_SPI.h" #include "../shared/HAL_SPI.h"
#include "fastio.h" #include "fastio.h"
#include "watchdog.h" #include "watchdog.h"
#include "serial.h"
#include "HAL_timers.h" #include "HAL_timers.h"
#include "HardwareSerial.h"
//
// Default graphical display delays
//
#ifndef ST7920_DELAY_1 #ifndef ST7920_DELAY_1
#define ST7920_DELAY_1 DELAY_NS(600) #define ST7920_DELAY_1 DELAY_NS(600)
#endif #endif
@ -78,6 +79,12 @@ extern "C" volatile uint32_t _millis;
#define ST7920_DELAY_3 DELAY_NS(750) #define ST7920_DELAY_3 DELAY_NS(750)
#endif #endif
//
// Arduino-style serial ports
//
#include "serial.h"
#include "HardwareSerial.h"
extern HalSerial usb_serial; extern HalSerial usb_serial;
#if !WITHIN(SERIAL_PORT, -1, 3) #if !WITHIN(SERIAL_PORT, -1, 3)
@ -126,24 +133,34 @@ extern HalSerial usb_serial;
#define NUM_SERIAL 1 #define NUM_SERIAL 1
#endif #endif
//
// Interrupts
//
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq() #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
#define CRITICAL_SECTION_END if (!primask) __enable_irq() #define CRITICAL_SECTION_END if (!primask) __enable_irq()
#define ISRS_ENABLED() (!__get_PRIMASK()) #define ISRS_ENABLED() (!__get_PRIMASK())
#define ENABLE_ISRS() __enable_irq() #define ENABLE_ISRS() __enable_irq()
#define DISABLE_ISRS() __disable_irq() #define DISABLE_ISRS() __disable_irq()
//Utility functions //
// Utility functions
//
int freeMemory(void); int freeMemory(void);
// SPI: Extended functions which take a channel number (hardware SPI only) //
/** Write single byte to specified SPI channel */ // SPI: Extended functions taking a channel number (Hardware SPI only)
//
// Write single byte to specified SPI channel
void spiSend(uint32_t chan, byte b); void spiSend(uint32_t chan, byte b);
/** Write buffer to specified SPI channel */ // Write buffer to specified SPI channel
void spiSend(uint32_t chan, const uint8_t* buf, size_t n); void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
/** Read single byte from specified SPI channel */ // Read single byte from specified SPI channel
uint8_t spiRec(uint32_t chan); uint8_t spiRec(uint32_t chan);
//
// ADC // ADC
//
#define HAL_ANALOG_SELECT(pin) HAL_adc_enable_channel(pin) #define HAL_ANALOG_SELECT(pin) HAL_adc_enable_channel(pin)
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin) #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_get_result() #define HAL_READ_ADC() HAL_adc_get_result()

View file

@ -73,7 +73,7 @@
#error "SERIAL_PORT must be from -1 to 3" #error "SERIAL_PORT must be from -1 to 3"
#endif #endif
#if SERIAL_PORT == -1 #if SERIAL_PORT == -1
extern USBSerial SerialUSB; extern USBSerial SerialUSB;
#define MYSERIAL0 SerialUSB #define MYSERIAL0 SerialUSB
#elif SERIAL_PORT == 0 #elif SERIAL_PORT == 0
#define MYSERIAL0 Serial #define MYSERIAL0 Serial