tinkerforge_async/bindings/
xmc1400_breakout_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! Breakout for Infineon XMC1400 microcontroller.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/XMC1400Breakout_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
17    low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum Xmc1400BreakoutBrickletFunction {
24    SetGpioConfig,
25    GetGpioInput,
26    SetAdcChannelConfig,
27    GetAdcChannelConfig,
28    GetAdcChannelValue,
29    GetAdcValues,
30    SetAdcValuesCallbackConfiguration,
31    GetAdcValuesCallbackConfiguration,
32    GetCount,
33    SetCountCallbackConfiguration,
34    GetCountCallbackConfiguration,
35    GetSpitfpErrorCount,
36    SetBootloaderMode,
37    GetBootloaderMode,
38    SetWriteFirmwarePointer,
39    WriteFirmware,
40    SetStatusLedConfig,
41    GetStatusLedConfig,
42    GetChipTemperature,
43    Reset,
44    WriteUid,
45    ReadUid,
46    GetIdentity,
47    CallbackAdcValues,
48    CallbackCount,
49}
50impl From<Xmc1400BreakoutBrickletFunction> for u8 {
51    fn from(fun: Xmc1400BreakoutBrickletFunction) -> Self {
52        match fun {
53            Xmc1400BreakoutBrickletFunction::SetGpioConfig => 1,
54            Xmc1400BreakoutBrickletFunction::GetGpioInput => 2,
55            Xmc1400BreakoutBrickletFunction::SetAdcChannelConfig => 3,
56            Xmc1400BreakoutBrickletFunction::GetAdcChannelConfig => 4,
57            Xmc1400BreakoutBrickletFunction::GetAdcChannelValue => 5,
58            Xmc1400BreakoutBrickletFunction::GetAdcValues => 6,
59            Xmc1400BreakoutBrickletFunction::SetAdcValuesCallbackConfiguration => 7,
60            Xmc1400BreakoutBrickletFunction::GetAdcValuesCallbackConfiguration => 8,
61            Xmc1400BreakoutBrickletFunction::GetCount => 10,
62            Xmc1400BreakoutBrickletFunction::SetCountCallbackConfiguration => 11,
63            Xmc1400BreakoutBrickletFunction::GetCountCallbackConfiguration => 12,
64            Xmc1400BreakoutBrickletFunction::GetSpitfpErrorCount => 234,
65            Xmc1400BreakoutBrickletFunction::SetBootloaderMode => 235,
66            Xmc1400BreakoutBrickletFunction::GetBootloaderMode => 236,
67            Xmc1400BreakoutBrickletFunction::SetWriteFirmwarePointer => 237,
68            Xmc1400BreakoutBrickletFunction::WriteFirmware => 238,
69            Xmc1400BreakoutBrickletFunction::SetStatusLedConfig => 239,
70            Xmc1400BreakoutBrickletFunction::GetStatusLedConfig => 240,
71            Xmc1400BreakoutBrickletFunction::GetChipTemperature => 242,
72            Xmc1400BreakoutBrickletFunction::Reset => 243,
73            Xmc1400BreakoutBrickletFunction::WriteUid => 248,
74            Xmc1400BreakoutBrickletFunction::ReadUid => 249,
75            Xmc1400BreakoutBrickletFunction::GetIdentity => 255,
76            Xmc1400BreakoutBrickletFunction::CallbackAdcValues => 9,
77            Xmc1400BreakoutBrickletFunction::CallbackCount => 13,
78        }
79    }
80}
81pub const XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
82pub const XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
83pub const XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
84pub const XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
85pub const XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
86pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_TRISTATE: u8 = 0;
87pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_PULL_DOWN: u8 = 1;
88pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_PULL_UP: u8 = 2;
89pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_SAMPLING: u8 = 3;
90pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_INVERTED_TRISTATE: u8 = 4;
91pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_INVERTED_PULL_DOWN: u8 = 5;
92pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_INVERTED_PULL_UP: u8 = 6;
93pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_INVERTED_SAMPLING: u8 = 7;
94pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_OUTPUT_PUSH_PULL: u8 = 8;
95pub const XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_OUTPUT_OPEN_DRAIN: u8 = 9;
96pub const XMC1400_BREAKOUT_BRICKLET_GPIO_INPUT_HYSTERESIS_STANDARD: u8 = 0;
97pub const XMC1400_BREAKOUT_BRICKLET_GPIO_INPUT_HYSTERESIS_LARGE: u8 = 4;
98pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
99pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
100pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
101pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
102pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
103pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
104pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
105pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
106pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
107pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
108pub const XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
109pub const XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
110pub const XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
111pub const XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
112pub const XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
113
114#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
115pub struct AdcValuesCallbackConfiguration {
116    pub period: u32,
117    pub value_has_to_change: bool,
118}
119impl FromByteSlice for AdcValuesCallbackConfiguration {
120    fn bytes_expected() -> usize {
121        5
122    }
123    fn from_le_byte_slice(bytes: &[u8]) -> AdcValuesCallbackConfiguration {
124        AdcValuesCallbackConfiguration {
125            period: <u32>::from_le_byte_slice(&bytes[0..4]),
126            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
127        }
128    }
129}
130
131#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
132pub struct CountCallbackConfiguration {
133    pub period: u32,
134    pub value_has_to_change: bool,
135    pub option: char,
136    pub min: u32,
137    pub max: u32,
138}
139impl FromByteSlice for CountCallbackConfiguration {
140    fn bytes_expected() -> usize {
141        14
142    }
143    fn from_le_byte_slice(bytes: &[u8]) -> CountCallbackConfiguration {
144        CountCallbackConfiguration {
145            period: <u32>::from_le_byte_slice(&bytes[0..4]),
146            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
147            option: <char>::from_le_byte_slice(&bytes[5..6]),
148            min: <u32>::from_le_byte_slice(&bytes[6..10]),
149            max: <u32>::from_le_byte_slice(&bytes[10..14]),
150        }
151    }
152}
153
154#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
155pub struct SpitfpErrorCount {
156    pub error_count_ack_checksum: u32,
157    pub error_count_message_checksum: u32,
158    pub error_count_frame: u32,
159    pub error_count_overflow: u32,
160}
161impl FromByteSlice for SpitfpErrorCount {
162    fn bytes_expected() -> usize {
163        16
164    }
165    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
166        SpitfpErrorCount {
167            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
168            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
169            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
170            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
171        }
172    }
173}
174
175#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
176pub struct Identity {
177    pub uid: String,
178    pub connected_uid: String,
179    pub position: char,
180    pub hardware_version: [u8; 3],
181    pub firmware_version: [u8; 3],
182    pub device_identifier: u16,
183}
184impl FromByteSlice for Identity {
185    fn bytes_expected() -> usize {
186        25
187    }
188    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
189        Identity {
190            uid: <String>::from_le_byte_slice(&bytes[0..8]),
191            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
192            position: <char>::from_le_byte_slice(&bytes[16..17]),
193            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
194            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
195            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
196        }
197    }
198}
199
200/// Breakout for Infineon XMC1400 microcontroller
201#[derive(Clone)]
202pub struct Xmc1400BreakoutBricklet {
203    device: Device,
204}
205impl Xmc1400BreakoutBricklet {
206    pub const DEVICE_IDENTIFIER: u16 = 279;
207    pub const DEVICE_DISPLAY_NAME: &'static str = "XMC1400 Breakout Bricklet";
208    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
209    pub fn new(uid: Uid, connection: AsyncIpConnection) -> Xmc1400BreakoutBricklet {
210        let mut result = Xmc1400BreakoutBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
211        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::SetGpioConfig) as usize] = ResponseExpectedFlag::False;
212        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetGpioInput) as usize] =
213            ResponseExpectedFlag::AlwaysTrue;
214        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::SetAdcChannelConfig) as usize] =
215            ResponseExpectedFlag::False;
216        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetAdcChannelConfig) as usize] =
217            ResponseExpectedFlag::AlwaysTrue;
218        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetAdcChannelValue) as usize] =
219            ResponseExpectedFlag::AlwaysTrue;
220        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetAdcValues) as usize] =
221            ResponseExpectedFlag::AlwaysTrue;
222        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::SetAdcValuesCallbackConfiguration) as usize] =
223            ResponseExpectedFlag::True;
224        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetAdcValuesCallbackConfiguration) as usize] =
225            ResponseExpectedFlag::AlwaysTrue;
226        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
227        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::SetCountCallbackConfiguration) as usize] =
228            ResponseExpectedFlag::True;
229        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetCountCallbackConfiguration) as usize] =
230            ResponseExpectedFlag::AlwaysTrue;
231        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetSpitfpErrorCount) as usize] =
232            ResponseExpectedFlag::AlwaysTrue;
233        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::SetBootloaderMode) as usize] =
234            ResponseExpectedFlag::AlwaysTrue;
235        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetBootloaderMode) as usize] =
236            ResponseExpectedFlag::AlwaysTrue;
237        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::SetWriteFirmwarePointer) as usize] =
238            ResponseExpectedFlag::False;
239        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::WriteFirmware) as usize] =
240            ResponseExpectedFlag::AlwaysTrue;
241        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::SetStatusLedConfig) as usize] =
242            ResponseExpectedFlag::False;
243        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetStatusLedConfig) as usize] =
244            ResponseExpectedFlag::AlwaysTrue;
245        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetChipTemperature) as usize] =
246            ResponseExpectedFlag::AlwaysTrue;
247        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
248        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
249        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
250        result.device.response_expected[u8::from(Xmc1400BreakoutBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
251        result
252    }
253
254    /// Returns the response expected flag for the function specified by the function ID parameter.
255    /// It is true if the function is expected to send a response, false otherwise.
256    ///
257    /// For getter functions this is enabled by default and cannot be disabled, because those
258    /// functions will always send a response. For callback configuration functions it is enabled
259    /// by default too, but can be disabled by [`set_response_expected`](crate::xmc1400_breakout_bricklet::Xmc1400BreakoutBricklet::set_response_expected).
260    /// For setter functions it is disabled by default and can be enabled.
261    ///
262    /// Enabling the response expected flag for a setter function allows to detect timeouts
263    /// and other error conditions calls of this setter as well. The device will then send a response
264    /// for this purpose. If this flag is disabled for a setter function then no response is sent
265    /// and errors are silently ignored, because they cannot be detected.
266    ///
267    /// See [`set_response_expected`](crate::xmc1400_breakout_bricklet::Xmc1400BreakoutBricklet::set_response_expected) for the list of function ID constants available for this function.
268    pub fn get_response_expected(&mut self, fun: Xmc1400BreakoutBrickletFunction) -> Result<bool, GetResponseExpectedError> {
269        self.device.get_response_expected(u8::from(fun))
270    }
271
272    /// Changes the response expected flag of the function specified by the function ID parameter.
273    /// This flag can only be changed for setter (default value: false) and callback configuration
274    /// functions (default value: true). For getter functions it is always enabled.
275    ///
276    /// Enabling the response expected flag for a setter function allows to detect timeouts and
277    /// other error conditions calls of this setter as well. The device will then send a response
278    /// for this purpose. If this flag is disabled for a setter function then no response is sent
279    /// and errors are silently ignored, because they cannot be detected.
280    pub fn set_response_expected(
281        &mut self,
282        fun: Xmc1400BreakoutBrickletFunction,
283        response_expected: bool,
284    ) -> Result<(), SetResponseExpectedError> {
285        self.device.set_response_expected(u8::from(fun), response_expected)
286    }
287
288    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
289    pub fn set_response_expected_all(&mut self, response_expected: bool) {
290        self.device.set_response_expected_all(response_expected)
291    }
292
293    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
294    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
295    pub fn get_api_version(&self) -> [u8; 3] {
296        self.device.api_version
297    }
298
299    /// This receiver is triggered periodically according to the configuration set by
300    /// [`set_adc_values_callback_configuration`].
301    ///
302    /// The parameters are the same as [`get_adc_values`].
303    ///
304    /// [`get_adc_values`]: #method.get_adc_values
305    /// [`set_adc_values_callback_configuration`]: #method.set_adc_values_callback_configuration
306    pub async fn get_adc_values_callback_receiver(&mut self) -> impl Stream<Item = [u16; 8]> {
307        self.device
308            .get_callback_receiver(u8::from(Xmc1400BreakoutBrickletFunction::CallbackAdcValues))
309            .await
310            .map(|p| <[u16; 8]>::from_le_byte_slice(p.body()))
311    }
312
313    /// This receiver is triggered periodically according to the configuration set by
314    /// [`set_count_callback_configuration`].
315    ///
316    /// The parameter is the same as [`get_count`].
317    pub async fn get_count_callback_receiver(&mut self) -> impl Stream<Item = u32> {
318        self.device
319            .get_callback_receiver(u8::from(Xmc1400BreakoutBrickletFunction::CallbackCount))
320            .await
321            .map(|p| u32::from_le_byte_slice(p.body()))
322    }
323
324    /// Example for a setter function. The values are the values that can be given to
325    /// the XMC_GPIO_Init function. See communication.c in the firmware.
326    ///
327    /// Associated constants:
328    /// * XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_TRISTATE
329    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_PULL_DOWN
330    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_PULL_UP
331    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_SAMPLING
332    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_INVERTED_TRISTATE
333    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_INVERTED_PULL_DOWN
334    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_INVERTED_PULL_UP
335    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_INPUT_INVERTED_SAMPLING
336    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_OUTPUT_PUSH_PULL
337    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_MODE_OUTPUT_OPEN_DRAIN
338    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_INPUT_HYSTERESIS_STANDARD
339    ///	* XMC1400_BREAKOUT_BRICKLET_GPIO_INPUT_HYSTERESIS_LARGE
340    pub async fn set_gpio_config(
341        &mut self,
342        port: u8,
343        pin: u8,
344        mode: u8,
345        input_hysteresis: u8,
346        output_level: bool,
347    ) -> Result<(), TinkerforgeError> {
348        let mut payload = [0; 5];
349        port.write_to_slice(&mut payload[0..1]);
350        pin.write_to_slice(&mut payload[1..2]);
351        mode.write_to_slice(&mut payload[2..3]);
352        input_hysteresis.write_to_slice(&mut payload[3..4]);
353        output_level.write_to_slice(&mut payload[4..5]);
354
355        #[allow(unused_variables)]
356        let result = self.device.set(u8::from(Xmc1400BreakoutBrickletFunction::SetGpioConfig), &payload).await?;
357        Ok(())
358    }
359
360    /// Example for a getter function. Returns the result of a
361    /// XMC_GPIO_GetInput call for the given port/pin.
362    pub async fn get_gpio_input(&mut self, port: u8, pin: u8) -> Result<bool, TinkerforgeError> {
363        let mut payload = [0; 2];
364        port.write_to_slice(&mut payload[0..1]);
365        pin.write_to_slice(&mut payload[1..2]);
366
367        #[allow(unused_variables)]
368        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetGpioInput), &payload).await?;
369        Ok(bool::from_le_byte_slice(result.body()))
370    }
371
372    /// Enables a ADC channel for the ADC driver example (adc.c/adc.h).
373    ///
374    /// There are 8 ADC channels and they correspond to the following pins:
375    ///
376    /// * Channel 0: P2_6
377    /// * Channel 1: P2_8
378    /// * Channel 2: P2_9
379    /// * Channel 3: P2_10
380    /// * Channel 4: P2_11
381    /// * Channel 5: P2_0
382    /// * Channel 6: P2_1
383    /// * Channel 7: P2_2
384    pub async fn set_adc_channel_config(&mut self, channel: u8, enable: bool) -> Result<(), TinkerforgeError> {
385        let mut payload = [0; 2];
386        channel.write_to_slice(&mut payload[0..1]);
387        enable.write_to_slice(&mut payload[1..2]);
388
389        #[allow(unused_variables)]
390        let result = self.device.set(u8::from(Xmc1400BreakoutBrickletFunction::SetAdcChannelConfig), &payload).await?;
391        Ok(())
392    }
393
394    /// Returns the config for the given channel as set by [`set_adc_channel_config`].
395    pub async fn get_adc_channel_config(&mut self, channel: u8) -> Result<bool, TinkerforgeError> {
396        let mut payload = [0; 1];
397        channel.write_to_slice(&mut payload[0..1]);
398
399        #[allow(unused_variables)]
400        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetAdcChannelConfig), &payload).await?;
401        Ok(bool::from_le_byte_slice(result.body()))
402    }
403
404    /// Returns the 12-bit value of the given ADC channel of the ADC driver example.
405    pub async fn get_adc_channel_value(&mut self, channel: u8) -> Result<u16, TinkerforgeError> {
406        let mut payload = [0; 1];
407        channel.write_to_slice(&mut payload[0..1]);
408
409        #[allow(unused_variables)]
410        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetAdcChannelValue), &payload).await?;
411        Ok(u16::from_le_byte_slice(result.body()))
412    }
413
414    /// Returns the values for all 8 ADC channels of the adc driver example.
415    ///
416    /// This example function also has a corresponding receiver.
417    ///
418    /// See [`set_adc_values_callback_configuration`] and [`get_adc_values_callback_receiver`] receiver.
419    pub async fn get_adc_values(&mut self) -> Result<Box<[u16; 8]>, TinkerforgeError> {
420        let payload = [0; 0];
421
422        #[allow(unused_variables)]
423        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetAdcValues), &payload).await?;
424        Ok(Box::<[u16; 8]>::from_le_byte_slice(result.body()))
425    }
426
427    /// The period is the period with which the [`get_adc_values_callback_receiver`]
428    /// receiver is triggered periodically. A value of 0 turns the receiver off.
429    ///
430    /// If the `value has to change`-parameter is set to true, the receiver is only
431    /// triggered after the value has changed. If the value didn't change within the
432    /// period, the receiver is triggered immediately on change.
433    ///
434    /// If it is set to false, the receiver is continuously triggered with the period,
435    /// independent of the value.
436    pub async fn set_adc_values_callback_configuration(&mut self, period: u32, value_has_to_change: bool) -> Result<(), TinkerforgeError> {
437        let mut payload = [0; 5];
438        period.write_to_slice(&mut payload[0..4]);
439        value_has_to_change.write_to_slice(&mut payload[4..5]);
440
441        #[allow(unused_variables)]
442        let result = self.device.set(u8::from(Xmc1400BreakoutBrickletFunction::SetAdcValuesCallbackConfiguration), &payload).await?;
443        Ok(())
444    }
445
446    /// Returns the receiver configuration as set by
447    /// [`set_adc_values_callback_configuration`].
448    pub async fn get_adc_values_callback_configuration(&mut self) -> Result<AdcValuesCallbackConfiguration, TinkerforgeError> {
449        let payload = [0; 0];
450
451        #[allow(unused_variables)]
452        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetAdcValuesCallbackConfiguration), &payload).await?;
453        Ok(AdcValuesCallbackConfiguration::from_le_byte_slice(result.body()))
454    }
455
456    /// Returns the value of the example count (see example.c).
457    ///
458    /// This example function uses the add_callback_value_function-helper in the
459    /// generator. The getter as well as the receiver and receiver configuration
460    /// functions are auto-generated for the API as well as the firmware.
461    ///
462    ///
463    /// If you want to get the value periodically, it is recommended to use the
464    /// [`get_count_callback_receiver`] receiver. You can set the receiver configuration
465    /// with [`set_count_callback_configuration`].
466    pub async fn get_count(&mut self) -> Result<u32, TinkerforgeError> {
467        let payload = [0; 0];
468
469        #[allow(unused_variables)]
470        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetCount), &payload).await?;
471        Ok(u32::from_le_byte_slice(result.body()))
472    }
473
474    /// The period is the period with which the [`get_count_callback_receiver`] receiver is triggered
475    /// periodically. A value of 0 turns the receiver off.
476    ///
477    /// If the `value has to change`-parameter is set to true, the receiver is only
478    /// triggered after the value has changed. If the value didn't change
479    /// within the period, the receiver is triggered immediately on change.
480    ///
481    /// If it is set to false, the receiver is continuously triggered with the period,
482    /// independent of the value.
483    ///
484    /// It is furthermore possible to constrain the receiver with thresholds.
485    ///
486    /// The `option`-parameter together with min/max sets a threshold for the [`get_count_callback_receiver`] receiver.
487    ///
488    /// The following options are possible:
489    ///
490    ///  Option| Description
491    ///  --- | ---
492    ///  'x'|    Threshold is turned off
493    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
494    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
495    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
496    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
497    ///
498    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
499    ///
500    /// Associated constants:
501    /// * XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_OFF
502    ///	* XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_OUTSIDE
503    ///	* XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_INSIDE
504    ///	* XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_SMALLER
505    ///	* XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_GREATER
506    pub async fn set_count_callback_configuration(
507        &mut self,
508        period: u32,
509        value_has_to_change: bool,
510        option: char,
511        min: u32,
512        max: u32,
513    ) -> Result<(), TinkerforgeError> {
514        let mut payload = [0; 14];
515        period.write_to_slice(&mut payload[0..4]);
516        value_has_to_change.write_to_slice(&mut payload[4..5]);
517        option.write_to_slice(&mut payload[5..6]);
518        min.write_to_slice(&mut payload[6..10]);
519        max.write_to_slice(&mut payload[10..14]);
520
521        #[allow(unused_variables)]
522        let result = self.device.set(u8::from(Xmc1400BreakoutBrickletFunction::SetCountCallbackConfiguration), &payload).await?;
523        Ok(())
524    }
525
526    /// Returns the receiver configuration as set by [`set_count_callback_configuration`].
527    ///
528    /// Associated constants:
529    /// * XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_OFF
530    ///	* XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_OUTSIDE
531    ///	* XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_INSIDE
532    ///	* XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_SMALLER
533    ///	* XMC1400_BREAKOUT_BRICKLET_THRESHOLD_OPTION_GREATER
534    pub async fn get_count_callback_configuration(&mut self) -> Result<CountCallbackConfiguration, TinkerforgeError> {
535        let payload = [0; 0];
536
537        #[allow(unused_variables)]
538        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetCountCallbackConfiguration), &payload).await?;
539        Ok(CountCallbackConfiguration::from_le_byte_slice(result.body()))
540    }
541
542    /// Returns the error count for the communication between Brick and Bricklet.
543    ///
544    /// The errors are divided into
545    ///
546    /// * ACK checksum errors,
547    /// * message checksum errors,
548    /// * framing errors and
549    /// * overflow errors.
550    ///
551    /// The errors counts are for errors that occur on the Bricklet side. All
552    /// Bricks have a similar function that returns the errors on the Brick side.
553    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
554        let payload = [0; 0];
555
556        #[allow(unused_variables)]
557        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetSpitfpErrorCount), &payload).await?;
558        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
559    }
560
561    /// Sets the bootloader mode and returns the status after the requested
562    /// mode change was instigated.
563    ///
564    /// You can change from bootloader mode to firmware mode and vice versa. A change
565    /// from bootloader mode to firmware mode will only take place if the entry function,
566    /// device identifier and CRC are present and correct.
567    ///
568    /// This function is used by Brick Viewer during flashing. It should not be
569    /// necessary to call it in a normal user program.
570    ///
571    /// Associated constants:
572    /// * XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
573    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE
574    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
575    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
576    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
577    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_OK
578    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
579    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
580    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
581    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
582    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
583    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
584        let mut payload = [0; 1];
585        mode.write_to_slice(&mut payload[0..1]);
586
587        #[allow(unused_variables)]
588        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::SetBootloaderMode), &payload).await?;
589        Ok(u8::from_le_byte_slice(result.body()))
590    }
591
592    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
593    ///
594    /// Associated constants:
595    /// * XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
596    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE
597    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
598    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
599    ///	* XMC1400_BREAKOUT_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
600    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
601        let payload = [0; 0];
602
603        #[allow(unused_variables)]
604        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetBootloaderMode), &payload).await?;
605        Ok(u8::from_le_byte_slice(result.body()))
606    }
607
608    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
609    /// to be increased by chunks of size 64. The data is written to flash
610    /// every 4 chunks (which equals to one page of size 256).
611    ///
612    /// This function is used by Brick Viewer during flashing. It should not be
613    /// necessary to call it in a normal user program.
614    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
615        let mut payload = [0; 4];
616        pointer.write_to_slice(&mut payload[0..4]);
617
618        #[allow(unused_variables)]
619        let result = self.device.set(u8::from(Xmc1400BreakoutBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
620        Ok(())
621    }
622
623    /// Writes 64 Bytes of firmware at the position as written by
624    /// [`set_write_firmware_pointer`] before. The firmware is written
625    /// to flash every 4 chunks.
626    ///
627    /// You can only write firmware in bootloader mode.
628    ///
629    /// This function is used by Brick Viewer during flashing. It should not be
630    /// necessary to call it in a normal user program.
631    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
632        let mut payload = [0; 64];
633        data.write_to_slice(&mut payload[0..64]);
634
635        #[allow(unused_variables)]
636        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::WriteFirmware), &payload).await?;
637        Ok(u8::from_le_byte_slice(result.body()))
638    }
639
640    /// Sets the status LED configuration. By default the LED shows
641    /// communication traffic between Brick and Bricklet, it flickers once
642    /// for every 10 received data packets.
643    ///
644    /// You can also turn the LED permanently on/off or show a heartbeat.
645    ///
646    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
647    ///
648    /// Associated constants:
649    /// * XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_OFF
650    ///	* XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_ON
651    ///	* XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
652    ///	* XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
653    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
654        let mut payload = [0; 1];
655        config.write_to_slice(&mut payload[0..1]);
656
657        #[allow(unused_variables)]
658        let result = self.device.set(u8::from(Xmc1400BreakoutBrickletFunction::SetStatusLedConfig), &payload).await?;
659        Ok(())
660    }
661
662    /// Returns the configuration as set by [`set_status_led_config`]
663    ///
664    /// Associated constants:
665    /// * XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_OFF
666    ///	* XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_ON
667    ///	* XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
668    ///	* XMC1400_BREAKOUT_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
669    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
670        let payload = [0; 0];
671
672        #[allow(unused_variables)]
673        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetStatusLedConfig), &payload).await?;
674        Ok(u8::from_le_byte_slice(result.body()))
675    }
676
677    /// Returns the temperature as measured inside the microcontroller. The
678    /// value returned is not the ambient temperature!
679    ///
680    /// The temperature is only proportional to the real temperature and it has bad
681    /// accuracy. Practically it is only useful as an indicator for
682    /// temperature changes.
683    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
684        let payload = [0; 0];
685
686        #[allow(unused_variables)]
687        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetChipTemperature), &payload).await?;
688        Ok(i16::from_le_byte_slice(result.body()))
689    }
690
691    /// Calling this function will reset the Bricklet. All configurations
692    /// will be lost.
693    ///
694    /// After a reset you have to create new device objects,
695    /// calling functions on the existing ones will result in
696    /// undefined behavior!
697    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
698        let payload = [0; 0];
699
700        #[allow(unused_variables)]
701        let result = self.device.set(u8::from(Xmc1400BreakoutBrickletFunction::Reset), &payload).await?;
702        Ok(())
703    }
704
705    /// Writes a new UID into flash. If you want to set a new UID
706    /// you have to decode the Base58 encoded UID string into an
707    /// integer first.
708    ///
709    /// We recommend that you use Brick Viewer to change the UID.
710    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
711        let mut payload = [0; 4];
712        uid.write_to_slice(&mut payload[0..4]);
713
714        #[allow(unused_variables)]
715        let result = self.device.set(u8::from(Xmc1400BreakoutBrickletFunction::WriteUid), &payload).await?;
716        Ok(())
717    }
718
719    /// Returns the current UID as an integer. Encode as
720    /// Base58 to get the usual string version.
721    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
722        let payload = [0; 0];
723
724        #[allow(unused_variables)]
725        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::ReadUid), &payload).await?;
726        Ok(u32::from_le_byte_slice(result.body()))
727    }
728
729    /// Returns the UID, the UID where the Bricklet is connected to,
730    /// the position, the hardware and firmware version as well as the
731    /// device identifier.
732    ///
733    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
734    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
735    /// position 'z'.
736    ///
737    /// The device identifier numbers can be found [here](device_identifier).
738    /// |device_identifier_constant|
739    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
740        let payload = [0; 0];
741
742        #[allow(unused_variables)]
743        let result = self.device.get(u8::from(Xmc1400BreakoutBrickletFunction::GetIdentity), &payload).await?;
744        Ok(Identity::from_le_byte_slice(result.body()))
745    }
746}