single repo

This commit is contained in:
Adolfo Reyna
2026-01-01 13:33:51 -05:00
parent 8b56187ef1
commit bc8ae91eba
334 changed files with 124529 additions and 2 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
add_library(ssd1306_textRenderer
TextRenderer.cpp
5x8_font.h
8x8_font.h
12x16_font.h
16x32_font.h
)
target_link_libraries(ssd1306_textRenderer
hardware_i2c
pico_stdlib
)

View File

@@ -0,0 +1,57 @@
#include "TextRenderer.h"
namespace pico_ssd1306 {
void drawText(pico_ssd1306::SSD1306 *ssd1306, const unsigned char *font, const char *text, uint8_t anchor_x,
uint8_t anchor_y, WriteMode mode, Rotation rotation) {
if(!ssd1306 || !font || !text) return;
uint8_t font_width = font[0];
uint16_t n = 0;
while (text[n] != '\0') {
switch (rotation) {
case Rotation::deg0:
drawChar(ssd1306, font, text[n], anchor_x + (n * font_width), anchor_y, mode, rotation);
break;
case Rotation::deg90:
drawChar(ssd1306, font, text[n], anchor_x, anchor_y + (n * font_width), mode, rotation);
break;
}
n++;
}
}
void drawChar(pico_ssd1306::SSD1306 *ssd1306, const unsigned char *font, char c, uint8_t anchor_x, uint8_t anchor_y,
WriteMode mode, Rotation rotation) {
if(!ssd1306 || !font || c < 32) return;
uint8_t font_width = font[0];
uint8_t font_height = font[1];
uint16_t seek = (c - 32) * (font_width * font_height) / 8 + 2;
uint8_t b_seek = 0;
for (uint8_t x = 0; x < font_width; x++) {
for (uint8_t y = 0; y < font_height; y++) {
if (font[seek] >> b_seek & 0b00000001) {
switch (rotation) {
case Rotation::deg0:
ssd1306->setPixel(x + anchor_x, y + anchor_y, mode);
break;
case Rotation::deg90:
ssd1306->setPixel(-y + anchor_x + font_height, x + anchor_y, mode);
break;
}
}
b_seek++;
if (b_seek == 8) {
b_seek = 0;
seek++;
}
}
}
}
}

View File

@@ -0,0 +1,40 @@
#ifndef SSD1306_TEXTRENDERER_H
#define SSD1306_TEXTRENDERER_H
#include "../ssd1306.h"
#include "5x8_font.h"
#include "8x8_font.h"
#include "12x16_font.h"
#include "16x32_font.h"
namespace pico_ssd1306{
/// \enum pico_ssd1306::Rotation
enum class Rotation{
/// deg0 - means no rotation
deg0,
/// deg 90 - means 90 deg rotation
deg90,
};
/// \brief Draws a single glyph on the screen
/// \param ssd1306 - pointer to a SSD1306 object aka initialised display
/// \param font - pointer to a font data array
/// \param c - char to be drawn
/// \param anchor_x, anchor_y - coordinates setting where to put the glyph
/// \param mode - mode describes setting behavior. See WriteMode doc for more information
/// \param rotation - either rotates the char by 90 deg or leaves it unrotated
void drawChar(pico_ssd1306::SSD1306 *ssd1306, const unsigned char * font, char c, uint8_t anchor_x, uint8_t anchor_y, WriteMode mode = WriteMode::ADD, Rotation rotation = Rotation::deg0);
/// \brief Draws text on screen
/// \param ssd1306 - pointer to a SSD1306 object aka initialised display
/// \param font - pointer to a font data array
/// \param text - text to be drawn
/// \param anchor_x, anchor_y - coordinates setting where to put the text
/// \param mode - mode describes setting behavior. See WriteMode doc for more information
/// \param rotation - either rotates the text by 90 deg or leaves it unrotated
void drawText(pico_ssd1306::SSD1306 *ssd1306, const unsigned char * font, const char * text, uint8_t anchor_x, uint8_t anchor_y, WriteMode mode = WriteMode::ADD, Rotation rotation = Rotation::deg0);
}
#endif //SSD1306_TEXTRENDERER_H

View File

@@ -0,0 +1,60 @@
# Text Renderer Module
## This module provides functions for drawing chars and text on ssd1306 displays
## 1. Importing
```c++
#include "pico-ssd1306/textRenderer/TextRenderer.h"
```
note that core library and hardware_i2c library's need to be imported to use this library so follow steps from section 1
of [readme.md](../readme.md)
## 2. Differences from core library
Calling functions from modules is different from core lib. You can't just do ```object.drawText(...``` since modules don't
actually extend the SSD1306 class. You need to provide module functions with a pointer to a display object. So the first
argument of every module draw function is a pointer to a display.
To see this more clearly here is an example:
```c++
// Create a new display object
pico_ssd1306::SSD1306 display = pico_ssd1306::SSD1306(I2C_PORT, 0x3D, pico_ssd1306::Size::W128xH64);
// Draw some text
// Notice how we first pass the address of display object to the function
drawText(&display, font_12x16, "TEST text", 0 ,0);
```
## 3. Available fonts
This module comes with 4 fonts to choose from
* font_5x8 - 5px wide, 8px high font
* font_8x8 - 8px wide, 8px high font
* font_12x16 - 12px wide, 16px high font
* font_16x32 - 16px wide, 32px high font
Basic fonts support basic ASCII set chars (32-127), if you want to extended ASCII define
```c++
#define SSD1306_ASCII_FULL
```
at the top of your file
#### Note that using extended ASCII range increases project size
### Creating your own fonts
doing so is not that hard
a font is just a large array of bytes
```c++
const unsigned char font_16x32[] = {
...
};
```
the first 2 bytes are font's width and height
```c++
const unsigned char font_16x32[] = {
0x10, 0x20, // font width, height
...
};
```
then followed by char data for ascii characters 32 - 126
Unlike bitmap images in the core library, fonts are scanned right to left, top to bottom
## All functions are documented [here](https://ssd1306.harbys.me)