Browse Source

HAL FastIO cleanup and fixes

Scott Lahteine 6 years ago
parent
commit
456cf971af

+ 24
- 24
Marlin/src/HAL/HAL_LPC1768/fastio.h View File

55
 #define WRITE_PIN_CLR(IO)       (LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOCLR = LPC_PIN(LPC1768_PIN_PIN(IO)))
55
 #define WRITE_PIN_CLR(IO)       (LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOCLR = LPC_PIN(LPC1768_PIN_PIN(IO)))
56
 
56
 
57
 #define READ_PIN(IO)            ((LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOPIN & LPC_PIN(LPC1768_PIN_PIN(IO))) ? 1 : 0)
57
 #define READ_PIN(IO)            ((LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOPIN & LPC_PIN(LPC1768_PIN_PIN(IO))) ? 1 : 0)
58
-#define WRITE_PIN(IO, v)        ((v) ? WRITE_PIN_SET(IO) : WRITE_PIN_CLR(IO))
58
+#define WRITE_PIN(IO,V)         ((V) ? WRITE_PIN_SET(IO) : WRITE_PIN_CLR(IO))
59
 
59
 
60
 /**
60
 /**
61
  * Magic I/O routines
61
  * Magic I/O routines
66
  */
66
  */
67
 
67
 
68
 /// Read a pin
68
 /// Read a pin
69
-#define _READ(IO) READ_PIN(IO)
69
+#define _READ(IO)         READ_PIN(IO)
70
 
70
 
71
 /// Write to a pin
71
 /// Write to a pin
72
-#define _WRITE_VAR(IO, v) digitalWrite(IO, v)
72
+#define _WRITE_VAR(IO,V)  digitalWrite(IO,V)
73
 
73
 
74
-#define _WRITE(IO, v) WRITE_PIN(IO, v)
74
+#define _WRITE(IO,V)      WRITE_PIN(IO,V)
75
 
75
 
76
 /// toggle a pin
76
 /// toggle a pin
77
-#define _TOGGLE(IO) _WRITE(IO, !READ(IO))
77
+#define _TOGGLE(IO)       _WRITE(IO, !READ(IO))
78
 
78
 
79
 /// set pin as input
79
 /// set pin as input
80
-#define _SET_INPUT(IO) SET_DIR_INPUT(IO)
80
+#define _SET_INPUT(IO)    SET_DIR_INPUT(IO)
81
 
81
 
82
 /// set pin as output
82
 /// set pin as output
83
-#define _SET_OUTPUT(IO) SET_DIR_OUTPUT(IO)
83
+#define _SET_OUTPUT(IO)   SET_DIR_OUTPUT(IO)
84
 
84
 
85
 /// set pin as input with pullup mode
85
 /// set pin as input with pullup mode
86
-#define _PULLUP(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLUP : INPUT)))
86
+#define _PULLUP(IO,V)     pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
87
 
87
 
88
 /// set pin as input with pulldown mode
88
 /// set pin as input with pulldown mode
89
-#define _PULLDOWN(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLDOWN : INPUT)))
89
+#define _PULLDOWN(IO,V)   pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT)
90
 
90
 
91
 // hg42: all pins can be input or output (I hope)
91
 // hg42: all pins can be input or output (I hope)
92
 // hg42: undefined pins create compile error (IO, is no pin)
92
 // hg42: undefined pins create compile error (IO, is no pin)
93
 // hg42: currently not used, but was used by pinsDebug
93
 // hg42: currently not used, but was used by pinsDebug
94
 
94
 
95
 /// check if pin is an input
95
 /// check if pin is an input
96
-#define _GET_INPUT(IO)        (LPC1768_PIN_PIN(IO)>=0)
96
+#define _GET_INPUT(IO)    (LPC1768_PIN_PIN(IO) >= 0)
97
 
97
 
98
 /// check if pin is an output
98
 /// check if pin is an output
99
-#define _GET_OUTPUT(IO)       (LPC1768_PIN_PIN(IO)>=0)
99
+#define _GET_OUTPUT(IO)   (LPC1768_PIN_PIN(IO) >= 0)
100
 
100
 
101
 // hg42: GET_TIMER is used only to check if it's a PWM pin
101
 // hg42: GET_TIMER is used only to check if it's a PWM pin
102
 // hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
