Skip to content

Commit

Permalink
Fixed all the initialization code which was for some unkonwn reason
Browse files Browse the repository at this point in the history
completely erased from the previous commit. Added some additional
functionality; see diff. This version should be fully usable.
  • Loading branch information
gammy committed Jun 20, 2012
1 parent de202a0 commit 5a38108
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 28 deletions.
2 changes: 1 addition & 1 deletion config/ks0108_Mega.h
Expand Up @@ -23,7 +23,7 @@
* Pins used for Commands
*/
#define glcdCSEL1 33 // CS1 Bit
#define glcdCSEL2 34 // CS2 Bit
//#define glcdCSEL2 34 // CS2 Bit
#define glcdRW 35 // R/W Bit
#define glcdDI 36 // D/I Bit
#define glcdEN 37 // EN Bit
Expand Down
5 changes: 4 additions & 1 deletion config/ks0108_Panel.h
Expand Up @@ -39,7 +39,8 @@
* Most panels use two pins for chip select,
* but check your datasheet to see if a different number is required
*/
#define NBR_CHIP_SELECT_PINS 2 // the number of chip select pins required for this panel
#define NBR_CHIP_SELECT_PINS 1 // the number of chip select pins required for this panel
//#define NBR_CHIP_SELECT_PINS 2 // the number of chip select pins required for this panel

/*
* The following conditional statements determine the relationship between the chip select
Expand All @@ -64,6 +65,7 @@
*/
#elif glcd_CHIP_COUNT == 3


#define glcd_CHIP0 glcdCSEL1,LOW, glcdCSEL2,HIGH
#define glcd_CHIP1 glcdCSEL1,HIGH, glcdCSEL2,LOW
#define glcd_CHIP2 glcdCSEL1,LOW, glcdCSEL2,LOW
Expand All @@ -82,6 +84,7 @@
* Defines for Two Chip panels using one Chip Select pin
*/
#elif (NBR_CHIP_SELECT_PINS == 1 && glcd_CHIP_COUNT == 2)

#define glcd_CHIP0 glcdCSEL1,LOW
#define glcd_CHIP1 glcdCSEL1,HIGH

Expand Down
2 changes: 1 addition & 1 deletion device/xxx_Device.h
Expand Up @@ -99,7 +99,7 @@ The following lcd primitives must be defined
* (if needed)
*/

* Convert X & Y coordinates to chip values
/* Convert X & Y coordinates to chip values
*/
#define glcd_DevXYval2Chip(x,y)
#define glcd_DevXval2ChipCol(x)
Expand Down
18 changes: 15 additions & 3 deletions gText.cpp
Expand Up @@ -696,20 +696,32 @@ char *ftoa(char *str, double val, int precision) {

return(ret);
}
void gText::CPuts(char *buf, int16_t originx, int16_t originy){

int16_t w = 0, h = 0;

w = StringWidth(buf);

this->x = originx - (.5 * w);
this->y = originy - (.5 * EmergencyFontRead(FONT_HEIGHT));

Puts(buf);

}
// Print number around origin
#if 1
void gText::CPrintNumber(long n, int radix, int16_t originx, int16_t originy){
void gText::CPrintNumber(signed long n, int radix, int16_t originx, int16_t originy){

char buf[16];
int16_t w = 0, h = 0;

sprintf(buf, "%u", n);
sprintf(buf, "%d", n);
w = StringWidth(buf);

this->x = originx - (.5 * w);
this->y = originy - (.5 * EmergencyFontRead(FONT_HEIGHT));

Printf("%u", n);
Printf("%d", n);

}
#endif
Expand Down
10 changes: 10 additions & 0 deletions glcd.cpp
Expand Up @@ -404,6 +404,16 @@ void glcd::SetDisplayMode(uint8_t invert) { // was named SetInverted
}
}


