diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..74b285c --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,38 @@ +FROM espressif/idf + +ARG DEBIAN_FRONTEND=nointeractive + +RUN apt-get update \ + && apt install -y -q \ + cmake \ + git \ + hwdata \ + libglib2.0-0 \ + libnuma1 \ + libpixman-1-0 \ + linux-tools-virtual \ + && rm -rf /var/lib/apt/lists/* + +RUN update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20 + +# QEMU +ENV QEMU_REL=esp-develop-20220919 +ENV QEMU_SHA256=f6565d3f0d1e463a63a7f81aec94cce62df662bd42fc7606de4b4418ed55f870 +ENV QEMU_DIST=qemu-${QEMU_REL}.tar.bz2 +ENV QEMU_URL=https://github.com/espressif/qemu/releases/download/${QEMU_REL}/${QEMU_DIST} + +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 + +RUN wget --no-verbose ${QEMU_URL} \ + && echo "${QEMU_SHA256} *${QEMU_DIST}" | sha256sum --check --strict - \ + && tar -xf $QEMU_DIST -C /opt \ + && rm ${QEMU_DIST} + +ENV PATH=/opt/qemu/bin:${PATH} + +RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc + +ENTRYPOINT [ "/opt/esp/entrypoint.sh" ] + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..502bbf7 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,29 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/ubuntu +{ + "name": "ESP-IDF QEMU", + "build": { + "dockerfile": "Dockerfile" + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-vscode.cpptools", + "espressif.esp-idf-extension" + ], + "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind", + /* the path of workspace folder to be opened after container is running + */ + "workspaceFolder": "/workspaces", + "mounts": [ + "source=extensionCache,target=/root/.vscode-server/extensions,type=volume" + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "bash", + "idf.espIdfPath": "/opt/esp/idf", + "idf.customExtraPaths": "", + "idf.pythonBinPath": "/opt/esp/python_env/idf5.1_py3.8_env/bin/python", + "idf.toolsPath": "/opt/esp", + "idf.gitPath": "/usr/bin/git" + }, + "runArgs": ["--privileged"] +} \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b6ce209 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,29 @@ +{ + "configurations": [ + { + "name": "ESP-IDF", + "compilerPath": "/Users/skot/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32s3-elf/bin/xtensa-esp32s3-elf-gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "includePath": [ + "${config:idf.espIdfPath}/components/**", + "${config:idf.espIdfPathWin}/components/**", + "${config:idf.espAdfPath}/components/**", + "${config:idf.espAdfPathWin}/components/**", + "${workspaceFolder}/**" + ], + "browse": { + "path": [ + "${config:idf.espIdfPath}/components", + "${config:idf.espIdfPathWin}/components", + "${config:idf.espAdfPath}/components/**", + "${config:idf.espAdfPathWin}/components/**", + "${workspaceFolder}" + ], + "limitSymbolsToIncludedHeaders": false + }, + "compileCommands": "${workspaceFolder}/build/compile_commands.json" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6d2236f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,10 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "espidf", + "name": "Launch", + "request": "launch" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..14ccc34 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "C_Cpp.intelliSenseEngine": "Tag Parser", + "idf.adapterTargetName": "esp32s3", + "idf.customExtraPaths": "/Users/skot/.espressif/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin:/Users/skot/.espressif/tools/xtensa-esp32s2-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32s2-elf/bin:/Users/skot/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32s3-elf/bin:/Users/skot/.espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin:/Users/skot/.espressif/tools/esp32ulp-elf/2.28.51-esp-20191205/esp32ulp-elf-binutils/bin:/Users/skot/.espressif/tools/esp32s2ulp-elf/2.28.51-esp-20191205/esp32s2ulp-elf-binutils/bin:/Users/skot/.espressif/tools/openocd-esp32/v0.11.0-esp32-20211220/openocd-esp32/bin", + "idf.customExtraVars": "{\"OPENOCD_SCRIPTS\":\"/Users/skot/.espressif/tools/openocd-esp32/v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts\"}", + "idf.espIdfPath": "/Users/skot/esp/esp-idf", + "idf.openOcdConfigs": [ + "interface/ftdi/esp32_devkitj_v1.cfg", + "target/esp32s3.cfg" + ], + "idf.port": "/dev/cu.usbserial-14301", + "idf.pythonBinPath": "/Users/skot/.espressif/python_env/idf4.4_py3.9_env/bin/python", + "idf.toolsPath": "/Users/skot/.espressif", + "files.associations": { + "array": "c", + "string": "c", + "string_view": "c", + "ds4432u.h": "c", + "led_controller.h": "c" + }, + "idf.flashType": "UART" +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..3a649a6 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,300 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build - Build project", + "type": "shell", + "command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py build", + "windows": { + "command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py build", + "options": { + "env": { + "PATH": "${env:PATH};${config:idf.customExtraPaths}" + } + } + }, + "options": { + "env": { + "PATH": "${env:PATH}:${config:idf.customExtraPaths}" + } + }, + "problemMatcher": [ + { + "owner": "cpp", + "fileLocation": [ + "relative", + "${workspaceFolder}" + ], + "pattern": { + "regexp": "^\\.\\.(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + }, + { + "owner": "cpp", + "fileLocation": "absolute", + "pattern": { + "regexp": "^[^\\.](.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } + ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Set ESP-IDF Target", + "type": "shell", + "command": "${command:espIdf.setTarget}", + "problemMatcher": { + "owner": "cpp", + "fileLocation": "absolute", + "pattern": { + "regexp": "^(.*):(//d+):(//d+)://s+(warning|error)://s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } + }, + { + "label": "Clean - Clean the project", + "type": "shell", + "command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py fullclean", + "windows": { + "command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py fullclean", + "options": { + "env": { + "PATH": "${env:PATH};${config:idf.customExtraPaths}" + } + } + }, + "options": { + "env": { + "PATH": "${env:PATH}:${config:idf.customExtraPaths}" + } + }, + "problemMatcher": [ + { + "owner": "cpp", + "fileLocation": [ + "relative", + "${workspaceFolder}" + ], + "pattern": { + "regexp": "^\\.\\.(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + }, + { + "owner": "cpp", + "fileLocation": "absolute", + "pattern": { + "regexp": "^[^\\.](.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } + ] + }, + { + "label": "Flash - Flash the device", + "type": "shell", + "command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py -p ${config:idf.port} -b ${config:idf.flashBaudRate} flash", + "windows": { + "command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py flash -p ${config:idf.portWin} -b ${config:idf.flashBaudRate}", + "options": { + "env": { + "PATH": "${env:PATH};${config:idf.customExtraPaths}" + } + } + }, + "options": { + "env": { + "PATH": "${env:PATH}:${config:idf.customExtraPaths}" + } + }, + "problemMatcher": [ + { + "owner": "cpp", + "fileLocation": [ + "relative", + "${workspaceFolder}" + ], + "pattern": { + "regexp": "^\\.\\.(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + }, + { + "owner": "cpp", + "fileLocation": "absolute", + "pattern": { + "regexp": "^[^\\.](.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } + ] + }, + { + "label": "Monitor: Start the monitor", + "type": "shell", + "command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py -p ${config:idf.port} monitor", + "windows": { + "command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py -p ${config:idf.portWin} monitor", + "options": { + "env": { + "PATH": "${env:PATH};${config:idf.customExtraPaths}" + } + } + }, + "options": { + "env": { + "PATH": "${env:PATH}:${config:idf.customExtraPaths}" + } + }, + "problemMatcher": [ + { + "owner": "cpp", + "fileLocation": [ + "relative", + "${workspaceFolder}" + ], + "pattern": { + "regexp": "^\\.\\.(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + }, + { + "owner": "cpp", + "fileLocation": "absolute", + "pattern": { + "regexp": "^[^\\.](.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } + ], + "dependsOn": "Flash - Flash the device" + }, + { + "label": "OpenOCD: Start openOCD", + "type": "shell", + "presentation": { + "echo": true, + "reveal": "never", + "focus": false, + "panel": "new" + }, + "command": "openocd -s ${command:espIdf.getOpenOcdScriptValue} ${command:espIdf.getOpenOcdConfigs}", + "windows": { + "command": "openocd.exe -s ${command:espIdf.getOpenOcdScriptValue} ${command:espIdf.getOpenOcdConfigs}", + "options": { + "env": { + "PATH": "${env:PATH};${config:idf.customExtraPaths}" + } + } + }, + "options": { + "env": { + "PATH": "${env:PATH}:${config:idf.customExtraPaths}" + } + }, + "problemMatcher": { + "owner": "cpp", + "fileLocation": "absolute", + "pattern": { + "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } + }, + { + "label": "adapter", + "type": "shell", + "command": "${config:idf.pythonBinPath}", + "isBackground": true, + "options": { + "env": { + "PATH": "${env:PATH}:${config:idf.customExtraPaths}", + "PYTHONPATH": "${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter" + } + }, + "problemMatcher": { + "background": { + "beginsPattern": "\bDEBUG_ADAPTER_STARTED\b", + "endsPattern": "DEBUG_ADAPTER_READY2CONNECT", + "activeOnStart": true + }, + "pattern": { + "regexp": "(\\d+)-(\\d+)-(\\d+)\\s(\\d+):(\\d+):(\\d+),(\\d+)\\s-(.+)\\s(ERROR)", + "file": 8, + "line": 2, + "column": 3, + "severity": 4, + "message": 9 + } + }, + "args": [ + "${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter_main.py", + "-e", + "${workspaceFolder}/build/${command:espIdf.getProjectName}.elf", + "-s", + "${command:espIdf.getOpenOcdScriptValue}", + "-ip", + "localhost", + "-dn", + "${config:idf.adapterTargetName}", + "-om", + "connect_to_instance" + ], + "windows": { + "command": "${config:idf.pythonBinPathWin}", + "options": { + "env": { + "PATH": "${env:PATH};${config:idf.customExtraPaths}", + "PYTHONPATH": "${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter" + } + } + } + } + ] +} \ No newline at end of file diff --git a/bm1397_protocol.md b/bm1397_protocol.md deleted file mode 100644 index 7163fe6..0000000 --- a/bm1397_protocol.md +++ /dev/null @@ -1,54 +0,0 @@ -## BM1397 protocol -notes from sniffing BM1397 communication and trying to match it up with cgminer - -It looks like this setting up the BM1397: -``` -TX: 55 AA 52 05 00 00 0A // also "chippy"?? - -RX: AA 55 13 97 18 00 00 00 06 //response from the BM1397 - -TX: 55 AA 53 05 00 00 03 //chain inactive -TX: 55 AA 53 05 00 00 03 //chain inactive -TX: 55 AA 53 05 00 00 03 //chain inactive -TX: 55 AA 40 05 00 00 1C //"chippy"?? -TX: 55 AA 51 09 00 80 00 00 00 00 1C //init1 -TX: 55 AA 51 09 00 84 00 00 00 00 11 //init2 -TX: 55 AA 51 09 00 20 00 00 00 01 02 //init3 -TX: 55 AA 51 09 00 3C 80 00 80 74 10 //init4 -TX: 55 AA 51 09 00 14 00 00 00 00 1C //set_ticket -TX: 55 AA 51 09 00 68 C0 70 01 11 00 //init5 -TX: 55 AA 51 09 00 68 C0 70 01 11 00 //init5 (second one) -TX: 55 AA 51 09 00 28 06 00 00 0F 18 //init6 -TX: 55 AA 51 09 00 18 00 00 7A 31 15 //baudrate -TX: 55 AA 51 09 00 70 0F 0F 0F 00 19 //prefreq -TX: 55 AA 51 09 00 70 0F 0F 0F 00 19 //prefreq -TX: 55 AA 51 09 00 08 40 A0 02 25 16 //freqbuf -TX: 55 AA 51 09 00 08 40 A0 02 25 16 //freqbuf -``` - -Sending work to the BM1397 looks like this; -``` -TX: 55 AA 21 96 04 04 00 00 00 00 72 E7 07 17 A9 81 51 63 EE D6 E5 43 35 3F 14 92 56 25 54 19 4E 41 31 08 E5 D7 89 4A C8 13 50 A4 48 05 B8 0E E2 E4 83 95 F8 C1 15 8D EC 07 D8 B8 AE CA DE E6 35 8C 3E E9 1C 57 5D 99 A7 52 95 DC D8 08 7B 7A D -``` - -How does this big work field break down? - -- `55 AA` -> (most) All of the commands to the BM1397 start with this -- `21` -> always 21. like bitcoin, always 21 million coins? -- `96` -> length -- `04` -> jobID -- `04` -> midstates -- `00 00 00 00` -> always zero. Is this the starting nonce? -- `72 E7 07 17` -> nbits -- `A9 81 51 63` -> ntime. if you flip the endianess, this is unixtimestamp for Thu Oct 20 2022 17:13:13 GMT. boom! -- `EE D6 E5 43` -> last 4 bytes of the merkle root -- `35 3F 14 92 56 25 54 19 4E 41 31 08 E5 D7 89 4A C8 13 50 A4 48 05 B8 0E E2 E4 83 95 F8 C1 15 8D` -> midstate computed from the first 64 bytes of the header -- `EC 07 D8 B8 AE CA DE E6 35 8C 3E E9 1C 57 5D 99 A7 52 95 DC D8 08 7B 7A D` -> ?? another midstate? - -when the BM1397 finds a nonce that makes a hash below the difficulty (which difficulty is that?) it responds with; -``` -AA 55 00 03 EA 0F 02 20 9C -``` -this means the Nonce `0003ea0f` was found for JobID `20` - -If the BM1397 _doesn't_ find a good nonce in the whole nonce space, it just goes off into lalaland. It's up to the miner to keep track of what the ASIC is doing and send it more work if this happens. If you look at the hashing frequency you should be able to time this. diff --git a/doc/diagram.png b/doc/diagram.png deleted file mode 100644 index fd0bd36..0000000 Binary files a/doc/diagram.png and /dev/null differ diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 6000d28..558f425 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,2 +1,2 @@ -idf_component_register(SRCS "i2c_simple_main.c" "led_controller.c" "DS4432U.c" +idf_component_register(SRCS "EMC2101.c" "i2c_simple_main.c" "led_controller.c" "DS4432U.c" "EMC2101.c" INCLUDE_DIRS ".") diff --git a/main/EMC2101.c b/main/EMC2101.c index df99375..45bb869 100644 --- a/main/EMC2101.c +++ b/main/EMC2101.c @@ -1,8 +1,81 @@ +#include +#include "esp_log.h" +#include "driver/i2c.h" + +#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL /*!< GPIO number used for I2C master clock */ +#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA /*!< 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 + //EMC2101 -- Fan and temp sensor controller //address: 0x4C #define EMC2101_SENSOR_ADDR 0x4C //Slave address of the EMC2101 #define EMC2101_PRODUCTID_REG 0xFD //should be 0x16 or 0x28 +#define EMC2101_CONFIG_REG 0x03 - // /* Read the EMC2101 WHO_AM_I register, on power up the register should have the value 0x16 or 0x28 */ - // ESP_ERROR_CHECK(register_read(EMC2101_SENSOR_ADDR, EMC2101_PRODUCTID_REG, data, 1)); - // ESP_LOGI(TAG, "EMC2101 PRODUCT ID = 0x%02X", data[0]); \ No newline at end of file +#define EMC2101_FANCONFIG_REG 0x4A +#define EMC2101_FANSETTING_REG 0x4C + +#define EMC2101_TACHREADING_REG 0x46 //2 bytes + +static const char *TAG = "EMC2101.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, EMC2101_SENSOR_ADDR, ®_addr, 1, data, len, I2C_MASTER_TIMEOUT_MS / portTICK_RATE_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, EMC2101_SENSOR_ADDR, write_buf, sizeof(write_buf), I2C_MASTER_TIMEOUT_MS / portTICK_RATE_MS); + + return ret; +} + +//takes a fan speed percent +void EMC2101_set_config(uint8_t reg) { + ESP_ERROR_CHECK(register_write_byte(EMC2101_CONFIG_REG, reg)); +} + +//takes a fan speed percent +void EMC2101_set_fan_speed(float percent) { + uint8_t speed; + + speed = (uint8_t)(63.0 * percent); + ESP_ERROR_CHECK(register_write_byte(EMC2101_FANSETTING_REG, speed)); +} + +//RPM = 5400000/reading +uint32_t EMC2101_get_fan_speed(void) { + uint8_t data[3]; + uint16_t reading; + uint32_t RPM; + + ESP_ERROR_CHECK(register_read(EMC2101_TACHREADING_REG, data, 2)); + + ESP_LOGI(TAG, "Raw Fan Speed = %02X %02X", data[0], data[1]); + + reading = data[0] | (data[1] << 8); + RPM = 5400000/reading; + + ESP_LOGI(TAG, "Fan Speed = %d RPM", RPM); + return RPM; +} + +void EMC2101_read(void) { + uint8_t data[3]; + + /* Read the EMC2101 WHO_AM_I register, on power up the register should have the value 0x16 or 0x28 */ + ESP_ERROR_CHECK(register_read(EMC2101_PRODUCTID_REG, data, 1)); + ESP_LOGI(TAG, "EMC2101 PRODUCT ID = 0x%02X", data[0]); +} \ No newline at end of file diff --git a/main/EMC2101.h b/main/EMC2101.h new file mode 100644 index 0000000..5ac11d7 --- /dev/null +++ b/main/EMC2101.h @@ -0,0 +1,9 @@ +#ifndef EMC2101_H_ +#define EMC2101_H_ + +void EMC2101_set_fan_speed(float); +void EMC2101_read(void); +uint32_t EMC2101_get_fan_speed(void); +void EMC2101_set_config(uint8_t); + +#endif /* EMC2101_H_ */ \ No newline at end of file diff --git a/main/i2c_simple_main.c b/main/i2c_simple_main.c index 8624a9c..ea46470 100755 --- a/main/i2c_simple_main.c +++ b/main/i2c_simple_main.c @@ -18,33 +18,43 @@ #include "esp_log.h" #include "driver/i2c.h" +// Include FreeRTOS for delay +#include +#include + #include "led_controller.h" #include "DS4432U.h" +#include "EMC2101.h" static const char *TAG = "i2c-test"; void app_main(void) { //test the LEDs - ESP_LOGI(TAG, "Init LEDs!"); - - ledc_init(); - led_set(); + // ESP_LOGI(TAG, "Init LEDs!"); + // ledc_init(); + // led_set(); ESP_ERROR_CHECK(i2c_master_init()); ESP_LOGI(TAG, "I2C initialized successfully"); - DS4432U_read(); + // DS4432U_read(); - DS4432U_set(0x00); - float core_voltage = 1.0; - uint8_t reg_setting; + // DS4432U_set(0x00); + // float core_voltage = 1.0; + // uint8_t reg_setting; - reg_setting = voltage_to_reg(core_voltage); + // reg_setting = voltage_to_reg(core_voltage); - ESP_LOGI(TAG, "Test set %.3fV = 0x%02X", core_voltage, reg_setting); + // ESP_LOGI(TAG, "Test set %.3fV = 0x%02X", core_voltage, reg_setting); - DS4432U_set(reg_setting); ///eek! + // DS4432U_set(reg_setting); ///eek! + + EMC2101_read(); + EMC2101_set_config(0x04); //set the tach input + EMC2101_set_fan_speed(0.5); + vTaskDelay(2000 / portTICK_RATE_MS); + EMC2101_get_fan_speed(); ESP_ERROR_CHECK(i2c_master_delete()); ESP_LOGI(TAG, "I2C unitialized successfully");