Misc. general cleanup

This commit is contained in:
Scott Lahteine
2017-11-19 14:12:45 -06:00
parent 8836623e0f
commit b9327a4d16
5 changed files with 130 additions and 145 deletions

View File

@@ -72,8 +72,7 @@ extern "C" void delay(const int msec) {
// IO functions
// As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
void pinMode(pin_t pin, uint8_t mode) {
if (!VALID_PIN(pin))
return;
if (!VALID_PIN(pin)) return;
PINSEL_CFG_Type config = { LPC1768_PIN_PORT(pin),
LPC1768_PIN_PIN(pin),
@@ -100,8 +99,7 @@ void pinMode(pin_t pin, uint8_t mode) {
}
void digitalWrite(pin_t pin, uint8_t pin_status) {
if (!VALID_PIN(pin))
return;
if (!VALID_PIN(pin)) return;
if (pin_status)
LPC_GPIO(LPC1768_PIN_PORT(pin))->FIOSET = LPC_PIN(LPC1768_PIN_PIN(pin));
@@ -120,20 +118,18 @@ void digitalWrite(pin_t pin, uint8_t pin_status) {
}
bool digitalRead(pin_t pin) {
if (!VALID_PIN(pin)) {
return false;
}
if (!VALID_PIN(pin)) return false;
return LPC_GPIO(LPC1768_PIN_PORT(pin))->FIOPIN & LPC_PIN(LPC1768_PIN_PIN(pin)) ? 1 : 0;
}
void analogWrite(pin_t pin, int pwm_value) { // 1 - 254: pwm_value, 0: LOW, 255: HIGH
if (!VALID_PIN(pin)) return;
#define MR0_MARGIN 200 // if channel value too close to MR0 the system locks up
static bool out_of_PWM_slots = false;
if (!VALID_PIN(pin))
return;
uint value = MAX(MIN(pwm_value, 255), 0);
if (value == 0 || value == 255) { // treat as digital pin
LPC1768_PWM_detach_pin(pin); // turn off PWM