/**
* Set contrast of display
*
* @param contrast
*
*/
void glcd::SetContrast(uint8_t value){
glcd_Device::SetContrast(value);
}
/**
* Draw a bitmap image
*
Expand Down
1 change: 1 addition & 0 deletions glcd.h
Expand Up @@ -67,6 +67,7 @@ class glcd : public gText
// Control functions
void Init(uint8_t invert = NON_INVERTED);
void SetDisplayMode(uint8_t mode); //NON_INVERTED or INVERTED, was SetInverted(uint8_t invert);
void SetContrast(uint8_t value);
/*@}*/

/** @name DRAWING FUNCTIONS
Expand Down
11 changes: 3 additions & 8 deletions glcd_Config.h
Expand Up @@ -2,7 +2,7 @@
* glcd_Config.h - User specific configuration for Arduino GLCD library
*
* This file is shipped to automatically configure the library for a
* 128x64 ks0108 panel using the wiring described in the documentation.
* 128x64 ssd1305 panel using the wiring described in the documentation.
*
* Use this file to select the active glcd configuration file
* Then edit the selected panel file to configure parameters for that panel.
Expand Down Expand Up @@ -69,8 +69,7 @@
/*
* autoconfig includes - (comment this out if using manual configurations, see below)
*/
//#include "config/ks0108_Panel.h" // automatically configure library for a ks0108 panel
#include "config/ks0108-192x64_Panel.h" // automatically configure library for a ks0108 192x64 panel
#include "config/ssd1305_Panel.h" // automatically configure library for a ssd1305 panel

/*
* If you want to explicitly select a manual configuration, you can edit the desired manual configuration
Expand All @@ -81,11 +80,7 @@
* and make sure that all the other config #includes are commented (including the autoconfig above)
*/

//#include "config/ks0108_Manual_Config.h" // generic ks0108 configuration

//#include "config/Modadm12864f_Manual_Config.h" // configuration for BGMicro 128x64 display with pinout diagram
//#include "config/Modvk5121_Manual_Config.h" // configuration for vk5121 122x32 display with pinout diagram
#include "config/ks0108_Mega.h"
#include "config/ssd1305_Mega.h" // Configuration for ssd1305 display

/*========================== Optional User Defines ==================================*/

Expand Down
188 changes: 176 additions & 12 deletions glcd_Device.cpp
Expand Up @@ -27,6 +27,42 @@
#include "include/glcd_Device.h"
#include "include/glcd_io.h"

#define WriteCmd(cmd) (this->WriteCommand(cmd, 0))

// From SSD1305.h by "Andrea" with a few additions
#define SSD1305_SETLOWCOLUMN 0x00
#define SSD1305_SETHIGHCOLUMN 0x10
#define SSD1305_SETSTARTCOLUMN 0x21
#define SSD1305_SETSTARTPAGE 0x22
#define SSD1305_MEMORYMODE 0x20
#define SSD1305_SETSTARTLINE 0x40
#define SSD1305_SETCONTRAST 0x81
#define SSD1305_SEGREMAP 0xA0
#define SSD1305_SEGREMAP1 0xA1
#define SSD1305_DISPLAYALLON_RESUME 0xA4
#define SSD1305_DISPLAYALLON 0xA5
#define SSD1305_NORMALDISPLAY 0xA6
#define SSD1305_INVERTDISPLAY 0xA7
#define SSD1305_SETMULTIPLEX 0xA8
#define SSD1305_DCVOLTCONVERT 0xAD
#define SSD1305_DISPLAYOFF 0xAE
#define SSD1305_DISPLAYON 0xAF
#define SSD1305_SET_PAGE 0xB0
#define SSD1305_COMSCANDEC 0xC8
#define SSD1305_SETDISPLAYOFFSET 0xD3
#define SSD1305_SETDISPLAYCLOCKDIV 0xD5
#define SSD1305_SETPRECHARGE 0xD9
#define SSD1305_SETCOMPINS 0xDA
#define SSD1305_SETVCOMDETECT 0xDB
#define SSD1305_SET_MODIFY 0xE0
#define SSD1305_CLR_MODIFY 0xEE
#define SSD1305_NOP 0xE3

