Browse Source

added working display test firmware

Toby Chui 6 months ago
parent
commit
65424a4f6d

BIN
PCB/v1/Gerber_Reflow-Hotplate_PCB_Lab-bench-Power-Supply_2024-08-10.zip


File diff suppressed because it is too large
+ 40 - 0
PCB/v1/PCB_PCB_Lab-bench-Power-Supply_2024-08-10.json


+ 24 - 3
firmware/display_test/display_test.ino

@@ -76,6 +76,27 @@ void clearScreen(){
   }
 }
 
+void nextRow(){
+
+}
+
+void lightScreen(){
+  for (uint8_t i = 0; i < 8; i++) {
+    I2CWriteCommand(0xB0 + i); // Set page address
+    I2CWriteCommand(0x00); // Set lower column address
+    I2CWriteCommand(0x10); // Set higher column address
+    for (uint8_t j = 0; j < 128; j++) {
+      if (j%8==0){
+        I2CWriteData(0xFF);
+      }else{
+        I2CWriteData(0x80);
+      }
+    }
+  }
+}
+
+void drawRectangle(uint8_t, uint8_t, uint8_t, uint8_t, bool);
+
 void setup() {
   // Initialize I2C pins
   scl_pin = 30; // P3.0
@@ -86,8 +107,8 @@ void setup() {
 
 void loop() {
   // Clear the display
- clearScreen();
-
-
+  clearScreen();
+  delay(1000);
+  lightScreen();
   delay(1000);
 }

+ 43 - 0
firmware/display_test/gfx.ino

@@ -0,0 +1,43 @@
+void drawPixel(uint8_t x, uint8_t y, bool on) {
+  uint8_t page = y / 8;
+  uint8_t bit = y % 8;
+  uint8_t column = x;
+
+  // Set the page and column address
+  I2CWriteCommand(0xB0 + page);         // Set page address
+  I2CWriteCommand(0x00 | (column & 0x0F));  // Set lower column address
+  I2CWriteCommand(0x10 | (column >> 4));   // Set higher column address
+
+  // Read the current data
+  uint8_t data;
+  I2CStart();
+  I2CSend(OLED_I2C_ADDRESS << 1);      // I2C address + Write bit
+  I2CSend(0x00);                       // Co = 0, D/C# = 0 (Command mode)
+  I2CSend(0x00);                       // Dummy command to read data
+  I2CStop();
+  
+  // Assume data is read correctly, here data should be handled
+  // Modify data based on the `on` parameter
+  if (on) {
+    data |= (1 << bit); // Set the pixel bit
+  } else {
+    data &= ~(1 << bit); // Clear the pixel bit
+  }
+
+  // Write the modified data back to the display
+  I2CStart();
+  I2CSend(OLED_I2C_ADDRESS << 1);      // I2C address + Write bit
+  I2CSend(0x40);                       // Co = 0, D/C# = 1 (Data mode)
+  I2CSend(data);                       // Write the modified data
+  I2CStop();
+}
+
+void drawRectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, bool fill) {
+  for (uint8_t i = 0; i < width; i++) {
+    for (uint8_t j = 0; j < height; j++) {
+      if (fill || (i == 0 || i == width - 1 || j == 0 || j == height - 1)) {
+        drawPixel(x + i, y + j, true); // Draw the pixel
+      }
+    }
+  }
+}

Some files were not shown because too many files changed in this diff