PCA9685.Chip (pca9685 v1.1.0)
Wafer connection for PCA9685 16-channel, 12-bit PWM driver.
This module implements the Wafer.Conn behaviour and provides low-level
access to the PCA9685 device over I2C.
Summary
Functions
Read all channels' PWM duty cycles.
Read a specific channel's PWM duty cycle.
Initialise the PCA9685 device and set all outputs to off.
Read the contents of the mode1 register.
Read the contents of the mode2 register.
Read the contents of the prescale register.
Set all channels to the same PWM duty cycle.
Set a specific channel's PWM duty cycle.
Set the PWM frequency in Hz.
Swap the contents of the mode1 register.
Swap the contents of the mode2 register.
Swap the contents of the prescale register.
Update the contents of the mode1 register using a
transformation function.
Update the contents of the mode2 register using a
transformation function.
Update the contents of the prescale register using a
transformation function.
Write new contents to the mode1 register.
Write new contents to the mode2 register.
Write new contents to the prescale register.
Types
@type t() :: %PCA9685.Chip{conn: Wafer.Driver.Circuits.I2C.t()}
Functions
Read all channels' PWM duty cycles.
@spec get_channel_pwm(t(), channel :: 0..15) :: {:ok, {on :: 0..4095, off :: 0..4095}} | {:error, term()}
Read a specific channel's PWM duty cycle.
@spec initialize(t(), frequency :: pos_integer(), oscillator_freq :: pos_integer()) :: {:ok, t()} | {:error, term()}
Initialise the PCA9685 device and set all outputs to off.
@spec read_mode1(Wafer.Conn.t()) :: {:ok, binary()} | {:error, reason :: any()}
Read the contents of the mode1 register.
Example
iex> read_mode1(conn)
{:ok, <<0>>}
@spec read_mode2(Wafer.Conn.t()) :: {:ok, binary()} | {:error, reason :: any()}
Read the contents of the mode2 register.
Example
iex> read_mode2(conn)
{:ok, <<0>>}
@spec read_prescale(Wafer.Conn.t()) :: {:ok, binary()} | {:error, reason :: any()}
Read the contents of the prescale register.
Example
iex> read_prescale(conn)
{:ok, <<0>>}
Set all channels to the same PWM duty cycle.
@spec set_channel_pwm(t(), channel :: 0..15, on :: 0..4095, off :: 0..4095) :: {:ok, t()} | {:error, term()}
Set a specific channel's PWM duty cycle.
@spec set_pwm_frequency(t(), pos_integer(), oscillator_freq :: pos_integer()) :: {:ok, t()} | {:error, term()}
Set the PWM frequency in Hz.
@spec swap_mode1(Wafer.Conn.t(), data :: binary()) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Swap the contents of the mode1 register.
Reads the contents of the register, then replaces it, returning the previous contents. Some drivers may implement this atomically.
Example
iex> swap_mode1(conn, <<0>>)
{:ok, <<0>>, _conn}
@spec swap_mode2(Wafer.Conn.t(), data :: binary()) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Swap the contents of the mode2 register.
Reads the contents of the register, then replaces it, returning the previous contents. Some drivers may implement this atomically.
Example
iex> swap_mode2(conn, <<0>>)
{:ok, <<0>>, _conn}
@spec swap_prescale(Wafer.Conn.t(), data :: binary()) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Swap the contents of the prescale register.
Reads the contents of the register, then replaces it, returning the previous contents. Some drivers may implement this atomically.
Example
iex> swap_prescale(conn, <<0>>)
{:ok, <<0>>, _conn}
@spec update_mode1(Wafer.Conn.t(), (<<_::_*8>> -> <<_::_*8>>)) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Update the contents of the mode1 register using a
transformation function.
Example
iex> transform = fn <<data::size(8)>> -> <<(data * 2)::size(8)>> end
...> update_mode1(conn, transform)
{:ok, _conn}
@spec update_mode2(Wafer.Conn.t(), (<<_::_*8>> -> <<_::_*8>>)) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Update the contents of the mode2 register using a
transformation function.
Example
iex> transform = fn <<data::size(8)>> -> <<(data * 2)::size(8)>> end
...> update_mode2(conn, transform)
{:ok, _conn}
@spec update_prescale(Wafer.Conn.t(), (<<_::_*8>> -> <<_::_*8>>)) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Update the contents of the prescale register using a
transformation function.
Example
iex> transform = fn <<data::size(8)>> -> <<(data * 2)::size(8)>> end
...> update_prescale(conn, transform)
{:ok, _conn}
@spec write_mode1(Wafer.Conn.t(), data :: binary()) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Write new contents to the mode1 register.
Example
iex> write_mode1(conn, <<0>>)
{:ok, _conn}
@spec write_mode2(Wafer.Conn.t(), data :: binary()) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Write new contents to the mode2 register.
Example
iex> write_mode2(conn, <<0>>)
{:ok, _conn}
@spec write_prescale(Wafer.Conn.t(), data :: binary()) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Write new contents to the prescale register.
Example
iex> write_prescale(conn, <<0>>)
{:ok, _conn}