Add gpio for debug purpose

This commit is contained in:
dehanj 2023-11-06 12:19:00 +01:00
parent 7f2efb68f9
commit f83abed4e4
No known key found for this signature in database
GPG Key ID: 3707A9DBF4BB8F1A
3 changed files with 60 additions and 6 deletions

View File

@ -160,3 +160,44 @@ int getchar() {
return SBUF; return SBUF;
} }
#endif #endif
// Set pin p1.4 and p1.5 to GPIO output mode.
void gpio_init(){
// p1.4
P1_MOD_OC &= ~0x10;
P1_DIR_PU |= 0x10;
// p1.5
P1_MOD_OC &= ~0x20;
P1_DIR_PU |= 0x20;
}
void gpio_set(uint8_t pin) {
switch (pin)
{
case 0x10: // p1.4
P1 |= 0x10;
break;
case 0x20: // p1.5
P1 |= 0x20;
break;
default: // do nothing, unsupported pin.
break;
}
}
void gpio_unset(uint8_t pin) {
switch (pin)
{
case 0x10:
P1 &= ~0x10;
break;
case 0x20:
P1 &= ~0x20;
break;
default: // do nothing, unsupported pin.
break;
}
}

View File

@ -177,3 +177,8 @@ inline void CH554WDTFeed(uint8_t tim)
WDOG_COUNT = tim; // Watchdog counter assignment WDOG_COUNT = tim; // Watchdog counter assignment
} }
// Set pin p1.4 and p1.5 to GPIO output mode.
void gpio_init();
void gpio_set(uint8_t pin);
void gpio_unset(uint8_t pin);

View File

@ -573,12 +573,17 @@ main()
UEP1_T_LEN = 0; //Pre-use send length must be cleared UEP1_T_LEN = 0; //Pre-use send length must be cleared
UEP2_T_LEN = 0; //Pre-use send length must be cleared UEP2_T_LEN = 0; //Pre-use send length must be cleared
gpio_init();
gpio_unset(0x10);
gpio_unset(0x20);
while(1) while(1)
{ {
if(UsbConfig) if(UsbConfig)
{ {
if(USBByteCount) // USB receiving endpoint has data if(USBByteCount) // USB receiving endpoint has data
{ {
gpio_set(0x20);
CH554UART1SendByte(Ep2Buffer[USBBufOutPoint++]); CH554UART1SendByte(Ep2Buffer[USBBufOutPoint++]);
recievedData[USBBufOutPoint] = Ep2Buffer[USBBufOutPoint]; recievedData[USBBufOutPoint] = Ep2Buffer[USBBufOutPoint];
USBByteCount--; USBByteCount--;
@ -586,6 +591,7 @@ main()
if(USBByteCount==0) if(USBByteCount==0)
UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_R_RES | UEP_R_RES_ACK; UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_R_RES | UEP_R_RES_ACK;
gpio_unset(0x20);
} }
if(UartByteCount) if(UartByteCount)
Uart_Timeout++; Uart_Timeout++;
@ -596,6 +602,7 @@ main()
{ {
if(length>39 || Uart_Timeout>100) if(length>39 || Uart_Timeout>100)
{ {
gpio_set(0x10);
Uart_Timeout = 0; Uart_Timeout = 0;
if(Uart_Output_Point+length>UART_REV_LEN) if(Uart_Output_Point+length>UART_REV_LEN)
length = UART_REV_LEN-Uart_Output_Point; length = UART_REV_LEN-Uart_Output_Point;
@ -605,12 +612,13 @@ main()
Uart_Output_Point+=length; Uart_Output_Point+=length;
if (Uart_Output_Point>=UART_REV_LEN) if (Uart_Output_Point>=UART_REV_LEN)
                            Uart_Output_Point = 0; Uart_Output_Point = 0;
                        UEP2_T_LEN = length; // Pre-use send length must be cleared UEP2_T_LEN = length; // Pre-use send length must be cleared
                        UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_ACK; // Answer ACK UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_ACK; // Answer ACK
                        UpPoint2_Busy = 1; UpPoint2_Busy = 1;
                    } gpio_unset(0x10);
                } }
}
} }
} }
} }