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_STM32F4.h Source File

FastIO_STM32F4.h

00001 #if defined(TARGET_STM32F4)
00002 
00003 #include "mbed.h"
00004 #include "pinmap.h"
00005 
00006 typedef struct {
00007     uint32_t mask;
00008 } fastio_vars;
00009 
00010 #define PINMASK             (1 << STM_PIN(pin))
00011 #define PINMASK_CLR         ((1<<16) << STM_PIN(pin))
00012 #define PORT                ((GPIO_TypeDef *)(GPIOA_BASE + 0x0400 * STM_PORT(pin)))
00013 
00014 #define INIT_PIN            RCC->AHB1ENR |= (1 << STM_PORT(pin)); (PORT->MODER &= ~(GPIO_MODER_MODER0_1 << (STM_PIN(pin) * 2))); container.mask = PINMASK
00015 #define DESTROY_PIN     
00016 
00017 #define SET_DIR_INPUT       (PORT->MODER &= ~(GPIO_MODER_MODER0_0 << (STM_PIN(pin) * 2)))
00018 #define SET_DIR_OUTPUT      (PORT->MODER |= (GPIO_MODER_MODER0_0 << (STM_PIN(pin) * 2)))
00019 #define SET_MODE(pull)      pin_mode(pin, pull);
00020 
00021 #define WRITE_PIN_SET       (PORT->BSRR = PINMASK)
00022 #define WRITE_PIN_CLR       (PORT->BSRR = PINMASK_CLR)
00023 
00024 #define READ_PIN            ((PORT->IDR & container.mask) ? 1 : 0)
00025 
00026 #endif