Replacement for regular GPIO (DigitalIn, DigitalOut, DigitalInOut) classes which has superior speed. (modified for use opendrain in stm32)
Fork of FastIO by
Diff: Devices/FastIO_LPC1768.h
- Revision:
- 4:6ebbf25b9167
- Parent:
- 2:1a6ed4b84590
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Devices/FastIO_LPC1768.h Wed Jul 16 19:31:35 2014 +0000 @@ -0,0 +1,28 @@ +#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 DESTROY_PIN + +#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