Помогите разобраться все залитает в Mega2560 а в arduino nano 328p не хочет

Тема в разделе "Arduino & Shields", создана пользователем nem-victor, 5 янв 2019.

Метки:
  1. nem-victor

    nem-victor Нерд

    Вложения:

  2. nem-victor

    nem-victor Нерд

    Вот если ставить плату Mega2560 то сообщение такое
    Код (Text):
    Изменены опции сборки, пересобираем все
    Скетч использует 27304 байт (10%) памяти устройства. Всего доступно 253952 байт.
    Глобальные переменные используют 655 байт (7%) динамической памяти, оставляя 7537 байт для локальных переменных. Максимум: 8192 байт.
     
    А если выбрать Nano и чип 328p (168 не хватает места) сообщение такое
    Код (Text):
    Изменены опции сборки, пересобираем все
    C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-master\GSL1680\GSL1680.ino: In function 'void load_fw()':

    GSL1680:176:55: error: 'pgm_read_byte_far' was not declared in this scope

        buf[0] = pgm_read_byte_far(gslx680_fw + source_line); // gslx680_fw[source_line];

                                                           ^

    GSL1680:184:59: error: 'pgm_read_byte_far' was not declared in this scope

        buf[off++] = pgm_read_byte_far(gslx680_fw + source_line); // gslx680_fw[source_line];

                                                               ^

    Несколько библиотек найдено для "gslfw.h"
    Используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-master
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-e801b50a1ff95af581f36103c694223ad47a81c7
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-e801b50a1ff95af581f36103c694223ad47a81c7
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-e801b50a1ff95af581f36103c694223ad47a81c7
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-e801b50a1ff95af581f36103c694223ad47a81c7
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680
    exit status 1
    'pgm_read_byte_far' was not declared in this scope

     
     
  3. тут точно без пива с чипсами не разобраться.
     
  4. nem-victor

    nem-victor Нерд

    Вот в принципе разобрался
    Код (C++):
    // driver for the GSL1680 touch panel
    // Information gleaned from https://github.com/rastersoft/gsl1680.git and various other sources
    // firmware for the specific panel was found here:- http://www.buydisplay.com/default/5-inch-tft-lcd-module-800x480-display-w-controller-i2c-serial-spi
    // As was some test code.
    // This is for that 800X480 display and the 480x272 from buydisplay.com

    /*
    Pin outs
    the FPC on the touch panel is six pins, pin 1 is to the left pin 6 to the right with the display facing up

    pin | function  | Arduino Uno
    -----------------------------
    1   | SCL       | A5
    2   | SDA       | A4
    3   | VDD (3v3) | 3v3
    4   | Wake      | 4
    5   | Int       | 2
    6   | Gnd       | gnd
    */

    #include <Wire.h>
    #include "Arduino.h"


    // set this for teensy3
    //#define BIGFLASH

    // TODO define for other resolution
    #ifndef BIGFLASH
    #include "gslfw.h" // this is compacted format made by compress_data.c
    #else
    #include "gslX680firmware.h"
    #endif

    // Pins
    #define WAKE 4
    #define INTRPT 2
    #define LED 13

    #define SCREEN_MAX_X         800
    #define SCREEN_MAX_Y         480

    #define GSLX680_I2C_ADDR     0x40

    #define GSL_DATA_REG        0x80
    #define GSL_STATUS_REG        0xe0
    #define GSL_PAGE_REG        0xf0
    #define pgm_read_byte_far(address_long)
    #define pgm_read_word_far(address_long)  
    #define delayus delayMicroseconds

    struct _coord { uint32_t x, y; uint8_t finger; };

    struct _ts_event
    {
        uint8_t  n_fingers;
        struct _coord coords[5];
    };

    struct _ts_event ts_event;
    bool led= false;

    static inline void wiresend(uint8_t x) {
    #if ARDUINO >= 100
      Wire.write((uint8_t)x);
    #else
      Wire.send(x);
    #endif
    }

    static inline uint8_t wirerecv(void) {
    #if ARDUINO >= 100
      return Wire.read();
    #else
      return Wire.receive();
    #endif
    }

    bool i2c_write(uint8_t reg, uint8_t *buf, int cnt)
    {
        #if 0
        Serial.print("i2c write: "); Serial.println(reg, HEX);
        for(int i=0; i<cnt; i++){
            Serial.print(buf[i], HEX); Serial.print(",");
        }
        Serial.println();
        #endif

        Wire.beginTransmission(GSLX680_I2C_ADDR);
        wiresend(reg);
        for(int i=0; i<cnt; i++){
            wiresend(buf[i]);
        }
        int r= Wire.endTransmission();
        if(r != 0){ Serial.print("i2c write error: "); Serial.print(r); Serial.print(" "); Serial.println(reg, HEX); }
        return r == 0;
    }

    int i2c_read(uint8_t reg, uint8_t *buf, int cnt)
    {
        Wire.beginTransmission(GSLX680_I2C_ADDR);
          wiresend(reg);
          int r= Wire.endTransmission();
        if(r != 0){ Serial.print("i2c read error: "); Serial.print(r); Serial.print(" "); Serial.println(reg, HEX); }

          int n= Wire.requestFrom(GSLX680_I2C_ADDR, cnt);
        if(n != cnt){ Serial.print("i2c read error: did not get expected count "); Serial.print(n); Serial.print(" - "); Serial.println(cnt); }

          for(int i=0; i<n; i++){
              buf[i]= wirerecv();
          }
          return n;
    }

    void clr_reg(void)
    {
        uint8_t buf[4];

        buf[0] = 0x88;
        i2c_write(0xe0, buf, 1);
        delay(20);

        buf[0] = 0x01;
        i2c_write(0x80, buf, 1);
        delay(5);

        buf[0] = 0x04;
        i2c_write(0xe4, buf, 1);
        delay(5);

        buf[0] = 0x00;
        i2c_write(0xe0, buf, 1);
        delay(20);
    }

    void reset_chip()
    {
        uint8_t buf[4];

        buf[0] = 0x88;
        i2c_write(GSL_STATUS_REG, buf, 1);
        delay(20);

        buf[0] = 0x04;
        i2c_write(0xe4,buf, 1);
        delay(10);

        buf[0] = 0x00;
        buf[1] = 0x00;
        buf[2] = 0x00;
        buf[3] = 0x00;
        i2c_write(0xbc,buf, 4);
        delay(10);
    }

    #ifndef BIGFLASH
    // the data is in blocks of 128 bytes, each one preceded by the page number
    // we first send the page number then we send the data in blocks of 32 until the entire page is sent
    // NOTE that the firmware data is stored in flash as it is huge! around 28kBytes
    void load_fw(void)
    {
        uint8_t buf[32];
        size_t source_len = sizeof(gslx680_fw);
        Serial.print("Firmware length: "); Serial.println(source_len);
        int blockstart= 1;
        int reg= 0;
        int off= 0;
        size_t source_line;
        for (source_line=0; source_line < source_len; source_line++) {
            if(off == 32){
                i2c_write(reg, buf, 32); // write accumulated block
                reg += 32;
                off= 0;
                if(reg >= 128) blockstart= 1;
            }

            if(blockstart) {
                blockstart= 0;
                buf[0] = pgm_read_byte_far(gslx680_fw + source_line) gslx680_fw[source_line];
                buf[1] = 0;
                buf[2] = 0;
                buf[3] = 0;
                i2c_write(GSL_PAGE_REG, buf, 4);
                reg= 0;

            }
            else{
                buf[off++] = pgm_read_byte_far(gslx680_fw + source_line) gslx680_fw[source_line];
            }
        }
        if(off == 32){ // write last accumulated block
            i2c_write(reg, buf, 32);
        }
    }

    #else

    void load_fw(void)
    {
        uint8_t addr;
        uint8_t Wrbuf[4];
        uint16_t source_line = 0;
        uint16_t source_len = sizeof(GSLX680_FW) / sizeof(struct fw_data);


        for (source_line = 0; source_line < source_len; source_line++) {
            addr = GSLX680_FW[source_line].offset;
            Wrbuf[0] = (char)(GSLX680_FW[source_line].val & 0x000000ff);
            Wrbuf[1] = (char)((GSLX680_FW[source_line].val & 0x0000ff00) >> 8);
            Wrbuf[2] = (char)((GSLX680_FW[source_line].val & 0x00ff0000) >> 16);
            Wrbuf[3] = (char)((GSLX680_FW[source_line].val & 0xff000000) >> 24);

            i2c_write(addr, Wrbuf, 4);
        }
    }
    #endif

    void startup_chip(void)
    {
        uint8_t buf[4];

        buf[0] = 0x00;
        i2c_write(0xe0, buf, 1);
    }

    void init_chip()
    {
    #if 1
        Serial.println("Toggle Wake");
        digitalWrite(WAKE, HIGH);
        delay(50);
        digitalWrite(WAKE, LOW);
        delay(50);
        digitalWrite(WAKE, HIGH);
        delay(30);

        delay(500);

        // CTP startup sequence
        Serial.println("clr reg");
        clr_reg();
        Serial.println("reset_chip");
        reset_chip();
        Serial.println("load_fw");
        load_fw();
        //startup_chip();
        Serial.println("reset_chip2");
        reset_chip();
        Serial.println("startup_chip");
        startup_chip();
        Serial.println("init done");

    #else
        // rastersoft int sequence
        reset_chip();
        load_fw();
        startup_chip();
        reset_chip();

        digitalWrite(WAKE, LOW);
        delay(50);
        digitalWrite(WAKE, HIGH);
        delay(30);
        digitalWrite(WAKE, LOW);
        delay(5);
        digitalWrite(WAKE, HIGH);
        delay(20);

        reset_chip();
        startup_chip();
    #endif
    }

    int read_data(void)
    {

        Serial.println("reading data...");
        uint8_t touch_data[24] = {0};
        int n= i2c_read(GSL_DATA_REG, touch_data, 24);
        Serial.print("read: "); Serial.println(n);

        ts_event.n_fingers= touch_data[0];
        for(int i=0; i<ts_event.n_fingers; i++){
            ts_event.coords[i].x = ( (((uint32_t)touch_data[(i*4)+5])<<8) | (uint32_t)touch_data[(i*4)+4] ) & 0x00000FFF; // 12 bits of X coord
            ts_event.coords[i].y = ( (((uint32_t)touch_data[(i*4)+7])<<8) | (uint32_t)touch_data[(i*4)+6] ) & 0x00000FFF;
            ts_event.coords[i].finger = (uint32_t)touch_data[(i*4)+7] >> 4; // finger that did the touch
        }

        return ts_event.n_fingers;
    }

    void setup() {
        Serial.begin(9600);
        Serial.println("Starting");
        pinMode(LED, OUTPUT);
        pinMode(WAKE, OUTPUT);
        digitalWrite(WAKE, LOW);
        pinMode(INTRPT, INPUT_PULLUP);
        delay(100);
        Wire.begin();
        init_chip();

    #if 0
        uint8_t buf[4];
        int n= i2c_read(0xB0, buf, 4);
        Serial.print(buf[0], HEX); Serial.print(","); Serial.print(buf[1], HEX); Serial.print(","); Serial.print(buf[2], HEX); Serial.print(","); Serial.println(buf[3], HEX);
    #endif
    }

    void loop() {
        if(digitalRead(INTRPT) == HIGH) {
            digitalWrite(LED, led);
            led= !led;
            int n= read_data();
            for(int i=0; i<n; i++){
                Serial.print(ts_event.coords[i].finger); Serial.print(" "), Serial.print(ts_event.coords[i].x); Serial.print(" "), Serial.print(ts_event.coords[i].y);
                 Serial.println("");
            }
            Serial.println("---");
        }
    }
     
     
  5. nem-victor

    nem-victor Нерд

    теперь проходит проверку для Nano 328p
     
  6. Airbus

    Airbus Радиохулиган Модератор

    Mega2560!=nano 328
     
  7. nem-victor

    nem-victor Нерд

    - тогда объясните почему вылазят ошибки когда скетч от 2560 пытатешся залить в 238ю?
     
  8. parovoZZ

    parovoZZ Гуру

    это такая шутка??? Те ж написали
     
  9. nem-victor

    nem-victor Нерд

    Хорошо, чисто для Вас "ГУРУ" по порядку:
    1) Берем скеч без правки, прям свежак из архива с Gihab.https://github.com/wolfmanjm/GSL1680/tree/f5af2ef8d11d7518a43f30183d75de5b5616f78c
    2) Открываем GSL1680.ino (Arduino 1.8.8.)
    3) Выбираем в инструментах плату "Arduino/Genuino Mega or Mega2560" на 2560 чипе
    4) Нажимаем "Проверить" и....
    Код (Text):
    Скетч использует 27304 байт (10%) памяти устройства. Всего доступно 253952 байт.
    Глобальные переменные используют 655 байт (7%) динамической памяти, оставляя 7537 байт для локальных переменных. Максимум: 8192 байт.
     
    Все норм
    5) Теперь берем и выбираем плату "Arduino Nano" на 328p чипе
    6) Нажимаем "проверить" и ....
    ошибка
    Код (Text):

    Изменены опции сборки, пересобираем все
    C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-master\GSL1680\GSL1680.ino: In function 'void load_fw()':

    GSL1680:176:55: error: 'pgm_read_byte_far' was not declared in this scope

        buf[0] = pgm_read_byte_far(gslx680_fw + source_line); // gslx680_fw[source_line];

                                                           ^

    GSL1680:184:59: error: 'pgm_read_byte_far' was not declared in this scope

        buf[off++] = pgm_read_byte_far(gslx680_fw + source_line); // gslx680_fw[source_line];

                                                               ^

    Несколько библиотек найдено для "gslfw.h"
    Используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-master
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-e801b50a1ff95af581f36103c694223ad47a81c7
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-e801b50a1ff95af581f36103c694223ad47a81c7
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-e801b50a1ff95af581f36103c694223ad47a81c7
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680-e801b50a1ff95af581f36103c694223ad47a81c7
    Не используется: C:\Users\nemvi.DESKTOP-SFK8G8G\Documents\Arduino\libraries\GSL1680
    exit status 1
    'pgm_read_byte_far' was not declared in this scope

     
    И так .... Ваш ответ?
     
  10. parovoZZ

    parovoZZ Гуру

    Печатаю в 25 раз - это разные МК с разным набором регистров и с разным объемом памяти. Если тебе кто-то сказал, что абдурина - это просто, то знай - тебя жестоко обманули.
     
  11. nem-victor

    nem-victor Нерд

    Так н*фига писать что "Mega2560!=nano 328", я и без вас знаю что чипы разные,
     
  12. parovoZZ

    parovoZZ Гуру

    захотели и написали. Мы же математики? Эта запись и обозначает не равенство.
     
  13. nem-victor

    nem-victor Нерд

    Еще бы на асемблере код написали из*шенцы. Все тема закрыта, а то флуд пошел
     
  14. Книга по работе с WinAVR и AVR Studio
    Роман Абраш г.Новочеркасск
    pgm_read_byte_far(address_long) – макрос, возвращающий значение байта, считанного из программной памяти по адресу address_long (32 бита, нет ограничения в 64К).

    Для меги 328p c её 32-мя килограммами флеша, макрос pgm_read_byte_far просто не определен, заменил в коде pgm_read_byte_far на pgm_read_byte и почему то собралсь ;-)
    Код (C++):

    Скетч использует 26824 байт (87%) памяти устройства. Всего доступно 30720 байт.
    Глобальные переменные используют 655 байт (31%) динамической памяти, оставляя 1393 байт для локальных переменных. Максимум: 2048 байт.
     
     
    Andrey12, FalloutST, Un_ka и 2 другим нравится это.
  15. nem-victor

    nem-victor Нерд

    Спасибо Алексей.А, просто объяснил и все, а не умничал как некоторые
     
    Un_ka нравится это.
  16. b707

    b707 Гуру

    кто ж виноват, что до тебя очевидные вещи доходят с десятого ответа?
     
    DetSimen нравится это.
  17. FalloutST

    FalloutST Нуб

    О ты друг и тут помог. Прям решил проблему человека. И доходчиво объяснил, что ему читать. Ладно дальше я твои коменты читать не буду. А то может быть заражусь и посоветую тебе не писать на эти форумы вообще. А то кроме спама ничего не генерируешь....