fast_io.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * fast_io.h
8  *
9  * @author mikee47 January 2022
10  *
11  * Support macros to perform GPIO as fast as possible by avoiding conditionals and accessing memory-mapped registers directly.
12  *
13  ****/
14 
15 #pragma once
16 
17 #include <sming_attr.h>
18 
24 #define GP_IF0(flag, value) ((value) & (((flag)&1) - 1))
25 
31 #define GP_IF1(flag, value) ((value) & ~(((flag)&1) - 1))
32 
39 #define GP_SELECT(flag, value0, value1) (((value0) & (((flag)&1) - 1)) | ((value1) & ~(((flag)&1) - 1)))
40 
47 #define GP_FAST_READ(pin, reg) ((*(const volatile uint32_t*)(reg) >> ((pin)&31)) & 1)
48 
55 #define GP_FAST_WRITE(pin, val, regclr, regset) (*(volatile uint32_t*)GP_SELECT(val, regclr, regset) = BIT(pin))