1
0
forked from me/IronOS

Add readback for the current font

This commit is contained in:
Ben V. Brown
2019-12-29 16:35:29 +11:00
parent 3040bc5fa4
commit e82c75258a
2 changed files with 121 additions and 112 deletions

View File

@@ -1,112 +1,113 @@
/* /*
* OLED.hpp * OLED.hpp
* *
* Created on: 20Jan.,2017 * Created on: 20Jan.,2017
* Author: Ben V. Brown <Ralim> * Author: Ben V. Brown <Ralim>
* Designed for the SSD1307 * Designed for the SSD1307
* Cleared for release for TS100 2017/08/20 * Cleared for release for TS100 2017/08/20
*/ */
#ifndef OLED_HPP_ #ifndef OLED_HPP_
#define OLED_HPP_ #define OLED_HPP_
#include <hardware.h> #include <hardware.h>
#include "stm32f1xx_hal.h" #include "stm32f1xx_hal.h"
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include "FRToSI2C.hpp" #include "FRToSI2C.hpp"
#include "Font.h" #include "Font.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "FreeRTOS.h" #include "FreeRTOS.h"
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#define DEVICEADDR_OLED (0x3c<<1) #define DEVICEADDR_OLED (0x3c<<1)
#define OLED_WIDTH 96 #define OLED_WIDTH 96
#define FRAMEBUFFER_START 17 #define FRAMEBUFFER_START 17
class OLED { class OLED {
public: public:
enum DisplayState : bool { enum DisplayState : bool {
OFF = false, OFF = false,
ON = true ON = true
}; };
static void initialize(); // Startup the I2C coms (brings screen out of reset etc) static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
// Draw the buffer out to the LCD using the DMA Channel // Draw the buffer out to the LCD using the DMA Channel
static void refresh() { static void refresh() {
FRToSI2C::Transmit( DEVICEADDR_OLED, screenBuffer, FRToSI2C::Transmit( DEVICEADDR_OLED, screenBuffer,
FRAMEBUFFER_START + (OLED_WIDTH * 2)); FRAMEBUFFER_START + (OLED_WIDTH * 2));
//DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms //DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
//or we need to goto double buffering //or we need to goto double buffering
} }
static void setDisplayState(DisplayState state) { static void setDisplayState(DisplayState state) {
displayState = state; displayState = state;
screenBuffer[1] = (state == ON) ? 0xAF : 0xAE; screenBuffer[1] = (state == ON) ? 0xAF : 0xAE;
} }
static void setRotation(bool leftHanded); // Set the rotation for the screen static void setRotation(bool leftHanded); // Set the rotation for the screen
// Get the current rotation of the LCD // Get the current rotation of the LCD
static bool getRotation() { static bool getRotation() {
return inLeftHandedMode; return inLeftHandedMode;
} }
static int16_t getCursorX() { static int16_t getCursorX() {
return cursor_x; return cursor_x;
} }
static void print(const char* string);// Draw a string to the current location, with current font static void print(const char* string);// Draw a string to the current location, with current font
// Set the cursor location by pixels // Set the cursor location by pixels
static void setCursor(int16_t x, int16_t y) { static void setCursor(int16_t x, int16_t y) {
cursor_x = x; cursor_x = x;
cursor_y = y; cursor_y = y;
} }
//Set cursor location by chars in current font //Set cursor location by chars in current font
static void setCharCursor(int16_t x, int16_t y) { static void setCharCursor(int16_t x, int16_t y) {
cursor_x = x * fontWidth; cursor_x = x * fontWidth;
cursor_y = y * fontHeight; cursor_y = y * fontHeight;
} }
static void setFont(uint8_t fontNumber); // (Future) Set the font that is being used static void setFont(uint8_t fontNumber); // (Future) Set the font that is being used
static void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) { static uint8_t getFont();
drawArea(x, 0, width, 16, buffer); static void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) {
} drawArea(x, 0, width, 16, buffer);
// Draws an image to the buffer, at x offset from top to bottom (fixed height renders) }
static void printNumber(uint16_t number, uint8_t places); // Draws an image to the buffer, at x offset from top to bottom (fixed height renders)
// Draws a number at the current cursor location static void printNumber(uint16_t number, uint8_t places);
// Clears the buffer // Draws a number at the current cursor location
static void clearScreen() { // Clears the buffer
memset(&screenBuffer[FRAMEBUFFER_START], 0, OLED_WIDTH * 2); static void clearScreen() {
} memset(&screenBuffer[FRAMEBUFFER_START], 0, OLED_WIDTH * 2);
// Draws the battery level symbol }
static void drawBattery(uint8_t state) { // Draws the battery level symbol
drawSymbol(3 + (state > 10 ? 10 : state)); static void drawBattery(uint8_t state) {
} drawSymbol(3 + (state > 10 ? 10 : state));
// Draws a checkbox }
static void drawCheckbox(bool state) { // Draws a checkbox
drawSymbol((state) ? 16 : 17); static void drawCheckbox(bool state) {
} drawSymbol((state) ? 16 : 17);
static void debugNumber(int32_t val); }
static void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width static void debugNumber(int32_t val);
static void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, static void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width
const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset static void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
static void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset
const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset static void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
static void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset
bool clear); static void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
static void drawHeatSymbol(uint8_t state); bool clear);
private: static void drawHeatSymbol(uint8_t state);
static void drawChar(char c); // Draw a character to a specific location private:
static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer static void drawChar(char c); // Draw a character to a specific location
static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer
static uint8_t* secondStripPtr; //Pointers to the strips static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM) static uint8_t* secondStripPtr; //Pointers to the strips
static DisplayState displayState; static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
static uint8_t fontWidth, fontHeight; static DisplayState displayState;
static int16_t cursor_x, cursor_y; static uint8_t fontWidth, fontHeight;
static uint8_t displayOffset; static int16_t cursor_x, cursor_y;
static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer static uint8_t displayOffset;
}; static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
};
#endif /* OLED_HPP_ */
#endif /* OLED_HPP_ */

View File

@@ -155,6 +155,14 @@ void OLED::setFont(uint8_t fontNumber) {
fontWidth = 12; fontWidth = 12;
} }
} }
uint8_t OLED::getFont() {
if (currentFont == USER_FONT_6x8)
return 1;
else if (currentFont == ExtraFontChars)
return 2;
else
return 0;
}
inline void stripLeaderZeros(char *buffer) { inline void stripLeaderZeros(char *buffer) {
//Removing the leading zero's by swapping them to SymbolSpace //Removing the leading zero's by swapping them to SymbolSpace
// Stop 1 short so that we dont blank entire number if its zero // Stop 1 short so that we dont blank entire number if its zero