Skip to content

Commit

Permalink
Merge pull request #188 from tdb3/dedup_i2c_params
Browse files Browse the repository at this point in the history
refactor: deduplicate i2c parameters
  • Loading branch information
Georges760 authored Jun 5, 2024
2 parents f2fda4e + 28d61cd commit abe6d28
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 29 deletions.
10 changes: 2 additions & 8 deletions main/DS4432U.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,4 +136,4 @@ bool DS4432U_set_vcore(float core_voltage)
DS4432U_set(reg_setting); /// eek!

return true;
}
}
4 changes: 3 additions & 1 deletion main/DS4432U.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
9 changes: 0 additions & 9 deletions main/EMC2101.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down
4 changes: 3 additions & 1 deletion main/EMC2101.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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_ */
10 changes: 1 addition & 9 deletions main/INA260.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion main/INA260.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 changes: 12 additions & 0 deletions main/i2c_params.h
Original file line number Diff line number Diff line change
@@ -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_ */

0 comments on commit abe6d28

Please sign in to comment.