Skip to content
Browse files

Fixed all the initialization code which was for some unkonwn reason

completely erased from the previous commit. Added some additional
functionality; see diff. This version should be fully usable.
  • Loading branch information...
1 parent de202a0 commit 5a38108d043af1000449bcbb5211d96c0ade2636 gammy committed
Showing with 227 additions and 28 deletions.
  1. +1 −1 config/ks0108_Mega.h
  2. +4 −1 config/ks0108_Panel.h
  3. +1 −1 device/xxx_Device.h
  4. +15 −3 gText.cpp
  5. +10 −0 glcd.cpp
  6. +1 −0 glcd.h
  7. +3 −8 glcd_Config.h
  8. +176 −12 glcd_Device.cpp
  9. +2 −1 include/gText.h
  10. +9 −0 include/glcd_Device.h
  11. +2 −0 include/glcd_io.h
  12. +3 −1 readme.txt
View
2 config/ks0108_Mega.h
@@ -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
View
5 config/ks0108_Panel.h
@@ -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
@@ -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
@@ -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
View
2 device/xxx_Device.h
@@ -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)
View
18 gText.cpp
@@ -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
View
10 glcd.cpp
@@ -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
*
View
1 glcd.h
@@ -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
View
11 glcd_Config.h
@@ -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.
@@ -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
@@ -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 ==================================*/
View
188 glcd_Device.cpp
@@ -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
@@ -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
*
@@ -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;
@@ -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;
@@ -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
*
@@ -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
}
@@ -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)
{
@@ -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);
@@ -458,10 +623,8 @@ void glcd_Device::WaitReady( uint8_t chip)
glcd_DevENstrobeHi(chip);
lcdDelayNanoseconds(GLCD_tDDR);
- while(lcdIsBusy())
- {
- ;
- }
+ //while(lcdIsBusy());
+
glcd_DevENstrobeLo(chip);
}
@@ -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;
View
3 include/gText.h
@@ -235,8 +235,9 @@ class gText : public glcd_Device
void SelectFont(Font_t font, uint8_t color=BLACK, FontCallback callback=ReadPgmData); // default arguments added, callback now last arg
void SetFontColor(uint8_t color); // new method
+ void CPuts(char *buf, int16_t originx, int16_t originy);
void CPrintFloat(float n, int16_t originx, int16_t originy);
- void CPrintNumber(long n, int radix, int16_t originx, int16_t originy);
+ void CPrintNumber(signed long n, int radix, int16_t originx, int16_t originy);
#if 0
void GetCharDims(char c, int16_t *w, int16_t *h);
#endif
View
9 include/glcd_Device.h
@@ -76,6 +76,7 @@ class glcd_Device : public Print
{
private:
// Control functions
+ void glcd_DeviceInit(int chip);
uint8_t DoReadData(void);
void WriteCommand(uint8_t cmd, uint8_t chip);
inline void Enable(void);
@@ -88,6 +89,14 @@ class glcd_Device : public Print
glcd_Device();
//protected: uncommented by gammy for ModeContainer compat
void Init(uint8_t invert = false); // now public, default is non-inverted
+ void SetMUX(uint8_t num);
+ void SetupHScroll();
+ void SetupVScroll();
+ void SetupScroll(uint8_t page_beg, uint8_t page_end, int8_t vstep, int8_t hstep, uint8_t delay);
+ void Scroll(bool on);
+ void DisplayOn();
+ void DisplayOff();
+ void SetContrast(uint8_t value);
void SetDot(uint8_t x, uint8_t y, uint8_t color);
void SetPixels(uint8_t x, uint8_t y,uint8_t x1, uint8_t y1, uint8_t color);
uint8_t ReadData(void); // now public
View
2 include/glcd_io.h
@@ -121,6 +121,7 @@
#define lcdReset() avrio_WritePin(glcdRES, 0)
#define lcdUnReset() avrio_WritePin(glcdRES, 1)
#else
+#error We expect glcdRES(ET) to be defined.
#define lcdReset()
#define lcdUnReset()
#endif
@@ -146,6 +147,7 @@
* a register when the number cycles is less than 12.
*/
#include "include/delay.h" // Hans' Heirichs delay macros
+#include "Arduino.h"
#define lcdDelayNanoseconds(__ns) _delay_cycles( (double)(F_CPU)*((double)__ns)/1.0e9 + 0.5 ) // Hans Heinrichs delay cycle routine
View
4 readme.txt
@@ -57,4 +57,6 @@ The glcd library was created by Michael Margolis. Extensive enhancements
including the majority of the improvements in this release were led
by Bill Perry.
-
+ssd1305 (6800 parallel mode) hacks by Kristian Gunstone(IPEC) with code based on
+"Andrea"'s SSD1305 ISP library for AVR (see
+http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=845965)

0 comments on commit 5a38108

Please sign in to comment.
Something went wrong with that request. Please try again.