Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(nll)]
- mod mercury {
- mod ftdi {
- use std::result;
- mod error {
- pub enum Error<'a> {
- LibFtdi(&'a str),
- MallocFailure,
- }
- }
- pub struct Context {
- context : (),
- }
- pub type Result<'a, T> = result::Result<T, error::Error<'a>>;
- }
- pub struct Mercury {
- context : ftdi::Context,
- }
- pub enum DeviceSelect {
- FPGA,
- FLASH,
- IDLE
- }
- impl Mercury {
- pub fn new() -> Mercury {
- unimplemented!()
- }
- pub fn spi_sel(&mut self, _sel : DeviceSelect) -> ftdi::Result<()> {
- unimplemented!()
- }
- // If deslect should happen after calling this function, it needs to be done manually!
- // Flash expects CS to stay asserted between data out and data in (PC's point-of-view).
- pub fn spi_out(&mut self, _bytes : &[u8], _sel : DeviceSelect) -> ftdi::Result<u32> {
- unimplemented!()
- }
- pub fn spi_in(&mut self, _bytes : &mut [u8], _sel : DeviceSelect) -> ftdi::Result<u32> {
- unimplemented!()
- }
- pub fn flash_id(&mut self) -> ftdi::Result<u32> {
- match self.spi_out(&[0x9F], DeviceSelect::FLASH) {
- Ok(v) => v,
- Err(e) => {
- self.spi_sel(DeviceSelect::IDLE)?;
- return Err(e);
- }
- };
- match self.spi_in(&mut [0; 4], DeviceSelect::FLASH) {
- Ok(v) => v,
- Err(e) => {
- self.spi_sel(DeviceSelect::IDLE)?;
- return Err(e);
- }
- };
- self.spi_sel(DeviceSelect::IDLE)?;
- Ok(0)
- }
- }
- }
- fn main() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement