abstract for external display lib

This commit is contained in:
DashyFox 2023-09-24 22:26:05 +03:00
parent 9a3e34c78b
commit 34c6a104a2
4 changed files with 124 additions and 45 deletions

View File

@ -1,8 +1,9 @@
#include <Adafruit_SSD1306.h> #include <Arduino.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels //#include <avr/iom328.h>
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); #include "implement/Display__Adafruit_SSD1306.h"
Display_Adafruit_SSD1306 screen(128, 32, Display::Ori_HORIZONTAL);
#define pin_Data 5 // yellow #define pin_Data 5 // yellow
#define pin_CLK_inside 6 // orange #define pin_CLK_inside 6 // orange
@ -21,6 +22,7 @@ volatile uint16_t frec = 42; // частота MusicRing
volatile uint16_t t_period_takts = F_CPU / 8 / LED_count / frec; volatile uint16_t t_period_takts = F_CPU / 8 / LED_count / frec;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
pinMode(pin_Data, OUTPUT); pinMode(pin_Data, OUTPUT);
@ -29,45 +31,45 @@ void setup() {
pinMode(pin_RESET, OUTPUT); pinMode(pin_RESET, OUTPUT);
pinMode(pin_OutputEnable, OUTPUT); pinMode(pin_OutputEnable, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); screen.begin();
display.clearDisplay();
// 'Text1', 128x32px // 'Text1', 128x32px
static const uint8_t DashyFox [] PROGMEM = { static const uint8_t DashyFox [] PROGMEM = {
0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, /* 0 */// 1 8 | 9 16| 17 24| 25 32| 33 40| 41 48| 49 56| 57 64| 65 72| 73 80| 81 88| 89 96| 97 104| 105 112| 113 120| 121 128|
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* 1 */ 0b11111111, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, 0b11111111,
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, /* 2 */ 0b11111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111111,
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, /* 3 */ 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, /* 4 */ 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, /* 5 */ 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001111,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, /* 6 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, /* 7 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111,
0xc0, 0x07, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, /* 8 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011,
0x80, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, /* 9 */ 0b11000000, 0b00000111, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011,
0x80, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, /* 10 */ 0b10000000, 0b00000111, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b01110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x1c, 0x0f, 0x60, 0xfc, 0x7f, 0x03, 0x9c, 0x30, 0x01, 0xe0, 0xc3, 0x00, 0x00, 0x01, /* 11 */ 0b10000000, 0b00000111, 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b01110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x0e, 0x1f, 0xe1, 0xfc, 0x7f, 0x87, 0xbc, 0x30, 0x07, 0xf0, 0xe7, 0x00, 0x00, 0x01, /* 12 */ 0b10000000, 0b00000110, 0b00011100, 0b00001111, 0b01100000, 0b11111100, 0b01111111, 0b00000011, 0b10011100, 0b00110000, 0b00000001, 0b11100000, 0b11000011, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x0e, 0x3f, 0xe1, 0xfc, 0x7f, 0xc7, 0xbc, 0x3f, 0x87, 0xf8, 0xe7, 0x00, 0x00, 0x01, /* 13 */ 0b10000000, 0b00000110, 0b00001110, 0b00011111, 0b11100001, 0b11111100, 0b01111111, 0b10000111, 0b10111100, 0b00110000, 0b00000111, 0b11110000, 0b11100111, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x0e, 0x30, 0xe3, 0x8c, 0x71, 0xc3, 0x0c, 0x3f, 0xce, 0x38, 0x7e, 0x00, 0x00, 0x01, /* 14 */ 0b10000000, 0b00000110, 0b00001110, 0b00111111, 0b11100001, 0b11111100, 0b01111111, 0b11000111, 0b10111100, 0b00111111, 0b10000111, 0b11111000, 0b11100111, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x0e, 0x70, 0xe1, 0xe0, 0x70, 0xc7, 0x0c, 0x3f, 0x8e, 0x18, 0x3c, 0x00, 0x00, 0x01, /* 15 */ 0b10000000, 0b00000110, 0b00001110, 0b00110000, 0b11100011, 0b10001100, 0b01110001, 0b11000011, 0b00001100, 0b00111111, 0b11001110, 0b00111000, 0b01111110, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x0e, 0x70, 0xe1, 0xf8, 0x70, 0xc7, 0x0c, 0x30, 0x0c, 0x18, 0x3c, 0x00, 0x00, 0x01, /* 16 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100001, 0b11100000, 0b01110000, 0b11000111, 0b00001100, 0b00111111, 0b10001110, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x0e, 0x70, 0xe0, 0xfc, 0x70, 0xc7, 0x0c, 0x30, 0x0c, 0x18, 0x3c, 0x00, 0x00, 0x01, /* 17 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100001, 0b11111000, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x0c, 0x70, 0xe0, 0x1c, 0x70, 0xc7, 0x0c, 0x30, 0x0c, 0x18, 0x3c, 0x00, 0x00, 0x01, /* 18 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100000, 0b11111100, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x06, 0x1c, 0x31, 0xe3, 0x8c, 0x71, 0xc3, 0x0c, 0x30, 0x0e, 0x38, 0x7e, 0x00, 0x00, 0x01, /* 19 */ 0b10000000, 0b00000110, 0b00001100, 0b01110000, 0b11100000, 0b00011100, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x07, 0xf8, 0x3f, 0xf3, 0xfc, 0x79, 0xe3, 0xfc, 0x30, 0x07, 0xf8, 0xe7, 0x00, 0x00, 0x01, /* 20 */ 0b10000000, 0b00000110, 0b00011100, 0b00110001, 0b11100011, 0b10001100, 0b01110001, 0b11000011, 0b00001100, 0b00110000, 0b00001110, 0b00111000, 0b01111110, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x07, 0xf0, 0x1f, 0xf1, 0xfc, 0x79, 0xe1, 0xfc, 0x30, 0x07, 0xf0, 0xe7, 0x00, 0x00, 0x01, /* 21 */ 0b10000000, 0b00000111, 0b11111000, 0b00111111, 0b11110011, 0b11111100, 0b01111001, 0b11100011, 0b11111100, 0b00110000, 0b00000111, 0b11111000, 0b11100111, 0b00000000, 0b00000000, 0b00000001,
0x80, 0x07, 0xe0, 0x0f, 0x60, 0xf8, 0x71, 0xc1, 0xfc, 0x30, 0x01, 0xe0, 0xc3, 0x00, 0x00, 0x01, /* 22 */ 0b10000000, 0b00000111, 0b11110000, 0b00011111, 0b11110001, 0b11111100, 0b01111001, 0b11100001, 0b11111100, 0b00110000, 0b00000111, 0b11110000, 0b11100111, 0b00000000, 0b00000000, 0b00000001,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0x03, /* 23 */ 0b10000000, 0b00000111, 0b11100000, 0b00001111, 0b01100000, 0b11111000, 0b01110001, 0b11000001, 0b11111100, 0b00110000, 0b00000001, 0b11100000, 0b11000011, 0b00000000, 0b00000000, 0b00000001,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xbc, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x03, /* 24 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, 0b11110000, 0b00000011,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0x07, /* 25 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b10111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01111111, 0b11111000, 0b00000011,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, /* 26 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, 0b11110000, 0b00000111,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, /* 27 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111,
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, /* 28 */ 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001111,
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, /* 29 */ 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* 30 */ 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111,
0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff /* 31 */ 0b11111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111111,
/* 32 */ 0b11111111, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, 0b11111111
}; };
display.drawBitmap(0, 0, DashyFox, 128, 32, WHITE); screen.adafruit->drawBitmap(0, 0, DashyFox, 128, 32, WHITE);
display.display(); screen.adafruit->display();
digitalWrite(pin_RESET, HIGH); digitalWrite(pin_RESET, HIGH);
@ -118,17 +120,16 @@ ISR(TIMER1_COMPA_vect) {
void loop() { void loop() {
static uint32_t tmr; static uint32_t tmr;
static uint8_t arr [6] = { 0x3f>>1, 0xf0 ,0x7f>>3, 0xf8, 0x3f>>1, 0xf0 }; static uint8_t arr[6] = { 0x3f >> 1, 0xf0 ,0x7f >> 3, 0xf8, 0x3f >> 1, 0xf0 };
static uint8_t arr2 [6]= { 0 }; static uint8_t arr2[6] = { 0 };
static bool f = false; static bool f = false;
if (millis() - tmr > 350) { if (millis() - tmr > 350) {
display.drawBitmap(105, 23, arr, 16, 3, f); screen.adafruit->drawBitmap(105, 23, arr, 16, 3, f);
display.display(); screen.adafruit->display();
tmr = millis(); tmr = millis();
f = !f; f = !f;
} }
// delayMicroseconds(1000000 / 42 / LED_count); // Если больше 2х перейти на micros
} }
void point_ini(uint8_t width) { void point_ini(uint8_t width) {

View File

@ -0,0 +1,26 @@
#pragma once
#include "../modules/Display.h"
#include <Adafruit_SSD1306.h>
class Display_Adafruit_SSD1306 : public Display {
public:
Adafruit_SSD1306* adafruit;
Display_Adafruit_SSD1306(uint16_t width, uint16_t height, uint16_t orientation) : Display(width, height, orientation) {
adafruit = new Adafruit_SSD1306(width, height, &Wire, -1);
};
void begin() { //TODO: Добавить поддержку других режимов
adafruit->begin(SSD1306_SWITCHCAPVCC, 0x3C);
adafruit->clearDisplay();
}
void writePixel() override {
}
~Display_Adafruit_SSD1306() {
delete adafruit;
}
};

35
modules/Display.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#include <Arduino.h>
class Display {
public:
enum ScreenOrientation {
Ori_0 = 0,
Ori_90 = 90,
Ori_180 = 180,
Ori_270 = 270,
Ori_HORIZONTAL = 0,
Ori_VERTICAL = 90,
Ori_HORIZONTAL_FLIP = 180,
Ori_VERTICAL_FLIP = 270,
};
protected:
struct ScreenParam {
uint16_t width, height, orientation;
} screen;
uint8_t* buffer;
public:
Display(uint16_t width, uint16_t height, uint16_t orientation) {
screen.width = width;
screen.height = height;
screen.orientation = orientation;
buffer = new uint8_t[((width * height) / 8)];
}
virtual void writePixel() {};
};

17
modules/LED_Ring.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <Arduino.h>
struct LED_Ring_PINOUT {
uint8_t Data, CLK_inside, CLK_outside, RESET, OutputEnable;
};
class LED_Ring {
public:
LED_Ring_PINOUT pinOut;
uint16_t ledCount;
uint16_t updateFrec;
LED_Ring(uint16_t _ledCount, LED_Ring_PINOUT _pinOut) : ledCount(_ledCount), pinOut(_pinOut) {};
};