Replacement for regular GPIO (DigitalIn, DigitalOut, DigitalInOut) classes which has superior speed. (modified for use opendrain in stm32)
Fork of FastIO by
Diff: FastIO_LPC1768.h
- Revision:
- 0:d394ebd01052
- Child:
- 2:1a6ed4b84590
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FastIO_LPC1768.h Tue Jul 01 17:04:08 2014 +0000 @@ -0,0 +1,27 @@ +#ifdef TARGET_LPC1768 + +#include "mbed.h" +#include "pinmap.h" + +typedef struct { + uint32_t mask; +} fastio_vars; + +#define LPC_GPIO ((LPC_GPIO_TypeDef*)(pin & ~0x1F)) +#define PINMASK (1UL << (((pin) - P0_0)%32)) + +#define PINSELREG (*(volatile uint32_t*)(LPC_PINCON_BASE + 4*(((pin) - P0_0)/16))) +#define PINSELMASK (0x03 << (((pin - P0_0)%16)*2) ) + +#define INIT_PIN container.mask = PINMASK; (PINSELREG &= ~PINSELMASK) + +#define SET_DIR_INPUT (LPC_GPIO->FIODIR &= ~PINMASK) +#define SET_DIR_OUTPUT (LPC_GPIO->FIODIR |= PINMASK) +#define SET_MODE(pull) (pin_mode(pin, pull)) + +#define WRITE_PIN_SET (LPC_GPIO->FIOSET = PINMASK) +#define WRITE_PIN_CLR (LPC_GPIO->FIOCLR = PINMASK) + +#define READ_PIN ((LPC_GPIO->FIOPIN & container.mask) ? 1 : 0) + +#endif \ No newline at end of file