[bsp/stm32] format code

This commit is contained in:
NU-LL 2022-10-16 20:42:31 +08:00 committed by guo
parent b380bdf071
commit 6723573716
15 changed files with 260 additions and 260 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -167,7 +167,7 @@
#define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */
#define USE_RTOS 0U
#define USE_SD_TRANSCEIVER 0U /*!< use uSD Transceiver */
#define USE_SPI_CRC 0U /*!< use CRC in SPI */
#define USE_SPI_CRC 0U /*!< use CRC in SPI */
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */

View File

@ -153,7 +153,7 @@ void SystemInit (void)
if(FLASH_LATENCY_DEFAULT > (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)))
{
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(FLASH_LATENCY_DEFAULT));
MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(FLASH_LATENCY_DEFAULT));
}
/* Set HSION bit */
@ -169,7 +169,7 @@ void SystemInit (void)
if(FLASH_LATENCY_DEFAULT < (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)))
{
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(FLASH_LATENCY_DEFAULT));
MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(FLASH_LATENCY_DEFAULT));
}
#if defined(D3_SRAM_BASE)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -26,8 +26,8 @@
static int rt_hw_spi_flash_with_sfud_init(void)
{
rt_err_t err = RT_EOK;
rt_hw_spi_device_attach("spi1", "spi10", SPI_CS_GPIO, SPI_CS_PIN);
rt_err_t err = RT_EOK;
rt_hw_spi_device_attach("spi1", "spi10", SPI_CS_GPIO, SPI_CS_PIN);
/* init W25Q16 , And register as a block device */
if (RT_NULL == rt_sfud_flash_probe(FAL_USING_NOR_FLASH_DEV_NAME, "spi10"))

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -12,14 +12,14 @@ static int32_t lcd_senddata(uint8_t* pdata,uint32_t length);
static int32_t lcd_recvdata(uint8_t* pdata,uint32_t length);
ST7735_IO_t st7735_pIO = {
lcd_init,
RT_NULL,
RT_NULL,
lcd_writereg,
lcd_readreg,
lcd_senddata,
lcd_recvdata,
RT_NULL
lcd_init,
RT_NULL,
RT_NULL,
lcd_writereg,
lcd_readreg,
lcd_senddata,
lcd_recvdata,
RT_NULL
};
ST7735_Object_t st7735_pObj;
uint32_t st7735_id;
@ -81,63 +81,63 @@ void LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t size,uint8_t mode)
num=num-' ';//得到偏移后的值
count = 0;
if(!mode) //非叠加方式
{
for(t=0;t<size;t++)
{
if(size==12)temp=asc2_1206[num][t]; //调用1206字体
else temp=asc2_1608[num][t]; //调用1608字体
if(!mode) //非叠加方式
{
for(t=0;t<size;t++)
{
if(size==12)temp=asc2_1206[num][t]; //调用1206字体
else temp=asc2_1608[num][t]; //调用1608字体
for(t1=0;t1<8;t1++)
{
if(temp&0x80)
write[count][t/2]=(BRUSH_POINT_COLOR&0xFF)<<8|BRUSH_POINT_COLOR>>8;
else
write[count][t/2]=(BRUSH_BACK_COLOR&0xFF)<<8|BRUSH_BACK_COLOR>>8;
for(t1=0;t1<8;t1++)
{
if(temp&0x80)
write[count][t/2]=(BRUSH_POINT_COLOR&0xFF)<<8|BRUSH_POINT_COLOR>>8;
else
write[count][t/2]=(BRUSH_BACK_COLOR&0xFF)<<8|BRUSH_BACK_COLOR>>8;
count ++;
if(count >= size) count =0;
count ++;
if(count >= size) count =0;
temp<<=1;
y++;
if(y>=h){return;}//超区域了
if((y-y0)==size)
{
y=y0;
x++;
if(x>=w){return;}//超区域了
break;
}
}
}
}
else//叠加方式
{
for(t=0;t<size;t++)
{
if(size==12)temp=asc2_1206[num][t]; //调用1206字体
else temp=asc2_1608[num][t]; //调用1608字体
for(t1=0;t1<8;t1++)
{
if(temp&0x80)
write[count][t/2]=(BRUSH_POINT_COLOR&0xFF)<<8|BRUSH_POINT_COLOR>>8;
count ++;
if(count >= size) count =0;
temp<<=1;
y++;
if(y>=h){return;}//超区域了
if((y-y0)==size)
{
y=y0;
x++;
if(x>=w){return;}//超区域了
break;
}
}
}
}
else//叠加方式
{
for(t=0;t<size;t++)
{
if(size==12)temp=asc2_1206[num][t]; //调用1206字体
else temp=asc2_1608[num][t]; //调用1608字体
for(t1=0;t1<8;t1++)
{
if(temp&0x80)
write[count][t/2]=(BRUSH_POINT_COLOR&0xFF)<<8|BRUSH_POINT_COLOR>>8;
count ++;
if(count >= size) count =0;
temp<<=1;
y++;
if(y>=h){return;}//超区域了
if((y-y0)==size)
{
y=y0;
x++;
if(x>=w){return;}//超区域了
break;
}
}
}
}
ST7735_FillRGBRect(&st7735_pObj,x0,y0,(uint8_t *)&write,size==12?6:8,size);
temp<<=1;
y++;
if(y>=h){return;}//超区域了
if((y-y0)==size)
{
y=y0;
x++;
if(x>=w){return;}//超区域了
break;
}
}
}
}
ST7735_FillRGBRect(&st7735_pObj,x0,y0,(uint8_t *)&write,size==12?6:8,size);
}
//显示字符串
@ -147,9 +147,9 @@ void LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t size,uint8_t mode)
//*p:字符串起始地址
void LCD_ShowString(uint16_t x,uint16_t y,uint16_t width,uint16_t height,uint8_t size,uint8_t *p)
{
uint8_t x0=x;
width+=x;
height+=y;
uint8_t x0=x;
width+=x;
height+=y;
while((*p<='~')&&(*p>=' '))//判断是不是非法字符!
{
if(x>=width){x=x0;y+=size;}
@ -167,58 +167,58 @@ void LCD_FillRGBRect(uint32_t Xpos, uint32_t Ypos, uint8_t *pData, uint32_t Widt
static int32_t lcd_init(void)
{
return ST7735_OK;
return ST7735_OK;
}
static int32_t lcd_writereg(uint8_t reg,uint8_t* pdata,uint32_t length)
{
int32_t result;
LCD_CS_RESET;
LCD_RS_RESET;
LCD_CS_RESET;
LCD_RS_RESET;
result = rt_spi_send(spi_dev_lcd, &reg, 1);
LCD_RS_SET;
if(length > 0)
LCD_RS_SET;
if(length > 0)
result += rt_spi_send(spi_dev_lcd, pdata, length);
LCD_CS_SET;
LCD_CS_SET;
return ((result == length+1)?0:-1);
}
static int32_t lcd_readreg(uint8_t reg,uint8_t* pdata)
{
int32_t result;
LCD_CS_RESET;
LCD_RS_RESET;
LCD_CS_RESET;
LCD_RS_RESET;
result = rt_spi_send(spi_dev_lcd, &reg, 1);
LCD_RS_SET;
result += rt_spi_recv(spi_dev_lcd, pdata, 1);
LCD_CS_SET;
result = rt_spi_send(spi_dev_lcd, &reg, 1);
LCD_RS_SET;
result += rt_spi_recv(spi_dev_lcd, pdata, 1);
LCD_CS_SET;
return ((result == 2)?0:-1);
}
static int32_t lcd_senddata(uint8_t* pdata,uint32_t length)
{
int32_t result;
LCD_CS_RESET;
//LCD_RS_SET;
result =rt_spi_send(spi_dev_lcd, pdata, length);
LCD_CS_SET;
LCD_CS_RESET;
//LCD_RS_SET;
result =rt_spi_send(spi_dev_lcd, pdata, length);
LCD_CS_SET;
return ((result == length)?0:-1);
}
static int32_t lcd_recvdata(uint8_t* pdata,uint32_t length)
{
int32_t result;
LCD_CS_RESET;
//LCD_RS_SET;
result = rt_spi_recv(spi_dev_lcd, pdata, length);
LCD_CS_SET;
LCD_CS_RESET;
//LCD_RS_SET;
result = rt_spi_recv(spi_dev_lcd, pdata, length);
LCD_CS_SET;
return ((result == length)?0:-1);
}
static int LCD_Init(void)
{
rt_pin_mode(WR_RS_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(WR_RS_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(CS_PIN, PIN_MODE_OUTPUT);
spi_dev_lcd = (struct rt_spi_device *)rt_device_find(LCD_SPI_DEVICE_NAME);
@ -229,13 +229,13 @@ static int LCD_Init(void)
}
ST7735_RegisterBusIO(&st7735_pObj,&st7735_pIO);
if(ST7735_ERROR == ST7735_LCD_Driver.Init(&st7735_pObj,ST7735_FORMAT_RBG565,ST7735_ORIENTATION_LANDSCAPE_ROT180))
if(ST7735_ERROR == ST7735_LCD_Driver.Init(&st7735_pObj,ST7735_FORMAT_RBG565,ST7735_ORIENTATION_LANDSCAPE_ROT180))
{
LOG_E("st7735 init failed!");
// return ;
}
ST7735_LCD_Driver.FillRect(&st7735_pObj,0,0,160,80,BLACK);
ST7735_LCD_Driver.ReadID(&st7735_pObj,&st7735_id);
ST7735_LCD_Driver.ReadID(&st7735_pObj,&st7735_id);
ST7735_LCD_Driver.DisplayOn(&st7735_pObj);
LOG_D("lcd id:0X%08X", st7735_id);
LOG_D("chip id:0X%08X", HAL_GetDEVID());
@ -263,21 +263,21 @@ INIT_COMPONENT_EXPORT(LCD_Init);
#ifdef FINSH_USING_MSH
static int show_logo(int argc, char **argv)
{
uint8_t text[20];
uint8_t text[20];
LCD_SetBrightness(MAX_BRIGHTNESS);
ST7735_LCD_Driver.DrawBitmap(&st7735_pObj,0,0,WeActStudiologo);
ST7735_LCD_Driver.DrawBitmap(&st7735_pObj,0,0,WeActStudiologo);
rt_thread_mdelay(1000);
ST7735_LCD_Driver.FillRect(&st7735_pObj,0,0,160,80,BLACK);
ST7735_LCD_Driver.FillRect(&st7735_pObj,0,0,160,80,BLACK);
sprintf((char *)&text,"WeAct Studio");
LCD_ShowString(4,4,160,16,16,text);
sprintf((char *)&text,"STM32H7xx 0x%X",HAL_GetDEVID());
LCD_ShowString(4,22,160,16,16,text);
sprintf((char *)&text,"LCD ID: 0x%X",st7735_id);
LCD_ShowString(4,40,160,16,16,text);
sprintf((char *)&text,"WeAct Studio");
LCD_ShowString(4,4,160,16,16,text);
sprintf((char *)&text,"STM32H7xx 0x%X",HAL_GetDEVID());
LCD_ShowString(4,22,160,16,16,text);
sprintf((char *)&text,"LCD ID: 0x%X",st7735_id);
LCD_ShowString(4,40,160,16,16,text);
return 0;
}
MSH_CMD_EXPORT(show_logo, show logo);

View File

@ -7,23 +7,23 @@
#include "st7735.h"
#include <stdio.h>
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕红色
#define GRAY 0X8430 //灰色
#define DARKBLUE 0X01CF //深蓝色
#define LIGHTBLUE 0X7D7C //浅蓝色
#define GRAYBLUE 0X5458 //灰蓝色
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕红色
#define GRAY 0X8430 //灰色
#define DARKBLUE 0X01CF //深蓝色
#define LIGHTBLUE 0X7D7C //浅蓝色
#define GRAYBLUE 0X5458 //灰蓝色
// lcd spi
#define LCD_SPI_DEVICE_NAME "spi40"

View File

@ -89,9 +89,9 @@ ST7735_LCD_Drv_t ST7735_LCD_Driver =
static uint32_t OrientationTab[4][2] =
{
{0x48U , 0xC8U}, /* Portrait orientation choice of LCD screen */
{0x88U , 0x08U}, /* Portrait rotated 180° orientation choice of LCD screen */
{0x88U , 0x08U}, /* Portrait rotated 180° orientation choice of LCD screen */
{0x28U , 0x68U}, /* Landscape orientation choice of LCD screen */
{0xE8U , 0xA8U} /* Landscape rotated 180° orientation choice of LCD screen */
{0xE8U , 0xA8U} /* Landscape rotated 180° orientation choice of LCD screen */
};
static ST7735_Ctx_t ST7735Ctx;
@ -177,16 +177,16 @@ int32_t ST7735_Init(ST7735_Object_t *pObj, uint32_t ColorCoding, uint32_t Orient
}
else
{
/* Out of sleep mode, 0 args, delay 120ms */
/* Out of sleep mode, 0 args, delay 120ms */
tmp = 0x00U;
ret = st7735_write_reg(&pObj->Ctx, ST7735_SW_RESET, &tmp, 0);
(void)ST7735_IO_Delay(pObj, 120);
(void)ST7735_IO_Delay(pObj, 120);
/* Out of sleep mode, 0 args, no delay */
tmp = 0x00U;
ret += st7735_write_reg(&pObj->Ctx, ST7735_SLEEP_OUT, &tmp, 1);
/* Frame rate ctrl - normal mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D)*/
/* Frame rate ctrl - normal mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D)*/
ret += st7735_write_reg(&pObj->Ctx, ST7735_FRAME_RATE_CTRL1, &tmp, 0);
tmp = 0x01U;
ret += st7735_send_data(&pObj->Ctx, &tmp, 1);
@ -384,7 +384,7 @@ int32_t ST7735_ReadID(ST7735_Object_t *pObj, uint32_t *Id)
{
ret = ST7735_ERROR;
}
else if(st7735_read_reg(&pObj->Ctx, ST7735_READ_ID3, &tmp[2]) != ST7735_OK)
else if(st7735_read_reg(&pObj->Ctx, ST7735_READ_ID3, &tmp[2]) != ST7735_OK)
{
ret = ST7735_ERROR;
}
@ -392,7 +392,7 @@ int32_t ST7735_ReadID(ST7735_Object_t *pObj, uint32_t *Id)
{
*Id = ((uint32_t)tmp[2])<<0| ((uint32_t)tmp[1])<<8 | ((uint32_t)tmp[0])<<16;
//*Id = __rbit(*Id);
//*Id = __rbit(*Id);
ret = ST7735_OK;
}
@ -501,7 +501,7 @@ int32_t ST7735_SetOrientation(ST7735_Object_t *pObj, uint32_t Orientation)
ST7735Ctx.Width = ST7735_HEIGHT;
ST7735Ctx.Height = ST7735_WIDTH;
}
ST7735Ctx.Orientation = Orientation;
ST7735Ctx.Orientation = Orientation;
ret = ST7735_SetDisplayWindow(pObj, 0U, 0U, ST7735Ctx.Width, ST7735Ctx.Height);
@ -545,27 +545,27 @@ int32_t ST7735_SetCursor(ST7735_Object_t *pObj, uint32_t Xpos, uint32_t Ypos)
int32_t ret;
uint8_t tmp;
/* Cursor calibration */
if(ST7735Ctx.Orientation <= ST7735_ORIENTATION_PORTRAIT_ROT180)
{
/* Cursor calibration */
if(ST7735Ctx.Orientation <= ST7735_ORIENTATION_PORTRAIT_ROT180)
{
#if IS_BOE_PANEL
Xpos += 24;
Ypos += 0;
Xpos += 24;
Ypos += 0;
#else
Xpos += 26;
Ypos += 1;
Xpos += 26;
Ypos += 1;
#endif
}
else
{
}
else
{
#if IS_BOE_PANEL
Xpos += 0;
Ypos += 24;
Xpos += 0;
Ypos += 24;
#else
Xpos += 1;
Ypos += 26;
Xpos += 1;
Ypos += 26;
#endif
}
}
ret = st7735_write_reg(&pObj->Ctx, ST7735_CASET, &tmp, 0);
tmp = (uint8_t)(Xpos >> 8U);
@ -949,27 +949,27 @@ static int32_t ST7735_SetDisplayWindow(ST7735_Object_t *pObj, uint32_t Xpos, uin
int32_t ret;
uint8_t tmp;
/* Cursor calibration */
if(ST7735Ctx.Orientation <= ST7735_ORIENTATION_PORTRAIT_ROT180)
{
/* Cursor calibration */
if(ST7735Ctx.Orientation <= ST7735_ORIENTATION_PORTRAIT_ROT180)
{
#if IS_BOE_PANEL
Xpos += 24;
Ypos += 0;
Xpos += 24;
Ypos += 0;
#else
Xpos += 26;
Ypos += 1;
Xpos += 26;
Ypos += 1;
#endif
}
else
{
}
else
{
#if IS_BOE_PANEL
Xpos += 0;
Ypos += 24;
Xpos += 0;
Ypos += 24;
#else
Xpos += 1;
Ypos += 26;
Xpos += 1;
Ypos += 26;
#endif
}
}
/* Column addr set, 4 args, no delay: XSTART = Xpos, XEND = (Xpos + Width - 1) */
ret = st7735_write_reg(&pObj->Ctx, ST7735_CASET, &tmp, 0);

View File

@ -131,9 +131,9 @@ typedef struct
* Possible values of Display Orientation
*/
#define ST7735_ORIENTATION_PORTRAIT 0x00U /* Portrait orientation choice of LCD screen */
#define ST7735_ORIENTATION_PORTRAIT_ROT180 0x01U /* Portrait rotated 180° orientation choice of LCD screen */
#define ST7735_ORIENTATION_PORTRAIT_ROT180 0x01U /* Portrait rotated 180° orientation choice of LCD screen */
#define ST7735_ORIENTATION_LANDSCAPE 0x02U /* Landscape orientation choice of LCD screen */
#define ST7735_ORIENTATION_LANDSCAPE_ROT180 0x03U /* Landscape rotated 180° orientation choice of LCD screen */
#define ST7735_ORIENTATION_LANDSCAPE_ROT180 0x03U /* Landscape rotated 180° orientation choice of LCD screen */
/**
* @brief Possible values of pixel data format (ie color coding)