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

View File

@@ -0,0 +1,43 @@
#include "FrameBuffer.h"
FrameBuffer::FrameBuffer() {
this->buffer = new unsigned char[FRAMEBUFFER_SIZE];
}
FrameBuffer::~FrameBuffer() {
delete[] this->buffer;
}
void FrameBuffer::byteOR(int n, unsigned char byte) {
// return if index outside 0 - buffer length - 1
if (n > (FRAMEBUFFER_SIZE-1)) return;
this->buffer[n] |= byte;
}
void FrameBuffer::byteAND(int n, unsigned char byte) {
// return if index outside 0 - buffer length - 1
if (n > (FRAMEBUFFER_SIZE-1)) return;
this->buffer[n] &= byte;
}
void FrameBuffer::byteXOR(int n, unsigned char byte) {
// return if index outside 0 - buffer length - 1
if (n > (FRAMEBUFFER_SIZE-1)) return;
this->buffer[n] ^= byte;
}
void FrameBuffer::setBuffer(unsigned char *new_buffer) {
// free buffer memory to prevent memory leak
delete[] this->buffer;
this->buffer = new_buffer;
}
void FrameBuffer::clear() {
//zeroes out the buffer via memset function from string library
memset(this->buffer, 0, FRAMEBUFFER_SIZE);
}
unsigned char *FrameBuffer::get() {
return this->buffer;
}

View File

@@ -0,0 +1,54 @@
#ifndef SSD1306_FRAMEBUFFER_H
#define SSD1306_FRAMEBUFFER_H
#include <string.h>
/// \brief Set frame buffer to 1024 bytes, witch is 128*64 / 8
///
/// For 128x32 displays it's still 1024 due to how memory mapping works on ssd1306.
/// This is explained in readme.md
#define FRAMEBUFFER_SIZE 1024
/// \brief Framebuffer class contains a pointer to buffer and functions for interacting with it
class FrameBuffer {
unsigned char * buffer;
public:
/// Constructs frame buffer and allocates memory for buffer
FrameBuffer();
/// Destroys frame buffer and frees buffer memory
~FrameBuffer();
/// \brief Performs OR logical operation on selected and provided byte
///
/// ex. if byte in buffer at position n is 0b10001111 and provided byte is 0b11110000 the buffer at position n becomes 0b11111111
/// \param n - byte offset in buffer array to work on
/// \param byte - provided byte to make operation
void byteOR(int n, unsigned char byte);
/// \brief Performs AND logical operation on selected and provided byte
///
/// ex. if byte in buffer at position n is 0b10001111 and provided byte is 0b11110000 the buffer at position n becomes 0b10000000
/// \param n - byte offset in buffer array to work on
/// \param byte - provided byte to make operation
void byteAND(int n, unsigned char byte);
/// \brief Performs XOR logical operation on selected and provided byte
///
/// ex. if byte in buffer at position n is 0b10001111 and provided byte is 0b11110000 the buffer at position n becomes 0b0111111
/// \param n - byte offset in buffer array to work on
/// \param byte - provided byte to make operation
void byteXOR(int n, unsigned char byte);
/// Replaces pointer with one pointing to a different buffer
void setBuffer(unsigned char * new_buffer);
/// Zeroes out the buffer aka set buffer to all 0
void clear();
/// Returns a pointer to the buffer
unsigned char * get();
};
#endif //SSD1306_FRAMEBUFFER_H