#[doc = "Register `ECR` reader"]
pub struct R(crate::R<ECR_SPEC>);
impl core::ops::Deref for R {
    type Target = crate::R<ECR_SPEC>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl core::convert::From<crate::R<ECR_SPEC>> for R {
    fn from(reader: crate::R<ECR_SPEC>) -> Self {
        R(reader)
    }
}
#[doc = "Register `ECR` writer"]
pub struct W(crate::W<ECR_SPEC>);
impl core::ops::Deref for W {
    type Target = crate::W<ECR_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<ECR_SPEC>> for W {
    fn from(writer: crate::W<ECR_SPEC>) -> Self {
        W(writer)
    }
}
#[doc = "Field `ECR_STATUS` reader - ECR STATUS -?0: ECR register captured an error, or it is in free running mode?1: ECR register is armed"]
pub struct ECR_STATUS_R(crate::FieldReader<bool, bool>);
impl ECR_STATUS_R {
    pub(crate) fn new(bits: bool) -> Self {
        ECR_STATUS_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for ECR_STATUS_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `ECR_STATUS` writer - ECR STATUS -?0: ECR register captured an error, or it is in free running mode?1: ECR register is armed"]
pub struct ECR_STATUS_W<'a> {
    w: &'a mut W,
}
impl<'a> ECR_STATUS_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 `ERROR_TYPE` reader - Error type -?000 : Arbitration loss?001 : Bit Error?010 : Bit Stuffing Error?011 : Acknowledge Error?100 : Form Error?101 : CRC Error?Others : N/A"]
pub struct ERROR_TYPE_R(crate::FieldReader<u8, u8>);
impl ERROR_TYPE_R {
    pub(crate) fn new(bits: u8) -> Self {
        ERROR_TYPE_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for ERROR_TYPE_R {
    type Target = crate::FieldReader<u8, u8>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `RX_MODE` reader - RX Mode -?0: No status?1: CAN Controller is receiver"]
pub struct RX_MODE_R(crate::FieldReader<bool, bool>);
impl RX_MODE_R {
    pub(crate) fn new(bits: bool) -> Self {
        RX_MODE_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for RX_MODE_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `TX_MODE` reader - TX Mode -?0: No status?1: CAN Controller is transmitter"]
pub struct TX_MODE_R(crate::FieldReader<bool, bool>);
impl TX_MODE_R {
    pub(crate) fn new(bits: bool) -> Self {
        TX_MODE_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for TX_MODE_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `BIT` reader - Bit number inside of Field"]
pub struct BIT_R(crate::FieldReader<u8, u8>);
impl BIT_R {
    pub(crate) fn new(bits: u8) -> Self {
        BIT_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for BIT_R {
    type Target = crate::FieldReader<u8, u8>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `Field` reader - Field -?0x00 : Stopped?0x01 : Synchronize?0x05 : Interframe?0x06 : Bus Idle?0x07 : Start of Frame?0x08 : Arbitration?0x09 : Control?0x0A : Data?0x0B : CRC?0x0C : ACK?0x0D : End of frame?0x10 : Error flag?0x11 : Error echo?0x12 : Error delimiter?0x18 : Overload flag?0x19 : Overload echo?0x1A : Overload delimiter?Others : N/A"]
pub struct FIELD_R(crate::FieldReader<u8, u8>);
impl FIELD_R {
    pub(crate) fn new(bits: u8) -> Self {
        FIELD_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for FIELD_R {
    type Target = crate::FieldReader<u8, u8>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl R {
    #[doc = "Bit 0 - ECR STATUS -?0: ECR register captured an error, or it is in free running mode?1: ECR register is armed"]
    #[inline(always)]
    pub fn ecr_status(&self) -> ECR_STATUS_R {
        ECR_STATUS_R::new((self.bits & 0x01) != 0)
    }
    #[doc = "Bits 1:3 - Error type -?000 : Arbitration loss?001 : Bit Error?010 : Bit Stuffing Error?011 : Acknowledge Error?100 : Form Error?101 : CRC Error?Others : N/A"]
    #[inline(always)]
    pub fn error_type(&self) -> ERROR_TYPE_R {
        ERROR_TYPE_R::new(((self.bits >> 1) & 0x07) as u8)
    }
    #[doc = "Bit 4 - RX Mode -?0: No status?1: CAN Controller is receiver"]
    #[inline(always)]
    pub fn rx_mode(&self) -> RX_MODE_R {
        RX_MODE_R::new(((self.bits >> 4) & 0x01) != 0)
    }
    #[doc = "Bit 5 - TX Mode -?0: No status?1: CAN Controller is transmitter"]
    #[inline(always)]
    pub fn tx_mode(&self) -> TX_MODE_R {
        TX_MODE_R::new(((self.bits >> 5) & 0x01) != 0)
    }
    #[doc = "Bits 6:11 - Bit number inside of Field"]
    #[inline(always)]
    pub fn bit_(&self) -> BIT_R {
        BIT_R::new(((self.bits >> 6) & 0x3f) as u8)
    }
    #[doc = "Bits 12:16 - Field -?0x00 : Stopped?0x01 : Synchronize?0x05 : Interframe?0x06 : Bus Idle?0x07 : Start of Frame?0x08 : Arbitration?0x09 : Control?0x0A : Data?0x0B : CRC?0x0C : ACK?0x0D : End of frame?0x10 : Error flag?0x11 : Error echo?0x12 : Error delimiter?0x18 : Overload flag?0x19 : Overload echo?0x1A : Overload delimiter?Others : N/A"]
    #[inline(always)]
    pub fn field(&self) -> FIELD_R {
        FIELD_R::new(((self.bits >> 12) & 0x1f) as u8)
    }
}
impl W {
    #[doc = "Bit 0 - ECR STATUS -?0: ECR register captured an error, or it is in free running mode?1: ECR register is armed"]
    #[inline(always)]
    pub fn ecr_status(&mut self) -> ECR_STATUS_W {
        ECR_STATUS_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 = "Error Capture 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 [ecr](index.html) module"]
pub struct ECR_SPEC;
impl crate::RegisterSpec for ECR_SPEC {
    type Ux = u32;
}
#[doc = "`read()` method returns [ecr::R](R) reader structure"]
impl crate::Readable for ECR_SPEC {
    type Reader = R;
}
#[doc = "`write(|w| ..)` method takes [ecr::W](W) writer structure"]
impl crate::Writable for ECR_SPEC {
    type Writer = W;
}
#[doc = "`reset()` method sets ECR to value 0"]
impl crate::Resettable for ECR_SPEC {
    #[inline(always)]
    fn reset_value() -> Self::Ux {
        0
    }
}
