mirror of
				https://github.com/PSenfft/mb85rc.git
				synced 2025-11-04 07:44:10 +00:00 
			
		
		
		
	created first example
This commit is contained in:
		
							parent
							
								
									c4d297f0ab
								
							
						
					
					
						commit
						d440043120
					
				
							
								
								
									
										14
									
								
								examples/esp32c6/.cargo/config.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								examples/esp32c6/.cargo/config.toml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
[target.riscv32imac-unknown-none-elf]
 | 
			
		||||
runner = "espflash flash --monitor --chip esp32c6"
 | 
			
		||||
 | 
			
		||||
[build]
 | 
			
		||||
rustflags = [
 | 
			
		||||
  # Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
 | 
			
		||||
  # NOTE: May negatively impact performance of produced code
 | 
			
		||||
  "-C", "force-frame-pointers",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
target = "riscv32imac-unknown-none-elf"
 | 
			
		||||
 | 
			
		||||
[unstable]
 | 
			
		||||
build-std = ["alloc", "core"]
 | 
			
		||||
							
								
								
									
										1
									
								
								examples/esp32c6/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								examples/esp32c6/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
/target
 | 
			
		||||
							
								
								
									
										1434
									
								
								examples/esp32c6/Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1434
									
								
								examples/esp32c6/Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										29
									
								
								examples/esp32c6/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								examples/esp32c6/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "esp32c6"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
edition = "2024"
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
mb85rc = { path = "../.." }
 | 
			
		||||
embedded-hal = "1.0.0"
 | 
			
		||||
embedded-io = "0.6.1"
 | 
			
		||||
esp-bootloader-esp-idf = "0.1.0"
 | 
			
		||||
esp-println = { version = "0.15.0", features = ["esp32c6", "log-04"] }
 | 
			
		||||
esp-hal = { version = "1.0.0-beta.1", features = ["esp32c6", "unstable"] } 
 | 
			
		||||
embedded-hal-bus = "0.3.0"
 | 
			
		||||
 | 
			
		||||
log = "0.4.27"
 | 
			
		||||
 | 
			
		||||
[profile.dev]
 | 
			
		||||
# Rust debug is too slow.
 | 
			
		||||
# For debug builds always builds with some optimization
 | 
			
		||||
opt-level = "s"
 | 
			
		||||
 | 
			
		||||
[profile.release]
 | 
			
		||||
codegen-units    = 1     # LLVM can perform better optimizations using a single thread
 | 
			
		||||
debug            = 2
 | 
			
		||||
debug-assertions = false
 | 
			
		||||
incremental      = false
 | 
			
		||||
lto              = 'fat'
 | 
			
		||||
opt-level        = 's'
 | 
			
		||||
overflow-checks  = false
 | 
			
		||||
							
								
								
									
										52
									
								
								examples/esp32c6/build.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								examples/esp32c6/build.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
			
		||||
fn main() {
 | 
			
		||||
    linker_be_nice();
 | 
			
		||||
    // make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
 | 
			
		||||
    println!("cargo:rustc-link-arg=-Tlinkall.x");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn linker_be_nice() {
 | 
			
		||||
    let args: Vec<String> = std::env::args().collect();
 | 
			
		||||
    if args.len() > 1 {
 | 
			
		||||
        let kind = &args[1];
 | 
			
		||||
        let what = &args[2];
 | 
			
		||||
 | 
			
		||||
        match kind.as_str() {
 | 
			
		||||
            "undefined-symbol" => match what.as_str() {
 | 
			
		||||
                "_defmt_timestamp" => {
 | 
			
		||||
                    eprintln!();
 | 
			
		||||
                    eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`");
 | 
			
		||||
                    eprintln!();
 | 
			
		||||
                }
 | 
			
		||||
                "_stack_start" => {
 | 
			
		||||
                    eprintln!();
 | 
			
		||||
                    eprintln!("💡 Is the linker script `linkall.x` missing?");
 | 
			
		||||
                    eprintln!();
 | 
			
		||||
                }
 | 
			
		||||
                "esp_wifi_preempt_enable"
 | 
			
		||||
                | "esp_wifi_preempt_yield_task"
 | 
			
		||||
                | "esp_wifi_preempt_task_create" => {
 | 
			
		||||
                    eprintln!();
 | 
			
		||||
                    eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler.");
 | 
			
		||||
                    eprintln!();
 | 
			
		||||
                }
 | 
			
		||||
                "embedded_test_linker_file_not_added_to_rustflags" => {
 | 
			
		||||
                    eprintln!();
 | 
			
		||||
                    eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests");
 | 
			
		||||
                    eprintln!();
 | 
			
		||||
                }
 | 
			
		||||
                _ => (),
 | 
			
		||||
            },
 | 
			
		||||
            // we don't have anything helpful for "missing-lib" yet
 | 
			
		||||
            _ => {
 | 
			
		||||
                std::process::exit(1);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        std::process::exit(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    println!(
 | 
			
		||||
        "cargo:rustc-link-arg=--error-handling-script={}",
 | 
			
		||||
        std::env::current_exe().unwrap().display()
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										4
									
								
								examples/esp32c6/rust-toolchain.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								examples/esp32c6/rust-toolchain.toml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
			
		||||
[toolchain]
 | 
			
		||||
channel    = "stable"
 | 
			
		||||
components = ["rust-src"]
 | 
			
		||||
targets = ["riscv32imac-unknown-none-elf"]
 | 
			
		||||
							
								
								
									
										66
									
								
								examples/esp32c6/src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								examples/esp32c6/src/main.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,66 @@
 | 
			
		||||
#![no_std]
 | 
			
		||||
#![no_main]
 | 
			
		||||
 | 
			
		||||
use embedded_hal_bus::i2c::RefCellDevice;
 | 
			
		||||
use esp_hal::main;
 | 
			
		||||
use esp_println::dbg;
 | 
			
		||||
use esp_println::logger::init_logger;
 | 
			
		||||
use core::cell::RefCell;
 | 
			
		||||
use core::default::Default;
 | 
			
		||||
use esp_hal::clock::CpuClock;
 | 
			
		||||
use esp_hal::peripherals::Peripherals;
 | 
			
		||||
use esp_hal::{delay::Delay, time::Duration};
 | 
			
		||||
use log::{debug, info, error};
 | 
			
		||||
use mb85rc::{self, MB85RC};
 | 
			
		||||
 | 
			
		||||
#[panic_handler]
 | 
			
		||||
fn panic(info: &core::panic::PanicInfo) -> ! {
 | 
			
		||||
    loop {
 | 
			
		||||
        error!("PANIC: {info}");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
esp_bootloader_esp_idf::esp_app_desc!();
 | 
			
		||||
 | 
			
		||||
#[main]
 | 
			
		||||
fn main() -> ! {
 | 
			
		||||
    let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
 | 
			
		||||
    let _peripherals = esp_hal::init(config);
 | 
			
		||||
    init_logger(log::LevelFilter::Debug);
 | 
			
		||||
 | 
			
		||||
    let peripherals = unsafe { Peripherals::steal() };
 | 
			
		||||
    let i2c = esp_hal::i2c::master::I2c::new(peripherals.I2C0, esp_hal::i2c::master::Config::default())
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .with_sda(peripherals.GPIO22)
 | 
			
		||||
        .with_scl(peripherals.GPIO23);
 | 
			
		||||
 | 
			
		||||
    let delay = Delay::new();
 | 
			
		||||
    delay.delay(Duration::from_millis(500));
 | 
			
		||||
    debug!("starting...");
 | 
			
		||||
 | 
			
		||||
    let i2c_refcell = RefCell::new(i2c);
 | 
			
		||||
 | 
			
		||||
    let display_refcell_device = RefCellDevice::new(&i2c_refcell);
 | 
			
		||||
 | 
			
		||||
    debug!("wait 1s...");
 | 
			
		||||
    delay.delay(Duration::from_millis(1000));
 | 
			
		||||
 | 
			
		||||
    let mut mb85rc = MB85RC::new(display_refcell_device, 0x50);
 | 
			
		||||
 | 
			
		||||
    let memory_address = [0x00, 0x00];
 | 
			
		||||
    let data = 0xFF;
 | 
			
		||||
 | 
			
		||||
    info!("writing {} in memory address: {:?}", data, memory_address);
 | 
			
		||||
    let write_result = mb85rc.byte_write(memory_address, data);
 | 
			
		||||
    dbg!(write_result);
 | 
			
		||||
 | 
			
		||||
    delay.delay(Duration::from_secs(1));
 | 
			
		||||
 | 
			
		||||
    debug!("reading fram...");
 | 
			
		||||
    let read_data = mb85rc.random_read(&memory_address);
 | 
			
		||||
    info!("read data: {:?}", read_data);
 | 
			
		||||
 | 
			
		||||
    loop {
 | 
			
		||||
        delay.delay(Duration::from_secs(2));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user