Expand description
This module contains all the structures and functions related to +
pub struct B15F { /* private fields */ }
Expand description
Structure representing the driver for the board 15
-Implementations
sourceimpl B15F
impl B15F
sourcepub fn new() -> Result<B15F, Error>
pub fn new() -> Result<B15F, Error>
Creates a new instance of the B15
+pub struct B15F { /* private fields */ }
Expand description
Structure representing the driver for the board 15
+Implementations
sourceimpl B15F
impl B15F
sourcepub fn new() -> Result<B15F, Error>
pub fn new() -> Result<B15F, Error>
Creates a new instance of the B15
This function will establish a connection to a connected B15 and return
a handle to interact with it. Only one such instance should exist per
program; calling B15F::new()
more than once might lead to unexpected
behaviour.
Returns
+A new B15F object is returned. It contains an already active USART connection, +so calling this function multiple times will create an Error
+Errors
+An error::Error
is generated if the connection to the board cannot be
+established, or if testing of that connection fails.
Examples
use b15f::B15F;
let drv = B15F::new().unwrap();
sourcepub fn get_board_info(&mut self) -> Result<Vec<String>, Error>
pub fn get_board_info(&mut self) -> Result<Vec<String>, Error>
Yields information about the installed firmware on the B15
+sourcepub fn get_board_info(&mut self) -> Result<Vec<String>, Error>
pub fn get_board_info(&mut self) -> Result<Vec<String>, Error>
Yields information about the installed firmware on the B15
Returns an array of strings, where each string contains a piece of information stored on the B15
-Examples
+Returns
+A list of strings where each string contains a piece of information +about the board. What string contains what information is determined, +but not explicitly listed.
+Errors
+An error::Error
is generated if the communication with the board fails.
Examples
use b15f::B15F;
let mut drv = B15F::new().unwrap();
@@ -21,12 +38,19 @@ of information stored on the B15
.unwrap()
.iter()
.for_each(|info| println!("{info}"));
sourcepub fn discard(&mut self) -> Result<(), Error>
pub fn discard(&mut self) -> Result<(), Error>
Clears data in the USART buffers on this device and on the B15
-sourcepub fn test_connection(&mut self) -> Result<(), Error>
pub fn test_connection(&mut self) -> Result<(), Error>
Tests the connetion to the B15
+sourcepub fn discard(&mut self) -> Result<(), Error>
pub fn discard(&mut self) -> Result<(), Error>
Clears data in the USART buffers on this device and on the B15
+sourcepub fn test_int_conv(&mut self) -> Result<(), Error>
pub fn test_int_conv(&mut self) -> Result<(), Error>
Test the integer conversion of the USART connection
+Errors
+If an error occurs in the conversion or the communication with the
+board, an error::Error
will be returned.
sourcepub fn test_connection(&mut self) -> Result<(), Error>
pub fn test_connection(&mut self) -> Result<(), Error>
Tests the connetion to the B15
To test the connection a Request::Test
request will be sent
to the board together with a randomly generated value. If the
board returns that value the connection is working correctly.
Examples
+Errors
+An error::Error
is returned if the test fails, or if the
+communication itself fails.
Examples
use b15f::B15F;
fn main() {
@@ -36,7 +60,7 @@ board returns that value the connection is working correctly.
panic!("Connection is not working: {err}");
}
}
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for B15F
impl Send for B15F
impl !Sync for B15F
impl Unpin for B15F
impl !UnwindSafe for B15F
Blanket Implementations
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for B15F
impl Send for B15F
impl !Sync for B15F
impl Unpin for B15F
impl !UnwindSafe for B15F
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
const: unstable · sourcefn into(self) -> U
fn into(self) -> U
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From<T> for U
chooses to do.
U::from(self)
.","Creates a new instance of the B15","Tests the connetion to the B15","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1],"f":[0,0,0,0,[[]],[[]],[1,[[2,[0]]]],[[1,3],4],[[]],[1,[[2,[[6,[5]],0]]]],[[]],[[],[[2,[1,0]]]],[1,[[2,[0]]]],[[],2],[[],2],[[],7],[[]]],"p":[[3,"B15F"],[4,"Result"],[3,"Formatter"],[6,"Result"],[3,"String"],[3,"Vec"],[3,"TypeId"]]}\
+"b15f":{"doc":"Driver code for the board 15","t":[2,0,14,3,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11],"n":["B15F","b15f","build_request","B15F","borrow","borrow_mut","digital_write","discard","fmt","from","get_board_info","into","new","test_connection","test_int_conv","try_from","try_into","type_id","vzip"],"q":["b15f","","","b15f::b15f","","","","","","","","","","","","","","",""],"d":["","This module contains all the structures and functions …","Builds a new request buffer from the given data","Structure representing the driver for the board 15","","","Sets the value of the specified port","Clears data in the USART buffers on this device and on the …","","Returns the argument unchanged.","Yields information about the installed firmware on the B15","Calls U::from(self)
.","Creates a new instance of the B15","Tests the connetion to the B15","Test the integer conversion of the USART connection","","","",""],"i":[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"f":[0,0,0,0,[[]],[[]],[[1,2],[[3,[0]]]],[1,[[3,[0]]]],[[1,4],5],[[]],[1,[[3,[[7,[6]],0]]]],[[]],[[],[[3,[1,0]]]],[1,[[3,[0]]]],[1,[[3,[0]]]],[[],3],[[],3],[[],8],[[]]],"p":[[3,"B15F"],[15,"u8"],[4,"Result"],[3,"Formatter"],[6,"Result"],[3,"String"],[3,"Vec"],[3,"TypeId"]]}\
}');
if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)};
if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
diff --git a/doc/src/b15f/b15f.rs.html b/doc/src/b15f/b15f.rs.html
index fa9c047..004a9f0 100644
--- a/doc/src/b15f/b15f.rs.html
+++ b/doc/src/b15f/b15f.rs.html
@@ -241,6 +241,79 @@
241
242
243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
//! This module contains all the structures and functions related to
//! interacting with the B15 on a high level. If you are writing code
//! for the B15, this is the module you want to use.
@@ -282,6 +355,14 @@
/// program; calling `B15F::new()` more than once might lead to unexpected
/// behaviour.
///
+ /// # Returns
+ /// A new B15F object is returned. It contains an already active USART connection,
+ /// so calling this function multiple times will create an Error
+ ///
+ /// # Errors
+ /// An `error::Error` is generated if the connection to the board cannot be
+ /// established, or if testing of that connection fails.
+ ///
/// # Examples
/// ```
/// use b15f::B15F;
@@ -305,6 +386,11 @@
Err(_) => {} // Do nothing
};
+ match drv.test_int_conv() {
+ Ok(()) => break,
+ Err(_) => {}
+ }
+
tries -= 1;
}
@@ -346,11 +432,46 @@
Ok(port)
}
+ /// Sets the value of the specified port
+ ///
+ /// # Errors
+ /// `port` can either be 0 or 1, other values will cause a compile-time
+ /// error. Otherwise an `error::Error` is generated if communication
+ /// with the B15 fails.
+ ///
+ /// # Examples
+ ///
+ pub fn digital_write<const port: u8> (&mut self, value: u8) -> Result<(), Error> {
+ assert!(port == 0 || port == 1);
+
+ let reversed = value.reverse_bits();
+ let request = if port == 0 { Request::DigitalWrite0 } else { Request::DigitalWrite1 };
+
+ self.usart.write(build_request![request, reversed])?;
+
+ let mut aw: [u8; 1] = [0; 1];
+ self.usart.read(&mut aw)?;
+
+ if aw[0] != B15F::MSG_OK {
+ return Err(format!("Setting Port {} failed", port).into());
+ }
+
+ Ok(())
+ }
+
/// Yields information about the installed firmware on the B15
///
/// Returns an array of strings, where each string contains a piece
/// of information stored on the B15
///
+ /// # Returns
+ /// A list of strings where each string contains a piece of information
+ /// about the board. What string contains what information is determined,
+ /// but not explicitly listed.
+ ///
+ /// # Errors
+ /// An `error::Error` is generated if the communication with the board fails.
+ ///
/// # Examples
/// ```
/// use b15f::B15F;
@@ -412,13 +533,38 @@
Ok(())
}
+ /// Test the integer conversion of the USART connection
+ ///
+ /// # Errors
+ /// If an error occurs in the conversion or the communication with the
+ /// board, an `error::Error` will be returned.
+ pub fn test_int_conv(&mut self) -> Result<(), Error> {
+ let dummy: u16 = rand::thread_rng().gen_range(0x0000..=(0xFFFF / 3));
+
+ self.usart.write(build_request!(Request::IntTest, dummy & 0xFF, dummy >> 8))?;
+
+ let mut aw: [u8; 2] = [0; 2];
+ self.usart.read(&mut aw)?;
+
+ let result = u16::from_le_bytes(aw);
+ if result != dummy * 3 {
+ return Err("Int conversion failed".into());
+ }
+
+ Ok(())
+ }
+
/// Tests the connetion to the B15
///
/// To test the connection a `Request::Test` request will be sent
/// to the board together with a randomly generated value. If the
/// board returns that value the connection is working correctly.
///
- /// ## Examples
+ /// # Errors
+ /// An `error::Error` is returned if the test fails, or if the
+ /// communication itself fails.
+ ///
+ /// # Examples
/// ```
/// use b15f::B15F;
///
diff --git a/doc/src/b15f/request.rs.html b/doc/src/b15f/request.rs.html
index 07114ae..49544b3 100644
--- a/doc/src/b15f/request.rs.html
+++ b/doc/src/b15f/request.rs.html
@@ -21,6 +21,10 @@
21
22
23
+24
+25
+26
+27
//! This module contains the request data used to communicate
//! with the B15 via USART.
//!
@@ -40,8 +44,12 @@
#[repr(u8)]
pub enum Request {
- Discard = 0,
- Test = 1,
- Info = 2
-}