klipper_config_generate!() { /* proc-macro */ }
Expand description

Generate compile-time configuration

This macro generates the protocol dictionary, message handlers, encoders, and dispatcher needed. The actual code is generated by the anchor_codegen build script, and the macro ensures that the generated code is included correctly.

This must be called exactly once at the root of your crate, typically in main.rs.

The syntax is as follows:

klipper_config_generate!(options);

The following options are supported:

  • transport = path: type
    This is the TransportOutput that will be used when sending messages to the remote end. The user crate must provide this, and it must be a global const. Any klipper_reply! calls will call the output method. Both a path and type must be provided, both must be fully expanded. E.g.:
    transport = crate::usb::TRANSPORT_OUTPUT: crate::usb::BufferTransportOutput

  • context = type
    An optional context can be passed to all klipper_command functions. The lifetime 'ctx is available, and allows the context to capture the lifetime when the generated dispatcher is called, and pass this along to the handler functions. If no context type is given, the default is the empty tuple ().

An example invocation could be:

klipper_config_generate!(
    transport = crate::usb::TRANSPORT_OUTPUT: crate::usb::BufferTransportOutput,
    context = &'ctx mut crate::State,
);

This generates a module called _anchor_config, and exports a KLIPPER_TRANSPORT symbol from it.