kernel/hil/
servo.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2024.
4
5use crate::ErrorCode;
6pub trait Servo<'a> {
7    /// Changes the angle of the servo.
8    /// Return values:
9    ///
10    /// - `Ok(())`: The attempt at changing the angle was successful.
11    /// - `FAIL`: Cannot change the angle.
12    /// - `INVAL`: The value exceeds u16, indicating it's incorrect
13    /// since servomotors can only have a maximum of 360 degrees.
14    /// - `NODEVICE`: The index exceeds the number of servomotors provided.
15    ///  # Arguments
16    /// - `angle` - the variable that receives the angle
17    /// (in degrees from 0 to 180) from the servo driver.
18    fn set_angle(&self, angle: u16) -> Result<(), ErrorCode>;
19
20    /// Returns the angle of the servo.
21    /// Return values:
22    ///
23    /// - `angle`: The value, in angles from 0 to 360, of the servo.
24    /// - `NOSUPPORT`:  The servo cannot return its angle.
25    /// - `NODEVICE`: The index exceeds the number of servomotors provided.
26    fn get_angle(&self) -> Result<usize, ErrorCode>;
27}