refactor: deduplicate i2c parameters

Pulls common i2c macros (e.g. GPIO pins, speed, etc.)
into a common header, to deduplicate and increase
maintainability.
Also adds missing include for DS4432U.h in DS4432U.c.
This commit is contained in:
tdb3 2024-05-27 11:43:29 -04:00
parent 00d5a7386f
commit 28d61cd027
No known key found for this signature in database
7 changed files with 24 additions and 29 deletions

View File

@ -3,13 +3,7 @@
#include "esp_log.h"
#include "driver/i2c.h"
#define I2C_MASTER_SCL_IO 48 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 47 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000
#include "DS4432U.h"
// DS4432U+ -- Adjustable current DAC for use with the TPS40305 voltage regulator
// address: 0x90
@ -142,4 +136,4 @@ bool DS4432U_set_vcore(float core_voltage)
DS4432U_set(reg_setting); /// eek!
return true;
}
}

View File

@ -3,10 +3,12 @@
#include "driver/i2c.h"
#include "i2c_params.h"
esp_err_t i2c_master_init(void);
esp_err_t i2c_master_delete(void);
void DS4432U_read(void);
bool DS4432U_test(void);
bool DS4432U_set_vcore(float);
#endif /* DS4432U_H_ */
#endif /* DS4432U_H_ */

View File

@ -4,15 +4,6 @@
#include "EMC2101.h"
#define I2C_MASTER_SCL_IO 48 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 47 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_NUM \
0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000
// static const char *TAG = "EMC2101.c";
/**

View File

@ -1,6 +1,8 @@
#ifndef EMC2101_H_
#define EMC2101_H_
#include "i2c_params.h"
#define EMC2101_I2CADDR_DEFAULT 0x4C ///< EMC2101 default i2c address
#define EMC2101_CHIP_ID 0x16 ///< EMC2101 default device id from part id
#define EMC2101_ALT_CHIP_ID 0x28 ///< EMC2101 alternate device id from part id
@ -87,4 +89,4 @@ uint16_t EMC2101_get_fan_speed(void);
void EMC2101_init(bool);
float EMC2101_get_external_temp(void);
uint8_t EMC2101_get_internal_temp(void);
#endif /* EMC2101_H_ */
#endif /* EMC2101_H_ */

View File

@ -4,14 +4,6 @@
#include "INA260.h"
#define I2C_MASTER_SCL_IO 48 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 47 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000
// static const char *TAG = "INA260.c";
/**
@ -67,4 +59,4 @@ float INA260_read_power(void)
// ESP_LOGI(TAG, "Raw Power = %02X %02X", data[1], data[0]);
return (data[1] | (data[0] << 8)) * 10;
}
}

View File

@ -1,6 +1,8 @@
#ifndef INA260_H_
#define INA260_H_
#include "i2c_params.h"
#define INA260_I2CADDR_DEFAULT 0x40 ///< INA260 default i2c address
#define INA260_REG_CONFIG 0x00 ///< Configuration register
#define INA260_REG_CURRENT 0x01 ///< Current measurement register (signed) in mA
@ -107,4 +109,4 @@ float INA260_read_current(void);
float INA260_read_voltage(void);
float INA260_read_power(void);
#endif /* INA260_H_ */
#endif /* INA260_H_ */

12
main/i2c_params.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef I2C_PARAMS_H_
#define I2C_PARAMS_H_
#define I2C_MASTER_SCL_IO 48 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 47 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000
#endif /* I2C_PARAMS_H_ */