Skip to main content

PoKeysDevice

Struct PoKeysDevice 

Source
pub struct PoKeysDevice {
Show 22 fields pub info: DeviceInfo, pub device_data: DeviceData, pub network_device_data: Option<NetworkDeviceInfo>, pub model: Option<DeviceModel>, pub pins: Vec<PinData>, pub encoders: Vec<EncoderData>, pub pwm: PwmData, pub matrix_keyboard: MatrixKeyboard, pub matrix_led: Vec<MatrixLed>, pub lcd: LcdData, pub pulse_engine_v2: PulseEngineV2, pub easy_sensors: Vec<EasySensor>, pub rtc: RealTimeClock, pub fast_encoders_configuration: u8, pub fast_encoders_options: u8, pub ultra_fast_encoder_configuration: u8, pub ultra_fast_encoder_options: u8, pub ultra_fast_encoder_filter: u32, pub po_ext_bus_data: Vec<u8>, pub i2c_config: I2cConfig, pub i2c_metrics: I2cMetrics, pub validation_level: ValidationLevel, /* private fields */
}
Expand description

Main PoKeys device structure

Fields§

§info: DeviceInfo§device_data: DeviceData§network_device_data: Option<NetworkDeviceInfo>§model: Option<DeviceModel>§pins: Vec<PinData>§encoders: Vec<EncoderData>§pwm: PwmData§matrix_keyboard: MatrixKeyboard§matrix_led: Vec<MatrixLed>§lcd: LcdData§pulse_engine_v2: PulseEngineV2§easy_sensors: Vec<EasySensor>§rtc: RealTimeClock§fast_encoders_configuration: u8§fast_encoders_options: u8§ultra_fast_encoder_configuration: u8§ultra_fast_encoder_options: u8§ultra_fast_encoder_filter: u32§po_ext_bus_data: Vec<u8>§i2c_config: I2cConfig§i2c_metrics: I2cMetrics§validation_level: ValidationLevel

Implementations§

Source§

impl PoKeysDevice

Source

pub fn get_device_data(&mut self) -> Result<()>

Get device information from the connected device

Source

pub fn is_pin_capability_supported(&self, pin: u32, capability: &str) -> bool

Check if a pin supports a specific capability

§Arguments
  • pin - The pin number to check
  • capability - The capability to check for
§Returns
  • bool - True if the pin supports the capability, false otherwise
Source

pub fn get_pin_capabilities(&self, pin: u32) -> Vec<String>

Get all capabilities for a pin

§Arguments
  • pin - The pin number to get capabilities for
§Returns
  • Vec<String> - List of capabilities supported by the pin
Source

pub fn validate_pin_capability(&self, pin: u32, capability: &str) -> Result<()>

Validate that a pin can be configured with a specific capability

§Arguments
  • pin - The pin number to check
  • capability - The capability to check for
§Returns
  • Result<()> - Ok if the capability is valid, an error otherwise

Get related capabilities for a specific capability

§Arguments
  • pin - The pin number with the capability
  • capability - The capability to find related capabilities for
§Returns
  • Vec<(String, u8)> - List of related capabilities and their pin numbers
Source

pub fn save_configuration(&mut self) -> Result<()>

Save current configuration to device

Source

pub fn get_system_load(&mut self) -> Result<u8>

Get the device’s current system load as a percentage (0–100).

Sends the “Get system load status” command (0x05) defined in the PoKeys protocol specification. The device replies with the current CPU/system load in byte 3 of the response.

Source

pub fn set_device_name(&mut self, name: &str) -> Result<()>

Set the device name (up to 20 bytes for the long device name).

Sends protocol command 0x06 with “write long device name” flags set. After the write succeeds, save_configuration is called to persist the value to non-volatile storage — 0x06 alone does not auto-save.

§Side effect

The request packet includes fields for the joystick device name (spec bytes 19–34) and the product-ID offset (byte 35) that this implementation always sends as zero. If the target device was using those fields, they will be cleared as a side effect of this call.

Source

pub fn clear_configuration(&mut self) -> Result<()>

Reset device configuration to defaults (protocol command 0x52 “Disable lock and reset configuration”). Requires the magic bytes 0xAA, 0x55 to match the spec and the upstream PoKeysLib behaviour.

Source

pub fn reboot_device(&mut self) -> Result<()>

Reboot the device (command 0xF3).

Sends the “Reboot system” command defined in the PoKeys protocol specification. The device may reboot before a response reaches the host; transfer-level failures caused by the interrupted response are treated as success, as the request was already delivered.

After a successful reboot the active connection is effectively invalidated — callers should re-enumerate and reconnect before issuing further commands.

Source

pub fn custom_request( &mut self, request_type: u8, param1: u8, param2: u8, param3: u8, param4: u8, ) -> Result<[u8; 68]>

Send custom request to device

Source

pub fn set_ethernet_retry_count_and_timeout( &mut self, send_retries: u32, read_retries: u32, timeout_ms: u32, )

Set ethernet retry count and timeout

Source

pub fn get_connection_type(&self) -> DeviceConnectionType

Get connection type

Source

pub fn set_i2c_config(&mut self, config: I2cConfig)

Set I2C configuration

Source

pub fn get_i2c_config(&self) -> &I2cConfig

Get I2C configuration

Source

pub fn set_validation_level(&mut self, level: ValidationLevel)

Set validation level

Source

pub fn get_i2c_metrics(&self) -> &I2cMetrics

Get I2C metrics

Source

pub fn reset_i2c_metrics(&mut self)

