Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit194a5454431bb9eb9e3da3165fe138b823be96ee (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-05-22 12:50:53 +0300
Committer
 Syndamia <kamen@syndamia.com>
2024-05-22 12:50:53 +0300
Files37401b25c47bcabbe443a4d4063bfc41be7289b2
uni-projects-194a5454431bb9eb9e3da3165fe138b823be96ee.tar
uni-projects-194a5454431bb9eb9e3da3165fe138b823be96ee.tar.gz
uni-projects-194a5454431bb9eb9e3da3165fe138b823be96ee.zip
Parentfec8cd4dc9f19794cff5fa831f92d6be3ce0ce84 (diff)
[iot/goam] Fixed display logic and started work on a font
diff --git a/Year 3/Internet of things/goam/main/CMakeLists.txt b/Year 3/Internet of things/goam/main/CMakeLists.txt
index 5b77e8c..5c20816 100644
--- a/Year 3/Internet of things/goam/main/CMakeLists.txt
+++ b/Year 3/Internet of things/goam/main/CMakeLists.txt
@@ -6,5 +6,6 @@ idf_component_register(SRCS "main.c"
"webserver.c"
"spiffs.c"
"nvs.c"
+ "ibm-vga-8x16.c"
EMBED_FILES "../webserver-src/index.html"
INCLUDE_DIRS "")
diff --git a/Year 3/Internet of things/goam/main/display.c b/Year 3/Internet of things/goam/main/display.c
index e7435fe..5c367c3 100644
--- a/Year 3/Internet of things/goam/main/display.c
+++ b/Year 3/Internet of things/goam/main/display.c
@@ -22,33 +22,31 @@ static void i2c_init() {
.scl_io_num = SCL_IO_PIN,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
- .master.clk_speed = 400000, // 4kHz; has to be at least 3.85kHz
+ .master.clk_speed = 400000, // 400kHz; has to be at least 385kHz
};
i2c_param_config(I2C_NUM_0, &conf);
i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
- i2c_set_start_timing(I2C_NUM_0, 10, 10);
+ /* i2c_set_start_timing(I2C_NUM_0, 10, 10); */
}
/*
* I2C commands
*/
-static void send_primitive(const unsigned char* data, size_t size, bool blankout) {
+enum DATA_TYPE {
+ CMD_STREAM = 0x00,
+ DATA_STREAM = 0x40,
+};
+
+static void send(enum DATA_TYPE type, 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));
// Slave address
ESP_ERROR_CHECK(i2c_master_write_byte(i2c_handle, 0b01111000, true));
- // Turn display off
- if (blankout) {
- ESP_ERROR_CHECK(i2c_master_write_byte(i2c_handle, 0xAE, true));
- }
+ ESP_ERROR_CHECK(i2c_master_write_byte(i2c_handle, type, true));
// Control/data bytes
ESP_ERROR_CHECK(i2c_master_write(i2c_handle, data, size, true));
- // Turn display on
- if (blankout) {
- ESP_ERROR_CHECK(i2c_master_write_byte(i2c_handle, 0xAF, true));
- }
// "The write mode will be finished when a stop condition is applied"
ESP_ERROR_CHECK(i2c_master_stop(i2c_handle));
@@ -56,42 +54,81 @@ static void send_primitive(const unsigned char* data, size_t size, bool blankout
i2c_cmd_link_delete(i2c_handle);
}
-static void send(const unsigned char* data, size_t size) {
- send_primitive(data, size, true);
-}
-
/*
* Public interface
*/
-static const unsigned char startup[] = { 0x00, 0x8D, 0x14, 0xAF };
+static const unsigned char startup[] = { 0x8D, 0x14, 0xAF };
const unsigned char pattern[] = {
- 0x20, // horizontal address mode
+ 0x20, // vertical address mode
0b00,
0x21, // set column start/end
0, 127,
0x22, //set page start/end
0, 7,
- 0x40, 0b101010, 0xFF
};
void display_init() {
i2c_init();
- send_primitive(startup, 4, false);
- send_primitive(pattern, 8, false);
+ send(CMD_STREAM, startup, 4);
+ send(CMD_STREAM, pattern, sizeof(pattern));
ESP_LOGI(TAG, "Initialized display");
}
void display_invertion(enum Inversion inv_byte) {
- send((const unsigned char*)&inv_byte, 1);
+ send(CMD_STREAM, (const unsigned char*)&inv_byte, 1);
+}
+
+// This is better than an include, because we can define our font
+// with compile flags
+extern const unsigned bitpixel_char_height;
+extern const unsigned bitpixel_char_width;
+extern const uint8_t* bitpixel_chars[256];
+
+static const size_t line_width = 16;
+/* static const size_t lines = 64 / bitpixel_char_height; */
+
+unsigned char out_str[1 + 16 * 8] = { };
+
+void display_print(const char* str) {
+ int outI = 1;
+ for (int pixelRow = 0; pixelRow < bitpixel_char_height; pixelRow++) {
+ for (int i = 0; i < line_width; i++) {
+ out_str[outI++] = bitpixel_chars[1][pixelRow];
+ }
+ }
}
const unsigned char off = 0xAE, on = 0xAF;
void display_example() {
// MUST be separated, for some reason
- send_primitive(&off, 1, false);
- send_primitive(pattern + 8, 3, false);
- send_primitive(&on, 1, false);
+ /* send(CMD_STREAM, &off, 1); */
+ /* display_print(""); */
+ for (int i = 0; i < 16; i++) {
+ out_str[i] = bitpixel_chars[1][(i * 2) % 16];
+ }
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ for (int i = 0; i < 16; i++) {
+ out_str[i] = bitpixel_chars[1][(i * 2+1) % 16];
+ }
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ send(DATA_STREAM, out_str, 16);
+ /* send(out_str, sizeof(out_str)); */
+ /* send(pattern + 8, 3); */
+ /* send(CMD_STREAM, &on, 1); */
}
diff --git a/Year 3/Internet of things/goam/main/ibm-vga-8x16.c b/Year 3/Internet of things/goam/main/ibm-vga-8x16.c
new file mode 100644
index 0000000..201310e
--- /dev/null
+++ b/Year 3/Internet of things/goam/main/ibm-vga-8x16.c
@@ -0,0 +1,39 @@
+#include <inttypes.h>
+
+// Sizes in bytes, aka 8 pixels
+const unsigned bitpixel_char_width = 8;
+const unsigned bitpixel_char_height = 16;
+
+#define COL(col) (0b ## col) & 0xFF, (0b ## col) >> 8,
+
+const uint8_t space[16] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+};
+
+
+const uint8_t A[16] = {
+ COL(0000111111100000)
+ COL(0000111111110000)
+ COL(0000000010011000)
+ COL(0000000010001100)
+ COL(0000000010011000)
+ COL(0000111111110000)
+ COL(0000111111100000)
+ COL(0000000000000000)
+};
+
+/* const uint8_t A[] = { */
+/* 0b11100000, 0b00001111, */
+/* 0b11110000, 0b00001111, */
+/* 0b10011000, 0b00000000, */
+/* 0b10001100, 0b00000000, */
+/* 0b10011000, 0b00000000, */
+/* 0b11110000, 0b00001111, */
+/* 0b11100000, 0b00001111, */
+/* 0b00000000, 0b00000000, */
+/* }; */
+
+const uint8_t* bitpixel_chars[256] = {
+ space, A
+};