2025-09-21 09:35:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								#![ no_std ] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#![ no_main ] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#![ deny(
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     clippy ::mem_forget , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     reason   =   " mem::forget is generally not safe to do with esp_hal types, especially those  \ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     holding   buffers   for   the   duration   of   a   data   transfer . " 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								) ] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-11-01 09:32:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use   esp_hal ::i2c ::master ::BusTimeout ; 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-21 09:35:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								use   esp_hal ::{ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     clock ::CpuClock , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     gpio ::{ Level ,   Output ,   OutputConfig } , 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     main , 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-11-01 09:32:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     time ::{ Duration ,   Instant } , 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-21 09:35:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} ; 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-11-01 09:32:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use   fugit ::RateExtU32 ; 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-21 09:35:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#[ panic_handler ] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fn  panic ( _ : & core ::panic ::PanicInfo )   -> !   { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     loop   { } 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// This creates a default app-descriptor required by the esp-idf bootloader.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_bootloader_esp_idf ::esp_app_desc! ( ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#[ main ] 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fn  main ( )   -> !   { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     // generator version: 0.5.0
 
							 
						 
					
						
							
								
									
										
										
										
											2025-11-01 09:32:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     esp_println ::logger ::init_logger_from_env ( ) ; 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-21 09:35:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								     let   config   =   esp_hal ::Config ::default ( ) . with_cpu_clock ( CpuClock ::max ( ) ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     let   peripherals   =   esp_hal ::init ( config ) ; 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-11-01 09:32:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     let   i2c_config   =   esp_hal ::i2c ::master ::Config ::default ( ) . with_timeout ( BusTimeout ::Maximum ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     let   mut   i2c   =   esp_hal ::i2c ::master ::I2c ::new ( peripherals . I2C0 ,   i2c_config ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         . unwrap ( ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         . with_sda ( peripherals . GPIO21 ) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         . with_scl ( peripherals . GPIO22 ) ; 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-21 09:35:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     let   mut   led   =   Output ::new ( peripherals . GPIO2 ,   Level ::High ,   OutputConfig ::default ( ) ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     loop   { 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-11-01 09:32:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								         log ::info! ( " Scanning for I2C devices.. " ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         for   i   in   0 ..= 127 u8   { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								             let   res   =   i2c . read ( i ,   & mut   [ 0 ] ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								             match   res   { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                 Ok ( _ )   = >   { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                     log ::info! ( " Device found at address: {} " ,   i ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                 } 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                 Err ( err )   = >   { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                     log ::warn! ( " Failed to read device address: {:?} " ,   err ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                 } 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								             } 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         } 
 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-21 09:35:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								         led . toggle ( ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         let   delay_start   =   Instant ::now ( ) ; 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								         while   delay_start . elapsed ( )   <   Duration ::from_millis ( 500 )   { } 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     } 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}