Reset I2C metrics

Source

pub fn health_check(&mut self) -> HealthStatus

Perform device health check

Source

pub fn check_pin_capability(&self, pin: u32, capability: PinCapability) -> bool

Check if device supports a specific capability

Source

pub fn get_network_configuration( &mut self, timeout_ms: u32, ) -> Result<(Option<NetworkDeviceSummary>, NetworkDeviceInfo)>

Get complete network configuration including discovery info

Source

pub fn set_network_configuration( &mut self, config: &NetworkDeviceInfo, ) -> Result<()>

Set network configuration on the device.

Sends command 0xE0 with option 10, which writes and saves the configuration to non-volatile storage in one operation — no separate save_configuration call is needed.

§Field mapping
NetworkDeviceInfo fieldProtocol byte (doc)Notes
dhcp90 = fixed IP, 1 = DHCP
ip_address_setup10–13Applied when dhcp == 0
tcp_timeout (ms)18–19Stored in units of 100 ms
gateway_ip20–23Applied when non-zero
subnet_mask24–27Applied when non-zero
additional_network_options29Upper nibble forced to 0xA

ip_address_current is read-only (assigned by DHCP) and is ignored here.

Source

pub fn send_request( &mut self, request_type: u8, param1: u8, param2: u8, param3: u8, param4: u8, ) -> Result<[u8; 68]>

Source

pub fn send_request_with_data( &mut self, request_type: u8, param1: u8, param2: u8, param3: u8, param4: u8, data: &[u8], ) -> Result<[u8; 68]>

Send request with data payload

Source

pub fn read_device_data(&mut self) -> Result<()>

Read comprehensive device data using command 0x00 This provides accurate device information including proper firmware version and device type

Source

pub fn configure_led_matrix( &mut self, config: &MatrixLedProtocolConfig, ) -> Result<()>

Command 0xD5: Get/Set Matrix LED Configuration

Source

pub fn read_led_matrix_config(&mut self) -> Result<MatrixLedProtocolConfig>

Read Matrix LED Configuration

Source

pub fn update_led_matrix( &mut self, matrix_id: u8, action: MatrixAction, row: u8, column: u8, data: &[u8], ) -> Result<()>

Command 0xD6: Update Matrix Display

Source

pub fn configure_matrix_keyboard( &mut self, width: u8, height: u8, column_pins: &[u8], row_pins: &[u8], ) -> Result<()>

Command 0xCA: Configure Matrix Keyboard

Configures a matrix keyboard using the official PoKeys protocol. Uses command 0xCA with option 16 for configuration.

§Arguments
  • width - Number of columns (1-8)
  • height - Number of rows (1-16)
  • column_pins - Pin numbers for columns (1-based)
  • row_pins - Pin numbers for rows (1-based)
§Protocol Details
  • Pins are converted to 0-based indexing for the device
  • Matrix uses 8-column internal layout regardless of configured width
  • Supports extended row pins for matrices with height > 8
Source

pub fn read_matrix_keyboard(&mut self) -> Result<()>

Command 0xCA: Read Matrix Keyboard State

Reads the current state of all keys in the matrix keyboard. Uses command 0xCA with option 20 to read the 16x8 matrix status.

§Protocol Details
  • Returns 16 bytes representing the full 16x8 matrix
  • Each byte represents 8 keys in a row (bit 0 = column 0, bit 7 = column 7)
  • Key indexing: row * 8 + column (e.g., key at row 1, col 2 = index 10)
  • Updates the internal key_values array with current state
Source

pub fn configure_led_matrices( &mut self, configs: &[LedMatrixConfig], ) -> Result<()>

Configure multiple LED matrices with device model validation

This method validates all configurations against the device model first, then applies the configurations and reserves the necessary pins.

§Arguments
  • configs - Array of LED matrix configurations
§Returns
  • Result<()> - Ok if all configurations were applied successfully
Source

pub fn configure_servo(&mut self, config: ServoConfig) -> Result<()>

Configure and control a servo motor

Source

pub fn set_servo_angle( &mut self, config: &ServoConfig, angle: f32, ) -> Result<()>

Set servo angle (for position servos)

Source

pub fn set_servo_speed( &mut self, config: &ServoConfig, speed: f32, ) -> Result<()>

Set servo speed (for speed servos)

Source

pub fn stop_servo(&mut self, config: &ServoConfig) -> Result<()>

Stop servo (for speed servos)

Source§

impl PoKeysDevice

Source

pub fn configure_encoder( &mut self, encoder_id: u8, channel_a_pin: u8, channel_b_pin: u8, options: EncoderOptions, ) -> Result<()>

Configure encoder with pins and options Protocol: 0x11 - Individual encoder settings (per protocol spec)

Source

pub fn read_encoder_settings(&mut self, encoder_id: u8) -> Result<EncoderData>

Read encoder settings using protocol 0x16

Source

pub fn enable_encoder(&mut self, encoder_id: u8, enable: bool) -> Result<()>

Enable or disable encoder

Source

pub fn set_encoder_sampling( &mut self, encoder_id: u8, sampling_4x: bool, sampling_2x: bool, ) -> Result<()>

Set encoder sampling mode (4x or 2x)

Source

pub fn configure_encoder_key_mapping_a( &mut self, encoder_id: u8, key_code: u8, key_modifier: u8, ) -> Result<()>

Configure encoder key mapping for direction A Protocol: 0x12 - Encoder key mapping for direction A

Source

pub fn configure_encoder_key_mapping_b( &mut self, encoder_id: u8, key_code: u8, key_modifier: u8, ) -> Result<()>

