
Demo for u0LED128-G1 4D Systems 128x128 Graphic Display This simple demo demonstrates the use of graphical display controls. The library construction does not use a C ++ class. Christian Dupaty 03/2021
Demo for u0LED128-G1 4D Systems 128x128 Graphic Display This simple demo demonstrates the use of graphical display controls. The library construction does not use a C ++ class.
Data Sheet : https://www.farnell.com/datasheets/356896.pdf
Ref 4DSystems for G2 version : https://4dsystems.com.au/uoled-128-g2
Revision 5:791713e36c37, committed 2021-03-13
- Comitter:
- cdupaty
- Date:
- Sat Mar 13 09:16:08 2021 +0000
- Parent:
- 4:a2d1329d042c
- Commit message:
- Demo for u0LED128-G1; 4D Systems 128x128 Graphic Display; This simple demo demonstrates the use of graphical display controls.; The library construction does not use a C ++ class.; Christian Dupaty; 03/2021
Changed in this revision
diff -r a2d1329d042c -r 791713e36c37 GSGCdef.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GSGCdef.h Sat Mar 13 09:16:08 2021 +0000 @@ -0,0 +1,101 @@ +/******************************************************************************* +4D LABS PTY. LTD. COPYRIGHT 2009. +THIS SOFTWARE IS PROVIDED "AS IS." 4D LABS EXPRESSLY DISCLAIM ANY WARRANTY OF +ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NONINFRINGEMENT. +IN NO EVENT SHALL 4D LABS BE LIABLE FOR ANY INCIDENTAL, SPECIAL, +INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR +EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY +CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENCE THEREOF), ANY +CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS. +*******************************************************************************/ +/******************************************************************************* +Name: GOLDELOX-SGC Host Serial Commands Definitions +File Name: GSGCdef.h +Description: Host Serial Interface Commands Definitions +*******************************************************************************/ +#ifndef GSGC_DEF_H +#define GSGC_DEF_H +// GSGC PROTOCOL CONSTANTS +#define ACK 0x06 // Acknowledge +#define NAK 0x15 // Not Acknowledge +// GSGC SWITCH-JOYSTICK CONSTANTS +#define SW1_UP 0x10 // SW1 or Joystick UP +#define SW2_LEFT 0x20 // SW2 or Joystick LEFT +#define SW3_DOWN 0x30 // SW3 or Joystick DOWN +#define SW4_RIGHT 0x40 // SW4 or Joystick RIGHT +#define SW5_FIRE 0x50 // SW5 or Joystick FIRE +// GSGC GRAPHICS CONSTANTS +#define COLOR8 0x08 // 8 bit Colour Mode +#define COLOR16 0x10 // 16 bit Colour Mode +#define BUTTONUP 0x01 // Button Up Mode +#define BUTTONDOWN 0x00 // Button Down Mode +#define RED 0xF800 // RED +#define GREEN 0x07E0 // GREEN +#define BLUE 0x001F // BLUE +#define BLACK 0x0000 // BLACK +#define WHITE 0xFFFF // WHITE +// GSGC TEXT CONSTANTS +#define FONT1 0x00 // 5x7 Internal Font +#define FONT2 0x01 // 8x8 Internal Font +#define FONT3 0x02 // 8x12 Internal Font +// GSGC GENERAL COMMANDS DEFINITIONS +#define GSGC_AUTOBAUD 0x55 // Auto Baud Command +#define GSGC_VERSION 0x56 // Device Info Request +#define GSGC_BACKGND 0x42 // Change Background Colour +#define GSGC_CLS 0x45 // Clear Screen +#define GSGC_DISPCONT 0x59 // Display Control Functions +#define GSGC_SWITCHSTAT 0x4A // Get Switch-Buttons Status +#define GSGC_SWITCHSTATWAIT 0x6A // Get Switch-Buttons Status with Timeout +#define GSGC_SOUND 0x4E // Generate a Tone +// GSGC GRAPHICS COMMANDS DEFINITIONS +#define GSGC_ADDBM 0x41 // Add User Bitmap +#define GSGC_CIRCLE 0x43 // Draw Circle +#define GSGC_BM 0x44 // Draw User Bitmap +#define GSGC_TRIANGLE 0x47 // Draw Triangle +#define GSGC_IMAGE 0x49 // Draw Image-Icon +#define GSGC_LINE 0x4C // Draw Line +#define GSGC_PIXEL 0x50 // Draw Pixel +#define GSGC_RDPIXEL 0x52 // Read Pixel +#define GSGC_SCRNCOPYPASTE 0x63 // Screen Copy-Paste +#define GSGC_POLYGON 0x67 // Draw Polygon +#define GSGC_SETPEN 0x70 // Set Pen Size +#define GSGC_RECTANGLE 0x72 // Draw Rectangle +// GSGC TEXT COMMANDS DEFINITIONS +#define GSGC_SETFONT 0x46 // Set Font +#define GSGC_SETOPAQUE 0x4F // Set Transparent-Opaque Text +#define GSGC_STRINGGFX 0x53 // “String” of ASCII Text (graphics format) +#define GSGC_CHARTXT 0x54 // ASCII Character (text format) +#define GSGC_BUTTONTXT 0x62 // Text Button +#define GSGC_STRINGTXT 0x73 // “String” of ASCII Text (text format) +#define GSGC_CHARGFX 0x74 // ASCII Character (graphics format) +// GSGC EXTENDED COMMANDS HEADER DEFINITION +#define GSGC_EXTCMD 0x40 // Extended Command Header +// GSGC MEMORY CARD COMMANDS DEFINITIONS +#define GSGC_MCAP 0x41 // Set Address Pointer of Memory Card +#define GSGC_MCCOPYSAVE 0x43 // Screen Copy-Save to Memory Card +#define GSGC_MCIMAGE 0x49 // Display Image-Icon from Memory Card +#define GSGC_MCOBJ 0x4F // Display Object from Memory Card +#define GSGC_MCRUN 0x50 // Run Script (4DSL) Program from Card +#define GSGC_MCRDSECTOR 0x52 // Read Sector Block Data from Memory Card +#define GSGC_MCVIDEO 0x56 // Display Video Clip from Memory Card +#define GSGC_MCWRSECTOR 0x57 // Write Sector Block Data to Memory Card +#define GSGC_MCINIT 0x69 // Initialise Memory Card +#define GSGC_MCRDBYTE 0x72 // Read Byte Data from Memory Card +#define GSGC_MCWRBYTE 0x77 // Write Byte Data to Memory Card +// GSGC SCRIPTING COMMANDS DEFINITIONS +#define GSGC_MCAP 0x41 // Set Address Pointer of Memory Card +#define GSGC_DELAY 0x07 // Delay +#define GSGC_SETCNTR 0x08 // Set Counter +#define GSGC_DECCNTR 0x09 // Decrement Counter +#define GSGC_JMPNZ 0x0A // Jump to Address If Counter Not Zero +#define GSGC_JMP 0x0B // Jump to Address +#define GSGC_EXIT 0x0C // Exit-Terminate Script Program +// DIVERS +#define SOLID 0 +#define EMPTY 1 +#define TRANSPARENT 0 +#define OPAQUE 1 +#define UP 1 +#define DOWN 0 +#endif \ No newline at end of file
diff -r a2d1329d042c -r 791713e36c37 main.cpp --- a/main.cpp Wed Jan 22 12:34:48 2020 +0000 +++ b/main.cpp Sat Mar 13 09:16:08 2021 +0000 @@ -1,22 +1,334 @@ -// Serial demo using mbed 5 + +// C.Dupaty 09/2010 adaptation STM32 03/2021 +// demo gestion afficheur graphique uOLED-128-G1 (SGC) +// les équivalences (#define) des commandes sont dans GSGCdef.h +// le descritif des commande uOLED est dans : GOLDELOX-SGC-COMMANDS-SIS-rev3.pdf +// le description des connexions et utilitaires uOLED sont dans : uOLED-128-G1SGC-DS-rev4.pdf +// La carte uSD a été chargé depuis un PC avec 3 images et une vidéo à partir de l'utilitaire GraphicsComposer.exe +// ce dernier a genere un fichier test.txt qui contient entre autre les adresses de ce objets dans la mémoire uSD + +// PC_1 : TX (donc RX de uOLED) +// PC_0 : RX (donc TX de uOLED) +// VSS : 0v +// GND : 5v +// VDD : Reset uOLED #include "mbed.h" +#include <stdio.h> + +#include "uOLEDLIB.h" DigitalOut myled(LED1); +DigitalIn bouton(USER_BUTTON); +DigitalOut reset(PB_0); Serial pc(USBTX, USBRX); // tx, rx +Serial uOLED(PC_1,PC_0); // tx, rx + +#define OMER 0x014120 // adresses des images dans la uSD (voir fichier test.txt) +#define debug + +char chaine1[]="Test uOLED-128-G1 (SGC)"; +char chaine2[]="presser bouton bleu"; + +unsigned char ack(void) +{ +unsigned char resp; + while (!uOLED.readable()) wait_ms(1); // wait for screen answer + resp = uOLED.getc(); + #ifdef debug + if(resp!=ACK) pc.printf("erreur d acquitement\n"); + else printf("Acquitement OK\n"); + #endif + return(resp); +} + + +void couleur_fond(int color) +{ + #ifdef debug + pc.printf("Commande GSGC_BACKGND %d\n",color); + #endif + uOLED.putc(GSGC_BACKGND); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + ack(); +} + +void rectangle(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned int color) +{ + #ifdef debug + pc.printf("Commande GSGC_RECTANGLE , %d, %d, %d, %d\n",x1,y1,x2,y2,color); + #endif + uOLED.putc(GSGC_RECTANGLE); + uOLED.putc(x1); + uOLED.putc(y1); + uOLED.putc(x2); + uOLED.putc(y2); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + ack(); +} + +void cercle(unsigned char x,unsigned char y,unsigned char radius,unsigned int color) +{ + #ifdef debug + pc.printf("Commande GSGC_CIRCLE , %d, %d, %d, %d\n",x,y,radius,color); + #endif + uOLED.putc(GSGC_CIRCLE); + uOLED.putc(x); + uOLED.putc(y); + uOLED.putc(radius); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + ack(); +} + +void triangle(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char x3,unsigned char y3,unsigned int color) +{ + #ifdef debug + pc.printf("Commande GSGC_TRIANGLE , %d, %d, %d, %d, %d, %d, %d\n",x1,y1,x2,y2,x3,y3,color); + #endif + uOLED.putc(GSGC_TRIANGLE); + uOLED.putc(x1); + uOLED.putc(y1); + uOLED.putc(x2); + uOLED.putc(y2); + uOLED.putc(x3); + uOLED.putc(y3); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + ack(); +} + +void ligne(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned int color) +{ + #ifdef debug + pc.printf("Commande GSGC_LINE , %d, %d, %d, %d\n",x1,y1,x2,y2,color); + #endif + uOLED.putc(GSGC_LINE); + uOLED.putc(x1); + uOLED.putc(y1); + uOLED.putc(x2); + uOLED.putc(y2); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + ack(); +} + +void opaque(unsigned char mode) +{ + #ifdef debug + pc.printf("Commande GSGC_SETOPAQUE , %d\n",mode); + #endif + uOLED.putc(GSGC_SETOPAQUE); + uOLED.putc(mode); + ack(); +} + +void pixel(unsigned char x1,unsigned char y1,unsigned int color) +{ + #ifdef debug + pc.printf("Commande GSGC_PIXEL , %d, %d\n",x1,y1,color); + #endif + uOLED.putc(GSGC_PIXEL); + uOLED.putc(x1); + uOLED.putc(y1); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + ack(); +} + +void penSize(unsigned char size) +{ + #ifdef debug + pc.printf("Commande GSGC_SETPEN , %d\n",size); + #endif + uOLED.putc(GSGC_SETPEN); + uOLED.putc(size); + ack(); +} + +void afftexte_graphic(char x, char y, char font,int color , char w, char h, char * mess) +{ + #ifdef debug + pc.printf("Commande GSGC_STRINGGFX , %d, %d, %d, %d,%d, %d, %s\n",x,y,font,color,w,h,mess); + #endif + uOLED.putc(GSGC_STRINGGFX); + uOLED.putc(x); + uOLED.putc(y); + uOLED.putc(font); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + uOLED.putc(w); + uOLED.putc(h); + uOLED.printf("%s",mess); + uOLED.putc(0); + ack(); +} -int main() { - char c ; - pc.printf("Enter a character>"); - while(1) { - myled = 0; // turn on - c = pc.getc(); - myled = 1; // turn off - pc.putc(c); - pc.putc(c); // echo twice - pc.putc('\r'); - pc.putc('\n'); - wait(0.5); - pc.printf("Enter a character>"); +void afftexte_text(char x,char y,char font,int color,char* mess) +{ + #ifdef debug + pc.printf("Commande GSGC_STRINGTXT , %d, %d, %d, %d, %s\n",x,y,font,color,mess); + #endif + uOLED.putc(GSGC_STRINGTXT); + uOLED.putc(x); + uOLED.putc(y); + uOLED.putc(font); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + uOLED.printf("%s",mess); + uOLED.putc(0); + ack(); +} + +void affiche_image(char x, char y, char w, char h, char color, unsigned long ad) +{ + #ifdef debug + pc.printf("Commande GSGC_MCIMAGE , %d, %d, %d, %d, %d, %X\n",x,y,w,h,color,ad); + #endif + uOLED.putc('@'); + uOLED.putc(GSGC_MCIMAGE); + uOLED.putc(x); + uOLED.putc(y); + uOLED.putc(w); + uOLED.putc(h); + uOLED.putc(color); + uOLED.putc(ad>>16); + uOLED.putc((ad>>8)&0x0000FF); + uOLED.putc(ad&0x0000FF); + ack(); +} + +void affiche_video(char x, char y, char w, char h, char color, char delay, int frames,unsigned long ad) +{ + #ifdef debug + pc.printf("Commande GSGC_MCVIDEO , %d, %d, %d, %d, %d ,%d %d, %X\n",x,y,w,h,color,delay,frames,ad); + #endif + uOLED.putc('@'); + uOLED.putc(GSGC_MCVIDEO); + uOLED.putc(x); + uOLED.putc(y); + uOLED.putc(w); + uOLED.putc(h); + uOLED.putc(color); + uOLED.putc(delay); + uOLED.putc(frames>>8); + uOLED.putc(frames&0x00FF); + uOLED.putc(ad>>16); + uOLED.putc((ad>>8)&0x0000FF); + uOLED.putc(ad&0x0000FF); + ack(); +} + +void txtBouton(char state, char x, char y, int color, char font, int textcolor, char w, char h, char *s) +{ + #ifdef debug + pc.printf("Commande GSGC_BUTTONTXT , %d, %d, %d, %d, %d ,%d %d, %d, %X, %d\n",state,x,y,color,font,textcolor,w,h,s); + #endif + uOLED.putc(GSGC_BUTTONTXT); + uOLED.putc(state); + uOLED.putc(x); + uOLED.putc(y); + uOLED.putc(color>>8); + uOLED.putc(color&0x00FF); + uOLED.putc(font); + uOLED.putc(textcolor>>8); + uOLED.putc(textcolor&0x00FF); + uOLED.putc(w); + uOLED.putc(h); + uOLED.printf("%s",s); +// uOLED.putc(0); + ack(); +} + +void efface(void) +{ + #ifdef debug + pc.printf("Commande GSGC_CLS\n"); + #endif + uOLED.putc(GSGC_CLS); // efface ecran + ack(); + wait(0.1); +} + + +void inituOLED(void) +{ + reset=0; + wait(0.1); + reset=1; + wait(1.0); + uOLED.putc(GSGC_AUTOBAUD); // autobaud + uOLED.putc(GSGC_AUTOBAUD); +} + + +int main(void) +{ +unsigned char resp; + #ifdef debug + pc.printf("Demo uOLED\n"); + pc.printf("Mode debug actif\n"); + #endif + inituOLED(); + while(1) + { + efface(); + uOLED.putc(GSGC_VERSION); // affiche infos uOLED + uOLED.putc(0x01); // sur ecran et serial + while (uOLED.readable()) + { + resp = uOLED.getc(); // vide buffer + wait_ms(5); + } + wait(1.0); + + efface(); + rectangle(10,10,100,80,RED); // affiche un rectangle rouge plein + penSize(EMPTY); + rectangle(40,40,110,110,WHITE); + penSize(SOLID); + cercle(50,90,30,BLUE); // affiche un cercle bleu plein + triangle(50,10,10,40,100,70,WHITE); + wait(1.0); + + efface(); + ligne(10,10,100,100,RED); + ligne(10,100,100,10,BLUE); + pixel(30,60,WHITE); + pixel(90,150,GREEN); + wait(1.0); + + efface(); + afftexte_text(2,2,FONT3,RED,chaine1); // affiche un texte formate + wait(1.0); + + efface(); + afftexte_graphic(10,12,FONT2,GREEN,2,2,chaine1); // affiche un texte graphique + wait(1.0); + + efface(); + couleur_fond(WHITE); + // txtBouton(UP,5,30,RED,FONT1,WHITE,10,5,"BTN Bleu"); + + efface(); + afftexte_text(2,2,FONT1,RED,chaine1); // affiche un texte formate + opaque(OPAQUE); + afftexte_text(2,30,FONT3,BLUE,chaine2); + opaque(TRANSPARENT); + pc.printf("recommencer : bouton bleu\n"); + while(bouton); + while(!bouton); + + couleur_fond(BLACK); + /* + efface(); + affiche_image(0,0,0x80,0x80,COLOR16,OMER); // OMER + wait(1.0); + */ } + return 0; } + + \ No newline at end of file
diff -r a2d1329d042c -r 791713e36c37 mbed-os.lib --- a/mbed-os.lib Wed Jan 22 12:34:48 2020 +0000 +++ b/mbed-os.lib Sat Mar 13 09:16:08 2021 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#c966348d3f9ca80843be7cdc9b748f06ea73ced0 +https://github.com/ARMmbed/mbed-os/#e4b81f67f939a0c0b11c147ce74aa367271e1279
diff -r a2d1329d042c -r 791713e36c37 uOLEDLIB.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uOLEDLIB.h Sat Mar 13 09:16:08 2021 +0000 @@ -0,0 +1,17 @@ +#include "GSGCdef.h" // commandes uOLED + +unsigned char ack(void); +void couleur_fond(int color); +void rectangle(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned int color); +void cercle(unsigned char x,unsigned char y,unsigned char radius,unsigned int color); +void triangle(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char x3,unsigned char y3,unsigned int color); +void ligne(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned int color); +void opaque(unsigned char mode); +void pixel(unsigned char x1,unsigned char y1,unsigned int color); +void penSize(unsigned char size); +void afftexte_graphic(char x, char y, char font,int color , char w, char h, char * mess); +void afftexte_text(char x,char y,char font,int color,char* mess); +void affiche_image(char x, char y, char w, char h, char color, unsigned long ad); +void affiche_video(char x, char y, char w, char h, char color, char delay, int frames,unsigned long ad); +void efface(void); +void inituOLED(void);