stm32ral/stm32f0/stm32f0x0/gpio.rs
1#![allow(non_snake_case, non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3//! General-purpose I/Os
4
5#[cfg(not(feature = "nosync"))]
6pub use crate::stm32f0::peripherals::gpio::Instance;
7pub use crate::stm32f0::peripherals::gpio::{RegisterBlock, ResetValues};
8pub use crate::stm32f0::peripherals::gpio::{
9 AFRH, AFRL, BRR, BSRR, IDR, LCKR, MODER, ODR, OSPEEDR, OTYPER, PUPDR,
10};
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: 0x48000000,
22 _marker: ::core::marker::PhantomData,
23 };
24
25 /// Reset values for each field in GPIOA
26 pub const reset: ResetValues = ResetValues {
27 MODER: 0x28000000,
28 OTYPER: 0x00000000,
29 OSPEEDR: 0x00000000,
30 PUPDR: 0x24000000,
31 IDR: 0x00000000,
32 ODR: 0x00000000,
33 BSRR: 0x00000000,
34 LCKR: 0x00000000,
35 AFRL: 0x00000000,
36 AFRH: 0x00000000,
37 BRR: 0x00000000,
38 };
39
40 #[cfg(not(feature = "nosync"))]
41 #[allow(renamed_and_removed_lints)]
42 #[allow(private_no_mangle_statics)]
43 #[no_mangle]
44 static mut GPIOA_TAKEN: bool = false;
45
46 /// Safe access to GPIOA
47 ///
48 /// This function returns `Some(Instance)` if this instance is not
49 /// currently taken, and `None` if it is. This ensures that if you
50 /// do get `Some(Instance)`, you are ensured unique access to
51 /// the peripheral and there cannot be data races (unless other
52 /// code uses `unsafe`, of course). You can then pass the
53 /// `Instance` around to other functions as required. When you're
54 /// done with it, you can call `release(instance)` to return it.
55 ///
56 /// `Instance` itself dereferences to a `RegisterBlock`, which
57 /// provides access to the peripheral's registers.
58 #[cfg(not(feature = "nosync"))]
59 #[inline]
60 pub fn take() -> Option<Instance> {
61 external_cortex_m::interrupt::free(|_| unsafe {
62 if GPIOA_TAKEN {
63 None
64 } else {
65 GPIOA_TAKEN = true;
66 Some(INSTANCE)
67 }
68 })
69 }
70
71 /// Release exclusive access to GPIOA
72 ///
73 /// This function allows you to return an `Instance` so that it
74 /// is available to `take()` again. This function will panic if
75 /// you return a different `Instance` or if this instance is not
76 /// already taken.
77 #[cfg(not(feature = "nosync"))]
78 #[inline]
79 pub fn release(inst: Instance) {
80 external_cortex_m::interrupt::free(|_| unsafe {
81 if GPIOA_TAKEN && inst.addr == INSTANCE.addr {
82 GPIOA_TAKEN = false;
83 } else {
84 panic!("Released a peripheral which was not taken");
85 }
86 });
87 }
88
89 /// Unsafely steal GPIOA
90 ///
91 /// This function is similar to take() but forcibly takes the
92 /// Instance, marking it as taken irregardless of its previous
93 /// state.
94 #[cfg(not(feature = "nosync"))]
95 #[inline]
96 pub unsafe fn steal() -> Instance {
97 GPIOA_TAKEN = true;
98 INSTANCE
99 }
100}
101
102/// Raw pointer to GPIOA
103///
104/// Dereferencing this is unsafe because you are not ensured unique
105/// access to the peripheral, so you may encounter data races with
106/// other users of this peripheral. It is up to you to ensure you
107/// will not cause data races.
108///
109/// This constant is provided for ease of use in unsafe code: you can
110/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
111pub const GPIOA: *const RegisterBlock = 0x48000000 as *const _;
112
113/// Access functions for the GPIOB peripheral instance
114pub mod GPIOB {
115 use super::ResetValues;
116
117 #[cfg(not(feature = "nosync"))]
118 use super::Instance;
119
120 #[cfg(not(feature = "nosync"))]
121 const INSTANCE: Instance = Instance {
122 addr: 0x48000400,
123 _marker: ::core::marker::PhantomData,
124 };
125
126 /// Reset values for each field in GPIOB
127 pub const reset: ResetValues = ResetValues {
128 MODER: 0x00000000,
129 OTYPER: 0x00000000,
130 OSPEEDR: 0x00000000,
131 PUPDR: 0x00000000,
132 IDR: 0x00000000,
133 ODR: 0x00000000,
134 BSRR: 0x00000000,
135 LCKR: 0x00000000,
136 AFRL: 0x00000000,
137 AFRH: 0x00000000,
138 BRR: 0x00000000,
139 };
140
141 #[cfg(not(feature = "nosync"))]
142 #[allow(renamed_and_removed_lints)]
143 #[allow(private_no_mangle_statics)]
144 #[no_mangle]
145 static mut GPIOB_TAKEN: bool = false;
146
147 /// Safe access to GPIOB
148 ///
149 /// This function returns `Some(Instance)` if this instance is not
150 /// currently taken, and `None` if it is. This ensures that if you
151 /// do get `Some(Instance)`, you are ensured unique access to
152 /// the peripheral and there cannot be data races (unless other
153 /// code uses `unsafe`, of course). You can then pass the
154 /// `Instance` around to other functions as required. When you're
155 /// done with it, you can call `release(instance)` to return it.
156 ///
157 /// `Instance` itself dereferences to a `RegisterBlock`, which
158 /// provides access to the peripheral's registers.
159 #[cfg(not(feature = "nosync"))]
160 #[inline]
161 pub fn take() -> Option<Instance> {
162 external_cortex_m::interrupt::free(|_| unsafe {
163 if GPIOB_TAKEN {
164 None
165 } else {
166 GPIOB_TAKEN = true;
167 Some(INSTANCE)
168 }
169 })
170 }
171
172 /// Release exclusive access to GPIOB
173 ///
174 /// This function allows you to return an `Instance` so that it
175 /// is available to `take()` again. This function will panic if
176 /// you return a different `Instance` or if this instance is not
177 /// already taken.
178 #[cfg(not(feature = "nosync"))]
179 #[inline]
180 pub fn release(inst: Instance) {
181 external_cortex_m::interrupt::free(|_| unsafe {
182 if GPIOB_TAKEN && inst.addr == INSTANCE.addr {
183 GPIOB_TAKEN = false;
184 } else {
185 panic!("Released a peripheral which was not taken");
186 }
187 });
188 }
189
190 /// Unsafely steal GPIOB
191 ///
192 /// This function is similar to take() but forcibly takes the
193 /// Instance, marking it as taken irregardless of its previous
194 /// state.
195 #[cfg(not(feature = "nosync"))]
196 #[inline]
197 pub unsafe fn steal() -> Instance {
198 GPIOB_TAKEN = true;
199 INSTANCE
200 }
201}
202
203/// Raw pointer to GPIOB
204///
205/// Dereferencing this is unsafe because you are not ensured unique
206/// access to the peripheral, so you may encounter data races with
207/// other users of this peripheral. It is up to you to ensure you
208/// will not cause data races.
209///
210/// This constant is provided for ease of use in unsafe code: you can
211/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
212pub const GPIOB: *const RegisterBlock = 0x48000400 as *const _;
213
214/// Access functions for the GPIOC peripheral instance
215pub mod GPIOC {
216 use super::ResetValues;
217
218 #[cfg(not(feature = "nosync"))]
219 use super::Instance;
220
221 #[cfg(not(feature = "nosync"))]
222 const INSTANCE: Instance = Instance {
223 addr: 0x48000800,
224 _marker: ::core::marker::PhantomData,
225 };
226
227 /// Reset values for each field in GPIOC
228 pub const reset: ResetValues = ResetValues {
229 MODER: 0x00000000,
230 OTYPER: 0x00000000,
231 OSPEEDR: 0x00000000,
232 PUPDR: 0x00000000,
233 IDR: 0x00000000,
234 ODR: 0x00000000,
235 BSRR: 0x00000000,
236 LCKR: 0x00000000,
237 AFRL: 0x00000000,
238 AFRH: 0x00000000,
239 BRR: 0x00000000,
240 };
241
242 #[cfg(not(feature = "nosync"))]
243 #[allow(renamed_and_removed_lints)]
244 #[allow(private_no_mangle_statics)]
245 #[no_mangle]
246 static mut GPIOC_TAKEN: bool = false;
247
248 /// Safe access to GPIOC
249 ///
250 /// This function returns `Some(Instance)` if this instance is not
251 /// currently taken, and `None` if it is. This ensures that if you
252 /// do get `Some(Instance)`, you are ensured unique access to
253 /// the peripheral and there cannot be data races (unless other
254 /// code uses `unsafe`, of course). You can then pass the
255 /// `Instance` around to other functions as required. When you're
256 /// done with it, you can call `release(instance)` to return it.
257 ///
258 /// `Instance` itself dereferences to a `RegisterBlock`, which
259 /// provides access to the peripheral's registers.
260 #[cfg(not(feature = "nosync"))]
261 #[inline]
262 pub fn take() -> Option<Instance> {
263 external_cortex_m::interrupt::free(|_| unsafe {
264 if GPIOC_TAKEN {
265 None
266 } else {
267 GPIOC_TAKEN = true;
268 Some(INSTANCE)
269 }
270 })
271 }
272
273 /// Release exclusive access to GPIOC
274 ///
275 /// This function allows you to return an `Instance` so that it
276 /// is available to `take()` again. This function will panic if
277 /// you return a different `Instance` or if this instance is not
278 /// already taken.
279 #[cfg(not(feature = "nosync"))]
280 #[inline]
281 pub fn release(inst: Instance) {
282 external_cortex_m::interrupt::free(|_| unsafe {
283 if GPIOC_TAKEN && inst.addr == INSTANCE.addr {
284 GPIOC_TAKEN = false;
285 } else {
286 panic!("Released a peripheral which was not taken");
287 }
288 });
289 }
290
291 /// Unsafely steal GPIOC
292 ///
293 /// This function is similar to take() but forcibly takes the
294 /// Instance, marking it as taken irregardless of its previous
295 /// state.
296 #[cfg(not(feature = "nosync"))]
297 #[inline]
298 pub unsafe fn steal() -> Instance {
299 GPIOC_TAKEN = true;
300 INSTANCE
301 }
302}
303
304/// Raw pointer to GPIOC
305///
306/// Dereferencing this is unsafe because you are not ensured unique
307/// access to the peripheral, so you may encounter data races with
308/// other users of this peripheral. It is up to you to ensure you
309/// will not cause data races.
310///
311/// This constant is provided for ease of use in unsafe code: you can
312/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
313pub const GPIOC: *const RegisterBlock = 0x48000800 as *const _;
314
315/// Access functions for the GPIOD peripheral instance
316pub mod GPIOD {
317 use super::ResetValues;
318
319 #[cfg(not(feature = "nosync"))]
320 use super::Instance;
321
322 #[cfg(not(feature = "nosync"))]
323 const INSTANCE: Instance = Instance {
324 addr: 0x48000c00,
325 _marker: ::core::marker::PhantomData,
326 };
327
328 /// Reset values for each field in GPIOD
329 pub const reset: ResetValues = ResetValues {
330 MODER: 0x00000000,
331 OTYPER: 0x00000000,
332 OSPEEDR: 0x00000000,
333 PUPDR: 0x00000000,
334 IDR: 0x00000000,
335 ODR: 0x00000000,
336 BSRR: 0x00000000,
337 LCKR: 0x00000000,
338 AFRL: 0x00000000,
339 AFRH: 0x00000000,
340 BRR: 0x00000000,
341 };
342
343 #[cfg(not(feature = "nosync"))]
344 #[allow(renamed_and_removed_lints)]
345 #[allow(private_no_mangle_statics)]
346 #[no_mangle]
347 static mut GPIOD_TAKEN: bool = false;
348
349 /// Safe access to GPIOD
350 ///
351 /// This function returns `Some(Instance)` if this instance is not
352 /// currently taken, and `None` if it is. This ensures that if you
353 /// do get `Some(Instance)`, you are ensured unique access to
354 /// the peripheral and there cannot be data races (unless other
355 /// code uses `unsafe`, of course). You can then pass the
356 /// `Instance` around to other functions as required. When you're
357 /// done with it, you can call `release(instance)` to return it.
358 ///
359 /// `Instance` itself dereferences to a `RegisterBlock`, which
360 /// provides access to the peripheral's registers.
361 #[cfg(not(feature = "nosync"))]
362 #[inline]
363 pub fn take() -> Option<Instance> {
364 external_cortex_m::interrupt::free(|_| unsafe {
365 if GPIOD_TAKEN {
366 None
367 } else {
368 GPIOD_TAKEN = true;
369 Some(INSTANCE)
370 }
371 })
372 }
373
374 /// Release exclusive access to GPIOD
375 ///
376 /// This function allows you to return an `Instance` so that it
377 /// is available to `take()` again. This function will panic if
378 /// you return a different `Instance` or if this instance is not
379 /// already taken.
380 #[cfg(not(feature = "nosync"))]
381 #[inline]
382 pub fn release(inst: Instance) {
383 external_cortex_m::interrupt::free(|_| unsafe {
384 if GPIOD_TAKEN && inst.addr == INSTANCE.addr {
385 GPIOD_TAKEN = false;
386 } else {
387 panic!("Released a peripheral which was not taken");
388 }
389 });
390 }
391
392 /// Unsafely steal GPIOD
393 ///
394 /// This function is similar to take() but forcibly takes the
395 /// Instance, marking it as taken irregardless of its previous
396 /// state.
397 #[cfg(not(feature = "nosync"))]
398 #[inline]
399 pub unsafe fn steal() -> Instance {
400 GPIOD_TAKEN = true;
401 INSTANCE
402 }
403}
404
405/// Raw pointer to GPIOD
406///
407/// Dereferencing this is unsafe because you are not ensured unique
408/// access to the peripheral, so you may encounter data races with
409/// other users of this peripheral. It is up to you to ensure you
410/// will not cause data races.
411///
412/// This constant is provided for ease of use in unsafe code: you can
413/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
414pub const GPIOD: *const RegisterBlock = 0x48000c00 as *const _;
415
416/// Access functions for the GPIOF peripheral instance
417pub mod GPIOF {
418 use super::ResetValues;
419
420 #[cfg(not(feature = "nosync"))]
421 use super::Instance;
422
423 #[cfg(not(feature = "nosync"))]
424 const INSTANCE: Instance = Instance {
425 addr: 0x48001400,
426 _marker: ::core::marker::PhantomData,
427 };
428
429 /// Reset values for each field in GPIOF
430 pub const reset: ResetValues = ResetValues {
431 MODER: 0x00000000,
432 OTYPER: 0x00000000,
433 OSPEEDR: 0x00000000,
434 PUPDR: 0x00000000,
435 IDR: 0x00000000,
436 ODR: 0x00000000,
437 BSRR: 0x00000000,
438 LCKR: 0x00000000,
439 AFRL: 0x00000000,
440 AFRH: 0x00000000,
441 BRR: 0x00000000,
442 };
443
444 #[cfg(not(feature = "nosync"))]
445 #[allow(renamed_and_removed_lints)]
446 #[allow(private_no_mangle_statics)]
447 #[no_mangle]
448 static mut GPIOF_TAKEN: bool = false;
449
450 /// Safe access to GPIOF
451 ///
452 /// This function returns `Some(Instance)` if this instance is not
453 /// currently taken, and `None` if it is. This ensures that if you
454 /// do get `Some(Instance)`, you are ensured unique access to
455 /// the peripheral and there cannot be data races (unless other
456 /// code uses `unsafe`, of course). You can then pass the
457 /// `Instance` around to other functions as required. When you're
458 /// done with it, you can call `release(instance)` to return it.
459 ///
460 /// `Instance` itself dereferences to a `RegisterBlock`, which
461 /// provides access to the peripheral's registers.
462 #[cfg(not(feature = "nosync"))]
463 #[inline]
464 pub fn take() -> Option<Instance> {
465 external_cortex_m::interrupt::free(|_| unsafe {
466 if GPIOF_TAKEN {
467 None
468 } else {
469 GPIOF_TAKEN = true;
470 Some(INSTANCE)
471 }
472 })
473 }
474
475 /// Release exclusive access to GPIOF
476 ///
477 /// This function allows you to return an `Instance` so that it
478 /// is available to `take()` again. This function will panic if
479 /// you return a different `Instance` or if this instance is not
480 /// already taken.
481 #[cfg(not(feature = "nosync"))]
482 #[inline]
483 pub fn release(inst: Instance) {
484 external_cortex_m::interrupt::free(|_| unsafe {
485 if GPIOF_TAKEN && inst.addr == INSTANCE.addr {
486 GPIOF_TAKEN = false;
487 } else {
488 panic!("Released a peripheral which was not taken");
489 }
490 });
491 }
492
493 /// Unsafely steal GPIOF
494 ///
495 /// This function is similar to take() but forcibly takes the
496 /// Instance, marking it as taken irregardless of its previous
497 /// state.
498 #[cfg(not(feature = "nosync"))]
499 #[inline]
500 pub unsafe fn steal() -> Instance {
501 GPIOF_TAKEN = true;
502 INSTANCE
503 }
504}
505
506/// Raw pointer to GPIOF
507///
508/// Dereferencing this is unsafe because you are not ensured unique
509/// access to the peripheral, so you may encounter data races with
510/// other users of this peripheral. It is up to you to ensure you
511/// will not cause data races.
512///
513/// This constant is provided for ease of use in unsafe code: you can
514/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
515pub const GPIOF: *const RegisterBlock = 0x48001400 as *const _;