Browse Source

Better u8g2 error handling and tuning to flags for perf

ugv_io
Alex Mikhalev 6 years ago
parent
commit
e97e1228be
  1. 26
      main/u8g2_esp32_hal.c

26
main/u8g2_esp32_hal.c

@ -10,7 +10,7 @@
#include "u8g2_esp32_hal.h" #include "u8g2_esp32_hal.h"
static const char * TAG = "u8g2_hal"; static const char * TAG = "u8g2_hal";
static const unsigned int I2C_TIMEOUT_MS = 1000; static const unsigned int I2C_TIMEOUT_MS = 10;
static spi_device_handle_t handle_spi; // SPI handle. static spi_device_handle_t handle_spi; // SPI handle.
static i2c_cmd_handle_t handle_i2c; // I2C handle. static i2c_cmd_handle_t handle_i2c; // I2C handle.
@ -19,10 +19,11 @@ static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data.
#undef ESP_ERROR_CHECK #undef ESP_ERROR_CHECK
#define ESP_ERROR_CHECK(x) \ #define ESP_ERROR_CHECK(x) \
do { \ do { \
esp_err_t rc = (x); \ esp_err_t _rc = (x); \
if (rc != ESP_OK) { \ if (_rc != ESP_OK) { \
ESP_LOGE("err", "esp_err_t = %d", rc); \ const char *_error_name = esp_err_to_name(_rc); \
assert(0 && #x); \ ESP_LOGE(TAG, "%s failed: %s (%d)", #x, _error_name, _rc); \
return 0; \
} \ } \
} while (0); } while (0);
@ -136,8 +137,11 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
ESP_LOGD(TAG, "i2c_param_config %d", conf.mode); ESP_LOGD(TAG, "i2c_param_config %d", conf.mode);
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf)); ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf));
ESP_LOGD(TAG, "i2c_driver_install %d", I2C_MASTER_NUM); ESP_LOGD(TAG, "i2c_driver_install %d", I2C_MASTER_NUM);
ESP_ERROR_CHECK( ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_NUM,
i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0)); conf.mode,
I2C_MASTER_RX_BUF_DISABLE,
I2C_MASTER_TX_BUF_DISABLE,
ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1));
break; break;
} }
@ -167,7 +171,7 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
} }
case U8X8_MSG_BYTE_END_TRANSFER: { case U8X8_MSG_BYTE_END_TRANSFER: {
// ESP_LOGV(TAG, "End I2C transfer. txbuf len: %d", txbuf_ptr - txbuf); ESP_LOGV(TAG, "End I2C transfer. txbuf len: %d", txbuf_ptr - txbuf);
// ESP_LOG_BUFFER_HEXDUMP(TAG, txbuf, txbuf_ptr - txbuf, ESP_LOG_VERBOSE); // ESP_LOG_BUFFER_HEXDUMP(TAG, txbuf, txbuf_ptr - txbuf, ESP_LOG_VERBOSE);
ESP_ERROR_CHECK(i2c_master_write(handle_i2c, txbuf, txbuf_ptr - txbuf, ACK_CHECK_EN)); ESP_ERROR_CHECK(i2c_master_write(handle_i2c, txbuf, txbuf_ptr - txbuf, ACK_CHECK_EN));
ESP_ERROR_CHECK(i2c_master_stop(handle_i2c)); ESP_ERROR_CHECK(i2c_master_stop(handle_i2c));
@ -175,8 +179,9 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
i2c_cmd_link_delete(handle_i2c); i2c_cmd_link_delete(handle_i2c);
break; break;
} }
default: return 0;
} }
return 0; return 1;
} // u8g2_esp32_i2c_byte_cb } // u8g2_esp32_i2c_byte_cb
/* /*
@ -243,6 +248,7 @@ uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int,
// Delay for the number of milliseconds passed in through arg_int. // Delay for the number of milliseconds passed in through arg_int.
case U8X8_MSG_DELAY_MILLI: vTaskDelay(arg_int / portTICK_PERIOD_MS); break; case U8X8_MSG_DELAY_MILLI: vTaskDelay(arg_int / portTICK_PERIOD_MS); break;
default: return 0;
} }
return 0; return 1;
} // u8g2_esp32_gpio_and_delay_cb } // u8g2_esp32_gpio_and_delay_cb
Loading…
Cancel
Save