Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jiga authored Oct 9, 2024
2 parents 22dc851 + 2c13f23 commit c120b8d
Show file tree
Hide file tree
Showing 49 changed files with 1,086 additions and 621 deletions.
1 change: 1 addition & 0 deletions components/asic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SRCS
"bm1397.c"
"serial.c"
"crc.c"
"common.c"

INCLUDE_DIRS
"include"
Expand Down
14 changes: 7 additions & 7 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,13 @@ static void _reset(void)
vTaskDelay(100 / portTICK_PERIOD_MS);
}

static void _send_read_address(void)
{
// static void _send_read_address(void)
// {

unsigned char read_address[2] = {0x00, 0x00};
// send serial data
_send_BM1366((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, BM1366_SERIALTX_DEBUG);
}
// unsigned char read_address[2] = {0x00, 0x00};
// // send serial data
// _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, BM1366_SERIALTX_DEBUG);
// }

uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count)
{
Expand Down Expand Up @@ -625,7 +625,7 @@ void BM1366_send_work(void * pvParameters, bm_job * next_bm_job)
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
#endif

_send_BM1366((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1366_job), BM1366_DEBUG_WORK);
_send_BM1366((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1366_job), BM1366_DEBUG_WORK);
}

asic_result * BM1366_receive_work(void)
Expand Down
2 changes: 1 addition & 1 deletion components/asic/bm1368.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void BM1368_send_work(void * pvParameters, bm_job * next_bm_job)
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
#endif

_send_BM1368((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1368_job), BM1368_DEBUG_WORK);
_send_BM1368((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1368_job), BM1368_DEBUG_WORK);
}

asic_result * BM1368_receive_work(void)
Expand Down
14 changes: 7 additions & 7 deletions components/asic/bm1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ static void _reset(void)
vTaskDelay(100 / portTICK_PERIOD_MS);
}

