Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
**/*.rs.bk
.idea
/lib.rs
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
sam3x8e
===
Rust crate to support Atmel's SAM3X8E microcontroller. The SAM3X8E is used on the Arduino Due board.
This source was created with the [svd2rust](https://docs.rs/svd2rust/) tool (version 0.14.0).

You can use this crate for cortex-m, cortex-m-rt and cortex-m-rtfm projects.
This source was generated from the Atmel SVD file. To regenerate it, ensure that the the [svd2rust](https://docs.rs/svd2rust/) and [form](https://docs.rs/form/) tools are installed via `cargo install`.

When this library was first created, the svd2rust-tool did not support the Atmel-SVD files, since they sometimes miss ResetValues. I forked the tool and fixed it. A PR was created.
My version of the svd2rust tool: https://github.com/ammoniak/svd2rust
You can use this crate for cortex-m, cortex-m-rt and cortex-m-rtfm projects.
41 changes: 39 additions & 2 deletions generate.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
rm lib.rs
#!/bin/sh

# TODO: Just put the expected dependencies in a list and iterate over that

SVD2RUST_CMD=$(which svd2rust)
if [ x"${SVD2RUST_CMD}" = "x" ]; then
echo "Dependency ‘svd2rust’ does not appear to be installed. Try: cargo install svd2rust"
exit 1
fi

FORM_CMD=$(which form)
if [ x"${FORM_CMD}" = "x" ]; then
echo "Dependency ‘form’ does not appear to be installed. Try: cargo install form"
exit 1
fi

rm -f lib.rs
rm -rf ./src/*
../svd2rust/target/debug/svd2rust --nightly -i ATSAM3X8E.svd

svd2rust -i ATSAM3X8E.svd
if [ x"$?" != "x0" ]; then
echo "svd2rust failed, aborting"
exit 1
fi

form -i lib.rs -o ./src/
if [ x"$?" != "x0" ]; then
echo "form failed, aborting"
exit 1
fi

echo "Running cargo fmt"
cargo fmt
if [ x"$?" != "x0" ]; then
echo "cargo fmt failed, aborting"
exit 1
fi

# Cleanup
rm -f lib.rs

echo "Building crate"
cargo build
1 change: 0 additions & 1 deletion lib.rs

This file was deleted.

325 changes: 216 additions & 109 deletions src/adc.rs

Large diffs are not rendered by default.

174 changes: 42 additions & 132 deletions src/adc/acr.rs
Original file line number Diff line number Diff line change
@@ -1,164 +1,74 @@
#[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
#[doc = r" Value to write to the register"]
pub struct W {
bits: u32,
}
impl super::ACR {
#[doc = r" Modifies the contents of the register"]
#[inline]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W,
{
let bits = self.register.get();
let r = R { bits: bits };
let mut w = W { bits: bits };
f(&r, &mut w);
self.register.set(w.bits);
}
#[doc = r" Reads the contents of the register"]
#[inline]
pub fn read(&self) -> R {
R {
bits: self.register.get(),
}
}
#[doc = r" Writes to the register"]
#[inline]
pub fn write<F>(&self, f: F)
where
F: FnOnce(&mut W) -> &mut W,
{
let mut w = W::reset_value();
f(&mut w);
self.register.set(w.bits);
}
#[doc = r" Writes the reset value to the register"]
#[inline]
pub fn reset(&self) {
self.write(|w| w)
}
}
#[doc = r" Value of the field"]
pub struct TSONR {
bits: bool,
}
impl TSONR {
#[doc = r" Value of the field as raw bits"]
#[inline]
pub fn bit(&self) -> bool {
self.bits
}
#[doc = r" Returns `true` if the bit is clear (0)"]
#[inline]
pub fn bit_is_clear(&self) -> bool {
!self.bit()
}
#[doc = r" Returns `true` if the bit is set (1)"]
#[inline]
pub fn bit_is_set(&self) -> bool {
self.bit()
}
}
#[doc = r" Value of the field"]
pub struct IBCTLR {
bits: u8,
}
impl IBCTLR {
#[doc = r" Value of the field as raw bits"]
#[inline]
pub fn bits(&self) -> u8 {
self.bits
#[doc = "Reader of register ACR"]
pub type R = crate::R<u32, super::ACR>;
#[doc = "Writer for register ACR"]
pub type W = crate::W<u32, super::ACR>;
#[doc = "Register ACR `reset()`'s with value 0x0100"]
impl crate::ResetValue for super::ACR {
type Type = u32;
#[inline(always)]
fn reset_value() -> Self::Type {
0x0100
}
}
#[doc = r" Proxy"]
pub struct _TSONW<'a> {
#[doc = "Reader of field `TSON`"]
pub type TSON_R = crate::R<bool, bool>;
#[doc = "Write proxy for field `TSON`"]
pub struct TSON_W<'a> {
w: &'a mut W,
}
impl<'a> _TSONW<'a> {
#[doc = r" Sets the field bit"]
impl<'a> TSON_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"]
#[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]
#[doc = r"Writes raw bits to the field"]
#[inline(always)]
pub fn bit(self, value: bool) -> &'a mut W {
const MASK: bool = true;
const OFFSET: u8 = 4;
self.w.bits &= !((MASK as u32) << OFFSET);
self.w.bits |= ((value & MASK) as u32) << OFFSET;
self.w.bits = (self.w.bits & !(0x01 << 4)) | (((value as u32) & 0x01) << 4);
self.w
}
}
#[doc = r" Proxy"]
pub struct _IBCTLW<'a> {
#[doc = "Reader of field `IBCTL`"]
pub type IBCTL_R = crate::R<u8, u8>;
#[doc = "Write proxy for field `IBCTL`"]
pub struct IBCTL_W<'a> {
w: &'a mut W,
}
impl<'a> _IBCTLW<'a> {
#[doc = r" Writes raw bits to the field"]
#[inline]
impl<'a> IBCTL_W<'a> {
#[doc = r"Writes raw bits to the field"]
#[inline(always)]
pub unsafe fn bits(self, value: u8) -> &'a mut W {
const MASK: u8 = 3;
const OFFSET: u8 = 8;
self.w.bits &= !((MASK as u32) << OFFSET);
self.w.bits |= ((value & MASK) as u32) << OFFSET;
self.w.bits = (self.w.bits & !(0x03 << 8)) | (((value as u32) & 0x03) << 8);
self.w
}
}
impl R {
#[doc = r" Value of the register as raw bits"]
#[inline]
pub fn bits(&self) -> u32 {
self.bits
}
#[doc = "Bit 4 - Temperature Sensor On"]
#[inline]
pub fn tson(&self) -> TSONR {
let bits = {
const MASK: bool = true;
const OFFSET: u8 = 4;
((self.bits >> OFFSET) & MASK as u32) != 0
};
TSONR { bits }
#[inline(always)]
pub fn tson(&self) -> TSON_R {
TSON_R::new(((self.bits >> 4) & 0x01) != 0)
}
#[doc = "Bits 8:9 - ADC Bias Current Control"]
#[inline]
pub fn ibctl(&self) -> IBCTLR {
let bits = {
const MASK: u8 = 3;
const OFFSET: u8 = 8;
((self.bits >> OFFSET) & MASK as u32) as u8
};
IBCTLR { bits }
#[inline(always)]
pub fn ibctl(&self) -> IBCTL_R {
IBCTL_R::new(((self.bits >> 8) & 0x03) as u8)
}
}
impl W {
#[doc = r" Reset value of the register"]
#[inline]
pub fn reset_value() -> W {
W { bits: 256 }
}
#[doc = r" Writes raw bits to the register"]
#[inline]
pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
self.bits = bits;
self
}
#[doc = "Bit 4 - Temperature Sensor On"]
#[inline]
pub fn tson(&mut self) -> _TSONW {
_TSONW { w: self }
#[inline(always)]
pub fn tson(&mut self) -> TSON_W {
TSON_W { w: self }
}
#[doc = "Bits 8:9 - ADC Bias Current Control"]
#[inline]
pub fn ibctl(&mut self) -> _IBCTLW {
_IBCTLW { w: self }
#[inline(always)]
pub fn ibctl(&mut self) -> IBCTL_W {
IBCTL_W { w: self }
}
}
44 changes: 7 additions & 37 deletions src/adc/cdr.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,11 @@
#[doc = r" Value read from the register"]
pub struct R {
bits: u32,
}
impl super::CDR {
#[doc = r" Reads the contents of the register"]
#[inline]
pub fn read(&self) -> R {
R {
bits: self.register.get(),
}
}
}
#[doc = r" Value of the field"]
pub struct DATAR {
bits: u16,
}
impl DATAR {
#[doc = r" Value of the field as raw bits"]
#[inline]
pub fn bits(&self) -> u16 {
self.bits
}
}
#[doc = "Reader of register CDR[%s]"]
pub type R = crate::R<u32, super::CDR>;
#[doc = "Reader of field `DATA`"]
pub type DATA_R = crate::R<u16, u16>;
impl R {
#[doc = r" Value of the register as raw bits"]
#[inline]
pub fn bits(&self) -> u32 {
self.bits
}
#[doc = "Bits 0:11 - Converted Data"]
#[inline]
pub fn data(&self) -> DATAR {
let bits = {
const MASK: u16 = 4095;
const OFFSET: u8 = 0;
((self.bits >> OFFSET) & MASK as u32) as u16
};
DATAR { bits }
#[inline(always)]
pub fn data(&self) -> DATA_R {
DATA_R::new((self.bits & 0x0fff) as u16)
}
}
Loading