1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
//! This crate provides a way to interact with a microcontroller with the punt bootloader connected //! via USB and exposes all bootloader functions. //! //! # Example: Basic flashing //! ```rust, no_run //! use punt::{Context, UsbContext, Operation}; //! use std::fs::File; //! use std::io::{Read, Write}; //! //! # fn main() -> Result<(), Box<dyn std::error::Error>> { //! // Open binary file and read contents //! let mut file = File::open("test.bin")?; //! let mut buff = Vec::new(); //! file.read_to_end(&mut buff)?; //! //! // Find a bootloader target //! let mut context = Context::new()?; //! let mut target_handle = context.pick_target(None)?.open()?; //! //! // Fetch information about the target's bootloader //! let start_address = target_handle.bootloader_info()?.application_base; //! //! // Erase the necessary flash area //! target_handle.erase_area(start_address, buff.len())?.execute()?; //! //! // Program the buffer into flash //! target_handle.program_at(buff.as_slice(), start_address)?.execute()?; //! //! // Verify flash contents //! target_handle.verify(buff.as_slice(), start_address)?; //! //! println!("Done!"); //! # Ok(()) //! # } //! ``` //! //! In addition to this very basic API, it also provides functionality for progress feedback during //! operations like reading, erasing and flashing. See the [`Operation`] trait for details. //! //! [`Operation`]: trait.Operation.html #![warn(missing_docs)] extern crate crc_any; extern crate rusb; pub mod bootloader_info; mod context; mod error; mod flash; pub mod operation; mod target; mod target_handle; pub use bootloader_info::BootloaderInfo; pub use context::{Context, UsbContext}; pub use error::{Error, Result}; pub use flash::{Page, FLASH_BASE, PAGE_SIZE}; pub use operation::Operation; pub use target::Target; pub use target_handle::TargetHandle; /// Timeout for all usb transactions. const TIMEOUT: std::time::Duration = std::time::Duration::from_millis(500);