static void _send_read_address(void)
{
// static void _send_read_address(void)
// {

unsigned char read_address[2] = {0x00, 0x00};
// send serial data
_send_BM1370((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, BM1370_SERIALTX_DEBUG);
}
// unsigned char read_address[2] = {0x00, 0x00};
// // send serial data
// _send_BM1370((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, BM1370_SERIALTX_DEBUG);
// }

uint8_t BM1370_init(uint64_t frequency, uint16_t asic_count)
{
Expand Down Expand Up @@ -432,7 +432,7 @@ void BM1370_send_work(void * pvParameters, bm_job * next_bm_job)
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
#endif

_send_BM1370((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(BM1370_job), BM1370_DEBUG_WORK);
_send_BM1370((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(BM1370_job), BM1370_DEBUG_WORK);
}

asic_result * BM1370_receive_work(void)
Expand Down
2 changes: 1 addition & 1 deletion components/asic/bm1397.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void BM1397_send_work(void *pvParameters, bm_job *next_bm_job)
ESP_LOGI(TAG, "Send Job: %02X", job.job_id);
#endif

_send_BM1397((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), &job, sizeof(job_packet), BM1397_DEBUG_WORK);
_send_BM1397((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&job, sizeof(job_packet), BM1397_DEBUG_WORK);
}

asic_result *BM1397_receive_work(void)
Expand Down
27 changes: 27 additions & 0 deletions components/asic/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "common.h"

unsigned char _reverse_bits(unsigned char num)
{
unsigned char reversed = 0;
int i;

for (i = 0; i < 8; i++) {
reversed <<= 1; // Left shift the reversed variable by 1
reversed |= num & 1; // Use bitwise OR to set the rightmost bit of reversed to the current bit of num
num >>= 1; // Right shift num by 1 to get the next bit
}

return reversed;
}

int _largest_power_of_two(int num)
{
int power = 0;

while (num > 1) {
num = num >> 1;
power++;
}

return 1 << power;
}
27 changes: 2 additions & 25 deletions components/asic/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,7 @@ typedef struct __attribute__((__packed__))
uint32_t rolled_version;
} task_result;

static unsigned char _reverse_bits(unsigned char num)
{
unsigned char reversed = 0;
int i;

for (i = 0; i < 8; i++) {
reversed <<= 1; // Left shift the reversed variable by 1
reversed |= num & 1; // Use bitwise OR to set the rightmost bit of reversed to the current bit of num
num >>= 1; // Right shift num by 1 to get the next bit
}

return reversed;
}

static int _largest_power_of_two(int num)
{
int power = 0;

while (num > 1) {
num = num >> 1;
power++;
}

return 1 << power;
}
unsigned char _reverse_bits(unsigned char num);
int _largest_power_of_two(int num);

#endif
2 changes: 1 addition & 1 deletion components/connect/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void wifi_init(const char * wifi_ssid, const char * wifi_pass, const char * host

/* Initialize AP */
ESP_LOGI(TAG, "ESP_WIFI Access Point On");
esp_netif_t * esp_netif_ap = wifi_init_softap();
wifi_init_softap();

/* Initialize STA */
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
Expand Down
2 changes: 1 addition & 1 deletion components/stratum/stratum_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ int STRATUM_V1_subscribe(int socket, char * model)
{
// Subscribe
char subscribe_msg[BUFFER_SIZE];
const esp_app_desc_t *app_desc = esp_ota_get_app_description();
const esp_app_desc_t *app_desc = esp_app_get_description();
const char *version = app_desc->version;
sprintf(subscribe_msg, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"bitaxe/%s/%s\"]}\n", send_uid++, model, version);
debug_stratum_tx(subscribe_msg);
Expand Down
4 changes: 2 additions & 2 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ SRCS
"DS4432U.c"
"EMC2101.c"
"fonts.c"
"i2c_master.c"
"i2c_bitaxe.c"
"INA260.c"
"led_controller.c"
"main.c"
"nvs_config.c"
"oled.c"
"system.c"
"TMP1075.c"
"TPS546.c"
"vcore.c"
"work_queue.c"
Expand Down Expand Up @@ -47,6 +46,7 @@ PRIV_REQUIRES
"nvs_flash"
"spiffs"
"vfs"
"esp_driver_i2c"
)

set(WEB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/http_server/axe-os")
Expand Down
20 changes: 15 additions & 5 deletions main/DS4432U.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include <math.h>
#include "esp_log.h"

#include "i2c_master.h"

#include "i2c_bitaxe.h"
#include "DS4432U.h"

// DS4432U+ -- Adjustable current DAC
Expand All @@ -13,6 +12,17 @@

static const char *TAG = "DS4432U";

static i2c_master_dev_handle_t ds4432u_dev_handle;

/**
* @brief Initialize the DS4432U+ sensor.
*
* @return esp_err_t ESP_OK on success, or an error code on failure.
*/
esp_err_t DS4432U_init(void) {
return i2c_bitaxe_add_device(DS4432U_SENSOR_ADDR, &ds4432u_dev_handle);
}

/**
* @brief Set the current DAC code for a specific DS4432U output.
*
Expand All @@ -22,7 +32,7 @@ static const char *TAG = "DS4432U";
*/
esp_err_t DS4432U_set_current_code(uint8_t output, uint8_t code) {
uint8_t reg = (output == 0) ? DS4432U_OUT0_REG : DS4432U_OUT1_REG;
return i2c_master_register_write_byte(DS4432U_SENSOR_ADDR, reg, code);
return i2c_bitaxe_register_write_byte(ds4432u_dev_handle, reg, code);
}

/**
Expand All @@ -34,15 +44,15 @@ esp_err_t DS4432U_set_current_code(uint8_t output, uint8_t code) {
*/
esp_err_t DS4432U_get_current_code(uint8_t output, uint8_t *code) {
uint8_t reg = (output == 0) ? DS4432U_OUT0_REG : DS4432U_OUT1_REG;
return i2c_master_register_read(DS4432U_SENSOR_ADDR, reg, code, 1);
return i2c_bitaxe_register_read(ds4432u_dev_handle, reg, code, 1);
}

bool DS4432U_test(void)
{
uint8_t data;

/* Read the DS4432U+ WHO_AM_I register, on power up the register should have the value 0x00 */
esp_err_t register_result = i2c_master_register_read(DS4432U_SENSOR_ADDR, DS4432U_OUT0_REG, &data, 1);
esp_err_t register_result = i2c_bitaxe_register_read(ds4432u_dev_handle, DS4432U_OUT0_REG, &data, 1);
ESP_LOGI(TAG, "DS4432U+ OUT0 = 0x%02X", data);
return register_result == ESP_OK;
}
1 change: 1 addition & 0 deletions main/DS4432U.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DS4432_VRFS 0.997

bool DS4432U_test(void);
esp_err_t DS4432U_init(void);
esp_err_t DS4432U_set_current_code(uint8_t output, uint8_t code);
esp_err_t DS4432U_get_current_code(uint8_t output, uint8_t *code);

Expand Down
38 changes: 26 additions & 12 deletions main/EMC2101.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
#include "esp_log.h"
#include <stdio.h>
#include "esp_log.h"

#include "i2c_bitaxe.h"
#include "EMC2101.h"

static const char * TAG = "EMC2101";

// static const char *TAG = "EMC2101.c";

// run this first. sets up the config register
void EMC2101_init(bool invertPolarity)
{
static i2c_master_dev_handle_t emc2101_dev_handle;

/**
* @brief Initialize the EMC2101 sensor.
*
* @return esp_err_t ESP_OK on success, or an error code on failure.
*/
esp_err_t EMC2101_init(bool invertPolarity) {

if (i2c_bitaxe_add_device(EMC2101_I2CADDR_DEFAULT, &emc2101_dev_handle) != ESP_OK) {
ESP_LOGE(TAG, "Failed to add device");
return ESP_FAIL;
}

// set the TACH input
ESP_ERROR_CHECK(i2c_master_register_write_byte(EMC2101_I2CADDR_DEFAULT, EMC2101_REG_CONFIG, 0x04));
ESP_ERROR_CHECK(i2c_bitaxe_register_write_byte(emc2101_dev_handle, EMC2101_REG_CONFIG, 0x04));

if (invertPolarity) {
ESP_ERROR_CHECK(i2c_master_register_write_byte(EMC2101_I2CADDR_DEFAULT, EMC2101_FAN_CONFIG, 0b00100011));
ESP_ERROR_CHECK(i2c_bitaxe_register_write_byte(emc2101_dev_handle, EMC2101_FAN_CONFIG, 0b00100011));
}

return ESP_OK;

}

// takes a fan speed percent
Expand All @@ -25,7 +39,7 @@ void EMC2101_set_fan_speed(float percent)
uint8_t speed;

speed = (uint8_t) (63.0 * percent);
ESP_ERROR_CHECK(i2c_master_register_write_byte(EMC2101_I2CADDR_DEFAULT, EMC2101_REG_FAN_SETTING, speed));
ESP_ERROR_CHECK(i2c_bitaxe_register_write_byte(emc2101_dev_handle, EMC2101_REG_FAN_SETTING, speed));
}

// RPM = 5400000/reading
Expand All @@ -35,8 +49,8 @@ uint16_t EMC2101_get_fan_speed(void)
uint16_t reading;
uint16_t RPM;

ESP_ERROR_CHECK(i2c_master_register_read(EMC2101_I2CADDR_DEFAULT, EMC2101_TACH_LSB, &tach_lsb, 1));
ESP_ERROR_CHECK(i2c_master_register_read(EMC2101_I2CADDR_DEFAULT, EMC2101_TACH_MSB, &tach_msb, 1));
ESP_ERROR_CHECK(i2c_bitaxe_register_read(emc2101_dev_handle, EMC2101_TACH_LSB, &tach_lsb, 1));
ESP_ERROR_CHECK(i2c_bitaxe_register_read(emc2101_dev_handle, EMC2101_TACH_MSB, &tach_msb, 1));

// ESP_LOGI(TAG, "Raw Fan Speed = %02X %02X", tach_msb, tach_lsb);

Expand All @@ -55,8 +69,8 @@ float EMC2101_get_external_temp(void)
uint8_t temp_msb, temp_lsb;
uint16_t reading;

ESP_ERROR_CHECK(i2c_master_register_read(EMC2101_I2CADDR_DEFAULT, EMC2101_EXTERNAL_TEMP_MSB, &temp_msb, 1));
ESP_ERROR_CHECK(i2c_master_register_read(EMC2101_I2CADDR_DEFAULT, EMC2101_EXTERNAL_TEMP_LSB, &temp_lsb, 1));
ESP_ERROR_CHECK(i2c_bitaxe_register_read(emc2101_dev_handle, EMC2101_EXTERNAL_TEMP_MSB, &temp_msb, 1));
ESP_ERROR_CHECK(i2c_bitaxe_register_read(emc2101_dev_handle, EMC2101_EXTERNAL_TEMP_LSB, &temp_lsb, 1));

reading = temp_lsb | (temp_msb << 8);
reading >>= 5;
Expand All @@ -80,6 +94,6 @@ float EMC2101_get_external_temp(void)
uint8_t EMC2101_get_internal_temp(void)
{
uint8_t temp;
ESP_ERROR_CHECK(i2c_master_register_read(EMC2101_I2CADDR_DEFAULT, EMC2101_INTERNAL_TEMP, &temp, 1));
ESP_ERROR_CHECK(i2c_bitaxe_register_read(emc2101_dev_handle, EMC2101_INTERNAL_TEMP, &temp, 1));
return temp;
}
4 changes: 2 additions & 2 deletions main/EMC2101.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef EMC2101_H_
#define EMC2101_H_

#include "i2c_master.h"
#include "i2c_bitaxe.h"

#define EMC2101_I2CADDR_DEFAULT 0x4C ///< EMC2101 default i2c address
#define EMC2101_CHIP_ID 0x16 ///< EMC2101 default device id from part id
Expand Down Expand Up @@ -88,7 +88,7 @@ typedef enum
void EMC2101_set_fan_speed(float);
// void EMC2101_read(void);
uint16_t EMC2101_get_fan_speed(void);
void EMC2101_init(bool);
esp_err_t EMC2101_init(bool);
float EMC2101_get_external_temp(void);
uint8_t EMC2101_get_internal_temp(void);
#endif /* EMC2101_H_ */
Loading

0 comments on commit c120b8d

Please sign in to comment.