Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: stm32-rs/stm32f1xx-hal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.1
Choose a base ref
...
head repository: stm32-rs/stm32f1xx-hal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.2.0
Choose a head ref
  • 8 commits
  • 5 files changed
  • 4 contributors

Commits on Jan 5, 2019

  1. Add support for setting initial pin state

    Allows to set pin to high or low before actual switch to the
    output mode, eliminating small "low" window in cases where pin should
    be idle high.
    WGH- committed Jan 5, 2019
    Copy the full SHA
    eb68c84 View commit details

Commits on Jan 8, 2019

  1. Fix link to docs.rs

    therealprof authored Jan 8, 2019
    Copy the full SHA
    b895c65 View commit details
  2. Merge pull request #5 from WGH-/initial-state

    Add support for setting initial pin state
    therealprof authored Jan 8, 2019
    Copy the full SHA
    6b1ea4b View commit details

Commits on Feb 4, 2019

  1. Allow read-/write-only transactions in write_read

    For WriteRead::write_read only:
    
    Allow transactions, with only read or write requests. More importantly, don't panic anymore (there is no mention of a valid panic at https://github.com/rust-embedded/embedded-hal/blob/master/src/blocking/i2c.rs#L75). Also use ```.is_empty()``` instead of ```== 0```
    kellerkindt authored and therealprof committed Feb 4, 2019
    Copy the full SHA
    efafedf View commit details

Commits on Feb 9, 2019

  1. Copy the full SHA
    2564117 View commit details
  2. Merge pull request #12 from TheZoq2/feature_to_readme

    Add information about device features to readme
    therealprof authored Feb 9, 2019
    Copy the full SHA
    d4323f4 View commit details

Commits on Feb 10, 2019

  1. Added CHANGELOG.md, bumped version and prepare 0.2.0 release

    Signed-off-by: Daniel Egger <daniel@eggers-club.de>
    therealprof committed Feb 10, 2019
    Copy the full SHA
    d2bfd49 View commit details
  2. Merge pull request #14 from stm32-rs/release-0.2.0

    Added CHANGELOG.md, bumped version and prepare 0.2.0 release
    therealprof authored Feb 10, 2019
    Copy the full SHA
    bc6cb3c View commit details
Showing with 109 additions and 17 deletions.
  1. +34 −0 CHANGELOG.md
  2. +7 −7 Cargo.toml
  3. +12 −0 README.md
  4. +50 −6 src/gpio.rs
  5. +6 −4 src/i2c.rs
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [v0.2.0] - 2019-02-10

### Added

- Add support for setting initial pin state
- Added ChangeLog

### Changed

- Add information about device features to readme
- Allow read-/write-only transactions in write_read
- Bumped dependency versions (breaking change)

### Fixed

- Fix link to docs.rs

## [v0.1.1] - 2018-12-17

### Added

- First tagged version

[Unreleased]: https://github.com/stm32-rs/stm32f1xx-hal/compare/v0.2.0...HEAD
[v0.2.0]: https://github.com/stm32-rs/stm32f1xx-hal/compare/v0.1.1...v0.2.0
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ keywords = ["arm", "cortex-m", "stm32", "hal"]
license = "MIT OR Apache-2.0"
name = "stm32f1xx-hal"
repository = "https://github.com/stm32-rs/stm32f1xx-hal"
documentation = "https://docs.rs/crate/stm32f1xx-hal"
version = "0.1.1"
documentation = "https://docs.rs/stm32f1xx-hal"
version = "0.2.0"

[package.metadata.docs.rs]
features = ["stm32f103", "rt"]
@@ -16,7 +16,7 @@ features = ["stm32f103", "rt"]
cortex-m = "0.5.8"
nb = "0.1.1"
cortex-m-rt = "0.6.7"
stm32f1 = "0.5.0"
stm32f1 = "0.6.0"

[dependencies.void]
default-features = false
@@ -35,15 +35,15 @@ panic-semihosting = "0.5.1"
panic-itm = "0.4.0"
# cortex-m-rtfm = "0.3.1"
cortex-m-semihosting = "0.3.2"
enc28j60 = "0.2.0"
enc28j60 = "0.2.1"
heapless = "0.4.1"
m = "0.1.1"
mfrc522 = "0.2.0"
serde_derive = "1.0.82"
serde_derive = "1.0.87"

[dev-dependencies.byteorder]
default-features = false
version = "1.2.7"
version = "1.3.1"

[dev-dependencies.cobs]
default-features = false
@@ -71,7 +71,7 @@ version = "1.5.0"

[dev-dependencies.serde]
default-features = false
version = "1.0.82"
version = "1.0.87"

