Browse Source

Tweaks to HAL format and order

Scott Lahteine 6 years ago
parent
commit
ad21a4f07b
3 changed files with 61 additions and 52 deletions
  1. 35
    43
      Marlin/src/HAL/HAL_DUE/HAL.h
  2. 24
    7
      Marlin/src/HAL/HAL_LPC1768/HAL.h
  3. 2
    2
      Marlin/src/HAL/HAL_STM32F1/HAL.h

+ 35
- 43
Marlin/src/HAL/HAL_DUE/HAL.h View File

@@ -41,26 +41,13 @@
41 41
 #include "watchdog_Due.h"
42 42
 #include "HAL_timers_Due.h"
43 43
 
44
-//
45
-// Defines
46
-//
47 44
 #define NUM_SERIAL 1
45
+// Required before the include or compilation fails
48 46
 #define MYSERIAL0 customizedSerial
49 47
 
50
-// We need the previous define before the include, or compilation bombs...
51 48
 #include "MarlinSerial_Due.h"
52 49
 #include "MarlinSerialUSB_Due.h"
53 50
 
54
-#ifndef analogInputToDigitalPin
55
-  #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
56
-#endif
57
-
58
-#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
59
-#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
60
-#define ISRS_ENABLED() (!__get_PRIMASK())
61
-#define ENABLE_ISRS()  __enable_irq()
62
-#define DISABLE_ISRS() __disable_irq()
63
-
64 51
 // On AVR this is in math.h?
65 52
 #define square(x) ((x)*(x))
66 53
 
@@ -86,19 +73,18 @@
86 73
 #define RST_SOFTWARE   32
87 74
 #define RST_BACKUP     64
88 75
 
89
-// --------------------------------------------------------------------------
90
-// Types
91
-// --------------------------------------------------------------------------
92
-
93 76
 typedef int8_t pin_t;
94 77
 
95 78
 #define HAL_SERVO_LIB Servo
96 79
 
97
-// --------------------------------------------------------------------------
98
-// Public Variables
99
-// --------------------------------------------------------------------------
100
-
101
-extern uint16_t HAL_adc_result;     // result of last ADC conversion
80
+//
81
+// Interrupts
82
+//
83
+#define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
84
+#define CRITICAL_SECTION_END    if (!primask) __enable_irq()
85
+#define ISRS_ENABLED() (!__get_PRIMASK())
86
+#define ENABLE_ISRS()  __enable_irq()
87
+#define DISABLE_ISRS() __disable_irq()
102 88
 
103 89
 void cli(void);                     // Disable interrupts
104 90
 void sei(void);                     // Enable interrupts
@@ -106,13 +92,9 @@ void sei(void);                     // Enable interrupts
106 92
 void HAL_clear_reset_source(void);  // clear reset reason
107 93
 uint8_t HAL_get_reset_source(void); // get reset reason
108 94
 
109
-void _delay_ms(const int delay);
110
-
111
-int freeMemory(void);
112
-
113
-/**
114
- * SPI: Extended functions taking a channel number (hardware SPI only)
115
- */
95
+//
96
+// SPI: Extended functions taking a channel number (Hardware SPI only)
97
+//
116 98
 
117 99
 // Write single byte to specified SPI channel
118 100
 void spiSend(uint32_t chan, byte b);
@@ -123,18 +105,22 @@ void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
123 105
 // Read single byte from specified SPI channel
124 106
 uint8_t spiRec(uint32_t chan);
125 107
 
126
-/**
127
- * EEPROM
128
- */
129
-
108
+//
109
+// EEPROM
110
+//
130 111
 void eeprom_write_byte(unsigned char *pos, unsigned char value);
131 112
 unsigned char eeprom_read_byte(unsigned char *pos);
132 113
 void eeprom_read_block (void *__dst, const void *__src, size_t __n);
133 114
 void eeprom_update_block (const void *__src, void *__dst, size_t __n);
134 115
 
135
-/**
136
- * ADC
137
- */
116
+//
117
+// ADC
118
+//
119
+extern uint16_t HAL_adc_result;     // result of last ADC conversion
120
+
121
+#ifndef analogInputToDigitalPin
122
+  #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
123
+#endif
138 124
 
139 125
 #define HAL_ANALOG_SELECT(pin)
140 126
 
@@ -154,16 +140,16 @@ uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
154 140
 void HAL_enable_AdcFreerun(void);
155 141
 //void HAL_disable_AdcFreerun(uint8_t chan);
156 142
 
157
-/**
158
- * Pin Map
159
- */
143
+//
144
+// Pin Map
145
+//
160 146
 #define GET_PIN_MAP_PIN(index) index
