Feetech STS Driver
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
sts_servo.h File Reference

: STS Service Layer and Hardware Abstraction Definitions More...

#include "sts_protocol.h"
#include <stdint.h>
#include <stddef.h>
#include "sts_registers.h"

Go to the source code of this file.

Classes

struct  sts_bus_s
 STS Shared Bus Handle. More...
 
struct  sts_servo_t
 STS Servo Handle Represents a single physical servo on the bus. More...
 

Macros

#define STS_ONLINE   1
 
#define STS_OFFLINE   0
 
#define STS_MAX_TX_BUFFER   128U
 
#define STS_MAX_RX_BUFFER   128U
 
#define STS_DEFAULT_TIMEOUT_MS   10U
 

Typedefs

typedef struct sts_bus_s sts_bus_t
 
typedef struct sts_servo_t sts_servo_t
 STS Servo Handle Represents a single physical servo on the bus.
 
typedef sts_result_t(* sts_hal_transmit_t) (sts_bus_t *bus, const uint8_t *data, uint16_t len)
 Context-Aware HAL Function Pointers. The bus itself is passed in, allowing the HAL to access the port_handle.
 
typedef sts_result_t(* sts_hal_receive_t) (sts_bus_t *bus, uint8_t *data, uint16_t len, uint32_t timeout_ms)
 
typedef sts_result_t(* sts_hal_flush_rx_t) (sts_bus_t *bus)
 

Functions

sts_result_t STS_Bus_Init (sts_bus_t *bus, void *port_handle, sts_hal_transmit_t tx_func, sts_hal_receive_t rx_func)
 Initializes the hardware bus abstraction.
 
sts_result_t STS_Servo_Init (sts_servo_t *servo, sts_bus_t *bus, uint8_t id)
 Initializes a servo handle.
 
sts_result_t STS_Bus_Transmit (sts_bus_t *bus, const uint8_t *data, uint16_t len)
 Safe wrapper for HAL transmission.
 
sts_result_t STS_Bus_Receive (sts_bus_t *bus, uint8_t *data, uint16_t len, uint32_t timeout)
 Safe wrapper for HAL reception.
 
sts_result_t STS_Bus_FlushRx (sts_bus_t *bus)
 Drains stale bytes from the RX buffer between transaction retries. No-op if the port did not register a flush_rx function.
 
sts_result_t STS_servo_ping (sts_servo_t *servo)
 Pings the servo to check if it's online.
 
sts_result_t STS_Write8 (sts_servo_t *servo, uint8_t reg_addr, uint8_t value)
 Writes a single byte (8-bit) to a specific servo register.
 
sts_result_t STS_Write16 (sts_servo_t *servo, uint8_t reg_addr, uint16_t value)
 Writes a word (16-bit) to a specific servo register (Little-Endian).
 
sts_result_t STS_Read8 (sts_servo_t *servo, uint8_t reg_addr, uint8_t *value_out)
 Reads a single byte (8-bit) from a specific servo register.
 
sts_result_t STS_Read16 (sts_servo_t *servo, uint8_t reg_addr, uint16_t *value_out)
 Reads a word (16-bit) from a specific servo register (Little-Endian).
 

Detailed Description

: STS Service Layer and Hardware Abstraction Definitions

Author
: Grisham Balloo
Date
: 2026-03-20

Defines the Hardware Abstraction Layer and public API for the Feetech STS protocol service layer. Uses an injected-dependency model (function pointers) to remain agnostic of the underlying MCU or UART implementation.

Exposes the bus handle, servo handle, HAL typedefs, register access primitives, and the ping service. The internal sts_cmd_t struct is conditionally visible for white-box unit testing via STATIC_TESTABLE.

Attention
Copyright (c) 2026 Grisham Balloo. All rights reserved.

Function Documentation

◆ STS_Bus_FlushRx()

sts_result_t STS_Bus_FlushRx ( sts_bus_t bus)

Drains stale bytes from the RX buffer between transaction retries. No-op if the port did not register a flush_rx function.

Returns
STS_OK always (flush failures are non-fatal).

◆ STS_Bus_Receive()

sts_result_t STS_Bus_Receive ( sts_bus_t bus,
uint8_t *  data,
uint16_t  len,
uint32_t  timeout 
)

Safe wrapper for HAL reception.

Returns
STS_ERR_NULL_PTR if function pointer is missing, else HAL result.

◆ STS_Bus_Transmit()

sts_result_t STS_Bus_Transmit ( sts_bus_t bus,
const uint8_t *  data,
uint16_t  len 
)

Safe wrapper for HAL transmission.

Returns
STS_ERR_NULL_PTR if function pointer is missing, else HAL result.

◆ STS_Servo_Init()

sts_result_t STS_Servo_Init ( sts_servo_t servo,
sts_bus_t bus,
uint8_t  id 
)

Initializes a servo handle.

Parameters
servoPointer to the servo handle to initialize.
busPointer to an initialized bus handle.
idThe hardware ID of the servo (must be < 254).
Returns
STS_OK on success, STS_ERR_NULL_PTR if servo/bus are NULL, STS_ERR_INVALID_PARAM if ID is 254 or 255.

◆ STS_servo_ping()

sts_result_t STS_servo_ping ( sts_servo_t servo)

Pings the servo to check if it's online.

Parameters
servoPointer to the initialized servo handle.
Returns
STS_OK if the servo responds correctly, error code otherwise. On success, the servo's is_online field is set to STS_ONLINE; on failure, it is set to STS_OFFLINE.