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:
Geremia
Date:
Mon Feb 16 00:52:24 2015 +0000
Revision:
5:b222a9461d6b
Parent:
4:12ba0ecc2c1f
Child:
6:8356d48a07db
Added pixelread for TFTs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 1:ff019d22b275 1 #ifndef SPI16_H
Geremia 1:ff019d22b275 2 #define SPI16_H
Geremia 1:ff019d22b275 3
Geremia 1:ff019d22b275 4 #include "mbed.h"
Geremia 1:ff019d22b275 5 #include "Protocols.h"
Geremia 1:ff019d22b275 6 //#include "GraphicsDisplay.h"
Geremia 1:ff019d22b275 7
Geremia 1:ff019d22b275 8 class SPI16 : public Protocols
Geremia 1:ff019d22b275 9 {
Geremia 1:ff019d22b275 10 public:
Geremia 1:ff019d22b275 11
Geremia 1:ff019d22b275 12 /** Create an SPI 8bit display interface with 3 control pins
Geremia 1:ff019d22b275 13 *
Geremia 1:ff019d22b275 14 * @param SPI mosi
Geremia 1:ff019d22b275 15 * @param SPI miso
Geremia 1:ff019d22b275 16 * @param SPI sclk
Geremia 1:ff019d22b275 17 * @param CS pin connected to CS of display
Geremia 1:ff019d22b275 18 * @param reset pin connected to RESET of display
Geremia 1:ff019d22b275 19 * @param DC pin connected to data/command of display
Geremia 1:ff019d22b275 20 */
Geremia 1:ff019d22b275 21 SPI16(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC);
Geremia 1:ff019d22b275 22
Geremia 1:ff019d22b275 23 protected:
Geremia 1:ff019d22b275 24
Geremia 1:ff019d22b275 25 /** Send 8bit command to display controller
Geremia 1:ff019d22b275 26 *
Geremia 1:ff019d22b275 27 * @note switches spi format 16->8->16, better use wr_cmd16 with NOP in front
Geremia 1:ff019d22b275 28 * @param cmd: byte to send
Geremia 1:ff019d22b275 29 *
Geremia 1:ff019d22b275 30 */
Geremia 1:ff019d22b275 31 virtual void wr_cmd8(unsigned char cmd);
Geremia 1:ff019d22b275 32
Geremia 1:ff019d22b275 33 /** Send 8bit data to display controller
Geremia 1:ff019d22b275 34 *
Geremia 1:ff019d22b275 35 * @note switches spi format 16->8->16, better use wr_data16 with repeated byte (if does not hurt)
Geremia 1:ff019d22b275 36 * @param data: byte to send
Geremia 1:ff019d22b275 37 *
Geremia 1:ff019d22b275 38 */
Geremia 1:ff019d22b275 39 virtual void wr_data8(unsigned char data);
Geremia 1:ff019d22b275 40
Geremia 4:12ba0ecc2c1f 41 /** Send 2x8bit command to display controller
Geremia 1:ff019d22b275 42 *
Geremia 1:ff019d22b275 43 * @param cmd: halfword to send
Geremia 4:12ba0ecc2c1f 44 * @note in SPI_16 mode a single 16bit transfer will be done
Geremia 1:ff019d22b275 45 */
Geremia 1:ff019d22b275 46 virtual void wr_cmd16(unsigned short cmd);
Geremia 1:ff019d22b275 47
Geremia 4:12ba0ecc2c1f 48 /** Send 2x8bit data to display controller
Geremia 4:12ba0ecc2c1f 49 *
Geremia 4:12ba0ecc2c1f 50 * @param data: halfword to send
Geremia 4:12ba0ecc2c1f 51 * @note in SPI_16 mode a single 16bit transfer will be done
Geremia 4:12ba0ecc2c1f 52 */
Geremia 4:12ba0ecc2c1f 53 virtual void wr_data16(unsigned short data);
Geremia 4:12ba0ecc2c1f 54
Geremia 4:12ba0ecc2c1f 55 /** Send 16bit pixeldata to display controller
Geremia 1:ff019d22b275 56 *
Geremia 1:ff019d22b275 57 * @param data: halfword to send
Geremia 1:ff019d22b275 58 *
Geremia 1:ff019d22b275 59 */
Geremia 4:12ba0ecc2c1f 60 virtual void wr_gram(unsigned short data);
Geremia 1:ff019d22b275 61
Geremia 4:12ba0ecc2c1f 62 /** Send same 16bit pixeldata to display controller multiple times
Geremia 1:ff019d22b275 63 *
Geremia 1:ff019d22b275 64 * @param data: halfword to send
Geremia 1:ff019d22b275 65 * @param count: how many
Geremia 1:ff019d22b275 66 *
Geremia 1:ff019d22b275 67 */
Geremia 4:12ba0ecc2c1f 68 virtual void wr_gram(unsigned short data, unsigned int count);
Geremia 1:ff019d22b275 69
Geremia 4:12ba0ecc2c1f 70 /** Send array of pixeldata shorts to display controller
Geremia 1:ff019d22b275 71 *
Geremia 4:12ba0ecc2c1f 72 * @param data: unsigned short pixeldata array
Geremia 1:ff019d22b275 73 * @param lenght: lenght (in shorts)
Geremia 1:ff019d22b275 74 *
Geremia 1:ff019d22b275 75 */
Geremia 4:12ba0ecc2c1f 76 virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
Geremia 1:ff019d22b275 77
Geremia 5:b222a9461d6b 78 /** Read 4x8bit data from display controller (with dummy cycle)
Geremia 5:b222a9461d6b 79 *
Geremia 5:b222a9461d6b 80 * @returns data as uint
Geremia 5:b222a9461d6b 81 *
Geremia 5:b222a9461d6b 82 */
Geremia 5:b222a9461d6b 83 virtual unsigned int rd_data32_wdummy();
Geremia 5:b222a9461d6b 84
Geremia 5:b222a9461d6b 85 /** Read 16bit pixeldata from display controller (with dummy cycle)
Geremia 5:b222a9461d6b 86 *
Geremia 5:b222a9461d6b 87 * @returns 16bit color
Geremia 5:b222a9461d6b 88 */
Geremia 5:b222a9461d6b 89 virtual unsigned short rd_gram();
Geremia 5:b222a9461d6b 90
Geremia 1:ff019d22b275 91 /** HW reset sequence (without display init commands)
Geremia 1:ff019d22b275 92 */
Geremia 1:ff019d22b275 93 virtual void hw_reset();
Geremia 1:ff019d22b275 94
Geremia 1:ff019d22b275 95 /** Set ChipSelect high or low
Geremia 1:ff019d22b275 96 * @param enable 0/1
Geremia 1:ff019d22b275 97 */
Geremia 1:ff019d22b275 98 virtual void BusEnable(bool enable);
Geremia 1:ff019d22b275 99
Geremia 1:ff019d22b275 100 DigitalOut _CS;
Geremia 1:ff019d22b275 101
Geremia 1:ff019d22b275 102 private:
Geremia 1:ff019d22b275 103
Geremia 1:ff019d22b275 104 SPI _spi;
Geremia 1:ff019d22b275 105 DigitalOut _reset;
Geremia 1:ff019d22b275 106 DigitalOut _DC;
Geremia 1:ff019d22b275 107
Geremia 1:ff019d22b275 108 };
Geremia 1:ff019d22b275 109 #endif