|
|
@ -12,19 +12,19 @@ |
|
|
|
static const char * TAG = "u8g2_hal"; |
|
|
|
static const char * TAG = "u8g2_hal"; |
|
|
|
static const unsigned int I2C_TIMEOUT_MS = 10; |
|
|
|
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.
|
|
|
|
static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data.
|
|
|
|
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) { \ |
|
|
|
const char *_error_name = esp_err_to_name(_rc); \ |
|
|
|
const char *_error_name = esp_err_to_name(_rc); \ |
|
|
|
ESP_LOGE(TAG, "%s failed: %s (%d)", #x, _error_name, _rc); \ |
|
|
|
ESP_LOGE(TAG, "%s failed: %s (%d)", #x, _error_name, _rc); \ |
|
|
|
return 0; \ |
|
|
|
return 0; \ |
|
|
|
} \ |
|
|
|
} \ |
|
|
|
} while (0); |
|
|
|
} while (0); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -32,219 +32,229 @@ static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param) { |
|
|
|
void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param) { |
|
|
|
u8g2_esp32_hal = u8g2_esp32_hal_param; |
|
|
|
u8g2_esp32_hal = u8g2_esp32_hal_param; |
|
|
|
} // u8g2_esp32_hal_init
|
|
|
|
} // u8g2_esp32_hal_init
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* HAL callback function as prescribed by the U8G2 library. This callback is |
|
|
|
* HAL callback function as prescribed by the U8G2 library. This callback is |
|
|
|
* invoked to handle SPI communications. |
|
|
|
* invoked to handle SPI communications. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { |
|
|
|
uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, |
|
|
|
ESP_LOGV(TAG, "spi_byte_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg, arg_int, arg_ptr); |
|
|
|
void *arg_ptr) { |
|
|
|
|
|
|
|
ESP_LOGV(TAG, "spi_byte_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", |
|
|
|
|
|
|
|
msg, arg_int, arg_ptr); |
|
|
|
switch (msg) { |
|
|
|
switch (msg) { |
|
|
|
case U8X8_MSG_BYTE_SET_DC: |
|
|
|
case U8X8_MSG_BYTE_SET_DC: |
|
|
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
gpio_set_level(u8g2_esp32_hal.dc, arg_int); |
|
|
|
gpio_set_level(u8g2_esp32_hal.dc, arg_int); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case U8X8_MSG_BYTE_INIT: { |
|
|
|
|
|
|
|
if (u8g2_esp32_hal.clk == U8G2_ESP32_HAL_UNDEFINED || |
|
|
|
|
|
|
|
u8g2_esp32_hal.mosi == U8G2_ESP32_HAL_UNDEFINED || |
|
|
|
|
|
|
|
u8g2_esp32_hal.cs == U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spi_bus_config_t bus_config; |
|
|
|
|
|
|
|
memset(&bus_config, 0, sizeof(spi_bus_config_t)); |
|
|
|
|
|
|
|
bus_config.sclk_io_num = u8g2_esp32_hal.clk; // CLK
|
|
|
|
|
|
|
|
bus_config.mosi_io_num = u8g2_esp32_hal.mosi; // MOSI
|
|
|
|
|
|
|
|
bus_config.miso_io_num = -1; // MISO
|
|
|
|
|
|
|
|
bus_config.quadwp_io_num = -1; // Not used
|
|
|
|
|
|
|
|
bus_config.quadhd_io_num = -1; // Not used
|
|
|
|
|
|
|
|
// ESP_LOGI(TAG, "... Initializing bus.");
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &bus_config, 1)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spi_device_interface_config_t dev_config; |
|
|
|
|
|
|
|
dev_config.address_bits = 0; |
|
|
|
|
|
|
|
dev_config.command_bits = 0; |
|
|
|
|
|
|
|
dev_config.dummy_bits = 0; |
|
|
|
|
|
|
|
dev_config.mode = 0; |
|
|
|
|
|
|
|
dev_config.duty_cycle_pos = 0; |
|
|
|
|
|
|
|
dev_config.cs_ena_posttrans = 0; |
|
|
|
|
|
|
|
dev_config.cs_ena_pretrans = 0; |
|
|
|
|
|
|
|
dev_config.clock_speed_hz = 10000; |
|
|
|
|
|
|
|
dev_config.spics_io_num = u8g2_esp32_hal.cs; |
|
|
|
|
|
|
|
dev_config.flags = 0; |
|
|
|
|
|
|
|
dev_config.queue_size = 200; |
|
|
|
|
|
|
|
dev_config.pre_cb = NULL; |
|
|
|
|
|
|
|
dev_config.post_cb = NULL; |
|
|
|
|
|
|
|
// ESP_LOGI(TAG, "... Adding device bus.");
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle_spi)); |
|
|
|
|
|
|
|
|
|
|
|
case U8X8_MSG_BYTE_INIT: { |
|
|
|
|
|
|
|
if (u8g2_esp32_hal.clk == U8G2_ESP32_HAL_UNDEFINED || u8g2_esp32_hal.mosi == U8G2_ESP32_HAL_UNDEFINED || |
|
|
|
|
|
|
|
u8g2_esp32_hal.cs == U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
spi_bus_config_t bus_config; |
|
|
|
case U8X8_MSG_BYTE_SEND: { |
|
|
|
memset(&bus_config, 0, sizeof(spi_bus_config_t)); |
|
|
|
spi_transaction_t trans_desc; |
|
|
|
bus_config.sclk_io_num = u8g2_esp32_hal.clk; // CLK
|
|
|
|
trans_desc.addr = 0; |
|
|
|
bus_config.mosi_io_num = u8g2_esp32_hal.mosi; // MOSI
|
|
|
|
trans_desc.cmd = 0; |
|
|
|
bus_config.miso_io_num = -1; // MISO
|
|
|
|
trans_desc.flags = 0; |
|
|
|
bus_config.quadwp_io_num = -1; // Not used
|
|
|
|
trans_desc.length = 8 * arg_int; // Number of bits NOT number of bytes.
|
|
|
|
bus_config.quadhd_io_num = -1; // Not used
|
|
|
|
trans_desc.rxlength = 0; |
|
|
|
// ESP_LOGI(TAG, "... Initializing bus.");
|
|
|
|
trans_desc.tx_buffer = arg_ptr; |
|
|
|
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &bus_config, 1)); |
|
|
|
trans_desc.rx_buffer = NULL; |
|
|
|
|
|
|
|
|
|
|
|
spi_device_interface_config_t dev_config; |
|
|
|
|
|
|
|
dev_config.address_bits = 0; |
|
|
|
|
|
|
|
dev_config.command_bits = 0; |
|
|
|
|
|
|
|
dev_config.dummy_bits = 0; |
|
|
|
|
|
|
|
dev_config.mode = 0; |
|
|
|
|
|
|
|
dev_config.duty_cycle_pos = 0; |
|
|
|
|
|
|
|
dev_config.cs_ena_posttrans = 0; |
|
|
|
|
|
|
|
dev_config.cs_ena_pretrans = 0; |
|
|
|
|
|
|
|
dev_config.clock_speed_hz = 10000; |
|
|
|
|
|
|
|
dev_config.spics_io_num = u8g2_esp32_hal.cs; |
|
|
|
|
|
|
|
dev_config.flags = 0; |
|
|
|
|
|
|
|
dev_config.queue_size = 200; |
|
|
|
|
|
|
|
dev_config.pre_cb = NULL; |
|
|
|
|
|
|
|
dev_config.post_cb = NULL; |
|
|
|
|
|
|
|
// ESP_LOGI(TAG, "... Adding device bus.");
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle_spi)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case U8X8_MSG_BYTE_SEND: { |
|
|
|
// ESP_LOGI(TAG, "... Transmitting %d bytes.", arg_int);
|
|
|
|
spi_transaction_t trans_desc; |
|
|
|
ESP_ERROR_CHECK(spi_device_transmit(handle_spi, &trans_desc)); |
|
|
|
trans_desc.addr = 0; |
|
|
|
break; |
|
|
|
trans_desc.cmd = 0; |
|
|
|
} |
|
|
|
trans_desc.flags = 0; |
|
|
|
|
|
|
|
trans_desc.length = 8 * arg_int; // Number of bits NOT number of bytes.
|
|
|
|
|
|
|
|
trans_desc.rxlength = 0; |
|
|
|
|
|
|
|
trans_desc.tx_buffer = arg_ptr; |
|
|
|
|
|
|
|
trans_desc.rx_buffer = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ESP_LOGI(TAG, "... Transmitting %d bytes.", arg_int);
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(spi_device_transmit(handle_spi, &trans_desc)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} // u8g2_esp32_spi_byte_cb
|
|
|
|
} // u8g2_esp32_spi_byte_cb
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* HAL callback function as prescribed by the U8G2 library. This callback is |
|
|
|
* HAL callback function as prescribed by the U8G2 library. This callback is |
|
|
|
* invoked to handle I2C communications. |
|
|
|
* invoked to handle I2C communications. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { |
|
|
|
uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, |
|
|
|
|
|
|
|
void *arg_ptr) { |
|
|
|
#define TXBUF_SIZE 32 |
|
|
|
#define TXBUF_SIZE 32 |
|
|
|
static uint8_t txbuf[TXBUF_SIZE]; |
|
|
|
static uint8_t txbuf[TXBUF_SIZE]; |
|
|
|
static uint8_t *txbuf_ptr; |
|
|
|
static uint8_t *txbuf_ptr; |
|
|
|
// ESP_LOGV(TAG, "i2c_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg,
|
|
|
|
// ESP_LOGV(TAG, "i2c_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg,
|
|
|
|
// arg_int, arg_ptr);
|
|
|
|
// arg_int, arg_ptr);
|
|
|
|
switch (msg) { |
|
|
|
switch (msg) { |
|
|
|
case U8X8_MSG_BYTE_SET_DC: { |
|
|
|
case U8X8_MSG_BYTE_SET_DC: { |
|
|
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
gpio_set_level(u8g2_esp32_hal.dc, arg_int); |
|
|
|
gpio_set_level(u8g2_esp32_hal.dc, arg_int); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case U8X8_MSG_BYTE_INIT: { |
|
|
|
case U8X8_MSG_BYTE_INIT: { |
|
|
|
if (u8g2_esp32_hal.sda == U8G2_ESP32_HAL_UNDEFINED || u8g2_esp32_hal.scl == U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.sda == U8G2_ESP32_HAL_UNDEFINED || |
|
|
|
|
|
|
|
u8g2_esp32_hal.scl == U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i2c_config_t conf; |
|
|
|
|
|
|
|
conf.mode = I2C_MODE_MASTER; |
|
|
|
|
|
|
|
conf.sda_io_num = u8g2_esp32_hal.sda; |
|
|
|
|
|
|
|
conf.sda_pullup_en = GPIO_PULLUP_ENABLE; |
|
|
|
|
|
|
|
conf.scl_io_num = u8g2_esp32_hal.scl; |
|
|
|
|
|
|
|
conf.scl_pullup_en = GPIO_PULLUP_ENABLE; |
|
|
|
|
|
|
|
ESP_LOGV(TAG, "clk_speed %d", I2C_MASTER_FREQ_HZ); |
|
|
|
|
|
|
|
conf.master.clk_speed = I2C_MASTER_FREQ_HZ; |
|
|
|
|
|
|
|
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf)); |
|
|
|
|
|
|
|
ESP_ERROR_CHECK(i2c_driver_install( |
|
|
|
|
|
|
|
I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, |
|
|
|
|
|
|
|
I2C_MASTER_TX_BUF_DISABLE, |
|
|
|
|
|
|
|
ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
i2c_config_t conf; |
|
|
|
case U8X8_MSG_BYTE_SEND: { |
|
|
|
conf.mode = I2C_MODE_MASTER; |
|
|
|
uint8_t *data_ptr = (uint8_t *)arg_ptr; |
|
|
|
conf.sda_io_num = u8g2_esp32_hal.sda; |
|
|
|
size_t data_len = (size_t)arg_int; |
|
|
|
conf.sda_pullup_en = GPIO_PULLUP_ENABLE; |
|
|
|
// ESP_LOGV(TAG, "U8x8_MSG_BYTE_SEND. txbuf len: %d", txbuf_ptr - txbuf);
|
|
|
|
conf.scl_io_num = u8g2_esp32_hal.scl; |
|
|
|
// ESP_LOG_BUFFER_HEXDUMP(TAG, data_ptr, data_len, ESP_LOG_VERBOSE);
|
|
|
|
conf.scl_pullup_en = GPIO_PULLUP_ENABLE; |
|
|
|
|
|
|
|
ESP_LOGV(TAG, "clk_speed %d", I2C_MASTER_FREQ_HZ); |
|
|
|
|
|
|
|
conf.master.clk_speed = I2C_MASTER_FREQ_HZ; |
|
|
|
|
|
|
|
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf)); |
|
|
|
|
|
|
|
ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_NUM, |
|
|
|
|
|
|
|
conf.mode, |
|
|
|
|
|
|
|
I2C_MASTER_RX_BUF_DISABLE, |
|
|
|
|
|
|
|
I2C_MASTER_TX_BUF_DISABLE, |
|
|
|
|
|
|
|
ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case U8X8_MSG_BYTE_SEND: { |
|
|
|
|
|
|
|
uint8_t *data_ptr = (uint8_t *)arg_ptr; |
|
|
|
|
|
|
|
size_t data_len = (size_t)arg_int; |
|
|
|
|
|
|
|
// ESP_LOGV(TAG, "U8x8_MSG_BYTE_SEND. txbuf len: %d", txbuf_ptr - txbuf);
|
|
|
|
|
|
|
|
// ESP_LOG_BUFFER_HEXDUMP(TAG, data_ptr, data_len, ESP_LOG_VERBOSE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (txbuf_ptr + data_len >= txbuf_ptr + TXBUF_SIZE) { |
|
|
|
if (txbuf_ptr + data_len >= txbuf_ptr + TXBUF_SIZE) { |
|
|
|
ESP_LOGE(TAG, "txbuf overflow"); |
|
|
|
ESP_LOGE(TAG, "txbuf overflow"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
memcpy(txbuf_ptr, data_ptr, data_len); |
|
|
|
|
|
|
|
txbuf_ptr += data_len; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
memcpy(txbuf_ptr, data_ptr, data_len); |
|
|
|
|
|
|
|
txbuf_ptr += data_len; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case U8X8_MSG_BYTE_START_TRANSFER: { |
|
|
|
case U8X8_MSG_BYTE_START_TRANSFER: { |
|
|
|
uint8_t i2c_address = u8x8_GetI2CAddress(u8x8); |
|
|
|
uint8_t i2c_address = u8x8_GetI2CAddress(u8x8); |
|
|
|
handle_i2c = i2c_cmd_link_create(); |
|
|
|
handle_i2c = i2c_cmd_link_create(); |
|
|
|
// ESP_LOGV(TAG, "Start I2C transfer to %02X.", i2c_address >> 1);
|
|
|
|
// ESP_LOGV(TAG, "Start I2C transfer to %02X.", i2c_address >> 1);
|
|
|
|
ESP_ERROR_CHECK(i2c_master_start(handle_i2c)); |
|
|
|
ESP_ERROR_CHECK(i2c_master_start(handle_i2c)); |
|
|
|
ESP_ERROR_CHECK(i2c_master_write_byte(handle_i2c, i2c_address | I2C_MASTER_WRITE, ACK_CHECK_EN)); |
|
|
|
ESP_ERROR_CHECK(i2c_master_write_byte( |
|
|
|
txbuf_ptr = txbuf; |
|
|
|
handle_i2c, i2c_address | I2C_MASTER_WRITE, ACK_CHECK_EN)); |
|
|
|
break; |
|
|
|
txbuf_ptr = txbuf; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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( |
|
|
|
ESP_ERROR_CHECK(i2c_master_stop(handle_i2c)); |
|
|
|
i2c_master_write(handle_i2c, txbuf, txbuf_ptr - txbuf, ACK_CHECK_EN)); |
|
|
|
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_MASTER_NUM, handle_i2c, I2C_TIMEOUT_MS / portTICK_RATE_MS)); |
|
|
|
ESP_ERROR_CHECK(i2c_master_stop(handle_i2c)); |
|
|
|
i2c_cmd_link_delete(handle_i2c); |
|
|
|
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_MASTER_NUM, handle_i2c, |
|
|
|
break; |
|
|
|
I2C_TIMEOUT_MS / portTICK_RATE_MS)); |
|
|
|
} |
|
|
|
i2c_cmd_link_delete(handle_i2c); |
|
|
|
default: return 0; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
default: return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} // u8g2_esp32_i2c_byte_cb
|
|
|
|
} // u8g2_esp32_i2c_byte_cb
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* HAL callback function as prescribed by the U8G2 library. This callback is |
|
|
|
* HAL callback function as prescribed by the U8G2 library. This callback is |
|
|
|
* invoked to handle callbacks for GPIO and delay functions. |
|
|
|
* invoked to handle callbacks for GPIO and delay functions. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { |
|
|
|
uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, |
|
|
|
ESP_LOGV(TAG, "gpio_and_delay_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg, arg_int, arg_ptr); |
|
|
|
void *arg_ptr) { |
|
|
|
|
|
|
|
ESP_LOGV(TAG, |
|
|
|
|
|
|
|
"gpio_and_delay_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", |
|
|
|
|
|
|
|
msg, arg_int, arg_ptr); |
|
|
|
|
|
|
|
|
|
|
|
switch (msg) { |
|
|
|
switch (msg) { |
|
|
|
// Initialize the GPIO and DELAY HAL functions. If the pins for DC and
|
|
|
|
// Initialize the GPIO and DELAY HAL functions. If the pins for DC and
|
|
|
|
// RESET have been specified then we define those pins as GPIO outputs.
|
|
|
|
// RESET have been specified then we define those pins as GPIO outputs.
|
|
|
|
case U8X8_MSG_GPIO_AND_DELAY_INIT: { |
|
|
|
case U8X8_MSG_GPIO_AND_DELAY_INIT: { |
|
|
|
uint64_t bitmask = 0; |
|
|
|
uint64_t bitmask = 0; |
|
|
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.dc); |
|
|
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.dc); |
|
|
|
} |
|
|
|
} |
|
|
|
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.reset); |
|
|
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.reset); |
|
|
|
} |
|
|
|
} |
|
|
|
if (u8g2_esp32_hal.cs != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.cs != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.cs); |
|
|
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (bitmask == 0) { |
|
|
|
if (bitmask == 0) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
gpio_config_t gpioConfig; |
|
|
|
|
|
|
|
gpioConfig.pin_bit_mask = bitmask; |
|
|
|
|
|
|
|
gpioConfig.mode = GPIO_MODE_OUTPUT; |
|
|
|
|
|
|
|
gpioConfig.pull_up_en = GPIO_PULLUP_DISABLE; |
|
|
|
|
|
|
|
gpioConfig.pull_down_en = GPIO_PULLDOWN_ENABLE; |
|
|
|
|
|
|
|
gpioConfig.intr_type = GPIO_INTR_DISABLE; |
|
|
|
|
|
|
|
gpio_config(&gpioConfig); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
gpio_config_t gpioConfig; |
|
|
|
|
|
|
|
gpioConfig.pin_bit_mask = bitmask; |
|
|
|
|
|
|
|
gpioConfig.mode = GPIO_MODE_OUTPUT; |
|
|
|
|
|
|
|
gpioConfig.pull_up_en = GPIO_PULLUP_DISABLE; |
|
|
|
|
|
|
|
gpioConfig.pull_down_en = GPIO_PULLDOWN_ENABLE; |
|
|
|
|
|
|
|
gpioConfig.intr_type = GPIO_INTR_DISABLE; |
|
|
|
|
|
|
|
gpio_config(&gpioConfig); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the GPIO reset pin to the value passed in through arg_int.
|
|
|
|
// Set the GPIO reset pin to the value passed in through arg_int.
|
|
|
|
case U8X8_MSG_GPIO_RESET: |
|
|
|
case U8X8_MSG_GPIO_RESET: |
|
|
|
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
gpio_set_level(u8g2_esp32_hal.reset, arg_int); |
|
|
|
gpio_set_level(u8g2_esp32_hal.reset, arg_int); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
// Set the GPIO client select pin to the value passed in through arg_int.
|
|
|
|
// Set the GPIO client select pin to the value passed in through arg_int.
|
|
|
|
case U8X8_MSG_GPIO_CS: |
|
|
|
case U8X8_MSG_GPIO_CS: |
|
|
|
if (u8g2_esp32_hal.cs != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.cs != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
gpio_set_level(u8g2_esp32_hal.cs, arg_int); |
|
|
|
gpio_set_level(u8g2_esp32_hal.cs, arg_int); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
// Set the Software I²C pin to the value passed in through arg_int.
|
|
|
|
// Set the Software I²C pin to the value passed in through arg_int.
|
|
|
|
case U8X8_MSG_GPIO_I2C_CLOCK: |
|
|
|
case U8X8_MSG_GPIO_I2C_CLOCK: |
|
|
|
if (u8g2_esp32_hal.scl != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.scl != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
gpio_set_level(u8g2_esp32_hal.scl, arg_int); |
|
|
|
gpio_set_level(u8g2_esp32_hal.scl, arg_int); |
|
|
|
// printf("%c",(arg_int==1?'C':'c'));
|
|
|
|
// printf("%c",(arg_int==1?'C':'c'));
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
// Set the Software I²C pin to the value passed in through arg_int.
|
|
|
|
// Set the Software I²C pin to the value passed in through arg_int.
|
|
|
|
case U8X8_MSG_GPIO_I2C_DATA: |
|
|
|
case U8X8_MSG_GPIO_I2C_DATA: |
|
|
|
if (u8g2_esp32_hal.sda != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
if (u8g2_esp32_hal.sda != U8G2_ESP32_HAL_UNDEFINED) { |
|
|
|
gpio_set_level(u8g2_esp32_hal.sda, arg_int); |
|
|
|
gpio_set_level(u8g2_esp32_hal.sda, arg_int); |
|
|
|
// printf("%c",(arg_int==1?'D':'d'));
|
|
|
|
// printf("%c",(arg_int==1?'D':'d'));
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
default: return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} // u8g2_esp32_gpio_and_delay_cb
|
|
|
|
} // u8g2_esp32_gpio_and_delay_cb
|