#[dev-dependencies.serde-json-core]
#git = "https://github.com/japaric/serde-json-core"
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,18 @@
[HAL]: https://crates.io/crates/embedded-hal

## Usage

This crate will eventually contain support for multiple microcontrollers in the
stm32f1 family. Which specific microcontroller you want to build for has to be
specified with a feature, for example `stm32f103`.

```
cargo build --features stm32f103
```

If no device is specified, the crate does not compile.

## License

Licensed under either of
56 changes: 50 additions & 6 deletions src/gpio.rs
Original file line number Diff line number Diff line change
@@ -46,6 +46,11 @@ pub struct Alternate<MODE> {
_mode: PhantomData<MODE>,
}

pub enum State {
High,
Low,
}

macro_rules! gpio {
($GPIOX:ident, $gpiox:ident, $gpioy:ident, $iopxenr:ident, $iopxrst:ident, $PXx:ident, [
$($PXi:ident: ($pxi:ident, $i:expr, $MODE:ty, $CR:ident),)+
@@ -66,6 +71,7 @@ macro_rules! gpio {
PullUp,
PushPull,
Analog,
State,
};

/// GPIO parts
@@ -182,7 +188,8 @@ macro_rules! gpio {
}

impl<MODE> $PXi<MODE> {
/// Configures the pin to operate as an alternate function push pull output pin
/// Configures the pin to operate as an alternate function push-pull output
/// pin.
pub fn into_alternate_push_pull(
self,
cr: &mut $CR,
@@ -204,6 +211,8 @@ macro_rules! gpio {
$PXi { _mode: PhantomData }
}

/// Configures the pin to operate as an alternate function open-drain output
/// pin.
pub fn into_alternate_open_drain(
self,
cr: &mut $CR,
@@ -299,10 +308,21 @@ macro_rules! gpio {
$PXi { _mode: PhantomData }
}

/// Configures the pin to operate as an open drain output pin
/// Configures the pin to operate as an open-drain output pin.
/// Initial state will be low.
pub fn into_open_drain_output(
self,
cr: &mut $CR,
) -> $PXi<Output<OpenDrain>> {
self.into_open_drain_output_with_state(cr, State::Low)
}

/// Configures the pin to operate as an open-drain output pin.
/// `initial_state` specifies whether the pin should be initially high or low.
pub fn into_open_drain_output_with_state(
self,
cr: &mut $CR,
initial_state: State,
) -> $PXi<Output<OpenDrain>> {
let offset = (4 * $i) % 32;
// General purpose output open-drain
@@ -311,19 +331,36 @@ macro_rules! gpio {
let mode = 0b11;
let bits = (cnf << 2) | mode;

let mut res = $PXi { _mode: PhantomData };

match initial_state {
State::High => res.set_high(),
State::Low => res.set_low(),
}

cr
.cr()
.modify(|r, w| unsafe {
w.bits((r.bits() & !(0b1111 << offset)) | (bits << offset))
});

$PXi { _mode: PhantomData }
res
}

/// Configures the pin to operate as an push pull output pin
/// Configures the pin to operate as an push-pull output pin.
/// Initial state will be low.
pub fn into_push_pull_output(
self,
cr: &mut $CR,
) -> $PXi<Output<PushPull>> {
self.into_push_pull_output_with_state(cr, State::Low)
}

/// Configures the pin to operate as an push-pull output pin.
/// `initial_state` specifies whether the pin should be initially high or low.
pub fn into_push_pull_output_with_state(
self,
cr: &mut $CR,
initial_state: State,
) -> $PXi<Output<PushPull>> {
let offset = (4 * $i) % 32;
// General purpose output push-pull
@@ -332,13 +369,20 @@ macro_rules! gpio {
let mode = 0b11;
let bits = (cnf << 2) | mode;

let mut res = $PXi { _mode: PhantomData };

match initial_state {
State::High => res.set_high(),
State::Low => res.set_low(),
}

cr
.cr()
.modify(|r, w| unsafe {
w.bits((r.bits() & !(0b1111 << offset)) | (bits << offset))
});

$PXi { _mode: PhantomData }
res
}

/// Configures the pin to operate as an analog input pin
10 changes: 6 additions & 4 deletions src/i2c.rs
Original file line number Diff line number Diff line change
@@ -459,13 +459,15 @@ macro_rules! hal {
bytes: &[u8],
buffer: &mut [u8],
) -> Result<(), Self::Error> {
assert!(buffer.len() > 0);

if bytes.len() != 0 {
if !bytes.is_empty() {
self.write_without_stop(addr, bytes)?;
}

self.read(addr, buffer)?;
if !buffer.is_empty() {
self.read(addr, buffer)?;
} else if !bytes.is_empty() {
self.nb.send_stop();
}

Ok(())
}