# `EtherCAT.Slave.Sync.CoE`
[🔗](https://github.com/sid2baker/ethercat/blob/main/lib/ethercat/slave/sync/coe.ex#L1)

Helpers for common CoE application sync-mode objects.

This module is driver-facing. It builds mailbox steps for the common
synchronization objects:

- `0x1C32` — SM output parameter
- `0x1C33` — SM input parameter

The public application API still uses `%EtherCAT.Slave.Sync.Config{}` for generic ESC
SYNC/latch intent. Drivers may use these helpers from `c:EtherCAT.Slave.Driver.sync_mode/2`
when a slave application also needs CoE object-dictionary sync-mode writes.

This module does not talk to the mailbox itself. It only builds
`{:sdo_download, ...}` steps for `EtherCAT.Slave.Mailbox.CoE` to execute later.

The generated steps intentionally cover only the common writable fields:

- subindex `0x01` — synchronization mode
- subindex `0x02` — cycle time

They do not attempt to write device-specific read-only or optional timing
fields such as shift/calc-and-copy delays.

## Examples

    def sync_mode(_config, %EtherCAT.Slave.Sync.Config{mode: :sync0} = sync) do
      EtherCAT.Slave.Sync.CoE.steps!(
        cycle_ns: 1_000_000,
        output: :sync0,
        input: :sync0
      )
    end

    def sync_mode(_config, _sync) do
      EtherCAT.Slave.Sync.CoE.steps!(
        cycle_ns: 1_000_000,
        output: :sm_event,
        input: {:sm_event, :sm2}
      )
    end

# `input_mode`

```elixir
@type input_mode() :: :free_run | {:sm_event, :sm2 | :sm3} | :sync0 | :sync1
```

# `mailbox_step`

```elixir
@type mailbox_step() :: EtherCAT.Slave.Driver.mailbox_step()
```

# `output_mode`

```elixir
@type output_mode() :: :free_run | :sm_event | :sync0 | :sync1
```

# `input_steps`

```elixir
@spec input_steps(input_mode() | nil, pos_integer()) :: [mailbox_step()]
```

Build CoE mailbox steps for the input sync object `0x1C33`.

# `output_steps`

```elixir
@spec output_steps(output_mode() | nil, pos_integer()) :: [mailbox_step()]
```

Build CoE mailbox steps for the output sync object `0x1C32`.

# `steps!`

```elixir
@spec steps!(keyword()) :: [mailbox_step()]
```

Build a combined list of CoE mailbox steps for `0x1C32` and/or `0x1C33`.

Options:
  - `:cycle_ns` (required) — cycle time written to subindex `0x02`
  - `:output` — optional output application mode for `0x1C32`
  - `:input` — optional input application mode for `0x1C33`

Returns a flat list of `{:sdo_download, index, subindex, binary}` steps.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
