pokeys-lib 1.0.4

Pure Rust core library for PoKeys device control - USB/Network connectivity, I/O, PWM, encoders, SPI/I2C protocols
Documentation
---
import '../../styles/global.css';
---

<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<meta name="viewport" content="width=device-width" />
		<meta name="generator" content={Astro.generator} />
		<title>Pin Functions API - PoKeys Core Library</title>
		<style>
			aside .sidebar-nav a {
				display: block !important;
				width: 100% !important;
			}
			aside .sidebar-nav {
				display: flex !important;
				flex-direction: column !important;
			}
		</style>
	</head>
	<body class="bg-gray-900 text-white">
		<!-- Navigation -->
		<nav class="fixed top-0 left-0 right-0 z-50 bg-gray-900/80 backdrop-blur-md border-b border-gray-800 h-16">
			<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-full">
				<div class="flex justify-between items-center h-full">
					<a href="/core/" class="text-2xl font-bold bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent">
						PoKeys
					</a>
					<div class="hidden md:flex space-x-8">
						<a href="/core/" class="text-gray-300 hover:text-white transition-colors">Home</a>
						<a href="/core/getting-started" class="text-gray-300 hover:text-white transition-colors">Getting Started</a>
						<a href="/core/examples/" class="text-gray-300 hover:text-white transition-colors">Examples</a>
						<a href="/core/api/" class="text-white font-semibold">API Reference</a>
					</div>
				</div>
			</div>
		</nav>

		<!-- Main Content -->
		<div class="flex min-h-screen pt-16">
			<!-- Sidebar -->
			<aside class="w-80 bg-gray-800/50 border-r border-gray-700 overflow-y-auto flex-shrink-0">
				<div class="p-6">
					<a href="/core/api/" class="text-blue-400 hover:text-blue-300 mb-4 inline-block">← Back to API Reference</a>
					<h2 class="text-xl font-bold mb-6 text-white">API Reference</h2>
					
					<!-- Core APIs -->
					<div class="mb-6">
						<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Core APIs</h3>
						<div class="space-y-1 sidebar-nav">
							<a href="/core/api/device" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Device Management
							</a>
							<a href="/core/api/connection" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Connection & Enumeration
							</a>
							<a href="/core/api/models" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Device Models
							</a>
						</div>
					</div>

					<!-- I/O Operations -->
					<div class="mb-6">
						<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">I/O Operations</h3>
						<div class="space-y-1 sidebar-nav">
							<a href="/core/api/digital-io" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Digital I/O
							</a>
							<a href="/core/api/analog-io" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Analog I/O
							</a>
							<a href="/core/api/pin-functions" class="block px-3 py-2 text-white bg-gray-700/50 rounded-md transition-colors">
								Pin Functions
							</a>
						</div>
					</div>

					<!-- Control Systems -->
					<div class="mb-6">
						<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Control Systems</h3>
						<div class="space-y-1 sidebar-nav">
							<a href="/core/api/pwm" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								PWM Control
							</a>
							<a href="/core/api/encoders" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Encoders
							</a>
							<a href="/core/api/pulse-engine" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Pulse Engine v2
							</a>
							<a href="/core/api/servo-control" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Servo Control
							</a>
						</div>
					</div>

					<!-- Communication -->
					<div class="mb-6">
						<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Communication</h3>
						<div class="space-y-1 sidebar-nav">
							<a href="/core/api/spi" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								SPI Protocol
							</a>
							<a href="/core/api/i2c" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								I2C Protocol
							</a>
							<a href="/core/api/uart" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								UART Serial
							</a>
							<a href="/core/api/can" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								CAN Bus
							</a>
							<a href="/core/api/onewire" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								1-Wire Protocol
							</a>
						</div>
					</div>

					<!-- Matrix Operations -->
					<div class="mb-6">
						<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Matrix Operations</h3>
						<div class="space-y-1 sidebar-nav">
							<a href="/core/api/matrix-keyboard" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Matrix Keyboard
							</a>
							<a href="/core/api/led-matrix" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								LED Matrix
							</a>
						</div>
					</div>

					<!-- Display & Sensors -->
					<div class="mb-6">
						<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Display & Sensors</h3>
						<div class="space-y-1 sidebar-nav">
							<a href="/core/api/lcd" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								LCD Display
							</a>
							<a href="/core/api/sensors" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								EasySensors
							</a>
							<a href="/core/api/rtc" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Real-Time Clock
							</a>
						</div>
					</div>

					<!-- Error Handling -->
					<div class="mb-6">
						<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Error Handling</h3>
						<div class="space-y-1 sidebar-nav">
							<a href="/core/api/errors" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Error Types
							</a>
							<a href="/core/api/result-handling" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Result Handling
							</a>
						</div>
					</div>

					<!-- Types & Utilities -->
					<div class="mb-6">
						<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Types & Utilities</h3>
						<div class="space-y-1 sidebar-nav">
							<a href="/core/api/types" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Core Types
							</a>
							<a href="/core/api/constants" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
								Constants
							</a>
						</div>
					</div>
				</div>
			</aside>

			<!-- Main Content Area -->
			<main class="flex-1 p-8 min-h-screen">
				<div class="max-w-4xl">
					<!-- Header -->
					<div class="mb-12">
						<div class="flex items-center gap-4 mb-6">
							<span class="px-3 py-1 bg-indigo-600/20 text-indigo-300 text-sm rounded-full">Pin Functions</span>
						</div>
						<h1 class="text-4xl font-bold mb-4 bg-gradient-to-r from-indigo-400 to-purple-500 bg-clip-text text-transparent">
							Pin Functions API
						</h1>
						<p class="text-xl text-gray-400">
							Pin function enumeration, configuration, and capability management
						</p>
					</div>

					<!-- Overview -->
					<section class="mb-12">
						<h2 class="text-2xl font-bold mb-4 text-white">Overview</h2>
						<div class="bg-gray-800 rounded-lg p-6">
							<p class="text-gray-300 mb-4">
								The Pin Functions API defines all available pin functions and provides utilities for pin configuration and validation. 
								Each pin can be configured for different functions based on device capabilities.
							</p>
						</div>
					</section>

					<!-- PinFunction Enum -->
					<section class="mb-12">
						<h2 class="text-2xl font-bold mb-6 text-white">PinFunction Enum</h2>
						<div class="bg-gray-800 rounded-lg p-6 mb-4">
							<p class="text-gray-300 mb-4">
								The wire-level pin-settings byte (byte 4 of protocol command
								<code class="bg-gray-700 px-1 rounded">0x10</code>) is a bitfield:
								the low seven bits carry the base function and bit 7
								(<code class="bg-gray-700 px-1 rounded">0x80</code>, the invert
								flag) composes with any digital function. This enum represents the
								base function only. Use
								<code class="bg-gray-700 px-1 rounded">set_pin_function_with_invert</code>
								to apply the invert flag.
							</p>
							<div class="bg-gray-900 rounded p-4">
								<pre class="text-gray-300"><code>pub enum PinFunction {`{`}
    PinRestricted  = 0,
    Reserved       = 1,
    DigitalInput   = 2,
    DigitalOutput  = 4,
    AnalogInput    = 8,
    AnalogOutput   = 16,
    TriggeredInput = 32,
    DigitalCounter = 64,

    #[deprecated]
    InvertPin      = 128, // protocol bit, not a standalone function
{`}`}</code></pre>
							</div>
						</div>
					</section>

					<!-- Function Descriptions -->
					<section class="mb-12">
						<h2 class="text-2xl font-bold mb-6 text-white">Function Descriptions</h2>
						<div class="space-y-4">
							<div class="bg-gray-800 rounded-lg p-4">
								<h3 class="text-lg font-semibold mb-2 text-indigo-400">PinRestricted</h3>
								<p class="text-gray-300 text-sm">Pin is restricted / unassigned. Default state.</p>
							</div>
							<div class="bg-gray-800 rounded-lg p-4">
								<h3 class="text-lg font-semibold mb-2 text-gray-400">Reserved</h3>
								<p class="text-gray-300 text-sm">Pin reserved by firmware for internal use (e.g. SPI MOSI/CLK when SPI is active). Not available to user code.</p>
							</div>
							<div class="bg-gray-800 rounded-lg p-4">
								<h3 class="text-lg font-semibold mb-2 text-green-400">DigitalInput</h3>
								<p class="text-gray-300 text-sm">Pin configured for digital input reading (HIGH/LOW states). Honors the invert flag.</p>
							</div>
							<div class="bg-gray-800 rounded-lg p-4">
								<h3 class="text-lg font-semibold mb-2 text-blue-400">DigitalOutput</h3>
								<p class="text-gray-300 text-sm">Pin configured for digital output control (set HIGH/LOW). Honors the invert flag.</p>
							</div>
							<div class="bg-gray-800 rounded-lg p-4">
								<h3 class="text-lg font-semibold mb-2 text-teal-400">AnalogInput</h3>
								<p class="text-gray-300 text-sm">Pin configured for analog voltage measurement. Invert flag is ignored by firmware.</p>
							</div>
							<div class="bg-gray-800 rounded-lg p-4">
								<h3 class="text-lg font-semibold mb-2 text-teal-400">AnalogOutput</h3>
								<p class="text-gray-300 text-sm">Pin configured as an analog output (10-bit DAC). Invert flag is ignored.</p>
							</div>
							<div class="bg-gray-800 rounded-lg p-4">
								<h3 class="text-lg font-semibold mb-2 text-yellow-400">TriggeredInput</h3>
								<p class="text-gray-300 text-sm">Digital input that generates an event on an edge rather than a level. Honors the invert flag.</p>
							</div>
							<div class="bg-gray-800 rounded-lg p-4">
								<h3 class="text-lg font-semibold mb-2 text-orange-400">DigitalCounter</h3>
								<p class="text-gray-300 text-sm">Digital input counting edges. Invert flag is ignored.</p>
							</div>
							<div class="bg-gray-800 rounded-lg p-4 border border-red-500/30">
								<h3 class="text-lg font-semibold mb-2 text-red-400">InvertPin (deprecated)</h3>
								<p class="text-gray-300 text-sm">
									Kept for backward compatibility only. Represents bit 7 of the
									pin-settings byte — it is not a standalone pin function. To apply
									the invert flag, pass <code class="bg-gray-700 px-1 rounded">inverted: true</code>
									to <code class="bg-gray-700 px-1 rounded">set_pin_function_with_invert</code>.
								</p>
							</div>
						</div>
					</section>

					<!-- Note on PWM / Encoder / Keyboard -->
					<section class="mb-12">
						<h2 class="text-2xl font-bold mb-4 text-white">PWM, Encoders, and Keyboard Matrix</h2>
						<div class="bg-gray-800 rounded-lg p-6">
							<p class="text-gray-300">
								PWM output, encoder inputs, and matrix-keyboard pins are
								configured through dedicated APIs (see <a href="/core/api/pwm" class="text-blue-400 hover:text-blue-300">PWM</a>,
								<a href="/core/api/encoders" class="text-blue-400 hover:text-blue-300">Encoders</a>, and
								<a href="/core/api/matrix-keyboard" class="text-blue-400 hover:text-blue-300">Matrix Keyboard</a>),
								not via <code class="bg-gray-700 px-1 rounded">PinFunction</code>.
								PWM is restricted to pins 17–22 by hardware.
							</p>
						</div>
					</section>

					<!-- Usage Example -->
					<section class="mb-12">
						<h2 class="text-2xl font-bold mb-4 text-white">Usage Example</h2>
						<div class="bg-gray-800 rounded-lg p-6">
							<div class="bg-gray-900 rounded p-4">
								<pre class="text-gray-300"><code>use pokeys_lib::*;

fn main() -> Result&lt;()&gt; {`{`}
    let mut device = connect_to_device(0)?;

    // Configure basic pin functions
    device.set_pin_function(1, PinFunction::DigitalOutput)?;
    device.set_pin_function(2, PinFunction::DigitalInput)?;
    device.set_pin_function(3, PinFunction::AnalogInput)?;

    // Active-low switch on pin 4: firmware reports `true` when pin is LOW
    device.set_pin_function_with_invert(4, PinFunction::DigitalInput, true)?;

    // Use the configured pins
    device.set_digital_output(1, true)?;
    let input_state = device.get_digital_input(2)?;
    let analog_value = device.get_analog_input(3)?;
    let switch_pressed = device.get_digital_input(4)?;

    Ok(())
{`}`}</code></pre>
							</div>
						</div>
					</section>
				</div>
			</main>
		</div>
	</body>
</html>