Ken Segler
/
ezLCD4_mbed
Not Complete
Fork of Nucleo_rtos by
Revision 77:cd59ac40b3be, committed 2016-06-23
- Comitter:
- codeman
- Date:
- Thu Jun 23 22:57:30 2016 +0000
- Parent:
- 76:7f2694a47e56
- Commit message:
- Not Complete;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ezLCD405.cpp Thu Jun 23 22:57:30 2016 +0000 @@ -0,0 +1,477 @@ +#include "mbed.h" +#include "ezLCD405.h" + + +void Tx_interrupt(); +void Rx_interrupt(); +void send_line(); +void read_line(); + +Timer timer; + +// MOSI = PA7 +// MISO = PA6 +// SCK = PA5 +// NSS = PA_4 + +SPI device(PA_7, PA_6, PA_5, PA_4); +DigitalOut nss(PA_4); + +// Circular buffers for serial TX and RX data - used by interrupt routines +const int buffer_size = 4096; +// might need to increase buffer size for high baud rates +char tx_buffer[buffer_size]; +char rx_buffer[buffer_size]; +// Circular buffer pointers +// volatile makes read-modify-write atomic +volatile int tx_in=0; +volatile int tx_out=0; +volatile int rx_in=0; +volatile int rx_out=0; +char buf[64]; +uint8_t ExtendedMode=0; + +uint8_t interface = SPI_IF; + +ezLCD4::ezLCD4(PinName tx, PinName rx) : Stream("ezLCD4") , _ser(tx, rx) +{ +// _ser.attach(this,&ezLCD4::Rx_interrupt, Serial::RxIrq); + // _ser.attach(this,&ezLCD4::Tx_interrupt, Serial::TxIrq); + _ser.baud(115200); // default baud rate + status = 0; + +} + +void ezLCD4::Rx_interrupt( void ) +{ +// Loop just in case more than one character is in UART's receive FIFO buffer +// Stop if buffer full +// while ((_ser.readable()) || (((rx_in + 1) % buffer_size) == rx_out)) { +// rx_buffer[rx_in] = _ser.getc(); +// rx_in = (rx_in + 1) % buffer_size; +// } + uint8_t c; + if(_ser.readable()) { + c=_ser.getc(); + //status=c; + // if(c==0xea) + // status=1; + // if(c==0x38) + // pong=1; + /* + if((c & 0xc0)==0x40) { + button=(c & 0x3f); + bState=1; + // beep(5); + } + if((c & 0xc0)==0x80) { + button=(c & 0x3f); + bState=0; + } + */ + + + if(c == 0x81) { + while(!_ser.readable()); + x = _ser.getc(); + while(!_ser.readable()); + x |= _ser.getc() << 7; + while(!_ser.readable()); + y = _ser.getc(); + while(!_ser.readable()); + y = _ser.getc(); + while(!_ser.readable()); + y |= _ser.getc() << 7; + } + + } + return; +} + +// Interupt Routine to write out data to serial port +void ezLCD4::Tx_interrupt( void ) +{ +// led2=1; +// Loop to fill more than one character in UART's transmit FIFO buffer +// Stop if buffer empty + /* + while (( _ser.writeable() ) && (tx_in != tx_out)) { + _ser.putc(tx_buffer[tx_out]); + tx_out = (tx_out + 1) % buffer_size; + } + // led2=0; + return; + */ +} + + + +uint8_t ezLCD4::getByte( void ) +{ + return rx_buffer[rx_out]; +} +uint8_t ezLCD4::getCount( void ) +{ + return rx_in; +} + +void ezLCD4::ezLCD405Init( uint8_t iface ) +{ + /* + while(c!=PONG) { + + _ser.putc(PING); + c=pc.getc(); + } + */ + //writeData(0x00); + interface = iface; + if(interface == SPI_IF) { + nss=1; + device.format(8,3); + device.frequency(10000000); + } + +} +void ezLCD4::showSettings( void ) +{ + writeData(SHOWSETTINGS); +} +void ezLCD4::buzzerOn( void ) +{ + writeData(EZNOW_BUZZER_ON ); +} +void ezLCD4::buzzerOff( void ) +{ + writeData(EZNOW_BUZZER_OFF ); +} + +void ezLCD4::beep( uint8_t duration ) +{ + writeData(EZNOW_BUZZER_BEEP ); + writeData(duration); +} + +void ezLCD4::lightON( void ) +{ + writeData(LIGHT_ON); +} + +void ezLCD4::lightOFF( void ) +{ + writeData(LIGHT_OFF); +} + +void ezLCD4::lightBright( uint8_t bright ) +{ + writeData(LIGHT_BRIGHT); + writeData(bright); +} +void ezLCD4::setTouchProtocol( uint8_t protocol) +{ + writeData(TOUCH_PROTOCOL); + writeData(protocol); +} + +void ezLCD4::putSfIcon( uint8_t icon ) +{ + writeData(PUT_SF_ICON); + writeData(icon); +} + +void ezLCD4::direct( uint8_t c ) +{ + writeData(c); +} + +void ezLCD4::exmode( void ) +{ + writeData(EXMODE); + ExtendedMode=true; +} +void ezLCD4::stdmode( void ) +{ + writeData(STDMODE); + ExtendedMode =false; +} +void ezLCD4::setLayer ( uint8_t layer ) +{ + writeData(SET_LAYER); + writeData(layer); +} +void ezLCD4::setLayerVisible ( uint8_t layer, uint8_t visible ) +{ + writeData(SET_LAYERVISIBLE); + writeData(layer); + writeData(visible); +} +void ezLCD4::setColorKey ( uint16_t color ) +{ + writeData(SET_COLORKEY); + writeData(color & 0x00ff); + writeData((color & 0xff00) >>8); +} +void ezLCD4::SDPutIcon( char *str ) +{ + writeData(SD_PUT_ICON); + while( (char) *str ) + writeData((char) *str++); + writeData(0x00); +} +void ezLCD4::setColor( uint16_t color ) +{ + writeData(SET_COLORH); + writeData(color & 0x00ff); + writeData((color & 0xff00) >>8); +} +void ezLCD4::setBgColor( uint16_t color ) +{ + writeData(SET_BG_COLORH); + writeData(color & 0x00ff); + writeData((color & 0xff00) >>8); +} +void ezLCD4::cls( void ) +{ + writeData(CLS); +} + +void ezLCD4::cls( uint16_t color) +{ + writeData(SET_COLORH); + send16LSB( color ); + writeData(CLS); +} +void ezLCD4::setXY( uint16_t x, uint16_t y) +{ + writeData(SET_XHY); + send16MSB( x ); + if(ExtendedMode == false) + writeData(y & 0x00ff); + else + send16MSB( y ); +} +void ezLCD4::printString( char *str ) +{ + writeData(PRINT_STRING); + while( (char) *str ) + writeData((char) *str++); + writeData(0x00); +} +void ezLCD4::textDirection( uint8_t dir ) +{ + writeData( dir ); +} + +void ezLCD4::printString( uint16_t x, uint16_t y, uint8_t font, uint16_t color, char *str , uint8_t dir, uint8_t efx, uint16_t ocolor) +{ + writeData( dir ); + writeData(SELECT_FONT); + writeData(font); + if(efx==OUTLINE) + { + setXY(x-1,y); + setColor(ocolor); + printString(str); + + setXY(x+1,y); + setColor(ocolor); + printString(str); + + setXY(x,y-1); + setColor(ocolor); + printString(str); + + setXY(x,y+1); + setColor(ocolor); + printString(str); + } + if(efx==SHADOW) + { + setXY(x+1,y+1); + setColor(ocolor); + printString(str); + } + + setXY(x,y); + setColor(color); + printString(str); +} +void ezLCD4::setFont( uint8_t font ) +{ + writeData(SELECT_FONT); + writeData(font); +} + +void ezLCD4::lineTo( uint16_t x , uint16_t y ) +{ + writeData( LINE_TO_XHY ) ; + send16MSB( x ); + if(ExtendedMode == false) + writeData(y & 0x00ff); + else + send16MSB( y ); +} +void ezLCD4::vLine( uint8_t y) +{ + writeData(V_LINE); + writeData(y ); +} +void ezLCD4::hLine( uint8_t x) +{ + writeData(H_LINE); + writeData( x ); +} + +void ezLCD4::hLineH( uint16_t x) +{ + writeData(H_LINEH); + send16MSB( x ); + +} +void ezLCD4::arc(uint16_t radius, uint16_t begin, uint16_t end) +{ + writeData(ARCH); + + writeData((radius & 0xff00) >>8); + writeData(radius & 0x00ff); + begin *=2048/45; + writeData((begin & 0xff00) >>8); + writeData(begin & 0x00ff); + end *=2048/45; + writeData((end & 0xff00) >>8); + writeData(end & 0x00ff); +} +void ezLCD4::box( uint16_t x, uint16_t y) +{ + writeData(BOXH); + send16MSB( x ); + if(ExtendedMode == false) + writeData( y & 0x00ff ); + else + send16MSB( y ); + +} +void ezLCD4::boxFill( uint16_t x, uint16_t y) +{ + + writeData(BOXH_FILL); + send16MSB( x ); + if(ExtendedMode == false) + writeData( y & 0x00ff ); + else + send16MSB( y); +} +void ezLCD4::createTextBox( uint16_t x , uint16_t y, uint16_t w, uint16_t h, uint16_t bcolor, uint16_t fcolor, uint16_t tcolor, uint16_t fsize, uint8_t font, char *str) +{ + setXY(x, y); + setColor(bcolor); + //boxFill(w,h); + setXY(x,y); + setColor(fcolor); + box(w,h); + setFont(font); + printString( x, y, font, tcolor, str , FONT_NORTH , false, 0); +} + +void ezLCD4::buttonsDeleteAll( void ) +{ + writeData( ERASE_ALL_BUTTONS ); +} + +// #define BUTTON_DEF 0xB0 +// 1: ID +// 2: State 0: None, 1: UP, 2: DN, 3: Disabled, 4: Non-Visible +// 3: IconUP +// 4: IconDN +// 5: IconDis +// 6: x0 MSB +// 7: x0 LSB +// 8: y0 +// 9: Width +//10: Height +uint8_t ezLCD4::createButton( uint8_t ID, uint8_t State, uint8_t IconUp, uint8_t IconDn, uint8_t IconDis, uint16_t X, uint16_t Y, uint16_t W, uint16_t H, uint8_t Callback) +{ + writeData(BUTTON_DEF); + writeData(ID); + writeData(State); + writeData(IconUp); + writeData(IconDn); + writeData(IconDis); + send16MSB( X ); + if(ExtendedMode == false) + writeData( Y & 0x00ff ); + else + send16MSB( Y ); + writeData( W ); + writeData( H ); + return true; +} +void ezLCD4::buttonState( uint8_t ID, uint8_t state ) +{ + writeData( BUTTON_STATE ); + writeData( ID ); + writeData( state ); +} + +void ezLCD4::send16MSB( uint16_t val ) +{ + writeData(( val & 0xff00) >>8); + writeData( val & 0x00ff); +} +void ezLCD4::send16LSB( uint16_t val ) +{ + writeData( val & 0x00ff); + writeData(( val & 0xff00) >>8); +} +uint8_t ezLCD4::ping( uint16_t timeout ) +{ + timer.reset(); + writeData(PING); + timer.start(); + while(timer.read_ms() < timeout) { + if( pollTouch(1, 0x00) == 0x38) + return true; + } + timer.stop(); + return timedOut; + +} + + + +uint8_t ezLCD4::pollTouch( uint8_t count, uint8_t cmd ) +{ + uint8_t c; + c = 0x00; + if(interface == SPI_IF) { + nss=0; + for(uint8_t i=0; i< count; i++) + c=device.write(cmd); + nss=1; + } + return c; +} + +uint8_t ezLCD4::writeData(uint8_t c) +{ + if(interface == SERIAL_IF) + _ser.putc(c); + if(interface == SPI_IF) { + nss=0; + device.write(c); + nss=1; + + } +} + +int ezLCD4::_putc( int c) +{ + + return (c); +} + +int ezLCD4::_getc(void) +{ + char r = 0; + return(r); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ezLCD405.h Thu Jun 23 22:57:30 2016 +0000 @@ -0,0 +1,540 @@ +#ifndef _CMDCODES_H_ +#define _CMDCODES_H_ + + + +#define SERIAL_IF 1 +#define SPI_IF 2 + + +// Color Definitions +// R4 R3 R2 R1 | R0 G5 G4 G3 | G2 G1 G0 B4 | B3 B2 B1 B0 +#define RED_0 0x0800 +#define RED_1 0x1000 +#define RED_2 0x2000 +#define RED_3 0x4000 +#define RED_4 0x8000 +#define MAX_RED 0x1F +#define CL_RED(x) (((uint16_t)x) << 11) + +#define GREEN_0 0x0020 +#define GREEN_1 0x0040 +#define GREEN_2 0x0080 +#define GREEN_3 0x0100 +#define GREEN_4 0x0200 +#define GREEN_5 0x0400 +#define MAX_GREEN 0x3F +#define CL_GREEN(x) (((uint16_t)x) << 5) + +#define BLUE_0 0x0001 +#define BLUE_1 0x0002 +#define BLUE_2 0x0004 +#define BLUE_3 0x0008 +#define BLUE_4 0x0010 +#define MAX_BLUE 0x1F +#define NAVY BLUE_4 +#define CL_BLUE(x) ((uint16_t)x) + +#define CL_GRAY(x) (CL_RED(x) | CL_GREEN((x << 1)) | CL_BLUE(x)) + +#define RED CL_RED(MAX_RED) +#define GREEN CL_GREEN(MAX_GREEN) +#define BLUE CL_BLUE(MAX_BLUE) + +#define YELLOW (RED | GREEN) +#define ORANGE (RED | CL_GREEN(MAX_GREEN >> 1)) +#define LIGHT_YELLOW (RED | CL_GREEN(0x3B) | CL_BLUE(0x19)) +#define WHITE (RED | GREEN | BLUE) +#define BLACK 0x0000 +#define GRAY (CL_RED(MAX_RED >> 1) | CL_GREEN(MAX_GREEN >> 1) | CL_BLUE(MAX_BLUE >> 1)) +#define GOLD (GREEN_5 + GREEN_4 + GREEN_3 + RED) + + +// ############################################################################ +// ## EZLCD COMMAND CODES ################################################### +// ############################################################################ + +#define EXMODE 0xFB +#define STDMODE 0xFC +#define GETSERIAL 0xFD +#define SHOWSETTINGS 0xFE +#define CALIBRATE 0xEF + +#define CLS 0x21 +#define LIGHT_ON 0x22 +#define LIGHT_OFF 0x23 +#define SET_COLOR 0x24 +#define SET_XY 0x25 +#define PLOT 0x26 +#define PLOT_XY 0x27 +#define LINE_TO_XY 0x28 +#define CIRCLE_R 0x29 +#define SCR_BMP 0x2A +#define SELECT_FONT 0x2B +#define PRINT_CHAR 0x2C +#define PRINT_STRING 0x2D +#define PUT_BITMAP 0x2E +#define ARC 0x2F + +#define PIE 0x30 + +#define SET_LAYER 0x31 +#define SET_COLORKEY 0x32 +#define SET_LAYERVISIBLE 0x33 + +#define SET_BG_COLOR 0x34 +#define SAVE_POSITION 0x35 +#define RESTORE_POSITION 0x36 +#define CIRCLE_R_FILL 0x39 +#define PRINT_CHAR_BG 0x3C +#define PRINT_STRING_BG 0x3D + +#define H_LINE 0x40 +#define V_LINE 0x41 +#define BOX 0x42 +#define BOX_FILL 0x43 + +#define PICTURE_ROM 0x50 +#define PUT_ICON 0x57 +#define PUT_SF_ICON 0x58 + +#define SET_X 0x5E +// 1: x +#define SET_Y 0x5F +// 1: y + +#define FONT_NORTH 0x60 +#define FONT_EAST 0x61 +#define FONT_SOUTH 0x62 +#define FONT_WEST 0x63 + +#define SET_XH 0x6E +// 1: xh 2: xl + +#define SD_PUT_ICON 0x70 +// 1 - 64: NULL terminated path +#define SD_FILE_OPEN 0x71 +// 1: File ID (1 to 255) +// 2 - 65: NULL terminated path +// Response: +// 0: 0x3F +// 1: 0 = Error, ID = Success +#define SD_FILE_CLOSE 0x72 +// 1: File ID (1 to 255) +#define SD_FILE_CLOSE_ALL 0x73 +#define SD_FILE_GET_SIZE 0x74 +// 1: File ID (1 to 255) +// Response: +// 0: 0x3D +// 1-4: File Size (0 = Error) +// or +// 0: 0x3E - Error +#define SD_FILE_READ 0x75 +// 1: File ID (1 to 255) +// 2-5: Number of Bytes +// Response: +// 0: 0x3C +// 1-n: Bytes Read +// or +// 0: 0x3E - Error +#define SD_FILE_CREATE 0x76 +// 1: File ID (1 to 255) +// 2 - 65: NULL terminated path +// Response: +// 0: 0x3F +// 1: 0 = Error, ID = Success +#define SD_SCREEN_CAPTURE 0x44 +// Response: +// 0: 0x3B - Success +// 0x3E - Error + +#define SD_FOLDER_CREATE 0x46 +// 1 - 64: NULL terminated path +// Response: +// 0: 0x3B - Success +// 0x3E - Error +#define SD_FOLDER_DELETE 0x4D +// 1 - 64: NULL terminated path +// Response: +// 0: 0x3A - Success +// 0x3E - Error +#define SD_FORMAT 0x4F +// 1 - 5: File system (FAT12, FAT16, FAT32) +// Response: +// 0: 0x3A - Success +// 0x3E - Error +#define SD_FILE_WRITE 0x77 +// 1: File ID (1 to 255) +// 2-5: Number of Bytes (n) +// 6-(n+5): Data to write +// Response: +// 0: 0x3B - Success +// 0x3E - Error + +#define SD_SPACE_INFO 0x48 +// 1: What (1: Free Space, 2: Used Space, 3: in Bad Sectors, Other: Total Space +// Response: +// 0: 0x3D +// 1-4: Space Info (0 = Error) +// or +// 0: 0x3E - Error + +#define SD_INSERTED 0x49 +// Response: +// 0: 0x3D - Inserted +// 0: 0x3E - Error + +#define SD_SIZE 0x78 +// Response: +// 0: 0x3D +// 1-4: SD Size (0 = Error) +// or +// 0: 0x3E - Error + +#define SD_FILE_LIST 0x79 +// 1 - 64: NULL terminated dir path +// Response: +// 0: 0x3A +// 1 - whatever: NULL terminated dir string +// Files separated by new_line +// or +// 0: 0x3E - Error + +#define SD_FIND_FIRST 0x4A +// 1 - F_MAXLNAME: NULL terminated dir path +// Response: +// 0: 0x3A +// 1 - whatever: NULL terminated string +// or +// 0: 0x3E - Error +#define SD_FIND_NEXT 0x4B +// Response: +// 0: 0x3A +// 1 - whatever: NULL terminated string +// or +// 0: 0x3E - Error + +#define SD_FILE_REWIND 0x7A +// 1: File ID (1 to 255) +// Response: +// 0: 0x39 - Success +// 0x3E - Error +#define SD_FILE_TELL 0x7B +// 1: File ID (1 to 255) +// Response: +// 0: 0x3D +// 1-4: Position +// or +// 0: 0x3E - Error + +#define SD_FILE_SEEK 0x7C +// 1: File ID (1 to 255) +// 2-5: Signed Offset +// 6: whence +// SD_SEEK_SET 0 File beginning +// SD_SEEK_CUR 1 Current file pointer position +// SD_SEEK_END 2 End-of-file +// Response: +// 0: 0x39 - Success +// 0x3E - Error +#define SD_SEEK_SET 0 // File beginning +#define SD_SEEK_CUR 1 // Current file pointer position +#define SD_SEEK_END 2 // End-of-file + +#define SD_FILE_DELETE 0x7D +// 1 - 64: NULL terminated path +// Response: +// 0: 0x3A - Success +// 0x3E - Error + +#define SD_RAW_READ 0x7E +// 1: 0xA5 +// 2-5: Address +// 6-9: Length +// Response: +// 0: 0x3C +// 1-n: Bytes Read +// or +// 0: 0x3E - Error + +#define SD_RAW_WRITE 0x7F +// 1: 0xA5 +// 2-5: Address +// 6-9: Length +// 10-(n+9): Data to write +// Response: +// 0: 0x3B - Success +// 0x3E - Error + +// TO DO in SD: +// f_setattr +// f_getattr + +#define LIGHT_BRIGHT 0x80 +#define PING 0x83 +// Response: +// 0: 0x38 +#define SET_COLORH 0x84 +#define SET_XHY 0x85 +#define PLOT_XHY 0x87 +#define LINE_TO_XHY 0x88 +#define CIRCLE_RH 0x89 +#define PUT_COMPR_BMPH 0x8D // Not implemented +#define ARCH 0x8F + +#define PIEH 0x90 +#define SET_BG_COLORH 0x94 +#define CIRCLE_RH_FILL 0x99 +#define PUT_BITMAPH 0x9E + +#define H_LINEH 0xA0 +#define BOXH 0xA2 +#define BOXH_FILL 0xA3 + +// Touch +#define BUTTON_DEF 0xB0 +// 1: ID +// 2: State 0: None, 1: UP, 2: DN, 3: Disabled, 4: Non-Visible +// 3: IconUP +// 4: IconDN +// 5: IconDis +// 6: x0 MSB +// 7: x0 LSB +// 8: y0 +// 9: Width +//10: Height +#define BUTTON_STATE 0xB1 +// 1: ID +// 2: State +#define TOUCH_PROTOCOL 0xB2 +// 1: Protocoles on/off (coded in 8 bits) +#define ALL_BUTTONS_UP 0xB3 +#define ERASE_ALL_BUTTONS 0xB4 + +#define USB_DISABLE_RS232 0xC0 +#define USB_DISABLE_SPI 0xC1 +#define USB_ENABLE_RS232 0xC2 +#define USB_ENABLE_SPI 0xC3 + +// ezNOW Buzzer +#define EZNOW_BUZZER_OFF 0xD0 +#define EZNOW_BUZZER_ON 0xD1 +#define EZNOW_BUZZER_BEEP 0xD2 +// 1: Beep time [0.01s] + +// Serial EEPROM +#define SE_BYTE_OUT 0xE0 +#define SE_BYTE_WR 0xE1 +#define SE_DATA_OUT 0xE2 +#define SE_WAIT_END 0xE3 +#define SE_ERASE_SECTOR 0xE4 +#define SE_BYTE_RD 0xE5 +#define SE_BULK_ERASE 0xE6 +#define SE_PROGRAM_PAGE 0xE7 +#define SE_READ_BAT 0xE8 + +// AVR (ATmega8) Flash Programming +#define AVR_PROG 0xF0 +// 1 - 15: password +#define EZNOW_AVR_PROG 0xF3 +// 1: Speed +// 2 - 16: password +// The following AVR commands are available only +// after AVR_PROG or EZNOW_AVR_PROG command has been received +#define AVR_PROG_CMD 0xF1 +// 1 - 4: Bytes 1 - 4 of AVR Serial Programming Instruction +#define AVR_PROG_CMD_FAST 0xF4 +// 1 - 4: Bytes 1 - 4 of AVR Serial Programming Instruction +#define AVR_PROG_CMD_NO_DELAY 0xF6 +// 1 - 4: Bytes 1 - 4 of AVR Serial Programming Instruction +#define AVR_PROG_CMDS_PACK 0xF7 +// 1 No of Prog commands +// 2 - 257 (64*4-1) Prog commands (4 bytes each) +#define AVR_WRITE_POLL 0xF8 +// 1 - Command +// 2 - Address MSB +// 3 - Address LSB +// 4 - Data +#define AVR_WRITE_PAGE 0xF2 +// 1: Page No +// 2 - 65: Bytes 0 - 63 of the page +#define AVR_SUCCESS 0xF5 +#define RESET_EZLCD 0xFA + +// ############################################################################ +// ## EZLCD OUTPUT CODES #################################################### +// ############################################################################ + +// Touch Screen Output +#define ID_TOUCH_X 0x81 +#define ID_TOUCH_Y 0x82 +#define ID_TOUCH_PEN_UP 0x83 +//#define ID_CAL_TOUCH_X 0x84 +//#define ID_CAL_TOUCH_Y 0x85 +#define ID_BUTTON_DN 0x86 +#define ID_BUTTON_LEAVE 0x87 + +#define EZLCD_READY 0xEA +#define PONG 0x38 + +// ############################################################################ +// ## OTHER DEFINITIONS ##################################################### +// ############################################################################ + +#define STX 0x02 +#define ETX 0x03 +#define ACK 0x06 +#define NAK 0x15 + +#define TOUCH_EZ_BUTTON 0x01 +#define TOUCH_CU_BUTTON 0x02 +#define TOUCH_CALIBRATED 0x40 +#define timedOut 0x2 +#define OUTLINE 1 +#define SHADOW 2 + +class ezLCD4: public Stream +{ +public: + /** Create a new interface to a ezLCD3xx display + * @param tx -- mbed transmit pin + * @param rx -- mbed receive pin + */ + volatile uint8_t status; + volatile uint8_t pong; + volatile uint8_t button; + volatile uint8_t bState; + volatile uint16_t x,y; + ezLCD4(PinName tx, PinName rx); + /** + * + * + */ + void Rx_interrupt( void ); + void Tx_interrupt( void ); + void send_line(); + /** + * + * + */ + uint8_t getByte( void ); + uint8_t getCount( void ); + void cls( void ); + void cls( uint16_t color); + void lightON( void ); + void lightOFF( void ); + void lightBright( uint8_t bright ); + void setTouchProtocol( uint8_t protocol); + uint16_t getX( void ); + uint16_t getY( void ); + void putSfIcon( uint8_t icon ); + + void vLine( uint8_t y); + void hLine( uint8_t x); + void hLineH( uint16_t x); + void setLayer ( uint8_t layer ); + void setLayerVisible ( uint8_t layer, uint8_t visible ); + void setColorKey ( uint16_t color ); + void SDPutIcon( char *str ); + void textDirection( uint8_t dir ); + void buttonState( uint8_t ID, uint8_t state ); + void buttonsDeleteAll( void ); + void showSettings( void ); + void buzzerOn( void ); + void buzzerOff( void ); + void lineTo( uint16_t x , uint16_t y ); + void beep( uint8_t duration ); + /** + * + * + */ + void printString( char *str ); + /** + * + * + */ + void printString( uint16_t x, uint16_t y, uint8_t font, uint16_t color, char *str , uint8_t dir, uint8_t efx, uint16_t ocolor); + /** + * + * + */ + void ezLCD405Init( uint8_t iface ); + /** + * + * + */ + void exmode( void ); + /** + * + * + */ + void stdmode( void ); + /** + * + * + */ + void setColor(uint16_t color); + /** + * + * + */ + void setBgColor(uint16_t color); + /** + * + * + */ + void setFont(unsigned char font); + /** + * + * + */ + void direct( unsigned char c ); + /** + * + * + */ + void setXY( uint16_t x, uint16_t y); + /** + * + * + */ + void box( uint16_t x, uint16_t y); + /** + * + * + */ + void boxFill( uint16_t x, uint16_t y); + /** + * + * + */ + void arc(uint16_t radius, uint16_t begin, uint16_t end); + /** + * + * + */ + uint8_t createButton( uint8_t ID, uint8_t State, uint8_t IconUp, uint8_t IconDn, uint8_t IconDis, uint16_t X, uint16_t Y, uint16_t W, uint16_t H, uint8_t Callback); + /** + * + * + */ + uint8_t pollTouch( uint8_t count , uint8_t cmd); + /** + * + * + */ + uint8_t ping( uint16_t timeout ); + + void createTextBox( uint16_t x , uint16_t y, uint16_t w, uint16_t h, uint16_t bcolor, uint16_t fcolor, uint16_t tcolor, uint16_t fsize, uint8_t font, char *str); +private: + Serial _ser; + virtual int _putc(int c); + virtual int _getc(); + void send16MSB( uint16_t val ); + void send16LSB( uint16_t val ); + uint8_t writeData(uint8_t c); +}; + + + +#endif
--- a/main.cpp Thu Apr 16 08:22:08 2015 +0000 +++ b/main.cpp Thu Jun 23 22:57:30 2016 +0000 @@ -1,47 +1,321 @@ + #include "mbed.h" -#include "rtos.h" +#include "ezLCD405.h" -DigitalOut led(LED1); +//DigitalOut led(LED1); InterruptIn button(USER_BUTTON); - +Serial pc(SERIAL_TX, SERIAL_RX); +uint8_t counter; uint32_t button_pressed; -Thread *thread2; +volatile uint32_t tick; +//Thread *thread2; +uint8_t buttonPressed; +uint8_t buttState[10]; + +//ezLCD4 lcd(PB_6,PA_10); //tx,rx + +ezLCD4 lcd(PG_14,PG_9); //tx,rx +//ezLCD4 lcd2(PA_11, PA_12); +const char *textBoxData[3][13]; + + +char temp[10]; +uint16_t count, ocount; +uint16_t ox, oy; +uint32_t countdown; +void drawScreen( void ); void button_press(void) { - thread2->signal_set(0x1); + pc.printf("Button Press\n"); + lcd.showSettings(); +// lcd.printString(12,14,3, 0x0001, "mbed RTOS ezLCD405 Demo"); +// lcd.printString(10,12,3,WHITE,"mbed RTOS ezLCD405 Demo"); + + //lcd.boxHFill(319,234); +// thread2->signal_set(0x1); } void led_thread(void const *argument) { while (true) { - led = !led; - Thread::wait(1000); + // led = !led; +// Thread::wait(100); } } void button_thread(void const *argument) { while (true) { - Thread::signal_wait(0x1); +// Thread::signal_wait(100); button_pressed++; } } + +void drawFrame(uint16_t sx , uint16_t sy, uint16_t ex , uint16_t ey , uint16_t topColor, uint16_t bottomColor, uint8_t radius) +{ + lcd.setXY(sx, sy); + lcd.setColor(topColor); + lcd.setXY(sx+radius, sy+radius); + lcd.arc(radius,270,0); + lcd.setXY(sx+radius, sy); + lcd.lineTo(ex-radius,sy); //top + lcd.setXY(sx, sy+radius); + lcd.lineTo(sx,ey-radius); //left + lcd.setXY(sx+radius, ey-radius); + lcd.arc(radius,180,270); + + lcd.setXY(sx+radius, ey); + lcd.setColor(bottomColor); + lcd.lineTo(ex-radius,ey); //bottom + lcd.setXY(ex-radius, ey-radius); + lcd.arc(radius,90,180); + lcd.setXY(ex, ey-radius); + lcd.lineTo(ex,sy+radius); //right + lcd.setXY(ex-radius, sy+radius); + lcd.arc(radius,0,90); +} +void drawScreen( void ) +{ + + lcd.setLayer(1); + lcd.setTouchProtocol( TOUCH_EZ_BUTTON ); + + lcd.createTextBox( 250 , 75, 500, 350, BLACK, GRAY, WHITE, 1, 6, " TextBox Test"); + lcd.setFont(4); + lcd.printString(75,5,2, YELLOW, "mbed ezLCD-405", FONT_NORTH, OUTLINE, WHITE ); + + + count =0 ; + ocount=0; + lcd.status=0; + + lcd.createButton( 0, 1, 0 , 1, 1, 10, 60, 200, 50, 0); + lcd.createButton( 1, 1, 2 , 3, 1, 10, 120, 200, 50, 0); + lcd.createButton( 2, 1, 4 , 5, 1, 10, 180, 200, 50, 0); + lcd.createButton( 3, 1, 6 , 7, 1, 10, 240, 200, 50, 0); + + + // lcd.createButton( 4, 1, 9 , 10, 1, 10, 300, 200, 50, 0); +} + +void specScreen( void ) +{ + lcd.buttonsDeleteAll(); + lcd.cls(BLACK); + + lcd.createButton( 10, 1, 10 , 11, 10, 10, 420, 200, 50, 0); + lcd.printString(0,40,6,WHITE,"STM32F429 Cortex-4 Processor", FONT_NORTH, false, 0 ); + lcd.printString(0,70,6,WHITE,"5.6\" 640x480 16-bit Color TFT Display", FONT_NORTH, false, 0 ); + lcd.printString(0,100,6,WHITE,"Resistive or Capacitive Touch", FONT_NORTH, false, 0 ); + lcd.printString(0,130,6,WHITE,"SD Card Socket QuadBit SDIO", FONT_NORTH, false, 0 ); + lcd.printString(0,160,6,WHITE,"Battery Backed RTC", FONT_NORTH, false, 0 ); + lcd.printString(0,190,6,WHITE,"Expansion Header With I2C/SPI/UART", FONT_NORTH, false, 0 ); + + wait(.5); + + while(lcd.pollTouch(1, 0x00)!=0x8a); + lcd.buttonsDeleteAll(); + lcd.cls(BLACK); + buttState[2]=1; + drawScreen(); +} +void fontDemo( void ) +{ + lcd.buttonsDeleteAll(); + lcd.cls(BLACK); + + lcd.createButton( 10, 1, 10 , 11, 10, 10, 420, 200, 50, 0); + + + lcd.printString(10,12,6,RED,"ezLCD-405 Font Demo", FONT_NORTH, OUTLINE, WHITE ); + + lcd.printString(10,60,1,BLUE,"ezLCD-405 ", FONT_NORTH, SHADOW, WHITE ); + lcd.printString(10,100,2,BLUE,"ezLCD-405 ", FONT_NORTH, false, 0 ); + lcd.printString(10,150,3,BLUE,"ezLCD-405 ", FONT_NORTH, false, 0 ); + lcd.printString(10,200,4,BLUE,"ezLCD-405 ", FONT_NORTH, false, 0 ); + lcd.printString(10,250,5,BLUE,"ezLCD-405 ", FONT_NORTH, false, 0 ); + lcd.printString(10,300,6,BLUE,"ezLCD-405 ", FONT_NORTH, false, 0 ); + lcd.printString(10,350,7,BLUE,"ezLCD-405 ", FONT_NORTH, false, 0 ); + lcd.printString(10,400,8,BLUE,"ezLCD-405 ", FONT_NORTH, false, 0 ); + +// Thread::wait(5000); + wait(1); + while(lcd.pollTouch(1, 0x00)!=0x8a); + lcd.buttonsDeleteAll(); + lcd.cls(BLACK); + buttState[1]=1; + drawScreen(); +} +void imageDemo( void ) +{ + lcd.buttonsDeleteAll(); + lcd.cls(BLACK); + + lcd.printString(13,15,2, 0x0001, "ezLCD-405 Image Demo", FONT_NORTH, false, 0 ); + lcd.printString(10,12,2,WHITE,"ezLCD-405 Image Demo", FONT_NORTH, false, 0); + lcd.setXY(10,240); + lcd.putSfIcon(5); +// Thread::wait(2000); +// lcd.cls(BLACK); + lcd.setXY(10,240); + lcd.putSfIcon(6); +// Thread::wait(2000); +// lcd.cls(BLACK); + lcd.setXY(10,240); + lcd.putSfIcon(7); +// Thread::wait(2000); + lcd.cls(BLACK); + + drawScreen(); +} + int main() { - Thread thread(led_thread); - thread2 = new Thread(button_thread); + textBoxData[0][0] = "The ezLCD-405" ; + textBoxData[1][0] = " " ; + textBoxData[2][0] = "0123456789012" ; + + button.mode(PullUp); + button.fall(&button_press); + pc.baud(115200); + lcd.ezLCD405Init(SPI_IF); + pc.printf("Start of Main\n"); + pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); + lcd.setLayerVisible(0,1); + lcd.setLayerVisible(1,1); + lcd.setLayer(1); + lcd.setColorKey(0x0000); + while(lcd.ping(100) !=1); + lcd.lightOFF(); + + lcd.exmode(); + lcd.cls(BLACK); + lcd.setLayer(0); + lcd.setXY(0,0); + lcd.SDPutIcon("ezlcd405.bmp"); + lcd.textDirection( FONT_NORTH ); + lcd.lightON(); +// thread2 = new Thread(button_thread); + buttState[0]=1; + buttState[1]=1; + buttState[2]=1; + buttState[3]=1; + buttState[4]=1; + buttState[5]=1; + + drawScreen(); + + while(1) { + //wait(.05); + buttonPressed = lcd.pollTouch(1, 0x00); + + if((buttonPressed & 0x40) == 0x40) { + if(buttState[buttonPressed & 0x0f] == 1) { + lcd.buttonState(buttonPressed & 0x0f, 2); + buttState[buttonPressed & 0x0f] = 2; + } + } + - printf("mbed RTOS example\n"); - + if((buttonPressed & 0x80) == 0x80) { + if(buttState[buttonPressed & 0x0f] == 2) { + lcd.buttonState(buttonPressed & 0x0f, 1); + buttState[buttonPressed & 0x0f] = 1; + } + } + if(buttState[2]==2) { + specScreen(); + } + if(buttState[1]==2) { + fontDemo(); + } + if(buttState[3]==2) { + lcd.showSettings(); + wait(5); + drawScreen(); + } + lcd.setFont(3); + lcd.setXY(20,300); + count++; + lcd.setColor(WHITE); + sprintf(temp, "%d", count); + lcd.printString(temp); + //wait(.05); + lcd.setXY(20,300); + lcd.setColor(BLACK); + lcd.boxFill(200,400); + wait(.02); + +// lcd.printString(temp); + } + + drawFrame(100 , 300, 300 , 400 , WHITE, GRAY, 5); + drawFrame(100 +5 , 300+5 , 300-5 , 400-5 , GRAY, WHITE, 5); + + ocount=0; + count=0; + //lcd.setBgColorH(BLUE); + while(1) { + if(lcd.status == 1) + drawScreen(); + //pc.printf("%d %d \n",lcd.x, lcd.y); + sprintf(temp,"%d",count); + if(lcd.button==0 && lcd.bState==1) { + fontDemo(); + } + + if(lcd.button==1 && lcd.bState==1) { + imageDemo(); + } + if(lcd.button==2 && lcd.bState==1) { + // lcd.buttonState(lcd.button, 2); +// lcd.buttonsDeleteAll(); +// lcd.showSettings(); +// Thread::wait(5000); +// drawScreen(); + } + if(lcd.button==3 && lcd.bState==1) { + // lcd.buttonState(lcd.button, 2); + //specScreen(); + } + if(count != ocount) { + lcd.setXY(0,0); + lcd.SDPutIcon("100_Single_Area.ezp"); + //lcd.printString(400, 100, 1, RED, temp); + // lcd.printString(400, 200, 1, RED, temp); + // lcd.printString(400, 300, 1, GREEN, temp); + // lcd.printString(400, 400, 1, GREEN, temp); + ocount=count; + } + countdown--; + if(countdown == 0) { + lcd.setXY(0,0); + lcd.SDPutIcon("100_Single_Area_return.ezp"); + // lcd.printString(400, 100, 1, BLACK, temp); + // lcd.printString(400, 200, 1, BLACK, temp); +// lcd.printString(400, 300, 1, BLACK, temp); +// lcd.printString(400, 400, 1, BLACK, temp); + + + + + count++; + } + + } button_pressed = 0; button.fall(&button_press); - + + while (true) { - Thread::wait(6000); - printf("During the last 6 seconds, the Button was pressed %d times\n", button_pressed); +// Thread::wait(6000); + //lcd.printString("hello"); + lcd.direct(PRINT_STRING); + printf("During the last 6 seconds, the Button was pressed %d times\n", button_pressed); + lcd.direct(0x00); fflush(stdout); button_pressed = 0; }
--- a/mbed-rtos.lib Thu Apr 16 08:22:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/teams/ST/code/mbed-rtos/#83895f30f8f2
--- a/mbed.bld Thu Apr 16 08:22:08 2015 +0000 +++ b/mbed.bld Thu Jun 23 22:57:30 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file