Configure encoder key mapping for direction B Protocol: 0x13 - Encoder key mapping for direction B

Source

pub fn read_encoder_key_mapping_a(&mut self, encoder_id: u8) -> Result<(u8, u8)>

Read encoder key mapping for direction A Protocol: 0x17 - Read encoder key mapping for direction A

Source

pub fn read_encoder_key_mapping_b(&mut self, encoder_id: u8) -> Result<(u8, u8)>

Read encoder key mapping for direction B Protocol: 0x18 - Read encoder key mapping for direction B

Source

pub fn read_encoder_raw_value(&mut self, encoder_id: u8) -> Result<i32>

Read encoder RAW value Protocol: 0x19 - Read encoder RAW value

Source

pub fn reset_encoder_raw_value(&mut self, encoder_id: u8) -> Result<()>

Reset encoder RAW value to zero Protocol: 0x1A - Reset encoder RAW value

Source

pub fn get_encoder_value(&mut self, encoder_id: u8) -> Result<i32>

Get encoder value (convenience method)

Source

pub fn reset_encoder(&mut self, encoder_id: u8) -> Result<()>

Reset encoder value (convenience method)

Source

pub fn read_encoder_long_values(&mut self, group: u8) -> Result<Vec<i32>>

Get encoder long RAW values (bulk operation) Protocol: 0xCD - Get encoder long RAW values option: 0 = encoders 1-13, 1 = encoders 14-26

Source

pub fn set_encoder_long_values( &mut self, group: u8, values: &[i32], ) -> Result<()>

Set encoder long RAW values (bulk operation) Protocol: 0xCD - Set encoder long RAW values option: 10 = encoders 1-13, 11 = encoders 14-26

Source

pub fn read_all_encoder_values(&mut self) -> Result<Vec<i32>>

Read all encoder values using bulk operations (more efficient)

Source

pub fn configure_encoder_options_bulk( &mut self, options: &[u8], ) -> Result<Vec<u8>>

Configure encoder options (bulk operation) Protocol: 0xC4 - Encoder option

Source

pub fn read_encoder_options_bulk(&mut self) -> Result<Vec<u8>>

Read encoder options (bulk operation) Protocol: 0xC4 - Encoder option

Source

pub fn configure_fast_encoders( &mut self, config: FastEncoderConfiguration, options: FastEncoderOptions, ) -> Result<()>

Configure the fast encoders via protocol command 0xCE.

0xCE uses two bytes: the configuration selector (which pin configuration / enable state to use) and the options byte (per-encoder direction invert + 4x-sampling control). They are passed as typed values so callers don’t have to know the bit layout.

Per PoKeysLib C reference (PoKeysLibEncoders.c:154): req[2] = FastEncodersConfiguration, req[3] = FastEncodersOptions.

Source

pub fn read_fast_encoder_values(&mut self) -> Result<[i32; 3]>

Read fast encoder values

Source

pub fn configure_ultra_fast_encoder( &mut self, enable: bool, options: UltraFastEncoderOptions, reset_on_index: bool, filter_delay: u32, ) -> Result<()>

Configure the ultra-fast encoder via protocol command 0x1C (PoKeys56E and later).

The ultra-fast encoder uses fixed pins: Pin 8 (Phase A), Pin 12 (Phase B), Pin 13 (Index).

Bit layout of the options byte matches PoKeysLib C reference (ePK_UltraFastEncoderOptions): bit 0 = invert direction, bit 1 = signal mode, bit 2 = enable 4x sampling. See UltraFastEncoderOptions.

Source

pub fn read_ultra_fast_encoder_config( &mut self, ) -> Result<(bool, UltraFastEncoderOptions, u32)>

Read the ultra-fast encoder’s current configuration.

Protocol: 0x1C with param1 = 0xFF to request a read. Returns the enable flag, decoded UltraFastEncoderOptions, and the filter delay (u32 LE at response bytes 8..12).

Source

pub fn read_ultra_fast_encoder_value(&mut self) -> Result<i32>

Read ultra-fast encoder value

Source

pub fn set_ultra_fast_encoder_value(&mut self, value: i32) -> Result<()>

Set ultra-fast encoder value

Source

pub fn configure_encoder_with_keys( &mut self, encoder_id: u8, channel_a_pin: u8, channel_b_pin: u8, sampling_4x: bool, sampling_2x: bool, dir_a_key_code: u8, dir_a_key_modifier: u8, dir_b_key_code: u8, dir_b_key_modifier: u8, ) -> Result<()>

Configure encoder with keyboard mapping (convenience method)

Source

pub fn get_encoder_sampling_mode(&self, encoder_id: u8) -> Result<String>

Get encoder sampling mode as string (for debugging/display)

Source

pub fn is_encoder_4x_sampling(&self, encoder_id: u8) -> Result<bool>

Check if encoder is configured for 4x sampling

Source

pub fn is_encoder_2x_sampling(&self, encoder_id: u8) -> Result<bool>

Check if encoder is configured for 2x sampling

Source

pub fn get_enabled_encoders(&self) -> Vec<u8>

Get all enabled encoders

Source§

impl PoKeysDevice

Source

pub fn set_pin_function( &mut self, pin: u32, pin_function: PinFunction, ) -> Result<(u32, PinFunction)>

Set a pin’s function (non-inverted polarity).

Thin wrapper over Self::set_pin_function_with_invert with inverted = false; byte-identical on the wire to the pre-invert behaviour for every existing caller.

Source

