style: code format

This commit is contained in:
IOsetting 2022-02-09 14:49:48 +08:00
parent 1dc7666b27
commit 3d22dac649

View File

@ -23,8 +23,6 @@
#include "fw_hal.h"
#include <string.h>
#define MAIN_Fosc 24000000L
#define Timer0_Reload (65536UL -(MAIN_Fosc / 1000)) //Timer 0 frequency 1000Hz
#define KeyIO P0
__BIT B_1ms; // 1ms flag
@ -53,13 +51,12 @@ void USB_Init(void);
void KeyScan(void);
void SendKeyStatus(void);
void main()
{
uint8_t i;
GPIO_P1_SetMode(GPIO_Pin_All, GPIO_Mode_InOut_QBD);
GPIO_P3_SetMode(GPIO_Pin_0|GPIO_Pin_1, GPIO_Mode_Input_HIP);
GPIO_P3_SetMode(GPIO_Pin_0 | GPIO_Pin_1, GPIO_Mode_Input_HIP);
GPIO_P6_SetMode(GPIO_Pin_All, GPIO_Mode_Output_PP);
USB_Init();
@ -70,22 +67,22 @@ void main()
TIM_Timer0_SetRunState(HAL_State_ON);
EXTI_Global_SetIntState(HAL_State_ON);
for(i = 0; i < 8; i++)
for (i = 0; i < 8; i++)
{
HidInput[i]=0;
HidInput[i] = 0;
}
while (1)
{
if(B_1ms) // every 1 ms
if (B_1ms) // every 1 ms
{
B_1ms = 0;
if(++cnt50ms >= 50) // scan every 50 ms
if (++cnt50ms >= 50) // scan every 50 ms
{
cnt50ms = 0;
KeyScan();
}
if(KeyChangeFlag) // if key status changed
if (KeyChangeFlag) // if key status changed
{
KeyChangeFlag = 0;
SendKeyStatus();
@ -363,9 +360,9 @@ uint8_t KeyCount(uint16_t dat)
uint8_t i;
i = 0;
while(dat)
while (dat)
{
if(dat & 0x8000) i++;
if (dat & 0x8000) i++;
dat <<= 1;
}
return i;
@ -378,7 +375,7 @@ void SendKeyStatus(void)
if(KeyCode) // if key pressed
{
// 4*4 key matrixmax 3 keys pressed simultaneously
// allow 3 keys pressed simultaneously
if(KeyCount(KeyCode) > 3)
{
return; // too many keys
@ -386,11 +383,11 @@ void SendKeyStatus(void)
else
{
n = 2;
for(i=0;i<16;i++)
for (i = 0; i < 16; i++)
{
if(i == 1)
if (i == 1)
{
if(KeyCode & (1<<i)) // left Ctrl
if (KeyCode & (1 << i)) // left Ctrl
{
HidInput[0] |= 1;
}
@ -399,20 +396,20 @@ void SendKeyStatus(void)
HidInput[0] &= ~1;
}
}
else if(i == 2)
else if (i == 2)
{
if(KeyCode & (1<<i)) // left alt
if (KeyCode & (1 << i)) // left alt
{
HidInput[0] |= 1<<2;
HidInput[0] |= 1 << 2;
}
else
{
HidInput[0] &= ~(1<<2);
HidInput[0] &= ~(1 << 2);
}
}
else
{
if(KeyCode & (1<<i))
if (KeyCode & (1 << i))
{
HidInput[n++] = KeyMap[i];
}
@ -427,15 +424,15 @@ void SendKeyStatus(void)
}
else // if no key pressed, return 0
{
for( i = 0; i < 8; i++)
for (i = 0; i < 8; i++)
{
HidInput[i]=0;
HidInput[i] = 0;
}
}
// return 8 bytes data
USB_WriteReg(INDEX, 1);
for(i = 0; i < 8; i++)
for (i = 0; i < 8; i++)
{
USB_WriteReg(FIFO1, HidInput[i]);
}
@ -462,20 +459,14 @@ P02 ---- K08 ---- K09 ---- K10 ---- K11 ----
P03 ---- K12 ---- K13 ---- K14 ---- K15 ----
| | | |
******************************************************/
void IO_KeyDelay(void)
{
uint8_t i;
i = 5;
while(--i);
}
void KeyScan(void)
{
uint8_t temp;
KeyIO = 0x0F;
IO_KeyDelay();
if((KeyIO & 0x0F) == 0x0F) // no key pressed
SYS_DelayUs(1);
if ((KeyIO & 0x0F) == 0x0F) // no key pressed
{
NewKeyCode = 0;
}
@ -483,34 +474,33 @@ void KeyScan(void)
{
// scan first line
KeyIO = (uint8_t)~0x10;
IO_KeyDelay();
SYS_DelayUs(1);
// save 4 keys status
temp = KeyIO & 0x0F;
// second line
KeyIO = (uint8_t)~0x20;
IO_KeyDelay();
// save 4 keys status
SYS_DelayUs(1);
temp |= KeyIO << 4;
// save current key status
NewKeyCode = (~temp) & 0xFF;
// scan third line
// third line
KeyIO = (uint8_t)~0x40;
IO_KeyDelay();
SYS_DelayUs(1);
temp = KeyIO & 0x0F;
// scan 4th line
// 4th line
KeyIO = (uint8_t)~0x80;
IO_KeyDelay();
SYS_DelayUs(1);
temp |= KeyIO << 4;
// save all 16 keys' status in 2 bytes, 1 indicates key pressed
NewKeyCode |= (((uint16_t)~temp)<<8);
NewKeyCode |= (((uint16_t)~temp) << 8);
}
if(NewKeyCode != OldKeyCode)
if (NewKeyCode != OldKeyCode)
{
KeyHoldTime = 0;
OldKeyCode = NewKeyCode;
@ -519,11 +509,11 @@ void KeyScan(void)
else
{
KeyHoldTime++;
if(KeyHoldTime >= 1)
if (KeyHoldTime >= 1)
{
KeyHoldTime = 1;
KeyCode = OldKeyCode;
if(KeyChangeTemp)
if (KeyChangeTemp)
{
KeyChangeTemp = 0;
KeyChangeFlag = 1; // Set send flag