@@ -170,23 +170,55 @@ uint8_t get_pin_id(uint16_t pin)
170
170
void stm32_interrupt_enable (GPIO_TypeDef * port , uint16_t pin , void (* callback )(void ), uint32_t mode )
171
171
{
172
172
GPIO_InitTypeDef GPIO_InitStruct ;
173
- uint32_t pull ;
174
173
uint8_t id = get_pin_id (pin );
174
+
175
+ #ifdef STM32F1xx
176
+ uint8_t position ;
177
+ uint32_t CRxRegOffset = 0 ;
178
+ uint32_t ODRRegOffset = 0 ;
179
+ volatile uint32_t * CRxRegister ;
180
+ const uint32_t ConfigMask = 0x00000008 ; //MODE0 == 0x0 && CNF0 == 0x2
181
+ #else
182
+ uint32_t pull ;
183
+ #endif /* STM32F1xx */
184
+
175
185
// GPIO pin configuration
176
186
GPIO_InitStruct .Pin = pin ;
177
187
GPIO_InitStruct .Mode = mode ;
178
188
179
189
//read the pull mode directly in the register as no function exists to get it.
180
190
//Do it in case the user already defines the IO through the digital io
181
191
//interface
192
+ #ifndef STM32F1xx
182
193
pull = port -> PUPDR ;
183
194
#ifdef GPIO_PUPDR_PUPD0
184
195
pull &=(GPIO_PUPDR_PUPD0 <<(id * 2 ));
185
196
GPIO_InitStruct .Pull = (GPIO_PUPDR_PUPD0 & (pull >>(id * 2 )));
186
197
#else
187
198
pull &=(GPIO_PUPDR_PUPDR0 <<(id * 2 ));
188
199
GPIO_InitStruct .Pull = (GPIO_PUPDR_PUPDR0 & (pull >>(id * 2 )));
189
- #endif
200
+ #endif /* GPIO_PUPDR_PUPD0 */
201
+ #else
202
+ CRxRegister = (pin < GPIO_PIN_8 ) ? & port -> CRL : & port -> CRH ;
203
+
204
+ for (position = 0 ; position < 16 ; position ++ ) {
205
+ if (pin == (0x0001 << position )) {
206
+ CRxRegOffset = (pin < GPIO_PIN_8 ) ? (position << 2 ) : ((position - 8 ) << 2 );
207
+ ODRRegOffset = position ;
208
+ }
209
+ }
210
+
211
+ if ((* CRxRegister & ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0 ) << CRxRegOffset )) == (ConfigMask << CRxRegOffset )) {
212
+ if ((port -> ODR & (GPIO_ODR_ODR0 << ODRRegOffset )) == (GPIO_ODR_ODR0 << ODRRegOffset )) {
213
+ GPIO_InitStruct .Pull = GPIO_PULLUP ;
214
+ } else {
215
+ GPIO_InitStruct .Pull = GPIO_PULLDOWN ;
216
+ }
217
+ } else {
218
+ GPIO_InitStruct .Pull = GPIO_NOPULL ;
219
+ }
220
+ #endif /* STM32F1xx */
221
+
190
222
GPIO_InitStruct .Speed = GPIO_SPEED_FREQ_HIGH ;
191
223
192
224
HAL_GPIO_Init (port , & GPIO_InitStruct );
0 commit comments