Added SPI burst mode to spi 8 bit.

Dependents:   Bicycl_Computer_NUCLEO-F411RE Bicycl_Computer_NUCLEO-L476RG

Fork of UniGraphic by GraphicsDisplay

Added SPI burst mode to this graphics driver. If whoever wants this rolled in to repository let me know. I replaced _spi.write(); with fastWrite(); and clearRX();

SPI8.cpp

// need to re-create SPI firmware to access SPI handle
static SPI_HandleTypeDef SpiHandle;

void SPI8::fastWrite(int data) {
    
      SpiHandle.Instance = SPI1;
    // Check if data is transmitted
    while ((SpiHandle.Instance->SR & SPI_SR_TXE) == 0);
    SpiHandle.Instance->DR = data;
}
    
void SPI8::clearRX( void ) {
        SpiHandle.Instance = SPI1;
    //Check if the RX buffer is busy
    //While busy, keep checking
    while (SpiHandle.Instance->SR & SPI_SR_BSY){   
        // Check RX buffer readable
        while ((SpiHandle.Instance->SR & SPI_SR_RXNE) == 0);
        int dummy = SpiHandle.Instance->DR;
    }
}      
Committer:
dreschpe
Date:
Sun Oct 18 13:53:20 2015 +0000
Revision:
25:daacdcf34e52
Parent:
20:14daa48ffd4c
Child:
27:acb2594b8aa4
Add check if platform supports par port mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 25:daacdcf34e52 1 #if DEVICE_PORTINOUT
dreschpe 25:daacdcf34e52 2
Geremia 4:12ba0ecc2c1f 3 #ifndef PAR16_H
Geremia 4:12ba0ecc2c1f 4 #define PAR16_H
Geremia 4:12ba0ecc2c1f 5
Geremia 4:12ba0ecc2c1f 6 #include "mbed.h"
Geremia 4:12ba0ecc2c1f 7 #include "Protocols.h"
Geremia 4:12ba0ecc2c1f 8 //#include "GraphicsDisplay.h"
Geremia 4:12ba0ecc2c1f 9
Geremia 6:8356d48a07db 10 /** Parallel 16bit interface
Geremia 6:8356d48a07db 11 */
Geremia 4:12ba0ecc2c1f 12 class PAR16 : public Protocols
Geremia 4:12ba0ecc2c1f 13 {
Geremia 4:12ba0ecc2c1f 14 public:
Geremia 4:12ba0ecc2c1f 15
Geremia 4:12ba0ecc2c1f 16 /** Create a PAR16 display interface with a GPIO port and 5 control pins
Geremia 4:12ba0ecc2c1f 17 *
Geremia 4:12ba0ecc2c1f 18 * @param port GPIO port to use
Geremia 4:12ba0ecc2c1f 19 * @param CS pin connected to CS of display
Geremia 4:12ba0ecc2c1f 20 * @param reset pin connected to RESET of display
Geremia 4:12ba0ecc2c1f 21 * @param DC pin connected to data/command of display
Geremia 4:12ba0ecc2c1f 22 * @param WR pin connected to SDI of display
Geremia 4:12ba0ecc2c1f 23 * @param RD pin connected to RS of display
Geremia 4:12ba0ecc2c1f 24 */
Geremia 4:12ba0ecc2c1f 25 PAR16(PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD);
Geremia 4:12ba0ecc2c1f 26
Geremia 4:12ba0ecc2c1f 27 protected:
Geremia 4:12ba0ecc2c1f 28
Geremia 4:12ba0ecc2c1f 29 /** Send 8bit command to display controller
Geremia 4:12ba0ecc2c1f 30 *
Geremia 4:12ba0ecc2c1f 31 * @param cmd: byte to send
Geremia 4:12ba0ecc2c1f 32 *
Geremia 4:12ba0ecc2c1f 33 */
Geremia 4:12ba0ecc2c1f 34 virtual void wr_cmd8(unsigned char cmd);
Geremia 4:12ba0ecc2c1f 35
Geremia 4:12ba0ecc2c1f 36 /** Send 8bit data to display controller
Geremia 4:12ba0ecc2c1f 37 *
Geremia 4:12ba0ecc2c1f 38 * @param data: byte to send
Geremia 4:12ba0ecc2c1f 39 *
Geremia 4:12ba0ecc2c1f 40 */
Geremia 4:12ba0ecc2c1f 41 virtual void wr_data8(unsigned char data);
Geremia 4:12ba0ecc2c1f 42
Geremia 4:12ba0ecc2c1f 43 /** Send 2x8bit command to display controller
Geremia 4:12ba0ecc2c1f 44 *
Geremia 4:12ba0ecc2c1f 45 * @param cmd: halfword to send
Geremia 4:12ba0ecc2c1f 46 * @note 2cycles using pins[7:0]
Geremia 4:12ba0ecc2c1f 47 */
Geremia 4:12ba0ecc2c1f 48 virtual void wr_cmd16(unsigned short cmd);
Geremia 4:12ba0ecc2c1f 49
Geremia 4:12ba0ecc2c1f 50 /** Send 2x8bit data to display controller
Geremia 4:12ba0ecc2c1f 51 *
Geremia 4:12ba0ecc2c1f 52 * @param data: halfword to send
Geremia 4:12ba0ecc2c1f 53 * @note 2cycles using pins[7:0], only gram write cmd uses pins[15:8]
Geremia 4:12ba0ecc2c1f 54 */
Geremia 4:12ba0ecc2c1f 55 virtual void wr_data16(unsigned short data);
Geremia 4:12ba0ecc2c1f 56
Geremia 4:12ba0ecc2c1f 57 /** Send 16bit pixeldata to display controller
Geremia 4:12ba0ecc2c1f 58 *
Geremia 4:12ba0ecc2c1f 59 * @param data: halfword to send
Geremia 4:12ba0ecc2c1f 60 * @note here using all pins[15:0]
Geremia 4:12ba0ecc2c1f 61 */
Geremia 4:12ba0ecc2c1f 62 virtual void wr_gram(unsigned short data);
Geremia 4:12ba0ecc2c1f 63
Geremia 4:12ba0ecc2c1f 64 /** Send same 16bit pixeldata to display controller multiple times
Geremia 4:12ba0ecc2c1f 65 *
Geremia 4:12ba0ecc2c1f 66 * @param data: halfword to send
Geremia 4:12ba0ecc2c1f 67 * @param count: how many
Geremia 4:12ba0ecc2c1f 68 * @note here using all pins[15:0]
Geremia 4:12ba0ecc2c1f 69 */
Geremia 4:12ba0ecc2c1f 70 virtual void wr_gram(unsigned short data, unsigned int count);
Geremia 4:12ba0ecc2c1f 71
Geremia 4:12ba0ecc2c1f 72 /** Send array of pixeldata shorts to display controller
Geremia 4:12ba0ecc2c1f 73 *
Geremia 4:12ba0ecc2c1f 74 * @param data: unsigned short pixeldata array
Geremia 4:12ba0ecc2c1f 75 * @param lenght: lenght (in shorts)
Geremia 4:12ba0ecc2c1f 76 * @note here using all pins[15:0]
Geremia 4:12ba0ecc2c1f 77 */
Geremia 4:12ba0ecc2c1f 78 virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
Geremia 4:12ba0ecc2c1f 79
Geremia 5:b222a9461d6b 80 /** Read 16bit pixeldata from display controller (with dummy cycle)
Geremia 5:b222a9461d6b 81 *
Geremia 11:b842b8e332cb 82 * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit
Geremia 5:b222a9461d6b 83 * @returns 16bit color
Geremia 5:b222a9461d6b 84 */
Geremia 11:b842b8e332cb 85 virtual unsigned short rd_gram(bool convert);
Geremia 5:b222a9461d6b 86
Geremia 7:bb0383b91104 87 /** Read 4x8bit register data (with dummy cycle)
Geremia 7:bb0383b91104 88 * @param reg the register to read
Geremia 7:bb0383b91104 89 * @returns data as uint
Geremia 7:bb0383b91104 90 *
Geremia 7:bb0383b91104 91 */
Geremia 7:bb0383b91104 92 virtual unsigned int rd_reg_data32(unsigned char reg);
Geremia 7:bb0383b91104 93
Geremia 7:bb0383b91104 94 /** Read 3x8bit ExtendedCommands register data
Geremia 7:bb0383b91104 95 * @param reg the register to read
Geremia 7:bb0383b91104 96 * @returns data as uint
Geremia 7:bb0383b91104 97 * @note EXTC regs (0xB0 to 0xFF) are read/write registers, for Parallel mode directly accessible in both directions
Geremia 7:bb0383b91104 98 */
Geremia 7:bb0383b91104 99 virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd);
Geremia 7:bb0383b91104 100
Geremia 20:14daa48ffd4c 101 /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent
Geremia 20:14daa48ffd4c 102 * for PAR protocols: a signle RD bit toggle
Geremia 20:14daa48ffd4c 103 * for SPI8: 8clocks
Geremia 20:14daa48ffd4c 104 * for SPI16: 16 clocks
Geremia 20:14daa48ffd4c 105 */
Geremia 20:14daa48ffd4c 106 virtual void dummyread ();
Geremia 20:14daa48ffd4c 107
Geremia 20:14daa48ffd4c 108 /** ILI932x specific, select register for a successive write or read
Geremia 20:14daa48ffd4c 109 *
Geremia 20:14daa48ffd4c 110 * @param reg register to be selected
Geremia 20:14daa48ffd4c 111 * @param forread false = a write next (default), true = a read next
Geremia 20:14daa48ffd4c 112 * @note forread only used by SPI protocols
Geremia 20:14daa48ffd4c 113 */
Geremia 20:14daa48ffd4c 114 virtual void reg_select(unsigned char reg, bool forread =false);
Geremia 20:14daa48ffd4c 115
Geremia 20:14daa48ffd4c 116 /** ILI932x specific, write register with data
Geremia 20:14daa48ffd4c 117 *
Geremia 20:14daa48ffd4c 118 * @param reg register to write
Geremia 20:14daa48ffd4c 119 * @param data 16bit data
Geremia 20:14daa48ffd4c 120 */
Geremia 20:14daa48ffd4c 121 virtual void reg_write(unsigned char reg, unsigned short data);
Geremia 20:14daa48ffd4c 122
Geremia 20:14daa48ffd4c 123 /** ILI932x specific, read register
Geremia 20:14daa48ffd4c 124 *
Geremia 20:14daa48ffd4c 125 * @param reg register to be read
Geremia 20:14daa48ffd4c 126 * @returns 16bit register value
Geremia 20:14daa48ffd4c 127 */
Geremia 20:14daa48ffd4c 128 virtual unsigned short reg_read(unsigned char reg);
Geremia 20:14daa48ffd4c 129
Geremia 4:12ba0ecc2c1f 130 /** HW reset sequence (without display init commands)
Geremia 4:12ba0ecc2c1f 131 */
Geremia 4:12ba0ecc2c1f 132 virtual void hw_reset();
Geremia 4:12ba0ecc2c1f 133
Geremia 4:12ba0ecc2c1f 134 /** Set ChipSelect high or low
Geremia 4:12ba0ecc2c1f 135 * @param enable 0/1
Geremia 4:12ba0ecc2c1f 136 */
Geremia 4:12ba0ecc2c1f 137 virtual void BusEnable(bool enable);
Geremia 4:12ba0ecc2c1f 138
Geremia 4:12ba0ecc2c1f 139
Geremia 4:12ba0ecc2c1f 140
Geremia 4:12ba0ecc2c1f 141 private:
Geremia 4:12ba0ecc2c1f 142
Geremia 4:12ba0ecc2c1f 143 PortInOut _port;
Geremia 4:12ba0ecc2c1f 144 DigitalOut _CS;
Geremia 4:12ba0ecc2c1f 145 DigitalOut _reset;
Geremia 4:12ba0ecc2c1f 146 DigitalOut _DC;
Geremia 4:12ba0ecc2c1f 147 DigitalOut _WR;
Geremia 4:12ba0ecc2c1f 148 DigitalOut _RD;
Geremia 4:12ba0ecc2c1f 149
Geremia 4:12ba0ecc2c1f 150 };
dreschpe 25:daacdcf34e52 151 #endif
dreschpe 25:daacdcf34e52 152
Geremia 4:12ba0ecc2c1f 153 #endif