#[doc = "Register `PWM` reader"]
pub struct R(crate::R<PWM_SPEC>);
impl core::ops::Deref for R {
    type Target = crate::R<PWM_SPEC>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl core::convert::From<crate::R<PWM_SPEC>> for R {
    fn from(reader: crate::R<PWM_SPEC>) -> Self {
        R(reader)
    }
}
#[doc = "Register `PWM` writer"]
pub struct W(crate::W<PWM_SPEC>);
impl core::ops::Deref for W {
    type Target = crate::W<PWM_SPEC>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl core::ops::DerefMut for W {
    #[inline(always)]
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}
impl core::convert::From<crate::W<PWM_SPEC>> for W {
    fn from(writer: crate::W<PWM_SPEC>) -> Self {
        W(writer)
    }
}
#[doc = "Field `PWM_COUNT` reader - The length of the modulation pulse in clk_csd2 cycles."]
pub struct PWM_COUNT_R(crate::FieldReader<u8, u8>);
impl PWM_COUNT_R {
    pub(crate) fn new(bits: u8) -> Self {
        PWM_COUNT_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for PWM_COUNT_R {
    type Target = crate::FieldReader<u8, u8>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `PWM_COUNT` writer - The length of the modulation pulse in clk_csd2 cycles."]
pub struct PWM_COUNT_W<'a> {
    w: &'a mut W,
}
impl<'a> PWM_COUNT_W<'a> {
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub unsafe fn bits(self, value: u8) -> &'a mut W {
        self.w.bits = (self.w.bits & !0x0f) | (value as u32 & 0x0f);
        self.w
    }
}
#[doc = "The mode of the PWM modulator\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(u8)]
pub enum PWM_SEL_A {
    #[doc = "0: No description available"]
    OFF = 0,
    #[doc = "2: No description available"]
    FIXED_HIGH = 2,
    #[doc = "3: No description available"]
    FIXED_LOW = 3,
}
impl From<PWM_SEL_A> for u8 {
    #[inline(always)]
    fn from(variant: PWM_SEL_A) -> Self {
        variant as _
    }
}
#[doc = "Field `PWM_SEL` reader - The mode of the PWM modulator"]
pub struct PWM_SEL_R(crate::FieldReader<u8, PWM_SEL_A>);
impl PWM_SEL_R {
    pub(crate) fn new(bits: u8) -> Self {
        PWM_SEL_R(crate::FieldReader::new(bits))
    }
    #[doc = r"Get enumerated values variant"]
    #[inline(always)]
    pub fn variant(&self) -> Option<PWM_SEL_A> {
        match self.bits {
            0 => Some(PWM_SEL_A::OFF),
            2 => Some(PWM_SEL_A::FIXED_HIGH),
            3 => Some(PWM_SEL_A::FIXED_LOW),
            _ => None,
        }
    }
    #[doc = "Checks if the value of the field is `OFF`"]
    #[inline(always)]
    pub fn is_off(&self) -> bool {
        **self == PWM_SEL_A::OFF
    }
    #[doc = "Checks if the value of the field is `FIXED_HIGH`"]
    #[inline(always)]
    pub fn is_fixed_high(&self) -> bool {
        **self == PWM_SEL_A::FIXED_HIGH
    }
    #[doc = "Checks if the value of the field is `FIXED_LOW`"]
    #[inline(always)]
    pub fn is_fixed_low(&self) -> bool {
        **self == PWM_SEL_A::FIXED_LOW
    }
}
impl core::ops::Deref for PWM_SEL_R {
    type Target = crate::FieldReader<u8, PWM_SEL_A>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `PWM_SEL` writer - The mode of the PWM modulator"]
pub struct PWM_SEL_W<'a> {
    w: &'a mut W,
}
impl<'a> PWM_SEL_W<'a> {
    #[doc = r"Writes `variant` to the field"]
    #[inline(always)]
    pub fn variant(self, variant: PWM_SEL_A) -> &'a mut W {
        unsafe { self.bits(variant.into()) }
    }
    #[doc = "No description available"]
    #[inline(always)]
    pub fn off(self) -> &'a mut W {
        self.variant(PWM_SEL_A::OFF)
    }
    #[doc = "No description available"]
    #[inline(always)]
    pub fn fixed_high(self) -> &'a mut W {
        self.variant(PWM_SEL_A::FIXED_HIGH)
    }
    #[doc = "No description available"]
    #[inline(always)]
    pub fn fixed_low(self) -> &'a mut W {
        self.variant(PWM_SEL_A::FIXED_LOW)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub unsafe fn bits(self, value: u8) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x03 << 4)) | ((value as u32 & 0x03) << 4);
        self.w
    }
}
impl R {
    #[doc = "Bits 0:3 - The length of the modulation pulse in clk_csd2 cycles."]
    #[inline(always)]
    pub fn pwm_count(&self) -> PWM_COUNT_R {
        PWM_COUNT_R::new((self.bits & 0x0f) as u8)
    }
    #[doc = "Bits 4:5 - The mode of the PWM modulator"]
    #[inline(always)]
    pub fn pwm_sel(&self) -> PWM_SEL_R {
        PWM_SEL_R::new(((self.bits >> 4) & 0x03) as u8)
    }
}
impl W {
    #[doc = "Bits 0:3 - The length of the modulation pulse in clk_csd2 cycles."]
    #[inline(always)]
    pub fn pwm_count(&mut self) -> PWM_COUNT_W {
        PWM_COUNT_W { w: self }
    }
    #[doc = "Bits 4:5 - The mode of the PWM modulator"]
    #[inline(always)]
    pub fn pwm_sel(&mut self) -> PWM_SEL_W {
        PWM_SEL_W { w: self }
    }
    #[doc = "Writes raw bits to the register."]
    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
        self.0.bits(bits);
        self
    }
}
#[doc = "CSD PWM Register\n\nThis register you can [`read`](crate::generic::Reg::read), [`write_with_zero`](crate::generic::Reg::write_with_zero), [`reset`](crate::generic::Reg::reset), [`write`](crate::generic::Reg::write), [`modify`](crate::generic::Reg::modify). See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [pwm](index.html) module"]
pub struct PWM_SPEC;
impl crate::RegisterSpec for PWM_SPEC {
    type Ux = u32;
}
#[doc = "`read()` method returns [pwm::R](R) reader structure"]
impl crate::Readable for PWM_SPEC {
    type Reader = R;
}
#[doc = "`write(|w| ..)` method takes [pwm::W](W) writer structure"]
impl crate::Writable for PWM_SPEC {
    type Writer = W;
}
#[doc = "`reset()` method sets PWM to value 0"]
impl crate::Resettable for PWM_SPEC {
    #[inline(always)]
    fn reset_value() -> Self::Ux {
        0
    }
}
