mirror of
https://github.com/PSenfft/mb85rc.git
synced 2025-08-22 12:54:16 +00:00
added get_device_id function
This commit is contained in:
parent
8e7389085f
commit
b94aafc820
@ -1,16 +1,16 @@
|
||||
#![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 embedded_hal_bus::i2c::RefCellDevice;
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::main;
|
||||
use esp_hal::peripherals::Peripherals;
|
||||
use esp_hal::{delay::Delay, time::Duration};
|
||||
use log::{debug, info, error};
|
||||
use esp_println::dbg;
|
||||
use esp_println::logger::init_logger;
|
||||
use log::{debug, error, info};
|
||||
use mb85rc::{self, MB85RC};
|
||||
|
||||
#[panic_handler]
|
||||
@ -29,10 +29,11 @@ fn main() -> ! {
|
||||
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 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));
|
||||
@ -47,6 +48,10 @@ fn main() -> ! {
|
||||
|
||||
let mut mb85rc = MB85RC::new(display_refcell_device, 0x50);
|
||||
|
||||
debug!("read device id");
|
||||
let device_id = mb85rc.get_device_id();
|
||||
dbg!(device_id);
|
||||
|
||||
let memory_address = [0x00, 0x00];
|
||||
let data = 0xFF;
|
||||
|
||||
|
12
src/lib.rs
12
src/lib.rs
@ -1,7 +1,7 @@
|
||||
#![no_std]
|
||||
|
||||
use core::{error::Error, result::Result};
|
||||
use embedded_hal::i2c::{I2c, SevenBitAddress};
|
||||
use core::result::Result;
|
||||
|
||||
const DEVICE_ADDRESS: u8 = 0b10100000;
|
||||
const DEVICE_ADDRESS_CODE: u8 = 0b00000000;
|
||||
@ -24,8 +24,14 @@ impl<T: I2c> MB85RC<T> {
|
||||
/// * `self` - A mutable reference to the MB85RC instance.
|
||||
/// # Returns
|
||||
/// * `Result<[u8; 3], Infallible>` -
|
||||
pub fn get_device_id(&mut self) -> [u8; 3] {
|
||||
todo!()
|
||||
pub fn get_device_id(&mut self) -> Result<[u8; 3], T::Error> {
|
||||
let mut buffer: [u8; 3] = [0, 0, 0];
|
||||
let reserved_slave_address = 0x7C; // Reserved Slave ID F9H without last bit, because wrte address adds this bit
|
||||
let payload = [0xA0]; // Device Address + read bit (write bit works also, because R/W code are “Don't care” value)
|
||||
self.i2c
|
||||
.write_read(reserved_slave_address, &payload, &mut buffer)?;
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
/// Write bit on the specified memory address
|
||||
|
Loading…
x
Reference in New Issue
Block a user