.

Committer:
Geremia
Date:
Sun Nov 29 19:58:47 2015 +0000
Revision:
30:87855d03d91a
Parent:
25:daacdcf34e52
Child:
33:f87f06292637
Add ILI9320 init to ILI932x

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 4:12ba0ecc2c1f 1 /* mbed UniGraphic library - Abstract protocol class
Geremia 4:12ba0ecc2c1f 2 * Copyright (c) 2015 Giuliano Dianda
Geremia 4:12ba0ecc2c1f 3 * Released under the MIT License: http://mbed.org/license/mit
Geremia 4:12ba0ecc2c1f 4 */
Geremia 4:12ba0ecc2c1f 5
Geremia 0:75ec1b3cde17 6 /** @file Protocols.h
Geremia 0:75ec1b3cde17 7 */
Geremia 0:75ec1b3cde17 8 #ifndef Protocols_H
Geremia 0:75ec1b3cde17 9 #define Protocols_H
Geremia 0:75ec1b3cde17 10
Geremia 0:75ec1b3cde17 11 #include "mbed.h"
Geremia 0:75ec1b3cde17 12
Geremia 11:b842b8e332cb 13 #define RGB24to16(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue
Geremia 5:b222a9461d6b 14 #define BGR2RGB(color) (((color&0x1F)<<11) | (color&0x7E0) | ((color&0xF800)>>11))
Geremia 5:b222a9461d6b 15
Geremia 30:87855d03d91a 16 #define FLIP_NONE 0
Geremia 30:87855d03d91a 17 #define FLIP_X 1
Geremia 30:87855d03d91a 18 #define FLIP_Y 2
Geremia 30:87855d03d91a 19
Geremia 3:48f3282c2be8 20 //#define USE_CS
Geremia 3:48f3282c2be8 21
Geremia 0:75ec1b3cde17 22 /** Protocol types
Geremia 0:75ec1b3cde17 23 */
dreschpe 25:daacdcf34e52 24 #include "platform.h"
dreschpe 25:daacdcf34e52 25
dreschpe 25:daacdcf34e52 26 #if DEVICE_PORTINOUT
Geremia 0:75ec1b3cde17 27 enum proto_t {
Geremia 21:ae0a4eedfc90 28 PAR_8 /**< Parallel 8bit, port pins 0 to 7 */
Geremia 21:ae0a4eedfc90 29 ,PAR_16 /**< Parallel 16bit, port pins 0 to 15 */
Geremia 21:ae0a4eedfc90 30 ,BUS_8 /**< Parallel 8bit, scattered pins */
Geremia 21:ae0a4eedfc90 31 ,BUS_16 /**< Parallel 16bit, scattered pins */
Geremia 0:75ec1b3cde17 32 ,SPI_8 /**< SPI 8bit */
Geremia 0:75ec1b3cde17 33 ,SPI_16 /**< SPI 16bit */
Geremia 0:75ec1b3cde17 34 };
dreschpe 25:daacdcf34e52 35 #else
dreschpe 25:daacdcf34e52 36 enum proto_t {
dreschpe 25:daacdcf34e52 37 BUS_8 /**< Parallel 8bit, scattered pins */
dreschpe 25:daacdcf34e52 38 ,BUS_16 /**< Parallel 16bit, scattered pins */
dreschpe 25:daacdcf34e52 39 ,SPI_8 /**< SPI 8bit */
dreschpe 25:daacdcf34e52 40 ,SPI_16 /**< SPI 16bit */
dreschpe 25:daacdcf34e52 41 };
dreschpe 25:daacdcf34e52 42 #endif
Geremia 0:75ec1b3cde17 43
Geremia 0:75ec1b3cde17 44
Geremia 6:8356d48a07db 45 /** Abstract interface class for spi and parallel protocols
Geremia 0:75ec1b3cde17 46 */
Geremia 0:75ec1b3cde17 47 class Protocols
Geremia 0:75ec1b3cde17 48 {
Geremia 0:75ec1b3cde17 49 public:
Geremia 0:75ec1b3cde17 50
Geremia 1:ff019d22b275 51 /** Send 8bit command to display controller
Geremia 0:75ec1b3cde17 52 *
Geremia 0:75ec1b3cde17 53 * @param cmd: byte to send
Geremia 0:75ec1b3cde17 54 *
Geremia 0:75ec1b3cde17 55 */
Geremia 1:ff019d22b275 56 virtual void wr_cmd8(unsigned char cmd) = 0;
Geremia 0:75ec1b3cde17 57
Geremia 1:ff019d22b275 58 /** Send 8bit data to display controller
Geremia 0:75ec1b3cde17 59 *
Geremia 1:ff019d22b275 60 * @param data: byte to send
Geremia 0:75ec1b3cde17 61 *
Geremia 0:75ec1b3cde17 62 */
Geremia 1:ff019d22b275 63 virtual void wr_data8(unsigned char data) = 0;
Geremia 0:75ec1b3cde17 64
Geremia 4:12ba0ecc2c1f 65 /** Send 2x8bit command to display controller
Geremia 1:ff019d22b275 66 *
Geremia 1:ff019d22b275 67 * @param cmd: halfword to send
Geremia 1:ff019d22b275 68 *
Geremia 1:ff019d22b275 69 */
Geremia 1:ff019d22b275 70 virtual void wr_cmd16(unsigned short cmd) = 0;
Geremia 1:ff019d22b275 71
Geremia 4:12ba0ecc2c1f 72 /** Send 2x8bit data to display controller
Geremia 1:ff019d22b275 73 *
Geremia 1:ff019d22b275 74 * @param data: halfword to send
Geremia 0:75ec1b3cde17 75 *
Geremia 0:75ec1b3cde17 76 */
Geremia 1:ff019d22b275 77 virtual void wr_data16(unsigned short data) = 0;
Geremia 1:ff019d22b275 78
Geremia 4:12ba0ecc2c1f 79 /** Send 16bit pixeldata to display controller
Geremia 4:12ba0ecc2c1f 80 *
Geremia 4:12ba0ecc2c1f 81 * @param data: halfword to send
Geremia 4:12ba0ecc2c1f 82 *
Geremia 4:12ba0ecc2c1f 83 */
Geremia 4:12ba0ecc2c1f 84 virtual void wr_gram(unsigned short data) = 0;
Geremia 4:12ba0ecc2c1f 85
Geremia 4:12ba0ecc2c1f 86 /** Send same 16bit pixeldata to display controller multiple times
Geremia 1:ff019d22b275 87 *
Geremia 1:ff019d22b275 88 * @param data: halfword to send
Geremia 1:ff019d22b275 89 * @param count: how many
Geremia 1:ff019d22b275 90 *
Geremia 1:ff019d22b275 91 */
Geremia 4:12ba0ecc2c1f 92 virtual void wr_gram(unsigned short data, unsigned int count) = 0;
Geremia 1:ff019d22b275 93
Geremia 4:12ba0ecc2c1f 94 /** Send array of pixeldata shorts to display controller
Geremia 1:ff019d22b275 95 *
Geremia 4:12ba0ecc2c1f 96 * @param data: unsigned short pixeldata array
Geremia 1:ff019d22b275 97 * @param lenght: lenght (in shorts)
Geremia 1:ff019d22b275 98 *
Geremia 1:ff019d22b275 99 */
Geremia 4:12ba0ecc2c1f 100 virtual void wr_grambuf(unsigned short* data, unsigned int lenght) = 0;
Geremia 0:75ec1b3cde17 101
Geremia 5:b222a9461d6b 102 /** Read 16bit pixeldata from display controller (with dummy cycle)
Geremia 5:b222a9461d6b 103 *
Geremia 11:b842b8e332cb 104 * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit
Geremia 5:b222a9461d6b 105 * @returns 16bit color
Geremia 5:b222a9461d6b 106 */
Geremia 11:b842b8e332cb 107 virtual unsigned short rd_gram(bool convert) = 0;
Geremia 5:b222a9461d6b 108
Geremia 7:bb0383b91104 109 /** Read 4x8bit register data (with dummy cycle)
Geremia 7:bb0383b91104 110 * @param reg the register to read
Geremia 7:bb0383b91104 111 * @returns data as uint
Geremia 7:bb0383b91104 112 *
Geremia 7:bb0383b91104 113 */
Geremia 7:bb0383b91104 114 virtual unsigned int rd_reg_data32(unsigned char reg) = 0;
Geremia 7:bb0383b91104 115
Geremia 7:bb0383b91104 116 /** Read 3x8bit ExtendedCommands register data
Geremia 7:bb0383b91104 117 * @param reg the register to read
Geremia 7:bb0383b91104 118 * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers
Geremia 7:bb0383b91104 119 * @returns data as uint
Geremia 7:bb0383b91104 120 * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode
Geremia 7:bb0383b91104 121 */
Geremia 7:bb0383b91104 122 virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) = 0;
Geremia 7:bb0383b91104 123
Geremia 20:14daa48ffd4c 124 /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent
Geremia 20:14daa48ffd4c 125 * for PAR protocols: a signle RD bit toggle
Geremia 20:14daa48ffd4c 126 * for SPI8: 8clocks
Geremia 20:14daa48ffd4c 127 * for SPI16: 16 clocks
Geremia 20:14daa48ffd4c 128 */
Geremia 20:14daa48ffd4c 129 virtual void dummyread () = 0;
Geremia 20:14daa48ffd4c 130
Geremia 20:14daa48ffd4c 131 /** ILI932x specific, select register for a successive write or read
Geremia 20:14daa48ffd4c 132 *
Geremia 20:14daa48ffd4c 133 * @param reg register to be selected
Geremia 20:14daa48ffd4c 134 * @param forread false = a write next (default), true = a read next
Geremia 20:14daa48ffd4c 135 * @note forread only used by SPI protocols
Geremia 20:14daa48ffd4c 136 */
Geremia 20:14daa48ffd4c 137 virtual void reg_select(unsigned char reg, bool forread =false) = 0;
Geremia 20:14daa48ffd4c 138
Geremia 20:14daa48ffd4c 139 /** ILI932x specific, write register with data
Geremia 20:14daa48ffd4c 140 *
Geremia 20:14daa48ffd4c 141 * @param reg register to write
Geremia 20:14daa48ffd4c 142 * @param data 16bit data
Geremia 20:14daa48ffd4c 143 */
Geremia 20:14daa48ffd4c 144 virtual void reg_write(unsigned char reg, unsigned short data) = 0;
Geremia 20:14daa48ffd4c 145
Geremia 20:14daa48ffd4c 146 /** ILI932x specific, read register
Geremia 20:14daa48ffd4c 147 *
Geremia 20:14daa48ffd4c 148 * @param reg register to be read
Geremia 20:14daa48ffd4c 149 * @returns 16bit register value
Geremia 20:14daa48ffd4c 150 */
Geremia 20:14daa48ffd4c 151 virtual unsigned short reg_read(unsigned char reg) = 0;
Geremia 20:14daa48ffd4c 152
Geremia 0:75ec1b3cde17 153 /** HW reset sequence (without display init commands)
Geremia 0:75ec1b3cde17 154 */
Geremia 0:75ec1b3cde17 155 virtual void hw_reset() = 0;
Geremia 0:75ec1b3cde17 156
Geremia 0:75ec1b3cde17 157 /** Set ChipSelect high or low
Geremia 0:75ec1b3cde17 158 * @param enable 0/1
Geremia 0:75ec1b3cde17 159 */
Geremia 0:75ec1b3cde17 160 virtual void BusEnable(bool enable) = 0;
Geremia 0:75ec1b3cde17 161
Geremia 0:75ec1b3cde17 162 };
Geremia 0:75ec1b3cde17 163 #endif