stm32ral/stm32f1/instances/gpio.rs
1#![allow(non_snake_case, non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3//! General purpose I/O
4//!
5//! Used by: stm32f100, stm32f101, stm32f102, stm32f103, stm32f107
6
7#[cfg(not(feature = "nosync"))]
8pub use crate::stm32f1::peripherals::gpio::Instance;
9pub use crate::stm32f1::peripherals::gpio::{RegisterBlock, ResetValues};
10pub use crate::stm32f1::peripherals::gpio::{BRR, BSRR, CRH, CRL, IDR, LCKR, ODR};
11
12/// Access functions for the GPIOA peripheral instance
13pub mod GPIOA {
14 use super::ResetValues;
15
16 #[cfg(not(feature = "nosync"))]
17 use super::Instance;
18
19 #[cfg(not(feature = "nosync"))]
20 const INSTANCE: Instance = Instance {
21 addr: 0x40010800,
22 _marker: ::core::marker::PhantomData,
23 };
24
25 /// Reset values for each field in GPIOA
26 pub const reset: ResetValues = ResetValues {
27 CRL: 0x44444444,
28 CRH: 0x44444444,
29 IDR: 0x00000000,
30 ODR: 0x00000000,
31 BSRR: 0x00000000,
32 BRR: 0x00000000,
33 LCKR: 0x00000000,
34 };
35
36 #[cfg(not(feature = "nosync"))]
37 #[allow(renamed_and_removed_lints)]
38 #[allow(private_no_mangle_statics)]
39 #[no_mangle]
40 static mut GPIOA_TAKEN: bool = false;
41
42 /// Safe access to GPIOA
43 ///
44 /// This function returns `Some(Instance)` if this instance is not
45 /// currently taken, and `None` if it is. This ensures that if you
46 /// do get `Some(Instance)`, you are ensured unique access to
47 /// the peripheral and there cannot be data races (unless other
48 /// code uses `unsafe`, of course). You can then pass the
49 /// `Instance` around to other functions as required. When you're
50 /// done with it, you can call `release(instance)` to return it.
51 ///
52 /// `Instance` itself dereferences to a `RegisterBlock`, which
53 /// provides access to the peripheral's registers.
54 #[cfg(not(feature = "nosync"))]
55 #[inline]
56 pub fn take() -> Option<Instance> {
57 external_cortex_m::interrupt::free(|_| unsafe {
58 if GPIOA_TAKEN {
59 None
60 } else {
61 GPIOA_TAKEN = true;
62 Some(INSTANCE)
63 }
64 })
65 }
66
67 /// Release exclusive access to GPIOA
68 ///
69 /// This function allows you to return an `Instance` so that it
70 /// is available to `take()` again. This function will panic if
71 /// you return a different `Instance` or if this instance is not
72 /// already taken.
73 #[cfg(not(feature = "nosync"))]
74 #[inline]
75 pub fn release(inst: Instance) {
76 external_cortex_m::interrupt::free(|_| unsafe {
77 if GPIOA_TAKEN && inst.addr == INSTANCE.addr {
78 GPIOA_TAKEN = false;
79 } else {
80 panic!("Released a peripheral which was not taken");
81 }
82 });
83 }
84
85 /// Unsafely steal GPIOA
86 ///
87 /// This function is similar to take() but forcibly takes the
88 /// Instance, marking it as taken irregardless of its previous
89 /// state.
90 #[cfg(not(feature = "nosync"))]
91 #[inline]
92 pub unsafe fn steal() -> Instance {
93 GPIOA_TAKEN = true;
94 INSTANCE
95 }
96}
97
98/// Raw pointer to GPIOA
99///
100/// Dereferencing this is unsafe because you are not ensured unique
101/// access to the peripheral, so you may encounter data races with
102/// other users of this peripheral. It is up to you to ensure you
103/// will not cause data races.
104///
105/// This constant is provided for ease of use in unsafe code: you can
106/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
107pub const GPIOA: *const RegisterBlock = 0x40010800 as *const _;
108
109/// Access functions for the GPIOB peripheral instance
110pub mod GPIOB {
111 use super::ResetValues;
112
113 #[cfg(not(feature = "nosync"))]
114 use super::Instance;
115
116 #[cfg(not(feature = "nosync"))]
117 const INSTANCE: Instance = Instance {
118 addr: 0x40010c00,
119 _marker: ::core::marker::PhantomData,
120 };
121
122 /// Reset values for each field in GPIOB
123 pub const reset: ResetValues = ResetValues {
124 CRL: 0x44444444,
125 CRH: 0x44444444,
126 IDR: 0x00000000,
127 ODR: 0x00000000,
128 BSRR: 0x00000000,
129 BRR: 0x00000000,
130 LCKR: 0x00000000,
131 };
132
133 #[cfg(not(feature = "nosync"))]
134 #[allow(renamed_and_removed_lints)]
135 #[allow(private_no_mangle_statics)]
136 #[no_mangle]
137 static mut GPIOB_TAKEN: bool = false;
138
139 /// Safe access to GPIOB
140 ///
141 /// This function returns `Some(Instance)` if this instance is not
142 /// currently taken, and `None` if it is. This ensures that if you
143 /// do get `Some(Instance)`, you are ensured unique access to
144 /// the peripheral and there cannot be data races (unless other
145 /// code uses `unsafe`, of course). You can then pass the
146 /// `Instance` around to other functions as required. When you're
147 /// done with it, you can call `release(instance)` to return it.
148 ///
149 /// `Instance` itself dereferences to a `RegisterBlock`, which
150 /// provides access to the peripheral's registers.
151 #[cfg(not(feature = "nosync"))]
152 #[inline]
153 pub fn take() -> Option<Instance> {
154 external_cortex_m::interrupt::free(|_| unsafe {
155 if GPIOB_TAKEN {
156 None
157 } else {
158 GPIOB_TAKEN = true;
159 Some(INSTANCE)
160 }
161 })
162 }
163
164 /// Release exclusive access to GPIOB
165 ///
166 /// This function allows you to return an `Instance` so that it
167 /// is available to `take()` again. This function will panic if
168 /// you return a different `Instance` or if this instance is not
169 /// already taken.
170 #[cfg(not(feature = "nosync"))]
171 #[inline]
172 pub fn release(inst: Instance) {
173 external_cortex_m::interrupt::free(|_| unsafe {
174 if GPIOB_TAKEN && inst.addr == INSTANCE.addr {
175 GPIOB_TAKEN = false;
176 } else {
177 panic!("Released a peripheral which was not taken");
178 }
179 });
180 }
181
182 /// Unsafely steal GPIOB
183 ///
184 /// This function is similar to take() but forcibly takes the
185 /// Instance, marking it as taken irregardless of its previous
186 /// state.
187 #[cfg(not(feature = "nosync"))]
188 #[inline]
189 pub unsafe fn steal() -> Instance {
190 GPIOB_TAKEN = true;
191 INSTANCE
192 }
193}
194
195/// Raw pointer to GPIOB
196///
197/// Dereferencing this is unsafe because you are not ensured unique
198/// access to the peripheral, so you may encounter data races with
199/// other users of this peripheral. It is up to you to ensure you
200/// will not cause data races.
201///
202/// This constant is provided for ease of use in unsafe code: you can
203/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
204pub const GPIOB: *const RegisterBlock = 0x40010c00 as *const _;
205
206/// Access functions for the GPIOC peripheral instance
207pub mod GPIOC {
208 use super::ResetValues;
209
210 #[cfg(not(feature = "nosync"))]
211 use super::Instance;
212
213 #[cfg(not(feature = "nosync"))]
214 const INSTANCE: Instance = Instance {
215 addr: 0x40011000,
216 _marker: ::core::marker::PhantomData,
217 };
218
219 /// Reset values for each field in GPIOC
220 pub const reset: ResetValues = ResetValues {
221 CRL: 0x44444444,
222 CRH: 0x44444444,
223 IDR: 0x00000000,
224 ODR: 0x00000000,
225 BSRR: 0x00000000,
226 BRR: 0x00000000,
227 LCKR: 0x00000000,
228 };
229
230 #[cfg(not(feature = "nosync"))]
231 #[allow(renamed_and_removed_lints)]
232 #[allow(private_no_mangle_statics)]
233 #[no_mangle]
234 static mut GPIOC_TAKEN: bool = false;
235
236 /// Safe access to GPIOC
237 ///
238 /// This function returns `Some(Instance)` if this instance is not
239 /// currently taken, and `None` if it is. This ensures that if you
240 /// do get `Some(Instance)`, you are ensured unique access to
241 /// the peripheral and there cannot be data races (unless other
242 /// code uses `unsafe`, of course). You can then pass the
243 /// `Instance` around to other functions as required. When you're
244 /// done with it, you can call `release(instance)` to return it.
245 ///
246 /// `Instance` itself dereferences to a `RegisterBlock`, which
247 /// provides access to the peripheral's registers.
248 #[cfg(not(feature = "nosync"))]
249 #[inline]
250 pub fn take() -> Option<Instance> {
251 external_cortex_m::interrupt::free(|_| unsafe {
252 if GPIOC_TAKEN {
253 None
254 } else {
255 GPIOC_TAKEN = true;
256 Some(INSTANCE)
257 }
258 })
259 }
260
261 /// Release exclusive access to GPIOC
262 ///
263 /// This function allows you to return an `Instance` so that it
264 /// is available to `take()` again. This function will panic if
265 /// you return a different `Instance` or if this instance is not
266 /// already taken.
267 #[cfg(not(feature = "nosync"))]
268 #[inline]
269 pub fn release(inst: Instance) {
270 external_cortex_m::interrupt::free(|_| unsafe {
271 if GPIOC_TAKEN && inst.addr == INSTANCE.addr {
272 GPIOC_TAKEN = false;
273 } else {
274 panic!("Released a peripheral which was not taken");
275 }
276 });
277 }
278
279 /// Unsafely steal GPIOC
280 ///
281 /// This function is similar to take() but forcibly takes the
282 /// Instance, marking it as taken irregardless of its previous
283 /// state.
284 #[cfg(not(feature = "nosync"))]
285 #[inline]
286 pub unsafe fn steal() -> Instance {
287 GPIOC_TAKEN = true;
288 INSTANCE
289 }
290}
291
292/// Raw pointer to GPIOC
293///
294/// Dereferencing this is unsafe because you are not ensured unique
295/// access to the peripheral, so you may encounter data races with
296/// other users of this peripheral. It is up to you to ensure you
297/// will not cause data races.
298///
299/// This constant is provided for ease of use in unsafe code: you can
300/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
301pub const GPIOC: *const RegisterBlock = 0x40011000 as *const _;
302
303/// Access functions for the GPIOD peripheral instance
304pub mod GPIOD {
305 use super::ResetValues;
306
307 #[cfg(not(feature = "nosync"))]
308 use super::Instance;
309
310 #[cfg(not(feature = "nosync"))]
311 const INSTANCE: Instance = Instance {
312 addr: 0x40011400,
313 _marker: ::core::marker::PhantomData,
314 };
315
316 /// Reset values for each field in GPIOD
317 pub const reset: ResetValues = ResetValues {
318 CRL: 0x44444444,
319 CRH: 0x44444444,
320 IDR: 0x00000000,
321 ODR: 0x00000000,
322 BSRR: 0x00000000,
323 BRR: 0x00000000,
324 LCKR: 0x00000000,
325 };
326
327 #[cfg(not(feature = "nosync"))]
328 #[allow(renamed_and_removed_lints)]
329 #[allow(private_no_mangle_statics)]
330 #[no_mangle]
331 static mut GPIOD_TAKEN: bool = false;
332
333 /// Safe access to GPIOD
334 ///
335 /// This function returns `Some(Instance)` if this instance is not
336 /// currently taken, and `None` if it is. This ensures that if you
337 /// do get `Some(Instance)`, you are ensured unique access to
338 /// the peripheral and there cannot be data races (unless other
339 /// code uses `unsafe`, of course). You can then pass the
340 /// `Instance` around to other functions as required. When you're
341 /// done with it, you can call `release(instance)` to return it.
342 ///
343 /// `Instance` itself dereferences to a `RegisterBlock`, which
344 /// provides access to the peripheral's registers.
345 #[cfg(not(feature = "nosync"))]
346 #[inline]
347 pub fn take() -> Option<Instance> {
348 external_cortex_m::interrupt::free(|_| unsafe {
349 if GPIOD_TAKEN {
350 None
351 } else {
352 GPIOD_TAKEN = true;
353 Some(INSTANCE)
354 }
355 })
356 }
357
358 /// Release exclusive access to GPIOD
359 ///
360 /// This function allows you to return an `Instance` so that it
361 /// is available to `take()` again. This function will panic if
362 /// you return a different `Instance` or if this instance is not
363 /// already taken.
364 #[cfg(not(feature = "nosync"))]
365 #[inline]
366 pub fn release(inst: Instance) {
367 external_cortex_m::interrupt::free(|_| unsafe {
368 if GPIOD_TAKEN && inst.addr == INSTANCE.addr {
369 GPIOD_TAKEN = false;
370 } else {
371 panic!("Released a peripheral which was not taken");
372 }
373 });
374 }
375
376 /// Unsafely steal GPIOD
377 ///
378 /// This function is similar to take() but forcibly takes the
379 /// Instance, marking it as taken irregardless of its previous
380 /// state.
381 #[cfg(not(feature = "nosync"))]
382 #[inline]
383 pub unsafe fn steal() -> Instance {
384 GPIOD_TAKEN = true;
385 INSTANCE
386 }
387}
388
389/// Raw pointer to GPIOD
390///
391/// Dereferencing this is unsafe because you are not ensured unique
392/// access to the peripheral, so you may encounter data races with
393/// other users of this peripheral. It is up to you to ensure you
394/// will not cause data races.
395///
396/// This constant is provided for ease of use in unsafe code: you can
397/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
398pub const GPIOD: *const RegisterBlock = 0x40011400 as *const _;
399
400/// Access functions for the GPIOE peripheral instance
401pub mod GPIOE {
402 use super::ResetValues;
403
404 #[cfg(not(feature = "nosync"))]
405 use super::Instance;
406
407 #[cfg(not(feature = "nosync"))]
408 const INSTANCE: Instance = Instance {
409 addr: 0x40011800,
410 _marker: ::core::marker::PhantomData,
411 };
412
413 /// Reset values for each field in GPIOE
414 pub const reset: ResetValues = ResetValues {
415 CRL: 0x44444444,
416 CRH: 0x44444444,
417 IDR: 0x00000000,
418 ODR: 0x00000000,
419 BSRR: 0x00000000,
420 BRR: 0x00000000,
421 LCKR: 0x00000000,
422 };
423
424 #[cfg(not(feature = "nosync"))]
425 #[allow(renamed_and_removed_lints)]
426 #[allow(private_no_mangle_statics)]
427 #[no_mangle]
428 static mut GPIOE_TAKEN: bool = false;
429
430 /// Safe access to GPIOE
431 ///
432 /// This function returns `Some(Instance)` if this instance is not
433 /// currently taken, and `None` if it is. This ensures that if you
434 /// do get `Some(Instance)`, you are ensured unique access to
435 /// the peripheral and there cannot be data races (unless other
436 /// code uses `unsafe`, of course). You can then pass the
437 /// `Instance` around to other functions as required. When you're
438 /// done with it, you can call `release(instance)` to return it.
439 ///
440 /// `Instance` itself dereferences to a `RegisterBlock`, which
441 /// provides access to the peripheral's registers.
442 #[cfg(not(feature = "nosync"))]
443 #[inline]
444 pub fn take() -> Option<Instance> {
445 external_cortex_m::interrupt::free(|_| unsafe {
446 if GPIOE_TAKEN {
447 None
448 } else {
449 GPIOE_TAKEN = true;
450 Some(INSTANCE)
451 }
452 })
453 }
454
455 /// Release exclusive access to GPIOE
456 ///
457 /// This function allows you to return an `Instance` so that it
458 /// is available to `take()` again. This function will panic if
459 /// you return a different `Instance` or if this instance is not
460 /// already taken.
461 #[cfg(not(feature = "nosync"))]
462 #[inline]
463 pub fn release(inst: Instance) {
464 external_cortex_m::interrupt::free(|_| unsafe {
465 if GPIOE_TAKEN && inst.addr == INSTANCE.addr {
466 GPIOE_TAKEN = false;
467 } else {
468 panic!("Released a peripheral which was not taken");
469 }
470 });
471 }
472
473 /// Unsafely steal GPIOE
474 ///
475 /// This function is similar to take() but forcibly takes the
476 /// Instance, marking it as taken irregardless of its previous
477 /// state.
478 #[cfg(not(feature = "nosync"))]
479 #[inline]
480 pub unsafe fn steal() -> Instance {
481 GPIOE_TAKEN = true;
482 INSTANCE
483 }
484}
485
486/// Raw pointer to GPIOE
487///
488/// Dereferencing this is unsafe because you are not ensured unique
489/// access to the peripheral, so you may encounter data races with
490/// other users of this peripheral. It is up to you to ensure you
491/// will not cause data races.
492///
493/// This constant is provided for ease of use in unsafe code: you can
494/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
495pub const GPIOE: *const RegisterBlock = 0x40011800 as *const _;
496
497/// Access functions for the GPIOF peripheral instance
498pub mod GPIOF {
499 use super::ResetValues;
500
501 #[cfg(not(feature = "nosync"))]
502 use super::Instance;
503
504 #[cfg(not(feature = "nosync"))]
505 const INSTANCE: Instance = Instance {
506 addr: 0x40011c00,
507 _marker: ::core::marker::PhantomData,
508 };
509
510 /// Reset values for each field in GPIOF
511 pub const reset: ResetValues = ResetValues {
512 CRL: 0x44444444,
513 CRH: 0x44444444,
514 IDR: 0x00000000,
515 ODR: 0x00000000,
516 BSRR: 0x00000000,
517 BRR: 0x00000000,
518 LCKR: 0x00000000,
519 };
520
521 #[cfg(not(feature = "nosync"))]
522 #[allow(renamed_and_removed_lints)]
523 #[allow(private_no_mangle_statics)]
524 #[no_mangle]
525 static mut GPIOF_TAKEN: bool = false;
526
527 /// Safe access to GPIOF
528 ///
529 /// This function returns `Some(Instance)` if this instance is not
530 /// currently taken, and `None` if it is. This ensures that if you
531 /// do get `Some(Instance)`, you are ensured unique access to
532 /// the peripheral and there cannot be data races (unless other
533 /// code uses `unsafe`, of course). You can then pass the
534 /// `Instance` around to other functions as required. When you're
535 /// done with it, you can call `release(instance)` to return it.
536 ///
537 /// `Instance` itself dereferences to a `RegisterBlock`, which
538 /// provides access to the peripheral's registers.
539 #[cfg(not(feature = "nosync"))]
540 #[inline]
541 pub fn take() -> Option<Instance> {
542 external_cortex_m::interrupt::free(|_| unsafe {
543 if GPIOF_TAKEN {
544 None
545 } else {
546 GPIOF_TAKEN = true;
547 Some(INSTANCE)
548 }
549 })
550 }
551
552 /// Release exclusive access to GPIOF
553 ///
554 /// This function allows you to return an `Instance` so that it
555 /// is available to `take()` again. This function will panic if
556 /// you return a different `Instance` or if this instance is not
557 /// already taken.
558 #[cfg(not(feature = "nosync"))]
559 #[inline]
560 pub fn release(inst: Instance) {
561 external_cortex_m::interrupt::free(|_| unsafe {
562 if GPIOF_TAKEN && inst.addr == INSTANCE.addr {
563 GPIOF_TAKEN = false;
564 } else {
565 panic!("Released a peripheral which was not taken");
566 }
567 });
568 }
569
570 /// Unsafely steal GPIOF
571 ///
572 /// This function is similar to take() but forcibly takes the
573 /// Instance, marking it as taken irregardless of its previous
574 /// state.
575 #[cfg(not(feature = "nosync"))]
576 #[inline]
577 pub unsafe fn steal() -> Instance {
578 GPIOF_TAKEN = true;
579 INSTANCE
580 }
581}
582
583/// Raw pointer to GPIOF
584///
585/// Dereferencing this is unsafe because you are not ensured unique
586/// access to the peripheral, so you may encounter data races with
587/// other users of this peripheral. It is up to you to ensure you
588/// will not cause data races.
589///
590/// This constant is provided for ease of use in unsafe code: you can
591/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
592pub const GPIOF: *const RegisterBlock = 0x40011c00 as *const _;
593
594/// Access functions for the GPIOG peripheral instance
595pub mod GPIOG {
596 use super::ResetValues;
597
598 #[cfg(not(feature = "nosync"))]
599 use super::Instance;
600
601 #[cfg(not(feature = "nosync"))]
602 const INSTANCE: Instance = Instance {
603 addr: 0x40012000,
604 _marker: ::core::marker::PhantomData,
605 };
606
607 /// Reset values for each field in GPIOG
608 pub const reset: ResetValues = ResetValues {
609 CRL: 0x44444444,
610 CRH: 0x44444444,
611 IDR: 0x00000000,
612 ODR: 0x00000000,
613 BSRR: 0x00000000,
614 BRR: 0x00000000,
615 LCKR: 0x00000000,
616 };
617
618 #[cfg(not(feature = "nosync"))]
619 #[allow(renamed_and_removed_lints)]
620 #[allow(private_no_mangle_statics)]
621 #[no_mangle]
622 static mut GPIOG_TAKEN: bool = false;
623
624 /// Safe access to GPIOG
625 ///
626 /// This function returns `Some(Instance)` if this instance is not
627 /// currently taken, and `None` if it is. This ensures that if you
628 /// do get `Some(Instance)`, you are ensured unique access to
629 /// the peripheral and there cannot be data races (unless other
630 /// code uses `unsafe`, of course). You can then pass the
631 /// `Instance` around to other functions as required. When you're
632 /// done with it, you can call `release(instance)` to return it.
633 ///
634 /// `Instance` itself dereferences to a `RegisterBlock`, which
635 /// provides access to the peripheral's registers.
636 #[cfg(not(feature = "nosync"))]
637 #[inline]
638 pub fn take() -> Option<Instance> {
639 external_cortex_m::interrupt::free(|_| unsafe {
640 if GPIOG_TAKEN {
641 None
642 } else {
643 GPIOG_TAKEN = true;
644 Some(INSTANCE)
645 }
646 })
647 }
648
649 /// Release exclusive access to GPIOG
650 ///
651 /// This function allows you to return an `Instance` so that it
652 /// is available to `take()` again. This function will panic if
653 /// you return a different `Instance` or if this instance is not
654 /// already taken.
655 #[cfg(not(feature = "nosync"))]
656 #[inline]
657 pub fn release(inst: Instance) {
658 external_cortex_m::interrupt::free(|_| unsafe {
659 if GPIOG_TAKEN && inst.addr == INSTANCE.addr {
660 GPIOG_TAKEN = false;
661 } else {
662 panic!("Released a peripheral which was not taken");
663 }
664 });
665 }
666
667 /// Unsafely steal GPIOG
668 ///
669 /// This function is similar to take() but forcibly takes the
670 /// Instance, marking it as taken irregardless of its previous
671 /// state.
672 #[cfg(not(feature = "nosync"))]
673 #[inline]
674 pub unsafe fn steal() -> Instance {
675 GPIOG_TAKEN = true;
676 INSTANCE
677 }
678}
679
680/// Raw pointer to GPIOG
681///
682/// Dereferencing this is unsafe because you are not ensured unique
683/// access to the peripheral, so you may encounter data races with
684/// other users of this peripheral. It is up to you to ensure you
685/// will not cause data races.
686///
687/// This constant is provided for ease of use in unsafe code: you can
688/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
689pub const GPIOG: *const RegisterBlock = 0x40012000 as *const _;