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;
6
7pub trait Servo<'a> {
8 /// Changes the angle of the servo.
9 ///
10 /// Return values:
11 /// - `Ok(())`: The attempt at changing the angle was successful.
12 /// - `FAIL`: Cannot change the angle.
13 /// - `INVAL`: The value exceeds u16, indicating it's incorrect
14 /// since servomotors can only have a maximum of 360 degrees.
15 /// - `NODEVICE`: The index exceeds the number of servomotors provided.
16 ///
17 /// # Arguments
18 /// - `angle`: the variable that receives the angle(in degrees from 0 to
19 /// 180) from the servo driver.
20 fn set_angle(&self, angle: u16) -> Result<(), ErrorCode>;
21
22 /// Returns the angle of the servo.
23 ///
24 /// Return values:
25 /// - `Ok(angle)`: The value, in angles from 0 to 360, of the servo.
26 /// - `NOSUPPORT`: The servo cannot return its angle.
27 /// - `NODEVICE`: The index exceeds the number of servomotors provided.
28 fn get_angle(&self) -> Result<usize, ErrorCode>;
29}