aboutsummaryrefslogtreecommitdiff
path: root/embassy-mspm0/build.rs
diff options
context:
space:
mode:
authorcrispaudio <[email protected]>2025-09-08 09:10:16 +0200
committercrispaudio <[email protected]>2025-09-08 09:10:16 +0200
commitbbcaab13bc074d8223b43d8e05682b708c192d78 (patch)
tree84bbe6af4b28f855a2c57d47413ec3cff44f6671 /embassy-mspm0/build.rs
parenta6cd24907aa43a8178a16b0db3d6b376f67f7540 (diff)
mspm0-adc: add adc with examples
Diffstat (limited to 'embassy-mspm0/build.rs')
-rw-r--r--embassy-mspm0/build.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/embassy-mspm0/build.rs b/embassy-mspm0/build.rs
index e8364e31a..ad90b5223 100644
--- a/embassy-mspm0/build.rs
+++ b/embassy-mspm0/build.rs
@@ -68,6 +68,7 @@ fn generate_code() {
68 g.extend(generate_pin_trait_impls()); 68 g.extend(generate_pin_trait_impls());
69 g.extend(generate_groups()); 69 g.extend(generate_groups());
70 g.extend(generate_dma_channel_count()); 70 g.extend(generate_dma_channel_count());
71 g.extend(generate_adc_constants());
71 72
72 let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); 73 let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
73 let out_file = out_dir.join("_generated.rs").to_string_lossy().to_string(); 74 let out_file = out_dir.join("_generated.rs").to_string_lossy().to_string();
@@ -220,6 +221,59 @@ fn generate_dma_channel_count() -> TokenStream {
220 quote! { pub const DMA_CHANNELS: usize = #count; } 221 quote! { pub const DMA_CHANNELS: usize = #count; }
221} 222}
222 223
224fn generate_adc_constants() -> TokenStream {
225 let vrsel = METADATA.adc_vrsel;
226 let memctl = METADATA.adc_memctl;
227
228 if vrsel == 3 {
229 quote! {
230 pub const ADC_VRSEL: u8 = #vrsel;
231 pub const ADC_MEMCTL: u8 = #memctl;
232
233 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
234 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
235 /// Reference voltage (Vref) selection for the ADC channels.
236 pub enum Vrsel {
237 /// VDDA reference
238 VddaVssa = 0,
239
240 /// External reference from pin
241 ExtrefVrefm = 1,
242
243 /// Internal reference
244 IntrefVssa = 2,
245 }
246 }
247 } else if vrsel == 5 {
248 quote! {
249 pub const ADC_VRSEL: u8 = #vrsel;
250 pub const ADC_MEMCTL: u8 = #memctl;
251
252 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
253 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
254 /// Reference voltage (Vref) selection for the ADC channels.
255 pub enum Vrsel {
256 /// VDDA reference
257 VddaVssa = 0,
258
259 /// External reference from pin
260 ExtrefVrefm = 1,
261
262 /// Internal reference
263 IntrefVssa = 2,
264
265 /// VDDA and VREFM connected to VREF+ and VREF- of ADC
266 VddaVrefm = 3,
267
268 /// INTREF and VREFM connected to VREF+ and VREF- of ADC
269 IntrefVrefm = 4,
270 }
271 }
272 } else {
273 panic!("Unsupported ADC VRSEL value: {vrsel}");
274 }
275}
276
223#[derive(Debug, Clone)] 277#[derive(Debug, Clone)]
224struct Singleton { 278struct Singleton {
225 name: String, 279 name: String,
@@ -561,6 +615,7 @@ fn generate_peripheral_instances() -> TokenStream {
561 "uart" => Some(quote! { impl_uart_instance!(#peri); }), 615 "uart" => Some(quote! { impl_uart_instance!(#peri); }),
562 "i2c" => Some(quote! { impl_i2c_instance!(#peri, #fifo_size); }), 616 "i2c" => Some(quote! { impl_i2c_instance!(#peri, #fifo_size); }),
563 "wwdt" => Some(quote! { impl_wwdt_instance!(#peri); }), 617 "wwdt" => Some(quote! { impl_wwdt_instance!(#peri); }),
618 "adc" => Some(quote! { impl_adc_instance!(#peri); }),
564 _ => None, 619 _ => None,
565 }; 620 };
566 621
@@ -609,6 +664,10 @@ fn generate_pin_trait_impls() -> TokenStream {
609 ("uart", "RTS") => Some(quote! { impl_uart_rts_pin!(#peri, #pin_name, #pf); }), 664 ("uart", "RTS") => Some(quote! { impl_uart_rts_pin!(#peri, #pin_name, #pf); }),
610 ("i2c", "SDA") => Some(quote! { impl_i2c_sda_pin!(#peri, #pin_name, #pf); }), 665 ("i2c", "SDA") => Some(quote! { impl_i2c_sda_pin!(#peri, #pin_name, #pf); }),
611 ("i2c", "SCL") => Some(quote! { impl_i2c_scl_pin!(#peri, #pin_name, #pf); }), 666 ("i2c", "SCL") => Some(quote! { impl_i2c_scl_pin!(#peri, #pin_name, #pf); }),
667 ("adc", s) => {
668 let signal = s.parse::<u8>().unwrap();
669 Some(quote! { impl_adc_pin!(#peri, #pin_name, #signal); })
670 }
612 671
613 _ => None, 672 _ => None,
614 }; 673 };