pub fn set_pin_function_with_invert( &mut self, pin: u32, pin_function: PinFunction, inverted: bool, ) -> Result<(u32, PinFunction)>

Set a pin’s function with an optional hardware invert flag.

When inverted == true, bit 7 (0x80) of protocol byte 4 is set, producing a combined wire byte such as 0x82 for inverted DigitalInput. The firmware then reports/drives the logical complement of the electrical state at no CPU cost to the caller.

Pin functions that honor the invert bit:

Pin functions that ignore the invert bit (firmware silently drops it):

For functions that ignore the flag, this method logs a warning via the log crate and still sends the byte as requested. Use Self::get_pin_invert to read the invert state back from the cache.

Source

pub fn get_pin_function(&self, pin: u32) -> Result<PinFunction>

Get pin function (base function only; the invert bit is ignored).

To read the invert flag, use Self::get_pin_invert.

Source

pub fn get_pin_invert(&self, pin: u32) -> Result<bool>

Return whether bit 7 (the hardware invert flag) is set on the pin’s cached configuration byte.

Reflects the most recently written or read-back wire byte; call Self::read_all_pin_functions first if you want the device’s current state rather than the local cache.

Source

pub fn get_digital_input(&mut self, pin: u32) -> Result<bool>

Read digital input

Source

pub fn set_digital_output(&mut self, pin: u32, value: bool) -> Result<bool>

Set digital output

Source

pub fn get_analog_input(&mut self, pin: u32) -> Result<u32>

Read analog input

Source

pub fn set_analog_output(&mut self, pin: u32, value: u32) -> Result<()>

Set analog output

Source

pub fn get_digital_counter(&mut self, pin: u32) -> Result<u32>

Read digital counter value

Source

pub fn reset_all_digital_counters(&mut self) -> Result<()>

Reset all digital counter values (protocol command 0x1D).

The PoKeys protocol does not support per-pin counter resets — 0x1D clears all digital counters at once.

Source

pub fn get_digital_inputs(&mut self) -> Result<()>

Read all digital inputs.

Uses two protocol commands:

  • 0x31 “Block inputs reading” — pins 1–32 packed into response bytes 3–6 (0-based 2–5)
  • 0x32 “Block inputs reading – part 2” — pins 33–55 packed into response bytes 3–5 (0-based 2–4)
Source

pub fn write_digital_outputs(&mut self) -> Result<()>

Write all digital outputs

Source

pub fn read_analog_inputs(&mut self) -> Result<()>

Read all analog inputs

Source

pub fn write_analog_outputs(&mut self) -> Result<()>

Write analog outputs for every pin currently configured as an analog output.

Sends one “Analog outputs settings” request (0x41) per pin, carrying the pin’s analog_value as a 10-bit DAC value (0–1023). Values larger than 10 bits are clamped by masking. The pin ID sent to the device is the 0-based pin code per the protocol spec (pin 43 → pin code 42).

Source

pub fn read_digital_counters(&mut self) -> Result<()>

Read digital counter values via protocol command 0xD8.

The request carries up to 13 pin IDs at spec bytes 9–21 (0-based 8–20) identifying which counters to return. The response packs thirteen 32-bit LE counter values at spec bytes 9–60 (0-based 8–59).

Source

pub fn read_all_pin_functions(&mut self) -> Result<[PinFunction; 55]>

Read all pin functions at once using extended mode (0xC0) This is much more efficient than reading pins individually Performance improvement: 55x fewer commands

Source

pub fn read_all_pin_settings_raw(&mut self) -> Result<[u8; 55]>

Read all 55 pin-setting bytes verbatim, including the invert bit (0x80) when set. Unlike Self::read_all_pin_functions, this preserves the full protocol byte so callers can reason about hardware-level polarity inversion.

Also refreshes the local pin cache with the returned bytes.

Source

pub fn set_all_pin_settings_raw(&mut self, raw: &[u8; 55]) -> Result<()>

Send all 55 pin-setting bytes verbatim using the bulk 0xC0 command. Callers compose each byte themselves — e.g. (PinFunction::DigitalInput as u8) | 0x80 for an inverted digital input.

The local pin cache is updated to match the bytes sent.

Source

pub fn set_all_pin_functions( &mut self, functions: &[PinFunction; 55], ) -> Result<()>

Set all pin functions at once using extended mode (0xC0) This is much more efficient than setting pins individually Performance improvement: 55x fewer commands — the 55-byte function array is sent in a single request instead of one request per pin.

Source

pub fn get_device_status(&mut self) -> Result<()>

Read combined device status (digital inputs, analog inputs, and encoder values) in a single round-trip using protocol command 0xCC (“Get device status (IO, analog, encoders)”).

Updates self.pins[*].digital_value_get, self.pins[*].analog_value (for up to 5 analog-input pins), and self.encoders[*].encoder_value (up to 25 channels).

Matrix keyboard rows and ultra-fast encoder data from the response are not applied here — use the dedicated methods for those when needed.

Source§

impl PoKeysDevice

Source

pub fn configure_lcd( &mut self, rows: u8, columns: u8, mode: LcdMode, ) -> Result<()>

Configure LCD display

Source

pub fn enable_lcd(&mut self, enable: bool) -> Result<()>

Enable or disable LCD

Source

pub fn lcd_write_line(&mut self, line: usize, text: &str) -> Result<()>

Write text to LCD line

Source

pub fn lcd_read_line(&self, line: usize) -> Result<String>

Read text from LCD line

Source

pub fn lcd_clear_line(&mut self, line: usize) -> Result<()>

