"more proper" data address offset
This commit is contained in:
@@ -210,7 +210,7 @@ pub fn setup_readable_pins<const N: usize>(
|
|||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
let data_address = port.data();
|
let data_address = port.data(&pins);
|
||||||
|
|
||||||
let pins: [ReadablePin; N] = pins.map(|bit| ReadablePin { data_address, bit });
|
let pins: [ReadablePin; N] = pins.map(|bit| ReadablePin { data_address, bit });
|
||||||
|
|
||||||
@@ -296,9 +296,9 @@ pub fn setup_writable_pins<const N: usize>(
|
|||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
let data_address = port.data();
|
let data_address = port.data(&pins);
|
||||||
|
|
||||||
let pins: [WritablePin; N] = pins.map(|bit| WritablePin { data_address, bit });
|
let pins: [WritablePin; N] = pins.map(|pin| WritablePin { data_address, bit: pin });
|
||||||
|
|
||||||
WritablePins { data_address, pins }
|
WritablePins { data_address, pins }
|
||||||
}
|
}
|
||||||
|
@@ -58,9 +58,19 @@ impl Port {
|
|||||||
/// The memory address of the data (DATA) register for this port
|
/// The memory address of the data (DATA) register for this port
|
||||||
///
|
///
|
||||||
/// Page 662 of data sheet
|
/// Page 662 of data sheet
|
||||||
pub(super) fn data(&self) -> *mut u32 {
|
pub(super) fn data(&self, pins: &[Pin]) -> *mut u32 {
|
||||||
const OFFSET: u32 = 0x3FC;
|
// Extra guidance provided by
|
||||||
(self.base() + OFFSET) as *mut u32
|
// http://shukra.cedt.iisc.ernet.in/edwiki/EmSys:TM4C123GXL_GPIO_-_Read_Write_Data_Register
|
||||||
|
// because the data sheet was a bit hard to understand when thinking about why
|
||||||
|
// the C code I was referencing used an offset of 0x3FC
|
||||||
|
let mut offset = 0;
|
||||||
|
|
||||||
|
for pin in pins {
|
||||||
|
let bit = (*pin as u32) + 2;
|
||||||
|
offset |= 1 << bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
(self.base() + offset) as *mut u32
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The memory address of the digital enable (DEN) register for this port
|
/// The memory address of the digital enable (DEN) register for this port
|
||||||
|
@@ -12,3 +12,5 @@ pub mod system {
|
|||||||
// TODO: page 340
|
// TODO: page 340
|
||||||
pub const RCGCGPIO: *mut u32 = (BASE + 0x608) as *mut u32;
|
pub const RCGCGPIO: *mut u32 = (BASE + 0x608) as *mut u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: delete this file
|
Reference in New Issue
Block a user