Skip to content

Commit

Permalink
Merge branch 'main' into native-file-browser-options-init
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft committed Dec 3, 2023
2 parents 6804d1e + 4f76105 commit deebdac
Show file tree
Hide file tree
Showing 14 changed files with 9,383 additions and 5,725 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/checkout@v4.1.0
- uses: actions/checkout@v4.1.1
- run: rustup component add llvm-tools
- run: sudo apt install libudev-dev
- name: Build
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/_lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/checkout@v4.1.0
- uses: actions/checkout@v4.1.1
- name: Install build dependencies
run: sudo apt install libudev-dev
- name: Run Clippy
uses: auguwu/clippy-action@1.2.2
uses: auguwu/clippy-action@1.3.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ${{ inputs.target }}
Expand All @@ -36,7 +36,7 @@ jobs:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/checkout@v4.1.0
- uses: actions/checkout@v4.1.1
- name: Install build dependencies
run: sudo apt install libudev-dev
- uses: dtolnay/rust-toolchain@beta
Expand All @@ -45,7 +45,7 @@ jobs:
components: clippy
- run: rustup override set ${{ steps.toolchain.outputs.name }}
- name: Run Clippy (beta)
uses: auguwu/clippy-action@1.2.2
uses: auguwu/clippy-action@1.3.0
continue-on-error: true
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -62,7 +62,7 @@ jobs:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/checkout@v4.1.0
- uses: actions/checkout@v4.1.1
- name: Install build dependencies
run: sudo apt install libudev-dev
# Use nightly Rust (as docs.rs does), because some of our dependencies enable the
Expand All @@ -86,5 +86,5 @@ jobs:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/checkout@v4.1.0
- uses: actions/checkout@v4.1.1
- run: cargo fmt --all --check
12 changes: 5 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Unreleased

- Migrated to SDK 39.1 (firmware 0.92.2).
### Added

## [0.12.0]
- `flipperzero::gpio::i2c`, providing a Rust interface to the external 3.3V I2C
bus over GPIO pins C0 and C1, as well as the internal (power) I2C bus.

### Changed

- `flipperzero::dialogs::DialogFileBrowserOptions` now uses native initialization function
- Migrated to SDK 46.0 (firmware 0.95.0).
- `flipperzero::dialogs::DialogFileBrowserOptions` now uses native initialization function.
- Bumped pinned nightly Rust version to `nightly-2023-12-03`.

### Removed

- `impl Default for flipperzero::dialogs::DialogFileBrowserOptions`

## [0.11.0]

### Added
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Rust for Flipper Zero 🐬❤️🦀

[![crates.io](https://img.shields.io/crates/v/flipperzero)](https://crates.io/crates/flipperzero)
[![Flipper Zero API](https://img.shields.io/badge/Flipper%20Zero%20API-39.1-orange)](https://github.com/flipperdevices/flipperzero-firmware/blob/0.92.2/firmware/targets/f7/api_symbols.csv)
[![Flipper Zero API](https://img.shields.io/badge/Flipper%20Zero%20API-46.0-orange)](https://github.com/flipperdevices/flipperzero-firmware/blob/0.95.0/targets/f7/api_symbols.csv)
[![docs.rs](https://img.shields.io/docsrs/flipperzero)](https://docs.rs/flipperzero)
[![MIT license](https://img.shields.io/crates/l/flipperzero)](LICENSE)

Expand All @@ -17,13 +17,13 @@ This means it's not possible to use anything in the [`std`](https://doc.rust-lan

## SDK version

Currently supports SDK 39.1 ([flipperzero-firmware@0.92.2](https://github.com/flipperdevices/flipperzero-firmware/tree/0.92.2)).
Currently supports SDK 46.0 ([flipperzero-firmware@0.95.0](https://github.com/flipperdevices/flipperzero-firmware/tree/0.95.0)).

The crate major version number will be updated after a bump in [API version](https://github.com/flipperdevices/flipperzero-firmware/blob/release/firmware/targets/f7/api_symbols.csv) in the Flipper Zero firmware.
The crate major version number will be updated after a bump in [API version](https://github.com/flipperdevices/flipperzero-firmware/blob/release/targets/f7/api_symbols.csv) in the Flipper Zero firmware.

| Crate version | API version |
|---------------|-------------|
| Unreleased | 39.1 |
| Unreleased | 46.0 |
| 0.11.x | 35.0 |
| 0.10.x | 28.2 |
| 0.9.x | 23.0 |
Expand Down
4 changes: 4 additions & 0 deletions crates/flipperzero/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ lock_api = "0.4"
digest = "0.10"
bitflags = "1.0"

# Embedded-hal
embedded-hal = { version = "1.0.0-rc.1", optional = true }
embedded-hal-0 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"], optional = true }

# Docs
document-features = { workspace = true, optional = true }

Expand Down
81 changes: 81 additions & 0 deletions crates/flipperzero/examples/i2c-ds3231.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//! Example of communicating with a [DS3231] Real-Time Clock.
//!
//! [DS3231]: https://www.analog.com/media/en/technical-documentation/data-sheets/DS3231.pdf

#![no_main]
#![no_std]

// Required for panic handler
extern crate flipperzero_rt;

// Required for allocator
#[cfg(feature = "alloc")]
extern crate flipperzero_alloc;

use flipperzero::{error, furi::time::Duration, gpio::i2c, println};
use flipperzero_rt::{entry, manifest};
use ufmt::derive::uDebug;

manifest!(name = "I2C DS3231 Example");
entry!(main);

#[derive(Debug, uDebug)]
enum Hour {
F12 { hour: u8, pm: bool },
F24(u8),
}

#[derive(Debug, uDebug)]
struct RtcTime {
year: u8,
month: u8,
date: u8,
day: u8,
hour: Hour,
minutes: u8,
seconds: u8,
}

impl RtcTime {
fn parse(data: [u8; 7]) -> Self {
let unbcd = |b: u8| 10 * (b >> 4) + (b & 0x0F);

const FORMAT_12HR: u8 = 0b0100_0000;

Self {
year: unbcd(data[6]),
month: unbcd(data[5] & 0x1F),
date: unbcd(data[4] & 0x3F),
day: data[3] & 0x07,
hour: if data[2] & FORMAT_12HR != 0 {
Hour::F12 {
hour: unbcd(data[2] & 0x1F),
pm: data[2] & 0b0010_0000 != 0,
}
} else {
Hour::F24(unbcd(data[2] & 0x3F))
},
minutes: unbcd(data[1] & 0x7F),
seconds: unbcd(data[0] & 0x7F),
}
}
}

fn main(_args: *mut u8) -> i32 {
let mut bus = i2c::Bus::EXTERNAL.acquire();
let rtc = i2c::DeviceAddress::new(0x68);
let timeout = Duration::from_millis(50);

if bus.is_device_ready(rtc, timeout) {
let mut data = [0; 7];
if bus.read_exact(rtc, 0x00, &mut data, timeout).is_ok() {
println!("Time: {:?}", RtcTime::parse(data));
} else {
error!("Could not read from DS3231");
}
} else {
error!("DS3231 is not connected and ready");
}

0
}
Loading

0 comments on commit deebdac

Please sign in to comment.