Clear LCD line

Source

pub fn lcd_clear_all(&mut self) -> Result<()>

Clear entire LCD display

Source

pub fn lcd_write_at( &mut self, line: usize, column: usize, text: &str, ) -> Result<()>

Write text at specific position

Source

pub fn lcd_set_custom_character( &mut self, char_index: usize, pattern: &[u8; 8], ) -> Result<()>

Set custom character pattern

Source

pub fn lcd_update(&mut self) -> Result<()>

Update LCD display (refresh all changed lines)

Source§

impl PoKeysDevice

Source

pub fn configure_matrix_led( &mut self, led_index: usize, rows: u8, columns: u8, ) -> Result<()>

Configure matrix LED display

Source

pub fn update_matrix_led(&mut self, led_index: usize) -> Result<()>

Update matrix LED display

Source

pub fn set_matrix_led( &mut self, led_index: usize, row: usize, col: usize, state: bool, ) -> Result<()>

Set individual LED in matrix

Source

pub fn get_matrix_led( &self, led_index: usize, row: usize, col: usize, ) -> Result<bool>

Get individual LED state in matrix

Source

pub fn clear_matrix_led(&mut self, led_index: usize) -> Result<()>

Clear all LEDs in matrix

Source

pub fn set_all_matrix_led(&mut self, led_index: usize) -> Result<()>

Set all LEDs in matrix

Source§

impl PoKeysDevice

Source

pub fn read_oem_parameter(&mut self, index: u8) -> Result<Option<i32>>

Read a single OEM parameter from non-volatile storage.

Returns None if the parameter slot has never been written (the device clears the corresponding status bit on a factory reset).

§Errors

Returns PoKeysError::Parameter when index > OEM_PARAMETER_MAX_INDEX, or a communication error if the exchange fails.

Source

pub fn write_oem_parameter(&mut self, index: u8, value: i32) -> Result<()>

Write a single OEM parameter to non-volatile storage.

§Errors

Returns PoKeysError::Parameter when index > OEM_PARAMETER_MAX_INDEX, or a communication error if the exchange fails.

Source

pub fn get_location(&mut self) -> Result<Option<i32>>

Read the device location from OEM parameter storage.

The location is persisted at OEM parameter index LOCATION_PARAMETER_INDEX. Returns None if the location has never been set.

Source

pub fn set_location(&mut self, location: i32) -> Result<()>

Write the device location to OEM parameter storage.

The location is a user-defined integer stored in the device’s non-volatile OEM parameter slot at index LOCATION_PARAMETER_INDEX.

Source

pub fn clear_location(&mut self) -> Result<()>

Clear the device location from OEM parameter storage.

After this call get_location will return None.

Source

pub fn clear_oem_parameter(&mut self, index: u8) -> Result<()>

Clear a single OEM parameter, marking it as unset in non-volatile storage.

After clearing, read_oem_parameter returns None for this index until a new value is written.

§Errors

Returns PoKeysError::Parameter when index > OEM_PARAMETER_MAX_INDEX, or a communication error if the exchange fails.

Source§

impl PoKeysDevice

CAN protocol implementation

Source

pub fn can_configure(&mut self, baud_rate: u32, mode: u8) -> Result<()>

Configure CAN interface

Source

pub fn can_send(&mut self, message: &CanMessage) -> Result<()>

Send CAN message

Source

pub fn can_receive(&mut self) -> Result<Option<CanMessage>>

Receive CAN message

Source

pub fn can_set_filter(&mut self, filter_id: u32, mask: u32) -> Result<()>

Set CAN filter

Source§

impl PoKeysDevice

I2C protocol implementation

Source

pub fn i2c_init(&mut self) -> Result<()>

Initialize I2C bus with default settings

This initializes the I2C bus. Note: I2C bus is always activated on PoKeys devices.

Source

pub fn i2c_configure(&mut self, _speed_khz: u16, _options: u8) -> Result<()>

Configure I2C bus with specific settings

§Arguments
  • speed_khz - I2C bus speed in kHz (typically 100 or 400)
  • options - Additional I2C configuration options
Source

pub fn i2c_write(&mut self, address: u8, data: &[u8]) -> Result<I2cStatus>

Write data to I2C device with enhanced error handling

§Arguments
  • address - 7-bit I2C device address
  • data - Data buffer to write (maximum 32 bytes)
§Returns

I2C operation status

Source

pub fn i2c_read( &mut self, address: u8, length: u8, ) -> Result<(I2cStatus, Vec<u8>)>

Read data from I2C device

§Arguments
  • address - 7-bit I2C device address
  • length - Number of bytes to read (maximum 32 bytes)
§Returns

Tuple of (status, data) where data contains the read bytes

Source

pub fn i2c_write_register( &mut self, address: u8, register: u8, data: &[u8], ) -> Result<I2cStatus>

Write to I2C device register

This is a convenience method for writing to a specific register in an I2C device.

§Arguments
  • address - 7-bit I2C device address
  • register - Register address
  • data - Data to write to the register
Source

pub fn i2c_read_register( &mut self, address: u8, register: u8, length: u8, ) -> Result<(I2cStatus, Vec<u8>)>

Read from I2C device register

This is a convenience method for reading from a specific register in an I2C device.

§Arguments
  • address - 7-bit I2C device address
  • register - Register address
  • length - Number of bytes to read
Source

pub fn i2c_scan(&mut self) -> Result<Vec<u8>>

Scan I2C bus for devices

This method scans the I2C bus for responding devices.

§Returns

