Skip to content

Commit

Permalink
v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGyver committed Jul 17, 2021
1 parent fe6000b commit b2d09d9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ void loop() {
- v0.5 (09.05.2021) - добавлена поддержка SPI и SSH1106 (только буфер)! gnd-vcc-sck-data-rst-dc-cs

- v1.0 - релиз
- v1.1 - улучшен перенос строк (не убирает первый символ просто так)
- v1.2 - переделан FastIO

<a id="feedback"></a>
## Баги и обратная связь
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=GyverOLED
version=1.0.1
version=1.2
author=AlexGyver <[email protected]>
maintainer=AlexGyver <[email protected]>
sentence=Fast and light library for SSD1306/SSH1106 OLED display
Expand Down
28 changes: 6 additions & 22 deletions src/FastIO.h → src/FastIO_v2.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
// Быстрый IO для AVR (для остальных будет digitalxxxxx)
// v1.0
#include "FastIO_v2.h"

#ifndef FastIO_h
#define FastIO_h
#include <Arduino.h>

bool fastRead(const uint8_t pin); // быстрое чтение пина
void fastWrite(const uint8_t pin, bool val); // быстрая запись
uint8_t fastShiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); // быстрый shiftIn
void fastShiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t data); // быстрый shiftOut

// ================================================================
bool fastRead(const uint8_t pin) {
bool F_fastRead(const uint8_t pin) {
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
if (pin < 8) return bitRead(PIND, pin);
else if (pin < 14) return bitRead(PINB, pin - 8);
Expand All @@ -32,8 +21,7 @@ bool fastRead(const uint8_t pin) {
return 0;
}


void fastWrite(const uint8_t pin, bool val) {
void F_fastWrite(const uint8_t pin, bool val) {
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
if (pin < 8) bitWrite(PORTD, pin, val);
else if (pin < 14) bitWrite(PORTB, (pin - 8), val);
Expand All @@ -56,8 +44,7 @@ void fastWrite(const uint8_t pin, bool val) {
#endif
}


uint8_t fastShiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
uint8_t F_fastShiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
#if defined(AVR)
volatile uint8_t *_clk_port = portOutputRegister(digitalPinToPort(clockPin));
volatile uint8_t *_dat_port = portInputRegister(digitalPinToPort(dataPin));
Expand All @@ -81,8 +68,7 @@ uint8_t fastShiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
#endif
}


void fastShiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t data) {
void F_fastShiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t data) {
#if defined(AVR)
volatile uint8_t *_clk_port = portOutputRegister(digitalPinToPort(clockPin));
volatile uint8_t *_dat_port = portOutputRegister(digitalPinToPort(dataPin));
Expand All @@ -104,6 +90,4 @@ void fastShiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t d
#else
shiftOut(dataPin, clockPin, bitOrder, data);
#endif
}

#endif
}
13 changes: 13 additions & 0 deletions src/FastIO_v2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Быстрый IO для AVR (для остальных будет digitalxxxxx)
// v1.0

#ifndef _FastIO_v2_h
#define _FastIO_v2_h
#include <Arduino.h>

bool F_fastRead(const uint8_t pin); // быстрое чтение пина
void F_fastWrite(const uint8_t pin, bool val); // быстрая запись
uint8_t F_fastShiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); // быстрый shiftIn
void F_fastShiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t data); // быстрый shiftOut

#endif
21 changes: 11 additions & 10 deletions src/GyverOLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
v1.0 - релиз
v1.1 - улучшен перенос строк (не убирает первый символ просто так)
v1.2 - переделан FastIO
*/

#ifndef GyverOLED_h
Expand Down Expand Up @@ -89,7 +90,7 @@
#include <Arduino.h>
#include <Print.h>
#include "charMap.h"
#include "FastIO.h"
#include "FastIO_v2.h"


// ============================ БЭКЭНД КОНСТАНТЫ ==============================
Expand Down Expand Up @@ -175,15 +176,15 @@ class GyverOLED : public Print {
if (_CONN) {
SPI.begin();
pinMode(_CS, OUTPUT);
fastWrite(_CS, 1);
F_fastWrite(_CS, 1);
pinMode(_DC, OUTPUT);
if (_RST > 0) {
pinMode(_RST, OUTPUT);
fastWrite(_RST, 1);
F_fastWrite(_RST, 1);
delay(1);
fastWrite(_RST, 0);
F_fastWrite(_RST, 0);
delay(10);
fastWrite(_RST, 1);
F_fastWrite(_RST, 1);
}
} else {
Wire.begin();
Expand Down Expand Up @@ -894,25 +895,25 @@ class GyverOLED : public Print {

void beginData() {
startTransm();
if (_CONN) fastWrite(_DC, 1);
if (_CONN) F_fastWrite(_DC, 1);
else sendByteRaw(OLED_DATA_MODE);
}

void beginCommand() {
startTransm();
if (_CONN) fastWrite(_DC, 0);
if (_CONN) F_fastWrite(_DC, 0);
else sendByteRaw(OLED_COMMAND_MODE);
}

void beginOneCommand() {
startTransm();
if (_CONN) fastWrite(_DC, 0);
if (_CONN) F_fastWrite(_DC, 0);
else sendByteRaw(OLED_ONE_COMMAND_MODE);
}

void endTransm() {
if (_CONN) {
fastWrite(_CS, 1);
F_fastWrite(_CS, 1);
SPI.endTransaction();
} else {
Wire.endTransmission();
Expand All @@ -923,7 +924,7 @@ class GyverOLED : public Print {
void startTransm() {
if (_CONN) {
SPI.beginTransaction(OLED_SPI_SETT);
fastWrite(_CS, 0);
F_fastWrite(_CS, 0);
} else Wire.beginTransmission(_address);
}

Expand Down

0 comments on commit b2d09d9

Please sign in to comment.