initial working (stm32f4-discovery)

This commit is contained in:
2026-07-31 19:07:15 +03:00
commit ce6632f48c
2214 changed files with 1264937 additions and 0 deletions
@@ -0,0 +1,37 @@
---
name: 'Bug report'
about: 'Create a report to help us improve the quality of our software'
title: ''
labels: ''
assignees: ''
---
**Caution**
The Issues are strictly limited for the reporting of problem encountered with the software provided in this project.
For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post your report to the **ST Community** in the STM32 MCUs dedicated [page](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus).
**Describe the set-up**
* The board (either ST RPN reference or your custom board)
* IDE or at least the compiler and its version
**Describe the bug (skip if none)**
A clear and concise description of what the bug is.
**How to reproduce the bug (skip if none)**
1. Indicate the global behavior of your application project
2. List the modules that you suspect to be the cause of the problem (Drivers, BSP, MW...)
3. Describe the use case that generates the problem
4. How we can reproduce the problem
**Additional context**
If you have a first analysis, an enhancement, a fix or a patch, thank you to share your proposal.
**Screenshots**
If applicable, add screenshots to help explain your problem.
@@ -0,0 +1,3 @@
## IMPORTANT INFORMATION
Pull-requests are **not** accepted on this repository. Please use issues to report any bug or request.
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team via this [link](https://www.st.com/content/st_com/en/contact-us.html).
All complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4,
available [here](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html).
For answers to common questions about this code of conduct, see the [FAQ section](https://www.contributor-covenant.org/faq).
@@ -0,0 +1,28 @@
## Contributing guide
This document serves as a checklist before contributing to this repository.
It includes links to read up on if topics are unclear to you.
This guide mainly focuses on steps to be followed to submit an issue or a pull-request.
### 1. Before opening an issue
To report a bug or a request please file an issue in the right repository
(example for [ls016b8uy](https://github.com/STMicroelectronics/ls016b8uy/issues/new/choose)).
Please check the following boxes before posting an issue:
- [ ] `Make sure you are using the latest commit (major releases are tagged, but corrections are available as new commits).`
- [ ] `Make sure your issue is a question/feedback/suggestions RELATED TO the software provided in this repository.` Otherwise, it should be submitted to the ST Community under the MCU topic [page](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus).
- [ ] `Make sure your issue is not already reported/fixed on GitHub or discussed on a previous issue.` Please refer to this [dashboard](https://github.com/orgs/STMicroelectronics/projects/2) for the list of issues and pull-requests. Do not forget to browse into the **closed** issues.
### 2. Posting the issue
When you have checked the previous boxes. You will find two templates (Bug Report or Other Issue) available in the **Issues** tab of the repository.
### 3. Pull Requests
Pull-requests are **not** accepted on this repository. Please use **issues** to report any bug or request.
### 4. How to proceed
* We recommend to engage first a communication thru an issue, in order to present your proposal. Just to confirm that it corresponds to STMicroelectronics domain or scope.
* Then fork the project to your GitHub account to further develop your contribution. Please use the latest commit version.
* Please, submit one Pull Request for one new feature or proposal. This will ease the analysis and the final merge if accepted.
@@ -0,0 +1,27 @@
Copyright 2017 STMicroelectronics.
All rights reserved.
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 the copyright holder 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.
@@ -0,0 +1,40 @@
# BSP LS016B8UY Component
## Overview
**STM32Cube** is an STMicroelectronics original initiative to ease the developers life by reducing efforts, time and cost.
**STM32Cube** covers the overall STM32 products portfolio. It includes a comprehensive embedded software platform delivered for each STM32 series.
* The CMSIS modules (core and device) corresponding to the ARM(tm) core implemented in this STM32 product.
* The STM32 HAL-LL drivers, an abstraction layer offering a set of APIs ensuring maximized portability across the STM32 portfolio.
* The BSP drivers of each evaluation, demonstration or nucleo board provided for this STM32 series.
* A consistent set of middleware components such as RTOS, USB, FatFS, graphics, touch sensing library...
* A full set of software projects (basic examples, applications, and demonstrations) for each board provided for this STM32 series.
Two models of publication are proposed for the STM32Cube embedded software:
* The monolithic **MCU Package**: all STM32Cube software modules of one STM32 series are present (Drivers, Middleware, Projects, Utilities) in the repository (usual name **STM32Cubexx**, xx corresponding to the STM32 series).
* The **MCU component**: each STM32Cube software module being part of the STM32Cube MCU Package, is delivered as an individual repository, allowing the user to select and get only the required software functions.
## Description
This **ls016b8uy** MCU component repository is one element **common to all** STM32Cube MCU embedded software packages, providing the **LS016B8UY** BSP LCD component part.
## License
Copyright (c) 2016 STMicroelectronics
This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this software except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause).
## Release note
Details about the content of this release are available in the release note [here](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/ls016b8uy/blob/main/Release_Notes.html).
## Compatibility information
Please refer to the repository of the BSP **board** driver you are using to know which version of this BSP component driver to use. It is **crucial** that you use a consistent set of versions.
## Troubleshooting
If you have any issue with the **software content** of this repository, you can file an issue [here](https://github.com/STMicroelectronics/ls016b8uy/issues/new/choose).
For any other question related to the product, the tools, the environment, you can submit a topic to the [ST Community](https://community.st.com/s/).
@@ -0,0 +1,31 @@
# Report potential product security vulnerabilities
ST places a high priority on security, and our Product Security Incident
Response Team (PSIRT) is committed to rapidly addressing potential security
vulnerabilities affecting our products. PSIRT's long history and vast experience
in security allows ST to perform clear analyses and provide appropriate guidance
on mitigations and solutions when applicable.
If you wish to report potential security vulnerabilities regarding our products,
**please do not report them through public GitHub issues.** Instead, we
encourage you to report them to our ST PSIRT following the process described at:
**https://www.st.com/content/st_com/en/security/report-vulnerabilities.html**
### IMPORTANT - READ CAREFULLY:
STMicroelectronics International N.V., on behalf of itself, its affiliates and
subsidiaries, (collectively “ST”) takes all potential security vulnerability
reports or other related communications (“Report(s)”) seriously. In order to
review Your Report (the terms “You” and “Yours” include your employer, and all
affiliates, subsidiaries and related persons or entities) and take actions as
deemed appropriate, ST requires that we have the rights and Your permission to
do so.
As such, by submitting Your Report to ST, You agree that You have the right to
do so, and You grant to ST the rights to use the Report for purposes related to
security vulnerability analysis, testing, correction, patching, reporting and
any other related purpose or function.
By submitting Your Report, You agree that ST’s
[Privacy Policy](https://www.st.com/content/st_com/en/common/privacy-portal.html)
applies to all related communications.
@@ -0,0 +1,640 @@
/**
******************************************************************************
* @file ls016b8uy.c
* @author MCD Application Team
* @brief This file includes the LCD driver for LS016B8UY LCD.
******************************************************************************
* @attention
*
* Copyright (c) 2016 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "ls016b8uy.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ls016b8uy
* @brief This file provides a set of functions needed to drive the
* LS016B8UY LCD.
* @{
*/
/** @defgroup LS016B8UY_Private_TypesDefinitions
* @{
*/
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
} LS016B8UY_Rgb888;
/**
* @}
*/
/** @defgroup LS016B8UY_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup LS016B8UY_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup LS016B8UY_Private_Variables
* @{
*/
LCD_DrvTypeDef ls016b8uy_drv =
{
ls016b8uy_Init,
ls016b8uy_ReadID,
ls016b8uy_DisplayOn,
ls016b8uy_DisplayOff,
ls016b8uy_SetCursor,
ls016b8uy_WritePixel,
ls016b8uy_ReadPixel,
ls016b8uy_SetDisplayWindow,
ls016b8uy_DrawHLine,
ls016b8uy_DrawVLine,
ls016b8uy_GetLcdPixelWidth,
ls016b8uy_GetLcdPixelHeight,
ls016b8uy_DrawBitmap,
ls016b8uy_DrawRGBImage,
};
static uint16_t WindowsXstart = 0;
static uint16_t WindowsYstart = 0;
static uint16_t WindowsXend = LS016B8UY_LCD_PIXEL_WIDTH-1;
static uint16_t WindowsYend = LS016B8UY_LCD_PIXEL_HEIGHT-1;
/**
* @}
*/
/** @defgroup LS016B8UY_Private_FunctionPrototypes
* @{
*/
static LS016B8UY_Rgb888 ls016b8uy_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos);
static void ls016b8uy_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata);
/**
* @}
*/
/** @defgroup LS016B8UY_Private_Functions
* @{
*/
/**
* @brief Initialize the LS016B8UY LCD Component.
* @param None
* @retval None
*/
void ls016b8uy_Init(void)
{
uint8_t parameter[4];
/* Initialize LS016B8UY low level bus layer ----------------------------------*/
LCD_IO_Init();
parameter[0] = 0x00; /* VSYNC output */
ls016b8uy_WriteReg(LCD_CMD_VSYNC_OUTPUT, parameter, 1);
parameter[0] = 0x06; /* 18 bits color mode */
ls016b8uy_WriteReg(LCD_CMD_COLOR_MODE, parameter, 1);
parameter[0] = 0x01; /* Panel setting command <No.1 UN-Lock> */
parameter[1] = 0xFE;
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_1, parameter, 2);
parameter[0] = 0xDE; /* Panel setting command <No.2 UN-Lock> */
parameter[1] = 0x21;
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_2, parameter, 2);
parameter[0] = 0x05; /* V-Porch setting */
parameter[1] = 0x33;
ls016b8uy_WriteReg(LCD_CMD_PANEL_V_PORCH, parameter, 2);
parameter[0] = 0x05; /* Idle mode V-Porch setting */
parameter[1] = 0x33;
ls016b8uy_WriteReg(LCD_CMD_PANEL_IDLE_V_PORCH, parameter, 2);
parameter[0] = 0x04; /* panel timing setting */
parameter[1] = 0x03;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_1, parameter, 2);
parameter[0] = 0x5E; /* panel timing setting */
parameter[1] = 0x08;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_2, parameter, 2);
parameter[0] = 0x0A; /* panel timing setting */
parameter[1] = 0x0C;
parameter[2] = 0x02;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_3, parameter, 3);
parameter[0] = 0x03; /* panel timing setting */
parameter[1] = 0x04;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_4, parameter, 2);
parameter[0] = 0x0C; /* panel power setting */
ls016b8uy_WriteReg(LCD_CMD_PANEL_POWER, parameter, 1);
parameter[0] = 0x02; /* Oscillator Setting = 2MHz */
ls016b8uy_WriteReg(LCD_CMD_OSCILLATOR, parameter, 1);
parameter[0] = 0x53; /* GVDD = 4.76V setting */
ls016b8uy_WriteReg(LCD_CMD_GVDD, parameter, 1);
parameter[0] = 0x00; /* Reload MTP After SLPOUT */
parameter[1] = 0x45; /* VCOMH=3.76V */
ls016b8uy_WriteReg(LCD_CMD_RELOAD_MTP_VCOMH, parameter, 2);
parameter[0] = 0x03; /* OP-Amp Ability. (Normal) */
parameter[1] = 0x12; /* Step-up Cycle for AVDD Booster Freq./4 */
ls016b8uy_WriteReg(LCD_CMD_OPAMP, parameter, 2);
parameter[0] = 0x00; /* Tearing Effect Option (00h:VSYNC Interface OFF, 01h:VSYNC Interface ON) */
ls016b8uy_WriteReg(LCD_CMD_TEARING_EFFECT, parameter, 1);
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_LOCK, parameter, 0); /* Panel setting command <Lock> */
ls016b8uy_WriteReg(LCD_CMD_SLEEP_OUT, parameter, 0); /* Sleep Out Command */
LCD_IO_Delay(150); /* Wait for 150ms */
parameter[0] = 0x00; /* CASET */
parameter[1] = 0x1E;
parameter[2] = 0x00;
parameter[3] = 0xD1;
ls016b8uy_WriteReg(LCD_CMD_CASET, parameter, 4);
parameter[0] = 0x00; /* RASET */
parameter[1] = 0x00;
parameter[2] = 0x00;
parameter[3] = 0xB3;
ls016b8uy_WriteReg(LCD_CMD_RASET, parameter, 4);
parameter[0] = 0x83; /* Normal display for Driver Down side */
ls016b8uy_WriteReg(LCD_CMD_NORMAL_DISPLAY, parameter, 1);
ls016b8uy_DisplayOn(); /* Display ON command */
}
/**
* @brief Enables the Display.
* @param None
* @retval None
*/
void ls016b8uy_DisplayOn(void)
{
ls016b8uy_WriteReg(LCD_CMD_DISPLAY_ON, (uint8_t*)NULL, 0); /* Display ON command */
ls016b8uy_WriteReg(LCD_CMD_IDLE_MODE_OFF, (uint8_t*)NULL, 0); /* Idle mode OFF command */
}
/**
* @brief Disables the Display.
* @param None
* @retval None
*/
void ls016b8uy_DisplayOff(void)
{
ls016b8uy_WriteReg(LCD_CMD_DISPLAY_OFF, (uint8_t*)NULL, 0); /* Display OFF command */
LCD_IO_Delay(20); /* Wait for 20ms */
ls016b8uy_WriteReg(LCD_CMD_SLEEP_IN, (uint8_t*)NULL, 0); /* Sleep In Command */
LCD_IO_Delay(150); /* Wait for 150ms */
}
/**
* @brief Get the LCD pixel Width.
* @param None
* @retval The Lcd Pixel Width
*/
uint16_t ls016b8uy_GetLcdPixelWidth(void)
{
return (uint16_t)LS016B8UY_LCD_PIXEL_WIDTH;
}
/**
* @brief Get the LCD pixel Height.
* @param None
* @retval The Lcd Pixel Height
*/
uint16_t ls016b8uy_GetLcdPixelHeight(void)
{
return (uint16_t)LS016B8UY_LCD_PIXEL_HEIGHT;
}
/**
* @brief Get the LS016B8UY ID.
* @param None
* @retval The LS016B8UY ID
*/
uint16_t ls016b8uy_ReadID(void)
{
LCD_IO_Init();
/* TODO : LCD read ID command not known for now, so assumption that the connected LCD is LS016B8UY */
return (LS016B8UY_ID);
}
/**
* @brief Set Cursor position.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval None
*/
void ls016b8uy_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
uint8_t parameter[4];
parameter[0] = 0x00; /* CASET */
parameter[1] = 0x1E + Xpos;
parameter[2] = 0x00;
parameter[3] = 0xD1 + Xpos;
ls016b8uy_WriteReg(LCD_CMD_CASET, parameter, 4);
parameter[0] = 0x00; /* RASET */
parameter[1] = 0x00 + Ypos;
parameter[2] = 0x00;
parameter[3] = 0xB3 + Ypos;
ls016b8uy_WriteReg(LCD_CMD_RASET, parameter, 4);
}
/**
* @brief Write pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param RGBCode: the RGB pixel color in RGB565 format
* @retval None
*/
void ls016b8uy_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{
uint16_t r, g, b;
uint16_t rgb888_part1, rgb888_part2;
r = (RGBCode & 0xF800) >> 11; /* Extract red component from RGB565 pixel data */
g = (RGBCode & 0x07E0) >> 5; /* Extract green component from RGB565 pixel data */
b = (RGBCode & 0x001F) >> 0; /* Extract blue component from RGB565 pixel data */
/* Prepare data to write with new pixel components and read old pixel component */
rgb888_part1 = (r << 11) + (g << 2);
rgb888_part2 = (b << 11);
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Write RAM data */
LCD_IO_WriteData(rgb888_part1);
LCD_IO_WriteData(rgb888_part2);
}
/**
* @brief Read pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval The RGB pixel color in RGB565 format
*/
uint16_t ls016b8uy_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
LS016B8UY_Rgb888 rgb888;
uint8_t r, g, b;
uint16_t rgb565;
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Read RGB888 data from LCD RAM */
rgb888 = ls016b8uy_ReadPixel_rgb888(Xpos, Ypos);
/* Convert RGB888 to RGB565 */
r = ((rgb888.red & 0xF8) >> 3); /* Extract the red component 5 most significant bits */
g = ((rgb888.green & 0xFC) >> 2); /* Extract the green component 6 most significant bits */
b = ((rgb888.blue & 0xF8) >> 3); /* Extract the blue component 5 most significant bits */
rgb565 = ((uint16_t)(r) << 11) + ((uint16_t)(g) << 5) + ((uint16_t)(b) << 0);
return (rgb565);
}
/**
* @brief Writes to the selected LCD register.
* @param Command: command value (or register address as named in LS016B8UY doc).
* @param Parameters: pointer on parameters value (if command uses one or several parameters).
* @param NbParameters: number of command parameters (0 if no parameter)
* @retval None
*/
void ls016b8uy_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters)
{
uint8_t i;
/* Send command */
LCD_IO_WriteReg(Command);
/* Send command's parameters if any */
for (i=0; i<NbParameters; i++)
{
LCD_IO_WriteData(Parameters[i]);
}
}
/**
* @brief Reads the selected LCD Register.
* @param Command: command value (or register address as named in LS016B8UY doc).
* @retval Register Value.
*/
uint8_t ls016b8uy_ReadReg(uint8_t Command)
{
/* Send command */
LCD_IO_WriteReg(Command);
/* Read dummy data */
LCD_IO_ReadData();
/* Read register value */
return (LCD_IO_ReadData());
}
/**
* @brief Sets a display window
* @param Xpos: specifies the X bottom left position.
* @param Ypos: specifies the Y bottom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void ls016b8uy_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
if (Xpos < LS016B8UY_LCD_PIXEL_WIDTH)
{
WindowsXstart = Xpos;
}
else
{
WindowsXstart = 0;
}
if (Ypos < LS016B8UY_LCD_PIXEL_HEIGHT)
{
WindowsYstart = Ypos;
}
else
{
WindowsYstart = 0;
}
if (Width + Xpos <= LS016B8UY_LCD_PIXEL_WIDTH)
{
WindowsXend = Width + Xpos - 1;
}
else
{
WindowsXend = LS016B8UY_LCD_PIXEL_WIDTH - 1;
}
if (Height + Ypos <= LS016B8UY_LCD_PIXEL_HEIGHT)
{
WindowsYend = Height + Ypos - 1;
}
else
{
WindowsYend = LS016B8UY_LCD_PIXEL_HEIGHT-1;
}
}
/**
* @brief Draw vertical line.
* @param RGBCode: Specifies the RGB color in RGB565 format
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the Line length.
* @retval None
*/
void ls016b8uy_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
uint16_t r, g, b;
uint16_t rgb888_part1, rgb888_part2, rgb888_part3;
r = (RGBCode & 0xF800) >> 11; /* Extract red component from RGB565 pixel data */
g = (RGBCode & 0x07E0) >> 5; /* Extract green component from RGB565 pixel data */
b = (RGBCode & 0x001F) >> 0; /* Extract blue component from RGB565 pixel data */
rgb888_part1 = (r << 11) + (g << 2); /* Build pattern first part to write in LCD RAM */
rgb888_part2 = (b << 11) + (r << 3); /* Build pattern second part to write in LCD RAM */
rgb888_part3 = (g << 10) + (b << 3); /* Build pattern third part to write in LCD RAM */
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Sent a complete line */
for(counter = 0; counter < Length; counter+=2)
{
/* Write 2 pixels at a time by performing 3 access (pixels coded on 24 bits in LCD RAM whereas access are coded on 16 bits) */
LCD_IO_WriteData(rgb888_part1);
LCD_IO_WriteData(rgb888_part2);
if (counter != (Length-1)) /* When writing last pixel when Length is odd, the third part is not written */
{
LCD_IO_WriteData(rgb888_part3);
}
}
}
/**
* @brief Draw vertical line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the Line length.
* @retval None
*/
void ls016b8uy_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Fill a complete vertical line */
for(counter = 0; counter < Length; counter++)
{
ls016b8uy_WritePixel(Xpos, Ypos + counter, RGBCode);
}
}
/**
* @brief Displays a bitmap picture.
* @param BmpAddress: Bmp picture address.
* @param Xpos: Bmp X position in the LCD
* @param Ypos: Bmp Y position in the LCD
* @retval None
*/
void ls016b8uy_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = 0, size = 0;
uint32_t posY;
uint32_t nb_line = 0;
uint16_t Xsize = WindowsXend - WindowsXstart + 1;
uint16_t Ysize = WindowsYend - WindowsYstart + 1;
/* Read bitmap size */
size = *(volatile uint16_t *) (pbmp + 2);
size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
/* Get bitmap data address offset */
index = *(volatile uint16_t *) (pbmp + 10);
index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
size = (size - index)/2;
pbmp += index;
for (posY = (Ypos + Ysize); posY > Ypos; posY--) /* In BMP files the line order is inverted */
{
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, posY - 1);
/* Draw one line of the picture */
ls016b8uy_DrawRGBHLine(Xpos, posY - 1, Xsize, (pbmp + (nb_line * Xsize * 2)));
nb_line++;
}
}
/**
* @brief Displays picture.
* @param pdata: picture address.
* @param Xpos: Image X position in the LCD
* @param Ypos: Image Y position in the LCD
* @param Xsize: Image X size in the LCD
* @param Ysize: Image Y size in the LCD
* @retval None
*/
void ls016b8uy_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata)
{
uint32_t posY;
uint32_t nb_line = 0;
for (posY = Ypos; posY < (Ypos + Ysize); posY ++)
{
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, posY);
/* Draw one line of the picture */
ls016b8uy_DrawRGBHLine(Xpos, posY, Xsize, (pdata + (nb_line * Xsize * 2)));
nb_line++;
}
}
/******************************************************************************
Static Functions
*******************************************************************************/
/**
* @brief Read pixel from LCD RAM in RGB888 format
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval Each RGB pixel color components in a structure
*/
static LS016B8UY_Rgb888 ls016b8uy_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos)
{
LS016B8UY_Rgb888 rgb888;
uint16_t rgb888_part1, rgb888_part2;
/* In LCD RAM, pixels are 24 bits packed and read with 16 bits access
* Here is the pixels components arrangement in memory :
* bits: 15 14 13 12 11 10 09 08 | 07 06 05 04 03 02 01 00
* address 0 : red pixel 0 X X | green pixel 0 X X
* address 1 : blue pixel 0 X X | red pixel 1 X X
* address 2 : green pixel 1 X X | blue pixel 1 X X
*/
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Prepare to read LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_READ_RAM, (uint8_t*)NULL, 0); /* RAM read data command */
/* Dummy read */
LCD_IO_ReadData();
/* Read first part of the RGB888 data */
rgb888_part1 = LCD_IO_ReadData();
/* Read first part of the RGB888 data */
rgb888_part2 = LCD_IO_ReadData();
/* red component */
rgb888.red = (rgb888_part1 & 0xFC00) >> 8;
/* green component */
rgb888.green = (rgb888_part1 & 0x00FC) >> 0;
/* blue component */
rgb888.blue = (rgb888_part2 & 0xFC00) >> 8;
return rgb888;
}
/**
* @brief Displays a single picture line.
* @param pdata: picture address.
* @param Xpos: Image X position in the LCD
* @param Ypos: Image Y position in the LCD
* @param Xsize: Image X size in the LCD
* @retval None
*/
static void ls016b8uy_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata)
{
uint32_t i = 0;
uint32_t posX;
uint16_t r, g, b;
uint16_t rgb888_part;
uint16_t *rgb565 = (uint16_t*)pdata;
/* Prepare to write to LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
for (posX = Xpos; posX < (Xsize + Xpos); posX += 2)
{
if ((posX >= WindowsXstart) && (Ypos >= WindowsYstart) && /* Check we are in the defined window */
(posX <= WindowsXend) && (Ypos <= WindowsYend))
{
/* Write pixels in LCD RAM after RGB565 -> RGB888 conversion */
/* As data in LCD RAM are 24bits packed, three 16 bits writes access are needed to transmit 2 pixels data */
r = (rgb565[i] & 0xF800) >> 11; /* Extract red component from first RGB565 pixel data */
g = (rgb565[i] & 0x07E0) >> 5; /* Extract green component from first RGB565 pixel data */
rgb888_part = (r << 11) + (g << 2); /* Build data to be written in LCD RAM */
LCD_IO_WriteData(rgb888_part);
b = (rgb565[i] & 0x001F) >> 0; /* Extract blue component from first RGB565 pixel data */
r = (rgb565[i+1] & 0xF800) >> 11; /* Extract red component from second RGB565 pixel data */
rgb888_part = (b << 11) + (r << 3); /* Build data to be written in LCD RAM */
LCD_IO_WriteData(rgb888_part);
if (posX != (Xsize + Xpos - 1)) /* When writing last pixel when size is odd, the third part is not written */
{
g = (rgb565[i+1] & 0x07E0) >> 5; /* Extract green component from second RGB565 pixel data */
b = (rgb565[i+1] & 0x001F) >> 0; /* Extract blue component from second RGB565 pixel data */
rgb888_part = (g << 10) + (b << 3); /* Build data to be written in LCD RAM */
LCD_IO_WriteData(rgb888_part);
}
i += 2;
}
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,158 @@
/**
******************************************************************************
* @file ls016b8uy.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the ls016b8uy.c
* driver.
******************************************************************************
* @attention
*
* Copyright (c) 2016 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LS016B8UY_H
#define __LS016B8UY_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "../Common/lcd.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ls016b8uy
* @{
*/
/** @defgroup LS016B8UY_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup LS016B8UY_Exported_Constants
* @{
*/
/**
* @brief LS016B8UY ID
*/
#define LS016B8UY_ID 0xFFFF
/**
* @brief LS016B8UY Size
*/
#define LS016B8UY_LCD_PIXEL_WIDTH ((uint16_t)180)
#define LS016B8UY_LCD_PIXEL_HEIGHT ((uint16_t)180)
/**
* @brief LS016B8UY Registers
*/
#define LCD_CMD_SLEEP_IN 0x10
#define LCD_CMD_SLEEP_OUT 0x11
#define LCD_CMD_DISPLAY_OFF 0x28
#define LCD_CMD_DISPLAY_ON 0x29
#define LCD_CMD_WRITE_RAM 0x2C
#define LCD_CMD_READ_RAM 0x2E
#define LCD_CMD_CASET 0x2A
#define LCD_CMD_RASET 0x2B
#define LCD_CMD_VSYNC_OUTPUT 0x35
#define LCD_CMD_NORMAL_DISPLAY 0x36
#define LCD_CMD_IDLE_MODE_OFF 0x38
#define LCD_CMD_IDLE_MODE_ON 0x39
#define LCD_CMD_COLOR_MODE 0x3A
#define LCD_CMD_PANEL_SETTING_1 0xB0
#define LCD_CMD_PANEL_SETTING_2 0xB1
#define LCD_CMD_OSCILLATOR 0xB3
#define LCD_CMD_PANEL_SETTING_LOCK 0xB4
#define LCD_CMD_PANEL_V_PORCH 0xB7
#define LCD_CMD_PANEL_IDLE_V_PORCH 0xB8
#define LCD_CMD_GVDD 0xC0
#define LCD_CMD_OPAMP 0xC2
#define LCD_CMD_RELOAD_MTP_VCOMH 0xC5
#define LCD_CMD_PANEL_TIMING_1 0xC8
#define LCD_CMD_PANEL_TIMING_2 0xC9
#define LCD_CMD_PANEL_TIMING_3 0xCA
#define LCD_CMD_PANEL_TIMING_4 0xCC
#define LCD_CMD_PANEL_POWER 0xD0
#define LCD_CMD_TEARING_EFFECT 0xDD
/**
* @}
*/
/** @defgroup LS016B8UY_Exported_Functions
* @{
*/
void ls016b8uy_Init(void);
uint16_t ls016b8uy_ReadID(void);
void ls016b8uy_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters);
uint8_t ls016b8uy_ReadReg(uint8_t Command);
void ls016b8uy_DisplayOn(void);
void ls016b8uy_DisplayOff(void);
void ls016b8uy_SetCursor(uint16_t Xpos, uint16_t Ypos);
void ls016b8uy_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode);
uint16_t ls016b8uy_ReadPixel(uint16_t Xpos, uint16_t Ypos);
void ls016b8uy_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void ls016b8uy_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void ls016b8uy_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp);
void ls016b8uy_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata);
void ls016b8uy_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
uint16_t ls016b8uy_GetLcdPixelWidth(void);
uint16_t ls016b8uy_GetLcdPixelHeight(void);
/* LCD driver structure */
extern LCD_DrvTypeDef ls016b8uy_drv;
/* LCD IO functions */
void LCD_IO_Init(void);
void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size);
void LCD_IO_WriteReg(uint8_t Reg);
void LCD_IO_WriteData(uint16_t RegValue);
uint16_t LCD_IO_ReadData(void);
void LCD_IO_Delay(uint32_t delay);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __LS016B8UY_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/