Skip to content
Snippets Groups Projects

Reworked pca9956 driver

Merged Jonathan Klimt requested to merge pca9956 into master
2 files
+ 146
133
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,43 +5,73 @@
#ifndef _PCA9956_H_
#define _PCA9956_H_
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "esp_err.h"
// Datasheet https://www.nxp.com/docs/en/data-sheet/PCA9956B.pdf
// I2C Addresses
//#define PCA9956_ADDRESS_02 (0x40) // 1000000 (A1+A0=GND)
//#define PCA9956_ADDRESS_04 (0x41) // 1000001 (A1=GND, A0=VDD)
//#define PCA9956_ADDRESS_06 (0x42) // 1000010 (A1=GND, A0=SDA)
//#define PCA9956_ADDRESS_08 (0x43) // 1000011 (A1=GND, A0=SCL)
//#define PCA9956_ADDRESS_0A (0x44) // 1000100 (A1=VDD, A0=GND)
//#define PCA9956_ADDRESS_0C (0x45) // 1000101 (A1+A0=VDD)
//#define PCA9956_ADDRESS_0E (0x46) // 1000110 (A1=VDD, A0=SDA)
//#define PCA9956_ADDRESS_10 (0x47) // 1000111 (A1=VDD, A0=SCL)
//#define PCA9956_ADDRESS_12 (0x48) // 1001000 (A1=SDA, A0=GND)
//#define PCA9956_ADDRESS_49 (0x49) // 1001001 (A1=SDA, A0=VDD)
//#define PCA9956_ADDRESS_4A (0x4A) // 1001010 (A1+A0=SDA)
//#define PCA9956_ADDRESS_4B (0x4B) // 1001011 (A1=SDA, A0=SCL)
//#define PCA9956_ADDRESS_4C (0x4C) // 1001100 (A1=SCL, A0=GND)
//#define PCA9956_ADDRESS_4D (0x4D) // 1001101 (A1=SCL, A0=VDD)
//#define PCA9956_ADDRESS_4E (0x4E) // 1001110 (A1=SCL, A0=SDA)
//#define PCA9956_ADDRESS_4F (0x4F) // 1001111 (A1+A0=SCL)
//.... Bis FAh (Siehe S.10 Datasheet) , das schreib ich jetzt mal nicht aus
#define I2C_MASTER_TX_BUF_DISABLE 0 // I2C master do not need buffer
#define I2C_MASTER_RX_BUF_DISABLE 0 // I2C master do not need buffer
#define I2C_MASTER_FREQ_HZ 400000 // I2C master clock frequency
#ifdef __cplusplus
extern "C" {
#endif
void pca_9956_single_switch(uint8_t ch, uint8_t duty);
void pca_9956_single_fade(
uint8_t ch, uint8_t duty, int fade_time_ms); // Not implemented yet
void pca_9956_single_current(uint8_t ch, float r_ext, float i_max_mA);
/**
* @brief PCA9956 device handle. Should be created with pca9956_init
*
* @param[in] pca device handle
* @param[in] ch LED Channel
* @param[in] duty LED Duty Cycle
*/
typedef struct pca9956_t {
uint8_t address;
i2c_port_t i2c_num;
float r_ext;
float i_max_mA;
gpio_num_t oe_pin;
} pca9956_t;
/**
* @brief Set PCA9956 Single LED PWM Value
*
* @param[in] pca device handle
* @param[in] ch LED Channel
* @param[in] duty LED Duty Cycle
*/
void pca9956_single_switch(pca9956_t* pca, uint8_t ch, uint8_t duty);
/**
* @brief Configure the maximum current for a single channel.
*
* @param[in] pca device handle
* @param[in] ch the channel to configure
* @param[in] i_max_mA the maximum current in mA
*/
void pca9956_set_max_current(pca9956_t* pca, uint8_t ch, float i_max_mA);
/**
* @brief Checks the PCA9956's error status and prints the error registers in
* case of an error
*
* @param[in] pca device handle
*
* @return
* - ESP_OK Success
* - ESP_FAIL Device reports error
*/
esp_err_t pca9956_error_check(pca9956_t* pca);
esp_err_t pca9956_init(i2c_port_t v_i2c_num, uint8_t addr, float r_ext);
/**
* @brief Init PCA9956 power monitor
*
* @param[in] v_i2c_num I2C port
* @param[in] addr I2C device address
* @param[in] r_ext the external current limiting resistor
* @param[in] oe_pin the gpio pin connected to the PCA9956 output-enable.
*
* @return handle struct for the configured PCA9956
*/
pca9956_t pca9956_init(
i2c_port_t v_i2c_num, uint8_t addr, float r_ext, gpio_num_t oe_pin);
#ifdef __cplusplus
}
Loading