#[doc = "Register `ERROR_STATUS` reader"]
pub struct R(crate::R<ERROR_STATUS_SPEC>);
impl core::ops::Deref for R {
    type Target = crate::R<ERROR_STATUS_SPEC>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl core::convert::From<crate::R<ERROR_STATUS_SPEC>> for R {
    fn from(reader: crate::R<ERROR_STATUS_SPEC>) -> Self {
        R(reader)
    }
}
#[doc = "Register `ERROR_STATUS` writer"]
pub struct W(crate::W<ERROR_STATUS_SPEC>);
impl core::ops::Deref for W {
    type Target = crate::W<ERROR_STATUS_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<ERROR_STATUS_SPEC>> for W {
    fn from(writer: crate::W<ERROR_STATUS_SPEC>) -> Self {
        W(writer)
    }
}
#[doc = "Field `TX_ERR_CNT` reader - The transmitter error counter according to the?CAN standard. When it is greater than 255,?it is fixed at 255"]
pub struct TX_ERR_CNT_R(crate::FieldReader<u8, u8>);
impl TX_ERR_CNT_R {
    pub(crate) fn new(bits: u8) -> Self {
        TX_ERR_CNT_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for TX_ERR_CNT_R {
    type Target = crate::FieldReader<u8, u8>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `RX_ERR_CNT` reader - The receive error counter according to the?CAN 2.0 specification. When in bus-off state,?this counter is used to count 128 groups of 11?recessive bits.?it is fixed at 255"]
pub struct RX_ERR_CNT_R(crate::FieldReader<u8, u8>);
impl RX_ERR_CNT_R {
    pub(crate) fn new(bits: u8) -> Self {
        RX_ERR_CNT_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for RX_ERR_CNT_R {
    type Target = crate::FieldReader<u8, u8>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `ERROR_STATE` reader - The error state of the CAN node:?\"00\": error active (normal operation)?\"01\": error passive?\"1x\": bus off"]
pub struct ERROR_STATE_R(crate::FieldReader<u8, u8>);
impl ERROR_STATE_R {
    pub(crate) fn new(bits: u8) -> Self {
        ERROR_STATE_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for ERROR_STATE_R {
    type Target = crate::FieldReader<u8, u8>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `TXGTE96` reader - The Tx error counter is greater or equal 96"]
pub struct TXGTE96_R(crate::FieldReader<bool, bool>);
impl TXGTE96_R {
    pub(crate) fn new(bits: bool) -> Self {
        TXGTE96_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for TXGTE96_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `RXGTE96` reader - The Rx error counter is greater or equal 96"]
pub struct RXGTE96_R(crate::FieldReader<bool, bool>);
impl RXGTE96_R {
    pub(crate) fn new(bits: bool) -> Self {
        RXGTE96_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for RXGTE96_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl R {
    #[doc = "Bits 0:7 - The transmitter error counter according to the?CAN standard. When it is greater than 255,?it is fixed at 255"]
    #[inline(always)]
    pub fn tx_err_cnt(&self) -> TX_ERR_CNT_R {
        TX_ERR_CNT_R::new((self.bits & 0xff) as u8)
    }
    #[doc = "Bits 8:15 - The receive error counter according to the?CAN 2.0 specification. When in bus-off state,?this counter is used to count 128 groups of 11?recessive bits.?it is fixed at 255"]
    #[inline(always)]
    pub fn rx_err_cnt(&self) -> RX_ERR_CNT_R {
        RX_ERR_CNT_R::new(((self.bits >> 8) & 0xff) as u8)
    }
    #[doc = "Bits 16:17 - The error state of the CAN node:?\"00\": error active (normal operation)?\"01\": error passive?\"1x\": bus off"]
    #[inline(always)]
    pub fn error_state(&self) -> ERROR_STATE_R {
        ERROR_STATE_R::new(((self.bits >> 16) & 0x03) as u8)
    }
    #[doc = "Bit 18 - The Tx error counter is greater or equal 96"]
    #[inline(always)]
    pub fn txgte96(&self) -> TXGTE96_R {
        TXGTE96_R::new(((self.bits >> 18) & 0x01) != 0)
    }
    #[doc = "Bit 19 - The Rx error counter is greater or equal 96"]
    #[inline(always)]
    pub fn rxgte96(&self) -> RXGTE96_R {
        RXGTE96_R::new(((self.bits >> 19) & 0x01) != 0)
    }
}
impl W {
    #[doc = "Writes raw bits to the register."]
    pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
        self.0.bits(bits);
        self
    }
}
#[doc = "CAN Error Status\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 [error_status](index.html) module"]
pub struct ERROR_STATUS_SPEC;
impl crate::RegisterSpec for ERROR_STATUS_SPEC {
    type Ux = u32;
}
#[doc = "`read()` method returns [error_status::R](R) reader structure"]
impl crate::Readable for ERROR_STATUS_SPEC {
    type Reader = R;
}
#[doc = "`write(|w| ..)` method takes [error_status::W](W) writer structure"]
impl crate::Writable for ERROR_STATUS_SPEC {
    type Writer = W;
}
#[doc = "`reset()` method sets ERROR_STATUS to value 0"]
impl crate::Resettable for ERROR_STATUS_SPEC {
    #[inline(always)]
    fn reset_value() -> Self::Ux {
        0
    }
}
