i2c.apply(.{
.baud_rate = .khz(100),
});
// POC implementation
const Frequency = enum(u32) {
_,
pub fn hz(value: u32) Frequency {
return @enumFromInt(value);
}
pub fn khz(value: u32) Frequency {
return @enumFromInt(value * 1_000);
}
pub fn mhz(value: u32) Frequency {
// what to do about overflows? Though I think it's fine to assert that the result must fit into u32.
return @enumFromInt(value * 1_000_000);
}
};
This would be used for baud rates, etc.
Something like this can be applied for other measures as well (apart from Frequency). In what other places can we use decl literals for more verbose initializations?
This would be used for baud rates, etc.
Something like this can be applied for other measures as well (apart from
Frequency). In what other places can we use decl literals for more verbose initializations?