#define SSD1305_SETHORISCROLL 0x26 // Horizontal scroll setup
#define SSD1305_SETVERTSCROLL 0xA3 // Set vertical scroll area
#define SSD1305_SETCONTSCROLL 0x29 // Continuous vertical & horizontal scroll setup
#define SSD1305_CLRSCROLL 0x2E // Deactivate scroll
#define SSD1305_SETSCROLL 0x2F // Activate scroll

/*
* define the static variables declared in glcd_Device
Expand Down Expand Up @@ -101,6 +137,51 @@ glcd_Device::glcd_Device(){

}

// ssd1305-specific initialization
void glcd_Device::glcd_DeviceInit(int chip) {

// Custom init sequence
WriteCmd(SSD1305_DISPLAYOFF); // Display = off
WriteCmd(SSD1305_DCVOLTCONVERT); // DC-DC voltage regulator =
WriteCmd(0x8A); // Disabled (8A = off, 8B = on)

WriteCmd(SSD1305_SETMULTIPLEX); // Multiplex ratio =
WriteCmd(0x3F); // 1/64

WriteCmd(SSD1305_SETDISPLAYOFFSET); // Display offset =
WriteCmd(0x00); // 0

WriteCmd(SSD1305_SETSTARTLINE); // Display start line =
WriteCmd(0x0); // 0

WriteCmd(SSD1305_COMSCANDEC); // Set common output scan direction
// to remapped mode.

// WriteCmd(0xC0); // Common output scan direction = WRONG
// WriteCmd(0xA6); // A6 = normal, A7 = reversed WRONG

// WriteCmd(SSD1305_DISPLAYALLON); // -Entire- display OFF (A4 = off, A5 = on)

// SetContrast(0xFF); // Contrast = 00 to FF

WriteCmd(SSD1305_SETDISPLAYCLOCKDIV); // Clock divider & OSC frequency =
WriteCmd(0xF0); // "max"

//WriteCmd(0x70); // Set lower column address(low nybble = 0)
WriteCmd(SSD1305_SETPRECHARGE); // Pre/Discharge period =
WriteCmd(0x00); // ?

WriteCmd(SSD1305_MEMORYMODE); // Addressing mode =
WriteCmd(0x02); // 0=Hori, 1=Vert, 2=Page

WriteCmd(SSD1305_SEGREMAP1);

//WriteCmd(SSD1305_DISPLAYON); // Display = on

// SetPixels(0, 0, DISPLAY_WIDTH-1, DISPLAY_HEIGHT-1, BLACK);
// TODO [delay 5000L NOPs]
}

/**
* set pixel at x,y to the given color
*
Expand Down Expand Up @@ -159,9 +240,24 @@ void glcd_Device::SetDot(uint8_t x, uint8_t y, uint8_t color)

void glcd_Device::SetPixels(uint8_t x, uint8_t y,uint8_t x2, uint8_t y2, uint8_t color)
{
uint8_t mask, pageOffset, h, i, data;
uint8_t height = y2-y+1;
uint8_t width = x2-x+1;

#if 0
if(x > x2) {
uint8_t t = x2;
x2 = x;
x = t;
}

if(y > y2) {
uint8_t t = y2;
y2 = y;
y = t;
}
#endif

uint8_t mask, pageOffset, h, i, data;
uint8_t height = y2-y+1;
uint8_t width = x2-x+1;

pageOffset = y%8;
y -= pageOffset;
Expand Down Expand Up @@ -226,6 +322,7 @@ uint8_t width = x2-x+1;
* is the upper left most pixel on the display.
*/

#if 0
void glcd_Device::GotoXY(uint8_t x, uint8_t y)
{
uint8_t chip, cmd;
Expand Down Expand Up @@ -281,6 +378,32 @@ void glcd_Device::GotoXY(uint8_t x, uint8_t y)
#endif
}
}
#endif


