Initial Demo OS

This commit is contained in:
dark98
2026-09-03 00:46:04 +01:00
commit 1491821e96
45 changed files with 2908 additions and 0 deletions
+129
View File
@@ -0,0 +1,129 @@
#ifndef OLED_DISPLAY_H
#define OLED_DISPLAY_H
#include <stdint.h>
#include <stdbool.h>
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Hardware Specifications for ABrobot ESP32-C3 0.42" OLED */
#define OLED_I2C_PORT I2C_NUM_0
#define OLED_I2C_ADDR 0x3C
#define OLED_PIN_SDA GPIO_NUM_5
#define OLED_PIN_SCL GPIO_NUM_6
#define OLED_I2C_FREQ_HZ 400000
/* Display Resolution */
#define OLED_WIDTH 72
#define OLED_HEIGHT 40
#define OLED_PAGES 5 /* (40 / 8) */
#define OLED_BUFFER_SIZE (OLED_WIDTH * OLED_PAGES)
/* Controller Column Offset (SSD1306/SH1106 internal RAM mapping) */
#ifndef OLED_COLUMN_OFFSET
#define OLED_COLUMN_OFFSET 28 /* Common offset is 28 (or 26-30 depending on batch) */
#endif
/* Color modes */
#define OLED_COLOR_BLACK 0
#define OLED_COLOR_WHITE 1
#define OLED_COLOR_INVERT 2
/**
* @brief Initialize I2C driver and SSD1306/SH1106 OLED display.
*
* @param sda GPIO number for SDA (default: GPIO_NUM_5)
* @param scl GPIO number for SCL (default: GPIO_NUM_6)
* @param col_offset Internal column offset (default: OLED_COLUMN_OFFSET)
* @return esp_err_t ESP_OK on success
*/
esp_err_t oled_init(gpio_num_t sda, gpio_num_t scl, uint8_t col_offset);
/**
* @brief Clear the frame buffer (all black).
*/
void oled_clear(void);
/**
* @brief Fill the entire frame buffer (all white).
*/
void oled_fill(void);
/**
* @brief Push the frame buffer to the OLED display over I2C.
*
* @return esp_err_t ESP_OK on success
*/
esp_err_t oled_update(void);
/**
* @brief Set display contrast.
*
* @param contrast Value 0 to 255
* @return esp_err_t ESP_OK on success
*/
esp_err_t oled_set_contrast(uint8_t contrast);
/**
* @brief Invert the display colors in hardware.
*
* @param invert true for inverted, false for normal
* @return esp_err_t ESP_OK on success
*/
esp_err_t oled_invert(bool invert);
/**
* @brief Draw a single pixel in the frame buffer.
*
* @param x X coordinate (0 to 71)
* @param y Y coordinate (0 to 39)
* @param color OLED_COLOR_BLACK, OLED_COLOR_WHITE, or OLED_COLOR_INVERT
*/
void oled_draw_pixel(int16_t x, int16_t y, uint8_t color);
/**
* @brief Draw a line using Bresenham's algorithm.
*/
void oled_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color);
/**
* @brief Draw an unfilled rectangle.
*/
void oled_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
/**
* @brief Draw a filled rectangle.
*/
void oled_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
/**
* @brief Draw a single character using the 5x7 font.
*
* @param x X position (top-left)
* @param y Y position (top-left)
* @param c ASCII character
* @param color OLED_COLOR_WHITE or OLED_COLOR_BLACK
*/
void oled_draw_char(int16_t x, int16_t y, char c, uint8_t color);
/**
* @brief Draw a text string using the 5x7 font.
*
* @param x X position (top-left)
* @param y Y position (top-left)
* @param str Null-terminated string
* @param color OLED_COLOR_WHITE or OLED_COLOR_BLACK
*/
void oled_draw_string(int16_t x, int16_t y, const char *str, uint8_t color);
#ifdef __cplusplus
}
#endif
#endif // OLED_DISPLAY_H