Skip to content

Commit 270b44e

Browse files
change portTICK_RATE_MS to portTICK_PERIOD_MS
DavidAntliff#10
1 parent 7c023f5 commit 270b44e

File tree

5 files changed

+51
-46
lines changed

5 files changed

+51
-46
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build/
22
sdkconfig
33
sdkconfig.old
44

5+
.vscode/

components/esp32-smbus

Submodule esp32-smbus updated 1 file

main/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
set(COMPONENT_SRCDIRS ".")
22
set(COMPONENT_ADD_INCLUDEDIRS ".")
3-
set(COMPONENT_REQUIRES "driver" "esp32-i2c-lcd1602" "esp32-smbus")
4-
register_component()
3+
4+
idf_component_register(SRCS "app_main.c"
5+
"components/esp32-smbus/smbus.c"
6+
"components/esp32-i2c-lcd1602/i2c-lcd1602.c"
7+
INCLUDE_DIRS ".")

main/app_main.c

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,41 @@
3737
#include "sdkconfig.h"
3838
#include "rom/uart.h"
3939

40-
#include "smbus.h"
41-
#include "i2c-lcd1602.h"
40+
#include "components/esp32-smbus/smbus.h"
41+
#include "components/esp32-i2c-lcd1602/i2c-lcd1602.h"
4242

4343
#define TAG "app"
4444

4545
// LCD1602
46-
#define LCD_NUM_ROWS 2
47-
#define LCD_NUM_COLUMNS 32
48-
#define LCD_NUM_VISIBLE_COLUMNS 16
46+
#define LCD_NUM_ROWS 2
47+
#define LCD_NUM_COLUMNS 32
48+
#define LCD_NUM_VISIBLE_COLUMNS 16
4949

5050
// LCD2004
51-
//#define LCD_NUM_ROWS 4
52-
//#define LCD_NUM_COLUMNS 40
53-
//#define LCD_NUM_VISIBLE_COLUMNS 20
51+
// #define LCD_NUM_ROWS 4
52+
// #define LCD_NUM_COLUMNS 40
53+
// #define LCD_NUM_VISIBLE_COLUMNS 20
5454

5555
// 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.
56-
#define USE_STDIN 1
57-
//#undef USE_STDIN
56+
#define USE_STDIN 1
57+
// #undef USE_STDIN
5858

59-
#define I2C_MASTER_NUM I2C_NUM_0
60-
#define I2C_MASTER_TX_BUF_LEN 0 // disabled
61-
#define I2C_MASTER_RX_BUF_LEN 0 // disabled
62-
#define I2C_MASTER_FREQ_HZ 100000
63-
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA
64-
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL
59+
#define I2C_MASTER_NUM I2C_NUM_0
60+
#define I2C_MASTER_TX_BUF_LEN 0 // disabled
61+
#define I2C_MASTER_RX_BUF_LEN 0 // disabled
62+
#define I2C_MASTER_FREQ_HZ 100000
63+
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA
64+
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL
6565