161 147
 #define GET_PIN_MAP_INDEX(pin) pin
162 148
 #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
163 149
 
164
-/**
165
- * Tone
166
- */
150
+//
151
+// Tone
152
+//
167 153
 void toneInit();
168 154
 void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
169 155
 void noTone(const pin_t _pin);
@@ -174,6 +160,12 @@ void noTone(const pin_t _pin);
174 160
 void HAL_idletask(void);
175 161
 void HAL_init(void);
176 162
 
163
+//
164
+// Utility functions
165
+//
166
+void _delay_ms(const int delay);
167
+int freeMemory(void);
168
+
177 169
 #ifdef __cplusplus
178 170
   extern "C" {
179 171
 #endif

+ 24
- 7
Marlin/src/HAL/HAL_LPC1768/HAL.h View File

@@ -64,10 +64,11 @@ extern "C" volatile uint32_t _millis;
64 64
 #include "../shared/HAL_SPI.h"
65 65
 #include "fastio.h"
66 66
 #include "watchdog.h"
67
-#include "serial.h"
68 67
 #include "HAL_timers.h"
69
-#include "HardwareSerial.h"
70 68
 
69
+//
70
+// Default graphical display delays
71
+//
71 72
 #ifndef ST7920_DELAY_1
72 73
   #define ST7920_DELAY_1 DELAY_NS(600)
73 74
 #endif
@@ -78,6 +79,12 @@ extern "C" volatile uint32_t _millis;
78 79
   #define ST7920_DELAY_3 DELAY_NS(750)
79 80
 #endif
80 81
 
82
+//
83
+// Arduino-style serial ports
84
+//
85
+#include "serial.h"
86
+#include "HardwareSerial.h"
87
+
81 88
 extern HalSerial usb_serial;
82 89
 
83 90
 #if !WITHIN(SERIAL_PORT, -1, 3)
@@ -126,24 +133,34 @@ extern HalSerial usb_serial;
126 133
   #define NUM_SERIAL 1
127 134
 #endif
128 135
 
136
+//
137
+// Interrupts
138
+//
129 139
 #define CRITICAL_SECTION_START  uint32_t primask = __get_PRIMASK(); __disable_irq()
130 140
 #define CRITICAL_SECTION_END    if (!primask) __enable_irq()
131 141
 #define ISRS_ENABLED() (!__get_PRIMASK())
132 142
 #define ENABLE_ISRS()  __enable_irq()
133 143
 #define DISABLE_ISRS() __disable_irq()
134 144
 
135
-//Utility functions
145
+//
146
+// Utility functions
147
+//
136 148
 int freeMemory(void);
137 149
 
138
-// SPI: Extended functions which take a channel number (hardware SPI only)
139
-/** Write single byte to specified SPI channel */
150
+//
151
+// SPI: Extended functions taking a channel number (Hardware SPI only)
152
+//
153
+
154
+// Write single byte to specified SPI channel
140 155
 void spiSend(uint32_t chan, byte b);
141
-/** Write buffer to specified SPI channel */
156
+// Write buffer to specified SPI channel
142 157
 void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
143
-/** Read single byte from specified SPI channel */
158
+// Read single byte from specified SPI channel
144 159
 uint8_t spiRec(uint32_t chan);
145 160
 
161
+//
146 162
 // ADC
163
+//
147 164
 #define HAL_ANALOG_SELECT(pin) HAL_adc_enable_channel(pin)
148 165
 #define HAL_START_ADC(pin)     HAL_adc_start_conversion(pin)
149 166
 #define HAL_READ_ADC()         HAL_adc_get_result()

+ 2
- 2
Marlin/src/HAL/HAL_STM32F1/HAL.h View File

@@ -73,7 +73,7 @@
73 73
   #error "SERIAL_PORT must be from -1 to 3"
74 74
 #endif
75 75
 #if SERIAL_PORT == -1
76
-extern USBSerial SerialUSB;
76
+  extern USBSerial SerialUSB;
77 77
   #define MYSERIAL0 SerialUSB
78 78
 #elif SERIAL_PORT == 0
79 79
   #define MYSERIAL0 Serial
@@ -93,7 +93,7 @@ extern USBSerial SerialUSB;
93 93
   #endif
94 94
   #define NUM_SERIAL 2
95 95
   #if SERIAL_PORT_2 == -1
96
-  extern USBSerial SerialUSB;
96
+    extern USBSerial SerialUSB;
97 97
     #define MYSERIAL1 SerialUSB
98 98
   #elif SERIAL_PORT_2 == 0
99 99
     #define MYSERIAL1 Serial

Loading…
Cancel
Save