Vector of addresses that responded to the scan

Source

pub fn i2c_write_fragmented( &mut self, address: u8, data: &[u8], ) -> Result<I2cStatus>

Write data to I2C device with automatic packet fragmentation

This method automatically fragments large I2C packets into smaller chunks that fit within the 32-byte limit.

§Arguments
  • address - 7-bit I2C device address
  • data - Data buffer to write (any size)
§Returns

I2C operation status

Source

pub fn i2c_write_with_retry( &mut self, address: u8, data: &[u8], config: &RetryConfig, ) -> Result<I2cStatus>

Write data to I2C device with retry logic

§Arguments
  • address - 7-bit I2C device address
  • data - Data buffer to write
  • config - Retry configuration
§Returns

I2C operation status

Source

pub fn i2c_get_status(&mut self) -> Result<I2cStatus>

Check I2C bus status

This method checks the current status of the I2C bus.

Source§

impl PoKeysDevice

1-Wire protocol implementation

Source

pub fn onewire_init(&mut self) -> Result<()>

Initialize 1-Wire bus

Source

pub fn onewire_reset(&mut self) -> Result<bool>

Reset 1-Wire bus

Source

pub fn onewire_write_byte(&mut self, data: u8) -> Result<()>

Write byte to 1-Wire bus

Source

pub fn onewire_read_byte(&mut self) -> Result<u8>

Read byte from 1-Wire bus

Search for 1-Wire devices

Source§

impl PoKeysDevice

SPI protocol implementation

Source

pub fn spi_configure(&mut self, prescaler: u8, frame_format: u8) -> Result<()>

Configure SPI interface

§Arguments
  • prescaler - SPI clock prescaler value (affects SPI clock speed)
  • frame_format - SPI frame format configuration

This matches the C library function: PK_SPIConfigure(device, prescaler, frameFormat)

Source

pub fn spi_write(&mut self, buffer: &[u8], pin_cs: u8) -> Result<()>

Write data to SPI bus

§Arguments
  • buffer - Data buffer to write (maximum 55 bytes)
  • pin_cs - Chip select pin number

This matches the C library function: PK_SPIWrite(device, buffer, length, pinCS)

Source

pub fn spi_read(&mut self, length: u8) -> Result<Vec<u8>>

Read data from SPI bus

§Arguments
  • length - Number of bytes to read (maximum 55 bytes)
§Returns

Vector containing the read data

This matches the C library function: PK_SPIRead(device, buffer, length)

Source

pub fn spi_transfer(&mut self, write_data: &[u8], pin_cs: u8) -> Result<Vec<u8>>

SPI transfer (write and read simultaneously) - convenience method

This is a higher-level method that combines write and read operations for full-duplex SPI communication.

Source§

impl PoKeysDevice

UART protocol implementation

Source

pub fn uart_configure( &mut self, baud_rate: u32, data_bits: u8, stop_bits: u8, parity: u8, ) -> Result<()>

Configure UART interface

Source

pub fn uart_write(&mut self, data: &[u8]) -> Result<()>

Write data to UART

Source

pub fn uart_read(&mut self) -> Result<Vec<u8>>

Read data from UART

Source

pub fn uart_status(&mut self) -> Result<(u8, u8)>

Check UART status

Source§

impl PoKeysDevice

uSPIBridge protocol implementation

Source

pub fn uspibridge_write_command( &mut self, slave_address: u8, command: USPIBridgeCommand, device_id: u8, data: &[u8], ) -> Result<I2cStatus>

Write I2C command with proper uSPIBridge packet structure

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • command - uSPIBridge command type
  • device_id - Target device ID (for device-specific commands)
  • data - Command payload data
§Returns

I2C operation status

Source

pub fn uspibridge_set_segment_mapping( &mut self, slave_address: u8, device_id: u8, mapping: &[u8; 8], ) -> Result<I2cStatus>

Set custom segment mapping for a specific device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • mapping - Array of 8 values mapping standard bits to custom bits
§Returns

I2C operation status

Source

pub fn uspibridge_set_segment_mapping_type( &mut self, slave_address: u8, device_id: u8, mapping_type: SegmentMappingType, ) -> Result<I2cStatus>

Set predefined segment mapping type for a specific device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • mapping_type - Predefined mapping type to use (0-4 supported)
§Returns

I2C operation status

Source

pub fn uspibridge_get_segment_mapping( &mut self, slave_address: u8, device_id: u8, ) -> Result<(I2cStatus, Option<[u8; 8]>)>

Get current segment mapping for a specific device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
§Returns

Tuple of (I2C status, optional segment mapping array)

Source

pub fn uspibridge_test_segment_mapping( &mut self, slave_address: u8, device_id: u8, test_pattern: u8, ) -> Result<I2cStatus>

Test segment mapping with a specific pattern

This command displays a test pattern on the specified device to verify that the segment mapping is working correctly.

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • test_pattern - 8-bit pattern to display for testing
§Returns

I2C operation status

Source

pub fn uspibridge_display_text( &mut self, slave_address: u8, device_id: u8, text: &str, ) -> Result<I2cStatus>

Display text on a specific MAX7219 device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • text - Text to display on the device
§Returns

I2C operation status

Source

pub fn uspibridge_display_number( &mut self, slave_address: u8, device_id: u8, number: u32, ) -> Result<I2cStatus>

Display a number on a specific MAX7219 device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • number - 32-bit number to display
§Returns

I2C operation status

Source

pub fn uspibridge_set_character( &mut self, slave_address: u8, device_id: u8, position: u8, character: u8, ) -> Result<I2cStatus>

