Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
new icons demo
Browse files Browse the repository at this point in the history
  • Loading branch information
indriApollo committed May 15, 2017
1 parent 98da4f3 commit cf0186d
Show file tree
Hide file tree
Showing 14 changed files with 13,700 additions and 4,767 deletions.
4 changes: 2 additions & 2 deletions Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ uint8_t BSP_LCD_Init(void)

/* Polarity */
hLtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL;
hLtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL;
hLtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL;
hLtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL;
hLtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL;
hLtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
hLtdcHandler.Instance = LTDC;

Expand Down
4,636 changes: 4,636 additions & 0 deletions Inc/arrow.h

Large diffs are not rendered by default.

4,641 changes: 0 additions & 4,641 deletions Inc/avatar272.h

This file was deleted.

267 changes: 267 additions & 0 deletions Inc/calib_icon.h

Large diffs are not rendered by default.

516 changes: 516 additions & 0 deletions Inc/calib_loading.h

Large diffs are not rendered by default.

8,171 changes: 8,171 additions & 0 deletions Inc/calib_screen.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Inc/font09.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <stdint.h>

const uint16_t font09[50*74*10*2] = {
const uint16_t font09[50*74*10] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels
0x0000, 0x0000, 0x3186, 0x8410, 0xC618, 0xE71C, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xE71C, 0xC618, 0x8410, 0x3186, // 0x0020 (32) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels
Expand Down
4 changes: 3 additions & 1 deletion Inc/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

void rotateImage(float angle, uint16_t* buf1, uint16_t* buf2);
void rotateImage(float angle, uint16_t* buf1, uint16_t* buf2, uint16_t width, uint16_t height);

void angleText(int16_t angle, uint16_t* fontBuffer);

Expand Down
13 changes: 13 additions & 0 deletions Inc/uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#ifndef UART_H_
#define UART_H_

#include <stdint.h>
#include <string.h>
#include "stm32f7xx_hal.h"

#define UART_TIMEOUT 100

void uart_send(UART_HandleTypeDef *huart, char* data);

#endif /* UART_H_ */
2 changes: 1 addition & 1 deletion STM32F746G-DISCO.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<board id="stm32f746g-disco">
<name>STM32F746G-DISCO</name>
<mcuId>stm32f746nghx</mcuId>
<dbgIF>SWD</dbgIF>
<dbgIF>JTAG</dbgIF>
<dbgIF>SWD</dbgIF>
<dbgDEV>ST-LinkV2-1</dbgDEV>
</board>
</targetDefinitions>
9 changes: 3 additions & 6 deletions Src/graphics.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

#include <stdio.h>
#include <string.h>
#include "graphics.h"
#include "font09.h"

Expand All @@ -10,13 +8,12 @@
#define N_CHARS 3
#define FONTBUFFER_WIDTH (FONT_WIDTH*N_CHARS)

void rotateImage(float angle, uint16_t* buf1, uint16_t* buf2) {
void rotateImage(float angle, uint16_t* buf1, uint16_t* buf2, uint16_t width, uint16_t height) {
float midX, midY;
float deltaX, deltaY;
int16_t rotX, rotY;
uint16_t x, y;
uint16_t height = 150;
uint16_t width = 74;

// Optimization: compute the sin and cos only once
float _sin = sin(angle);
float _cos = cos(angle);
Expand Down Expand Up @@ -45,7 +42,7 @@ void angleText(int16_t angle, uint16_t* fontBuffer)
snprintf((char*)strbuf, sizeof(strbuf), "%d", angle);

uint16_t *fontStart;
uint8_t strbufLen = strlen(strbuf);
uint8_t strbufLen = strlen((char*)strbuf);
uint16_t bgFillLen = (N_CHARS-strbufLen)*FONT_WIDTH/2; // compute the needed borders to center the chars
uint16_t* fontBufferPtr = fontBuffer;

Expand Down
193 changes: 79 additions & 114 deletions Src/main.c
Original file line number Diff line number Diff line change
@@ -1,100 +1,57 @@
/**
******************************************************************************
* File Name : main.c
* Description : Main program body
******************************************************************************
*
* COPYRIGHT(c) 2017 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */
#include "main.h"

#include "avatar272.h"
#include "arrow.h"
#include "calib_icon.h"
#include "calib_screen.h"
#include "calib_loading.h"
#include "stm32f7xx_hal.h"

#include "stm32746g_discovery.h"
#include "stm32746g_discovery_lcd.h"
#include "stm32746g_discovery_sdram.h"
#include "stm32746g_discovery_ts.h"

#include "lsm303.h"
#include "graphics.h"
#include "uart.h"

static sample accSample;
//static sample magSample;
#define LCD_WIDTH 480
#define LCD_HEIGHT 272
#define IMGSIZE (LCD_WIDTH*LCD_HEIGHT*2)

#define IMGSIZE 482*272*2
#define FB1 0xc0000000
#define FB2 (FB1+IMGSIZE)

static sample accSample;
static sample magSample;

static LTDC_LayerCfgTypeDef pLayerCfg;
static LTDC_LayerCfgTypeDef pLayerCfg1;
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

UART_HandleTypeDef huart1;
I2C_HandleTypeDef hi2c1;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
LTDC_HandleTypeDef hLtdcHandler;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_I2C1_Init(void);
static void MX_LTDC_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
static void initScreen1(void);
static void initScreen2(void);

const uint16_t *buf1 = avatar_272;

const uint16_t *buf1 = calib_screen;
uint16_t buf2[272*272];
uint16_t fontBuffer[50*74*3];
uint16_t fontBufferRtd[50*74*3];


/* USER CODE END PFP */

/* USER CODE BEGIN 0 */
/* USER CODE END 0 */

int main(void)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* Enable I-Cache-------------------------------------------------------------*/
SCB_EnableICache();

Expand All @@ -114,38 +71,52 @@ int main(void)
MX_USART1_UART_Init();
MX_I2C1_Init();
MX_LTDC_Init();
BSP_TS_Init(LCD_WIDTH, LCD_HEIGHT);
BSP_SDRAM_Init();
clearBuffer((uint16_t*)FB1, IMGSIZE, 0x0f0f);

/* USER CODE BEGIN 2 */
//BSP_SDRAM_WriteData(FB1,(uint32_t*)&avatar_272, 272*272/2);
/* USER CODE END 2 */
initScreen1();
initScreen2();



/* Infinite loop */
/* USER CODE BEGIN WHILE */
writeAccConfig(&hi2c1);
//writeMagConfig(&hi2c1);
HAL_Delay(100);
uint8_t msg[] = "UART IS WORKING !\n";

int16_t angle;
char msg[32];
float ang = 0;
TS_StateTypeDef ts_state;
uint8_t touchToggle = 0;
uint8_t screenToggle = 0;
while (1)
{
readAccSample(&hi2c1, &accSample);
/*readAccSample(&hi2c1, &accSample);
//readMagSample(&hi2c1, &magSample);

angleText(atan2(accSample.z, accSample.x)*180.0f/M_PI, fontBuffer);
angle = (int16_t)(atan2(accSample.z, accSample.x)*180.0f/M_PI);
angleText(angle, fontBuffer);
cpyRotated(fontBuffer, fontBufferRtd, 150, 74);
cpyToFb(fontBufferRtd, 74, 150, (uint16_t*)FB1, 480, 200, 50);
HAL_UART_Transmit(&huart1, msg, sizeof(msg), 100);

HAL_Delay(100);

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

snprintf(msg, 32, "angle: %d", angle);
uart_send(&huart1, msg);*/
//rotateImage(ang, calib_loading, (uint16_t*)FB1, 90, 90);
//ang += 0.314159f;
BSP_TS_GetState(&ts_state);
if(ts_state.touchDetected && ts_state.touchX[0] <= 64 && ts_state.touchY[0] >= 208) {
if(!touchToggle) { // first time we touch
touchToggle = 1;

HAL_LTDC_SetAlpha_NoReload(&hLtdcHandler, 0, screenToggle);
screenToggle = !screenToggle;
HAL_LTDC_SetAlpha_NoReload(&hLtdcHandler, 255, screenToggle);
HAL_LTDC_Reload(&hLtdcHandler, LTDC_RELOAD_VERTICAL_BLANKING);
}
} else {
touchToggle = 0; // reset touch
}
BSP_TS_ResetTouchData(&ts_state);
HAL_Delay(20);
}
/* USER CODE END 3 */

}

/** System Clock Configuration
Expand Down Expand Up @@ -251,7 +222,7 @@ static void MX_I2C1_Init(void)
{

hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x20404768;
hi2c1.Init.Timing = 0x20404768; // 100 khz
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
Expand Down Expand Up @@ -286,37 +257,37 @@ static void MX_LTDC_Init(void)
BSP_LCD_Init();

pLayerCfg.WindowX0 = 0;
pLayerCfg.WindowX1 = 480;
pLayerCfg.WindowX1 = LCD_WIDTH;
pLayerCfg.WindowY0 = 0;
pLayerCfg.WindowY1 = 272;
pLayerCfg.WindowY1 = LCD_HEIGHT;
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
pLayerCfg.Alpha = 255;
pLayerCfg.Alpha0 = 0;
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
pLayerCfg.FBStartAdress = (uint32_t)FB1;
pLayerCfg.ImageWidth = 480;
pLayerCfg.ImageHeight = 272;
pLayerCfg.Backcolor.Blue = 255;
pLayerCfg.Backcolor.Green = 255;
pLayerCfg.Backcolor.Red = 255;
pLayerCfg.ImageWidth = LCD_WIDTH;
pLayerCfg.ImageHeight = LCD_HEIGHT;
pLayerCfg.Backcolor.Blue = 0;
pLayerCfg.Backcolor.Green = 0;
pLayerCfg.Backcolor.Red = 0;
if (HAL_LTDC_ConfigLayer(&hLtdcHandler, &pLayerCfg, 0) != HAL_OK)
{
Error_Handler();
}

pLayerCfg1.WindowX0 = 0;
pLayerCfg1.WindowX1 = 480;
pLayerCfg1.WindowX1 = LCD_WIDTH;
pLayerCfg1.WindowY0 = 0;
pLayerCfg1.WindowY1 = 272;
pLayerCfg1.WindowY1 = LCD_HEIGHT;
pLayerCfg1.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
pLayerCfg1.Alpha = 0;
pLayerCfg1.Alpha0 = 0;
pLayerCfg1.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
pLayerCfg1.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
pLayerCfg1.FBStartAdress = (uint32_t)FB2;
pLayerCfg1.ImageWidth = 480;
pLayerCfg1.ImageHeight = 272;
pLayerCfg1.ImageWidth = LCD_WIDTH;
pLayerCfg1.ImageHeight = LCD_HEIGHT;
pLayerCfg1.Backcolor.Blue = 0;
pLayerCfg1.Backcolor.Green = 0;
pLayerCfg1.Backcolor.Red = 0;
Expand All @@ -326,13 +297,6 @@ static void MX_LTDC_Init(void)
}
}

/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
static void MX_GPIO_Init(void)
{

Expand All @@ -350,22 +314,23 @@ static void MX_GPIO_Init(void)

}

/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
static void initScreen1(void)
{
clearBuffer((uint16_t*)FB1, IMGSIZE, 0x0000);
angleText(0.0f, fontBuffer);
cpyRotated(fontBuffer, fontBufferRtd, 150, 74);
cpyToFb(fontBufferRtd, 74, 150, (uint16_t*)FB1, LCD_WIDTH, 400, 61);
cpyToFb(arrow, 272, 272, (uint16_t*)FB1, LCD_WIDTH, 100, 0);
cpyToFb(calib_icon, 64, 64, (uint16_t*)FB1, LCD_WIDTH, 0, 208);
}

/**
* @brief This function is executed in case of error occurrence.
* @param None
* @retval None
*/
void Error_Handler(void)
static void initScreen2(void)
{
/* USER CODE BEGIN Error_Handler */
/* User can add his own implementation to report the HAL error return state */
while(1)
{
}
/* USER CODE END Error_Handler */
cpyRotated(calib_screen, (uint16_t*)FB2, 272, 480);
cpyToFb(calib_loading, 90, 90, (uint16_t*)FB2, LCD_WIDTH, 20, 91);
}

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void Error_Handler(void)
{
while(1) {}
}
2 changes: 1 addition & 1 deletion Src/stm32f7xx_hal_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* Includes ------------------------------------------------------------------*/
#include "stm32f7xx_hal.h"

extern void Error_Handler(void);
//extern void Error_Handler(void);
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */
Expand Down
Loading

0 comments on commit cf0186d

Please sign in to comment.