WIP: implementing basic displaycontrols

This commit is contained in:
Hans Haupt 2024-05-29 00:41:11 +02:00
parent f41de7378f
commit b1a0bc32bc
3 changed files with 218 additions and 0 deletions

157
src/display/Display.cpp Normal file
View File

@ -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<count;i++) //count-1 to prevent the terminate string to be send
{
charval = procfs_buffer[i];
if(charval=='/')
{
nextchar = procfs_buffer[i+1];
if(nextchar=='c')
{
clearDisplay(display_i2c_client);
currLine = 0;
charsOnCurrLine = 0;
}
else if(nextchar=='n')
{
if(charsOnCurrLine==16)
{
currLine=currLine+1;
charsOnCurrLine=0;
}
while(charsOnCurrLine<17)
{
i2c_master_send(display_i2c_client,font8x8_colwise[0],9);
updateLine(1);
if(charsOnCurrLine==16)
{
break;
}
}
}
else
{
}
i=i+1;
}
else
{
updateLine(1);
i2c_master_send(display_i2c_client,font8x8_colwise[charval],9);
}
}
// }
return procfs_buffer_size;
}
};
void Display::println(char *value){
};
void Display::print(int value);

37
src/display/Display.h Normal file
View File

@ -0,0 +1,37 @@
/**
* @file InfraredLight.h
* @author Hans Haupt (hans.haupt@dezibot.de)
* @brief Adds the ability to print to the display of the robot.
* @version 0.1
* @date 2024-05-24
*
* @copyright Copyright (c) 2024
*
*/
#ifndef Display_h
#define Display_h
#include <stdint.h>
#include <Arduino.h>
#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

24
src/display/DisplayCMDs.h Normal file
View File

@ -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