#[doc = "ADC Control and Status"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Cs(pub u32);
impl Cs {
#[doc = "Power on ADC and enable its clock. 1 - enabled. 0 - disabled."]
#[inline(always)]
pub const fn en(&self) -> bool {
let val = (self.0 >> 0usize) & 0x01;
val != 0
}
#[doc = "Power on ADC and enable its clock. 1 - enabled. 0 - disabled."]
#[inline(always)]
pub fn set_en(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 0usize)) | (((val as u32) & 0x01) << 0usize);
}
#[doc = "Power on temperature sensor. 1 - enabled. 0 - disabled."]
#[inline(always)]
pub const fn ts_en(&self) -> bool {
let val = (self.0 >> 1usize) & 0x01;
val != 0
}
#[doc = "Power on temperature sensor. 1 - enabled. 0 - disabled."]
#[inline(always)]
pub fn set_ts_en(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 1usize)) | (((val as u32) & 0x01) << 1usize);
}
#[doc = "Start a single conversion. Self-clearing. Ignored if start_many is asserted."]
#[inline(always)]
pub const fn start_once(&self) -> bool {
let val = (self.0 >> 2usize) & 0x01;
val != 0
}
#[doc = "Start a single conversion. Self-clearing. Ignored if start_many is asserted."]
#[inline(always)]
pub fn set_start_once(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 2usize)) | (((val as u32) & 0x01) << 2usize);
}
#[doc = "Continuously perform conversions whilst this bit is 1. A new conversion will start immediately after the previous finishes."]
#[inline(always)]
pub const fn start_many(&self) -> bool {
let val = (self.0 >> 3usize) & 0x01;
val != 0
}
#[doc = "Continuously perform conversions whilst this bit is 1. A new conversion will start immediately after the previous finishes."]
#[inline(always)]
pub fn set_start_many(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 3usize)) | (((val as u32) & 0x01) << 3usize);
}
#[doc = "1 if the ADC is ready to start a new conversion. Implies any previous conversion has completed. 0 whilst conversion in progress."]
#[inline(always)]
pub const fn ready(&self) -> bool {
let val = (self.0 >> 8usize) & 0x01;
val != 0
}
#[doc = "1 if the ADC is ready to start a new conversion. Implies any previous conversion has completed. 0 whilst conversion in progress."]
#[inline(always)]
pub fn set_ready(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 8usize)) | (((val as u32) & 0x01) << 8usize);
}
#[doc = "The most recent ADC conversion encountered an error; result is undefined or noisy."]
#[inline(always)]
pub const fn err(&self) -> bool {
let val = (self.0 >> 9usize) & 0x01;
val != 0
}
#[doc = "The most recent ADC conversion encountered an error; result is undefined or noisy."]
#[inline(always)]
pub fn set_err(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 9usize)) | (((val as u32) & 0x01) << 9usize);
}
#[doc = "Some past ADC conversion encountered an error. Write 1 to clear."]
#[inline(always)]
pub const fn err_sticky(&self) -> bool {
let val = (self.0 >> 10usize) & 0x01;
val != 0
}
#[doc = "Some past ADC conversion encountered an error. Write 1 to clear."]
#[inline(always)]
pub fn set_err_sticky(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 10usize)) | (((val as u32) & 0x01) << 10usize);
}
#[doc = "Select analog mux input. Updated automatically in round-robin mode."]
#[inline(always)]
pub const fn ainsel(&self) -> u8 {
let val = (self.0 >> 12usize) & 0x07;
val as u8
}
#[doc = "Select analog mux input. Updated automatically in round-robin mode."]
#[inline(always)]
pub fn set_ainsel(&mut self, val: u8) {
self.0 = (self.0 & !(0x07 << 12usize)) | (((val as u32) & 0x07) << 12usize);
}
#[doc = "Round-robin sampling. 1 bit per channel. Set all bits to 0 to disable. Otherwise, the ADC will cycle through each enabled channel in a round-robin fashion. The first channel to be sampled will be the one currently indicated by AINSEL. AINSEL will be updated after each conversion with the newly-selected channel."]
#[inline(always)]
pub const fn rrobin(&self) -> u8 {
let val = (self.0 >> 16usize) & 0x1f;
val as u8
}
#[doc = "Round-robin sampling. 1 bit per channel. Set all bits to 0 to disable. Otherwise, the ADC will cycle through each enabled channel in a round-robin fashion. The first channel to be sampled will be the one currently indicated by AINSEL. AINSEL will be updated after each conversion with the newly-selected channel."]
#[inline(always)]
pub fn set_rrobin(&mut self, val: u8) {
self.0 = (self.0 & !(0x1f << 16usize)) | (((val as u32) & 0x1f) << 16usize);
}
}
impl Default for Cs {
#[inline(always)]
fn default() -> Cs {
Cs(0)
}
}
#[doc = "Clock divider. If non-zero, CS_START_MANY will start conversions at regular intervals rather than back-to-back. The divider is reset when either of these fields are written. Total period is 1 + INT + FRAC / 256"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Div(pub u32);
impl Div {
#[doc = "Fractional part of clock divisor. First-order delta-sigma."]
#[inline(always)]
pub const fn frac(&self) -> u8 {
let val = (self.0 >> 0usize) & 0xff;
val as u8
}
#[doc = "Fractional part of clock divisor. First-order delta-sigma."]
#[inline(always)]
pub fn set_frac(&mut self, val: u8) {
self.0 = (self.0 & !(0xff << 0usize)) | (((val as u32) & 0xff) << 0usize);
}
#[doc = "Integer part of clock divisor."]
#[inline(always)]
pub const fn int(&self) -> u16 {
let val = (self.0 >> 8usize) & 0xffff;
val as u16
}
#[doc = "Integer part of clock divisor."]
#[inline(always)]
pub fn set_int(&mut self, val: u16) {
self.0 = (self.0 & !(0xffff << 8usize)) | (((val as u32) & 0xffff) << 8usize);
}
}
impl Default for Div {
#[inline(always)]
fn default() -> Div {
Div(0)
}
}
#[doc = "FIFO control and status"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Fcs(pub u32);
impl Fcs {
#[doc = "If 1: write result to the FIFO after each conversion."]
#[inline(always)]
pub const fn en(&self) -> bool {
let val = (self.0 >> 0usize) & 0x01;
val != 0
}
#[doc = "If 1: write result to the FIFO after each conversion."]
#[inline(always)]
pub fn set_en(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 0usize)) | (((val as u32) & 0x01) << 0usize);
}
#[doc = "If 1: FIFO results are right-shifted to be one byte in size. Enables DMA to byte buffers."]
#[inline(always)]
pub const fn shift(&self) -> bool {
let val = (self.0 >> 1usize) & 0x01;
val != 0
}
#[doc = "If 1: FIFO results are right-shifted to be one byte in size. Enables DMA to byte buffers."]
#[inline(always)]
pub fn set_shift(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 1usize)) | (((val as u32) & 0x01) << 1usize);
}
#[doc = "If 1: conversion error bit appears in the FIFO alongside the result"]
#[inline(always)]
pub const fn err(&self) -> bool {
let val = (self.0 >> 2usize) & 0x01;
val != 0
}
#[doc = "If 1: conversion error bit appears in the FIFO alongside the result"]
#[inline(always)]
pub fn set_err(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 2usize)) | (((val as u32) & 0x01) << 2usize);
}
#[doc = "If 1: assert DMA requests when FIFO contains data"]
#[inline(always)]
pub const fn dreq_en(&self) -> bool {
let val = (self.0 >> 3usize) & 0x01;
val != 0
}
#[doc = "If 1: assert DMA requests when FIFO contains data"]
#[inline(always)]
pub fn set_dreq_en(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 3usize)) | (((val as u32) & 0x01) << 3usize);
}
#[inline(always)]
pub const fn empty(&self) -> bool {
let val = (self.0 >> 8usize) & 0x01;
val != 0
}
#[inline(always)]
pub fn set_empty(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 8usize)) | (((val as u32) & 0x01) << 8usize);
}
#[inline(always)]
pub const fn full(&self) -> bool {
let val = (self.0 >> 9usize) & 0x01;
val != 0
}
#[inline(always)]
pub fn set_full(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 9usize)) | (((val as u32) & 0x01) << 9usize);
}
#[doc = "1 if the FIFO has been underflowed. Write 1 to clear."]
#[inline(always)]
pub const fn under(&self) -> bool {
let val = (self.0 >> 10usize) & 0x01;
val != 0
}
#[doc = "1 if the FIFO has been underflowed. Write 1 to clear."]
#[inline(always)]
pub fn set_under(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 10usize)) | (((val as u32) & 0x01) << 10usize);
}
#[doc = "1 if the FIFO has been overflowed. Write 1 to clear."]
#[inline(always)]
pub const fn over(&self) -> bool {
let val = (self.0 >> 11usize) & 0x01;
val != 0
}
#[doc = "1 if the FIFO has been overflowed. Write 1 to clear."]
#[inline(always)]
pub fn set_over(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 11usize)) | (((val as u32) & 0x01) << 11usize);
}
#[doc = "The number of conversion results currently waiting in the FIFO"]
#[inline(always)]
pub const fn level(&self) -> u8 {
let val = (self.0 >> 16usize) & 0x0f;
val as u8
}
#[doc = "The number of conversion results currently waiting in the FIFO"]
#[inline(always)]
pub fn set_level(&mut self, val: u8) {
self.0 = (self.0 & !(0x0f << 16usize)) | (((val as u32) & 0x0f) << 16usize);
}
#[doc = "DREQ/IRQ asserted when level >= threshold"]
#[inline(always)]
pub const fn thresh(&self) -> u8 {
let val = (self.0 >> 24usize) & 0x0f;
val as u8
}
#[doc = "DREQ/IRQ asserted when level >= threshold"]
#[inline(always)]
pub fn set_thresh(&mut self, val: u8) {
self.0 = (self.0 & !(0x0f << 24usize)) | (((val as u32) & 0x0f) << 24usize);
}
}
impl Default for Fcs {
#[inline(always)]
fn default() -> Fcs {
Fcs(0)
}
}
#[doc = "Conversion result FIFO"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Fifo(pub u32);
impl Fifo {
#[inline(always)]
pub const fn val(&self) -> u16 {
let val = (self.0 >> 0usize) & 0x0fff;
val as u16
}
#[inline(always)]
pub fn set_val(&mut self, val: u16) {
self.0 = (self.0 & !(0x0fff << 0usize)) | (((val as u32) & 0x0fff) << 0usize);
}
#[doc = "1 if this particular sample experienced a conversion error. Remains in the same location if the sample is shifted."]
#[inline(always)]
pub const fn err(&self) -> bool {
let val = (self.0 >> 15usize) & 0x01;
val != 0
}
#[doc = "1 if this particular sample experienced a conversion error. Remains in the same location if the sample is shifted."]
#[inline(always)]
pub fn set_err(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 15usize)) | (((val as u32) & 0x01) << 15usize);
}
}
impl Default for Fifo {
#[inline(always)]
fn default() -> Fifo {
Fifo(0)
}
}
#[doc = "Interrupt Enable"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Int(pub u32);
impl Int {
#[doc = "Triggered when the sample FIFO reaches a certain level. This level can be programmed via the FCS_THRESH field."]
#[inline(always)]
pub const fn fifo(&self) -> bool {
let val = (self.0 >> 0usize) & 0x01;
val != 0
}
#[doc = "Triggered when the sample FIFO reaches a certain level. This level can be programmed via the FCS_THRESH field."]
#[inline(always)]
pub fn set_fifo(&mut self, val: bool) {
self.0 = (self.0 & !(0x01 << 0usize)) | (((val as u32) & 0x01) << 0usize);
}
}
impl Default for Int {
#[inline(always)]
fn default() -> Int {
Int(0)
}
}
#[doc = "Result of most recent ADC conversion"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Result(pub u32);
impl Result {
#[inline(always)]
pub const fn result(&self) -> u16 {
let val = (self.0 >> 0usize) & 0x0fff;
val as u16
}
#[inline(always)]
pub fn set_result(&mut self, val: u16) {
self.0 = (self.0 & !(0x0fff << 0usize)) | (((val as u32) & 0x0fff) << 0usize);
}
}
impl Default for Result {
#[inline(always)]
fn default() -> Result {
Result(0)
}
}