Skip to content

change portTICK_RATE_MS to portTICK_PERIOD_MS #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/
sdkconfig
sdkconfig.old

.vscode/
6 changes: 4 additions & 2 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
set(COMPONENT_SRCDIRS ".")
set(COMPONENT_ADD_INCLUDEDIRS ".")

register_component()

idf_component_register(SRCS "app_main.c"
"components/esp32-smbus/smbus.c"
"components/esp32-i2c-lcd1602/i2c-lcd1602.c"
INCLUDE_DIRS ".")
83 changes: 42 additions & 41 deletions main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,41 @@
#include "sdkconfig.h"
#include "rom/uart.h"

#include "smbus.h"
#include "i2c-lcd1602.h"
#include "components/esp32-smbus/smbus.h"
#include "components/esp32-i2c-lcd1602/i2c-lcd1602.h"

#define TAG "app"

// LCD1602
#define LCD_NUM_ROWS 2
#define LCD_NUM_COLUMNS 32
#define LCD_NUM_VISIBLE_COLUMNS 16
#define LCD_NUM_ROWS 2
#define LCD_NUM_COLUMNS 32
#define LCD_NUM_VISIBLE_COLUMNS 16

// LCD2004
//#define LCD_NUM_ROWS 4
//#define LCD_NUM_COLUMNS 40
//#define LCD_NUM_VISIBLE_COLUMNS 20
// #define LCD_NUM_ROWS 4
// #define LCD_NUM_COLUMNS 40
// #define LCD_NUM_VISIBLE_COLUMNS 20

// Undefine USE_STDIN if no stdin is available (e.g. no USB UART) - a fixed delay will occur instead of a wait for a keypress.
#define USE_STDIN 1
//#undef USE_STDIN
#define USE_STDIN 1
// #undef USE_STDIN

#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_TX_BUF_LEN 0 // disabled
#define I2C_MASTER_RX_BUF_LEN 0 // disabled
#define I2C_MASTER_FREQ_HZ 100000
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL
#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_TX_BUF_LEN 0 // disabled
#define I2C_MASTER_RX_BUF_LEN 0 // disabled
#define I2C_MASTER_FREQ_HZ 100000
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL

