aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuliDi <[email protected]>2023-09-27 20:58:00 +0200
committerJuliDi <[email protected]>2023-10-01 12:32:47 +0200
commit49608714aaa509bd7720c2e8b68b3bf743cdfb39 (patch)
tree6464f4e8ba6c49d3fbc02d83cc224ae2e03eabce
parentf116ca83e0e5d78e8bac92d037b90fc7deaecc55 (diff)
cleanup, fix pushing to pins_table
-rw-r--r--embassy-stm32/build.rs122
1 files changed, 62 insertions, 60 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs
index 00f52294c..717da9049 100644
--- a/embassy-stm32/build.rs
+++ b/embassy-stm32/build.rs
@@ -88,26 +88,48 @@ fn main() {
88 } 88 }
89 } 89 }
90 90
91 struct SplitFeature {
92 feature_name: String,
93 pin_name_with_c: String,
94 pin_name_without_c: String,
95 }
96
91 // Extra analog switch pins available on most H7 chips 97 // Extra analog switch pins available on most H7 chips
92 let split_features = [ 98 let split_features = [
93 #[cfg(feature = "split-pa0")] 99 #[cfg(feature = "split-pa0")]
94 ("split-pa0", "PA0_C"), 100 SplitFeature {
101 feature_name: "split-pa0".to_string(),
102 pin_name_with_c: "PA0_C".to_string(),
103 pin_name_without_c: "PA0".to_string(),
104 },
95 #[cfg(feature = "split-pa1")] 105 #[cfg(feature = "split-pa1")]
96 ("split-pa1", "PA1_C"), 106 SplitFeature {
107 feature_name: "split-pa1".to_string(),
108 pin_name_with_c: "PA1_C".to_string(),
109 pin_name_without_c: "PA1".to_string(),
110 },
97 #[cfg(feature = "split-pc2")] 111 #[cfg(feature = "split-pc2")]
98 ("split-pc2", "PC2_C"), 112 SplitFeature {
113 feature_name: "split-pc2".to_string(),
114 pin_name_with_c: "PC2_C".to_string(),
115 pin_name_without_c: "PC2".to_string(),
116 },
99 #[cfg(feature = "split-pc3")] 117 #[cfg(feature = "split-pc3")]
100 ("split-pc3", "PC3_C"), 118 SplitFeature {
119 feature_name: "split-pc3".to_string(),
120 pin_name_with_c: "PC3_C".to_string(),
121 pin_name_without_c: "PC3".to_string(),
122 },
101 ]; 123 ];
102 124
103 for (feature_name, pin_name) in split_features { 125 for split_feature in &split_features {
104 if pin_set.contains(pin_name) { 126 if pin_set.contains(split_feature.pin_name_with_c.as_str()) {
105 singletons.push(pin_name.into()); 127 singletons.push(split_feature.pin_name_with_c.clone());
106 } else { 128 } else {
107 panic!( 129 panic!(
108 "'{}' feature invalid for this chip! No pin '{}' found.\n 130 "'{}' feature invalid for this chip! No pin '{}' found.\n
109 Found pins: {:#?}", 131 Found pins: {:#?}",
110 feature_name, pin_name, pin_set 132 split_feature.feature_name, split_feature.pin_name_with_c, pin_set
111 ) 133 )
112 } 134 }
113 } 135 }
@@ -711,25 +733,13 @@ fn main() {
711 if let Some(tr) = signals.get(&key) { 733 if let Some(tr) = signals.get(&key) {
712 let mut peri = format_ident!("{}", p.name); 734 let mut peri = format_ident!("{}", p.name);
713 let pin_name = { 735 let pin_name = {
714 #[allow(unused_mut)] 736 // If we encounter a "_C" pin, we remove the suffix
715 let mut pin_name = pin.pin; 737 let mut pin_name = pin.pin.strip_suffix("_C").unwrap_or(pin.pin).to_string();
716 738 // However, if the corresponding split_feature is enabled, we actually do want the pin name including "_C"
717 #[cfg(not(feature = "split-pa0"))] 739 for split_feature in &split_features {
718 if pin.pin == "PA0_C" { 740 if pin.pin == split_feature.pin_name_with_c {
719 pin_name = "PA0"; 741 pin_name = split_feature.pin_name_with_c.clone();
720 } 742 }
721 #[cfg(not(feature = "split-pa1"))]
722 if pin.pin == "PA1_C" {
723 pin_name = "PA1";
724 }
725
726 #[cfg(not(feature = "split-pc2"))]
727 if pin.pin == "PC2_C" {
728 pin_name = "PC2";
729 }
730 #[cfg(not(feature = "split-pc3"))]
731 if pin.pin == "PC3_C" {
732 pin_name = "PC3";
733 } 743 }
734 744
735 format_ident!("{}", pin_name) 745 format_ident!("{}", pin_name)
@@ -772,25 +782,13 @@ fn main() {
772 782
773 let peri = format_ident!("{}", p.name); 783 let peri = format_ident!("{}", p.name);
774 let pin_name = { 784 let pin_name = {
775 #[allow(unused_mut)] 785 // If we encounter a "_C" pin, we remove the suffix
776 let mut pin_name = pin.pin; 786 let mut pin_name = pin.pin.strip_suffix("_C").unwrap_or(pin.pin).to_string();
777 787 // However, if the corresponding split_feature is enabled, we actually do want the pin name including "_C"
778 #[cfg(not(feature = "split-pa0"))] 788 for split_feature in &split_features {
779 if pin.pin == "PA0_C" { 789 if pin.pin == split_feature.pin_name_with_c {
780 pin_name = "PA0"; 790 pin_name = split_feature.pin_name_with_c.clone();
781 } 791 }
782 #[cfg(not(feature = "split-pa1"))]
783 if pin.pin == "PA1_C" {
784 pin_name = "PA1";
785 }
786
787 #[cfg(not(feature = "split-pc2"))]
788 if pin.pin == "PC2_C" {
789 pin_name = "PC2";
790 }
791 #[cfg(not(feature = "split-pc3"))]
792 if pin.pin == "PC3_C" {
793 pin_name = "PC3";
794 } 792 }
795 793
796 format_ident!("{}", pin_name) 794 format_ident!("{}", pin_name)
@@ -945,26 +943,30 @@ fn main() {
945 for pin_num in 0u32..16 { 943 for pin_num in 0u32..16 {
946 let pin_name = format!("P{}{}", port_letter, pin_num); 944 let pin_name = format!("P{}{}", port_letter, pin_num);
947 945
948 // TODO: Here we need to take care of the _C pins properly.
949 // Maybe it would be better to not iterate over 0..16 but the
950 // Pin names directly. However, this might have side-effects... :(
951 if pin_name == "PC2" {
952 pins_table.push(vec![
953 "PC2_C".to_string(),
954 p.name.to_string(),
955 port_num.to_string(),
956 "2".to_string(),
957 format!("EXTI{}", 2),
958 ]);
959 }
960
961 pins_table.push(vec![ 946 pins_table.push(vec![
962 pin_name, 947 pin_name.clone(),
963 p.name.to_string(), 948 p.name.to_string(),
964 port_num.to_string(), 949 port_num.to_string(),
965 pin_num.to_string(), 950 pin_num.to_string(),
966 format!("EXTI{}", pin_num), 951 format!("EXTI{}", pin_num),
967 ]); 952 ]);
953
954 // If we have the split pins, we need to do a little extra work:
955 // Add the "_C" variant to the table. The solution is not optimal, though.
956 // Adding them only when the corresponding GPIOx also appears.
957 // This should avoid unintended side-effects as much as possible.
958 #[cfg(feature = "_split-pins-enabled")]
959 for split_feature in &split_features {
960 if split_feature.pin_name_without_c == pin_name {
961 pins_table.push(vec![
962 split_feature.pin_name_with_c.to_string(),
963 p.name.to_string(),
964 port_num.to_string(),
965 pin_num.to_string(),
966 format!("EXTI{}", pin_num),
967 ]);
968 }
969 }
968 } 970 }
969 } 971 }
970 972