33
33
#include "components/driver/include/driver/gpio.h"
34
34
#include "components/hal/include/hal/gpio_hal.h"
35
35
36
- #include "esp_log.h"
37
- #include "freertos/FreeRTOS.h"
38
- #include "freertos/task.h"
36
+ STATIC uint64_t never_reset_pins ;
37
+ STATIC uint64_t in_use ;
39
38
40
- STATIC uint32_t never_reset_pins [ 2 ];
41
- STATIC uint32_t in_use [ 2 ];
39
+ // 64-bit pin mask for a single bit
40
+ #define PIN_BIT ( pin_number ) (((uint64_t)1) << pin_number)
42
41
43
42
// Bit mask of all pins that should never ever be reset.
44
43
// Typically these are SPI flash and PSRAM control pins, and communication pins.
@@ -111,7 +110,7 @@ void never_reset_pin_number(gpio_num_t pin_number) {
111
110
if (pin_number == NO_PIN ) {
112
111
return ;
113
112
}
114
- never_reset_pins [ pin_number / 32 ] |= 1 << pin_number % 32 ;
113
+ never_reset_pins |= PIN_BIT ( pin_number ) ;
115
114
}
116
115
117
116
void common_hal_never_reset_pin (const mcu_pin_obj_t * pin ) {
@@ -127,7 +126,7 @@ MP_WEAK bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
127
126
128
127
STATIC void _reset_pin (gpio_num_t pin_number ) {
129
128
// Never ever reset pins used for flash, RAM, and basic communication.
130
- if (pin_mask_reset_forbidden & ((( uint64_t ) 1 ) << pin_number )) {
129
+ if (pin_mask_reset_forbidden & PIN_BIT ( pin_number )) {
131
130
return ;
132
131
}
133
132
@@ -152,8 +151,8 @@ void reset_pin_number(gpio_num_t pin_number) {
152
151
if (pin_number == NO_PIN ) {
153
152
return ;
154
153
}
155
- never_reset_pins [ pin_number / 32 ] &= ~( 1 << pin_number % 32 );
156
- in_use [ pin_number / 32 ] &= ~( 1 << pin_number % 32 );
154
+ never_reset_pins &= ~PIN_BIT ( pin_number );
155
+ in_use &= ~PIN_BIT ( pin_number );
157
156
158
157
_reset_pin (pin_number );
159
158
}
@@ -170,40 +169,34 @@ void common_hal_reset_pin(const mcu_pin_obj_t *pin) {
170
169
}
171
170
172
171
void reset_all_pins (void ) {
173
- ESP_LOGI ("Pin.c" , "reset_all_pins" );
174
172
for (uint8_t i = 0 ; i < GPIO_PIN_COUNT ; i ++ ) {
175
173
uint32_t iomux_address = GPIO_PIN_MUX_REG [i ];
176
174
if (iomux_address == 0 ||
177
- (never_reset_pins [ i / 32 ] & ( 1 << i % 32 )) != 0 ) {
175
+ (never_reset_pins & PIN_BIT ( i )) ) {
178
176
continue ;
179
177
}
180
- ESP_LOGI ("Pin.c" , "about to reset pin %d" , i );
181
- vTaskDelay (100 );
182
178
_reset_pin (i );
183
179
}
184
- in_use [0 ] = never_reset_pins [0 ];
185
- in_use [1 ] = never_reset_pins [1 ];
180
+ in_use = never_reset_pins ;
186
181
}
187
182
188
183
void claim_pin_number (gpio_num_t pin_number ) {
189
184
if (pin_number == NO_PIN ) {
190
185
return ;
191
186
}
192
- in_use [ pin_number / 32 ] |= ( 1 << ( pin_number % 32 ) );
187
+ in_use |= PIN_BIT ( pin_number );
193
188
}
194
189
195
190
void claim_pin (const mcu_pin_obj_t * pin ) {
196
- in_use [ pin -> number / 32 ] |= ( 1 << ( pin -> number % 32 ) );
191
+ claim_pin_number ( pin -> number );
197
192
}
198
193
199
194
void common_hal_mcu_pin_claim (const mcu_pin_obj_t * pin ) {
200
195
claim_pin (pin );
201
196
}
202
197
203
198
bool pin_number_is_free (gpio_num_t pin_number ) {
204
- uint8_t offset = pin_number / 32 ;
205
- uint32_t mask = 1 << (pin_number % 32 );
206
- return (in_use [offset ] & mask ) == 0 ;
199
+ return in_use & PIN_BIT (pin_number );
207
200
}
208
201
209
202
bool common_hal_mcu_pin_is_free (const mcu_pin_obj_t * pin ) {
0 commit comments