Replacement for regular GPIO (DigitalIn, DigitalOut, DigitalInOut) classes which has superior speed. (modified for use opendrain in stm32)
Fork of FastIO by
Devices/FastIO_NUCLEO_F401.h@4:6ebbf25b9167, 2014-07-16 (annotated)
- Committer:
- Sissors
- Date:
- Wed Jul 16 19:31:35 2014 +0000
- Revision:
- 4:6ebbf25b9167
- Child:
- 5:3dd1ab9bbc59
First Nucleo, first version added: F401RE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 4:6ebbf25b9167 | 1 | #ifdef TARGET_NUCLEO_F401RE |
Sissors | 4:6ebbf25b9167 | 2 | |
Sissors | 4:6ebbf25b9167 | 3 | #include "mbed.h" |
Sissors | 4:6ebbf25b9167 | 4 | #include "pinmap.h" |
Sissors | 4:6ebbf25b9167 | 5 | |
Sissors | 4:6ebbf25b9167 | 6 | typedef struct { |
Sissors | 4:6ebbf25b9167 | 7 | uint32_t mask; |
Sissors | 4:6ebbf25b9167 | 8 | } fastio_vars; |
Sissors | 4:6ebbf25b9167 | 9 | |
Sissors | 4:6ebbf25b9167 | 10 | #define PINMASK (1 << STM_PIN(pin)) |
Sissors | 4:6ebbf25b9167 | 11 | #define PORT ((GPIO_TypeDef *)(GPIOA_BASE + 0x0400 * STM_PORT(pin))) |
Sissors | 4:6ebbf25b9167 | 12 | |
Sissors | 4:6ebbf25b9167 | 13 | #define INIT_PIN RCC->AHB1ENR |= (1 << STM_PORT(pin)); container.mask = PINMASK |
Sissors | 4:6ebbf25b9167 | 14 | #define DESTROY_PIN |
Sissors | 4:6ebbf25b9167 | 15 | |
Sissors | 4:6ebbf25b9167 | 16 | #define SET_DIR_INPUT (PORT->MODER &= ~(GPIO_MODER_MODER0 << (STM_PIN(pin) * 2))) |
Sissors | 4:6ebbf25b9167 | 17 | #define SET_DIR_OUTPUT (PORT->MODER |= (GPIO_MODER_MODER0_0 << (STM_PIN(pin) * 2))) |
Sissors | 4:6ebbf25b9167 | 18 | #define SET_MODE(pull) pin_mode(pin, pull); |
Sissors | 4:6ebbf25b9167 | 19 | |
Sissors | 4:6ebbf25b9167 | 20 | #define WRITE_PIN_SET (PORT->BSRRL = PINMASK) |
Sissors | 4:6ebbf25b9167 | 21 | #define WRITE_PIN_CLR (PORT->BSRRH = PINMASK) |
Sissors | 4:6ebbf25b9167 | 22 | |
Sissors | 4:6ebbf25b9167 | 23 | #define READ_PIN ((PORT->IDR & container.mask) ? 1 : 0) |
Sissors | 4:6ebbf25b9167 | 24 | |
Sissors | 4:6ebbf25b9167 | 25 | #endif |