Standard Library Reference¶
The standard library lives in std/ and is written in ik itself. Pull a
module into your program with import, naming it by path without the .ik
extension:
import std/gpio
import std/delay
General rules¶
A handful of conventions hold across the whole library:
No dynamic allocation. Nothing uses a heap. When a routine needs scratch space or an output buffer, you declare it and pass a pointer.
Strings are caller-owned ``str ram``. The string and conversion routines operate on NUL-terminated SRAM strings and
ptr ram u8buffers; there are nostr flashvariants in their signatures.Peripheral modules depend on ``target``.
std/gpio,std/uart,std/spi,std/twi,std/adc,std/pwm, andstd/timerresolve their register addresses for the selected device via compile-time? target == ...blocks. A function only makes sense on a device that actually has the corresponding peripheral, port, or instance.The CPU clock is a project constant. Time-based code (
std/delay) calls a@cpu_mhz()function that you define once per project.Some routines wrap intrinsics. Library code freely uses the compiler intrinsics
@burn,@cli,@sei, and@nop(see Compiler intrinsics).
A note on naming: functions whose names begin with an underscore (for example
@_delay_ms or @_eeprom_wait) are internal primitives. They are
documented for completeness, but day-to-day code uses the public wrappers.
Hardware and peripherals¶
std/gpio— Digital I/O pinsstd/uart— Serial USARTstd/spi— SPI masterstd/twi— I²C / TWI masterstd/adc— Analog-to-digitalstd/pwm— Pulse-width mod.std/timer— Timersstd/eeprom— EEPROMstd/wdt— Watchdog timerstd/sleep— Sleep modesstd/boot— Flash self-programming (SPM)std/bootloader— Serial firmware bootloader
Concurrency and buffers¶
Time¶
Strings, conversion, and memory¶
Numeric and bit manipulation¶
Graphics¶
Module summary¶
Module |
Summary |
|---|---|
|
Per-port pin mode, read, write, and toggle. |
|
Blocking USART transmit/receive (USART0–5). |
|
Blocking master-mode SPI byte transfer. |
|
I²C / TWI master primitives. |
|
Analog-to-digital conversion reads. |
|
Fast-PWM setup for Timer0 (8-bit) and Timer1 (16-bit). |
|
Timer0/Timer1 prescaler, compare, count, and CTC mode. |
|
Byte read/write of on-chip EEPROM. |
|
Watchdog timer enable/disable/reset. |
|
Sleep-mode entry and configuration. |
|
Flash self-programming (SPM) for bootloaders. |
|
Ready-made serial firmware bootloader over USART0. |
|
Save/restore SREG around a critical section. |
|
Caller-owned byte ring buffer. |
|
Blocking millisecond/microsecond delays. |
|
String and character-class routines. |
|
Integer ↔ string (decimal and hexadecimal). |
|
Memory block routines. |
|
Rotation, population count, parity, and bit reversal. |
|
CRC-8 (Dallas/Maxim) and CRC-16 (IBM/ANSI). |
|
Q8.8 fixed-point math: trig, logs, roots, and more. |
|
5×8 font: render to a buffer, stream, or fold. |