102
 // hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
103
 // hg42: instead use PWM bit from the #define
103
 // hg42: instead use PWM bit from the #define
104
 
104
 
105
 /// check if pin is a timer
105
 /// check if pin is a timer
106
-#define _GET_TIMER(IO)        TRUE  // could be LPC1768_PIN_PWM(IO), but there
106
+#define _GET_TIMER(IO)    TRUE  // could be LPC1768_PIN_PWM(IO), but there
107
 // hg42: could be this:
107
 // hg42: could be this:
108
 // #define _GET_TIMER(IO)        LPC1768_PIN_PWM(IO)
108
 // #define _GET_TIMER(IO)        LPC1768_PIN_PWM(IO)
109
 // but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
109
 // but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
110
 
110
 
111
 /// Read a pin wrapper
111
 /// Read a pin wrapper
112
-#define READ(IO)  _READ(IO)
112
+#define READ(IO)          _READ(IO)
113
 
113
 
114
 /// Write to a pin wrapper
114
 /// Write to a pin wrapper
115
-#define WRITE_VAR(IO, v)  _WRITE_VAR(IO, v)
116
-#define WRITE(IO, v)  _WRITE(IO, v)
115
+#define WRITE_VAR(IO,V)   _WRITE_VAR(IO,V)
116
+#define WRITE(IO,V)       _WRITE(IO,V)
117
 
117
 
118
 /// toggle a pin wrapper
118
 /// toggle a pin wrapper
119
-#define TOGGLE(IO)  _TOGGLE(IO)
119
+#define TOGGLE(IO)        _TOGGLE(IO)
120
 
120
 
121
 /// set pin as input wrapper
121
 /// set pin as input wrapper
122
-#define SET_INPUT(IO)  _SET_INPUT(IO)
122
+#define SET_INPUT(IO)     _SET_INPUT(IO)
123
 /// set pin as input with pullup wrapper
123
 /// set pin as input with pullup wrapper
124
-#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
124
+#define SET_INPUT_PULLUP(IO)    do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
125
 /// set pin as input with pulldown wrapper
125
 /// set pin as input with pulldown wrapper
126
-#define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
126
+#define SET_INPUT_PULLDOWN(IO)  do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
127
 /// set pin as output wrapper  -  reads the pin and sets the output to that value
127
 /// set pin as output wrapper  -  reads the pin and sets the output to that value
128
-#define SET_OUTPUT(IO)  do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
128
+#define SET_OUTPUT(IO)          do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
129
 
129
 
130
 /// check if pin is an input wrapper
130
 /// check if pin is an input wrapper
131
-#define GET_INPUT(IO)  _GET_INPUT(IO)
131
+#define GET_INPUT(IO)     _GET_INPUT(IO)
132
 /// check if pin is an output wrapper
132
 /// check if pin is an output wrapper
133
-#define GET_OUTPUT(IO)  _GET_OUTPUT(IO)
133
+#define GET_OUTPUT(IO)    _GET_OUTPUT(IO)
134
 
134
 
135
 /// check if pin is a timer (wrapper)
135
 /// check if pin is a timer (wrapper)
136
-#define GET_TIMER(IO)  _GET_TIMER(IO)
136
+#define GET_TIMER(IO)     _GET_TIMER(IO)
137
 
137
 
138
 // Shorthand
138
 // Shorthand
139
-#define OUT_WRITE(IO, v) { SET_OUTPUT(IO); WRITE(IO, v); }
139
+#define OUT_WRITE(IO,V)   do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
140
 
140
 
141
 #endif // _FASTIO_LPC1768_H
141
 #endif // _FASTIO_LPC1768_H

+ 1
- 1
Marlin/src/HAL/HAL_STM32F1/fastio_Stm32f1.h View File

34
 #define READ(IO)              (PIN_MAP[IO].gpio_device->regs->IDR & (1U << PIN_MAP[IO].gpio_bit) ? HIGH : LOW)
34
 #define READ(IO)              (PIN_MAP[IO].gpio_device->regs->IDR & (1U << PIN_MAP[IO].gpio_bit) ? HIGH : LOW)
35
 #define WRITE(IO,V)           (PIN_MAP[IO].gpio_device->regs->BSRR = (1U << PIN_MAP[IO].gpio_bit) << (16 * !(bool)V))
