WouoUI/Third-party-design/platform-test/User/mylib.c

109 lines
2.5 KiB
C
Raw Normal View History

#include "mylib.h"
#define IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != 0U)
#define IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U)
int32_t not_int32(int32_t n)
{
return (~n + 1);
}
float map_number(float num, float minInput, float maxInput, float minOutput, float maxOutput)
{
// = 0.0; // <20><><EFBFBD>Χ<EBB7B6><CEA7><EFBFBD><EFBFBD>Сֵ
// = 4096.0; // <20><><EFBFBD>Χ<EBB7B6><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
// = 0.0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD>Сֵ
// = 32.0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>
float mappedNum = ((num - minInput) / (maxInput - minInput)) * (maxOutput - minOutput) + minOutput;
return mappedNum;
}
void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
{
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵ<EFBFBD>USART */
LL_USART_TransmitData8(pUSARTx,ch);
/* <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼĴ<DDBC><C4B4><EFBFBD>Ϊ<EFBFBD><CEAA> */
while (LL_USART_IsActiveFlag_TXE(pUSARTx) == RESET); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>TXE<58><45>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
}
/***************** <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD> **********************/
void Usart_SendString( USART_TypeDef * pUSARTx, char *str)
{
unsigned int k=0;
do
{
Usart_SendByte( pUSARTx, *(str + k) );
k++;
} while(*(str + k)!='\0');
/* <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
while(LL_USART_IsActiveFlag_TC(pUSARTx)==RESET); //<2F><EFBFBD><E0BBBA><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>TC<54><43>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
}
/****************** <20><><EFBFBD><EFBFBD><38><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ************************/
void Usart_SendArray( USART_TypeDef * pUSARTx, uint8_t *array, uint16_t num)
{
uint8_t i;
for(i=0; i<num; i++)
{
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵ<EFBFBD>USART */
Usart_SendByte(pUSARTx,array[i]);
}
/* <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
while(LL_USART_IsActiveFlag_TC(pUSARTx)==RESET);
}
/***************** <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>16λ<36><CEBB> **********************/
void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch)
{
uint8_t temp_h, temp_l;
/* ȡ<><C8A1><EFBFBD>߰<EFBFBD>λ */
temp_h = (ch&0XFF00)>>8;
/* ȡ<><C8A1><EFBFBD>Ͱ<EFBFBD>λ */
temp_l = ch&0XFF;
/* <20><><EFBFBD>͸߰<CDB8>λ */
LL_USART_TransmitData8(pUSARTx,temp_h);
while (LL_USART_IsActiveFlag_TXE(pUSARTx) == RESET);
/* <20><><EFBFBD>͵Ͱ<CDB5>λ */
LL_USART_TransmitData8(pUSARTx,temp_l);
while (LL_USART_IsActiveFlag_TXE(pUSARTx) == RESET);
}
int fputc(int c,FILE *stream)
{
LL_USART_TransmitData8(USART3,c);
while(!LL_USART_IsActiveFlag_TXE(USART3))__NOP();
LL_USART_ClearFlag_TC(USART3);
return c;
}
int fgetc(FILE *stream)
{
while(!LL_USART_IsActiveFlag_RXNE(USART3)) __NOP();
return ((char)LL_USART_ReceiveData8(USART3));
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
void SoftReset(void)
{
__set_FAULTMASK(1); // <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
NVIC_SystemReset(); // <20><>λ
}
//<2F><><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>ַ
//addr:ջ<><D5BB><EFBFBD><EFBFBD>ַ
//__asm void MSR_MSP(uint32_t addr)
//{
//// MSR MSP, r0 //set Main Stack value
//// BX r14
//}