/*
* TOPPERS BASE PLATFORM MIDDLEWARE
*
* Copyright (C) 2017-2018 by TOPPERS PROJECT
* Educational Working Group.
*
* 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
* ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
* 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
* (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
* 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
* スコード中に含まれていること.
* (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
* 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
* 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
* の無保証規定を掲載すること.
* (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
* 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
* と.
* (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
* 作権表示,この利用条件および下記の無保証規定を掲載すること.
* (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
* 報告すること.
* (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
* 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
* また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
* 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
* 免責すること.
*
* 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
* よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
* に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
* アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
* の責任を負わない.
*
* @(#) $Id$
*/
/**
******************************************************************************
* @attention
*
*
© COPYRIGHT(c) 2016 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#ifndef _STLCD_OTM8009A_H_
#define _STLCD_OTM8009A_H_
#ifdef __cplusplus
extern "C" {
#endif
#include
#include
#include
#include
#include
#include
#include "device.h"
#include "i2c.h"
#include "ltdc.h"
#include "dsi.h"
#include "dfsdm.h"
/** @defgroup RCCEx_PLLSAI_DIVR RCCEx PLLSAI DIVR
* @{
*/
#define RCC_PLLSAIDIVR_2 ((uint32_t)0x00000000U)
#define RCC_PLLSAIDIVR_4 RCC_DCKCFGR1_PLLSAIDIVR_0
#define RCC_PLLSAIDIVR_8 RCC_DCKCFGR1_PLLSAIDIVR_1
#define RCC_PLLSAIDIVR_16 RCC_DCKCFGR1_PLLSAIDIVR
/**
* @brief LCD_OrientationTypeDef
* Possible values of Display Orientation
*/
#define OTM8009A_ORIENTATION_PORTRAIT ((uint32_t)0x00) /* Portrait orientation choice of LCD screen */
#define OTM8009A_ORIENTATION_LANDSCAPE ((uint32_t)0x01) /* Landscape orientation choice of LCD screen */
/**
* @brief Possible values of
* pixel data format (ie color coding) transmitted on DSI Data lane in DSI packets
*/
#define OTM8009A_FORMAT_RGB888 ((uint32_t)0x00) /* Pixel format chosen is RGB888 : 24 bpp */
#define OTM8009A_FORMAT_RBG565 ((uint32_t)0x02) /* Pixel format chosen is RGB565 : 16 bpp */
/**
* @brief otm8009a_480x800 Size
*/
/* Width and Height in Portrait mode */
#define OTM8009A_480X800_WIDTH ((uint16_t)480) /* LCD PIXEL WIDTH */
#define OTM8009A_480X800_HEIGHT ((uint16_t)800) /* LCD PIXEL HEIGHT */
/* Width and Height in Landscape mode */
#define OTM8009A_800X480_WIDTH ((uint16_t)800) /* LCD PIXEL WIDTH */
#define OTM8009A_800X480_HEIGHT ((uint16_t)480) /* LCD PIXEL HEIGHT */
/**
* @brief OTM8009A_480X800 Timing parameters for Portrait orientation mode
*/
#define OTM8009A_480X800_HSYNC ((uint16_t)63) /* Horizontal synchronization: This value is set to limit value mentionned
in otm8009a spec to fit with USB functional clock configuration constraints */
#define OTM8009A_480X800_HBP ((uint16_t)120) /* Horizontal back porch */
#define OTM8009A_480X800_HFP ((uint16_t)120) /* Horizontal front porch */
#define OTM8009A_480X800_VSYNC ((uint16_t)12) /* Vertical synchronization */
#define OTM8009A_480X800_VBP ((uint16_t)12) /* Vertical back porch */
#define OTM8009A_480X800_VFP ((uint16_t)12) /* Vertical front porch */
/**
* @brief OTM8009A_800X480 Timing parameters for Landscape orientation mode
* Same values as for Portrait mode in fact.
*/
#define OTM8009A_800X480_HSYNC OTM8009A_480X800_HSYNC /* Horizontal synchronization */
#define OTM8009A_800X480_HBP OTM8009A_480X800_HBP /* Horizontal back porch */
#define OTM8009A_800X480_HFP OTM8009A_480X800_HFP /* Horizontal front porch */
#define OTM8009A_800X480_VSYNC OTM8009A_480X800_VSYNC /* Vertical synchronization */
#define OTM8009A_800X480_VBP OTM8009A_480X800_VBP /* Vertical back porch */
#define OTM8009A_800X480_VFP OTM8009A_480X800_VFP /* Vertical front porch */
/* List of OTM8009A used commands */
/* Detailed in OTM8009A Data Sheet 'DATA_SHEET_OTM8009A_V0 92.pdf' */
/* Version of 14 June 2012 */
#define OTM8009A_CMD_NOP 0x00 /* NOP command */
#define OTM8009A_CMD_SWRESET 0x01 /* Sw reset command */
#define OTM8009A_CMD_RDDMADCTL 0x0B /* Read Display MADCTR command : read memory display access ctrl */
#define OTM8009A_CMD_RDDCOLMOD 0x0C /* Read Display pixel format */
#define OTM8009A_CMD_SLPIN 0x10 /* Sleep In command */
#define OTM8009A_CMD_SLPOUT 0x11 /* Sleep Out command */
#define OTM8009A_CMD_PTLON 0x12 /* Partial mode On command */
#define OTM8009A_CMD_DISPOFF 0x28 /* Display Off command */
#define OTM8009A_CMD_DISPON 0x29 /* Display On command */
#define OTM8009A_CMD_CASET 0x2A /* Column address set command */
#define OTM8009A_CMD_PASET 0x2B /* Page address set command */
#define OTM8009A_CMD_RAMWR 0x2C /* Memory (GRAM) write command */
#define OTM8009A_CMD_RAMRD 0x2E /* Memory (GRAM) read command */
#define OTM8009A_CMD_PLTAR 0x30 /* Partial area command (4 parameters) */
#define OTM8009A_CMD_TEOFF 0x34 /* Tearing Effect Line Off command : command with no parameter */
#define OTM8009A_CMD_TEEON 0x35 /* Tearing Effect Line On command : command with 1 parameter 'TELOM' */
/* Parameter TELOM : Tearing Effect Line Output Mode : possible values */
#define OTM8009A_TEEON_TELOM_VBLANKING_INFO_ONLY 0x00
#define OTM8009A_TEEON_TELOM_VBLANKING_AND_HBLANKING_INFO 0x01
#define OTM8009A_CMD_MADCTR 0x36 /* Memory Access write control command */
/* Possible used values of MADCTR */
#define OTM8009A_MADCTR_MODE_PORTRAIT 0x00
#define OTM8009A_MADCTR_MODE_LANDSCAPE 0x60 /* MY = 0, MX = 1, MV = 1, ML = 0, RGB = 0 */
#define OTM8009A_CMD_IDMOFF 0x38 /* Idle mode Off command */
#define OTM8009A_CMD_IDMON 0x39 /* Idle mode On command */
#define OTM8009A_CMD_COLMOD 0x3A /* Interface Pixel format command */
/* Possible values of COLMOD parameter corresponding to used pixel formats */
#define OTM8009A_COLMOD_RGB565 0x55
#define OTM8009A_COLMOD_RGB888 0x77
#define OTM8009A_CMD_RAMWRC 0x3C /* Memory write continue command */
#define OTM8009A_CMD_RAMRDC 0x3E /* Memory read continue command */
#define OTM8009A_CMD_WRTESCN 0x44 /* Write Tearing Effect Scan line command */
#define OTM8009A_CMD_RDSCNL 0x45 /* Read Tearing Effect Scan line command */
/* CABC Management : ie : Content Adaptive Back light Control in IC OTM8009a */
#define OTM8009A_CMD_WRDISBV 0x51 /* Write Display Brightness command */
#define OTM8009A_CMD_WRCTRLD 0x53 /* Write CTRL Display command */
#define OTM8009A_CMD_WRCABC 0x55 /* Write Content Adaptive Brightness command */
#define OTM8009A_CMD_WRCABCMB 0x5E /* Write CABC Minimum Brightness command */
/**
* @brief OTM8009A_480X800 frequency divider
*/
#define OTM8009A_480X800_FREQUENCY_DIVIDER 2 /* LCD Frequency divider */
/**
* @brief LCD FB_StartAddress
*/
#define LCD_FB_START_ADDRESS ((uint32_t)0xC0000000)
/** @brief Maximum number of LTDC layers
*/
#define LTDC_MAX_LAYER_NUMBER ((uint32_t) 2)
/** @brief LTDC Background layer index
*/
#define LTDC_ACTIVE_LAYER_BACKGROUND ((uint32_t) 0)
/** @brief LTDC Foreground layer index
*/
#define LTDC_ACTIVE_LAYER_FOREGROUND ((uint32_t) 1)
/** @brief Number of LTDC layers
*/
#define LTDC_NB_OF_LAYERS ((uint32_t) 2)
/** @brief LTDC Default used layer index
*/
#define LTDC_DEFAULT_ACTIVE_LAYER LTDC_ACTIVE_LAYER_FOREGROUND
/**
* @brief LCD Display OTM8009A DSI Virtual Channel ID
*/
#define LCD_OTM8009A_ID ((uint32_t) 0)
/**
* @brief LCD color
*/
#define LCD_COLOR_BLUE ((uint32_t)0xFF0000FF)
#define LCD_COLOR_GREEN ((uint32_t)0xFF00FF00)
#define LCD_COLOR_RED ((uint32_t)0xFFFF0000)
#define LCD_COLOR_CYAN ((uint32_t)0xFF00FFFF)
#define LCD_COLOR_MAGENTA ((uint32_t)0xFFFF00FF)
#define LCD_COLOR_YELLOW ((uint32_t)0xFFFFFF00)
#define LCD_COLOR_LIGHTBLUE ((uint32_t)0xFF8080FF)
#define LCD_COLOR_LIGHTGREEN ((uint32_t)0xFF80FF80)
#define LCD_COLOR_LIGHTRED ((uint32_t)0xFFFF8080)
#define LCD_COLOR_LIGHTCYAN ((uint32_t)0xFF80FFFF)
#define LCD_COLOR_LIGHTMAGENTA ((uint32_t)0xFFFF80FF)
#define LCD_COLOR_LIGHTYELLOW ((uint32_t)0xFFFFFF80)
#define LCD_COLOR_DARKBLUE ((uint32_t)0xFF000080)
#define LCD_COLOR_DARKGREEN ((uint32_t)0xFF008000)
#define LCD_COLOR_DARKRED ((uint32_t)0xFF800000)
#define LCD_COLOR_DARKCYAN ((uint32_t)0xFF008080)
#define LCD_COLOR_DARKMAGENTA ((uint32_t)0xFF800080)
#define LCD_COLOR_DARKYELLOW ((uint32_t)0xFF808000)
#define LCD_COLOR_WHITE ((uint32_t)0xFFFFFFFF)
#define LCD_COLOR_LIGHTGRAY ((uint32_t)0xFFD3D3D3)
#define LCD_COLOR_GRAY ((uint32_t)0xFF808080)
#define LCD_COLOR_DARKGRAY ((uint32_t)0xFF404040)
#define LCD_COLOR_BLACK ((uint32_t)0xFF000000)
#define LCD_COLOR_BROWN ((uint32_t)0xFFA52A2A)
#define LCD_COLOR_ORANGE ((uint32_t)0xFFFFA500)
#define LCD_COLOR_TRANSPARENT ((uint32_t)0xFF000000)
/**
* @brief Possible values of
* pixel data format (ie color coding) transmitted on DSI Data lane in DSI packets
*/
#define LCD_DSI_PIXEL_DATA_FMT_RBG888 DSI_RGB888 /*!< DSI packet pixel format chosen is RGB888 : 24 bpp */
#define LCD_DSI_PIXEL_DATA_FMT_RBG565 DSI_RGB565 /*!< DSI packet pixel format chosen is RGB565 : 16 bpp */
/*
* LCDハンドラ構造体定義
*/
typedef struct
{
LTDC_Handle_t *hltdc; /* LTDCハンドラ */
DSI_Handle_t *hdsi; /* DSIハンドラ */
DSI_VideoConfig_t dsivc; /* DSI video configハンドラ */
uint32_t layer;
uint16_t _width; /* 幅ピクセル数 */
uint16_t _height; /* 高さピクセル数 */
} LCD_Handler_t;
/**
* @brief LCD Drawing main properties
*/
typedef struct
{
LCD_Handler_t *hlcd;
uint32_t TextColor; /* Specifies the color of text */
uint32_t BackColor; /* Specifies the background color below the text */
void *pFont; /* Specifies the font used for the text */
} LCD_DrawProp_t;
/**
* @brief LCD Drawing point (pixel) geometric definition
*/
typedef struct
{
int16_t X; /*!< geometric X position of drawing */
int16_t Y; /*!< geometric Y position of drawing */
} Point;
/**
* @brief Pointer on LCD Drawing point (pixel) geometric definition
*/
typedef Point * pPoint;
/**
* @brief LCD_OrientationTypeDef
* Possible values of Display Orientation
*/
typedef enum
{
LCD_ORIENTATION_PORTRAIT = 0x00, /*!< Portrait orientation choice of LCD screen */
LCD_ORIENTATION_LANDSCAPE = 0x01, /*!< Landscape orientation choice of LCD screen */
LCD_ORIENTATION_INVALID = 0x02 /*!< Invalid orientation choice of LCD screen */
} LCD_OrientationTypeDef;
extern ER lcd_init(LCD_Handler_t *hlcd, LCD_OrientationTypeDef orientation);
extern ER lcd_reset(LCD_Handler_t *hlcd);
extern ER lcd_layerdefaultinit(LCD_Handler_t *hlcd, LCD_DrawProp_t *pDrawProp, uint16_t LayerIndex, uint32_t FB_Address);
extern void lcd_setlayervisible(LCD_Handler_t *hlcd, uint32_t LayerIndex, uint8_t State);
extern void lcd_settransparency(LCD_Handler_t *hlcd, uint32_t LayerIndex, uint8_t Transparency);
extern void lcd_setlayeraddress(LCD_Handler_t *hlcd, uint32_t LayerIndex, uint32_t Address);
extern void lcd_setcolorkeying(LCD_Handler_t *hlcd, uint32_t LayerIndex, uint32_t RGBValue);
extern void lcd_resetcolorkeying(LCD_Handler_t *hlcd, uint32_t LayerIndex);
extern void lcd_setAddrWindow(LCD_Handler_t *hlcd, uint16_t LayerIndex, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
extern void lcd_clear(LCD_Handler_t *hlcd, uint32_t Color);
extern uint32_t lcd_readPixel(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos);
extern void lcd_drawPixel(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code);
extern void lcd_drawFastHLine(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint32_t color);
extern void lcd_drawFastVLine(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint32_t color);
extern void lcd_drawBitmap(LCD_Handler_t *hlcd, uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp);
extern void lcd_displayOn(LCD_Handler_t *hlcd);
extern void lcd_displayOff(LCD_Handler_t *hlcd);
extern void lcd_setbrightness(LCD_Handler_t *hlcd, uint8_t BrightnessValue);
extern void lcd_fillRect(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint32_t color);
extern void lcd_drawLine(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
extern void lcd_drawRect(LCD_DrawProp_t *pDrawProp, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
extern void lcd_DrawCircle(LCD_DrawProp_t *pDrawProp, uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
extern void lcd_DrawEllipse(LCD_DrawProp_t *pDrawProp, int Xpos, int Ypos, int XRadius, int YRadius);
extern void lcd_drawPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount);
extern void lcd_fillCircle(LCD_DrawProp_t *pDrawProp, uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
extern void lcd_fillEllipse(LCD_DrawProp_t *pDrawProp, int Xpos, int Ypos, int XRadius, int YRadius);
extern void lcd_fillPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount);
#ifdef __cplusplus
}
#endif
#endif /* _STLCD_OTM8009A_H_ */