From 849a1b38db34dba9a08f7ecb5368f633e5880e7a Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Sun, 28 Jun 2026 14:24:57 +0900 Subject: [PATCH] feat: Use enum for duty ratio --- src/sound.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sound.rs b/src/sound.rs index 3834d882..fafe5606 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -13,13 +13,23 @@ impl SweepControl { u8_int_field!(4 - 6, sweep_time, with_sweep_time); } +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[repr(u16)] +pub enum DutyRatio { + _12_5 = 0, + _25 = 1, + #[default] + _50 = 2, + _75 = 3, +} + #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct TonePattern(u16); impl TonePattern { pub_const_fn_new_zeroed!(); u16_int_field!(0 - 5, length, with_length); - u16_int_field!(6 - 7, duty, with_duty); + u16_enum_field!(6 - 7: DutyRatio, duty, with_duty); u16_int_field!(8 - 10, step_time, with_step_time); u16_bool_field!(11, step_increasing, with_step_increasing); u16_int_field!(12 - 15, volume, with_volume);