Common rust source for both rust driver and userland code.
use core::intrinsics::transmute;
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub enum Partnum {
CC1121,
CC1120,
CC1125,
CC1175,
Invalid,
}
impl From<u8> for Partnum {
fn from(val: u8) -> Partnum {
match val {
0x40 => Partnum::CC1121,
0x48 => Partnum::CC1120,
0x58 => Partnum::CC1125,
0x5A => Partnum::CC1175,
_ => Partnum::Invalid,
}
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub enum Command {
Supported = 0,
Partnum = 1,
NotSupported,
}
impl From<Command> for usize {
fn from(cmd: Command) -> usize {
unsafe { transmute(cmd) }
}
}
impl From<usize> for Command {
fn from(val: usize) -> Command {
match val {
0 => Command::Supported,
1 => Command::Partnum,
_ => Command::NotSupported,
}
}
}
Generated c header:
#ifndef cheddar_generated_cc112x_h
#define cheddar_generated_cc112x_h
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
typedef enum Partnum {
Partnum_CC1121,
Partnum_CC1120,
Partnum_CC1125,
Partnum_CC1175,
Partnum_Invalid,
} Partnum;
typedef enum Command {
Command_Supported = 0,
Command_Partnum = 1,
Command_NotSupported,
} Command;
#ifdef __cplusplus
}
#endif
#endif