#[doc = "Register `CHGDET_CTRL` reader"]
pub struct R(crate::R<CHGDET_CTRL_SPEC>);
impl core::ops::Deref for R {
    type Target = crate::R<CHGDET_CTRL_SPEC>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl core::convert::From<crate::R<CHGDET_CTRL_SPEC>> for R {
    fn from(reader: crate::R<CHGDET_CTRL_SPEC>) -> Self {
        R(reader)
    }
}
#[doc = "Register `CHGDET_CTRL` writer"]
pub struct W(crate::W<CHGDET_CTRL_SPEC>);
impl core::ops::Deref for W {
    type Target = crate::W<CHGDET_CTRL_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<CHGDET_CTRL_SPEC>> for W {
    fn from(writer: crate::W<CHGDET_CTRL_SPEC>) -> Self {
        W(writer)
    }
}
#[doc = "Field `COMP_DP` reader - Connect the primary/secondary detection comparator and current sink to D+"]
pub struct COMP_DP_R(crate::FieldReader<bool, bool>);
impl COMP_DP_R {
    pub(crate) fn new(bits: bool) -> Self {
        COMP_DP_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for COMP_DP_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `COMP_DP` writer - Connect the primary/secondary detection comparator and current sink to D+"]
pub struct COMP_DP_W<'a> {
    w: &'a mut W,
}
impl<'a> COMP_DP_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !0x01) | (value as u32 & 0x01);
        self.w
    }
}
#[doc = "Field `COMP_DM` reader - Connect the primary/secondary detection comparator and current sink to D-"]
pub struct COMP_DM_R(crate::FieldReader<bool, bool>);
impl COMP_DM_R {
    pub(crate) fn new(bits: bool) -> Self {
        COMP_DM_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for COMP_DM_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `COMP_DM` writer - Connect the primary/secondary detection comparator and current sink to D-"]
pub struct COMP_DM_W<'a> {
    w: &'a mut W,
}
impl<'a> COMP_DM_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x01 << 1)) | ((value as u32 & 0x01) << 1);
        self.w
    }
}
#[doc = "Field `COMP_EN` reader - Enable the primary/secondary detection comparator and current sink. This bit can be written concurrently with COMP_DP/COMP_DM. Note that REF_EN must also be 1 for the comparator to work (because it receives a reference from it)."]
pub struct COMP_EN_R(crate::FieldReader<bool, bool>);
impl COMP_EN_R {
    pub(crate) fn new(bits: bool) -> Self {
        COMP_EN_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for COMP_EN_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `COMP_EN` writer - Enable the primary/secondary detection comparator and current sink. This bit can be written concurrently with COMP_DP/COMP_DM. Note that REF_EN must also be 1 for the comparator to work (because it receives a reference from it)."]
pub struct COMP_EN_W<'a> {
    w: &'a mut W,
}
impl<'a> COMP_EN_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x01 << 2)) | ((value as u32 & 0x01) << 2);
        self.w
    }
}
#[doc = "Field `REF_DP` reader - Connect the primary/secondary detection reference driver to D+"]
pub struct REF_DP_R(crate::FieldReader<bool, bool>);
impl REF_DP_R {
    pub(crate) fn new(bits: bool) -> Self {
        REF_DP_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for REF_DP_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `REF_DP` writer - Connect the primary/secondary detection reference driver to D+"]
pub struct REF_DP_W<'a> {
    w: &'a mut W,
}
impl<'a> REF_DP_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x01 << 3)) | ((value as u32 & 0x01) << 3);
        self.w
    }
}
#[doc = "Field `REF_DM` reader - Connect the primary/secondary detection reference driver to D-"]
pub struct REF_DM_R(crate::FieldReader<bool, bool>);
impl REF_DM_R {
    pub(crate) fn new(bits: bool) -> Self {
        REF_DM_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for REF_DM_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `REF_DM` writer - Connect the primary/secondary detection reference driver to D-"]
pub struct REF_DM_W<'a> {
    w: &'a mut W,
}
impl<'a> REF_DM_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x01 << 4)) | ((value as u32 & 0x01) << 4);
        self.w
    }
}
#[doc = "Field `REF_EN` reader - Enable the primary/secondary reference driver. This bit can be written concurrently with REF_DP/REF_DM."]
pub struct REF_EN_R(crate::FieldReader<bool, bool>);
impl REF_EN_R {
    pub(crate) fn new(bits: bool) -> Self {
        REF_EN_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for REF_EN_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `REF_EN` writer - Enable the primary/secondary reference driver. This bit can be written concurrently with REF_DP/REF_DM."]
pub struct REF_EN_W<'a> {
    w: &'a mut W,
}
impl<'a> REF_EN_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x01 << 5)) | ((value as u32 & 0x01) << 5);
        self.w
    }
}
#[doc = "Field `DCD_SRC_EN` reader - Enable the Data Contact Detect current source on D+"]
pub struct DCD_SRC_EN_R(crate::FieldReader<bool, bool>);
impl DCD_SRC_EN_R {
    pub(crate) fn new(bits: bool) -> Self {
        DCD_SRC_EN_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for DCD_SRC_EN_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `DCD_SRC_EN` writer - Enable the Data Contact Detect current source on D+"]
pub struct DCD_SRC_EN_W<'a> {
    w: &'a mut W,
}
impl<'a> DCD_SRC_EN_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x01 << 6)) | ((value as u32 & 0x01) << 6);
        self.w
    }
}
#[doc = "ADFT option to bring out buffered version of voltage reference input or adft intput to ADFT output (adft_out).\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(u8)]
pub enum ADFT_CTRL_A {
    #[doc = "0: No description available"]
    ADFT_NORMAL = 0,
    #[doc = "1: No description available"]
    ADFT_VBG = 1,
    #[doc = "2: No description available"]
    ADFT_DONTUSE = 2,
    #[doc = "3: No description available"]
    ADFT_ADFTIN = 3,
}
impl From<ADFT_CTRL_A> for u8 {
    #[inline(always)]
    fn from(variant: ADFT_CTRL_A) -> Self {
        variant as _
    }
}
#[doc = "Field `ADFT_CTRL` reader - ADFT option to bring out buffered version of voltage reference input or adft intput to ADFT output (adft_out)."]
pub struct ADFT_CTRL_R(crate::FieldReader<u8, ADFT_CTRL_A>);
impl ADFT_CTRL_R {
    pub(crate) fn new(bits: u8) -> Self {
        ADFT_CTRL_R(crate::FieldReader::new(bits))
    }
    #[doc = r"Get enumerated values variant"]
    #[inline(always)]
    pub fn variant(&self) -> ADFT_CTRL_A {
        match self.bits {
            0 => ADFT_CTRL_A::ADFT_NORMAL,
            1 => ADFT_CTRL_A::ADFT_VBG,
            2 => ADFT_CTRL_A::ADFT_DONTUSE,
            3 => ADFT_CTRL_A::ADFT_ADFTIN,
            _ => unreachable!(),
        }
    }
    #[doc = "Checks if the value of the field is `ADFT_NORMAL`"]
    #[inline(always)]
    pub fn is_adft_normal(&self) -> bool {
        **self == ADFT_CTRL_A::ADFT_NORMAL
    }
    #[doc = "Checks if the value of the field is `ADFT_VBG`"]
    #[inline(always)]
    pub fn is_adft_vbg(&self) -> bool {
        **self == ADFT_CTRL_A::ADFT_VBG
    }
    #[doc = "Checks if the value of the field is `ADFT_DONTUSE`"]
    #[inline(always)]
    pub fn is_adft_dontuse(&self) -> bool {
        **self == ADFT_CTRL_A::ADFT_DONTUSE
    }
    #[doc = "Checks if the value of the field is `ADFT_ADFTIN`"]
    #[inline(always)]
    pub fn is_adft_adftin(&self) -> bool {
        **self == ADFT_CTRL_A::ADFT_ADFTIN
    }
}
impl core::ops::Deref for ADFT_CTRL_R {
    type Target = crate::FieldReader<u8, ADFT_CTRL_A>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `ADFT_CTRL` writer - ADFT option to bring out buffered version of voltage reference input or adft intput to ADFT output (adft_out)."]
pub struct ADFT_CTRL_W<'a> {
    w: &'a mut W,
}
impl<'a> ADFT_CTRL_W<'a> {
    #[doc = r"Writes `variant` to the field"]
    #[inline(always)]
    pub fn variant(self, variant: ADFT_CTRL_A) -> &'a mut W {
        self.bits(variant.into())
    }
    #[doc = "No description available"]
    #[inline(always)]
    pub fn adft_normal(self) -> &'a mut W {
        self.variant(ADFT_CTRL_A::ADFT_NORMAL)
    }
    #[doc = "No description available"]
    #[inline(always)]
    pub fn adft_vbg(self) -> &'a mut W {
        self.variant(ADFT_CTRL_A::ADFT_VBG)
    }
    #[doc = "No description available"]
    #[inline(always)]
    pub fn adft_dontuse(self) -> &'a mut W {
        self.variant(ADFT_CTRL_A::ADFT_DONTUSE)
    }
    #[doc = "No description available"]
    #[inline(always)]
    pub fn adft_adftin(self) -> &'a mut W {
        self.variant(ADFT_CTRL_A::ADFT_ADFTIN)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bits(self, value: u8) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x03 << 12)) | ((value as u32 & 0x03) << 12);
        self.w
    }
}
#[doc = "Field `COMP_OUT` reader - Output of the primary/secondary detection comparator. This output is not filtered or debounced and must be polled in software."]
pub struct COMP_OUT_R(crate::FieldReader<bool, bool>);
impl COMP_OUT_R {
    pub(crate) fn new(bits: bool) -> Self {
        COMP_OUT_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for COMP_OUT_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl R {
    #[doc = "Bit 0 - Connect the primary/secondary detection comparator and current sink to D+"]
    #[inline(always)]
    pub fn comp_dp(&self) -> COMP_DP_R {
        COMP_DP_R::new((self.bits & 0x01) != 0)
    }
    #[doc = "Bit 1 - Connect the primary/secondary detection comparator and current sink to D-"]
    #[inline(always)]
    pub fn comp_dm(&self) -> COMP_DM_R {
        COMP_DM_R::new(((self.bits >> 1) & 0x01) != 0)
    }
    #[doc = "Bit 2 - Enable the primary/secondary detection comparator and current sink. This bit can be written concurrently with COMP_DP/COMP_DM. Note that REF_EN must also be 1 for the comparator to work (because it receives a reference from it)."]
    #[inline(always)]
    pub fn comp_en(&self) -> COMP_EN_R {
        COMP_EN_R::new(((self.bits >> 2) & 0x01) != 0)
    }
    #[doc = "Bit 3 - Connect the primary/secondary detection reference driver to D+"]
    #[inline(always)]
    pub fn ref_dp(&self) -> REF_DP_R {
        REF_DP_R::new(((self.bits >> 3) & 0x01) != 0)
    }
    #[doc = "Bit 4 - Connect the primary/secondary detection reference driver to D-"]
    #[inline(always)]
    pub fn ref_dm(&self) -> REF_DM_R {
        REF_DM_R::new(((self.bits >> 4) & 0x01) != 0)
    }
    #[doc = "Bit 5 - Enable the primary/secondary reference driver. This bit can be written concurrently with REF_DP/REF_DM."]
    #[inline(always)]
    pub fn ref_en(&self) -> REF_EN_R {
        REF_EN_R::new(((self.bits >> 5) & 0x01) != 0)
    }
    #[doc = "Bit 6 - Enable the Data Contact Detect current source on D+"]
    #[inline(always)]
    pub fn dcd_src_en(&self) -> DCD_SRC_EN_R {
        DCD_SRC_EN_R::new(((self.bits >> 6) & 0x01) != 0)
    }
    #[doc = "Bits 12:13 - ADFT option to bring out buffered version of voltage reference input or adft intput to ADFT output (adft_out)."]
    #[inline(always)]
    pub fn adft_ctrl(&self) -> ADFT_CTRL_R {
        ADFT_CTRL_R::new(((self.bits >> 12) & 0x03) as u8)
    }
    #[doc = "Bit 31 - Output of the primary/secondary detection comparator. This output is not filtered or debounced and must be polled in software."]
    #[inline(always)]
    pub fn comp_out(&self) -> COMP_OUT_R {
        COMP_OUT_R::new(((self.bits >> 31) & 0x01) != 0)
    }
}
impl W {
    #[doc = "Bit 0 - Connect the primary/secondary detection comparator and current sink to D+"]
    #[inline(always)]
    pub fn comp_dp(&mut self) -> COMP_DP_W {
        COMP_DP_W { w: self }
    }
    #[doc = "Bit 1 - Connect the primary/secondary detection comparator and current sink to D-"]
    #[inline(always)]
    pub fn comp_dm(&mut self) -> COMP_DM_W {
        COMP_DM_W { w: self }
    }
    #[doc = "Bit 2 - Enable the primary/secondary detection comparator and current sink. This bit can be written concurrently with COMP_DP/COMP_DM. Note that REF_EN must also be 1 for the comparator to work (because it receives a reference from it)."]
    #[inline(always)]
    pub fn comp_en(&mut self) -> COMP_EN_W {
        COMP_EN_W { w: self }
    }
    #[doc = "Bit 3 - Connect the primary/secondary detection reference driver to D+"]
    #[inline(always)]
    pub fn ref_dp(&mut self) -> REF_DP_W {
        REF_DP_W { w: self }
    }
    #[doc = "Bit 4 - Connect the primary/secondary detection reference driver to D-"]
    #[inline(always)]
    pub fn ref_dm(&mut self) -> REF_DM_W {
        REF_DM_W { w: self }
    }
    #[doc = "Bit 5 - Enable the primary/secondary reference driver. This bit can be written concurrently with REF_DP/REF_DM."]
    #[inline(always)]
    pub fn ref_en(&mut self) -> REF_EN_W {
        REF_EN_W { w: self }
    }
    #[doc = "Bit 6 - Enable the Data Contact Detect current source on D+"]
    #[inline(always)]
    pub fn dcd_src_en(&mut self) -> DCD_SRC_EN_W {
        DCD_SRC_EN_W { w: self }
    }
    #[doc = "Bits 12:13 - ADFT option to bring out buffered version of voltage reference input or adft intput to ADFT output (adft_out)."]
    #[inline(always)]
    pub fn adft_ctrl(&mut self) -> ADFT_CTRL_W {
        ADFT_CTRL_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 = "Charger Detection Control 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 [chgdet_ctrl](index.html) module"]
pub struct CHGDET_CTRL_SPEC;
impl crate::RegisterSpec for CHGDET_CTRL_SPEC {
    type Ux = u32;
}
#[doc = "`read()` method returns [chgdet_ctrl::R](R) reader structure"]
impl crate::Readable for CHGDET_CTRL_SPEC {
    type Reader = R;
}
#[doc = "`write(|w| ..)` method takes [chgdet_ctrl::W](W) writer structure"]
impl crate::Writable for CHGDET_CTRL_SPEC {
    type Writer = W;
}
#[doc = "`reset()` method sets CHGDET_CTRL to value 0"]
impl crate::Resettable for CHGDET_CTRL_SPEC {
    #[inline(always)]
    fn reset_value() -> Self::Ux {
        0
    }
}
