Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional macros/constants to sys/lcd.h and created sys/spi.h #489

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/ce/include/sys/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ extern "C" {
/** LCD Control register */
#define lcd_Control (*(volatile uint24_t*)0xE30018)
/* @cond */
/** LCD RGB/BGR and Bits per pixel */
#define lcd_VideoMode (*(volatile uint16_t*)0xE30018)
#define LCD_RGB1bit (0x821) /**< RGB 1bit indexed color */
#define LCD_RGB2bit (0x823) /**< RGB 2bit indexed color */
#define LCD_RGB4bit (0x825) /**< RGB 4bit indexed color */
#define LCD_RGB8bit (0x827) /**< RGB 8bit indexed color */
#define LCD_RGB1555 (0x829) /**< RGB 1555 16bit */
#define LCD_RGB565 (0x82D) /**< RGB 565 16bit */
#define LCD_RGB444 (0x82F) /**< RGB 444 16bit */
#define LCD_RGB16bit (LCD_RGB565) /**< TI-OS Default */
#define LCD_BGR1bit (0x921) /**< BGR 1bit indexed color */
#define LCD_BGR2bit (0x923) /**< BGR 2bit indexed color */
#define LCD_BGR4bit (0x925) /**< BGR 4bit indexed color */
#define LCD_BGR8bit (0x927) /**< BGR 8bit indexed color */
#define LCD_BGR1555 (0x929) /**< BGR 1555 16bit */
#define LCD_BGR565 (0x92D) /**< BGR 565 16bit */
#define LCD_BGR444 (0x92F) /**< BGR 444 16bit */
#define LCD_BGR16bit (LCD_BGR565) /**< TI-OS Default */
/** LCD Bits per pixel */
#define lcd_VideoBPP (*(volatile uint8_t*)0xE30018)
#define LCD_INDEXED1 (0x21) /**< 1bit indexed color */
#define LCD_INDEXED2 (0x23) /**< 2bit indexed color */
#define LCD_INDEXED4 (0x25) /**< 4bit indexed color */
#define LCD_INDEXED8 (0x27) /**< 8bit indexed color */
#define LCD_COLOR1555 (0x29) /**< 1555 16bit */
#define LCD_COLOR565 (0x2D) /**< 565 16bit */
#define LCD_COLOR444 (0x2F) /**< 444 16bit */
#define LCD_COLOR16 (LCD_COLOR565) /**< TI-OS Default */
#define lcd_EnableInt (*(volatile uint8_t*)0xE3001C)
#define lcd_IntStatus (*(volatile uint8_t*)0xE30020)
#define lcd_IntStatusMasked (*(volatile uint8_t*)0xE30024)
Expand All @@ -42,8 +70,8 @@ extern "C" {
/** LCD palette registers, 512 bytes */
#define lcd_Palette ((uint16_t*)0xE30200)
/* @cond */
#define lcd_CrsrImageLen32 256
#define lcd_CrsrImageLen64 1024
#define lcd_CrsrImageLen32 (256)
#define lcd_CrsrImageLen64 (1024)
#define lcd_CrsrImage ((uint8_t*)0xE30800)
#define lcd_CrsrCtrl (*(volatile uint8_t*)0xE30C00)
#define lcd_CrsrConfig (*(volatile uint8_t*)0xE30C04)
Expand Down
104 changes: 104 additions & 0 deletions src/ce/include/sys/spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @file
* @authors
* @brief CE SPI controller define file
*/

#ifndef SYS_SPI_H
#define SYS_SPI_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/* @cond */
#define spi_ControlRegister0 ((volatile void*)0xF80000)
#define spi_ControlRegister1 ((volatile void*)0xF80004)
#define spi_ControlRegister2 ((volatile void*)0xF80008)
#define spi_StatusBits ((const volatile void*)0xF8000C)
#define spi_InterruptControl ((volatile void*)0xF80010)
#define spi_InterruptStatus ((const volatile void*)0xF80014)
#define spi_FIFO ((volatile void*)0xF80018)
#define spi_InsideReservedRange ((volatile void*)0xF8001C)
#define spi_Revision ((const volatile void*)0xF80060)
#define spi_Features (*(const volatile uint32_t*)0xF80064)
/* @endcond */

/**
* In order to reliably use the LCD interface, the
* boot_InitializeHardware routine should be called at the start of a program
* to select the LCD interface and reset its configuration to the default.
*/
#define boot_InitializeHardware() ((void(*)(void))0x384)();

/**
* Sends a Command to the SPI controller using the 9bit FIFO protocol.
*
* @param[in] x 8bit command.
*/
#define SPI_COMMAND(x) \
do { \
*(volatile uint8_t*)spi_FIFO = ((x) >> 6) & 0b111; \
*(volatile uint8_t*)spi_FIFO = ((x) >> 3) & 0b111; \
*(volatile uint8_t*)spi_FIFO = (x) & 0b111; \
*(volatile uint8_t*)spi_ControlRegister2 = 0x1; \
while ( ((const volatile uint8_t*)spi_StatusBits)[1] & 0xF0) {}; \
while ( ((const volatile uint8_t*)spi_StatusBits)[0] & (1 << 2)) {}; \
*(volatile uint8_t*)spi_ControlRegister2 = 0x0; \
} while(0)

/**
* Sends a Parameter to the SPI controller using the 9bit FIFO protocol.
*
* @param[in] x 8bit parameter.
*/
#define SPI_PARAMETER(x) \
do { \
*(volatile uint8_t*)spi_FIFO = (((x) >> 6) & 0b111) | 0b100; \
*(volatile uint8_t*)spi_FIFO = ((x) >> 3) & 0b111; \
*(volatile uint8_t*)spi_FIFO = (x) & 0b111; \
*(volatile uint8_t*)spi_ControlRegister2 = 0x1; \
while ( ((const volatile uint8_t*)spi_StatusBits)[1] & 0xF0) {}; \
while ( ((const volatile uint8_t*)spi_StatusBits)[0] & (1 << 2)) {}; \
*(volatile uint8_t*)spi_ControlRegister2 = 0x0; \
} while(0)

/** @todo Implement vsync */
#define SPI_UNINVERT_COLORS() SPI_COMMAND(0x20)

/** @todo Implement vsync */
#define SPI_INVERT_COLORS() SPI_COMMAND(0x21)

/** Sets the LCD to BGR Row-Major mode (TI-OS default) */
#define SPI_ROW_MAJOR() \
do { \
SPI_COMMAND(0x36); \
SPI_PARAMETER(0b00001000); \
SPI_COMMAND(0x2A); \
SPI_PARAMETER(0x00); SPI_PARAMETER(0x00); \
SPI_PARAMETER(0x01); SPI_PARAMETER(0x3F); \
SPI_COMMAND(0x2B); \
SPI_PARAMETER(0x00); SPI_PARAMETER(0x00); \
SPI_PARAMETER(0x00); SPI_PARAMETER(0xEF); \
} while(0)

/** Sets the LCD to BGR Column-Major mode */
#define SPI_COLUMN_MAJOR() \
do { \
SPI_COMMAND(0x36); \
SPI_PARAMETER(0b00101000); \
SPI_COMMAND(0x2A); \
SPI_PARAMETER(0x00); SPI_PARAMETER(0x00); \
SPI_PARAMETER(0x00); SPI_PARAMETER(0xEF); \
SPI_COMMAND(0x2B); \
SPI_PARAMETER(0x00); SPI_PARAMETER(0x00); \
SPI_PARAMETER(0x01); SPI_PARAMETER(0x3F); \
} while(0)

#ifdef __cplusplus
}
#endif

#endif