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

Dependents:   Eavesdropper BitstreamGenerator SimpleDecimationFilter 11U68_MP3Player with TFTLCD ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FastIO_LPC11XX.h Source File

FastIO_LPC11XX.h

00001 #ifdef TARGET_LPC11XX_11CXX
00002 
00003 #include "mbed.h"
00004 #include "pinmap.h"
00005 #include "reserved_pins.h"
00006 
00007 typedef struct {
00008 } fastio_vars;
00009 
00010 #define PORT            ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000)))
00011 #define PIN             ((pin & 0x0F00) >> 8 )
00012 #define MASKDATA        (*((volatile uint32_t*) ((uint32_t)PORT + (1 << (PIN + 2)))))
00013 static inline void initpin(PinName pin);
00014 static const PinName reserved_pins[] = TARGET_RESERVED_PINS;
00015 
00016 #define INIT_PIN        initpin(pin)
00017 #define DESTROY_PIN     
00018 
00019 #define SET_DIR_INPUT   (PORT->DIR &= ~(1 << PIN))
00020 #define SET_DIR_OUTPUT  (PORT->DIR |= (1<<PIN))
00021 #define SET_MODE(pull)  (pin_mode(pin, pull))
00022 
00023 #define WRITE_PIN_SET   (MASKDATA = 0xFFFF)
00024 #define WRITE_PIN_CLR   (MASKDATA = 0)
00025 
00026 #define READ_PIN        ((MASKDATA == 0) ? 0 : 1)
00027 
00028 static inline void initpin(PinName pin) {
00029     unsigned i;
00030     int f = 0;
00031 
00032     for (i = 0; i < sizeof(reserved_pins) / sizeof(PinName); i ++) {
00033         if (pin == reserved_pins[i]) {
00034             f = 1;
00035             break;
00036         }
00037     }
00038     pin_function(pin, f);
00039 }
00040 
00041 #endif