Loading...
Searching...
No Matches
pca9685.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Gunar Schorcht
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
82
83#ifdef __cplusplus
84extern "C"
85{
86#endif
87
88#include <stdbool.h>
89#include <stdint.h>
90
91#include "periph/gpio.h"
92#include "periph/i2c.h"
93#include "periph/pwm.h"
94
111#define PCA9685_I2C_BASE_ADDR (0x40)
112#define PCA9685_I2C_ALLCALLADDR (0x70)
113#define PCA9685_I2C_SUBADR1 (0x71)
114#define PCA9685_I2C_SUBADR2 (0x72)
115#define PCA9685_I2C_SUBADR3 (0x73)
117
121#define PCA9685_CHANNEL_NUM (16U)
122
126#define PCA9685_RESOLUTION (1 << 12)
127
131#define PCA9685_OSC_FREQ (25000000)
132
136#define PCA9685_EXT_FERQ_MAX (50000000)
137
145
155
170
174typedef struct {
175
177 uint8_t i2c_addr;
178
181 uint32_t freq;
182 uint16_t res;
183
184 bool inv;
185
186 uint32_t ext_freq;
187 gpio_t oe_pin;
191
193
197typedef struct {
198
201
202} pca9685_t;
203
204#if MODULE_SAUL || DOXYGEN
208typedef struct {
209 const char *name;
210 unsigned int dev;
211 uint8_t channel;
212 uint16_t initial;
214#endif
215
230int pca9685_init(pca9685_t *dev, const pca9685_params_t *params);
231
255uint32_t pca9685_pwm_init(pca9685_t *dev, pwm_mode_t mode, uint32_t freq,
256 uint16_t res);
257
273void pca9685_pwm_set(pca9685_t *dev, uint8_t channel, uint16_t value);
274
287
301
307static inline uint8_t pca9685_pwm_channels(pca9685_t *dev)
308{
309 (void)dev;
310 return PCA9685_CHANNEL_NUM;
311}
312
313#ifdef __cplusplus
314}
315#endif
316
pwm_mode_t
Low-level GPIO peripheral driver interface definitions.
pca9685_out_ne_t
PCA9685 output-not-enabled mode.
Definition pca9685.h:162
void pca9685_pwm_poweroff(pca9685_t *dev)
Stop the PWM generation on the given PCA9685 device.
pca9685_out_drv_t
PCA9685 output driver mode.
Definition pca9685.h:151
#define PCA9685_CHANNEL_NUM
Number of PWM channels provided by PCA9685.
Definition pca9685.h:121
void pca9685_pwm_poweron(pca9685_t *dev)
Resume PWM generation on the given PCA9685 device.
void pca9685_pwm_set(pca9685_t *dev, uint8_t channel, uint16_t value)
Set the duty-cycle for a given channel or all channels of the given PCA9685 PWM device.
pca9685_error_t
PCA9685 driver error codes.
Definition pca9685.h:141
uint32_t pca9685_pwm_init(pca9685_t *dev, pwm_mode_t mode, uint32_t freq, uint16_t res)
Initialize the PCA9685 PWM device.
static uint8_t pca9685_pwm_channels(pca9685_t *dev)
Get the number of available channels of the given PCA9685 device.
Definition pca9685.h:307
int pca9685_init(pca9685_t *dev, const pca9685_params_t *params)
Initialize the PCA9685 PWM device driver.
@ PCA9685_OUT_DRV
Outputs depend on the output driver mode pca9685_params_t::out_drv.
Definition pca9685.h:164
@ PCA9685_HIHGH_Z
If /OE pin is HIGH, outputs are high-impedance.
Definition pca9685.h:168
@ PCA9685_OFF
If /OE pin is HIGH, outputs are LOW.
Definition pca9685.h:163
@ PCA9685_TOTEM_POLE
Totem pole structure output.
Definition pca9685.h:153
@ PCA9685_OPEN_DRAIN
Open-drain structure output.
Definition pca9685.h:152
@ PCA9685_ERROR_I2C
I2C communication error.
Definition pca9685.h:143
@ PCA9685_OK
Success.
Definition pca9685.h:142
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
Low-level I2C peripheral driver interface definition.
Low-level PWM peripheral driver interface definitions.
PCA9685 device initialization parameters.
Definition pca9685.h:174
uint8_t i2c_addr
I2C slave address.
Definition pca9685.h:177
uint32_t ext_freq
If not 0, EXTCLK pin is used with this frequency.
Definition pca9685.h:186
i2c_t i2c_dev
I2C device, default I2C_DEV(0)
Definition pca9685.h:176
uint16_t res
PWM resolution (default 4096)
Definition pca9685.h:182
bool inv
Invert outputs, e.g., for LEDs (default yes)
Definition pca9685.h:184
gpio_t oe_pin
Active LOW output enable pin /OE.
Definition pca9685.h:187
uint32_t freq
PWM frequency in Hz (default 100)
Definition pca9685.h:181
pca9685_out_ne_t out_ne
Output-not-enabled mode.
Definition pca9685.h:190
pca9685_out_drv_t out_drv
Output driver mode.
Definition pca9685.h:189
pwm_mode_t mode
PWM mode for all channels: PWM_LEFT, PWM_CENTER, PWM_RIGHT supported, (default PWM_CENTER)
Definition pca9685.h:179
PCA9685 configuration structure for mapping PWM channels to SAUL.
Definition pca9685.h:208
const char * name
name of the PCA9685 device
Definition pca9685.h:209
uint16_t initial
initial duty-cycle value
Definition pca9685.h:212
uint8_t channel
channel of the PCA9685 device
Definition pca9685.h:211
unsigned int dev
index of the PCA9685 device
Definition pca9685.h:210
PCA9685 PWM device data structure type.
Definition pca9685.h:197
bool powered_on
Devices is powered on if true.
Definition pca9685.h:200
pca9685_params_t params
Device initialization parameters.
Definition pca9685.h:199