-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TCH - 2.1.9 All-In-One PR #276
Open
aaron3481
wants to merge
12
commits into
skot:master
Choose a base branch
from
TinyChipHub:All-in-one-2.1.9-TCH
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4e0c175
Start adding TPS config based on models
aaron3481 6b13935
Finish all in one merge across Supra, Ultra, Hex
aaron3481 58c13b0
Fix EMC2302 set fan speed.
aaron3481 1276ea0
Read auto fan control within the while loop to enable manual control …
aaron3481 01efeda
UI fix for Ultra, Supra and Hex
aaron3481 a0c38b4
remove extra characters
aaron3481 9d2c670
manually setting the Version
aaron3481 3e340a0
improved hashrate
shufps d3513e8
removed old variable
shufps c25806b
fixed comment
shufps 80e72cc
Merge pull request #293 from shufps/hashrate
WantClue cd42727
Merge branch 'master' into All-in-one-2.1.9-TCH
aaron3481 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ SRCS | |
"adc.c" | ||
"DS4432U.c" | ||
"EMC2101.c" | ||
"EMC2302.c" | ||
"fonts.c" | ||
"i2c_master.c" | ||
"INA260.c" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "driver/i2c.h" | ||
#include "esp_log.h" | ||
#include <stdio.h> | ||
|
||
#include "EMC2302.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 = "EMC2302.c"; | ||
|
||
/** | ||
* @brief Read a sequence of I2C bytes | ||
*/ | ||
static esp_err_t register_read(uint8_t reg_addr, uint8_t * data, size_t len) | ||
{ | ||
return i2c_master_write_read_device(I2C_MASTER_NUM, EMC2302_I2CADDR_DEFAULT, ®_addr, 1, data, len, | ||
I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS); | ||
} | ||
|
||
/** | ||
* @brief Write a byte to a I2C register | ||
*/ | ||
static esp_err_t register_write_byte(uint8_t reg_addr, uint8_t data) | ||
{ | ||
int ret; | ||
uint8_t write_buf[2] = {reg_addr, data}; | ||
|
||
ret = i2c_master_write_to_device(I2C_MASTER_NUM, EMC2302_I2CADDR_DEFAULT, write_buf, sizeof(write_buf), | ||
I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS); | ||
|
||
return ret; | ||
} | ||
|
||
// run this first. sets up the PWM polarity register | ||
void EMC2302_init(bool invertPolarity) | ||
{ | ||
if (invertPolarity) { | ||
ESP_ERROR_CHECK(register_write_byte(EMC2302_PWM_POLARITY, 0b00011111)); | ||
} | ||
} | ||
|
||
// Sets the fan speed to a given percent | ||
void EMC2302_set_fan_speed(uint8_t devicenum, float percent) | ||
{ | ||
uint8_t speed; | ||
uint8_t FAN_SETTING_REG = EMC2302_FAN1_SETTING + (devicenum * 0x10); | ||
|
||
speed = (uint8_t) (255.0 * (1.0f-percent)); | ||
ESP_ERROR_CHECK(register_write_byte(FAN_SETTING_REG, speed)); | ||
} | ||
|
||
// Gets the fan speed | ||
uint16_t EMC2302_get_fan_speed(uint8_t devicenum) | ||
{ | ||
uint8_t tach_lsb, tach_msb; | ||
uint16_t RPM; | ||
uint8_t TACH_LSB_REG = EMC2302_TACH1_LSB + (devicenum * 0x10); | ||
uint8_t TACH_MSB_REG = EMC2302_TACH1_MSB + (devicenum * 0x10); | ||
|
||
ESP_ERROR_CHECK(register_read(TACH_LSB_REG, &tach_lsb, 1)); | ||
ESP_ERROR_CHECK(register_read(TACH_MSB_REG, &tach_msb, 1)); | ||
|
||
//ESP_LOGI(TAG, "Raw Fan Speed[%d] = %02X %02X", devicenum, tach_msb, tach_lsb); | ||
RPM = (tach_msb << 5) + ((tach_lsb >> 3) & 0x1F); | ||
RPM = EMC2302_FAN_RPM_NUMERATOR / RPM; | ||
//ESP_LOGI(TAG, "Fan Speed[%d] = %d RPM", devicenum, RPM); | ||
|
||
return RPM; | ||
} | ||
|
||
float EMC2302_get_external_temp(void) | ||
{ | ||
// We don't have temperature on this chip, so fake it | ||
return 0; | ||
} | ||
|
||
uint8_t EMC2302_get_internal_temp(void) | ||
{ | ||
// We don't have temperature on this chip, so fake it | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#ifndef EMC2302_H_ | ||
#define EMC2302_H_ | ||
|
||
|
||
#define EMC2302_I2CADDR_DEFAULT 0x2F ///< EMC2302-2 default i2c address | ||
#define EMC2302_1_I2CADDR_DEFAULT 0x2E ///< EMC2302-2 default i2c address | ||
#define EMC2302_WHOAMI 0xFD ///< Chip ID register | ||
#define EMC2302_MANUFACTURER_ID 0xFE ///< Manufacturer ID | ||
#define EMC2302_REVISION 0xFF ///< Chip revision | ||
|
||
#define EMC2302_CONFIG 0x20 ///< configuration register | ||
#define EMC2302_STATUS 0x24 ///< status register | ||
#define EMC2302_STALL_STATUS 0x25 ///< fan stall status | ||
#define EMC2302_SPIN_STATUS 0x26 ///< fan spin status | ||
#define EMC2302_DRIVE_FAIL_STATUS 0x27 ///< drive fail status | ||
#define EMC2302_INT_ENABLE 0x29 ///< interrupt enable register | ||
#define EMC2302_PWM_POLARITY 0x2A ///< PWM polarity config | ||
#define EMC2302_PWM_OUTPUT 0x2B ///< PWM output config | ||
#define EMC2302_PWM_BASEF45 0x2C ///< | ||
#define EMC2302_PWM_BASEF123 ///< | ||
|
||
#define EMC2302_FAN1_SETTING 0x30 ///< Fan 1 setting | ||
#define EMC2302_PWM1_DIVIDE 0x31 ///< PWM 1 divider | ||
#define EMC2302_FAN1_CONFIG1 0x32 ///< Fan 1 configuration 1 register | ||
#define EMC2302_FAN1_CONFIG2 0x33 ///< Fan 1 configuration 2 register | ||
#define EMC2302_GAIN1 0x35 ///< Gain 1 register | ||
#define EMC2302_FAN1_SPINUP_CONFIG 0x36 ///< Fan 1 spinup configuration register | ||
#define EMC2302_FAN1_MAX_STEP 0x37 ///< Fan 1 max step register | ||
#define EMC2302_FAN1_MIN_DRIVE 0x38 ///< Fan 1 minimum drive register | ||
#define EMC2302_FAN1_TACH_COUNT 0x39 ///< Fan 1 valid TACH count | ||
#define EMC2302_FAN1_DRV_FAIL_LOW 0x3A ///< Fan 1 drive fail band low byte | ||
#define EMC2302_FAN1_DRV_FAIL_HIGH 0x3B ///< Fan 1 drive fail band high byte | ||
#define EMC2302_TACH1_TARGET_LSB 0x3C ///< Tach 1 target low byte | ||
#define EMC2302_TACH1_TARGET_MSB 0x3D ///< Tach 1 target high byte | ||
#define EMC2302_TACH1_LSB 0x3E ///< Tach 1 reading low byte | ||
#define EMC2302_TACH1_MSB 0x3F ///< Tach 1 reading high byte | ||
|
||
#define EMC2302_FAN2_SETTING 0x40 ///< Fan 2 setting | ||
#define EMC2302_PWM2_DIVIDE 0x41 ///< PWM 2 divider | ||
#define EMC2302_FAN2_CONFIG1 0x42 ///< Fan 2 configuration 1 register | ||
#define EMC2302_FAN2_CONFIG2 0x43 ///< Fan 2 configuration 2 register | ||
#define EMC2302_GAIN2 0x45 ///< Gain 2 register | ||
#define EMC2302_FAN2_SPINUP_CONFIG 0x46 ///< Fan 2 spinup configuration register | ||
#define EMC2302_FAN2_MAX_STEP 0x47 ///< Fan 2 max step register | ||
#define EMC2302_FAN2_MIN_DRIVE 0x48 ///< Fan 2 minimum drive register | ||
#define EMC2302_FAN2_TACH_COUNT 0x49 ///< Fan 2 valid TACH count | ||
#define EMC2302_FAN2_DRV_FAIL_LOW 0x4A ///< Fan 2 drive fail band low byte | ||
#define EMC2302_FAN2_DRV_FAIL_HIGH 0x4B ///< Fan 2 drive fail band high byte | ||
#define EMC2302_TACH2_TARGET_LSB 0x4C ///< Tach 2 target low byte | ||
#define EMC2302_TACH2_TARGET_MSB 0x4D ///< Tach 2 target high byte | ||
#define EMC2302_TACH2_LSB 0x4E ///< Tach 2 reading low byte | ||
#define EMC2302_TACH2_MSB 0x4F ///< Tach 2 reading high byte | ||
|
||
#define EMC2302_FAN_RPM_NUMERATOR 3932160 ///< Conversion unit to convert LSBs to fan RPM | ||
#define _TEMP_LSB 0.125 ///< single bit value for internal temperature readings | ||
|
||
/** | ||
* @brief | ||
* | ||
* Allowed values for `setDataRate`. | ||
*/ | ||
typedef enum | ||
{ | ||
EMC2302_RATE_1_16_HZ, ///< 1_16_HZ | ||
EMC2302_RATE_1_8_HZ, ///< 1_8_HZ | ||
EMC2302_RATE_1_4_HZ, ///< 1_4_HZ | ||
EMC2302_RATE_1_2_HZ, ///< 1_2_HZ | ||
EMC2302_RATE_1_HZ, ///< 1_HZ | ||
EMC2302_RATE_2_HZ, ///< 2_HZ | ||
EMC2302_RATE_4_HZ, ///< 4_HZ | ||
EMC2302_RATE_8_HZ, ///< 8_HZ | ||
EMC2302_RATE_16_HZ, ///< 16_HZ | ||
EMC2302_RATE_32_HZ, ///< 32_HZ | ||
} emc2302_rate_t; | ||
|
||
void EMC2302_init(bool); | ||
void EMC2302_set_fan_speed(uint8_t, float); | ||
uint16_t EMC2302_get_fan_speed(uint8_t); | ||
|
||
float EMC2302_get_external_temp(void); | ||
uint8_t EMC2302_get_internal_temp(void); | ||
|
||
#endif /* EMC2302_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do arithmetic with constants, this is bound to cause problems. Use ifs or switch and handle out of bound devicenum.