static void i2c_master_init(void)
{
int i2c_master_port = I2C_MASTER_NUM;
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = I2C_MASTER_SDA_IO;
conf.sda_pullup_en = GPIO_PULLUP_DISABLE; // GY-2561 provides 10kΩ pullups
conf.sda_pullup_en = GPIO_PULLUP_DISABLE; // GY-2561 provides 10kΩ pullups
conf.scl_io_num = I2C_MASTER_SCL_IO;
conf.scl_pullup_en = GPIO_PULLUP_DISABLE; // GY-2561 provides 10kΩ pullups
conf.scl_pullup_en = GPIO_PULLUP_DISABLE; // GY-2561 provides 10kΩ pullups
conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
i2c_param_config(i2c_master_port, &conf);
i2c_driver_install(i2c_master_port, conf.mode,
Expand All @@ -88,32 +88,33 @@ static uint8_t _wait_for_user(void)
#ifdef USE_STDIN
while (!c)
{
STATUS s = uart_rx_one_char(&c);
if (s == OK) {
printf("%c", c);
}
vTaskDelay(1);
STATUS s = uart_rx_one_char(&c);
if (s == OK)
{
printf("%c", c);
}
vTaskDelay(1);
}
#else
vTaskDelay(1000 / portTICK_RATE_MS);
#endif
return c;
}

void lcd1602_task(void * pvParameter)
void lcd1602_task(void *pvParameter)
{
// Set up I2C
i2c_master_init();
i2c_port_t i2c_num = I2C_MASTER_NUM;
uint8_t address = CONFIG_LCD1602_I2C_ADDRESS;

// Set up the SMBus
smbus_info_t * smbus_info = smbus_malloc();
smbus_info_t *smbus_info = smbus_malloc();
ESP_ERROR_CHECK(smbus_init(smbus_info, i2c_num, address));
ESP_ERROR_CHECK(smbus_set_timeout(smbus_info, 1000 / portTICK_RATE_MS));
ESP_ERROR_CHECK(smbus_set_timeout(smbus_info, 1000 / portTICK_PERIOD_MS));

// Set up the LCD1602 device with backlight off
i2c_lcd1602_info_t * lcd_info = i2c_lcd1602_malloc();
i2c_lcd1602_info_t *lcd_info = i2c_lcd1602_malloc();
ESP_ERROR_CHECK(i2c_lcd1602_init(lcd_info, smbus_info, true,
LCD_NUM_ROWS, LCD_NUM_COLUMNS, LCD_NUM_VISIBLE_COLUMNS));

Expand Down Expand Up @@ -148,7 +149,7 @@ void lcd1602_task(void * pvParameter)
i2c_lcd1602_move_cursor(lcd_info, 15, 1);
i2c_lcd1602_write_char(lcd_info, 'C');

ESP_LOGI(TAG, "move to 0,1 and blink"); // cursor should still be on
ESP_LOGI(TAG, "move to 0,1 and blink"); // cursor should still be on
_wait_for_user();
i2c_lcd1602_move_cursor(lcd_info, 0, 1);
i2c_lcd1602_set_blink(lcd_info, true);
Expand All @@ -175,13 +176,13 @@ void lcd1602_task(void * pvParameter)

ESP_LOGI(TAG, "disable blink");
_wait_for_user();
i2c_lcd1602_set_blink(lcd_info, false); // cursor should still be on
i2c_lcd1602_set_blink(lcd_info, false); // cursor should still be on

ESP_LOGI(TAG, "disable cursor");
_wait_for_user();
i2c_lcd1602_set_cursor(lcd_info, false);

ESP_LOGI(TAG, "display alphabet from 0,0"); // should overflow to second line at "ABC..."
ESP_LOGI(TAG, "display alphabet from 0,0"); // should overflow to second line at "ABC..."
_wait_for_user();
i2c_lcd1602_home(lcd_info);
i2c_lcd1602_write_string(lcd_info, "abcdefghijklmnopqrstuvwxyz0123456789.,-+ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Expand All @@ -191,7 +192,7 @@ void lcd1602_task(void * pvParameter)
for (int i = 0; i < 8; ++i)
{
i2c_lcd1602_scroll_display_left(lcd_info);
vTaskDelay(200 / portTICK_RATE_MS);
vTaskDelay(200 / portTICK_PERIOD_MS);
}

ESP_LOGI(TAG, "scroll display right 8 places quickly");
Expand Down Expand Up @@ -226,7 +227,7 @@ void lcd1602_task(void * pvParameter)
for (int i = 0; i < 5; ++i)
{
i2c_lcd1602_write_char(lcd_info, '>');
vTaskDelay(200 / portTICK_RATE_MS);
vTaskDelay(200 / portTICK_PERIOD_MS);
}

ESP_LOGI(TAG, "change address counter to decrement (right to left) and display <<<<<");
Expand All @@ -235,7 +236,7 @@ void lcd1602_task(void * pvParameter)
for (int i = 0; i < 5; ++i)
{
i2c_lcd1602_write_char(lcd_info, '<');
vTaskDelay(200 / portTICK_RATE_MS);
vTaskDelay(200 / portTICK_PERIOD_MS);
}

ESP_LOGI(TAG, "disable auto-scroll and display +++++");
Expand All @@ -244,7 +245,7 @@ void lcd1602_task(void * pvParameter)
for (int i = 0; i < 5; ++i)
{
i2c_lcd1602_write_char(lcd_info, '+');
vTaskDelay(200 / portTICK_RATE_MS);
vTaskDelay(200 / portTICK_PERIOD_MS);
}

ESP_LOGI(TAG, "set left_to_right and display >>>>>");
Expand All @@ -253,7 +254,7 @@ void lcd1602_task(void * pvParameter)
for (int i = 0; i < 5; ++i)
{
i2c_lcd1602_write_char(lcd_info, '>');
vTaskDelay(200 / portTICK_RATE_MS);
vTaskDelay(200 / portTICK_PERIOD_MS);
}

ESP_LOGI(TAG, "clear display and disable cursor");
Expand All @@ -264,14 +265,14 @@ void lcd1602_task(void * pvParameter)
ESP_LOGI(TAG, "create and display custom characters");
_wait_for_user();
// https://github.com/agnunez/ESP8266-I2C-LCD1602/blob/master/examples/CustomChars/CustomChars.ino
uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
uint8_t note[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
uint8_t note[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
uint8_t clock[8] = {0x0, 0xe, 0x15, 0x17, 0x11, 0xe, 0x0};
uint8_t heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
uint8_t duck[8] = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t check[8] = {0x0, 0x1 ,0x3, 0x16, 0x1c, 0x8, 0x0};
uint8_t duck[8] = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t check[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
uint8_t cross[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
uint8_t retarrow[8] = { 0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};
uint8_t retarrow[8] = {0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};
i2c_lcd1602_define_char(lcd_info, I2C_LCD1602_INDEX_CUSTOM_0, bell);
i2c_lcd1602_define_char(lcd_info, I2C_LCD1602_INDEX_CUSTOM_1, note);
i2c_lcd1602_define_char(lcd_info, I2C_LCD1602_INDEX_CUSTOM_2, clock);
Expand Down Expand Up @@ -320,7 +321,7 @@ void lcd1602_task(void * pvParameter)
while (1)
{
i2c_lcd1602_write_char(lcd_info, c);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
ESP_LOGD(TAG, "col %d, row %d, char 0x%02x", col, row, c);
++c;
++col;
Expand Down
Loading