35
 #define WRITE(IO,V)           (PIN_MAP[IO].gpio_device->regs->BSRR = (1U << PIN_MAP[IO].gpio_bit) << (16 * !(bool)V))
36
 #define TOGGLE(IO)            (PIN_MAP[IO].gpio_device->regs->ODR = PIN_MAP[IO].gpio_device->regs->ODR ^ (1U << PIN_MAP[IO].gpio_bit))
36
 #define TOGGLE(IO)            (PIN_MAP[IO].gpio_device->regs->ODR = PIN_MAP[IO].gpio_device->regs->ODR ^ (1U << PIN_MAP[IO].gpio_bit))
37
-#define WRITE_VAR(IO,V)       WRITE(io,V)
37
+#define WRITE_VAR(IO,V)       WRITE(IO,V)
38
 
38
 
39
 #define _GET_MODE(IO)         gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
39
 #define _GET_MODE(IO)         gpio_get_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit)
40
 #define _SET_MODE(IO,M)       gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)
40
 #define _SET_MODE(IO,M)       gpio_set_mode(PIN_MAP[IO].gpio_device, PIN_MAP[IO].gpio_bit, M)

+ 13
- 12
Marlin/src/HAL/HAL_STM32F4/fastio_STM32F4.h View File

31
 
31
 
32
 #define _BV(b) (1 << (b))
32
 #define _BV(b) (1 << (b))
33
 
33
 
34
-#define READ(IO)              digitalRead(IO)
35
-#define WRITE(IO, v)          digitalWrite(IO,v)
36
-#define TOGGLE(IO)            do{ _SET_OUTPUT(IO); digitalWrite(IO,!digitalRead(IO)); }while(0)
37
-#define WRITE_VAR(IO, v)      digitalWrite(IO,v)
34
+#define READ(IO)                digitalRead(IO)
35
+#define WRITE(IO,V)             digitalWrite(IO,V)
36
+#define WRITE_VAR(IO,V)         WRITE(IO,V)
38
 
37
 
39
 #define _GET_MODE(IO)
38
 #define _GET_MODE(IO)
40
-#define _SET_MODE(IO,M)       pinMode(IO, M)
41
-#define _SET_OUTPUT(IO)       pinMode(IO, OUTPUT)                               /*!< Output Push Pull Mode & GPIO_NOPULL   */
39
+#define _SET_MODE(IO,M)         pinMode(IO, M)
40
+#define _SET_OUTPUT(IO)         pinMode(IO, OUTPUT)                               /*!< Output Push Pull Mode & GPIO_NOPULL   */
42
 
41
 
43
-#define SET_INPUT(IO)         _SET_MODE(IO, INPUT)                              /*!< Input Floating Mode                   */
44
-#define SET_INPUT_PULLUP(IO)  _SET_MODE(IO, INPUT_PULLUP)                       /*!< Input with Pull-up activation         */
45
-#define SET_INPUT_PULLDOW(IO) _SET_MODE(IO, INPUT_PULLDOWN)                     /*!< Input with Pull-down activation       */
46
-#define SET_OUTPUT(IO)        do{ _SET_OUTPUT(IO); WRITE(IO, LOW); }while(0)
42
+#define OUT_WRITE(IO,V)         do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
43
+
44
+#define SET_INPUT(IO)           _SET_MODE(IO, INPUT)                              /*!< Input Floating Mode                   */
45
+#define SET_INPUT_PULLUP(IO)    _SET_MODE(IO, INPUT_PULLUP)                       /*!< Input with Pull-up activation         */
46
+#define SET_INPUT_PULLDOWN(IO)  _SET_MODE(IO, INPUT_PULLDOWN)                     /*!< Input with Pull-down activation       */
47
+#define SET_OUTPUT(IO)          OUT_WRITE(IO, LOW)
48
+
49
+#define TOGGLE(IO)              OUT_WRITE(IO, !READ(IO))
47
 
50
 
48
 #define GET_INPUT(IO)
51
 #define GET_INPUT(IO)
49
 #define GET_OUTPUT(IO)
52
 #define GET_OUTPUT(IO)
50
 #define GET_TIMER(IO)
53
 #define GET_TIMER(IO)
51
 
54
 
