Announcement

Collapse
No announcement yet.

Gen4 uLCD and redpitaya

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gen4 uLCD and redpitaya

    I'm trying to ouput a data to au Led digit widget on a gen4-uLCD-32DT with a Redpitaya 125-14. I'd trying C examples but i've got complilation issues. Does someone tried it with a redpitaya ?

  • #2
    Hi,

    I don't have the Redpitaya to test with, but can you detail to me the compilation errors that you are getting? and whatC example you are using?

    Best Regards,

    Comment


    • #3

      Code:
      gcc -g -std=gnu99 -Wall -Werror main.c -o main
      /tmp/ccGeHw4r.o: In function `myGenieEventHandler':
      /root/RedPitaya/Com_VisiGenie/uart/main.c:103: undefined reference to `genieDequeueEvent'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:112: undefined reference to `genieGetEventData'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:113: undefined reference to `genieWriteObject'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:122: undefined reference to `genieGetEventData'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:124: undefined reference to `genieWriteObject'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:159: undefined reference to `genieWriteObject'
      /tmp/ccGeHw4r.o: In function `main':
      /root/RedPitaya/Com_VisiGenie/uart/main.c:312: undefined reference to `genieBegin'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:313: undefined reference to `genieAttachEventHandler'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:318: undefined reference to `genieWriteObject'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:322: undefined reference to `genieWriteStr'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:327: undefined reference to `genieDoEvents'
      /root/RedPitaya/Com_VisiGenie/uart/main.c:332: undefined reference to `genieOnline'
      collect2: error: ld returned 1 exit status
      <builtin>: recipe for target 'main' failed
      make: *** [main] Error 1

      Comment


      • #4
        My main.c

        Code:
        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
        #include <unistd.h> //Used for UART
        #include <fcntl.h> //Used for UART
        #include <termios.h> //Used for UART
        #include <errno.h>
        #include "visi_genie.h"
        
        
        
        /* Inline function definition */
        static int uart_init();
        static int release();
        //static int uart_read(int size);
        static int uart_write();
        
        /* File descriptor definition */
        int uart_fd = -1;
        
        typedef enum {
        RX_REINITIALIZE,
        RX_READY
        } RxStatus;
        /*VisiGenie*/
        
        
        //#define GenieSerial Serial1
        //#define GenieDebug Serial
        #define RX_BUF_SIZE 64
        #define UPDATE_INTERVAL 10
        #define CW 0
        #define CCW 1
        #define ticks 125
        
        /* Private variables ---------------------------------------------------------*/
        //UART_HandleTypeDef huart1;STM32
        //UART_HandleTypeDef huart2;STM32
        
        
        
        /* USER CODE BEGIN PV */
        struct RxBuffer {
        uint8_t data[RX_BUF_SIZE];
        uint8_t head; // read from head
        uint8_t tail; // write from tail
        uint8_t count;
        uint8_t new;
        RxStatus status;
        } rx_buffer;
        /* USER CODE END PV */
        
        //Extern
        
        // Extern Functions
        void showError(uint16_t interval) {
        while (1) {
        //show error
        }
        }
        void geniePutByte(uint8_t c) {
        uart_write(uart_fd, &c,sizeof(c)-1);
        }
        
        uint16_t genieGetByteCount() {
        //return GenieSerial.available();
        return 0;
        }
        
        uint8_t geniePeekByte() {
        //return GenieSerial.peek();
        return 0;
        }
        
        uint8_t genieGetByte() {
        //return GenieSerial.read();
        //return int rx_length = read(uart_fd, (void*)rx_buffer, size);
        return 0;
        }
        
        unsigned long millis(void) {
        return ticks;
        }
        
        // Handlers
        void myDebugHandler(char *str){
        //myprintf("%s\r\n", str);
        }
        
        
        
        void myGenieEventHandler(void) {
        genieFrame Event;
        genieDequeueEvent(&Event);
        
        //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
        static int slider_val = 0;
        
        /* If the commamd received is from a Reported Event, it will be processed here. */
        if (Event.reportObject.cmd == GENIE_REPORT_EVENT) {
        if (Event.reportObject.object == GENIE_OBJ_SLIDER) { // If the Reported Message was from a Slider
        if (Event.reportObject.index == 0) { // If Slider0 (Index = 0)
        slider_val = genieGetEventData( & Event); // Receive the event data from the Slider0
        genieWriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value to to LED Digits 0
        }
        }
        }
        
        /* If the commamd received is from a Reported Object, which occurs if a Read Object (genie.ReadOject) is requested in the main code, reply processed here. */
        else if (Event.reportObject.cmd == GENIE_REPORT_OBJ) {
        if (Event.reportObject.object == GENIE_OBJ_USER_LED) { // If the Reported Message was from a User LED
        if (Event.reportObject.index == 0) { // If UserLed0 (Index = 0)
        bool UserLed0_val = genieGetEventData( & Event); // Receive the event data from the UserLed0
        UserLed0_val = !UserLed0_val; // Toggle the state of the User LED Variable
        genieWriteObject(GENIE_OBJ_USER_LED, 0, UserLed0_val); // Write UserLed0_val value back to to UserLed0
        }
        }
        }
        
        /********** This can be expanded as more objects are added that need to be captured *************
        *************************************************************************************************
        Event.reportObject.cmd is used to determine the command of that event, such as an reported event
        Event.reportObject.object is used to determine the object type, such as a Slider
        Event.reportObject.index is used to determine the index of the object, such as Slider0
        genieGetEventData(&Event) us used to save the data from the Event, into a variable.
        *************************************************************************************************/
        else if (Event.reportObject.cmd == GENIE_PING) {
        if (Event.reportObject.object == GENIE_DISCONNECTED) {
        /* This function runs once, when the LCD is disconnected, because it was turned off or out of sync.
        You may use this to process necessary code. */
        //HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
        
        // uint16_t reason = genieGetEventData(&Event); // Receive the reason
        // if (reason == 1) {
        // HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
        // while (1);
        // } else {
        // while (1) {
        // HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET); // here we toggle the led on and off after every successful ping interval.
        // HAL_Delay(500);
        // HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
        // HAL_Delay(500);
        // }
        // }
        
        
        } else if (Event.reportObject.object == GENIE_READY) {
        /* This function runs once, when the LCD is connected and synchronized.
        You may use this to restore screen widgets, or process other code. */
        genieWriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Restore Leddigits0
        //genieWriteObject(GENIE_OBJ_SLIDER, 0, slider_val); // Restore Slider0
        static int recover_times = -1; // how many times did the display recover?
        recover_times++;
        // genieWriteStr(0, (String) GENIE_VERSION + "\n\n\tRecovered " + recover_times + " Time(s)!"); // Restore text in Strings0
        } else if (Event.reportObject.object == GENIE_ACK) {
        /* If a user issues a genie.Ping(interval) request and it passes,
        this function will happen every 'interval' times chosen by the user. */
        // HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET); // here we toggle the led on and off after every successful ping interval.
        // HAL_Delay(20);
        // HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
        } else if (Event.reportObject.object == GENIE_NAK) {
        /* If a user issues a genie.Ping(interval) request and it fails,
        this function will happen every 'interval' times chosen by the user. */
        }
        }
        }
        
        static int uart_init(){
        
        uart_fd = open("/dev/ttyPS1", O_RDWR | O_NOCTTY | O_NDELAY);
        
        if(uart_fd == -1){
        fprintf(stderr, "Failed to open uart.\n");
        return -1;
        }
        
        struct termios settings;
        tcgetattr(uart_fd, &settings);
        
        /* CONFIGURE THE UART
        * The flags (defined in /usr/include/termios.h - see http://pubs.opengroup.org/onlinepubs/007908799/xsh/termios.h.html):
        * Baud rate:- B1200, B2400, B4800, B9600, B19200, B38400, B57600, B115200, B230400, B460800, B500000, B576000, B921600, B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, B4000000
        * CSIZE:- CS5, CS6, CS7, CS8
        * CLOCAL - Ignore modem status lines
        * CREAD - Enable receiver
        * IGNPAR = Ignore characters with parity errors
        * ICRNL - Map CR to NL on input (Use for ASCII comms where you want to auto correct end of line characters - don't use for bianry comms!)
        * PARENB - Parity enable
        * PARODD - Odd parity (else even) */
        
        /* Set baud rate - default set to 9600Hz */
        speed_t baud_rate = B115200;
        
        /* Baud rate fuctions
        * cfsetospeed - Set output speed
        * cfsetispeed - Set input speed
        * cfsetspeed - Set both output and input speed */
        
        cfsetspeed(&settings, baud_rate);
        
        settings.c_cflag &= ~PARENB; /* no parity */
        settings.c_cflag &= ~CSTOPB; /* 1 stop bit */
        settings.c_cflag &= ~CSIZE;
        settings.c_cflag |= CS8 | CLOCAL; /* 8 bits */
        settings.c_lflag = ICANON; /* canonical mode */
        settings.c_oflag &= ~OPOST; /* raw output */
        
        /* Setting attributes */
        tcflush(uart_fd, TCIFLUSH);
        tcsetattr(uart_fd, TCSANOW, &settings);
        
        return 0;
        }
        
        /*
        static int uart_read(int size){
        
        // Read some sample data from RX UART
        
        // Don't block serial read
        fcntl(uart_fd, F_SETFL, FNDELAY);
        
        while(1){
        if(uart_fd == -1){
        fprintf(stderr, "Failed to read from UART.\n");
        return -1;
        }
        
        unsigned char rx_buffer[size];
        
        int rx_length = read(uart_fd, (void*)rx_buffer, size);
        
        if (rx_length < 0){
        
        // No data yet avaliable, check again
        
        if(errno == EAGAIN){
        fprintf(stderr, "AGAIN!\n");
        continue;
        // Error differs
        }else{
        fprintf(stderr, "Error!\n");
        return -1;
        }
        
        }else if (rx_length == 0){
        fprintf(stderr, "No data waiting\n");
        // Print data and exit while loop
        }else{
        rx_buffer[rx_length] = '\0';
        printf("%i bytes read : %s\n", rx_length, rx_buffer);
        break;
        
        }
        }
        
        return 0;
        }
        */
        static int uart_write(int data){
        
        /* Write some sample data into UART */
        /* ----- TX BYTES ----- */
        int msg_len = sizeof(data)-1;
        
        int count = 0;
        /*char tx_buffer[msg_len+1];
        
        strncpy(tx_buffer, &data, msg_len);
        tx_buffer[msg_len++] = 0x0a; //New line numerical value*/
        
        if(uart_fd != -1){
        count = write(uart_fd, &data,msg_len);
        }
        if(count < 0){
        fprintf(stderr, "UART TX error.\n");
        return -1;
        }
        
        return 0;
        }
        
        static int release(){
        
        tcflush(uart_fd, TCIFLUSH);
        close(uart_fd);
        
        return 0;
        }
        
        int main(int argc, char *argv[]){
        
        unsigned long lastUpdate = 0;
        int temperature=100;
        uint8_t state;
        
        //uart init
        if(uart_init() < 0){
        printf("Uart init error.\n");
        return -1;
        }
        uart_init();
        genieBegin();
        genieAttachEventHandler(myGenieEventHandler);
        //int data = 0x003A01; //01 3A 00 00 01 3A
        //int data2 = 0x3A0100;
        
        
        genieWriteObject(GENIE_OBJ_LED_DIGITS, 0, temperature); //on affiche la température
        
        
        
        genieWriteStr(0, GENIE_VERSION);
        lastUpdate = millis() - UPDATE_INTERVAL;
        
        while (1)
        {
        genieDoEvents();
        if (millis() - lastUpdate >= UPDATE_INTERVAL) {
        lastUpdate = millis();
        state = !(state);
        
        if (genieOnline()) { // check if the display is online (connected) and if on Form0
        
        }
        //genieWriteObject(GENIE_OBJ_COOL_GAUGE, 0, coolgaugeVal);
        
        // The results of this call will be available to myGenieEventHandler() after the display has responded
        //genieReadObject(GENIE_OBJ_USER_LED, 0); // Do a manual read from the UserLEd0 object
        }
        }
        /* USER CODE END WHILE */
        //uart_write(data);
        //uart_write(data2);
        /*
        //Sample write
        if(uart_write(data) < 0){
        printf("Uart write error\n");
        return -1;
        }
        
        //Sample read
        if(uart_read(strlen(data)) < 0){
        printf("Uart read error\n");
        return -1;
        }
        */
        // CLOSING UART
        release();
        
        return 0;
        }

        Comment


        • #5
          Perhaps my makefile isn't appropriate ?
          Code:
          #
          # Red Pitaya UART makefile
          # Author: Luka Golinar <[email protected]>
          #
          
          # Versioning system
          VERSION ?= 0.10-0000
          
          REVISION ?= devbuild
          
          #Cross compiler definition
          CC = $(CROSS_COMPILE)gcc
          #Flags
          CFLAGS = -g -std=gnu99 -Wall -Werror
          #Objects
          #$(SRC:.c=.o)
          #OBJECTS = main.o visi_genie.o
          
          #OBJECTS = $(.c=.o)
          OBJECTS = $(wildcard *.c)
          #Target file
          TARGET = uart_test
          
          #Build the executable
          all: $(TARGET)
          
          $(TARGET): $(OBJECTS)
          $(CC) -o [email protected] $^ $(CFLAGS)
          
          
          %.o: %.c
          $(CC) -c $(CFLAGS) $< -o [email protected]
          
          clean:
          $(RM) $(TARGET) *.o ~*

          Comment


          • #6
            Hi,

            It seems that your main issue is the "undefined reference to". Please make sure the h file for the ViSi-genie library is declared properly and the path is correct.

            Best Regards,

            Comment

            Working...
            X