Set a character at a specific position on a MAX7219 device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • position - Position on the display (0-7)
  • character - Character to display
§Returns

I2C operation status

Source

pub fn uspibridge_set_pattern( &mut self, slave_address: u8, device_id: u8, position: u8, pattern: u8, ) -> Result<I2cStatus>

Set a raw segment pattern at a specific position on a MAX7219 device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • position - Position on the display (0-7)
  • pattern - 8-bit segment pattern
§Returns

I2C operation status

Source

pub fn uspibridge_set_decimal( &mut self, slave_address: u8, device_id: u8, position: u8, state: bool, ) -> Result<I2cStatus>

Set decimal point at a specific position on a MAX7219 device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • position - Position on the display (0-7)
  • state - Decimal point state (0=off, 1=on)
§Returns

I2C operation status

Source

pub fn uspibridge_set_brightness( &mut self, slave_address: u8, device_id: u8, brightness: u8, ) -> Result<I2cStatus>

Set brightness for a specific MAX7219 device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
  • brightness - Brightness level (0-15)
§Returns

I2C operation status

Source

pub fn uspibridge_clear_device( &mut self, slave_address: u8, device_id: u8, ) -> Result<I2cStatus>

Clear a specific MAX7219 device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • device_id - Target MAX7219 device ID (0-based)
§Returns

I2C operation status

Source

pub fn uspibridge_virtual_text( &mut self, slave_address: u8, virtual_id: u8, text: &str, ) -> Result<I2cStatus>

Set text on a virtual display

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • virtual_id - Virtual display ID (0-based)
  • text - Text to display
§Returns

I2C operation status

Source

pub fn uspibridge_create_virtual_device( &mut self, slave_address: u8, virtual_id: u8, physical_devices: &[u8], ) -> Result<I2cStatus>

Create a new virtual device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • virtual_id - Virtual device ID to create (0-based)
  • physical_devices - Array of physical device IDs to map to this virtual device
§Returns

I2C operation status

Source

pub fn uspibridge_delete_virtual_device( &mut self, slave_address: u8, virtual_id: u8, ) -> Result<I2cStatus>

Delete a virtual device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • virtual_id - Virtual device ID to delete (0-based)
§Returns

I2C operation status

Source

pub fn uspibridge_list_virtual_devices( &mut self, slave_address: u8, ) -> Result<(I2cStatus, Option<Vec<u8>>)>

List all virtual devices

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
§Returns

Tuple of (I2C status, optional virtual device list data)

Source

pub fn uspibridge_virtual_brightness( &mut self, slave_address: u8, virtual_id: u8, brightness: u8, ) -> Result<I2cStatus>

Set brightness for a virtual device

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • virtual_id - Virtual device ID (0-based)
  • brightness - Brightness level (0-15)
§Returns

I2C operation status

Source

pub fn uspibridge_virtual_scroll( &mut self, slave_address: u8, virtual_id: u8, text: &str, speed_ms: u16, direction_left: bool, ) -> Result<I2cStatus>

Start scrolling effect on a virtual display

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • virtual_id - Virtual display ID (0-based)
  • text - Text to scroll
  • speed_ms - Scroll speed in milliseconds
  • direction_left - True for left scroll, false for right scroll
§Returns

I2C operation status

Source

pub fn uspibridge_virtual_flash( &mut self, slave_address: u8, virtual_id: u8, text: &str, interval_ms: u16, ) -> Result<I2cStatus>

Start flashing effect on a virtual display

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • virtual_id - Virtual display ID (0-based)
  • text - Text to flash
  • interval_ms - Flash interval in milliseconds
§Returns

I2C operation status

Source

pub fn uspibridge_virtual_stop( &mut self, slave_address: u8, virtual_id: u8, ) -> Result<I2cStatus>

Stop effects on a virtual display

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • virtual_id - Virtual display ID (0-based)
§Returns

I2C operation status

Source

pub fn uspibridge_virtual_clear( &mut self, slave_address: u8, virtual_id: u8, ) -> Result<I2cStatus>

Clear a virtual display

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
  • virtual_id - Virtual display ID (0-based)
§Returns

I2C operation status

Source

pub fn uspibridge_system_reset( &mut self, slave_address: u8, ) -> Result<I2cStatus>

Reset the uSPIBridge system

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
§Returns

I2C operation status

Source

pub fn uspibridge_system_status( &mut self, slave_address: u8, ) -> Result<(I2cStatus, Option<Vec<u8>>)>

Get uSPIBridge system status

§Arguments
  • slave_address - I2C slave address of the uSPIBridge device
§Returns

Tuple of (I2C status, optional status data)

Source§

impl PoKeysDevice

Source

pub fn enable_pulse_engine(&mut self, enable: bool) -> Result<()>

Enable pulse engine

Source

pub fn activate_pulse_engine(&mut self, activate: bool) -> Result<()>

Activate pulse engine

Source

pub fn setup_pulse_engine_with_axes( &mut self, config: &PulseEngineConfig, axis_enable_mask: u8, ) -> Result<()>

Setup pulse engine (0x85/0x01) Setup pulse engine (0x85/0x01) with axis enable mask

Source

pub fn get_pulse_engine_status(&mut self) -> Result<()>

Source

pub fn set_axis_position(&mut self, axis: usize, position: i32) -> Result<()>

Set axis position (0x85/0x03)

Source

pub fn set_pulse_engine_state( &mut self, state: u8, limit_override: u8, output_enable_mask: u8, ) -> Result<()>

