diff --git a/hw/boards/mta1-usb-v1/ch552_fw/include/debug.c b/hw/boards/mta1-usb-v1/ch552_fw/include/debug.c index 4328123..7d16178 100644 --- a/hw/boards/mta1-usb-v1/ch552_fw/include/debug.c +++ b/hw/boards/mta1-usb-v1/ch552_fw/include/debug.c @@ -160,3 +160,44 @@ int getchar() { return SBUF; } #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; + } + +} \ No newline at end of file diff --git a/hw/boards/mta1-usb-v1/ch552_fw/include/debug.h b/hw/boards/mta1-usb-v1/ch552_fw/include/debug.h index fc4ae39..eb0291a 100644 --- a/hw/boards/mta1-usb-v1/ch552_fw/include/debug.h +++ b/hw/boards/mta1-usb-v1/ch552_fw/include/debug.h @@ -177,3 +177,8 @@ inline void CH554WDTFeed(uint8_t tim) 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); \ No newline at end of file diff --git a/hw/boards/mta1-usb-v1/ch552_fw/main.c b/hw/boards/mta1-usb-v1/ch552_fw/main.c index 4d0b5ed..5ce23a6 100644 --- a/hw/boards/mta1-usb-v1/ch552_fw/main.c +++ b/hw/boards/mta1-usb-v1/ch552_fw/main.c @@ -573,12 +573,17 @@ main() UEP1_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) { if(UsbConfig) { if(USBByteCount) // USB receiving endpoint has data { + gpio_set(0x20); CH554UART1SendByte(Ep2Buffer[USBBufOutPoint++]); recievedData[USBBufOutPoint] = Ep2Buffer[USBBufOutPoint]; USBByteCount--; @@ -586,6 +591,7 @@ main() if(USBByteCount==0) UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_R_RES | UEP_R_RES_ACK; + gpio_unset(0x20); } if(UartByteCount) Uart_Timeout++; @@ -596,6 +602,7 @@ main() { if(length>39 || Uart_Timeout>100) { + gpio_set(0x10); Uart_Timeout = 0; if(Uart_Output_Point+length>UART_REV_LEN) length = UART_REV_LEN-Uart_Output_Point; @@ -605,12 +612,13 @@ main() Uart_Output_Point+=length; if (Uart_Output_Point>=UART_REV_LEN) -                            Uart_Output_Point = 0; -                        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 -                        UpPoint2_Busy = 1; -                    } -                } + Uart_Output_Point = 0; + 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 + UpPoint2_Busy = 1; + gpio_unset(0x10); + } + } } } }