Kleidos API Search

In development. It changes without notice.

Topic

Trackball Driver

The trackball: four direction lines and a click.

QuadratureTrackball counts each falling edge of a direction as a step and keeps when the last one came. A trackball has no bus and no identity to probe, so the board's configuration says whether there is one; NullTrackball stands in where there is none.

See also
Input Sources & the Wake Rule

Files

file src/drivers/trackball/i_trackball.h
Device-level quadrature-trackball driver contract.
file src/drivers/trackball/null_trackball.h
No-op trackball driver for the boards without a trackball.
file src/drivers/trackball/quadrature_trackball.h
Generic four-direction + click GPIO quadrature trackball driver.
file src/drivers/trackball/trackball_factory.h
Factory for the quadrature-trackball driver.
file src/drivers/trackball/trackball_selftest.h
Pure decision helpers for the kleidos::drivers::trackball::ITrackball self-test.

Classes

struct kleidos::drivers::trackball::QuadratureSteps
One atomic snapshot of the quadrature accumulators + velocity timing. More about kleidos::drivers::trackball::QuadratureSteps
class kleidos::drivers::trackball::ITrackball
Device-level quadrature-trackball driver interface. More about kleidos::drivers::trackball::ITrackball
class kleidos::drivers::trackball::NullTrackball
No-op trackball driver used on the boards that have no trackball. More about kleidos::drivers::trackball::NullTrackball
struct kleidos::drivers::trackball::QuadratureTrackballPins
GPIO pin mapping for a four-direction + click quadrature trackball. More about kleidos::drivers::trackball::QuadratureTrackballPins
class kleidos::drivers::trackball::QuadratureTrackball
Generic GPIO quadrature trackball driver (four directions + center click). More about kleidos::drivers::trackball::QuadratureTrackball

Enumerations

enum class kleidos::drivers::trackball::TrackballFamily : uint8_t { kleidos::drivers::trackball::TrackballFamily::None , kleidos::drivers::trackball::TrackballFamily::Quadrature }
Trackball family selected by the board's compile-time flag + pin mapping. More about kleidos::drivers::trackball::TrackballFamily

Functions

constexpr boolkleidos::drivers::trackball::quadratureDirectionsValid (const QuadratureTrackballPins &pins)
Whether the four direction pins are all assigned.
constexpr TrackballFamilykleidos::drivers::trackball::classifyTrackball (bool quadraturePinsValid)
Classify a trackball from its pin-mapping sanity check (pure).
ITrackball *kleidos::drivers::trackball::createTrackball (const QuadratureTrackballPins &pins)
Resolve and return the fitted trackball driver.
constexpr boolkleidos::drivers::trackball::selfTestCountersCleared (int32_t up, int32_t down, int32_t left, int32_t right)
Whether the drained step counters read back all-zero after a reset.
constexpr boolkleidos::drivers::trackball::selfTestClickIdleHigh (bool clickLevel)
Whether the click line reads its expected idle level (pull-up → HIGH).
constexpr boolkleidos::drivers::trackball::selfTestPassed (bool ready, bool countersCleared)
Overall pass decision for the passive-device self-test.

Enumeration Type Documentation

TrackballFamily #

enum class kleidos::drivers::trackball::TrackballFamily : uint8_t

Trackball family selected by the board's compile-time flag + pin mapping.

Enumerator
None 

No supported trackball, or pins unassigned.

Quadrature 

Four-direction + click GPIO quadrature trackball.

Function Documentation

classifyTrackball() #

TrackballFamily kleidos::drivers::trackball::classifyTrackball(bool quadraturePinsValid)
constexpr

Classify a trackball from its pin-mapping sanity check (pure).

A passive GPIO device cannot be probed, so the only decision a factory can make before hardware is whether the family's pins are wired. The caller runs the check only for the family compiled into the build and passes its result, so an un-compiled family can never match.

Parameters
NameDirectionMeaning
quadraturePinsValidinWhether the quadrature direction pins are assigned.
Returns
TrackballFamily::Quadrature when valid, else TrackballFamily::None.

createTrackball() #

ITrackball * kleidos::drivers::trackball::createTrackball(const QuadratureTrackballPins & pins)

Resolve and return the fitted trackball driver.

For the trackball family compiled into this build, checks the direction-pin mapping and returns the matching driver (constructed but not yet initialized — the caller runs ITrackball::init). On no family, or unassigned pins, returns the shared kleidos::drivers::trackball::NullTrackball.

Parameters
NameDirectionMeaning
pinsinDirection + click GPIO mapping for this board.
Returns
A driver owned by function-local static storage (never delete, never nullptr).

quadratureDirectionsValid() #

bool kleidos::drivers::trackball::quadratureDirectionsValid(const QuadratureTrackballPins & pins)
constexpr

Whether the four direction pins are all assigned.

A quadrature trackball needs its four motion pins; the click pin is optional. This is the passive-device analogue of an address ACK — the only pre-hardware "detection" a factory can make for a device with no bus.

Parameters
NameDirectionMeaning
pinsinCandidate pin mapping.
Return values
ValueMeaning
trueAll four direction pins are valid GPIO numbers (>= 0).
falseAt least one direction pin is unassigned.

selfTestClickIdleHigh() #

bool kleidos::drivers::trackball::selfTestClickIdleHigh(bool clickLevel)
constexpr

Whether the click line reads its expected idle level (pull-up → HIGH).

Informational only: the center button is active LOW under an internal pull-up, so at rest the line idles HIGH. A physically held button legitimately reads LOW, so the self-test never fails on this — it only annotates the level in the detail string.

Parameters
NameDirectionMeaning
clickLevelinRaw click-pin level (true = HIGH).
Return values
ValueMeaning
trueThe line idles HIGH as expected at rest.
falseThe line reads LOW (button held, or a wiring fault).

selfTestCountersCleared() #

bool kleidos::drivers::trackball::selfTestCountersCleared(int32_t up, int32_t down, int32_t left, int32_t right)
constexpr

Whether the drained step counters read back all-zero after a reset.

A drain must read and clear the four direction accumulators; an immediate re-drain returning all zeros proves the read-and-reset path is coherent (no counter is stuck or aliased). Any non-zero value signals a broken accumulator or a reset that did not take.

Parameters
NameDirectionMeaning
upinUP counter from the confirming re-drain.
downinDOWN counter from the confirming re-drain.
leftinLEFT counter from the confirming re-drain.
rightinRIGHT counter from the confirming re-drain.
Return values
ValueMeaning
trueAll four counters are zero (accumulators drained coherently).
falseAt least one counter did not reset.

selfTestPassed() #

bool kleidos::drivers::trackball::selfTestPassed(bool ready, bool countersCleared)
constexpr

Overall pass decision for the passive-device self-test.

The verifiable pass gate is: the driver initialized (pins configured as inputs, edge ISRs armed) AND the step accumulators drained coherently. The click idle level is deliberately excluded from the gate (see selfTestClickIdleHigh).

Parameters
NameDirectionMeaning
readyinWhether init() configured the pins and armed the ISRs.
countersClearedinWhether the confirming re-drain read all-zero.
Return values
ValueMeaning
trueBoth verifiable preconditions hold.
falseThe driver did not initialize, or a counter did not reset.