Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/embedded/hal/fake"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
| Alias | Package | Source file |
|---|---|---|
executor |
std/embedded/executor |
fake.dodo |
hal |
std/embedded/hal |
fake.dodo |
io |
std/io |
fake.dodo |
option |
core/option |
fake.dodo |
power |
std/embedded/power |
fake.dodo |
ptr |
core/ptr |
fake.dodo |
serial |
std/embedded/hal/serial |
fake.dodo |
Pin
Struct · Source
An output and input pin. It starts low.
pub struct Pin {
// Private implementation fields omitted.
}
Pin.new
Function · Source
pub fn new() -> Pin
Pin.set_high
Function · Source
pub fn set_high(&mut self)
Pin.set_low
Function · Source
pub fn set_low(&mut self)
Pin.is_high
Function · Source
pub fn is_high(&self) -> bool
Pin.changes
Function · Source
Number of level changes so far, for example 2 per blink.
pub fn changes(&self) -> u32
Delay
Struct · Source
A delay that returns immediately and adds up the requested time. It is a counter too, whose time is that sum, so a driver that delays between polls of a device reaches its deadline without waiting.
pub struct Delay {
// Private implementation fields omitted.
}
Delay.new
Function · Source
pub fn new() -> Delay
Delay.delay_us
Function · Source
pub fn delay_us(&mut self, microseconds: u32)
Delay.elapsed_us
Function · Source
pub fn elapsed_us(&self) -> u64
Delay.now_us
Function · Source
The counter’s time: the delays so far.
pub fn now_us(&self) -> u64
Alarm
Struct · Source
A one-shot alarm on a simulated counter that starts at 0 and moves only when the test calls
advance. It reaches any time ahead.
pub struct Alarm {
// Private implementation fields omitted.
}
Alarm.new
Function · Source
pub fn new() -> Alarm
Alarm.now_us
Function · Source
pub fn now_us(&self) -> u64
Alarm.advance
Function · Source
Let
microsecondspass; the alarm fires if its time falls within them.
pub fn advance(&mut self, microseconds: u64)
Alarm.schedule_at_us
Function · Source
pub fn schedule_at_us(&mut self, time_us: u64) -> void!hal.Error
Alarm.cancel
Function · Source
pub fn cancel(&mut self)
Alarm.is_armed
Function · Source
True from scheduling until it fires or is cancelled.
pub fn is_armed(&self) -> bool
Alarm.fired
Function · Source
pub fn fired(&self) -> bool
Alarm.clear
Function · Source
pub fn clear(&mut self)
Alarm.target_us
Function · Source
The scheduled time, armed or not.
pub fn target_us(&self) -> u64
Alarm.schedules
Function · Source
Number of successful schedules so far.
pub fn schedules(&self) -> u32
Alarm.fail_next
Function · Source
Make the next schedule fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
TickCounter
Struct · Source
A counter at
tick_hzthat starts at 0 and moves only when the test callsadvance. Implements hal.TickCounter.
pub struct TickCounter: hal.TickCounter {
// Private implementation fields omitted.
}
TickCounter.new
Function · Source
pub fn new(tick_hz: u32) -> TickCounter
TickCounter.advance
Function · Source
pub fn advance(&mut self, ticks: u64)
TickCounter.tick_hz
Function · Source
pub fn tick_hz(&self) -> u32
TickCounter.now_ticks
Function · Source
pub fn now_ticks(&self) -> u64
Compare
Struct · Source
A compare channel on a simulated counter at
tick_hzthat starts at 0 and moves only when the test callsadvance. It reaches any count ahead unlessset_reachlimits it, as hardware with a narrower compare register does. Implements hal.Compare.
pub struct Compare: hal.Compare {
// Private implementation fields omitted.
}
Compare.new
Function · Source
pub fn new(tick_hz: u32) -> Compare
Compare.set_reach
Function · Source
Refuse counts more than
ticksahead with InvalidInput.
pub fn set_reach(&mut self, ticks: u64)
Compare.advance
Function · Source
Let
tickspass; the channel fires if its count falls within them.
pub fn advance(&mut self, ticks: u64)
Compare.tick_hz
Function · Source
pub fn tick_hz(&self) -> u32
Compare.now_ticks
Function · Source
pub fn now_ticks(&self) -> u64
Compare.schedule_at_ticks
Function · Source
pub fn schedule_at_ticks(&mut self, ticks: u64) -> void!hal.Error
Compare.cancel
Function · Source
pub fn cancel(&mut self)
Compare.fired
Function · Source
pub fn fired(&self) -> bool
Compare.clear
Function · Source
pub fn clear(&mut self)
Compare.listen
Function · Source
pub fn listen(&mut self)
Compare.ignore
Function · Source
pub fn ignore(&mut self)
Compare.is_listening
Function · Source
pub fn is_listening(&self) -> bool
Compare.is_raised
Function · Source
True while its interrupt would be raised: it fired and listens.
pub fn is_raised(&self) -> bool
Compare.is_armed
Function · Source
True from scheduling until it fires or is cancelled.
pub fn is_armed(&self) -> bool
Compare.target_ticks
Function · Source
The scheduled count, armed or not.
pub fn target_ticks(&self) -> u64
Compare.schedules
Function · Source
Number of successful schedules so far.
pub fn schedules(&self) -> u32
Compare.fail_next
Function · Source
Make the next schedule fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
PeriodicTimer
Struct · Source
A periodic timer on a simulated counter at
tick_hzthat starts at 0 and moves only when the test callsadvance. Periods up toset_max_period(any at first) are accepted. Implements hal.PeriodicTimer.
pub struct PeriodicTimer: hal.PeriodicTimer {
// Private implementation fields omitted.
}
PeriodicTimer.new
Function · Source
pub fn new(tick_hz: u32) -> PeriodicTimer
PeriodicTimer.set_max_period
Function · Source
Refuse periods longer than
tickswith InvalidInput.
pub fn set_max_period(&mut self, ticks: u64)
PeriodicTimer.advance
Function · Source
Let
tickspass; every period that ends within them counts.
pub fn advance(&mut self, ticks: u64)
PeriodicTimer.tick_hz
Function · Source
pub fn tick_hz(&self) -> u32
PeriodicTimer.now_ticks
Function · Source
pub fn now_ticks(&self) -> u64
PeriodicTimer.start
Function · Source
pub fn start(&mut self, period_ticks: u64) -> void!hal.Error
PeriodicTimer.cancel
Function · Source
pub fn cancel(&mut self)
PeriodicTimer.poll_periods
Function · Source
pub fn poll_periods(&mut self) -> u32
PeriodicTimer.listen
Function · Source
pub fn listen(&mut self)
PeriodicTimer.ignore
Function · Source
pub fn ignore(&mut self)
PeriodicTimer.is_listening
Function · Source
pub fn is_listening(&self) -> bool
PeriodicTimer.is_raised
Function · Source
True while its interrupt would be raised: a period ended that was not polled yet, and it listens.
pub fn is_raised(&self) -> bool
PeriodicTimer.is_running
Function · Source
pub fn is_running(&self) -> bool
PeriodicTimer.period_ticks
Function · Source
pub fn period_ticks(&self) -> u64
PeriodicTimer.next_ticks
Function · Source
The count at which the next period ends.
pub fn next_ticks(&self) -> u64
PeriodicTimer.starts
Function · Source
Number of successful starts so far.
pub fn starts(&self) -> u32
PeriodicTimer.fail_next
Function · Source
Make the next start fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
InputCapture
Struct · Source
A capture channel at
tick_hzwhose events the test makes withevent. It holds up toset_depthevents (16, and 16 at most), as a FIFO in hardware does; one that arrives while it is full is lost and the next poll reports Overrun. Implements hal.InputCapture.
pub struct InputCapture: hal.InputCapture {
// Private implementation fields omitted.
}
InputCapture.new
Function · Source
pub fn new(tick_hz: u32) -> InputCapture
InputCapture.set_depth
Function · Source
Hold at most
eventsevents, 1 to 16; 1 is a single capture register.
pub fn set_depth(&mut self, events: usize)
InputCapture.event
Function · Source
An event at tick count
ticks, as if the input saw one then.
pub fn event(&mut self, ticks: u64)
InputCapture.waiting
Function · Source
The events waiting to be read.
pub fn waiting(&self) -> usize
InputCapture.tick_hz
Function · Source
pub fn tick_hz(&self) -> u32
InputCapture.poll_event
Function · Source
pub fn poll_event(&mut self, ticks: &mut u64) -> bool!hal.Error
InputCapture.listen
Function · Source
pub fn listen(&mut self)
InputCapture.ignore
Function · Source
pub fn ignore(&mut self)
InputCapture.is_listening
Function · Source
pub fn is_listening(&self) -> bool
InputCapture.is_raised
Function · Source
True while its interrupt would be raised: an event waits and it listens.
pub fn is_raised(&self) -> bool
InputCapture.fail_next
Function · Source
Make the next poll fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
I2c
Struct · Source
One I2C device with 256 numbered 8-bit registers, the layout used by most sensors. A write sets the register pointer from its first byte and stores any following bytes at successive registers; a read continues from the pointer. Other addresses report NoAcknowledge.
It also implements hal.I2cPoll: a polled transaction takes the number of polls set by
set_poll_steps(1 at first) and happens, all at once, on the last of them.
pub struct I2c: hal.I2c + hal.I2cPoll {
// Private implementation fields omitted.
}
I2c.new
Function · Source
pub fn new(address: u8) -> I2c
I2c.set_poll_steps
Function · Source
Make each polled transaction take
pollspolls, at least 1.
pub fn set_poll_steps(&mut self, polls: u32)
I2c.cancels
Function · Source
How many polled transactions were cancelled.
pub fn cancels(&self) -> u32
I2c.is_busy
Function · Source
True while a polled transaction runs.
pub fn is_busy(&self) -> bool
I2c.poll_write
Function · Source
pub fn poll_write(&mut self, address: u8, bytes: &[u8]) -> bool!hal.Error
I2c.poll_read
Function · Source
pub fn poll_read(&mut self, address: u8, buffer: &mut[u8]) -> bool!hal.Error
I2c.poll_write_read
Function · Source
pub fn poll_write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut[u8]) -> bool!hal.Error
I2c.cancel
Function · Source
pub fn cancel(&mut self)
I2c.register
Function · Source
pub fn register(&self, index: u8) -> u8
I2c.set_register
Function · Source
pub fn set_register(&mut self, index: u8, value: u8)
I2c.fail_next
Function · Source
Make the next transaction fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
I2c.write
Function · Source
pub fn write(&mut self, address: u8, bytes: &[u8]) -> void!hal.Error
I2c.read
Function · Source
pub fn read(&mut self, address: u8, buffer: &mut[u8]) -> void!hal.Error
I2c.write_read
Function · Source
pub fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut[u8]) -> void!hal.Error
Spi
Struct · Source
An SPI bus that records the most recent 64 bytes sent and answers each byte from a programmed reply, then with zeros.
It also implements hal.SpiPoll: each poll exchanges at most the number of bytes set by
set_poll_chunk(all at first).
pub struct Spi: hal.Spi + hal.SpiPoll {
// Private implementation fields omitted.
}
Spi.new
Function · Source
pub fn new() -> Spi
Spi.set_poll_chunk
Function · Source
Exchange at most
bytesbytes per poll; 0 for all of them.
pub fn set_poll_chunk(&mut self, bytes: usize)
Spi.polls
Function · Source
Polls made of polled transfers so far.
pub fn polls(&self) -> u32
Spi.poll_transfer
Function · Source
pub fn poll_transfer(&mut self, bytes: &mut[u8]) -> bool!hal.Error
Spi.poll_write
Function · Source
pub fn poll_write(&mut self, bytes: &[u8]) -> bool!hal.Error
Spi.cancel
Function · Source
pub fn cancel(&mut self)
Spi.is_busy
Function · Source
pub fn is_busy(&self) -> bool
Spi.reply_with
Function · Source
Bytes the device answers with, in order. At most 64.
pub fn reply_with(&mut self, bytes: &[u8])
Spi.sent
Function · Source
Bytes sent since the last call to
clear, up to the first 64.
pub fn sent(&self) -> &[u8]
Spi.clear
Function · Source
pub fn clear(&mut self)
Spi.transfer
Function · Source
pub fn transfer(&mut self, bytes: &mut[u8]) -> void!hal.Error
Spi.write
Function · Source
pub fn write(&mut self, bytes: &[u8]) -> void!hal.Error
Pwm
Struct · Source
A PWM output that remembers its duty. It starts at 0, low.
pub struct Pwm {
// Private implementation fields omitted.
}
Pwm.new
Function · Source
An output whose duty runs from 0 to
max_duty, at least 1.
pub fn new(max_duty: u16) -> Pwm
Pwm.max_duty
Function · Source
pub fn max_duty(&self) -> u16
Pwm.set_duty
Function · Source
pub fn set_duty(&mut self, duty: u16) -> void!hal.Error
Pwm.duty
Function · Source
The duty last set.
pub fn duty(&self) -> u16
Pwm.changes
Function · Source
The number of duties set so far.
pub fn changes(&self) -> u32
Pwm.fail_next
Function · Source
Make the next set_duty fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
Analog
Struct · Source
An analog input that reads the value given to
set, at first 0, or the values given toqueue, one per read, before that.
pub struct Analog {
// Private implementation fields omitted.
}
Analog.new
Function · Source
An input whose values run from 0 to
max_value, such as 4095 for a 12-bit converter.
pub fn new(max_value: u16) -> Analog
Analog.max_value
Function · Source
pub fn max_value(&self) -> u16
Analog.set
Function · Source
Read
valuefrom now on, once queued values are used up. Traps if it is above max_value.
pub fn set(&mut self, value: u16)
Analog.queue
Function · Source
Values for the next reads to return in order, after any still unread, before the one given to
set. At most 32 can wait at once.
pub fn queue(&mut self, values: &[u16])
Analog.read
Function · Source
pub fn read(&mut self) -> u16!hal.Error
Analog.reads
Function · Source
The number of successful reads so far.
pub fn reads(&self) -> u32
Analog.fail_next
Function · Source
Make the next read fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
Rng
Struct · Source
A random number generator that fills buffers with the bytes given to
queue, in order, and after those with a counting pattern: 0, 1, 2, …, 255, 0, 1, … continuing across calls. Tests then see exactly which bytes a driver drew, and how many.
pub struct Rng {
// Private implementation fields omitted.
}
Rng.new
Function · Source
pub fn new() -> Rng
Rng.queue
Function · Source
Bytes for the next fills to return in order, after any still unread, before the counting pattern resumes. At most 64 can wait at once.
pub fn queue(&mut self, bytes: &[u8])
Rng.fill
Function · Source
pub fn fill(&mut self, bytes: &mut[u8]) -> void!hal.Error
Rng.drawn
Function · Source
The number of bytes filled so far.
pub fn drawn(&self) -> u32
Rng.fail_next
Function · Source
Make the next fill fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
Serial
Struct · Source
A serial port that records the most recent 256 bytes written and reads back bytes given to
feed, as if they had arrived on its receive line; once they are read, reads report end of input. Implements the std/io Reader and Writer protocols like the chips’ serial ports, so drivers for devices on a UART, and std/fmt output, can be tested on a desktop.It also implements serial.Port and serial.PollPort.
set_write_roomlimits how many bytes one poll_write takes, to test a driver against a full transmitter, andset_flush_pollshow many poll_flush calls report output still going out after a write.
pub struct Serial: serial.Port + serial.PollPort {
// Private implementation fields omitted.
}
Serial.new
Function · Source
pub fn new() -> Serial
Serial.set_write_room
Function · Source
Take at most
bytesbytes per poll_write; 0 for no limit.
pub fn set_write_room(&mut self, bytes: usize)
Serial.set_flush_polls
Function · Source
After each write, report output going out for
pollspoll_flush calls.
pub fn set_flush_polls(&mut self, polls: u32)
Serial.flushes
Function · Source
Times flush or a finished poll_flush saw all output gone.
pub fn flushes(&self) -> u32
Serial.poll_write
Function · Source
pub fn poll_write(&mut self, bytes: &[u8]) -> io.Poll!io.Error
Serial.flush
Function · Source
pub fn flush(&mut self) -> void!io.Error
Serial.poll_flush
Function · Source
pub fn poll_flush(&mut self) -> bool!io.Error
Serial.feed
Function · Source
Bytes for reads to return, after any still unread. At most 256 can wait at once.
pub fn feed(&mut self, bytes: &[u8])
Serial.sent
Function · Source
Bytes written since the last call to
clear, up to the first 256.
pub fn sent(&self) -> &[u8]
Serial.clear
Function · Source
pub fn clear(&mut self)
Serial.write
Function · Source
pub fn write(&mut self, bytes: &[u8]) -> usize!io.Error
Serial.read
Function · Source
pub fn read(&mut self, buffer: &mut[u8]) -> usize!io.Error
Serial.poll_read
Function · Source
The polling read of the chips’ serial ports: what has been fed and not read yet, up to
buffer.len, or Pending while nothing is waiting, as on a UART, rather than end of input.
pub fn poll_read(&mut self, buffer: &mut[u8]) -> io.Poll!io.Error
Clock
Struct · Source
A simulated clock for running std/embedded/executor tasks on a desktop. Time stands still while tasks run and jumps forward when the executor sleeps, to the time it asked for or to the next simulated interrupt, whichever comes first. A simulated interrupt raises its signal at its time, as a handler would, so tasks waiting for hardware events are tested without hardware. A sleep that nothing could end, with no time and no interrupt to come, traps instead of hanging the test.
pub struct Clock {
// Private implementation fields omitted.
}
Clock.new
Function · Source
A clock at time 0 with no interrupts to come.
pub fn new() -> Clock
Clock.now_us
Function · Source
pub fn now_us(&self) -> u64
Clock.interrupt_at
Function · Source
Raise
signalwhen the time reachestime_us, as an interrupt handler would; at most 16 can be waiting. A time already past raises it at the next sleep or advance.
pub fn interrupt_at(&mut self, time_us: u64, signal: &executor.Signal)
Clock.advance
Function · Source
Let
microsecondspass, as if a task were busy for that long, and raise the signals of interrupts that fall within it.
pub fn advance(&mut self, microseconds: u64)
Clock.sleep_until
Function · Source
The executor’s sleep: see the type’s comment.
pub fn sleep_until(&mut self, deadline: Option<u64>)
Clock.sleeps
Function · Source
How many times the executor slept, and for how long in all.
pub fn sleeps(&self) -> u32
Clock.idle_us
Function · Source
pub fn idle_us(&self) -> u64
I2cTarget
Struct · Source
An I2C target and the master that addresses it, played by the test:
master_write,master_read, andmaster_stopqueue what the master does, and the target’s poll reports it in order, as hal.I2cTarget requires. A master read waits until the driver answers withrespond; the bytes it read are inmaster_received. At most 64 steps wait at once, and 256 bytes are recorded.
pub struct I2cTarget: hal.I2cTarget {
// Private implementation fields omitted.
}
I2cTarget.new
Function · Source
pub fn new() -> I2cTarget
I2cTarget.master_write
Function · Source
The master addresses the target and writes
bytes.
pub fn master_write(&mut self, bytes: &[u8])
I2cTarget.master_read
Function · Source
The master addresses the target, or repeats a START, and reads
countbytes.
pub fn master_read(&mut self, count: usize)
I2cTarget.master_stop
Function · Source
The master ends the transaction with a STOP.
pub fn master_stop(&mut self)
I2cTarget.master_received
Function · Source
The bytes the master has read so far, up to the first 256.
pub fn master_received(&self) -> &[u8]
I2cTarget.is_idle
Function · Source
True once every queued step has been reported and answered.
pub fn is_idle(&self) -> bool
I2cTarget.fail_next
Function · Source
Make the next poll fail with
error, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
I2cTarget.poll
Function · Source
pub fn poll(&mut self, buffer: &mut[u8]) -> hal.I2cTargetEvent!hal.Error
I2cTarget.respond
Function · Source
pub fn respond(&mut self, bytes: &[u8]) -> usize!hal.Error
SpiTarget
Struct · Source
An SPI target and the master that clocks it, played by the test:
master_exchangeclocks bytes in from the master and out of the queue the driver filled, as many as the master sends; with the queue empty the target answers 0. 64 bytes wait in each direction at most; bytes the master sends beyond what waits unread are lost, and the next read reports Overrun.
pub struct SpiTarget: hal.SpiTarget {
// Private implementation fields omitted.
}
SpiTarget.new
Function · Source
pub fn new() -> SpiTarget
SpiTarget.master_exchange
Function · Source
The master sends
bytes, each replaced by the byte the target sent in its place.
pub fn master_exchange(&mut self, bytes: &mut[u8])
SpiTarget.queued
Function · Source
Bytes queued and not yet clocked out.
pub fn queued(&self) -> usize
SpiTarget.queue
Function · Source
pub fn queue(&mut self, bytes: &[u8]) -> usize!hal.Error
SpiTarget.read
Function · Source
pub fn read(&mut self, buffer: &mut[u8]) -> usize!hal.Error
PwmInput
Struct · Source
A PWM input that reports the measurements given to
queue, one per poll_capture, in order; with none waiting, poll_capture is false. At most 16 wait at once.
pub struct PwmInput: hal.PwmInput {
// Private implementation fields omitted.
}
PwmInput.new
Function · Source
pub fn new() -> PwmInput
PwmInput.queue
Function · Source
A measurement for a later poll_capture to report.
pub fn queue(&mut self, period_ns: u64, high_ns: u64, cycles: u32)
PwmInput.queue_signal
Function · Source
A signal of
frequency_hzthat is highpercentof each period, as a single-period measurement.
pub fn queue_signal(&mut self, frequency_hz: u32, percent: u32)
PwmInput.fail_next
Function · Source
pub fn fail_next(&mut self, error: hal.Error)
PwmInput.poll_capture
Function · Source
pub fn poll_capture(&mut self, capture: &mut hal.PulseCapture) -> bool!hal.Error
Can
Struct · Source
A CAN controller on a simulated bus. Frames sent are recorded, up to 16, for
sentto return, and withset_loopbackalso received, as a controller in loopback mode does; frames given toinjectarrive as if another node had sent them.set_transmit_roomlimits how many frames may wait to leave, untildrain_transmitsends them; up to 16 received frames wait. Classic CAN unless created withnew_fd.
pub struct Can: hal.Can {
// Private implementation fields omitted.
}
Can.new
Function · Source
pub fn new() -> Can
Can.new_fd
Function · Source
A CAN FD controller, which also sends and receives FD frames.
pub fn new_fd() -> Can
Can.set_loopback
Function · Source
Receive every frame sent, too.
pub fn set_loopback(&mut self, on: bool)
Can.set_transmit_room
Function · Source
Let at most
framesframes wait to leave, as a controller with that many transmit buffers on a bus where frames leave only whendrain_transmitsays so; 0 sends every frame at once (the default).
pub fn set_transmit_room(&mut self, frames: usize)
Can.drain_transmit
Function · Source
Let the frames waiting to leave go.
pub fn drain_transmit(&mut self)
Can.set_error_state
Function · Source
Change the fault confinement state; while BusOff, poll_send fails with Bus.
pub fn set_error_state(&mut self, state: hal.CanErrorState)
Can.inject
Function · Source
A frame arrives from another node. When 16 already wait, it is lost and the next poll_receive reports Overrun.
pub fn inject(&mut self, frame: &hal.CanFrame)
Can.sent_count
Function · Source
The frames sent so far, up to the first 16.
pub fn sent_count(&self) -> usize
Can.sent
Function · Source
pub fn sent(&self, index: usize) -> &hal.CanFrame
Can.waiting
Function · Source
Received frames still waiting.
pub fn waiting(&self) -> usize
Can.fail_next
Function · Source
pub fn fail_next(&mut self, error: hal.Error)
Can.poll_send
Function · Source
pub fn poll_send(&mut self, frame: &hal.CanFrame) -> bool!hal.Error
Can.poll_receive
Function · Source
pub fn poll_receive(&mut self, frame: &mut hal.CanFrame) -> bool!hal.Error
Can.error_state
Function · Source
pub fn error_state(&mut self) -> hal.CanErrorState!hal.Error
I2sOutput
Struct · Source
An I2S output that records the samples it plays, up to the first 1024, and takes at most
roomsamples per poll_write, as a stream whose queue is full.
pub struct I2sOutput: hal.I2sOutput {
// Private implementation fields omitted.
}
I2sOutput.new
Function · Source
A stream of
sample_rateframes per second withchannels(1 or 2) samples each.
pub fn new(sample_rate: u32, channels: u32) -> I2sOutput
I2sOutput.set_room
Function · Source
Take at most
samplessamples per poll_write, rounded down to whole frames; 0 for no limit.
pub fn set_room(&mut self, samples: usize)
I2sOutput.played
Function · Source
The samples queued so far, up to the first 1024.
pub fn played(&self) -> &[i32]
I2sOutput.total
Function · Source
How many samples were queued in all.
pub fn total(&self) -> usize
I2sOutput.sample_rate
Function · Source
pub fn sample_rate(&self) -> u32
I2sOutput.channels
Function · Source
pub fn channels(&self) -> u32
I2sOutput.poll_write
Function · Source
pub fn poll_write(&mut self, samples: &[i32]) -> usize!hal.Error
I2sInput
Struct · Source
An I2S input that delivers the samples given to
feed, at mostroomper poll_read.drop_samplesmakes the next read report Overrun.
pub struct I2sInput: hal.I2sInput {
// Private implementation fields omitted.
}
I2sInput.new
Function · Source
pub fn new(sample_rate: u32, channels: u32) -> I2sInput
I2sInput.feed
Function · Source
Samples for later reads, after any unread; whole frames, at most 1024 waiting at once.
pub fn feed(&mut self, samples: &[i32])
I2sInput.set_room
Function · Source
Deliver at most
samplessamples per read, rounded down to whole frames; 0 for no limit.
pub fn set_room(&mut self, samples: usize)
I2sInput.drop_samples
Function · Source
Report Overrun on the next read, as if samples had been lost.
pub fn drop_samples(&mut self)
I2sInput.sample_rate
Function · Source
pub fn sample_rate(&self) -> u32
I2sInput.channels
Function · Source
pub fn channels(&self) -> u32
I2sInput.poll_read
Function · Source
pub fn poll_read(&mut self, samples: &mut[i32]) -> usize!hal.Error
DmaBuffer
Struct · Source
A DMA buffer transfer without DMA: it holds up to 256 bytes of its own, and a transfer finishes after the number of polls set by
set_poll_steps(1 at first). A transmitting buffer records what each transfer sent, forsent; a receiving one fills the buffer from the bytes given tofeed, then zeros.
pub struct DmaBuffer: hal.DmaBuffer {
// Private implementation fields omitted.
}
DmaBuffer.transmit
Function · Source
A session that sends
capacitybytes at most, up to 256.
pub fn transmit(capacity: usize) -> DmaBuffer
DmaBuffer.receive
Function · Source
A session that receives
capacitybytes at most, up to 256.
pub fn receive(capacity: usize) -> DmaBuffer
DmaBuffer.set_poll_steps
Function · Source
pub fn set_poll_steps(&mut self, polls: u32)
DmaBuffer.feed
Function · Source
Bytes the next receive transfers deliver, in order, up to 256.
pub fn feed(&mut self, bytes: &[u8])
DmaBuffer.sent
Function · Source
What the last finished transmit transfer sent.
pub fn sent(&self) -> &[u8]
DmaBuffer.fail_next
Function · Source
Make the running or next transfer end with
error.
pub fn fail_next(&mut self, error: hal.Error)
DmaBuffer.is_busy
Function · Source
pub fn is_busy(&self) -> bool
DmaBuffer.buffer
Function · Source
pub fn buffer(&mut self) -> &mut[u8]!hal.Error
DmaBuffer.capacity
Function · Source
pub fn capacity(&self) -> usize
DmaBuffer.start
Function · Source
pub fn start(&mut self, count: usize) -> void!hal.Error
DmaBuffer.poll_finish
Function · Source
pub fn poll_finish(&mut self) -> bool!hal.Error
DmaBuffer.abort
Function · Source
pub fn abort(&mut self)
DmaChannel
Struct · Source
A DMA channel that runs transfers in host memory:
startmoves every element at once, through real addresses, and the channel then reports itself busy for the number of is_busy calls set byset_busy_polls(0 at first). Addresses that do not increment are read or written element by element, as a peripheral register would be, so a test passes the address of a variable standing in for the register. Pacing is ignored; rings are Unsupported. For testing code written against hal.DmaChannel, such as hal.DmaStream, on a desktop.
pub struct DmaChannel: hal.DmaChannel {
// Private implementation fields omitted.
}
DmaChannel.new
Function · Source
pub fn new() -> DmaChannel
DmaChannel.set_busy_polls
Function · Source
pub fn set_busy_polls(&mut self, polls: u32)
DmaChannel.set_max_count
Function · Source
The largest count a transfer may have, for max_count.
pub fn set_max_count(&mut self, count: u32)
DmaChannel.fail_next
Function · Source
Make the next transfer report a bus error to take_error.
pub fn fail_next(&mut self)
DmaChannel.starts
Function · Source
Transfers started and aborted so far.
pub fn starts(&self) -> u32
DmaChannel.aborts
Function · Source
pub fn aborts(&self) -> u32
DmaChannel.start
Function · Source
pub unsafe fn start(&mut self, transfer: hal.DmaTransfer) -> void!hal.Error
Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.
DmaChannel.is_busy
Function · Source
pub fn is_busy(&mut self) -> bool
DmaChannel.remaining
Function · Source
pub fn remaining(&mut self) -> u32
DmaChannel.max_count
Function · Source
pub fn max_count(&mut self) -> u32
DmaChannel.abort
Function · Source
pub fn abort(&mut self)
DmaChannel.take_error
Function · Source
pub fn take_error(&mut self) -> void!hal.Error
Flash
Struct · Source
NOR flash in caller-provided memory, with the hal Flash protocol, that checks the protocol strictly: it refuses misaligned and out-of-range requests and writes over bytes that are not erased with InvalidInput, so code that passes its tests here also works on flash that cannot rewrite a byte. It counts erases and written bytes, can fail its next operation, and can cut the power partway through an operation or just after one, to test recovery:
memory := [0u8; 16384] flash := fake.Flash.new(&mut memory, 4096, 4) flash.erase(0, 16384)!
Fresh memory holds whatever the caller filled it with; erase it first to start from blank flash.
pub struct Flash {
// Private implementation fields omitted.
}
Flash.new
Function · Source
Flash over
memory, whose length must be a nonzero multiple oferase_size; both sizes must be powers of two,write_sizeat most 256 and at mosterase_size. Traps otherwise.
pub fn new(memory: &mut[u8], erase_size: u32, write_size: u32) -> Flash from(memory)
Flash.capacity
Function · Source
pub fn capacity(&self) -> u32
Flash.erase_size
Function · Source
pub fn erase_size(&self) -> u32
Flash.write_size
Function · Source
pub fn write_size(&self) -> u32
Flash.read
Function · Source
pub fn read(&mut self, offset: u32, buffer: &mut[u8]) -> void!hal.Error
Flash.erase
Function · Source
pub fn erase(&mut self, offset: u32, length: u32) -> void!hal.Error
Flash.write
Function · Source
pub fn write(&mut self, offset: u32, bytes: &[u8]) -> void!hal.Error
Flash.erases
Function · Source
Blocks erased so far.
pub fn erases(&self) -> u32
Flash.written
Function · Source
Bytes written so far.
pub fn written(&self) -> u32
Flash.operations
Function · Source
Erases and writes completed so far.
pub fn operations(&self) -> u32
Flash.fail_next
Function · Source
Make the next operation fail with
error, changing nothing.
pub fn fail_next(&mut self, error: hal.Error)
Flash.cut_power_after
Function · Source
Cut the power once erases and writes have changed
bytesmore bytes: the operation in progress stops there, leaving the bytes it reached changed and the rest as they were, and fails with Bus, as does every operation after it until restore_power.
pub fn cut_power_after(&mut self, bytes: u32)
Flash.cut_power_after_operations
Function · Source
Cut the power just after
countmore erases and writes complete: they succeed, and every operation after them fails with Bus until restore_power. 0 cuts it now.
pub fn cut_power_after_operations(&mut self, count: u32)
Flash.is_off
Function · Source
True once a cut has happened.
pub fn is_off(&self) -> bool
Flash.restore_power
Function · Source
Turn the power back on and cancel a pending cut.
pub fn restore_power(&mut self)
Flash.memory
Function · Source
The memory, for inspecting or corrupting it.
pub fn memory(&mut self) -> &mut[u8] from(self)
Power
Struct · Source
A chip’s low-power controls in memory, implementing std/embedded/power’s protocol. Every clock starts running, awake and in deep sleep. The test says which clocks the simulated program cannot run without, which ones the simulated chip manages for peripherals, and which of those are claimed, and the fake records the sleeps and dormant states the code under test asks for. A dormant state ends on the pins given to
wake_next_dormant, or else on its timeout; one that nothing could end traps instead of hanging the test. Timeouts work untilrefuse_timeouts, which simulates a chip whose clocks all stop while it is dormant.
pub struct Power {
// Private implementation fields omitted.
}
Power.new
Function · Source
Clocks 0 to 63 all exist.
essentialcannot be disabled, andmanagedbelong to peripherals, which disable_unused_clocks stops unless claimed.
pub fn new(essential: power.Clocks, managed: power.Clocks) -> Power
Power.claim
Function · Source
Claim a peripheral’s clocks, as a chip does when the program takes the peripheral: they start and can no longer be disabled.
pub fn claim(&mut self, clocks: power.Clocks)
Power.release
Function · Source
Give a peripheral’s clocks back, as a chip does when the program releases the peripheral.
pub fn release(&mut self, clocks: power.Clocks)
Power.claimed
Function · Source
pub fn claimed(&self) -> power.Clocks
Power.wake_next_dormant
Function · Source
End the next dormant state as if
pins(bit n for pin n) changed; only those the dormant state waits for wake it. Without such a pin, a dormant state with a timeout ends on it.
pub fn wake_next_dormant(&mut self, pins: u64)
Power.refuse_timeouts
Function · Source
Refuse every later dormant state with a timeout, as a chip does whose clock for it has no time set (
busy: Busy) or does not run while dormant (Unsupported).
pub fn refuse_timeouts(&mut self, busy: bool)
Power.accept_timeouts
Function · Source
Accept timeouts again.
pub fn accept_timeouts(&mut self)
Power.requested_timeout_ms
Function · Source
The timeout of the last dormant state, 0 for none.
pub fn requested_timeout_ms(&self) -> u64
Power.dormant_ms
Function · Source
The milliseconds that dormant states ended by their timeouts have lasted, in total.
pub fn dormant_ms(&self) -> u64
Power.light_sleeps
Function · Source
Waits in each mode, and dormant states, so far.
pub fn light_sleeps(&self) -> u32
Power.deep_sleeps
Function · Source
pub fn deep_sleeps(&self) -> u32
Power.dormant_states
Function · Source
pub fn dormant_states(&self) -> u32
Power.requested_events
Function · Source
The events of
pinthe last dormant state waited for.
pub fn requested_events(&self, pin: u32) -> u32
Power.mode
Function · Source
pub fn mode(&self) -> power.Mode
Power.set_mode
Function · Source
pub fn set_mode(&mut self, mode: power.Mode)
Power.sleep
Function · Source
Returns at once, as if an interrupt were pending, and counts the wait.
pub fn sleep(&mut self)
Power.enabled_clocks
Function · Source
pub fn enabled_clocks(&self) -> power.Clocks
Power.enable_clocks
Function · Source
pub fn enable_clocks(&mut self, clocks: power.Clocks)
Power.disable_clocks
Function · Source
pub fn disable_clocks(&mut self, clocks: power.Clocks) -> void!hal.Error
Power.disable_unused_clocks
Function · Source
pub fn disable_unused_clocks(&mut self) -> power.Clocks
Power.sleep_clocks
Function · Source
pub fn sleep_clocks(&self) -> power.Clocks
Power.set_sleep_clocks
Function · Source
pub fn set_sleep_clocks(&mut self, clocks: power.Clocks)
Power.dormant
Function · Source
pub fn dormant(&mut self, wake: &power.Wake) -> u64!hal.Error
Rtc
Struct · Source
A real-time clock with an alarm, implementing hal.Rtc and hal.RtcAlarm. It starts unset, as a clock that has just been powered, and keeps time only as
advancesays. Its resolution is 1 ms unless made coarser, so drivers are tested against clocks that count whole seconds too.
pub struct Rtc: hal.Rtc + hal.RtcAlarm {
// Private implementation fields omitted.
}
Rtc.new
Function · Source
An unset clock that counts milliseconds.
pub fn new() -> Rtc
Rtc.with_resolution
Function · Source
An unset clock whose steps are
resolution_mslong, such as 1000 for one that counts seconds; at least 1.
pub fn with_resolution(resolution_ms: u32) -> Rtc
Rtc.advance
Function · Source
Let
millisecondspass. An unset clock stays unset.
pub fn advance(&mut self, milliseconds: u64)
Rtc.lose_power
Function · Source
Lose power: the time is gone and the alarm disarmed, as when a backup battery runs out.
pub fn lose_power(&mut self)
Rtc.is_armed
Function · Source
True from set_alarm_ms until clear_alarm or a loss of power.
pub fn is_armed(&self) -> bool
Rtc.alarm_ms
Function · Source
The time the alarm was last set for.
pub fn alarm_ms(&self) -> u64
Rtc.fail_next
Function · Source
Make the next operation fail with
error, as a clock chip on a bus may, for testing error paths.
pub fn fail_next(&mut self, error: hal.Error)
Rtc.is_set
Function · Source
pub fn is_set(&mut self) -> bool!hal.Error
Rtc.now_ms
Function · Source
pub fn now_ms(&mut self) -> u64!hal.Error
Rtc.set_ms
Function · Source
pub fn set_ms(&mut self, time_ms: u64) -> void!hal.Error
Rtc.resolution_ms
Function · Source
pub fn resolution_ms(&self) -> u32
Rtc.set_alarm_ms
Function · Source
pub fn set_alarm_ms(&mut self, time_ms: u64) -> void!hal.Error
Rtc.alarm_fired
Function · Source
pub fn alarm_fired(&mut self) -> bool!hal.Error
Rtc.clear_alarm
Function · Source
pub fn clear_alarm(&mut self) -> void!hal.Error