Skip to content

Commit fbb6c9a

Browse files
committed
Update README.md
1 parent a9d9275 commit fbb6c9a

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

README.md

+13-14
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,35 @@
55

66
[API Documentation](https://docs.rs/avr_delay/)
77

8-
The intent of this library is to provide avr specific delay routines similar to the ones provided by the arduino library. The public functions are:
8+
The intent of this library is to provide avr specific delay routines similar to the ones provided by the arduino library.
99

1010
## `$AVR_CPU_FREQUENCY_HZ`
1111

1212
This crate uses the [`avr-config`](https://crates.io/crates/avr-config) crate for fetching the CPU frequency. As such, the `AVR_CPU_FREQUENCY_HZ` environment variable will need to be set when compiling your crate for AVR.
1313

14-
Example:
15-
1614
```bash
1715
export AVR_CPU_FREQUENCY_HZ=16000000
1816
cargo build -Z build-std=core --target avr-atmega328p.json --release
1917
```
2018

21-
```rust
22-
delay(count: u32)
23-
```
24-
25-
is a raw delay loop. Each loop is 4 cycles. The asm section can loop 65536 times. Initial overhead is about 13 cycles. Each outer loop has an overhead of about 11 cycles.
19+
## API
2620

2721
```rust
28-
delay_us(us: u32)
22+
delay_cycles<const CYCLES: u64>()
23+
delay_us<const US: u64>()
24+
delay_ms<const MS: u64>()
25+
delay_sec<const SEC: u64>()
2926
```
3027

31-
delay _us_ microseconds
28+
`delay_cycles` accepts 0 to 25_769_803_784 cycles (almost 18 minutes at 24Mhz).
29+
30+
The other functions convert time to cycles by using CPU_FREQUENCY_HZ.
3231

3332
```rust
34-
delay_ms(ms: u32)
33+
delay_ms<42>(); // delay by 42ms (exactly 1_008_000 cycles at 24Mhz).
3534
```
3635

37-
delay _ms_ milliseconds
36+
## Example
3837

3938
A simple example of how to use it follows.
4039

@@ -64,7 +63,7 @@ extern crate avr_delay;
6463

6564
use arduino::{DDRB, PORTB};
6665
use core::ptr::write_volatile;
67-
use avr_delay::{delay, delay_ms, delay_us};
66+
use avr_delay::delay_ms;
6867

6968
#[no_mangle]
7069
pub extern fn main() {
@@ -73,7 +72,7 @@ pub extern fn main() {
7372
loop {
7473
out = out ^ 0xff;
7574
unsafe { write_volatile(PORTB, out) }
76-
delay_ms(1000000);
75+
delay_ms<1000000>();
7776
}
7877
}
7978

0 commit comments

Comments
 (0)