Close

Test Menu Code

A project log for Not Quite Useless Raspberry Pi Replacement

Make a Raspberry Pi replacement using a Cypress Semiconductor Programmable System on a Chip (PSOC 5)

land-boardscomland-boards.com 10/17/2019 at 14:350 Comments

I need a really simple test menu. It should display over the USB-Serial interface and run under PuTTY.

This project started with the PSoC example project: USBUART. Currently, the code is doing the USBUART code which takes the serial data that the PSoC receives and loops it back to the Host.

Instead of pickup up the code it needs to be interpreted and responses sent back to the Host.

I think I will implement a very simple command interpreter to being with. The commands will be:

That was fairly easy to do. Here's the code:

       /* Service USB CDC when device is configured. */
        if (0u != USBUART_GetConfiguration())
        {
            /* Check for input data from host. */
            if (0u != USBUART_DataIsReady())
            {
                /* Read received data and re-enable OUT endpoint. */
                inCount = USBUART_GetAll(inBuffer);

                if (0u != inCount)
                {
                    /* Wait until component is ready to send data to host. */
                    while (0u == USBUART_CDCIsReady())
                    {
                    }
                    
                    if ((inBuffer[0] == 'r') || (inBuffer[0] == 'R'))
                    {
                        strcpy(outBuffer,"Read from the EEPROM\n\r");
                        outCount = strlen(outBuffer);
                        USBUART_PutData(outBuffer, outCount);
                    }
                    else if ((inBuffer[0] == 'w') || (inBuffer[0] == 'W'))
                    {
                        strcpy(outBuffer,"Write to the EEPROM\n\r");
                        outCount = strlen(outBuffer);
                        USBUART_PutData(outBuffer, outCount);
                    }
                    else if ((inBuffer[0] == 'b') || (inBuffer[0] == 'B'))
                    {
                        strcpy(outBuffer,"Blinking the LEDs on the RPP-UIO-16 card, please wait\n\r");
                        outCount = strlen(outBuffer);
                        USBUART_PutData(outBuffer, outCount);
                        testRPPUIO16();
                        strcpy(outBuffer,"Completed blinking the LEDs on the RPP-UIO-16 card\n\r");
                        USBUART_PutData(outBuffer, outCount);
                    }
                    else
                    {
                        strcpy(outBuffer,"Not a valid command, legal values are r, w, b\n\r");
                        outCount = strlen(outBuffer);
                        USBUART_PutData(outBuffer, outCount);
                    }
                    /* If the last sent packet is exactly the maximum packet 
                    *  size, it is followed by a zero-length packet to assure
                    *  that the end of the segment is properly identified by 
                    *  the terminal.
                    */
                    if (USBUART_Buffer_SIZE == inCount)
                    {
                        /* Wait until component is ready to send data to PC. */
                        while (0u == USBUART_CDCIsReady())
                        {
                        }

                        /* Send zero-length packet to PC. */
                        USBUART_PutData(NULL, 0u);
                    }
                }
            }
        }

Discussions