pca9685 - Driver for 16-channel, 12-bit PWM PCA9685

group pca9685

ESP-IDF driver for 16-channel, 12-bit PWM PCA9685.

Ported from esp-open-rtos

Copyright (C) 2016, 2018 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

PCA9685_ADDR_BASE

Base I2C device address.

Enums

enum pca9685_channel_t

PWM channel.

Values:

enumerator PCA9685_CHANNEL_0
enumerator PCA9685_CHANNEL_1
enumerator PCA9685_CHANNEL_2
enumerator PCA9685_CHANNEL_3
enumerator PCA9685_CHANNEL_4
enumerator PCA9685_CHANNEL_5
enumerator PCA9685_CHANNEL_6
enumerator PCA9685_CHANNEL_7
enumerator PCA9685_CHANNEL_8
enumerator PCA9685_CHANNEL_9
enumerator PCA9685_CHANNEL_10
enumerator PCA9685_CHANNEL_11
enumerator PCA9685_CHANNEL_12
enumerator PCA9685_CHANNEL_13
enumerator PCA9685_CHANNEL_14
enumerator PCA9685_CHANNEL_15
enumerator PCA9685_CHANNEL_ALL

All channels.

Functions

esp_err_t pca9685_init_desc(i2c_dev_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptior.

Return

ESP_OK on success

Parameters
  • dev: Pointer to I2C device descriptor

  • addr: PCA9685 address

  • port: I2C port number

  • sda_gpio: GPIO pin number for SDA

  • scl_gpio: GPIO pin number for SCL

esp_err_t pca9685_free_desc(i2c_dev_t *dev)

Free device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Pointer to I2C device descriptor

esp_err_t pca9685_init(i2c_dev_t *dev)

Init device.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t pca9685_set_subaddr(i2c_dev_t *dev, uint8_t num, uint8_t subaddr, bool enable)

Setup device subaddress (see section 7.3.6 if the datasheet)

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • num: Subaddress number, 0..2

  • subaddr: Subaddress, 7 bit

  • enable: True to enable subaddress, false to disable

esp_err_t pca9685_restart(i2c_dev_t *dev)

Restart device (see section 7.3.1.1 of the datasheet)

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t pca9685_is_sleeping(i2c_dev_t *dev, bool *sleeping)

Check if device is in sleep mode.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • sleeping: True if device is sleeping

esp_err_t pca9685_sleep(i2c_dev_t *dev, bool sleep)

Switch device to low-power mode or wake it up.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • sleep: True for sleep mode, false for wake up

esp_err_t pca9685_is_output_inverted(i2c_dev_t *dev, bool *inv)

Get logic inversion of the outputs.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • inv: True if outputs are inverted, false otherwise

esp_err_t pca9685_set_output_inverted(i2c_dev_t *dev, bool inverted)

Logically invert outputs (see section 7.7 of the datasheet)

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • inverted: True for inverted outputs

esp_err_t pca9685_get_output_open_drain(i2c_dev_t *dev, bool *od)

Get outputs mode.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • od: True if outputs are in open drain mode

esp_err_t pca9685_set_output_open_drain(i2c_dev_t *dev, bool od)

Set outputs mode.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • od: True to set open drain mode, false to normal mode

esp_err_t pca9685_get_prescaler(i2c_dev_t *dev, uint8_t *prescaler)

Get PWM frequency prescaler.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • prescaler: Frequency prescaler

esp_err_t pca9685_set_prescaler(i2c_dev_t *dev, uint8_t prescaler)

Set PWM frequency prescaler.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • prescaler: Prescaler value

esp_err_t pca9685_get_pwm_frequency(i2c_dev_t *dev, uint16_t *freq)

Get PWM frequency.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • freq: PWM frequency, Hz

esp_err_t pca9685_set_pwm_frequency(i2c_dev_t *dev, uint16_t freq)

Set PWM frequency.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • freq: PWM frequency, Hz

esp_err_t pca9685_set_pwm_value(i2c_dev_t *dev, uint8_t channel, uint16_t val)

Set PWM value on output channel.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • channel: Channel number, 0..15 or >15 for all channels

  • val: PWM value, 0..4096

esp_err_t pca9685_set_pwm_values(i2c_dev_t *dev, uint8_t first_ch, uint8_t channels, const uint16_t *values)

Set PWM values on multiple output channels.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • first_ch: First channel, 0..15

  • channels: Number of channels to update

  • values: Array of the channel values, each 0..4096