6666
static void i2c_master_init(void)
6767
{
6868
int i2c_master_port = I2C_MASTER_NUM;
6969
i2c_config_t conf;
7070
conf.mode = I2C_MODE_MASTER;
7171
conf.sda_io_num = I2C_MASTER_SDA_IO;
72-
conf.sda_pullup_en = GPIO_PULLUP_DISABLE; // GY-2561 provides 10kΩ pullups
72+
conf.sda_pullup_en = GPIO_PULLUP_DISABLE; // GY-2561 provides 10kΩ pullups
7373
conf.scl_io_num = I2C_MASTER_SCL_IO;
74-
conf.scl_pullup_en = GPIO_PULLUP_DISABLE; // GY-2561 provides 10kΩ pullups
74+
conf.scl_pullup_en = GPIO_PULLUP_DISABLE; // GY-2561 provides 10kΩ pullups
7575
conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
7676
i2c_param_config(i2c_master_port, &conf);
7777
i2c_driver_install(i2c_master_port, conf.mode,
@@ -88,32 +88,33 @@ static uint8_t _wait_for_user(void)
8888
#ifdef USE_STDIN
8989
while (!c)
9090
{
91-
STATUS s = uart_rx_one_char(&c);
92-
if (s == OK) {
93-
printf("%c", c);
94-
}
95-
vTaskDelay(1);
91+
STATUS s = uart_rx_one_char(&c);
92+
if (s == OK)
93+
{
94+
printf("%c", c);
95+
}
96+
vTaskDelay(1);
9697
}
9798
#else
9899
vTaskDelay(1000 / portTICK_RATE_MS);
99100
#endif
100101
return c;
101102
}
102103

103-
void lcd1602_task(void * pvParameter)
104+
void lcd1602_task(void *pvParameter)
104105
{
105106
// Set up I2C
106107
i2c_master_init();
107108
i2c_port_t i2c_num = I2C_MASTER_NUM;
108109
uint8_t address = CONFIG_LCD1602_I2C_ADDRESS;
109110

110111
// Set up the SMBus
111-
smbus_info_t * smbus_info = smbus_malloc();
112+
smbus_info_t *smbus_info = smbus_malloc();
112113
ESP_ERROR_CHECK(smbus_init(smbus_info, i2c_num, address));
113-
ESP_ERROR_CHECK(smbus_set_timeout(smbus_info, 1000 / portTICK_RATE_MS));
114+
ESP_ERROR_CHECK(smbus_set_timeout(smbus_info, 1000 / portTICK_PERIOD_MS));
114115

115116
// Set up the LCD1602 device with backlight off
116-
i2c_lcd1602_info_t * lcd_info = i2c_lcd1602_malloc();
117+
i2c_lcd1602_info_t *lcd_info = i2c_lcd1602_malloc();
117118
ESP_ERROR_CHECK(i2c_lcd1602_init(lcd_info, smbus_info, true,
118119
LCD_NUM_ROWS, LCD_NUM_COLUMNS, LCD_NUM_VISIBLE_COLUMNS));
119120

@@ -148,7 +149,7 @@ void lcd1602_task(void * pvParameter)
148149
i2c_lcd1602_move_cursor(lcd_info, 15, 1);
149150
i2c_lcd1602_write_char(lcd_info, 'C');
150151

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

176177
ESP_LOGI(TAG, "disable blink");
177178
_wait_for_user();
178-
i2c_lcd1602_set_blink(lcd_info, false); // cursor should still be on
179+
i2c_lcd1602_set_blink(lcd_info, false); // cursor should still be on
179180

180181
ESP_LOGI(TAG, "disable cursor");
181182
_wait_for_user();
182183
i2c_lcd1602_set_cursor(lcd_info, false);
183184

184-
ESP_LOGI(TAG, "display alphabet from 0,0"); // should overflow to second line at "ABC..."
185+
ESP_LOGI(TAG, "display alphabet from 0,0"); // should overflow to second line at "ABC..."
185186
_wait_for_user();
186187
i2c_lcd1602_home(lcd_info);
187188
i2c_lcd1602_write_string(lcd_info, "abcdefghijklmnopqrstuvwxyz0123456789.,-+ABCDEFGHIJKLMNOPQRSTUVWXYZ");
@@ -191,7 +192,7 @@ void lcd1602_task(void * pvParameter)
191192
for (int i = 0; i < 8; ++i)
192193
{
193194
i2c_lcd1602_scroll_display_left(lcd_info);
194-
vTaskDelay(200 / portTICK_RATE_MS);
195+
vTaskDelay(200 / portTICK_PERIOD_MS);
195196
}
196197

197198
ESP_LOGI(TAG, "scroll display right 8 places quickly");
@@ -226,7 +227,7 @@ void lcd1602_task(void * pvParameter)
226227
for (int i = 0; i < 5; ++i)
227228
{
228229
i2c_lcd1602_write_char(lcd_info, '>');
229-
vTaskDelay(200 / portTICK_RATE_MS);
230+
vTaskDelay(200 / portTICK_PERIOD_MS);
230231
}
231232

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

241242
ESP_LOGI(TAG, "disable auto-scroll and display +++++");
@@ -244,7 +245,7 @@ void lcd1602_task(void * pvParameter)
244245
for (int i = 0; i < 5; ++i)
245246
{
246247
i2c_lcd1602_write_char(lcd_info, '+');
247-
vTaskDelay(200 / portTICK_RATE_MS);
248+
vTaskDelay(200 / portTICK_PERIOD_MS);
248249
}
249250

250251
ESP_LOGI(TAG, "set left_to_right and display >>>>>");
@@ -253,7 +254,7 @@ void lcd1602_task(void * pvParameter)
253254
for (int i = 0; i < 5; ++i)
254255
{
255256
i2c_lcd1602_write_char(lcd_info, '>');
256-
vTaskDelay(200 / portTICK_RATE_MS);
257+
vTaskDelay(200 / portTICK_PERIOD_MS);
257258
}
258259

259260
ESP_LOGI(TAG, "clear display and disable cursor");
@@ -264,14 +265,14 @@ void lcd1602_task(void * pvParameter)
264265
ESP_LOGI(TAG, "create and display custom characters");
265266
_wait_for_user();
266267
// https://github.com/agnunez/ESP8266-I2C-LCD1602/blob/master/examples/CustomChars/CustomChars.ino
267-
uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
268-
uint8_t note[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
268+
uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
269+
uint8_t note[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
269270
uint8_t clock[8] = {0x0, 0xe, 0x15, 0x17, 0x11, 0xe, 0x0};
270271
uint8_t heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
271-
uint8_t duck[8] = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
272-
uint8_t check[8] = {0x0, 0x1 ,0x3, 0x16, 0x1c, 0x8, 0x0};
272+
uint8_t duck[8] = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
273+
uint8_t check[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
273274
uint8_t cross[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
274-
uint8_t retarrow[8] = { 0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};
275+
uint8_t retarrow[8] = {0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};
275276
i2c_lcd1602_define_char(lcd_info, I2C_LCD1602_INDEX_CUSTOM_0, bell);
276277
i2c_lcd1602_define_char(lcd_info, I2C_LCD1602_INDEX_CUSTOM_1, note);
277278
i2c_lcd1602_define_char(lcd_info, I2C_LCD1602_INDEX_CUSTOM_2, clock);
@@ -320,7 +321,7 @@ void lcd1602_task(void * pvParameter)
320321
while (1)
321322
{
322323
i2c_lcd1602_write_char(lcd_info, c);
323-
vTaskDelay(100 / portTICK_RATE_MS);
324+
vTaskDelay(100 / portTICK_PERIOD_MS);
324325
ESP_LOGD(TAG, "col %d, row %d, char 0x%02x", col, row, c);
325326
++c;
326327
++col;
@@ -342,4 +343,4 @@ void lcd1602_task(void * pvParameter)
342343
void app_main()
343344
{
344345
xTaskCreate(&lcd1602_task, "lcd1602_task", 4096, NULL, 5, NULL);
345-
}
346+
}

0 commit comments

Comments
 (0)