52
-#define OUT_WRITE(IO, v) { _SET_OUTPUT(IO); WRITE(IO, v); }
53
-
54
 #define PORTA 0
55
 #define PORTA 0
55
 #define PORTB 1
56
 #define PORTB 1
56
 #define PORTC 2
57
 #define PORTC 2

+ 13
- 12
Marlin/src/HAL/HAL_STM32F7/fastio_STM32F7.h View File

31
 
31
 
32
 #define _BV(b) (1 << (b))
32
 #define _BV(b) (1 << (b))
33
 
33
 
34
-#define READ(IO)              digitalRead(IO)
35
-#define WRITE(IO, v)          digitalWrite(IO,v)
36
-#define TOGGLE(IO)            do{ _SET_OUTPUT(IO); digitalWrite(IO,!digitalRead(IO)); }while(0)
37
-#define WRITE_VAR(IO, v)      digitalWrite(IO,v)
34
+#define READ(IO)                digitalRead(IO)
35
+#define WRITE(IO,V)             digitalWrite(IO,V)
36
+#define WRITE_VAR(IO,V)         WRITE(IO,V)
38
 
37
 
39
 #define _GET_MODE(IO)
38
 #define _GET_MODE(IO)
40
-#define _SET_MODE(IO,M)       pinMode(IO, M)
41
-#define _SET_OUTPUT(IO)       pinMode(IO, OUTPUT)                               /*!< Output Push Pull Mode & GPIO_NOPULL   */
39
+#define _SET_MODE(IO,M)         pinMode(IO, M)
40
+#define _SET_OUTPUT(IO)         pinMode(IO, OUTPUT)                               /*!< Output Push Pull Mode & GPIO_NOPULL   */
42
 
41
 
43
-#define SET_INPUT(IO)         _SET_MODE(IO, INPUT)                              /*!< Input Floating Mode                   */
44
-#define SET_INPUT_PULLUP(IO)  _SET_MODE(IO, INPUT_PULLUP)                       /*!< Input with Pull-up activation         */
45
-#define SET_INPUT_PULLDOW(IO) _SET_MODE(IO, INPUT_PULLDOWN)                     /*!< Input with Pull-down activation       */
46
-#define SET_OUTPUT(IO)        do{ _SET_OUTPUT(IO); WRITE(IO, LOW); }while(0)
42
+#define OUT_WRITE(IO,V)         do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
43
+
44
+#define SET_INPUT(IO)           _SET_MODE(IO, INPUT)                              /*!< Input Floating Mode                   */
45
+#define SET_INPUT_PULLUP(IO)    _SET_MODE(IO, INPUT_PULLUP)                       /*!< Input with Pull-up activation         */
46
+#define SET_INPUT_PULLDOWN(IO)  _SET_MODE(IO, INPUT_PULLDOWN)                     /*!< Input with Pull-down activation       */
47
+#define SET_OUTPUT(IO)          OUT_WRITE(IO, LOW)
48
+
49
+#define TOGGLE(IO)              OUT_WRITE(IO, !READ(IO))
47
 
50
 
48
 #define GET_INPUT(IO)
51
 #define GET_INPUT(IO)
49
 #define GET_OUTPUT(IO)
52
 #define GET_OUTPUT(IO)
50
 #define GET_TIMER(IO)
53
 #define GET_TIMER(IO)
51
 
54
 
52
-#define OUT_WRITE(IO, v) { _SET_OUTPUT(IO); WRITE(IO, v); }
53
-
54
 #define PORTA 0
55
 #define PORTA 0
55
 #define PORTB 1
56
 #define PORTB 1
56
 #define PORTC 2
57
 #define PORTC 2

+ 1
- 1
Marlin/src/core/macros.h View File

99
 
99
 
100
 // Macros for bit masks
100
 // Macros for bit masks
101
 #undef _BV
101
 #undef _BV
102
-#define _BV(b) (1<<(b))
102
+#define _BV(b) (1 << (b))
103
 #define TEST(n,b) !!((n)&_BV(b))
103
 #define TEST(n,b) !!((n)&_BV(b))
104
 #define SBI(n,b) (n |= _BV(b))
104
 #define SBI(n,b) (n |= _BV(b))
105
 #define CBI(n,b) (n &= ~_BV(b))
105
 #define CBI(n,b) (n &= ~_BV(b))

Loading…
Cancel
Save