#if 1
void glcd_Device::GotoXY(uint8_t x, uint8_t y)
{
uint8_t chip, cmd;

if((x == this->Coord.x) && (y == this->Coord.y))
return;

if( (x > DISPLAY_WIDTH-1) || (y > DISPLAY_HEIGHT-1) ) // exit if coordinates are not legal
{
return;
}

this->Coord.x = x; // save new coordinates
this->Coord.y = y;

WriteCmd(SSD1305_SETSTARTCOLUMN);
WriteCmd(x);
WriteCmd(DISPLAY_WIDTH - 1);
WriteCmd(SSD1305_SET_PAGE + (y / 8));
}
#endif

/**
* Low level h/w initialization of display and AVR pins
*
Expand Down Expand Up @@ -404,12 +527,13 @@ void glcd_Device::Init(uint8_t invert)
lcdDelayMilliseconds(50); // extra delay for *very* slow rising reset signals
#endif

#ifdef glcd_DeviceInit // this provides override for chip specific init - mem 8 Dec 09
//#ifdef glcd_DeviceInit // this provides override for chip specific init - mem 8 Dec 09
glcd_DeviceInit(chip); // call device specific initialization if defined
#else
this->WriteCommand(LCD_ON, chip); // display on
this->WriteCommand(LCD_DISP_START, chip); // display start line = 0
#endif
//#else
// #error this is not supposed to be executed
// this->WriteCommand(LCD_ON, chip); // display on
// this->WriteCommand(LCD_DISP_START, chip); // display start line = 0
//#endif

}

Expand All @@ -430,6 +554,46 @@ void glcd_Device::Init(uint8_t invert)
this->GotoXY(0,0);
}

void glcd_Device::SetMUX(uint8_t num){
//WriteCmd(SSD1305_SETMULTIPLEX);
//WriteCmd(64);
//WriteCmd(SSD1305_SETSTARTLINE); // Display start line =
WriteCmd(SSD1305_SETMULTIPLEX);
WriteCmd(num);
}

void glcd_Device::SetupHScroll(){}
void glcd_Device::SetupVScroll(){}
void glcd_Device::SetupScroll(uint8_t page_beg, uint8_t page_end, int8_t vstep, int8_t hstep, uint8_t delay){
//Scroll(false);
WriteCmd(SSD1305_SETCONTSCROLL);
WriteCmd(hstep); // Horizontal scroll
WriteCmd(page_beg); // Beg page address
WriteCmd(delay); // Time interval per 6 frames
WriteCmd(page_end); // End page address
WriteCmd(vstep); // Vertical scroll
}

void glcd_Device::Scroll(bool on){
WriteCmd(on ? SSD1305_SETSCROLL : SSD1305_CLRSCROLL);
}

void glcd_Device::DisplayOn()
{
WriteCmd(SSD1305_DISPLAYON);
}

void glcd_Device::DisplayOff()
{
WriteCmd(SSD1305_DISPLAYOFF);
}

void glcd_Device::SetContrast(uint8_t value)
{
WriteCmd(SSD1305_SETCONTRAST);
WriteCmd(value);
}

#ifdef glcd_CHIP0 // if at least one chip select string
__inline__ void glcd_Device::SelectChip(uint8_t chip)
{
Expand All @@ -449,6 +613,7 @@ __inline__ void glcd_Device::SelectChip(uint8_t chip)

void glcd_Device::WaitReady( uint8_t chip)
{

// wait until LCD busy bit goes to zero
glcd_DevSelectChip(chip);
lcdDataDir(0x00);
Expand All @@ -458,10 +623,8 @@ void glcd_Device::WaitReady( uint8_t chip)
glcd_DevENstrobeHi(chip);
lcdDelayNanoseconds(GLCD_tDDR);

while(lcdIsBusy())
{
;
}
//while(lcdIsBusy());

glcd_DevENstrobeLo(chip);
}

Expand Down Expand Up @@ -507,6 +670,7 @@ uint8_t glcd_Device::DoReadData()

glcd_DevENstrobeLo(chip);
#ifdef GLCD_XCOL_SUPPORT
#error huh what
this->Coord.chip[chip].col++;
#endif
return data;
Expand Down

0 comments on commit 5a38108

Please sign in to comment.