Advertisement
Guest User

Untitled

a guest
May 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #![feature(nll)]
  2.  
  3. mod mercury {
  4. mod ftdi {
  5. use std::result;
  6.  
  7. mod error {
  8. pub enum Error<'a> {
  9. LibFtdi(&'a str),
  10. MallocFailure,
  11. }
  12. }
  13.  
  14. pub struct Context {
  15. context : (),
  16. }
  17.  
  18. pub type Result<'a, T> = result::Result<T, error::Error<'a>>;
  19. }
  20.  
  21. pub struct Mercury {
  22. context : ftdi::Context,
  23. }
  24.  
  25. pub enum DeviceSelect {
  26. FPGA,
  27. FLASH,
  28. IDLE
  29. }
  30.  
  31.  
  32. impl Mercury {
  33. pub fn new() -> Mercury {
  34. unimplemented!()
  35. }
  36.  
  37. pub fn spi_sel(&mut self, _sel : DeviceSelect) -> ftdi::Result<()> {
  38. unimplemented!()
  39. }
  40.  
  41. // If deslect should happen after calling this function, it needs to be done manually!
  42. // Flash expects CS to stay asserted between data out and data in (PC's point-of-view).
  43. pub fn spi_out(&mut self, _bytes : &[u8], _sel : DeviceSelect) -> ftdi::Result<u32> {
  44. unimplemented!()
  45. }
  46.  
  47. pub fn spi_in(&mut self, _bytes : &mut [u8], _sel : DeviceSelect) -> ftdi::Result<u32> {
  48. unimplemented!()
  49. }
  50.  
  51. pub fn flash_id(&mut self) -> ftdi::Result<u32> {
  52. match self.spi_out(&[0x9F], DeviceSelect::FLASH) {
  53. Ok(v) => v,
  54. Err(e) => {
  55. self.spi_sel(DeviceSelect::IDLE)?;
  56. return Err(e);
  57. }
  58. };
  59.  
  60. match self.spi_in(&mut [0; 4], DeviceSelect::FLASH) {
  61. Ok(v) => v,
  62. Err(e) => {
  63. self.spi_sel(DeviceSelect::IDLE)?;
  64. return Err(e);
  65. }
  66. };
  67.  
  68. self.spi_sel(DeviceSelect::IDLE)?;
  69. Ok(0)
  70. }
  71. }
  72. }
  73.  
  74.  
  75. fn main() {
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement