diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-04-17 00:13:25 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-04-17 17:52:02 +0200 |
| commit | df7ef1d98f48a18027f5f0dcd0bc39cef0bfe8b9 (patch) | |
| tree | 18f19e821178d8084355c9a30d1cc80522022d54 | |
| parent | 9202dbf32a7854f9234ae51faff14144389bf84c (diff) | |
stm32/sdmmc: remove cfg_if.
| -rw-r--r-- | embassy-stm32/src/sdmmc/mod.rs | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index ac00b5176..92c54d815 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -135,57 +135,53 @@ enum Response { | |||
| 135 | Long = 3, | 135 | Long = 3, |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | cfg_if::cfg_if! { | 138 | /// Calculate clock divisor. Returns a SDMMC_CK less than or equal to |
| 139 | if #[cfg(sdmmc_v1)] { | 139 | /// `sdmmc_ck` in Hertz. |
| 140 | /// Calculate clock divisor. Returns a SDMMC_CK less than or equal to | 140 | /// |
| 141 | /// `sdmmc_ck` in Hertz. | 141 | /// Returns `(bypass, clk_div, clk_f)`, where `bypass` enables clock divisor bypass (only sdmmc_v1), |
| 142 | /// | 142 | /// `clk_div` is the divisor register value and `clk_f` is the resulting new clock frequency. |
| 143 | /// Returns `(bypass, clk_div, clk_f)`, where `bypass` enables clock divisor bypass (only sdmmc_v1), | 143 | #[cfg(sdmmc_v1)] |
| 144 | /// `clk_div` is the divisor register value and `clk_f` is the resulting new clock frequency. | 144 | fn clk_div(ker_ck: Hertz, sdmmc_ck: u32) -> Result<(bool, u8, Hertz), Error> { |
| 145 | fn clk_div(ker_ck: Hertz, sdmmc_ck: u32) -> Result<(bool, u8, Hertz), Error> { | 145 | // sdmmc_v1 maximum clock is 50 MHz |
| 146 | // sdmmc_v1 maximum clock is 50 MHz | 146 | if sdmmc_ck > 50_000_000 { |
| 147 | if sdmmc_ck > 50_000_000 { | 147 | return Err(Error::BadClock); |
| 148 | return Err(Error::BadClock); | 148 | } |
| 149 | } | ||
| 150 | 149 | ||
| 151 | // bypass divisor | 150 | // bypass divisor |
| 152 | if ker_ck.0 <= sdmmc_ck { | 151 | if ker_ck.0 <= sdmmc_ck { |
| 153 | return Ok((true, 0, ker_ck)); | 152 | return Ok((true, 0, ker_ck)); |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 156 | // `ker_ck / sdmmc_ck` rounded up | 155 | // `ker_ck / sdmmc_ck` rounded up |
| 157 | let clk_div = match (ker_ck.0 + sdmmc_ck - 1) / sdmmc_ck { | 156 | let clk_div = match (ker_ck.0 + sdmmc_ck - 1) / sdmmc_ck { |
| 158 | 0 | 1 => Ok(0), | 157 | 0 | 1 => Ok(0), |
| 159 | x @ 2..=258 => { | 158 | x @ 2..=258 => Ok((x - 2) as u8), |
| 160 | Ok((x - 2) as u8) | 159 | _ => Err(Error::BadClock), |
| 161 | } | 160 | }?; |
| 162 | _ => Err(Error::BadClock), | ||
| 163 | }?; | ||
| 164 | 161 | ||
| 165 | // SDIO_CK frequency = SDIOCLK / [CLKDIV + 2] | 162 | // SDIO_CK frequency = SDIOCLK / [CLKDIV + 2] |
| 166 | let clk_f = Hertz(ker_ck.0 / (clk_div as u32 + 2)); | 163 | let clk_f = Hertz(ker_ck.0 / (clk_div as u32 + 2)); |
| 167 | Ok((false, clk_div, clk_f)) | 164 | Ok((false, clk_div, clk_f)) |
| 168 | } | 165 | } |
| 169 | } else if #[cfg(sdmmc_v2)] { | 166 | |
| 170 | /// Calculate clock divisor. Returns a SDMMC_CK less than or equal to | 167 | /// Calculate clock divisor. Returns a SDMMC_CK less than or equal to |
| 171 | /// `sdmmc_ck` in Hertz. | 168 | /// `sdmmc_ck` in Hertz. |
| 172 | /// | 169 | /// |
| 173 | /// Returns `(bypass, clk_div, clk_f)`, where `bypass` enables clock divisor bypass (only sdmmc_v1), | 170 | /// Returns `(bypass, clk_div, clk_f)`, where `bypass` enables clock divisor bypass (only sdmmc_v1), |
| 174 | /// `clk_div` is the divisor register value and `clk_f` is the resulting new clock frequency. | 171 | /// `clk_div` is the divisor register value and `clk_f` is the resulting new clock frequency. |
| 175 | fn clk_div(ker_ck: Hertz, sdmmc_ck: u32) -> Result<(bool, u16, Hertz), Error> { | 172 | #[cfg(sdmmc_v2)] |
| 176 | // `ker_ck / sdmmc_ck` rounded up | 173 | fn clk_div(ker_ck: Hertz, sdmmc_ck: u32) -> Result<(bool, u16, Hertz), Error> { |
| 177 | match (ker_ck.0 + sdmmc_ck - 1) / sdmmc_ck { | 174 | // `ker_ck / sdmmc_ck` rounded up |
| 178 | 0 | 1 => Ok((false, 0, ker_ck)), | 175 | match (ker_ck.0 + sdmmc_ck - 1) / sdmmc_ck { |
| 179 | x @ 2..=2046 => { | 176 | 0 | 1 => Ok((false, 0, ker_ck)), |
| 180 | // SDMMC_CK frequency = SDMMCCLK / [CLKDIV + 2] | 177 | x @ 2..=2046 => { |
| 181 | let clk_div = ((x + 1) / 2) as u16; | 178 | // SDMMC_CK frequency = SDMMCCLK / [CLKDIV + 2] |
| 182 | let clk = Hertz(ker_ck.0 / (clk_div as u32 * 2)); | 179 | let clk_div = ((x + 1) / 2) as u16; |
| 183 | 180 | let clk = Hertz(ker_ck.0 / (clk_div as u32 * 2)); | |
| 184 | Ok((false, clk_div, clk)) | 181 | |
| 185 | } | 182 | Ok((false, clk_div, clk)) |
| 186 | _ => Err(Error::BadClock), | ||
| 187 | } | ||
| 188 | } | 183 | } |
| 184 | _ => Err(Error::BadClock), | ||
| 189 | } | 185 | } |
| 190 | } | 186 | } |
| 191 | 187 | ||
| @@ -904,13 +900,10 @@ impl SdmmcInner { | |||
| 904 | // NOTE(unsafe) Atomic read with no side-effects | 900 | // NOTE(unsafe) Atomic read with no side-effects |
| 905 | unsafe { | 901 | unsafe { |
| 906 | let status = regs.star().read(); | 902 | let status = regs.star().read(); |
| 907 | cfg_if::cfg_if! { | 903 | #[cfg(sdmmc_v1)] |
| 908 | if #[cfg(sdmmc_v1)] { | 904 | return status.rxact() || status.txact(); |
| 909 | status.rxact() || status.txact() | 905 | #[cfg(sdmmc_v2)] |
| 910 | } else if #[cfg(sdmmc_v2)] { | 906 | return status.dpsmact(); |
| 911 | status.dpsmact() | ||
| 912 | } | ||
| 913 | } | ||
| 914 | } | 907 | } |
| 915 | } | 908 | } |
| 916 | 909 | ||
| @@ -922,13 +915,10 @@ impl SdmmcInner { | |||
| 922 | // NOTE(unsafe) Atomic read with no side-effects | 915 | // NOTE(unsafe) Atomic read with no side-effects |
| 923 | unsafe { | 916 | unsafe { |
| 924 | let status = regs.star().read(); | 917 | let status = regs.star().read(); |
| 925 | cfg_if::cfg_if! { | 918 | #[cfg(sdmmc_v1)] |
| 926 | if #[cfg(sdmmc_v1)] { | 919 | return status.cmdact(); |
| 927 | status.cmdact() | 920 | #[cfg(sdmmc_v2)] |
| 928 | } else if #[cfg(sdmmc_v2)] { | 921 | return status.cpsmact(); |
| 929 | status.cpsmact() | ||
| 930 | } | ||
| 931 | } | ||
| 932 | } | 922 | } |
| 933 | } | 923 | } |
| 934 | 924 | ||
| @@ -961,20 +951,26 @@ impl SdmmcInner { | |||
| 961 | regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout)); | 951 | regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout)); |
| 962 | regs.dlenr().write(|w| w.set_datalength(length_bytes)); | 952 | regs.dlenr().write(|w| w.set_datalength(length_bytes)); |
| 963 | 953 | ||
| 964 | cfg_if::cfg_if! { | 954 | #[cfg(sdmmc_v1)] |
| 965 | if #[cfg(sdmmc_v1)] { | 955 | { |
| 966 | let request = dma.request(); | 956 | let request = dma.request(); |
| 967 | dma.start_read(request, regs.fifor().ptr() as *const u32, buffer, crate::dma::TransferOptions { | 957 | dma.start_read( |
| 958 | request, | ||
| 959 | regs.fifor().ptr() as *const u32, | ||
| 960 | buffer, | ||
| 961 | crate::dma::TransferOptions { | ||
| 968 | pburst: crate::dma::Burst::Incr4, | 962 | pburst: crate::dma::Burst::Incr4, |
| 969 | mburst: crate::dma::Burst::Incr4, | 963 | mburst: crate::dma::Burst::Incr4, |
| 970 | flow_ctrl: crate::dma::FlowControl::Peripheral, | 964 | flow_ctrl: crate::dma::FlowControl::Peripheral, |
| 971 | fifo_threshold: Some(crate::dma::FifoThreshold::Full), | 965 | fifo_threshold: Some(crate::dma::FifoThreshold::Full), |
| 972 | ..Default::default() | 966 | ..Default::default() |
| 973 | }); | 967 | }, |
| 974 | } else if #[cfg(sdmmc_v2)] { | 968 | ); |
| 975 | regs.idmabase0r().write(|w| w.set_idmabase0(buffer as *mut u32 as u32)); | 969 | } |
| 976 | regs.idmactrlr().modify(|w| w.set_idmaen(true)); | 970 | #[cfg(sdmmc_v2)] |
| 977 | } | 971 | { |
| 972 | regs.idmabase0r().write(|w| w.set_idmabase0(buffer as *mut u32 as u32)); | ||
| 973 | regs.idmactrlr().modify(|w| w.set_idmaen(true)); | ||
| 978 | } | 974 | } |
| 979 | 975 | ||
| 980 | regs.dctrl().modify(|w| { | 976 | regs.dctrl().modify(|w| { |
| @@ -1011,20 +1007,27 @@ impl SdmmcInner { | |||
| 1011 | regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout)); | 1007 | regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout)); |
| 1012 | regs.dlenr().write(|w| w.set_datalength(length_bytes)); | 1008 | regs.dlenr().write(|w| w.set_datalength(length_bytes)); |
| 1013 | 1009 | ||
| 1014 | cfg_if::cfg_if! { | 1010 | #[cfg(sdmmc_v1)] |
| 1015 | if #[cfg(sdmmc_v1)] { | 1011 | { |
| 1016 | let request = dma.request(); | 1012 | let request = dma.request(); |
| 1017 | dma.start_write(request, buffer, regs.fifor().ptr() as *mut u32, crate::dma::TransferOptions { | 1013 | dma.start_write( |
| 1014 | request, | ||
| 1015 | buffer, | ||
| 1016 | regs.fifor().ptr() as *mut u32, | ||
| 1017 | crate::dma::TransferOptions { | ||
| 1018 | pburst: crate::dma::Burst::Incr4, | 1018 | pburst: crate::dma::Burst::Incr4, |
| 1019 | mburst: crate::dma::Burst::Incr4, | 1019 | mburst: crate::dma::Burst::Incr4, |
| 1020 | flow_ctrl: crate::dma::FlowControl::Peripheral, | 1020 | flow_ctrl: crate::dma::FlowControl::Peripheral, |
| 1021 | fifo_threshold: Some(crate::dma::FifoThreshold::Full), | 1021 | fifo_threshold: Some(crate::dma::FifoThreshold::Full), |
| 1022 | ..Default::default() | 1022 | ..Default::default() |
| 1023 | }); | 1023 | }, |
| 1024 | } else if #[cfg(sdmmc_v2)] { | 1024 | ); |
| 1025 | regs.idmabase0r().write(|w| w.set_idmabase0(buffer as *const u32 as u32)); | 1025 | } |
| 1026 | regs.idmactrlr().modify(|w| w.set_idmaen(true)); | 1026 | #[cfg(sdmmc_v2)] |
| 1027 | } | 1027 | { |
| 1028 | regs.idmabase0r() | ||
| 1029 | .write(|w| w.set_idmabase0(buffer as *const u32 as u32)); | ||
| 1030 | regs.idmactrlr().modify(|w| w.set_idmaen(true)); | ||
| 1028 | } | 1031 | } |
| 1029 | 1032 | ||
| 1030 | regs.dctrl().modify(|w| { | 1033 | regs.dctrl().modify(|w| { |
| @@ -1043,16 +1046,13 @@ impl SdmmcInner { | |||
| 1043 | let regs = self.0; | 1046 | let regs = self.0; |
| 1044 | 1047 | ||
| 1045 | unsafe { | 1048 | unsafe { |
| 1046 | cfg_if::cfg_if! { | 1049 | #[cfg(sdmmc_v1)] |
| 1047 | if #[cfg(sdmmc_v1)] { | 1050 | regs.dctrl().modify(|w| { |
| 1048 | regs.dctrl().modify(|w| { | 1051 | w.set_dmaen(false); |
| 1049 | w.set_dmaen(false); | 1052 | w.set_dten(false); |
| 1050 | w.set_dten(false); | 1053 | }); |
| 1051 | }); | 1054 | #[cfg(sdmmc_v2)] |
| 1052 | } else if #[cfg(sdmmc_v2)] { | 1055 | regs.idmactrlr().modify(|w| w.set_idmaen(false)); |
| 1053 | regs.idmactrlr().modify(|w| w.set_idmaen(false)); | ||
| 1054 | } | ||
| 1055 | } | ||
| 1056 | } | 1056 | } |
| 1057 | } | 1057 | } |
| 1058 | 1058 | ||