Set pulse engine state (0x85/0x02)

Source

pub fn reboot_pulse_engine(&mut self) -> Result<()>

Reboot pulse engine (0x85/0x05)

Source

pub fn set_axis_configuration(&mut self, axis: usize) -> Result<()>

Set axis configuration (0x85/0x11)

Source

pub fn get_axis_configuration(&mut self, axis: usize) -> Result<()>

Get axis configuration (0x85/0x10)

Source

pub fn get_axis_position(&mut self, axis: usize) -> Result<i32>

Source

pub fn move_axis_to_position( &mut self, axis: usize, position: i32, _speed: f32, ) -> Result<()>

Move axis to position using 0x85/0x20 command in position control mode

Source

pub fn start_axis_homing(&mut self, axis_mask: u8) -> Result<()>

Start axis homing

Source

pub fn configure_axis_homing( &mut self, axis: usize, home_pin: u8, homing_speed: u8, home_offset: i32, ) -> Result<()>

Configure axis homing

Source

pub fn configure_axis_limits( &mut self, axis: usize, limit_n_pin: u8, limit_p_pin: u8, soft_limit_min: i32, soft_limit_max: i32, ) -> Result<()>

Configure axis limits

Source

pub fn emergency_stop(&mut self) -> Result<()>

Emergency stop

Source

pub fn read_pulse_engine_status(&mut self) -> Result<()>

Read pulse engine status

Source

pub fn get_pulse_engine_state(&mut self) -> Result<PulseEngineState>

Get pulse engine state

Source

pub fn get_axis_state(&mut self, axis: usize) -> Result<PulseEngineAxisState>

Get axis state

Source

pub fn is_axis_homed(&mut self, axis: usize) -> Result<bool>

Check if axis is homed

Source

pub fn wait_for_axis(&mut self, axis: usize, timeout_ms: u32) -> Result<()>

Wait for axis to complete movement

Source

pub fn set_motor_drivers_configuration(&mut self) -> Result<()>

Set internal motor drivers configuration (0x85/0x19)

Source

pub fn configure_axis(&mut self, axis: usize) -> AxisConfigBuilder

Create axis configuration builder

Source

pub fn set_axis_positions( &mut self, axis_mask: u8, positions: &[i32; 8], ) -> Result<()>

Set axis positions (0x85/0x03)

Source

pub fn move_pv( &mut self, axis_mask: u8, positions: &[i32; 8], velocity: u16, ) -> Result<()>

Move PV (Set reference position and speed) (0x85/0x25)

Source

pub fn configure_motor_drivers(&mut self) -> MotorDriverConfigBuilder

Create motor driver configuration builder

Source

pub fn get_motor_drivers_configuration(&mut self) -> Result<()>

Get internal motor drivers configuration (0x85/0x18)

Source§

impl PoKeysDevice

Source

pub fn set_pwm_configuration(&mut self) -> Result<()>

Set PWM configuration using command 0xCB

Source

pub fn update_pwm_duty_values(&mut self) -> Result<()>

Update only PWM duty values using command 0xCB

Source

pub fn get_pwm_configuration(&mut self) -> Result<()>

Get PWM configuration using command 0xCB

Source

pub fn set_pwm_period(&mut self, period: u32) -> Result<()>

Set PWM period (shared among all channels)

Source

pub fn get_pwm_period(&self) -> u32

Get PWM period

Source

pub fn set_pwm_duty_cycle_for_pin(&mut self, pin: u8, duty: u32) -> Result<()>

Set PWM duty cycle for a pin (17-22)

Source

pub fn get_pwm_duty_cycle_for_pin(&self, pin: u8) -> Result<u32>

Get PWM duty cycle for a pin (17-22)

Source

pub fn enable_pwm_for_pin(&mut self, pin: u8, enabled: bool) -> Result<()>

Enable or disable PWM for a pin (17-22)

Source

pub fn is_pwm_enabled_for_pin(&self, pin: u8) -> Result<bool>

Check if PWM is enabled for a pin (17-22)

Source

pub fn set_pwm_duty_cycle_percent_for_pin( &mut self, pin: u8, percent: f32, ) -> Result<()>

Set PWM duty cycle as percentage (0.0 to 100.0) for a pin

Source

pub fn get_pwm_duty_cycle_percent_for_pin(&self, pin: u8) -> Result<f32>

Get PWM duty cycle as percentage for a pin

Source§

impl PoKeysDevice

Source

pub fn configure_easy_sensor( &mut self, sensor_index: usize, sensor_type: u8, sensor_id: &[u8; 8], refresh_period_seconds: f32, reading_id: u8, ) -> Result<()>

Configure EasySensor

Source

pub fn enable_easy_sensor( &mut self, sensor_index: usize, enable: bool, ) -> Result<()>

Enable EasySensor

Source

pub fn read_easy_sensor(&mut self, sensor_index: usize) -> Result<i32>

Read EasySensor value

Source

pub fn read_all_easy_sensors(&mut self) -> Result<()>

Read all EasySensor values

Source

pub fn configure_sensor_failsafe( &mut self, sensor_index: usize, timeout_seconds: u8, invalid_value_zero: bool, invalid_value_max: bool, ) -> Result<()>

Configure sensor failsafe settings

Source

pub fn get_sensor_status(&self, sensor_index: usize) -> Result<bool>

Get sensor status

Source

pub fn set_custom_sensor_unit( &mut self, unit_index: usize, unit: &CustomSensorUnit, ) -> Result<()>

Set custom sensor unit

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.