diff options
| Commit | 211264c14c1ae0b8f9b7f671a0c646035b1557f3 (patch) | |
|---|---|---|
| Author | 2024-05-06 15:55:42 +0300 | |
| Committer | 2024-05-06 15:55:42 +0300 | |
| Files | a63b5171d9603bbabb56fe1111864969fdad761b | |
| uni-projects-211264c14c1ae0b8f9b7f671a0c646035b1557f3.tar uni-projects-211264c14c1ae0b8f9b7f671a0c646035b1557f3.tar.gz uni-projects-211264c14c1ae0b8f9b7f671a0c646035b1557f3.zip | ||
| Parent | f4078a73fd5d27cebcc77cd6d2297286e3515564 (diff) | |
[iot/goam] Made sending data more generic and implemented invert display function
3 files changed, 23 insertions, 4 deletions
| -rw-r--r-- | Year 3/Internet of things/goam/main/display.c | 18 | ||||
| -rw-r--r-- | Year 3/Internet of things/goam/main/display.h | 5 | ||||
| -rw-r--r-- | Year 3/Internet of things/goam/main/main.c | 4 |
diff --git a/Year 3/Internet of things/goam/main/display.c b/Year 3/Internet of things/goam/main/display.c index 7a77910..668721e 100644 --- a/Year 3/Internet of things/goam/main/display.c +++ b/Year 3/Internet of things/goam/main/display.c @@ -1,9 +1,12 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "esp_log.h" #include "driver/i2c.h" #include "display.h" +static const char* TAG = "display"; + #define SCL_IO_PIN 19 #define SDA_IO_PIN 18 #define MASTER_FREQUENCY CONFIG_I2C_MASTER_FREQUENCY @@ -22,18 +25,25 @@ static void i2c_init() { i2c_set_start_timing(I2C_NUM_0, 10, 10); } -static void i2c_send() { +static void i2c_send(const unsigned char* data, size_t size) { i2c_cmd_handle_t i2c_handle = i2c_cmd_link_create(); ESP_ERROR_CHECK(i2c_master_start(i2c_handle)); ESP_ERROR_CHECK(i2c_master_write_byte(i2c_handle, 0b01111000, true)); - char data[] = { 0x00, 0x8D, 0x14, 0xAF, 0xA7 }; - ESP_ERROR_CHECK(i2c_master_write(i2c_handle, (const unsigned char*)data, sizeof(data), true)); + ESP_ERROR_CHECK(i2c_master_write(i2c_handle, data, size, true)); ESP_ERROR_CHECK(i2c_master_stop(i2c_handle)); ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_NUM_0, i2c_handle, 1000)); i2c_cmd_link_delete(i2c_handle); } +static const unsigned char startup[] = { 0x00, 0x8D, 0x14, 0xAF }; + void display_init() { i2c_init(); - i2c_send(); + i2c_send(startup, 4); + ESP_LOGI(TAG, "Initialized display successfully."); +} + +void display_invertion(enum Inversion inv_byte) { + const unsigned char data[] = { 0xAE, inv_byte, 0xAF }; + i2c_send(&data, 3); } diff --git a/Year 3/Internet of things/goam/main/display.h b/Year 3/Internet of things/goam/main/display.h index d796bd7..8053ff7 100644 --- a/Year 3/Internet of things/goam/main/display.h +++ b/Year 3/Internet of things/goam/main/display.h @@ -1,3 +1,8 @@ #pragma once void display_init(); +enum Inversion { + NORMAL = 0xA6, + INVERSE = 0xA7 +}; +void display_invertion(enum Inversion inv_byte); diff --git a/Year 3/Internet of things/goam/main/main.c b/Year 3/Internet of things/goam/main/main.c index 232bfdc..e7d8414 100644 --- a/Year 3/Internet of things/goam/main/main.c +++ b/Year 3/Internet of things/goam/main/main.c @@ -71,6 +71,10 @@ void app_main(void) for (int i = 0; true; i++) { /* ptc06_reset(); */ /* printf("%d seconds, %d\n", i, gpio_get_level(GPIO_INPUT_CAMERA)); */ + + display_invertion(INVERSE); + vTaskDelay(1000 / portTICK_PERIOD_MS); + display_invertion(NORMAL); vTaskDelay(1000 / portTICK_PERIOD_MS); } |
