You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
4.6 KiB
C

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
******************************************************************************
* @file driver_ST7735S.c
* @author <20>Ϻ<EFBFBD><CFBA><EFBFBD><EFBFBD><EFBFBD>
* @version V1.0.0
* @date 2023
* @brief ST7735S driver.
* This file provides firmware functions to manage gc9c01
* with SPI and DMA. User should set GPIO, dma channel, spi
* channel according actual resource allocation.
******************************************************************************
* @attention
*
* Copyright (c) 2023 Bixdo.
* All rights reserved.
******************************************************************************
*/
#include "ALLinclude.h"
#include "FuctionRGB.h"
void F_RGB_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable the GPIO_LED Clock */
__HAL_RCC_GPIOB_CLK_ENABLE();
/* Configure the GPIO_CE pin */
GPIO_InitStruct.Pin = Pin_LEDDout;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;//GPIO_MODE_OUTPUT_OD; GPIO_MODE_OUTPUT_PP
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(Port_LEDDout, &GPIO_InitStruct);
}
void F_UV_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable the GPIO_LED Clock */
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_WritePin(Port_UV_ON,Pin_UV_ON,GPIO_PIN_RESET);
HAL_GPIO_WritePin(Port_UV_CE,Pin_UV_CE,GPIO_PIN_RESET);
/* Configure the GPIO_CE pin */
GPIO_InitStruct.Pin = Pin_UV_ON;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;//GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(Port_UV_ON, &GPIO_InitStruct);
/* Configure the GPIO_CE pin */
GPIO_InitStruct.Pin = Pin_UV_CE;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;//GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(Port_UV_CE, &GPIO_InitStruct);
HAL_GPIO_WritePin(Port_UV_ON,Pin_UV_ON,GPIO_PIN_RESET);
HAL_GPIO_WritePin(Port_UV_CE,Pin_UV_CE,GPIO_PIN_RESET);
}
void Function_UV_ON(void)
{
HAL_GPIO_WritePin(Port_UV_ON,Pin_UV_ON,GPIO_PIN_SET);
HAL_GPIO_WritePin(Port_UV_CE,Pin_UV_CE,GPIO_PIN_SET);
}
void Function_UV_OFF(void)
{
HAL_GPIO_WritePin(Port_UV_ON,Pin_UV_ON,GPIO_PIN_RESET);
HAL_GPIO_WritePin(Port_UV_CE,Pin_UV_CE,GPIO_PIN_RESET);
}
static void delayMicroseconds(uint8_t delaydata)
{
uint8_t delay = delaydata;
while(delay){
delay--;
};
}
// 发送一个bit的函数
static void sendBit(uint32_t bitValue) {
if(bitValue ) {
setOutput_H;
delayMicroseconds(BIT1_HIGH);
setOutput_L;
// delayMicroseconds(BIT1_LOW);
} else {
setOutput_H;
delayMicroseconds(BIT0_HIGH);
setOutput_L;
delayMicroseconds(BIT0_LOW);
}
}
// 发送一个字节的函数
static void sendByte(uint8_t data) {
uint8_t datasend[8];
for(int i=0; i<8; i++) {
// datasend[i] = (data & (1<<i));
sendBit(data & (1<<i));
}
}
// 发送3个字节的函数
static void send3Byte(uint32_t data) {
uint32_t datasend = data;
// uint32_t DataSend[24];
// for(int i=0; i<24; i++) {
// // datasend[i] = (data & (1<<i));
// DataSend[i] =(datasend & (1<<i));
// }
for(int i=0; i<24; i++) {
// datasend[i] = (data & (1<<i));
sendBit(datasend & (1<<i));
}
}
void SetRGBColor(typedefEnumRGBLED ColorData)
{
#if 0
switch (ColorData)
{
case RGB_OFF:
send3Byte(0x00000000);
break;
case RGB_BLUE:
send3Byte(0xFF0000);
break;
case RGB_RED:
send3Byte(0x00FF00);
break;
case RGB_GREEN:
send3Byte(0x0000FF);
break;
default:
break;
}
#endif
#if 1
switch (ColorData)
{
case RGB_OFF:
sendByte(0x00);
sendByte(0x00);
sendByte(0x00);
break;
case RGB_BLUE:
sendByte(0xFF);
sendByte(0x00);
sendByte(0x00);
break;
case RGB_RED:
sendByte(0x00);
sendByte(0xFF);
sendByte(0x00);
break;
case RGB_GREEN:
sendByte(0x00);
sendByte(0x00);
sendByte(0xFF);
break;
default:
break;
}
#endif
}
void TaskRGBFunction(void *pvParamters)
{
BaseType_t Err = 0;
typedefEnumRGBLED ECmdRGBRegister;
const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
for(;;)
{
Err = xQueueReceive(at_CmdRGB, &ECmdRGBRegister, 0);
if(Err == pdTRUE)
{
//printf("ECmdRGBRegister = %d\r\n",ECmdRGBRegister);
SetRGBColor(ECmdRGBRegister);
}
vTaskDelay(50);
}
}
void SendRGBCmd(typedefEnumRGBLED CmdData)
{
typedefEnumRGBLED CmdRegister = CmdData;
xQueueSend(at_CmdRGB,&CmdRegister,portMAX_DELAY);
}
/*********************************************END OF FILE*********************************************/