|
@@ -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();
|