diff --git a/src/display/Display.cpp b/src/display/Display.cpp new file mode 100644 index 0000000..b54b8bd --- /dev/null +++ b/src/display/Display.cpp @@ -0,0 +1,157 @@ +#include Display.h + +void Display::sendDisplayCMD(uint8_t cmd){ + +}; +void Display::begin(void){ + //TODO: change pin to #defines, first check if Wire.begin was already called + Wire.begin(1,2); + //set Mux Ratio + sendDisplayCMD(client,muxRatio); + sendDisplayCMD(client,0x3f); + + sendDisplayCMD(client,setOffset); + sendDisplayCMD(client,0x00); + + sendDisplayCMD(client, setStartLine); + + + /*x-flip*/ + //sendDisplayCMD(client,setSegmentMap); + sendDisplayCMD(client, setSegmentReMap); + + /*mapping of the rows*/ + sendDisplayCMD(client,setComHardwareConfig); + sendDisplayCMD(client,0x10); + + /*y-flip*/ + //sendDisplayCMD(client, setComDirectionNormal); + sendDisplayCMD(client, setComDirectionFlipped); + + sendDisplayCMD(client, setContrast); + sendDisplayCMD(client, 0x7f); + + sendDisplayCMD(client,stopCompleteOn); + + /*which pixels are bright: normal = 1s are bright, inverese= 0s are bright*/ + sendDisplayCMD(client, setNormalMode); + //sendDisplayCMD(client, setInverseMode); + + sendDisplayCMD(client, setOscFreq); + sendDisplayCMD(client,0x80); + + sendDisplayCMD(client,setChargePump); + sendDisplayCMD(client,0x14); + + sendDisplayCMD(client, activateDisplay); + return; +}; +void Display::clear(void){ + + int index=0; + sendDisplayCMD(client,addressingMode); + sendDisplayCMD(client,0x00); //horizontal + printk(KERN_ALERT "DEBUG: Passed %s %d \n",__FUNCTION__,__LINE__); + sendDisplayCMD(client,colRange); + sendDisplayCMD(client,0x00); + sendDisplayCMD(client,0x7f); + printk(KERN_ALERT "DEBUG: Passed %s %d \n",__FUNCTION__,__LINE__); + sendDisplayCMD(client,pageRange); + sendDisplayCMD(client,0x00); + sendDisplayCMD(client,0x07); + printk(KERN_ALERT "DEBUG: Passed %s %d \n",__FUNCTION__,__LINE__); + i2c_data[0]=data_byte; + for(index=1;index<128*8;index++){i2c_data[index]=0x00;} + printk(KERN_ALERT "DEBUG: Passed %s %d \n",__FUNCTION__,__LINE__); + Wire.beginTransmission(DisplayAdress); + Wire.write(data_byte); + Wire.endTransmission(); + //Wire only has a 32-Byte Buffer for transmission + for(uint index= 0; index<4;index++){ + Wire.beginTransmission(DisplayAdress); + for(uint bufferIndex = 0;bufferIndex<32;bufferIndex++){ + Wire.write(0x00); + } + Wire.endTransmission(); + } + return; +}; + +/** + * @brief updates amount of chars on current rows and also the current row + * + * @param charAmount how many chars were added + */ +void Display::updateLine(int charAmount) +{ + if(charAmount+this->charsOnCurrLine>16) + { + this->currLine = (this->currLine+((charAmount+this->charsOnCurrLine)/16))%8; + this->charsOnCurrLine = (charAmount+this->charsOnCurrLine)%17; //there can be 0-16 chars on one line, so the 17th char is on next line + } + else + { + this->charsOnCurrLine = this->charAmount+this->charsOnCurrLine; + } +} + + +void Display::print(char *value){ + int i = 0; + int charval; + int nextchar; + /* write data to the buffer */ + //check if input is a predefined cmd + for(i=0;i +#include +#include "DisplayCMDs.h" + + +#define display +class Display{ + protected: + //how many chars are on current line + uint8_t charsOnCurrLine = 0; + //on which line are we currently printing + uint8_t currLine = 0; + void sendDisplayCMD(uint8_t cmd); + void updateLine(uint charAmount); + public: + void begin(void); + void clear(void); + void print(char *value); + void println(char *value); + void print(int value); +}; + + +#endif //Display_h \ No newline at end of file diff --git a/src/display/DisplayCMDs.h b/src/display/DisplayCMDs.h new file mode 100644 index 0000000..45d2c30 --- /dev/null +++ b/src/display/DisplayCMDs.h @@ -0,0 +1,24 @@ +#define cmd_byte 0x80 +#define data_byte 0x40 +#define muxRatio 0xa8 //needs second argument ranging from 16-63 +#define setOffset 0xd3 //needs second argument ranging from 0-63 +#define setStartLine 0x40 +#define setSegmentMap 0xa0 +#define setSegmentReMap 0xa1 +#define setComDirectionNormal 0xc0 +#define setComDirectionFlipped 0xc8 +#define setComHardwareConfig 0xda //needs second arg +#define setContrast 0x81 //needs second arg +#define completeOn 0xa5 +#define stopCompleteOn 0xa4 +#define setNormalMode 0xa6 +#define setInverseMode 0xa7 +#define setOscFreq 0xd5 //needs second arg +#define setChargePump 0x8d//needs second arg 0x14 for enable +#define activateDisplay 0xaf +#define disableDisplay 0xae +#define addressingMode 0x20 +#define colRange 0x21 +#define pageRange 0x22 + +#define DisplayAdress \ No newline at end of file