diff options
| author | chemicstry <[email protected]> | 2022-06-06 17:05:37 +0300 |
|---|---|---|
| committer | chemicstry <[email protected]> | 2022-06-06 17:12:52 +0300 |
| commit | b0ffd9a1cc6ae19f4698f704df037e5dd6f5fb97 (patch) | |
| tree | 0cdf0c6d11b34b3172ee4bbeb5380020d87ebb47 | |
| parent | 34673f52c9c23179f0274726a5aa1877dd554df0 (diff) | |
Fix AF pullup configuration for GPIOv1
| -rw-r--r-- | embassy-stm32/src/gpio.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index b6982e91a..f7a5da0a8 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -424,9 +424,14 @@ pub(crate) mod sealed { | |||
| 424 | } | 424 | } |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | #[inline] | ||
| 428 | unsafe fn set_as_af(&self, af_num: u8, af_type: AFType) { | ||
| 429 | self.set_as_af_pull(af_num, af_type, Pull::None); | ||
| 430 | } | ||
| 431 | |||
| 427 | #[cfg(gpio_v1)] | 432 | #[cfg(gpio_v1)] |
| 428 | #[inline] | 433 | #[inline] |
| 429 | unsafe fn set_as_af(&self, _af_num: u8, af_type: AFType) { | 434 | unsafe fn set_as_af_pull(&self, _af_num: u8, af_type: AFType, pull: Pull) { |
| 430 | // F1 uses the AFIO register for remapping. | 435 | // F1 uses the AFIO register for remapping. |
| 431 | // For now, this is not implemented, so af_num is ignored | 436 | // For now, this is not implemented, so af_num is ignored |
| 432 | // _af_num should be zero here, since it is not set by stm32-data | 437 | // _af_num should be zero here, since it is not set by stm32-data |
| @@ -435,9 +440,21 @@ pub(crate) mod sealed { | |||
| 435 | let crlh = if n < 8 { 0 } else { 1 }; | 440 | let crlh = if n < 8 { 0 } else { 1 }; |
| 436 | match af_type { | 441 | match af_type { |
| 437 | AFType::Input => { | 442 | AFType::Input => { |
| 443 | let cnf = match pull { | ||
| 444 | Pull::Up => { | ||
| 445 | r.bsrr().write(|w| w.set_bs(n, true)); | ||
| 446 | vals::CnfIn::PULL | ||
| 447 | } | ||
| 448 | Pull::Down => { | ||
| 449 | r.bsrr().write(|w| w.set_br(n, true)); | ||
| 450 | vals::CnfIn::PULL | ||
| 451 | } | ||
| 452 | Pull::None => vals::CnfIn::FLOATING, | ||
| 453 | }; | ||
| 454 | |||
| 438 | r.cr(crlh).modify(|w| { | 455 | r.cr(crlh).modify(|w| { |
| 439 | w.set_mode(n % 8, vals::Mode::INPUT); | 456 | w.set_mode(n % 8, vals::Mode::INPUT); |
| 440 | w.set_cnf_in(n % 8, vals::CnfIn::FLOATING); | 457 | w.set_cnf_in(n % 8, cnf); |
| 441 | }); | 458 | }); |
| 442 | } | 459 | } |
| 443 | AFType::OutputPushPull => { | 460 | AFType::OutputPushPull => { |
| @@ -457,12 +474,6 @@ pub(crate) mod sealed { | |||
| 457 | 474 | ||
| 458 | #[cfg(gpio_v2)] | 475 | #[cfg(gpio_v2)] |
| 459 | #[inline] | 476 | #[inline] |
| 460 | unsafe fn set_as_af(&self, af_num: u8, af_type: AFType) { | ||
| 461 | self.set_as_af_pull(af_num, af_type, Pull::None); | ||
| 462 | } | ||
| 463 | |||
| 464 | #[cfg(gpio_v2)] | ||
| 465 | #[inline] | ||
| 466 | unsafe fn set_as_af_pull(&self, af_num: u8, af_type: AFType, pull: Pull) { | 477 | unsafe fn set_as_af_pull(&self, af_num: u8, af_type: AFType, pull: Pull) { |
| 467 | let pin = self._pin() as usize; | 478 | let pin = self._pin() as usize; |
| 468 | let block = self.block(); | 479 | let block = self.block(); |
