# HG changeset patch # User David Douard # Date 1476137660 -7200 # Node ID 55021f3f192962e14295ae4008770f869ee427fd # Parent 5cf4034ba4e07faecaa945cf390bdfa0fdb169b9 pff so many stuff let's break everything again diff -r 5cf4034ba4e0 -r 55021f3f1929 lib/unigraphic/Mono19x27.h --- a/lib/unigraphic/Mono19x27.h Fri Sep 23 21:12:43 2016 +0200 +++ b/lib/unigraphic/Mono19x27.h Tue Oct 11 00:14:20 2016 +0200 @@ -514,7 +514,7 @@ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Char '8' - 16, + 15, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x0c, 0x00, diff -r 5cf4034ba4e0 -r 55021f3f1929 lib/unigraphic/Protocols.h --- a/lib/unigraphic/Protocols.h Fri Sep 23 21:12:43 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,163 +0,0 @@ - /* mbed UniGraphic library - Abstract protocol class - * Copyright (c) 2015 Giuliano Dianda - * Released under the MIT License: http://mbed.org/license/mit - */ - -/** @file Protocols.h -*/ -#ifndef Protocols_H -#define Protocols_H - -#include "mbed.h" - -#define RGB24to16(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue -#define BGR2RGB(color) (((color&0x1F)<<11) | (color&0x7E0) | ((color&0xF800)>>11)) - -#define FLIP_NONE 0 -#define FLIP_X 1 -#define FLIP_Y 2 - -//#define USE_CS - -/** Protocol types -*/ -#include "platform.h" - -#if DEVICE_PORTINOUT -enum proto_t { - PAR_8 /**< Parallel 8bit, port pins 0 to 7 */ - ,PAR_16 /**< Parallel 16bit, port pins 0 to 15 */ - ,BUS_8 /**< Parallel 8bit, scattered pins */ - ,BUS_16 /**< Parallel 16bit, scattered pins */ - ,SPI_8 /**< SPI 8bit */ - ,SPI_16 /**< SPI 16bit */ -}; -#else -enum proto_t { - BUS_8 /**< Parallel 8bit, scattered pins */ - ,BUS_16 /**< Parallel 16bit, scattered pins */ - ,SPI_8 /**< SPI 8bit */ - ,SPI_16 /**< SPI 16bit */ -}; -#endif - - -/** Abstract interface class for spi and parallel protocols -*/ -class Protocols -{ - public: - - /** Send 8bit command to display controller - * - * @param cmd: byte to send - * - */ - virtual void wr_cmd8(unsigned char cmd) = 0; - - /** Send 8bit data to display controller - * - * @param data: byte to send - * - */ - virtual void wr_data8(unsigned char data) = 0; - - /** Send 2x8bit command to display controller - * - * @param cmd: halfword to send - * - */ - virtual void wr_cmd16(unsigned short cmd) = 0; - - /** Send 2x8bit data to display controller - * - * @param data: halfword to send - * - */ - virtual void wr_data16(unsigned short data) = 0; - - /** Send 16bit pixeldata to display controller - * - * @param data: halfword to send - * - */ - virtual void wr_gram(unsigned short data) = 0; - - /** Send same 16bit pixeldata to display controller multiple times - * - * @param data: halfword to send - * @param count: how many - * - */ - virtual void wr_gram(unsigned short data, unsigned int count) = 0; - - /** Send array of pixeldata shorts to display controller - * - * @param data: unsigned short pixeldata array - * @param lenght: lenght (in shorts) - * - */ - virtual void wr_grambuf(unsigned short* data, unsigned int lenght) = 0; - - /** Read 16bit pixeldata from display controller (with dummy cycle) - * - * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit - * @returns 16bit color - */ - virtual unsigned short rd_gram(bool convert) = 0; - - /** Read 4x8bit register data (with dummy cycle) - * @param reg the register to read - * @returns data as uint - * - */ - virtual unsigned int rd_reg_data32(unsigned char reg) = 0; - - /** Read 3x8bit ExtendedCommands register data - * @param reg the register to read - * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers - * @returns data as uint - * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode - */ - virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) = 0; - - /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent - * for PAR protocols: a signle RD bit toggle - * for SPI8: 8clocks - * for SPI16: 16 clocks - */ - virtual void dummyread () = 0; - - /** ILI932x specific, select register for a successive write or read - * - * @param reg register to be selected - * @param forread false = a write next (default), true = a read next - * @note forread only used by SPI protocols - */ - virtual void reg_select(unsigned char reg, bool forread =false) = 0; - - /** ILI932x specific, write register with data - * - * @param reg register to write - * @param data 16bit data - */ - virtual void reg_write(unsigned char reg, unsigned short data) = 0; - - /** ILI932x specific, read register - * - * @param reg register to be read - * @returns 16bit register value - */ - virtual unsigned short reg_read(unsigned char reg) = 0; - - /** HW reset sequence (without display init commands) - */ - virtual void hw_reset() = 0; - - /** Set ChipSelect high or low - * @param enable 0/1 - */ - virtual void BusEnable(bool enable) = 0; - -}; -#endif \ No newline at end of file diff -r 5cf4034ba4e0 -r 55021f3f1929 lib/unigraphic/SPI8.cpp --- a/lib/unigraphic/SPI8.cpp Fri Sep 23 21:12:43 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,209 +0,0 @@ - /* mbed UniGraphic library - SPI8 protocol class - * Copyright (c) 2015 Giuliano Dianda - * Released under the MIT License: http://mbed.org/license/mit - * - * Derived work of: - * - * mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller - * Copyright (c) 2013 Peter Drescher - DC2PD - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "SPI8.h" - - -SPI8::SPI8(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC) - : _CS(CS), _spi(mosi, miso, sclk), _reset(reset), _DC(DC) -{ - _reset = 1; - _DC=1; - _CS=1; - _spi.format(8,0); // 8 bit spi mode 0 - _spi.frequency(Hz); - hw_reset(); -} - -void SPI8::wr_cmd8(unsigned char cmd) -{ - _DC.write(0); // 0=cmd - _spi.write(cmd); // write 8bit - _DC.write(1); // 1=data next -} -void SPI8::wr_data8(unsigned char data) -{ - _spi.write(data); // write 8bit -} - -void SPI8::wr_cmd16(unsigned short cmd) -{ - _DC.write(0); // 0=cmd - _spi.write(cmd>>8); // write 8bit - _spi.write(cmd&0xFF); // write 8bit - _DC.write(1); // 1=data next -} -void SPI8::wr_data16(unsigned short data) -{ - _spi.write(data>>8); // write 8bit - _spi.write(data&0xFF); // write 8bit -} -void SPI8::wr_gram(unsigned short data) -{ - _spi.write(data>>8); // write 8bit - _spi.write(data&0xFF); // write 8bit -} -void SPI8::wr_gram(unsigned short data, unsigned int count) -{ - if((data>>8)==(data&0xFF)) - { - count<<=1; - while(count) - { - _spi.write(data); // write 8bit - count--; - } - } - else - { - while(count) - { - _spi.write(data>>8); // write 8bit - _spi.write(data&0xFF); // write 8bit - count--; - } - } -} -void SPI8::wr_grambuf(unsigned short* data, unsigned int lenght) -{ - while(lenght) - { - _spi.write((*data)>>8); // write 8bit - _spi.write((*data)&0xFF); // write 8bit - data++; - lenght--; - } -} -unsigned short SPI8::rd_gram(bool convert) -{ - unsigned int r=0; - _spi.write(0); // whole first byte is dummy - r |= _spi.write(0); - r <<= 8; - r |= _spi.write(0); - if(convert) - { - r <<= 8; - r |= _spi.write(0); - // gram is 18bit/pixel, if you set 16bit/pixel (cmd 3A), during writing the 16bits are expanded to 18bit - // during reading, you read the raw 18bit gram - r = RGB24to16((r&0xFF0000)>>16, (r&0xFF00)>>8, r&0xFF);// 18bit pixel padded to 24bits, rrrrrr00_gggggg00_bbbbbb00, converted to 16bit - } - _CS = 1; // force CS HIG to interupt the "read state" - _CS = 0; - return (unsigned short)r; -} -unsigned int SPI8::rd_reg_data32(unsigned char reg) -{ - wr_cmd8(reg); - unsigned int r=0; - - r |= _spi.write(0); // we get only 7bit valid, first bit was the dummy cycle - r <<= 8; - r |= _spi.write(0); - r <<= 8; - r |= _spi.write(0); - r <<= 8; - r |= _spi.write(0); - r <<= 1; // 32bits are aligned, now collecting bit_0 - r |= (_spi.write(0) >> 7); - // we clocked 7 more bit so ILI waiting for 8th, we need to reset spi bus - _CS = 1; // force CS HIG to interupt the cmd - _CS = 0; - return r; -} -unsigned int SPI8::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) -{ - unsigned int r=0; - for(int regparam=1; regparam<4; regparam++) // when reading EXTC regs, first parameter is always dummy, so start with 1 - { - wr_cmd8(SPIreadenablecmd); // spi-in enable cmd, 0xD9 (ili9341) or 0xFB (ili9488) or don't know - wr_data8(0xF0|regparam); // in low nibble specify which reg parameter we want - wr_cmd8(reg); // now send cmd (select register we want to read) - r <<= 8; - r |= _spi.write(0); - // r = _spi.write(0) >> 8; for 16bit - } - _CS = 1; // force CS HIG to interupt the cmd - _CS = 0; - return r; -} -// ILI932x specific -void SPI8::dummyread() -{ - _spi.write(0); // dummy read -} -// ILI932x specific -void SPI8::reg_select(unsigned char reg, bool forread) -{ - _CS = 1; //fixme: really needed? - _CS = 0; //fixme: really needed? - _spi.write(0x70); - _spi.write(0); // write MSB - _spi.write(reg); // write LSB - _CS = 1; //fixme: really needed? - _CS = 0; //fixme: really needed? - if(forread) _spi.write(0x73); - else _spi.write(0x72); -} -// ILI932x specific -void SPI8::reg_write(unsigned char reg, unsigned short data) -{ - _CS = 1; //fixme: really needed? - _CS = 0; //fixme: really needed? - _spi.write(0x70); - _spi.write(0); // write MSB - _spi.write(reg); // write LSB - _CS = 1; //fixme: really needed? - _CS = 0; //fixme: really needed? - _spi.write(0x72); - _spi.write(data>>8); - _spi.write(data&0xFF); -} -// ILI932x specific -unsigned short SPI8::reg_read(unsigned char reg) -{ - unsigned short r=0; - _CS = 1; //fixme: really needed? - _CS = 0; //fixme: really needed? - _spi.write(0x70); - _spi.write(0); // write MSB - _spi.write(reg); // write LSB - _CS = 1; //fixme: really needed? - _CS = 0; //fixme: really needed? - _spi.write(0x73); - _spi.write(0); // dummy read - r = _spi.write(0); // read 8bit - r <<= 8; - r |= _spi.write(0); // read 8bit - return r; -} -void SPI8::hw_reset() -{ - wait_ms(15); - _DC = 1; - _CS = 1; - _reset = 0; // display reset - wait_ms(2); - _reset = 1; // end reset - wait_ms(100); -} -void SPI8::BusEnable(bool enable) -{ - _CS = enable ? 0:1; -} diff -r 5cf4034ba4e0 -r 55021f3f1929 lib/unigraphic/SPI8.h --- a/lib/unigraphic/SPI8.h Fri Sep 23 21:12:43 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +0,0 @@ -#ifndef SPI8_H -#define SPI8_H - -#define NDEBUG // avoid MBED_ASSERT to halt process when PinName DC==NC - -#include "mbed.h" -#include "Protocols.h" -//#include "GraphicsDisplay.h" - -/** SPI 8bit interface -*/ -class SPI8 : public Protocols -{ - public: - - /** Create an SPI 8bit display interface with 3 control pins - * - * @param SPI mosi - * @param SPI miso - * @param SPI sclk - * @param CS pin connected to CS of display - * @param reset pin connected to RESET of display - * @param DC pin connected to data/command of display - */ - SPI8(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC=NC); - -protected: - - /** Send 8bit command to display controller - * - * @param cmd: byte to send - * - */ - virtual void wr_cmd8(unsigned char cmd); - - /** Send 8bit data to display controller - * - * @param data: byte to send - * - */ - virtual void wr_data8(unsigned char data); - - /** Send 2x8bit command to display controller - * - * @param cmd: halfword to send - */ - virtual void wr_cmd16(unsigned short cmd); - - /** Send 2x8bit data to display controller - * - * @param data: halfword to send - * - */ - virtual void wr_data16(unsigned short data); - - /** Send 16bit pixeldata to display controller - * - * @param data: halfword to send - * - */ - virtual void wr_gram(unsigned short data); - - /** Send same 16bit pixeldata to display controller multiple times - * - * @param data: halfword to send - * @param count: how many - * - */ - virtual void wr_gram(unsigned short data, unsigned int count); - - /** Send array of pixeldata shorts to display controller - * - * @param data: unsigned short pixeldata array - * @param lenght: lenght (in shorts) - * - */ - virtual void wr_grambuf(unsigned short* data, unsigned int lenght); - - /** Read 16bit pixeldata from display controller (with dummy cycle) - * - * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit - * @returns 16bit color - */ - virtual unsigned short rd_gram(bool convert); - - /** Read 4x8bit register data (with dummy cycle) - * @param reg the register to read - * @returns data as uint - * - */ - virtual unsigned int rd_reg_data32(unsigned char reg); - - /** Read 3x8bit ExtendedCommands register data - * @param reg the register to read - * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers - * @returns data as uint - * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode - */ - virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); - - /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent - * for PAR protocols: a signle RD bit toggle - * for SPI8: 8clocks - * for SPI16: 16 clocks - */ - virtual void dummyread (); - - /** ILI932x specific, select register for a successive write or read - * - * @param reg register to be selected - * @param forread false = a write next (default), true = a read next - * @note forread only used by SPI protocols - */ - virtual void reg_select(unsigned char reg, bool forread =false); - - /** ILI932x specific, write register with data - * - * @param reg register to write - * @param data 16bit data - */ - virtual void reg_write(unsigned char reg, unsigned short data); - - /** ILI932x specific, read register - * - * @param reg register to be read - * @returns 16bit register value - */ - virtual unsigned short reg_read(unsigned char reg); - - /** HW reset sequence (without display init commands) - */ - virtual void hw_reset(); - - /** Set ChipSelect high or low - * @param enable 0/1 - */ - virtual void BusEnable(bool enable); - - DigitalOut _CS; - -private: - - SPI _spi; - DigitalOut _reset; - DigitalOut _DC; - -}; -#endif diff -r 5cf4034ba4e0 -r 55021f3f1929 lib/unigraphic/SSD1322.cpp --- a/lib/unigraphic/SSD1322.cpp Fri Sep 23 21:12:43 2016 +0200 +++ b/lib/unigraphic/SSD1322.cpp Tue Oct 11 00:14:20 2016 +0200 @@ -94,70 +94,65 @@ #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; } -SSD1322::SSD1322(proto_t displayproto, - int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, - const char *name, - const unsigned int lcdsize_x, const unsigned int lcdsize_y) +SSD1322::SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, + const char *name) : GraphicsDisplay(name), - screensize_X(lcdsize_x), screensize_Y(lcdsize_y), - _BPP(BPP), _PAGES(lcdsize_y/8*BPP), - _IC_X_SEGS(IC_X_SEGS), _IC_Y_COMS(IC_Y_COMS), _IC_PAGES(IC_Y_COMS/8*BPP) + screensize_X(DISPLAY_WIDTH), screensize_Y(DISPLAY_HEIGHT), + _BPP(BPP), _PAGES(DISPLAY_HEIGHT/8*BPP), + _IC_X_SEGS(IC_X_SEGS), _IC_Y_COMS(IC_Y_COMS), _IC_PAGES(IC_Y_COMS/8*BPP), + _spi(mosi, miso, sclk), + _DC(DC), _CS(CS), _RST(reset) { - proto = new SPI8(Hz, mosi, miso, sclk, CS, reset, DC); - buffer = (unsigned char*) malloc (screensize_X*_PAGES); + _RST = 1; + _DC = 1; + _CS = 1; + _spi.format(8, 0); // 8 bit spi mode 0 + _spi.frequency(Hz); set_auto_up(false); foreground(0xFFFF); background(0x0000); hw_reset(); - bus_enable(true); init(); set_orientation(1); cls(); locate(0,0); -} - -SSD1322::~SSD1322() -{ - free(buffer); + //_internalEventCallback.attach(this, &SSD1322::_cbHandler); } void SSD1322::wr_cmd8(unsigned char cmd) { - proto->wr_cmd8(cmd); + _CS = 0; + _DC.write(0); // 0=cmd + _spi.write(cmd); // write 8bit + _DC.write(1); // 1=data next + _CS = 1; } void SSD1322::wr_data8(unsigned char data) { - proto->wr_data8(data); -} - -void SSD1322::wr_cmd16(unsigned short cmd) -{ - proto->wr_cmd16(cmd); -} + _CS = 0; + _spi.write(data); // write 8bit + _CS = 1; -void SSD1322::wr_gram(unsigned short data, unsigned int count) -{ - proto->wr_gram(data, count); -} - -void SSD1322::wr_grambuf(unsigned short* data, unsigned int lenght) -{ - proto->wr_grambuf(data, lenght); } void SSD1322::hw_reset() { - proto->hw_reset(); + wait_ms(15); + _DC = 1; + _CS = 1; + _RST = 0; // display reset + wait_ms(2); + _RST = 1; // end reset + wait_ms(100); } void SSD1322::bus_enable(bool enable) { - proto->BusEnable(enable); + _CS = enable ? 0:1; } - // monochrome SSD1322 driver ICs does not have ram rotate in hw (swap raw<->columns) like TFT displays // for portrait views, XY swap will be done in sw in pixel() function void SSD1322::set_orientation(int o) @@ -216,8 +211,8 @@ void SSD1322::invert(unsigned char o) { - if(o == 0) wr_cmd8(0xA6); - else wr_cmd8(0xA7); + if(o == 0) wr_cmd8(SSD1322_CMD_SET_DISPLAY_MODE_NORMAL); + else wr_cmd8(SSD1322_CMD_SET_DISPLAY_MODE_INVERSE); } void SSD1322::set_contrast(int o) @@ -243,48 +238,48 @@ win_y2 = y + h - 1; } void SSD1322::window_pushpixel(unsigned short color) { - pixel(cur_x, cur_y, color); - cur_x++; - if(cur_x > win_x2) { - cur_x = win_x1; - cur_y++; - if(cur_y > win_y2) { - cur_y = win_y1; - } + pixel(cur_x, cur_y, color); + cur_x++; + if(cur_x > win_x2) { + cur_x = win_x1; + cur_y++; + if(cur_y > win_y2) { + cur_y = win_y1; } + } } void SSD1322::window_pushpixel(unsigned short color, unsigned int count) { - while(count) + while(count) { - pixel(cur_x, cur_y, color); - cur_x++; - if(cur_x > win_x2) + pixel(cur_x, cur_y, color); + cur_x++; + if(cur_x > win_x2) { - cur_x = win_x1; - cur_y++; - if(cur_y > win_y2) + cur_x = win_x1; + cur_y++; + if(cur_y > win_y2) { - cur_y = win_y1; + cur_y = win_y1; } } - count--; + count--; } } void SSD1322::window_pushpixelbuf(unsigned short* color, unsigned int lenght) { - while(lenght) + while(lenght) { - pixel(cur_x, cur_y, *color++); - cur_x++; - if(cur_x > win_x2) + pixel(cur_x, cur_y, *color++); + cur_x++; + if(cur_x > win_x2) { - cur_x = win_x1; - cur_y++; - if(cur_y > win_y2) + cur_x = win_x1; + cur_y++; + if(cur_y > win_y2) { - cur_y = win_y1; + cur_y = win_y1; } } - lenght--; + lenght--; } } @@ -312,13 +307,13 @@ buffer[(x + page*screensize_X)] = (buffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); */ - unsigned char cval = buffer[(y*128) + x/2]; + unsigned char cval = _pixelBuffer[(y*128) + x/2]; if (x&1) { cval = (cval & 0xF0) | (color & 0x0F); } else { cval = (cval & 0x0F) | (color & 0x0F)<<4; } - buffer[(y*128) + x/2] = cval; + _pixelBuffer[(y*128) + x/2] = cval; } unsigned short SSD1322::pixelread(int x, int y) @@ -332,7 +327,7 @@ unsigned char mask = (( 1 << _BPP) - 1); //FAUX - return (buffer[(x + page*screensize_X)]); // = (buffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); + return (_pixelBuffer[(x + page*screensize_X)]); // = (_pixelBuffer[(x + page*screensize_X)] & ~(mask<<(pos*_BPP))) | ((color&mask)<<(pos*_BPP)); } @@ -359,107 +354,69 @@ void SSD1322::copy_to_lcd(void) { + unsigned int x, y; unsigned int i; - unsigned char x, y; - set_row_address(0); set_column_address(0); + memcpy((void*)_trBuffer, + (const void*)_pixelBuffer, + DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE)); + wr_cmd8(SSD1322_CMD_WRITE_RAM); + i = 0; - wr_cmd8(SSD1322_CMD_WRITE_RAM); for(y=0; y<64; y++) for(x=0; x<128; x++) - wr_data8(buffer[i++]); + wr_data8(_trBuffer[i++]); } void SSD1322::copy_to_lcd(unsigned char from_col, unsigned char to_col, unsigned char from_row, unsigned char to_row) { - unsigned char x, y; - + unsigned int x, y; if (to_col>0x3F) to_col = 0x3F; if (to_row>0x3F) to_row = 0x3F; + + memcpy((void*)_trBuffer, + (const void*)_pixelBuffer, + DISPLAY_BUFFER_ELEMENTS * sizeof(DISPLAY_BUFFER_TYPE)); + set_row_address(from_row, to_row); set_column_address(from_col, to_col); wr_cmd8(SSD1322_CMD_WRITE_RAM); for(y=from_row; y<=to_row; y++) { for(x=from_col; x<=to_col; x++) { - wr_data8(buffer[y*128 + 2*x]); - wr_data8(buffer[y*128 + 2*x + 1]); + wr_data8(_trBuffer[y*128 + 2*x]); + wr_data8(_trBuffer[y*128 + 2*x + 1]); } } } unsigned long SSD1322::buffaddr(unsigned int i) { - return (unsigned long) &(buffer[i]); + return (unsigned long) &(_pixelBuffer[i]); } void SSD1322::clrbuff(const unsigned char value) { - memset(buffer, value, screensize_X*_PAGES); + memset((void*)_pixelBuffer, value, screensize_X*_PAGES); } void SSD1322::fills(const unsigned char value) { -clrbuff(value); -copy_to_lcd(); + clrbuff(value); + copy_to_lcd(); } void SSD1322::cls(void) { -clrbuff(); -copy_to_lcd(); + clrbuff(); + copy_to_lcd(); } -//void ll_fill(const unsigned char value=0xFF, const unsigned char w=0x78, const unsigned char=0x80); -void SSD1322::ll_fill(const unsigned char value, const unsigned char w, const unsigned char h) -{ - unsigned short x,y; - //w = 0x78; // 120 x 2px by byte => 240px - //h = 0x80; // 0x80 for 64 rows because 2 COMs mode - - wr_cmd8(0x15); // COL ADDR - wr_data8(0x00); - wr_data8(w-1); - - wr_cmd8(0x75); // ROW ADDR - wr_data8(0x00); - wr_data8(h-1); - - wr_cmd8(0x5C); // WRITE RAM - for(y=0; y= 64) - loop_pos = 0; - set_row_address(loop_pos); - set_column_address(0); - wr_cmd8(SSD1322_CMD_WRITE_RAM); - - for(uint8_t i=0; i<128; i++) - wr_data8(buffer[loop_pos*64+i]); -} - -void SSD1322::start_loop(float tick) { - loop_pos = 0; - bah.attach(this, &SSD1322::loop_event, tick); -} - -void SSD1322::stop_loop() { - bah.detach(); -} diff -r 5cf4034ba4e0 -r 55021f3f1929 lib/unigraphic/SSD1322.h --- a/lib/unigraphic/SSD1322.h Fri Sep 23 21:12:43 2016 +0200 +++ b/lib/unigraphic/SSD1322.h Tue Oct 11 00:14:20 2016 +0200 @@ -2,18 +2,32 @@ #define MBED_SSD1322_H #include "mbed.h" - -#include "SPI8.h" - -#include "Protocols.h" #include "GraphicsDisplay.h" +//Display module specs +#define DISPLAY_WIDTH (256) +#define DISPLAY_HEIGHT (64) +#define DISPLAY_BUFFER_TYPE uint8_t +#define DISPLAY_BUFFER_TYPE_SIZE (2) // 2 pixel / byte +#define DISPLAY_BUFFER_ELEMENTS 8192 // 256*64 / 2 (because 2 pixels/byte) + + /** Mirror mode */ -enum mirror_t {X,Y,XY,NONE}; +enum mirror_t {X, Y, XY, NONE}; + +typedef enum { + IDLE, // No operation currently ongoing + CLEARING, // In the process of clearing the display + WRITING, // In the process of sending a display update + WAIT_CLEAR, // Going to clear after CS pin timeout + WAIT_WRITE, // Going to write after CS pin timeout + TRANSFERS_DONE, // Last transfer in progress + DONE, // Done with transmission, waiting for CS pin to become high +} SSD1322_state_t; /** A common base class for monochrome Display */ -class SSD1322 : public GraphicsDisplay +class SSD1322: public GraphicsDisplay { public: @@ -22,15 +36,13 @@ /** Create a monochrome SSD1322 SPI interface * @param name The name used by the parent class to access the interface */ - SSD1322(proto_t displayproto, - int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, - const char* name, - const unsigned int lcdsize_x=128, const unsigned int lcdsize_y=64); + SSD1322(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, + const char* name); /** Destructor * will free framebuffer */ - virtual ~SSD1322(); + virtual ~SSD1322() {}; @@ -129,12 +141,12 @@ /** get display X size in pixels (native, orientation independent) * @returns X size in pixels */ - int sizeX(); + int sizeX() {return screensize_X;}; /** get display Y size in pixels (native, orientation independent) * @returns Y size in pixels */ - int sizeY(); + int sizeY() {return screensize_Y;}; //////////////////////////////////////////////////////////////////////////////// // not implemented yet @@ -151,13 +163,10 @@ void clrbuff(const unsigned char value=0x00); unsigned long buffaddr(unsigned int i); void fills(const unsigned char value=0xFF); - void ll_fill(const unsigned char value=0xFF, const unsigned char w=0x78, const unsigned char=0x80); + void set_row_address(unsigned char start_row=0x00, unsigned char end_row=0x3F); void set_column_address(unsigned char start_col=0x00, unsigned char end_col=0x3F); - void start_loop(float tick); - void stop_loop(void); - virtual void copy_to_lcd(unsigned char from_col, unsigned char to_col, unsigned char from_row, unsigned char to_row); @@ -188,41 +197,22 @@ * */ void wr_data8(unsigned char data); - - /** Send 16bit command to display controller - * - * @param cmd: halfword to send - * - */ - void wr_cmd16(unsigned short cmd); - - /** Send same 16bit pixeldata to display controller multiple times - * - * @param data: halfword to send - * @param count: how many - * - */ - virtual void wr_gram(unsigned short data, unsigned int count); - - /** Send array of pixeldata shorts to display controller - * - * @param data: unsigned short pixeldata array - * @param lenght: lenght (in shorts) - * - */ - virtual void wr_grambuf(unsigned short* data, unsigned int lenght); - + /** HW reset sequence (without display init commands) */ void hw_reset(); int contrast; - void loop_event(void); protected: - Protocols* proto; - unsigned char *buffer; + mbed::SPI _spi; + DigitalOut _CS; + DigitalOut _RST; + DigitalOut _DC; + volatile DISPLAY_BUFFER_TYPE _pixelBuffer[DISPLAY_BUFFER_ELEMENTS]; // one full frame buffer + DISPLAY_BUFFER_TYPE _trBuffer[DISPLAY_BUFFER_ELEMENTS]; // for sending + const int screensize_X; const int screensize_Y; const int _PAGES; @@ -231,8 +221,6 @@ const int _IC_Y_COMS; const int _IC_PAGES; - Ticker bah; - int loop_pos; // pixel location int cur_x; int cur_y; @@ -242,6 +230,9 @@ int win_y1; int win_y2; int orientation; + + SSD1322_state_t _state; + }; #endif diff -r 5cf4034ba4e0 -r 55021f3f1929 platformio.ini --- a/platformio.ini Fri Sep 23 21:12:43 2016 +0200 +++ b/platformio.ini Tue Oct 11 00:14:20 2016 +0200 @@ -17,14 +17,27 @@ # Automatic targets - enable auto-uploading # targets = upload -[env:nucleo_f446re] +[env:f446re] platform = ststm32 framework = mbed board = nucleo_f446re -build_flags = -D UNIG_SPI8 -fpermissive upload_port = /media/sdb lib_compat_mode = 0 +[env:f303k8] +platform = ststm32 +framework = mbed +board = nucleo_f303k8 +upload_port = /media/sdb + +[env:l432kc] +platform = ststm32 +framework = mbed +board = nucleo_l432kc +upload_port = /media/sdb +lib_compat_mode = 0 +build_flags = -DDEBUG -DDEBUG2 + # [env:nucleo_f031k6] # platform = ststm31 # framework = mbed diff -r 5cf4034ba4e0 -r 55021f3f1929 src/hp34comm.cpp --- a/src/hp34comm.cpp Fri Sep 23 21:12:43 2016 +0200 +++ b/src/hp34comm.cpp Tue Oct 11 00:14:20 2016 +0200 @@ -4,23 +4,22 @@ /***** HP 34970A communication class ***/ -#define HP_SERIAL_TX PC_7 // serial6 RX -#define HP_SERIAL_RX PA_1 // serial4 RX - -#ifdef DEBUG +#ifdef DEBUG2 -DigitalOut inrx(PC_0); -DigitalOut intx(PC_1); -DigitalOut ack(PC_3); -DigitalOut staterx(PC_2); -DigitalOut statetx(PH_1); +DigitalOut inrx(D9); +DigitalOut intx(D5); +DigitalOut ack(D6); +DigitalOut staterx(D7); +DigitalOut statetx(D8); #endif +DigitalOut lled(LED1); -HPSerial::HPSerial(): - ncmd(0), - serial_tx(NC, HP_SERIAL_TX), serial_rx(NC, HP_SERIAL_RX) { +HPSerial::HPSerial(PinName rx, PinName tx): + serial_tx(A7, tx), + serial_rx(NC, rx), + ncmd(0) { //pc.printf("HPSerial init\n"); @@ -84,7 +83,7 @@ if (val == 0x99) { tx_ack = true; -#ifdef DEBUG +#ifdef DEBUG2 ack = 1; wait_us(2); ack = 0; @@ -97,7 +96,7 @@ if (val == 0x00) { tx_ack = true; -#ifdef DEBUG +#ifdef DEBUG2 ack = 1; wait_us(2); ack = 0; @@ -150,7 +149,7 @@ } else { // end of payload, manage sent content uint8_t cur_state = tx_state; - pushCmd(tx_state, tx_cmd, head, buf); + pushCmd((TrState)tx_state, tx_cmd, head, (char*)buf); switch(val) { case 0x66: // a new transmisson @@ -171,24 +170,25 @@ void HPSerial::setstatedbg(void) { - /* +#ifdef DEBUG2 if (tx_state == Rx) - staterx = 1; + staterx = 1; else - staterx = 0; + staterx = 0; if (tx_state == Tx) - statetx = 1; + statetx = 1; else - statetx = 0; - */ + statetx = 0; +#endif } void HPSerial::rxIrq(void) { uint8_t val; if(serial_rx.readable()) { // no reason why we would end here without this condition, but hey -#ifdef DEBUG +#ifdef DEBUG2 inrx=1; #endif + lled = 1; val = serial_rx.getc(); timeouter.attach(this, &HPSerial::timeout, 0.001); // if nothing else happen in the next ms, reset @@ -200,15 +200,16 @@ tx_ack = false; setstatedbg(); } - else + else { reset(4); - + } else if (tx_state == Tx) // manage the acks handleAck(val); else handleChar(val); -#ifdef DEBUG + lled = 0; +#ifdef DEBUG2 inrx=0; #endif } @@ -217,7 +218,7 @@ void HPSerial::txIrq(void) { uint8_t val; if(serial_tx.readable()) { // no reason why we would end here without this condition, but hey -#ifdef DEBUG +#ifdef DEBUG2 intx=1; #endif val = serial_tx.getc(); @@ -231,8 +232,9 @@ tx_ack = false; setstatedbg(); } - else + else { reset(5); + } else if (tx_state == Rx) // manage the acks handleAck(val); @@ -240,7 +242,7 @@ else handleChar(val); } -#ifdef DEBUG +#ifdef DEBUG2 intx=0; #endif } diff -r 5cf4034ba4e0 -r 55021f3f1929 src/hp34comm.cpp~ --- a/src/hp34comm.cpp~ Fri Sep 23 21:12:43 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,241 +0,0 @@ - -#include "hp34comm.h" - -/***** HP 34970A communication class ***/ - - - - -HPSerial::HPSerial(): - ncmd(0), - serial_tx(NC, HP_SERIAL_TX), serial_rx(NC, HP_SERIAL_RX) { - - //pc.printf("HPSerial init\n"); - - for(uint8_t i=0; i 0) { - // a payload char - buf[head++] = val; - tx_len--; - tx_ack = false; - } - else { // end of payload, manage sent content - uint8_t cur_state = tx_state; - pushCmd(tx_state, tx_cmd, head, buf); - - switch(val) { - case 0x66: // a new transmisson - reset(); - tx_state = cur_state; - setstatedbg(); - break; - case 0x55: - reset(); - break; - default: - reset(6); - break; - } - } -} - - - -void HPSerial::setstatedbg(void) { - /* - if (tx_state == Rx) - staterx = 1; - else - staterx = 0; - if (tx_state == Tx) - statetx = 1; - else - statetx = 0; - */ -} - -void HPSerial::rxIrq(void) { - uint8_t val; - if(serial_rx.readable()) { // no reason why we would end here without this condition, but hey -#ifdef DEBUG - inrx=1; -#endif - val = serial_rx.getc(); - - timeouter.attach(this, &HPSerial::timeout, 0.001); // if nothing else happen in the next ms, reset - - if (tx_state == Idle) - if (val == 0x66) { - // no transmission in progress, expect a start of transmission - tx_state = Rx; - tx_ack = false; - setstatedbg(); - } - else - reset(4); - - else if (tx_state == Tx) // manage the acks - handleAck(val); - - else - handleChar(val); -#ifdef DEBUG - inrx=0; -#endif - } -} - -void HPSerial::txIrq(void) { - uint8_t val; - if(serial_tx.readable()) { // no reason why we would end here without this condition, but hey -#ifdef DEBUG - intx=1; -#endif - val = serial_tx.getc(); - - timeouter.attach(this, &HPSerial::timeout, 0.001); // if nothing else happen in the next ms, reset - - if (tx_state == Idle) - if (val == 0x66) { - // no transmission in progress, expect a start of transmission - tx_state = Tx; - tx_ack = false; - setstatedbg(); - } - else - reset(5); - - else if (tx_state == Rx) // manage the acks - handleAck(val); - - else - handleChar(val); - } -#ifdef DEBUG - intx=0; -#endif -} - -void HPSerial::timeout(void) { - if (tx_state != Idle) { - reset(7); - } -} diff -r 5cf4034ba4e0 -r 55021f3f1929 src/hp34comm.h --- a/src/hp34comm.h Fri Sep 23 21:12:43 2016 +0200 +++ b/src/hp34comm.h Tue Oct 11 00:14:20 2016 +0200 @@ -7,8 +7,8 @@ /***** HP 34970A communication class ***/ #define MAX_ERRS 10 -#define MAX_BUFF 32 -#define BUF_SIZE 32 +#define MAX_BUFF 16 +#define BUF_SIZE 16 class HPSerial { @@ -29,7 +29,7 @@ - HPSerial(); + HPSerial(PinName rx, PinName tx); bool cmd_available(void); bool pop(CMD& cmd); diff -r 5cf4034ba4e0 -r 55021f3f1929 src/hp34comm.h~ --- a/src/hp34comm.h~ Fri Sep 23 21:12:43 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,270 +0,0 @@ -#ifndef HP34COMM_H -#define HP34COMM_H - -/***** HP 34970A communication class ***/ - -class HPSerial { - -public: - enum TrState { - Idle = 0, - Tx, - Rx, - }; - typedef struct _CMD - { - TrState direction; - uint8_t cmd; - uint8_t size; - char value[MAX_BUFF+1]; - unsigned long id; - } CMD; - - - - HPSerial(): ncmd(0), serial_tx(NC, HP_SERIAL_TX), serial_rx(NC, HP_SERIAL_RX) { - pc.printf("HPSerial init\n"); - for(uint8_t i=0; i 0) { - // a payload char - buf[head++] = val; - tx_len--; - tx_ack = false; - } - else { // end of payload, manage sent content - uint8_t cur_state = tx_state; - pushCmd(tx_state, tx_cmd, head, buf); - - switch(val) { - case 0x66: // a new transmisson - reset(); - tx_state = cur_state; - setstatedbg(); - break; - case 0x55: - reset(); - break; - default: - reset(6); - break; - } - } - } - - - - void setstatedbg(void) { - /* - if (tx_state == Rx) - staterx = 1; - else - staterx = 0; - if (tx_state == Tx) - statetx = 1; - else - statetx = 0; - */ - } - - void rxIrq(void) { - uint8_t val; - if(serial_rx.readable()) { // no reason why we would end here without this condition, but hey -#ifdef DEBUG - inrx=1; -#endif - val = serial_rx.getc(); - - timeouter.attach(this, &HPSerial::timeout, 0.001); // if nothing else happen in the next ms, reset - - if (tx_state == Idle) - if (val == 0x66) { - // no transmission in progress, expect a start of transmission - tx_state = Rx; - tx_ack = false; - setstatedbg(); - } - else - reset(4); - - else if (tx_state == Tx) // manage the acks - handleAck(val); - - else - handleChar(val); -#ifdef DEBUG - inrx=0; -#endif - } - } - - void txIrq(void) { - uint8_t val; - if(serial_tx.readable()) { // no reason why we would end here without this condition, but hey -#ifdef DEBUG - intx=1; -#endif - val = serial_tx.getc(); - - timeouter.attach(this, &HPSerial::timeout, 0.001); // if nothing else happen in the next ms, reset - - if (tx_state == Idle) - if (val == 0x66) { - // no transmission in progress, expect a start of transmission - tx_state = Tx; - tx_ack = false; - setstatedbg(); - } - else - reset(5); - - else if (tx_state == Rx) // manage the acks - handleAck(val); - - else - handleChar(val); - } -#ifdef DEBUG - intx=0; -#endif - } - - void timeout(void) { - if (tx_state != Idle) { - reset(7); - } - } -private: - RawSerial serial_tx; - RawSerial serial_rx; - uint8_t buf[BUF_SIZE]; - uint8_t head; - uint8_t tx_state; - uint8_t tx_cmd; - uint8_t tx_len; - bool tx_ack; - CircularBuffer cmdbuf; - unsigned long ncmd; - unsigned int errs[MAX_ERRS]; - Ticker timeouter; -}; - -#endif diff -r 5cf4034ba4e0 -r 55021f3f1929 src/main.cpp --- a/src/main.cpp Fri Sep 23 21:12:43 2016 +0200 +++ b/src/main.cpp Tue Oct 11 00:14:20 2016 +0200 @@ -12,18 +12,63 @@ #include "SSD1322.h" #include "hp34comm.h" + +#if (defined STM32F303x8) || (defined STM32L432xx) +// display +#define DSP_MOSI PA_7 //A6 +#define DSP_MISO PA_6 //A5 +#define DSP_SCLK PA_5 //A4 +#define DSP_CS PB_0 //D3 +#define DSP_RST PB_5 //D11 +#define DSP_DC PB_4 //D12 +// UART for RX (CPU->DP) +#define HP_RX PA_10 // serial1 RX +// UART for TX (DP->CPU) +#define HP_TX PA_3 // serial2 RX + +// misc +#define DBGPIN PA_12 + + +#elif defined STM32F446xx +// display +#define DSP_MOSI PB_15 +#define DSP_MISO PB_14 +#define DSP_SCLK PB_13 +#define DSP_CS PB_12 +#define DSP_RST D11 +#define DSP_DC D12 +// UART for RX (CPU->DP) +#define HP_RX PA_1 // serial4 RX +// UART for TX (DP->CPU) +#define HP_TX PC_7 // serial6 RX + +// misc +#define DBGPIN PC_0 + +#define HAS_PC Serial pc(USBTX, USBRX); -#define DEBUG +#endif + -SSD1322 dsp(SPI_8, 20000000, PB_15, PB_14, PB_13, PB_12, D11, D12, "SSD1322", 256, 64); - +SSD1322 *dsp;//(10000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, DSP_RST, DSP_DC, "SSD1322"); +HPSerial *hp; //(HP_RX, HP_TX); +volatile uint8_t must_refresh; +Thread tdsp, tloop; +Timeout blinker; +DigitalOut led(LED1); uint8_t curchar; uint8_t cmd; uint8_t nchars; char buffer[MAX_BUFF+1]; +void timeout_h() { + led = !led; + blinker.attach(&timeout_h, 0.5f); +} + typedef struct _DSP { uint8_t cmd; @@ -80,7 +125,7 @@ typedef struct _FLAG { uint8_t flag; - uint8_t zone; + uint16_t zone; uint8_t x; uint8_t y; const char* msg; @@ -89,7 +134,7 @@ typedef struct _FRAME { - uint8_t flag; + uint16_t flag; uint8_t x0; uint8_t y0; uint8_t x1; @@ -102,36 +147,38 @@ // right-side icons area { 0x00, 0x02, 0, 0, NULL, icon_alarm}, // F1.1 { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.2 - { 0x14, 0x02, 0, 22, "4W"}, // F2.5 + { 0x03, 0x04, 1, 2, "Channel"}, // F1.4 // col 1 { 0x34, 0x10, 0, 0, "MON"}, // F4.5 { 0x33, 0x10, 0, 8, "VIEW"}, // F4.4 - { 0x35, 0x10, 0, 16, "SCAN"}, // F4.6 + { 0x35, 0x10, 0, 16, "SCAN"}, // F4.6 //col 2 { 0x32, 0x20, 0, 0, "*"}, // F4.3 { 0x36, 0x20, 0, 8, "CFG"}, // F4.7 - { 0xFF, 0x20, 0, 16, "ERROR"}, + { 0x27, 0x20, 0, 16, "ERR"}, // F3.8 - /* - { 0xFF, 0, 0, "ADRS"}, - { 0xFF, 0, 0, "RMT"}, - { 0xFF, 0, 0, "EXT"}, + // col 3 + { 0x41, 0x040, 0, 0, "ADRS"}, // F4.2 + { 0x40, 0x040, 0, 8, "RMT"}, // F4.1 - { 0xFF, 0, 0, "ONCE"}, - { 0xFF, 0, 0, "AUTO"}, - { 0xFF, 0, 0, "MEM"}, + // col 4 + { 0x26, 0x080, 0, 0, "EXT"}, // F3.7 + { 0x25, 0x080, 0, 8, "ONCE"}, // F3.6 + + { 0xFF, 0x080, 0, 16, "MEM"}, - { 0xFF, 0, 0, "LAST"}, - { 0xFF, 0, 0, "MIN"}, - { 0xFF, 0, 0, "MAX"}, - - { 0xFF, 0, 0, "AVG"}, - { 0xFF, 0, 0, "OC"}, - */ + + // col 5 + { 0x14, 0x100, 0, 0, "4W"}, // F2.5 + { 0x15, 0x100, 0, 8, "OC"}, // F2.6 + { 0xFF, 0x100, 0, 16, "LST"}, // F3.8? Nope + { 0xFF, 0x100, 0, 16, "MIN"}, + { 0xFF, 0x100, 0, 16, "MAX"}, + { 0xFF, 0x100, 0, 16, "AVG"}, { 0x05, 0x08, 0, 0, "Alarm"}, // F1.6 { 0x06, 0x08, 0, 10, "H"}, // F1.7 @@ -145,25 +192,27 @@ static const FRAME zones[] = { - { 0x01, 0, 0, 245, 27}, // main display area - { 0x02, 246, 0, 255, 27}, // right notif area - { 0x04, 203, 28, 255, 54}, // channels display area - { 0x08, 160, 28, 202, 54}, // alarms area - { 0x10, 0, 28, 32, 54}, // flags col1 - { 0x20, 33, 28, 70, 54}, // flags col2 - { 0x40, 71, 28, 159, 54}, // flags col3 + { 0x001, 0, 0, 245, 27}, // main display area + { 0x002, 246, 0, 255, 27}, // right notif area + { 0x004, 203, 28, 255, 54}, // channels display area + { 0x008, 160, 28, 202, 54}, // alarms area + { 0x010, 0, 28, 32, 54}, // flags col1 + { 0x020, 33, 28, 70, 54}, // flags col2 + { 0x040, 71, 28, 103, 54}, // flags col3 + { 0x080, 104, 28, 128, 54}, // flags col4 + { 0x100, 129, 28, 159, 54}, // flags col5 - { 0x80, 0, 55, 255, 63}, // flags bits display area + { 0x8000, 0, 55, 255, 63}, // flags bits display area }; static const FRAME frames[] = { - { 0x02, 203, 35, 248, 55}, // F1.3 + { 0x02, 203, 35, 255, 54}, // F1.3 - channel frame + { 0x07, 160, 28, 202, 54}, // F1.8 - alarm frame }; #ifdef DEBUG -#define DBGPIN PC_0 DigitalOut dbgpin(DBGPIN); inline void pulse(uint8_t count=1, bool stayup=false) @@ -187,44 +236,48 @@ #endif -HPSerial hp; -volatile uint8_t must_refresh; -Thread tdsp, tloop; void copy_to_lcd(void); void test_dsp(); void setup() { - // init the LCD - - //dsp.set_orientation(3); - pc.baud (115200); - pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n", - (float)SystemCoreClock/1000000); - - // myLCD.set_font((unsigned char*) Terminal6x8); - // myLCD.claim(stdout); // send stdout to the LCD display - // myLCD.claim(stderr); // send stderr to the LCD display - dsp.background(Black); // set background to black - dsp.foreground(0xF); - dsp.cls(); + blinker.attach(&timeout_h, 0.5f); - cmd = 0xFF; - curchar = 0; - nchars = 0; - - for (uint8_t i=0; ibackground(Black); // set background to black + dsp->foreground(0xF); + dsp->cls(); + + cmd = 0xFF; + curchar = 0; + nchars = 0; - dsp.locate(30, 10); - dsp.set_font(Mono19x27); - dsp.printf("HP34970A"); - dsp.set_font(Terminal6x8); - dsp.locate(90, 40); - dsp.printf("David Douard"); - dsp.copy_to_lcd(); - wait(2); - dsp.cls(); + for (uint8_t i=0; ilocate(30, 10); + dsp->set_font((unsigned char*)Mono19x27); + dsp->printf("HP34970A"); + dsp->set_font((unsigned char*)Terminal6x8); + dsp->locate(90, 40); + dsp->printf("David Douard"); + dsp->copy_to_lcd(); + wait(2); + dsp->cls(); + + hp = new HPSerial(HP_RX, HP_TX); + //hp = NULL; } void copy_to_lcd(void) { @@ -232,10 +285,17 @@ while(1) { pulse(0, true); + if (must_refresh) { + must_refresh = 0; + //Thread::wait(20); // give a bit of time for some more cmds + dsp->copy_to_lcd(); + } + + /* if (must_refresh & mask) { for(uint8_t i=0; icopy_to_lcd(zones[i].x0/4, (zones[i].x1+3)/4, zones[i].y0, zones[i].y1); must_refresh &= ~mask; break; @@ -245,9 +305,9 @@ if (mask == 0) { mask = 1; } - + */ pulse(0, false); - Thread::wait(10); + Thread::wait(30); } } @@ -264,96 +324,97 @@ if (table[i].cmd == cmd) { bgcolor = table[i].bgcolor; fgcolor = table[i].color; - dsp.background(bgcolor); - dsp.foreground(fgcolor); - dsp.set_font((unsigned char*) table[i].font); + dsp->background(bgcolor); + dsp->foreground(fgcolor); + dsp->set_font((unsigned char*) table[i].font); oldv = table[i].buffer; - dsp.locate(table[i].x0, table[i].y0); + dsp->locate(table[i].x0, table[i].y0); if (table[i].fmt & 0x01 ) { - // ascii - if (table[i].width > 0) - dsp.fillrect(table[i].x0, table[i].y0, table[i].x0 + table[i].width, table[i].y0 + table[i].font[2], bgcolor); - for (uint8_t k=0; ;k++) { - if (txt[k] == 0x00) - { - dsp.printf(txt); - break; + if (strncmp(oldv, txt, table[i].maxsize) != 0) { + // ascii + if (table[i].width > 0) + dsp->fillrect(table[i].x0, table[i].y0, table[i].x0 + table[i].width, table[i].y0 + table[i].font[2], bgcolor); + for (uint8_t k=0; ;k++) { + if (txt[k] == 0x00) + { + dsp->printf(txt); + break; + } + if (txt[k] == 0x09) { // \t is a special char for 'unselected' display value + txt[k] = 0x00; + dsp->printf(txt); + + if (fgcolor == table[i].color) + fgcolor /= 2; + else + fgcolor = table[i].color; + dsp->foreground(fgcolor); + txt = &(txt[k+1]); + k = 0; } - if (txt[k] == 0x09) { // \t is a special char for 'unselected' display value - txt[k] = 0x00; - dsp.printf(txt); - - if (fgcolor == table[i].color) - fgcolor /= 2; - else - fgcolor = table[i].color; - dsp.foreground(fgcolor); - txt = &(txt[k+1]); - k = 0; } + if (cmd == 0x00) // main area + must_refresh |= 0x01; + if (cmd == 0x0C) // channels area + must_refresh |= 0x04; } - if (cmd == 0x00) // main area - must_refresh |= 0x01; - if (cmd == 0x0C) // channels area - must_refresh |= 0x04; } - /* if (table[i].fmt & 0x02 ) { // hex for (uint8_t j=0;; j++) { if (txt[j] == 0x00) break; - dsp.printf("%02X ", txt[j]); + dsp->printf("%02X ", txt[j]); } for (uint8_t j=3*strlen(txt); jprintf(" "); } */ if (table[i].fmt & 0x04 ) { // binary - dsp.foreground(fgcolor); - dsp.printf(" ["); + dsp->foreground(fgcolor); + dsp->printf(" ["); for (uint8_t j=0; j0) { - dsp.foreground(fgcolor); - dsp.printf(" | "); + dsp->foreground(fgcolor); + dsp->printf(" | "); } for (uint8_t k=0; k<8; k++) { if (txt[j] & (1 << (7-k))) - dsp.foreground(fgcolor); + dsp->foreground(fgcolor); else - dsp.foreground(bgcolor); - dsp.printf("%d", (8-k)); + dsp->foreground(bgcolor); + dsp->printf("%d", (8-k)); } } - dsp.foreground(fgcolor); - dsp.printf("]"); - must_refresh |= 0x80; + dsp->foreground(fgcolor); + dsp->printf("]"); + must_refresh |= 0x8000; } if (table[i].fmt & 0x08 ) { // flags for (uint8_t j=0; jforeground(fgcolor); else - dsp.foreground(bgcolor); + dsp->foreground(bgcolor); /* for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l) { if (frames[l].flag & ((j<<4) + k)) - dsp.fillrect(frames[l].x0, frames[l].y0, + dsp->fillrect(frames[l].x0, frames[l].y0, frames[l].x1, frames[l].y1, fgcolor/8); else - dsp.fillrect(frames[l].x0, frames[l].y0, + dsp->fillrect(frames[l].x0, frames[l].y0, frames[l].x1, frames[l].y1, bgcolor); @@ -366,12 +427,12 @@ for (uint8_t m=0; m<(sizeof(zones)/sizeof(zones[0])); m++) { if (flags[l].zone == zones[m].flag) { if (flags[l].msg != NULL) { // a string - dsp.locate(flags[l].x + zones[m].x0, + dsp->locate(flags[l].x + zones[m].x0, flags[l].y + zones[m].y0); - dsp.printf(flags[l].msg);} + dsp->printf(flags[l].msg);} else { // an icon - Bitmap_s pic = {9, 10, 2, flags[l].icon}; - dsp.Bitmap_BW(pic, + Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon}; + dsp->Bitmap_BW(pic, flags[l].x + zones[m].x0, flags[l].y + zones[m].y0); } @@ -393,7 +454,7 @@ } } - //dsp.copy_to_lcd(); + //dsp->copy_to_lcd(); pulse(1, false); } @@ -403,61 +464,93 @@ show(0x00, "8g8g8g8g8g8g8", 13); // main dsp show(0x0C, "888", 3); // channel dsp show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags - dsp.copy_to_lcd(); + dsp->copy_to_lcd(); wait(3); - dsp.cls(); - + dsp->cls(); + for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) { z = &zones[i]; - dsp.fillrect(z->x0, z->y0, z->x1, z->y1, 4+i); - dsp.locate(z->x0+1, z->y0+1); - dsp.printf("%d", i); + dsp->fillrect(z->x0, z->y0, z->x1, z->y1, 4+i); + dsp->locate(z->x0+1, z->y0+1); + dsp->printf("%d", i); } + + /* for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) { z = &zones[i]; - pc.printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag, + printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag, z->x0, z->y0, z->x1, z->y1); - must_refresh = z->flag; + must_refresh = z->flag; wait(1); } - pc.printf("Done\n"); + printf("Done\n"); wait(2); - pc.printf("Copy ALL\n"); - dsp.copy_to_lcd(); - wait(2); - dsp.cls(); + printf("Copy ALL\n"); + dsp->copy_to_lcd(); + */ + wait(2); + dsp->cls(); } void loop() { // run over and over - while(1){ - if (hp.cmd_available()) - { - HPSerial::CMD cmd; - if (hp.pop(cmd)) - {/* - pc.printf("CMD[%s:%d %d/%d/%d/%d/%d/%d/%d] %X\n", (cmd.direction==HPSerial::Rx)?"Rx":"Tx", cmd.id, - hp.nerrors(0), - hp.nerrors(1), - hp.nerrors(2), - hp.nerrors(3), - hp.nerrors(4), - hp.nerrors(5), - hp.nerrors(6), - cmd.cmd); - */ - if (cmd.direction == HPSerial::Rx) { - // if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) - // pc.printf(" data=%s\n", cmd.value); - show(cmd.cmd, cmd.value, cmd.size); - - } + unsigned int err[8]; + for (uint8_t i=0; i<8; i++) + err[i] = 0; + while(1) { + if (hp != NULL) { + if (hp->cmd_available()) + { + led = 1; + HPSerial::CMD cmd; + if (hp->pop(cmd)) + { + for (uint8_t i=0; i<7; i++) + if (hp->nerrors(i) > err[i]) { + printf("ERR: %d/%d/%d/%d/%d/%d/%d\n", + hp->nerrors(0), + hp->nerrors(1), + hp->nerrors(2), + hp->nerrors(3), + hp->nerrors(4), + hp->nerrors(5), + hp->nerrors(6) + ); + break; + } + for (uint8_t i=0; i<7; i++) + err[i] = hp->nerrors(i); + printf("CMD[%s:%d] %02X", (cmd.direction==HPSerial::Rx)?"Rx":"Tx", cmd.id, + cmd.cmd); + + if (cmd.direction == HPSerial::Rx) { + if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) + printf(": '%s'\n", cmd.value); + else { + printf(":"); + for (uint8_t i=0; i