mirror of
				https://github.com/PSenfft/mb85rc.git
				synced 2025-11-04 07:44:10 +00:00 
			
		
		
		
	finished write_page and sequential_read function
This commit is contained in:
		
							parent
							
								
									6df4796084
								
							
						
					
					
						commit
						a4e8cc5250
					
				
							
								
								
									
										46
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								src/lib.rs
									
									
									
									
									
								
							@ -23,7 +23,7 @@ impl<T: I2c> MB85RC<T> {
 | 
			
		||||
    ///  # Arguments
 | 
			
		||||
    /// * `self` - A mutable reference to the MB85RC instance.
 | 
			
		||||
    /// # Returns
 | 
			
		||||
    /// * `Result<[u8; 3], Infallible>` -
 | 
			
		||||
    /// * `Result<[u8; 3], Error>` - Device ID is 3 bytes and consists of manufacturer ID and product ID
 | 
			
		||||
    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 
 | 
			
		||||
@ -39,9 +39,12 @@ impl<T: I2c> MB85RC<T> {
 | 
			
		||||
    /// * `self` - A mutable reference to the MB85RC instance.
 | 
			
		||||
    /// * `memory_address` - The memory address to write to.
 | 
			
		||||
    /// * `data` - The data byte to write.
 | 
			
		||||
    /// # Returns
 | 
			
		||||
    /// * `Result<u8, T::Error>`
 | 
			
		||||
    pub fn byte_write(&mut self, memory_address: [u8; 2], data: u8) -> Result<u8, T::Error> {
 | 
			
		||||
        let payload = [memory_address[0], memory_address[1], data];
 | 
			
		||||
        self.i2c.write(self.address, &payload)?;
 | 
			
		||||
 | 
			
		||||
        Ok(data)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -51,16 +54,33 @@ impl<T: I2c> MB85RC<T> {
 | 
			
		||||
    /// of the memory address that was written first. Because FRAM performs the high-speed write operations, the
 | 
			
		||||
    /// data will be written to FRAM right after the ACK response finished.
 | 
			
		||||
    /// array 32KB
 | 
			
		||||
    pub fn write_page(memory_address: [u8; 2], buf: &mut [u8]) -> Result<(), T::Error> {
 | 
			
		||||
        todo!()
 | 
			
		||||
    /// # Arguments
 | 
			
		||||
    /// * `self` - A mutable reference to the MB85RC instance.
 | 
			
		||||
    /// * `memory_address` - The memory address to write to.
 | 
			
		||||
    /// * `data` - The data bytes to write max 32KB.
 | 
			
		||||
    /// # Returns
 | 
			
		||||
    /// * `Result<(), T::Error>`
 | 
			
		||||
    pub fn write_page(
 | 
			
		||||
        &mut self,
 | 
			
		||||
        memory_address: [u8; 2],
 | 
			
		||||
        data: &mut [u8; 32000],
 | 
			
		||||
    ) -> Result<(), T::Error> {
 | 
			
		||||
        let mut payload = [0u8; 32002];
 | 
			
		||||
        payload[0] = memory_address[0];
 | 
			
		||||
        payload[1] = memory_address[1];
 | 
			
		||||
        payload[2..].copy_from_slice(data);
 | 
			
		||||
        self.i2c.write(self.address, &payload)?;
 | 
			
		||||
 | 
			
		||||
        Ok(())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// The one byte of data from the memory address saved in the memory address buffer can be read out
 | 
			
		||||
    /// synchronously
 | 
			
		||||
    /// # Arguments
 | 
			
		||||
    /// * `self` - A mutable reference to the MB85RC instance.
 | 
			
		||||
    /// * `memory_address` - The memory address to read from.
 | 
			
		||||
    /// # Returns
 | 
			
		||||
    /// * `Result<u8, Infallible>` - The byte read from the specified
 | 
			
		||||
    /// * `Result<u8, Error>` - The byte read from the specified
 | 
			
		||||
    pub fn random_read(&mut self, memory_address: &[u8; 2]) -> Result<u8, T::Error> {
 | 
			
		||||
        let mut buffer: [u8; 1] = [0];
 | 
			
		||||
        self.i2c
 | 
			
		||||
@ -75,11 +95,19 @@ impl<T: I2c> MB85RC<T> {
 | 
			
		||||
    /// command. If the end of the memory address space is reached, the internal read
 | 
			
		||||
    /// address automatically rolls over to the first memory address (0x0000) and continues
 | 
			
		||||
    /// reading.
 | 
			
		||||
    pub fn sequential_read(
 | 
			
		||||
    /// # Arguments
 | 
			
		||||
    /// * `self` - A mutable reference to the MB85RC instance.
 | 
			
		||||
    /// * `memory_address` - The memory address to read from.
 | 
			
		||||
    /// * `buffer` - buffer to write the payload data
 | 
			
		||||
    /// # Return
 | 
			
		||||
    /// * `Result<&'a mut [u8], T::Error>` - Pointer to the array with the read data
 | 
			
		||||
    pub fn sequential_read<'a>(
 | 
			
		||||
        &mut self,
 | 
			
		||||
        memory_address: [u8; 2],
 | 
			
		||||
        buf: &mut [u8],
 | 
			
		||||
    ) -> Result<usize, T::Error> {
 | 
			
		||||
        todo!()
 | 
			
		||||
        memory_address: &[u8; 2],
 | 
			
		||||
        buffer: &'a mut [u8],
 | 
			
		||||
    ) -> Result<&'a mut [u8], T::Error> {
 | 
			
		||||
        self.i2c.write_read(self.address, memory_address, buffer)?;
 | 
			
		||||
 | 
			
		||||
        Ok(buffer)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user