Replacement for regular GPIO (DigitalIn, DigitalOut, DigitalInOut) classes which has superior speed.

Fork of FastIO by Erik -

Committer:
amateusz
Date:
Tue Apr 17 13:28:24 2018 +0000
Revision:
23:23a43a288e2c
Parent:
19:89d6ae484a35
Added support for STM32L1xx (checked on Nucleo L152). I'm done this solely cross referenced existing STM32 target files with L152 reference manual.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nameless129 19:89d6ae484a35 1 #ifdef TARGET_LPC43XX
nameless129 19:89d6ae484a35 2
nameless129 19:89d6ae484a35 3 #include "mbed.h"
nameless129 19:89d6ae484a35 4 #include "pinmap.h"
nameless129 19:89d6ae484a35 5
nameless129 19:89d6ae484a35 6 typedef struct {
nameless129 19:89d6ae484a35 7 uint32_t mask;
nameless129 19:89d6ae484a35 8 } fastio_vars;
nameless129 19:89d6ae484a35 9
nameless129 19:89d6ae484a35 10 #define PORT (((unsigned int)pin >> PORT_SHIFT) & 0x0000000F)
nameless129 19:89d6ae484a35 11 #define PINMASK (1 << ((int)pin & 0x1F))
nameless129 19:89d6ae484a35 12 static inline void initpin(PinName pin);
nameless129 19:89d6ae484a35 13
nameless129 19:89d6ae484a35 14 #define INIT_PIN container.mask = PINMASK; initpin(pin)
nameless129 19:89d6ae484a35 15 #define DESTROY_PIN
nameless129 19:89d6ae484a35 16
nameless129 19:89d6ae484a35 17 #define SET_DIR_INPUT ( ((LPC_GPIO_T *)(LPC_GPIO_PORT_BASE))->DIR[PORT] &= ~PINMASK )
nameless129 19:89d6ae484a35 18 #define SET_DIR_OUTPUT ( ((LPC_GPIO_T *)(LPC_GPIO_PORT_BASE))->DIR[PORT] |= PINMASK )
nameless129 19:89d6ae484a35 19 #define SET_MODE(pull) (pin_mode(pin, pull))
nameless129 19:89d6ae484a35 20
nameless129 19:89d6ae484a35 21 #define WRITE_PIN_SET ( ((LPC_GPIO_T *)(LPC_GPIO_PORT_BASE))->SET[PORT] = PINMASK )
nameless129 19:89d6ae484a35 22 #define WRITE_PIN_CLR ( ((LPC_GPIO_T *)(LPC_GPIO_PORT_BASE))->CLR[PORT] = PINMASK )
nameless129 19:89d6ae484a35 23
nameless129 19:89d6ae484a35 24 #define READ_PIN ( (((LPC_GPIO_T *)(LPC_GPIO_PORT_BASE))->PIN[PORT] & container.mask) ? 1 : 0 )
nameless129 19:89d6ae484a35 25
nameless129 19:89d6ae484a35 26 static inline void initpin(PinName pin) {
nameless129 19:89d6ae484a35 27 unsigned int port = (unsigned int)MBED_GPIO_PORT(pin);
nameless129 19:89d6ae484a35 28 int f = SCU_PINIO_FAST | ((port > 4) ? (4) : (0));
nameless129 19:89d6ae484a35 29 pin_function(pin, f);
nameless129 19:89d6ae484a35 30 }
nameless129 19:89d6ae484a35 31
nameless129 19:89d6ae484a35 32 #endif