forked from skot/ESP-Miner
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request skot#25 from shufps/nerdaxe
initial nerdaxe support
- Loading branch information
Showing
42 changed files
with
62,278 additions
and
36 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
idf_component_register( | ||
SRCS | ||
"asic.cpp" | ||
"bm1366.cpp" | ||
"bm1368.cpp" | ||
"bm1370.cpp" | ||
"serial.cpp" | ||
|
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,136 @@ | ||
#include <endian.h> | ||
#include <math.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdarg.h> | ||
#include <stddef.h> | ||
|
||
#include "esp_log.h" | ||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
|
||
#include "asic.h" | ||
#include "bm1366.h" | ||
|
||
#include "crc.h" | ||
#include "serial.h" | ||
#include "utils.h" | ||
|
||
static const uint64_t BM1366_CORE_COUNT = 112; | ||
static const uint64_t BM1366_SMALL_CORE_COUNT = 894; | ||
|
||
static const char *TAG = "bm1366Module"; | ||
|
||
static const uint8_t chip_id[6] = {0xaa, 0x55, 0x13, 0x66, 0x00, 0x00}; | ||
|
||
BM1366::BM1366() : Asic() { | ||
// NOP | ||
} | ||
|
||
const uint8_t* BM1366::getChipId() { | ||
return (uint8_t*) chip_id; | ||
} | ||
|
||
uint8_t BM1366::init(uint64_t frequency, uint16_t asic_count, uint32_t difficulty) | ||
{ | ||
// reset is done externally to not have board dependencies | ||
|
||
// enable and set version rolling mask to 0xFFFF | ||
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF); | ||
|
||
// enable and set version rolling mask to 0xFFFF (again) | ||
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF); | ||
|
||
// enable and set version rolling mask to 0xFFFF (again) | ||
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF); | ||
|
||
// enable and set version rolling mask to 0xFFFF (again) | ||
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF); | ||
|
||
int chip_counter = count_asics(); | ||
ESP_LOGI(TAG, "%i chip(s) detected on the chain, expected %i", chip_counter, asic_count); | ||
|
||
// enable and set version rolling mask to 0xFFFF (again) | ||
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF); | ||
|
||
// Reg_A8 | ||
send6(CMD_WRITE_ALL, 0x00, 0xA8, 0x00, 0x07, 0x00, 0x00); | ||
|
||
// Misc Control | ||
send6(CMD_WRITE_ALL, 0x00, 0x18, 0xFF, 0x0F, 0xC1, 0x00); | ||
|
||
// chain inactive | ||
sendChainInactive(); | ||
|
||
// set chip address | ||
for (uint8_t i = 0; i < chip_counter; i++) { | ||
setChipAddress(i * 2); | ||
} | ||
|
||
// Core Register Control | ||
send6(CMD_WRITE_ALL, 0x00, 0x3C, 0x80, 0x00, 0x85, 0x40); | ||
|
||
// Core Register Control | ||
send6(CMD_WRITE_ALL, 0x00, 0x3C, 0x80, 0x00, 0x80, 0x20); | ||
|
||
setJobDifficultyMask(difficulty); | ||
|
||
// Analog Mux Control | ||
send6(CMD_WRITE_ALL, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03); | ||
|
||
// Set the IO Driver Strength on chip 00 | ||
send6(CMD_WRITE_ALL, 0x00, 0x58, 0x02, 0x11, 0x11, 0x11); | ||
|
||
for (uint8_t i = 0; i < chip_counter; i++) { | ||
// Reg_A8 | ||
send6(CMD_WRITE_SINGLE, i * 2, 0xA8, 0x00, 0x07, 0x01, 0xF0); | ||
// Misc Control | ||
send6(CMD_WRITE_SINGLE, i * 2, 0x18, 0xF0, 0x00, 0xC1, 0x00); | ||
// Core Register Control | ||
send6(CMD_WRITE_SINGLE, i * 2, 0x3C, 0x80, 0x00, 0x85, 0x40); | ||
// Core Register Control | ||
send6(CMD_WRITE_SINGLE, i * 2, 0x3C, 0x80, 0x00, 0x80, 0x20); | ||
// Core Register Control | ||
send6(CMD_WRITE_SINGLE, i * 2, 0x3C, 0x80, 0x00, 0x82, 0xAA); | ||
} | ||
|
||
doFrequencyTransition(frequency); | ||
|
||
// register 10 is still a bit of a mystery. discussion: https://github.com/skot/ESP-Miner/pull/167 | ||
|
||
// send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x00, 0x11, 0x5A); //S19k Pro Default | ||
// send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x00, 0x14, 0x46); //S19XP-Luxos Default | ||
send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x00, 0x15, 0x1C); //S19XP-Stock Default | ||
// send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x0F, 0x00, 0x00); //supposedly the "full" 32bit nonce range | ||
//send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x00, 0x15, 0xA4); // S21-Stock Default | ||
|
||
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF); | ||
|
||
return chip_counter; | ||
} | ||
|
||
int BM1366::setMaxBaud(void) | ||
{ | ||
// return 115749; | ||
ESP_LOGI(TAG, "Setting max baud of 1000000 "); | ||
send6(CMD_WRITE_ALL, 0x00, 0x28, 0x11, 0x30, 0x02, 0x00); | ||
return 1000000; | ||
} | ||
|
||
void BM1366::requestChipTemp() { | ||
// NOP | ||
} | ||
|
||
uint8_t BM1366::jobToAsicId(uint8_t job_id) { | ||
return (job_id * 8) & 0x7f; | ||
} | ||
|
||
uint8_t BM1366::asicToJobId(uint8_t asic_id) { | ||
return asic_id & 0xf8; | ||
} | ||
|
||
uint16_t BM1366::getSmallCoreCount() { | ||
return BM1366_SMALL_CORE_COUNT; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "driver/gpio.h" | ||
#include "mining.h" | ||
#include "rom/gpio.h" | ||
#include "asic.h" | ||
|
||
class BM1366 : public Asic { | ||
protected: | ||
virtual const uint8_t* getChipId(); | ||
|
||
virtual uint8_t jobToAsicId(uint8_t job_id); | ||
virtual uint8_t asicToJobId(uint8_t asic_id); | ||
|
||
public: | ||
BM1366(); | ||
virtual const char* getName() { return "BM1366"; }; | ||
virtual uint8_t init(uint64_t frequency, uint16_t asic_count, uint32_t difficulty); | ||
virtual int setMaxBaud(void); | ||
virtual void requestChipTemp(); | ||
virtual uint16_t getSmallCoreCount(); | ||
}; | ||
|
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
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
#include "esp_log.h" | ||
|
||
#include "i2c_master.h" | ||
|
||
#include "DS4432U.h" | ||
|
||
// DS4432U+ -- Adjustable current DAC | ||
#define DS4432U_SENSOR_ADDR 0x48 // Slave address of the DS4432U+ | ||
#define DS4432U_OUT0_REG 0xF8 // register for current output 0 | ||
#define DS4432U_OUT1_REG 0xF9 // register for current output 1 | ||
|
||
static const char *TAG = "DS4432U"; | ||
|
||
/** | ||
* @brief Set the current DAC code for a specific DS4432U output. | ||
* | ||
* @param output The output channel (0 or 1). | ||
* @param code The current code value to set. | ||
* @return esp_err_t ESP_OK on success, or an error code on failure. | ||
*/ | ||
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); | ||
} | ||
|
||
/** | ||
* @brief Get the current DAC code value for a specific DS4432U output. | ||
* | ||
* @param output The output channel (0 or 1). | ||
* @param code Pointer to store the current code value. | ||
* @return esp_err_t ESP_OK on success, or an error code on failure. | ||
*/ | ||
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); | ||
} | ||
|
||
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_LOGI(TAG, "DS4432U+ OUT0 = 0x%02X", data); | ||
return register_result == ESP_OK; | ||
} |
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,13 @@ | ||
#ifndef DS4432U_H_ | ||
#define DS4432U_H_ | ||
|
||
#include <stdbool.h> | ||
#include "esp_check.h" | ||
|
||
#define DS4432_VRFS 0.997 | ||
|
||
bool DS4432U_test(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); | ||
|
||
#endif /* DS4432U_H_ */ |
Oops, something went wrong.