Skip to content

Commit

Permalink
Merge pull request #402 from skot/i2c_timeout
Browse files Browse the repository at this point in the history
Fix bad www.bin loads
  • Loading branch information
eandersson authored Oct 10, 2024
2 parents 70d551e + a0da6aa commit 478b01d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 10 additions & 6 deletions main/i2c_bitaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
#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_FREQ_HZ 100000 /*!< 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_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_TIMEOUT_MS 1000

//#define I2C_DEFAULT_TIMEOUT ( I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS )
#define I2C_DEFAULT_TIMEOUT -1 //-1 means wait forever

static i2c_master_bus_handle_t i2c_bus_handle;

Expand Down Expand Up @@ -55,7 +59,7 @@ esp_err_t i2c_bitaxe_register_read(i2c_master_dev_handle_t dev_handle, uint8_t r
// return i2c_master_write_read_device(I2C_MASTER_NUM, device_address, &reg_addr, 1, data, len, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
//ESP_LOGI("I2C", "Reading %d bytes from register 0x%02X", len, reg_addr);

return i2c_master_transmit_receive(dev_handle, &reg_addr, 1, read_buf, len, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
return i2c_master_transmit_receive(dev_handle, &reg_addr, 1, read_buf, len, I2C_DEFAULT_TIMEOUT);
}

/**
Expand All @@ -70,7 +74,7 @@ esp_err_t i2c_bitaxe_register_write_byte(i2c_master_dev_handle_t dev_handle, uin

//return i2c_master_write_to_device(I2C_MASTER_NUM, device_address, write_buf, sizeof(write_buf), I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);

return i2c_master_transmit(dev_handle, write_buf, 2, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
return i2c_master_transmit(dev_handle, write_buf, 2, I2C_DEFAULT_TIMEOUT);
}

/**
Expand All @@ -81,7 +85,7 @@ esp_err_t i2c_bitaxe_register_write_byte(i2c_master_dev_handle_t dev_handle, uin
*/
esp_err_t i2c_bitaxe_register_write_bytes(i2c_master_dev_handle_t dev_handle, uint8_t * data, uint8_t len)
{
return i2c_master_transmit(dev_handle, data, len, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
return i2c_master_transmit(dev_handle, data, len, I2C_DEFAULT_TIMEOUT);
}

/**
Expand All @@ -96,5 +100,5 @@ esp_err_t i2c_bitaxe_register_write_word(i2c_master_dev_handle_t dev_handle, uin

//return i2c_master_write_to_device(I2C_MASTER_NUM, device_address, write_buf, sizeof(write_buf), I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);

return i2c_master_transmit(dev_handle, write_buf, 3, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
return i2c_master_transmit(dev_handle, write_buf, 3, I2C_DEFAULT_TIMEOUT);
}
3 changes: 0 additions & 3 deletions main/i2c_bitaxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include "driver/i2c_master.h"
//#include "driver/i2c.h"

#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_TIMEOUT_MS 1000

esp_err_t i2c_bitaxe_init(void);
esp_err_t i2c_bitaxe_add_device(uint8_t device_address, i2c_master_dev_handle_t * dev_handle);

Expand Down

0 comments on commit 478b01d

Please sign in to comment.