Merge pull request #222 from bmoniey/protected

Protected
This commit is contained in:
Limor "Ladyada" Fried 2021-10-10 11:50:17 -04:00 committed by GitHub
commit 04207b6f39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 15 deletions

View file

@ -345,6 +345,16 @@ Adafruit_SSD1306::~Adafruit_SSD1306(void) {
// Issue single byte out SPI, either soft or hardware as appropriate.
// SPI transaction/selection must be performed in calling function.
/*!
@brief Write a single byte to the SPI port.
@param d
Data byte to be written.
@return void
@note See HAVE_PORTREG which defines if the method uses a port or bit-bang
method
*/
inline void Adafruit_SSD1306::SPIwrite(uint8_t d) {
if (spi) {
(void)spi->transfer(d);
@ -366,10 +376,18 @@ inline void Adafruit_SSD1306::SPIwrite(uint8_t d) {
}
}
// Issue single command to SSD1306, using I2C or hard/soft SPI as needed.
// Because command calls are often grouped, SPI transaction and selection
// must be started/ended in calling function for efficiency.
// This is a private function, not exposed (see ssd1306_command() instead).
/*!
@brief Issue single command to SSD1306, using I2C or hard/soft SPI as
needed. Because command calls are often grouped, SPI transaction and
selection must be started/ended in calling function for efficiency. This is a
protected function, not exposed (see ssd1306_command() instead).
@param c
the command character to send to the display.
Refer to ssd1306 data sheet for commands
@return None (void).
@note
*/
void Adafruit_SSD1306::ssd1306_command1(uint8_t c) {
if (wire) { // I2C
wire->beginTransmission(i2caddr);
@ -382,8 +400,18 @@ void Adafruit_SSD1306::ssd1306_command1(uint8_t c) {
}
}
// Issue list of commands to SSD1306, same rules as above re: transactions.
// This is a private function, not exposed.
/*!
@brief Issue list of commands to SSD1306, same rules as above re:
transactions. This is a protected function, not exposed.
@param c
pointer to list of commands
@param n
number of commands in the list
@return None (void).
@note
*/
void Adafruit_SSD1306::ssd1306_commandList(const uint8_t *c, uint8_t n) {
if (wire) { // I2C
wire->beginTransmission(i2caddr);
@ -695,6 +723,23 @@ void Adafruit_SSD1306::drawFastHLine(int16_t x, int16_t y, int16_t w,
drawFastHLineInternal(x, y, w, color);
}
/*!
@brief Draw a horizontal line with a width and color. Used by public
methods drawFastHLine,drawFastVLine
@param x
Leftmost column -- 0 at left to (screen width - 1) at right.
@param y
Row of display -- 0 at top to (screen height -1) at bottom.
@param w
Width of line, in pixels.
@param color
Line color, one of: SSD1306_BLACK, SSD1306_WHITE or
SSD1306_INVERT.
@return None (void).
@note Changes buffer contents only, no immediate effect on display.
Follow up with a call to display(), or with other graphics
commands as needed by one's own application.
*/
void Adafruit_SSD1306::drawFastHLineInternal(int16_t x, int16_t y, int16_t w,
uint16_t color) {
@ -778,6 +823,22 @@ void Adafruit_SSD1306::drawFastVLine(int16_t x, int16_t y, int16_t h,
drawFastVLineInternal(x, y, h, color);
}
/*!
@brief Draw a vertical line with a width and color. Used by public method
drawFastHLine,drawFastVLine
@param x
Leftmost column -- 0 at left to (screen width - 1) at right.
@param __y
Row of display -- 0 at top to (screen height -1) at bottom.
@param __h height of the line in pixels
@param color
Line color, one of: SSD1306_BLACK, SSD1306_WHITE or
SSD1306_INVERT.
@return None (void).
@note Changes buffer contents only, no immediate effect on display.
Follow up with a call to display(), or with other graphics
commands as needed by one's own application.
*/
void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y,
int16_t __h, uint16_t color) {

View file

@ -160,27 +160,39 @@ public:
bool getPixel(int16_t x, int16_t y);
uint8_t *getBuffer(void);
private:
protected:
inline void SPIwrite(uint8_t d) __attribute__((always_inline));
void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color);
void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color);
void ssd1306_command1(uint8_t c);
void ssd1306_commandList(const uint8_t *c, uint8_t n);
SPIClass *spi;
TwoWire *wire;
uint8_t *buffer;
int8_t i2caddr, vccstate, page_end;
int8_t mosiPin, clkPin, dcPin, csPin, rstPin;
SPIClass *spi; ///< Initialized during construction when using SPI. See
///< SPI.cpp, SPI.h
TwoWire *wire; ///< Initialized during construction when using I2C. See
///< Wire.cpp, Wire.h
uint8_t *buffer; ///< Buffer data used for display buffer. Allocated when
///< begin method is called.
int8_t i2caddr; ///< I2C address initialized when begin method is called.
int8_t vccstate; ///< VCC selection, set by begin method.
int8_t page_end; ///< not used
int8_t mosiPin; ///< (Master Out Slave In) set when using SPI set during
///< construction.
int8_t clkPin; ///< (Clock Pin) set when using SPI set during construction.
int8_t dcPin; ///< (Data Pin) set when using SPI set during construction.
int8_t
csPin; ///< (Chip Select Pin) set when using SPI set during construction.
int8_t rstPin; ///< Display reset pin assignment. Set during construction.
#ifdef HAVE_PORTREG
PortReg *mosiPort, *clkPort, *dcPort, *csPort;
PortMask mosiPinMask, clkPinMask, dcPinMask, csPinMask;
#endif
#if ARDUINO >= 157
uint32_t wireClk; // Wire speed for SSD1306 transfers
uint32_t restoreClk; // Wire speed following SSD1306 transfers
uint32_t wireClk; ///< Wire speed for SSD1306 transfers
uint32_t restoreClk; ///< Wire speed following SSD1306 transfers
#endif
uint8_t contrast; // normal contrast setting for this device
uint8_t contrast; ///< normal contrast setting for this device
#if defined(SPI_HAS_TRANSACTION)
protected:
// Allow sub-class to change