Просмотр исходного кода

Define pin accessors more like <Arduino.h>

Scott Lahteine 7 лет назад
Родитель
Сommit
599f2ad983
2 измененных файлов: 18 добавлений и 19 удалений
  1. 12
    13
      Marlin/src/HAL/HAL_LPC1768/arduino.cpp
  2. 6
    6
      Marlin/src/HAL/HAL_LPC1768/include/arduino.h

+ 12
- 13
Marlin/src/HAL/HAL_LPC1768/arduino.cpp Просмотреть файл

@@ -25,6 +25,7 @@
25 25
 #include <lpc17xx_pinsel.h>
26 26
 #include "HAL.h"
27 27
 #include "../../core/macros.h"
28
+#include "../../core/types.h"
28 29
 
29 30
 // Interrupts
30 31
 void cli(void) { __disable_irq(); } // Disable
@@ -32,7 +33,7 @@ void sei(void) { __enable_irq(); }  // Enable
32 33
 
33 34
 // Time functions
34 35
 void _delay_ms(int delay_ms) {
35
-  delay (delay_ms);
36
+  delay(delay_ms);
36 37
 }
37 38
 
38 39
 uint32_t millis() {
@@ -72,16 +73,16 @@ void delayMicroseconds(uint32_t us) {
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 83
 // IO functions
83 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 86
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF)
86 87
     return;
87 88
 
@@ -109,7 +110,7 @@ void pinMode(int pin, int mode) {
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 114
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF)
114 115
     return;
115 116
 
@@ -129,16 +130,14 @@ void digitalWrite(int pin, int pin_status) {
129 130
      */
130 131
 }
131 132
 
132
-bool digitalRead(int pin) {
133
+bool digitalRead(uint8_t pin) {
133 134
   if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) {
134 135
     return false;
135 136
   }
136 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 142
   extern bool LPC1768_PWM_attach_pin(uint8_t, uint32_t, uint32_t, uint8_t);
144 143
   extern bool LPC1768_PWM_write(uint8_t, uint32_t);
@@ -168,7 +167,7 @@ void analogWrite(int pin, int pwm_value) {  // 1 - 254: pwm_value, 0: LOW, 255:
168 167
 
169 168
 extern bool HAL_adc_finished();
170 169
 
171
-uint16_t analogRead(int adc_pin) {
170
+uint16_t analogRead(uint8_t adc_pin) {
172 171
   HAL_adc_start_conversion(adc_pin);
173 172
   while (!HAL_adc_finished());  // Wait for conversion to finish
174 173
   return HAL_adc_get_result();

+ 6
- 6
Marlin/src/HAL/HAL_LPC1768/include/arduino.h Просмотреть файл

@@ -92,18 +92,18 @@ extern "C" void GpioDisableInt(uint32_t port, uint32_t pin);
92 92
 
93 93
 // Time functions
94 94
 extern "C" {
95
-void delay(int milis);
95
+  void delay(const int milis);
96 96
 }
97 97
 void _delay_ms(int delay);
98 98
 void delayMicroseconds(unsigned long);
99 99
 uint32_t millis();
100 100
 
101 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 108
 // EEPROM
109 109
 void eeprom_write_byte(unsigned char *pos, unsigned char value);

Загрузка…
Отмена
Сохранить