Browse Source

Define pin accessors more like <Arduino.h>

Scott Lahteine 7 years ago
parent
commit
599f2ad983

+ 12
- 13
Marlin/src/HAL/HAL_LPC1768/arduino.cpp View File

25
 #include <lpc17xx_pinsel.h>
25
 #include <lpc17xx_pinsel.h>
26
 #include "HAL.h"
26
 #include "HAL.h"
27
 #include "../../core/macros.h"
27
 #include "../../core/macros.h"
28
+#include "../../core/types.h"
28
 
29
 
29
 // Interrupts
30
 // Interrupts
30
 void cli(void) { __disable_irq(); } // Disable
31
 void cli(void) { __disable_irq(); } // Disable
32
 
33
 
33
 // Time functions
34
 // Time functions
34
 void _delay_ms(int delay_ms) {
35
 void _delay_ms(int delay_ms) {
35
-  delay (delay_ms);
36
+  delay(delay_ms);
36
 }
37
 }
37
 
38
 
38
 uint32_t millis() {
39
 uint32_t millis() {
72
   }
73
   }
73
 }
74
 }
74
 
75
 
75
-extern "C" void delay(int msec) {
76
-   volatile int32_t end = _millis + msec;
77
-   SysTick->VAL = SysTick->LOAD; // reset systick counter so next systick is in exactly 1ms
78
-                                 // this could extend the time between systicks by upto 1ms
79
-   while (_millis < end) __WFE();
76
+extern "C" void delay(const int msec) {
77
+  volatile millis_t end = _millis + msec;
78
+  SysTick->VAL = SysTick->LOAD; // reset systick counter so next systick is in exactly 1ms
79
+                                // this could extend the time between systicks by upto 1ms
80
+  while PENDING(_millis, end) __WFE();
80
 }
81
 }
81
 
82
 
82
 // IO functions
83
 // IO functions
83
 // As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
84
 // As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
84
-void pinMode(int pin, int mode) {
85
+void pinMode(uint8_t pin, uint8_t mode) {
85
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF)
86
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF)
86
     return;
87
     return;
87
 
88
 
109
   }
110
   }
110
 }
111
 }
111
 
112
 
112
-void digitalWrite(int pin, int pin_status) {
113
+void digitalWrite(uint8_t pin, uint8_t pin_status) {
113
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF)
114
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF)
114
     return;
115
     return;
115
 
116
 
129
      */
130
      */
130
 }
131
 }
131
 
132
 
132
-bool digitalRead(int pin) {
133
+bool digitalRead(uint8_t pin) {
133
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) {
134
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) {
134
     return false;
135
     return false;
135
   }
136
   }
136
   return LPC_GPIO(pin_map[pin].port)->FIOPIN & LPC_PIN(pin_map[pin].pin) ? 1 : 0;
137
   return LPC_GPIO(pin_map[pin].port)->FIOPIN & LPC_PIN(pin_map[pin].pin) ? 1 : 0;
137
 }
138
 }
138
 
139
 
139
-
140
-
141
-void analogWrite(int pin, int pwm_value) {  // 1 - 254: pwm_value, 0: LOW, 255: HIGH
140
+void analogWrite(uint8_t pin, int pwm_value) {  // 1 - 254: pwm_value, 0: LOW, 255: HIGH
142
 
141
 
143
   extern bool LPC1768_PWM_attach_pin(uint8_t, uint32_t, uint32_t, uint8_t);
142
   extern bool LPC1768_PWM_attach_pin(uint8_t, uint32_t, uint32_t, uint8_t);
144
   extern bool LPC1768_PWM_write(uint8_t, uint32_t);
143
   extern bool LPC1768_PWM_write(uint8_t, uint32_t);
168
 
167
 
169
 extern bool HAL_adc_finished();
168
 extern bool HAL_adc_finished();
170
 
169
 
171
-uint16_t analogRead(int adc_pin) {
170
+uint16_t analogRead(uint8_t adc_pin) {
172
   HAL_adc_start_conversion(adc_pin);
171
   HAL_adc_start_conversion(adc_pin);
173
   while (!HAL_adc_finished());  // Wait for conversion to finish
172
   while (!HAL_adc_finished());  // Wait for conversion to finish
174
   return HAL_adc_get_result();
173
   return HAL_adc_get_result();

+ 6
- 6
Marlin/src/HAL/HAL_LPC1768/include/arduino.h View File

92
 
92
 
93
 // Time functions
93
 // Time functions
94
 extern "C" {
94
 extern "C" {
95
-void delay(int milis);
95
+  void delay(const int milis);
96
 }
96
 }
97
 void _delay_ms(int delay);
97
 void _delay_ms(int delay);
98
 void delayMicroseconds(unsigned long);
98
 void delayMicroseconds(unsigned long);
99
 uint32_t millis();
99
 uint32_t millis();
100
 
100
 
101
 //IO functions
101
 //IO functions
102
-void pinMode(int pin_number, int mode);
103
-void digitalWrite(int pin_number, int pin_status);
104
-bool digitalRead(int pin);
105
-void analogWrite(int pin_number, int pin_status);
106
-uint16_t analogRead(int adc_pin);
102
+void pinMode(uint8_t, uint8_t);
103
+void digitalWrite(uint8_t, uint8_t);
104
+int digitalRead(uint8_t);
105
+void analogWrite(uint8_t, int);
106
+int analogRead(uint8_t);
107
 
107
 
108
 // EEPROM
108
 // EEPROM
109
 void eeprom_write_byte(unsigned char *pos, unsigned char value);
109
 void eeprom_write_byte(unsigned char *pos, unsigned char value);

Loading…
Cancel
Save