HAL FastIO cleanup and fixes
This commit is contained in:
parent
5b5e322356
commit
456cf971af
|
@ -55,7 +55,7 @@ bool useable_hardware_PWM(pin_t pin);
|
||||||
#define WRITE_PIN_CLR(IO) (LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOCLR = LPC_PIN(LPC1768_PIN_PIN(IO)))
|
#define WRITE_PIN_CLR(IO) (LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOCLR = LPC_PIN(LPC1768_PIN_PIN(IO)))
|
||||||
|
|
||||||
#define READ_PIN(IO) ((LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOPIN & LPC_PIN(LPC1768_PIN_PIN(IO))) ? 1 : 0)
|
#define READ_PIN(IO) ((LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOPIN & LPC_PIN(LPC1768_PIN_PIN(IO))) ? 1 : 0)
|
||||||
#define WRITE_PIN(IO, v) ((v) ? WRITE_PIN_SET(IO) : WRITE_PIN_CLR(IO))
|
#define WRITE_PIN(IO,V) ((V) ? WRITE_PIN_SET(IO) : WRITE_PIN_CLR(IO))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Magic I/O routines
|
* Magic I/O routines
|
||||||
|
@ -66,76 +66,76 @@ bool useable_hardware_PWM(pin_t pin);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// Read a pin
|
/// Read a pin
|
||||||
#define _READ(IO) READ_PIN(IO)
|
#define _READ(IO) READ_PIN(IO)
|
||||||
|
|
||||||
/// Write to a pin
|
/// Write to a pin
|
||||||
#define _WRITE_VAR(IO, v) digitalWrite(IO, v)
|
#define _WRITE_VAR(IO,V) digitalWrite(IO,V)
|
||||||
|
|
||||||
#define _WRITE(IO, v) WRITE_PIN(IO, v)
|
#define _WRITE(IO,V) WRITE_PIN(IO,V)
|
||||||
|
|
||||||
/// toggle a pin
|
/// toggle a pin
|
||||||
#define _TOGGLE(IO) _WRITE(IO, !READ(IO))
|
#define _TOGGLE(IO) _WRITE(IO, !READ(IO))
|
||||||
|
|
||||||
/// set pin as input
|
/// set pin as input
|
||||||
#define _SET_INPUT(IO) SET_DIR_INPUT(IO)
|
#define _SET_INPUT(IO) SET_DIR_INPUT(IO)
|
||||||
|
|
||||||
/// set pin as output
|
/// set pin as output
|
||||||
#define _SET_OUTPUT(IO) SET_DIR_OUTPUT(IO)
|
#define _SET_OUTPUT(IO) SET_DIR_OUTPUT(IO)
|
||||||
|
|
||||||
/// set pin as input with pullup mode
|
/// set pin as input with pullup mode
|
||||||
#define _PULLUP(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLUP : INPUT)))
|
#define _PULLUP(IO,V) pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
|
||||||
|
|
||||||
/// set pin as input with pulldown mode
|
/// set pin as input with pulldown mode
|
||||||
#define _PULLDOWN(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLDOWN : INPUT)))
|
#define _PULLDOWN(IO,V) pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT)
|
||||||
|
|
||||||
// hg42: all pins can be input or output (I hope)
|
// hg42: all pins can be input or output (I hope)
|
||||||
// hg42: undefined pins create compile error (IO, is no pin)
|
// hg42: undefined pins create compile error (IO, is no pin)
|
||||||
// hg42: currently not used, but was used by pinsDebug
|
// hg42: currently not used, but was used by pinsDebug
|
||||||
|
|
||||||
/// check if pin is an input
|
/// check if pin is an input
|
||||||
#define _GET_INPUT(IO) (LPC1768_PIN_PIN(IO)>=0)
|
#define _GET_INPUT(IO) (LPC1768_PIN_PIN(IO) >= 0)
|
||||||
|
|
||||||
/// check if pin is an output
|
/// check if pin is an output
|
||||||
#define _GET_OUTPUT(IO) (LPC1768_PIN_PIN(IO)>=0)
|
#define _GET_OUTPUT(IO) (LPC1768_PIN_PIN(IO) >= 0)
|
||||||
|
|
||||||
// hg42: GET_TIMER is used only to check if it's a PWM pin
|
// hg42: GET_TIMER is used only to check if it's a PWM pin
|
||||||
// hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
|
// hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
|
||||||
// hg42: instead use PWM bit from the #define
|
// hg42: instead use PWM bit from the #define
|
||||||
|
|
||||||
/// check if pin is a timer
|
/// check if pin is a timer
|
||||||
#define _GET_TIMER(IO) TRUE // could be LPC1768_PIN_PWM(IO), but there
|
#define _GET_TIMER(IO) TRUE // could be LPC1768_PIN_PWM(IO), but there
|
||||||
// hg42: could be this:
|
// hg42: could be this:
|
||||||
// #define _GET_TIMER(IO) LPC1768_PIN_PWM(IO)
|
// #define _GET_TIMER(IO) LPC1768_PIN_PWM(IO)
|
||||||
// but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
|
// but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
|
||||||
|
|
||||||
/// Read a pin wrapper
|
/// Read a pin wrapper
|
||||||
#define READ(IO) _READ(IO)
|
#define READ(IO) _READ(IO)
|
||||||
|
|
||||||
/// Write to a pin wrapper
|
/// Write to a pin wrapper
|
||||||
#define WRITE_VAR(IO, v) _WRITE_VAR(IO, v)
|
#define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
|
||||||
#define WRITE(IO, v) _WRITE(IO, v)
|
#define WRITE(IO,V) _WRITE(IO,V)
|
||||||
|
|
||||||
/// toggle a pin wrapper
|
/// toggle a pin wrapper
|
||||||
#define TOGGLE(IO) _TOGGLE(IO)
|
#define TOGGLE(IO) _TOGGLE(IO)
|
||||||
|
|
||||||
/// set pin as input wrapper
|
/// set pin as input wrapper
|
||||||
#define SET_INPUT(IO) _SET_INPUT(IO)
|
#define SET_INPUT(IO) _SET_INPUT(IO)
|
||||||
/// set pin as input with pullup wrapper
|
/// set pin as input with pullup wrapper
|
||||||
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
||||||
/// set pin as input with pulldown wrapper
|
/// set pin as input with pulldown wrapper
|
||||||
#define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
|
#define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
|
||||||
/// set pin as output wrapper - reads the pin and sets the output to that value
|
/// set pin as output wrapper - reads the pin and sets the output to that value
|
||||||
#define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
|
#define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
|
||||||
|
|
||||||
/// check if pin is an input wrapper
|
/// check if pin is an input wrapper
|
||||||
#define GET_INPUT(IO) _GET_INPUT(IO)
|
#define GET_INPUT(IO) _GET_INPUT(IO)
|
||||||
/// check if pin is an output wrapper
|
/// check if pin is an output wrapper
|
||||||
#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
|
#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
|
||||||
|
|
||||||
/// check if pin is a timer (wrapper)
|
/// check if pin is a timer (wrapper)
|
||||||
#define GET_TIMER(IO) _GET_TIMER(IO)
|
#define GET_TIMER(IO) _GET_TIMER(IO)
|
||||||
|
|
||||||
// Shorthand
|
// Shorthand
|
||||||
#define OUT_WRITE(IO, v) { SET_OUTPUT(IO); WRITE(IO, v); }
|
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
|
||||||
|
|
||||||
#endif // _FASTIO_LPC1768_H
|
#endif // _FASTIO_LPC1768_H
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#define READ(IO) (PIN_MAP[IO].gpio_device->regs->IDR & (1U << PIN_MAP[IO].gpio_bit) ? HIGH : LOW)
|
#define READ(IO) (PIN_MAP[IO].gpio_device->regs->IDR & (1U << PIN_MAP[IO].gpio_bit) ? HIGH : LOW)
|
||||||
#define WRITE(IO,V) (PIN_MAP[IO].gpio_device->regs->BSRR = (1U << PIN_MAP[IO].gpio_bit) << (16 * !(bool)V))
|
#define WRITE(IO,V) (PIN_MAP[IO].gpio_device->regs->BSRR = (1U << PIN_MAP[IO].gpio_bit) << (16 * !(bool)V))
|
||||||
#define TOGGLE(IO) (PIN_MAP[IO].gpio_device->regs->ODR = PIN_MAP[IO].gpio_device->regs->ODR ^ (1U << PIN_MAP[IO].gpio_bit))
|
#define TOGGLE(IO) (PIN_MAP[IO].gpio_device->regs->ODR = PIN_MAP[IO].gpio_device->regs->ODR ^ (1U << PIN_MAP[IO].gpio_bit))
|
||||||
#define WRITE_VAR(IO,V) WRITE(io,V)
|
#define WRITE_VAR(IO,V) WRITE(IO,V)
|
||||||
|
|
||||||
#define _GET_MODE(IO) gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
|
#define _GET_MODE(IO) gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
|
||||||
#define _SET_MODE(IO,M) gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)
|
#define _SET_MODE(IO,M) gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)
|
||||||
|
|
|
@ -31,26 +31,27 @@
|
||||||
|
|
||||||
#define _BV(b) (1 << (b))
|
#define _BV(b) (1 << (b))
|
||||||
|
|
||||||
#define READ(IO) digitalRead(IO)
|
#define READ(IO) digitalRead(IO)
|
||||||
#define WRITE(IO, v) digitalWrite(IO,v)
|
#define WRITE(IO,V) digitalWrite(IO,V)
|
||||||
#define TOGGLE(IO) do{ _SET_OUTPUT(IO); digitalWrite(IO,!digitalRead(IO)); }while(0)
|
#define WRITE_VAR(IO,V) WRITE(IO,V)
|
||||||
#define WRITE_VAR(IO, v) digitalWrite(IO,v)
|
|
||||||
|
|
||||||
#define _GET_MODE(IO)
|
#define _GET_MODE(IO)
|
||||||
#define _SET_MODE(IO,M) pinMode(IO, M)
|
#define _SET_MODE(IO,M) pinMode(IO, M)
|
||||||
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
|
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
|
||||||
|
|
||||||
#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
|
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
|
||||||
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
|
|
||||||
#define SET_INPUT_PULLDOW(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
|
#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
|
||||||
#define SET_OUTPUT(IO) do{ _SET_OUTPUT(IO); WRITE(IO, LOW); }while(0)
|
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
|
||||||
|
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
|
||||||
|
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
|
||||||
|
|
||||||
|
#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
|
||||||
|
|
||||||
#define GET_INPUT(IO)
|
#define GET_INPUT(IO)
|
||||||
#define GET_OUTPUT(IO)
|
#define GET_OUTPUT(IO)
|
||||||
#define GET_TIMER(IO)
|
#define GET_TIMER(IO)
|
||||||
|
|
||||||
#define OUT_WRITE(IO, v) { _SET_OUTPUT(IO); WRITE(IO, v); }
|
|
||||||
|
|
||||||
#define PORTA 0
|
#define PORTA 0
|
||||||
#define PORTB 1
|
#define PORTB 1
|
||||||
#define PORTC 2
|
#define PORTC 2
|
||||||
|
|
|
@ -31,26 +31,27 @@
|
||||||
|
|
||||||
#define _BV(b) (1 << (b))
|
#define _BV(b) (1 << (b))
|
||||||
|
|
||||||
#define READ(IO) digitalRead(IO)
|
#define READ(IO) digitalRead(IO)
|
||||||
#define WRITE(IO, v) digitalWrite(IO,v)
|
#define WRITE(IO,V) digitalWrite(IO,V)
|
||||||
#define TOGGLE(IO) do{ _SET_OUTPUT(IO); digitalWrite(IO,!digitalRead(IO)); }while(0)
|
#define WRITE_VAR(IO,V) WRITE(IO,V)
|
||||||
#define WRITE_VAR(IO, v) digitalWrite(IO,v)
|
|
||||||
|
|
||||||
#define _GET_MODE(IO)
|
#define _GET_MODE(IO)
|
||||||
#define _SET_MODE(IO,M) pinMode(IO, M)
|
#define _SET_MODE(IO,M) pinMode(IO, M)
|
||||||
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
|
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
|
||||||
|
|
||||||
#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
|
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
|
||||||
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
|
|
||||||
#define SET_INPUT_PULLDOW(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
|
#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
|
||||||
#define SET_OUTPUT(IO) do{ _SET_OUTPUT(IO); WRITE(IO, LOW); }while(0)
|
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
|
||||||
|
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
|
||||||
|
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
|
||||||
|
|
||||||
|
#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
|
||||||
|
|
||||||
#define GET_INPUT(IO)
|
#define GET_INPUT(IO)
|
||||||
#define GET_OUTPUT(IO)
|
#define GET_OUTPUT(IO)
|
||||||
#define GET_TIMER(IO)
|
#define GET_TIMER(IO)
|
||||||
|
|
||||||
#define OUT_WRITE(IO, v) { _SET_OUTPUT(IO); WRITE(IO, v); }
|
|
||||||
|
|
||||||
#define PORTA 0
|
#define PORTA 0
|
||||||
#define PORTB 1
|
#define PORTB 1
|
||||||
#define PORTC 2
|
#define PORTC 2
|
||||||
|
|
|
@ -99,7 +99,7 @@
|
||||||
|
|
||||||
// Macros for bit masks
|
// Macros for bit masks
|
||||||
#undef _BV
|
#undef _BV
|
||||||
#define _BV(b) (1<<(b))
|
#define _BV(b) (1 << (b))
|
||||||
#define TEST(n,b) !!((n)&_BV(b))
|
#define TEST(n,b) !!((n)&_BV(b))
|
||||||
#define SBI(n,b) (n |= _BV(b))
|
#define SBI(n,b) (n |= _BV(b))
|
||||||
#define CBI(n,b) (n &= ~_BV(b))
|
#define CBI(n,b) (n &= ~_BV(b))
|
||||||
|
|
Loading…
Reference in a new issue