-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to update nScope from driver
- Loading branch information
1 parent
30d6d58
commit 51c2779
Showing
10 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
.DS_Store | ||
Cargo.lock | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Update Firmware" type="CargoCommandRunConfiguration" factoryName="Cargo Command" folderName="Examples"> | ||
<option name="command" value="run --example update_firmware" /> | ||
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> | ||
<option name="emulateTerminal" value="false" /> | ||
<option name="channel" value="DEFAULT" /> | ||
<option name="requiredFeatures" value="true" /> | ||
<option name="allFeatures" value="false" /> | ||
<option name="withSudo" value="false" /> | ||
<option name="buildTarget" value="REMOTE" /> | ||
<option name="backtrace" value="SHORT" /> | ||
<envs> | ||
<env name="RUST_LOG" value="trace" /> | ||
</envs> | ||
<option name="isRedirectInput" value="false" /> | ||
<option name="redirectInputPath" value="" /> | ||
<method v="2"> | ||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" /> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*************************************************************************************************** | ||
* | ||
* nLabs, LLC | ||
* https://nscope.org | ||
* Copyright(c) 2020. All Rights Reserved | ||
* | ||
* This file is part of the nScope API | ||
* | ||
**************************************************************************************************/ | ||
|
||
use nscope::{LabBench, NscopeDFU}; | ||
use std::error::Error; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
env_logger::init(); | ||
|
||
// Create a LabBench | ||
let bench = LabBench::new()?; | ||
|
||
// Print the bench to show a list of detected nScopes | ||
println!("{:?}", bench); | ||
|
||
// Get a list of all the nScopes that are detected in DFU mode | ||
let scopes_in_dfu: Vec<NscopeDFU> = bench.scopes_in_dfu().collect(); | ||
|
||
// If we have a scope in DFU mode, update the first one we found | ||
if let Some(dfu) = scopes_in_dfu.first() { | ||
dfu.update()?; | ||
} else { | ||
println!("Cannot find any nScopes in DFU mode"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*************************************************************************************************** | ||
* | ||
* nLabs, LLC | ||
* https://nscope.org | ||
* Copyright(c) 2020. All Rights Reserved | ||
* | ||
* This file is part of the nScope API | ||
* | ||
**************************************************************************************************/ | ||
|
||
pub(crate) static FIRMWARE: &[u8] = include_bytes!("firmware/v2.0"); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*************************************************************************************************** | ||
* | ||
* nLabs, LLC | ||
* https://nscope.org | ||
* Copyright(c) 2020. All Rights Reserved | ||
* | ||
* This file is part of the nScope API | ||
* | ||
**************************************************************************************************/ | ||
|
||
use std::error::Error; | ||
use std::fmt; | ||
|
||
use crate::firmware::FIRMWARE; | ||
|
||
pub struct NscopeDFU { | ||
device: rusb::Device<rusb::GlobalContext>, | ||
} | ||
|
||
|
||
impl NscopeDFU { | ||
pub(crate) fn new(device: &rusb::Device<rusb::GlobalContext>) -> Option<Self> { | ||
if let Ok(device_desc) = device.device_descriptor() { | ||
if device_desc.vendor_id() == 0x0483 && device_desc.product_id() == 0xA4AB { | ||
return Some(NscopeDFU { device: device.clone() }); | ||
} | ||
} | ||
None | ||
} | ||
|
||
pub fn update(&self) -> Result<(), Box<dyn Error>> { | ||
let mut dfu = dfu_libusb::DfuLibusb::from_usb_device( | ||
self.device.clone(), | ||
self.device.open()?, | ||
0, 0)?; | ||
|
||
dfu.override_address(0x08008000); | ||
dfu.download_from_slice(FIRMWARE)?; | ||
dfu.detach()?; | ||
println!("Resetting device"); | ||
dfu.usb_reset()?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl fmt::Debug for NscopeDFU { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "nScope in DFU mode: {:?}", &self.device) | ||
} | ||
} |