|
@ -25,6 +25,7 @@ |
|
|
#include <lpc17xx_pinsel.h> |
|
|
#include <lpc17xx_pinsel.h> |
|
|
#include "HAL.h" |
|
|
#include "HAL.h" |
|
|
#include "../../core/macros.h" |
|
|
#include "../../core/macros.h" |
|
|
|
|
|
#include "../../core/types.h" |
|
|
|
|
|
|
|
|
// Interrupts
|
|
|
// Interrupts
|
|
|
void cli(void) { __disable_irq(); } // Disable
|
|
|
void cli(void) { __disable_irq(); } // Disable
|
|
@ -72,16 +73,16 @@ void delayMicroseconds(uint32_t us) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
extern "C" void delay(int msec) { |
|
|
extern "C" void delay(const int msec) { |
|
|
volatile int32_t end = _millis + msec; |
|
|
volatile millis_t end = _millis + msec; |
|
|
SysTick->VAL = SysTick->LOAD; // reset systick counter so next systick is in exactly 1ms
|
|
|
SysTick->VAL = SysTick->LOAD; // reset systick counter so next systick is in exactly 1ms
|
|
|
// this could extend the time between systicks by upto 1ms
|
|
|
// this could extend the time between systicks by upto 1ms
|
|
|
while (_millis < end) __WFE(); |
|
|
while PENDING(_millis, end) __WFE(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// IO functions
|
|
|
// IO functions
|
|
|
// As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
|
|
|
// As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
|
|
|
void pinMode(int pin, int mode) { |
|
|
void pinMode(uint8_t pin, uint8_t mode) { |
|
|
if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) |
|
|
if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
@ -109,7 +110,7 @@ void pinMode(int pin, int mode) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void digitalWrite(int pin, int pin_status) { |
|
|
void digitalWrite(uint8_t pin, uint8_t pin_status) { |
|
|
if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) |
|
|
if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
@ -129,16 +130,14 @@ void digitalWrite(int pin, int pin_status) { |
|
|
*/ |
|
|
*/ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool digitalRead(int pin) { |
|
|
bool digitalRead(uint8_t pin) { |
|
|
if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) { |
|
|
if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
return LPC_GPIO(pin_map[pin].port)->FIOPIN & LPC_PIN(pin_map[pin].pin) ? 1 : 0; |
|
|
return LPC_GPIO(pin_map[pin].port)->FIOPIN & LPC_PIN(pin_map[pin].pin) ? 1 : 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void analogWrite(uint8_t pin, int pwm_value) { // 1 - 254: pwm_value, 0: LOW, 255: HIGH
|
|
|
|
|
|
|
|
|
void analogWrite(int pin, int pwm_value) { // 1 - 254: pwm_value, 0: LOW, 255: HIGH
|
|
|
|
|
|
|
|
|
|
|
|
extern bool LPC1768_PWM_attach_pin(uint8_t, uint32_t, uint32_t, uint8_t); |
|
|
extern bool LPC1768_PWM_attach_pin(uint8_t, uint32_t, uint32_t, uint8_t); |
|
|
extern bool LPC1768_PWM_write(uint8_t, uint32_t); |
|
|
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: |
|
|
|
|
|
|
|
|
extern bool HAL_adc_finished(); |
|
|
extern bool HAL_adc_finished(); |
|
|
|
|
|
|
|
|
uint16_t analogRead(int adc_pin) { |
|
|
uint16_t analogRead(uint8_t adc_pin) { |
|
|
HAL_adc_start_conversion(adc_pin); |
|
|
HAL_adc_start_conversion(adc_pin); |
|
|
while (!HAL_adc_finished()); // Wait for conversion to finish
|
|
|
while (!HAL_adc_finished()); // Wait for conversion to finish
|
|
|
return HAL_adc_get_result(); |
|
|
return HAL_adc_get_result(); |
|
|