'prog_uint8_t' 没有命名类型 - ARDUINO IDE

'prog_uint8_t' does not name a type - ARDUINO IDE

恐怕这是一个非常新手的问题,但我已经尽力理解这个问题,但由于我对 C 编程的经验很少,所以一无所获。

我目前正在从 Instructables 中挑选一两年前的旧项目:https://www.instructables.com/id/Jar-of-Fireflies/

这包括为 Firefly 模式编写的固件的 C 文件,但这是 12 年前编写的。

但是......我没有按照第N度的指导。相反,我使用的是 DIP AtTiny85,我之前使用 Arduino 作为 ISP 对其进行了编程。因此希望能够使用 Visual Micro 插件在 Arduino IDE 或 Atmel Studio 中编译代码。

每次在 Arduino IDE 中编译时,我都会收到以下错误: 'prog_uint8_t' 没有命名类型,这会导致很多错误。

据我了解,这种减速是 removed/changed 作为 AVR GCC 的一部分,在 2010 年左右...我是否可以将其正确编译为 运行 代码?也许使用宏或包含一个库。我已经尝试了一些库,例如 #include <stdint.h>,但相信这应该作为自动 <Arduino.h> 包含的一部分来处理。我确定如果我带了合适的程序员,我的问题可能会消失,但我确定有一个简单的解决方法..?

以上可指导 link 中以 .tgz 形式提供的代码,其中包括 headers、c 可执行文件、十六进制等,

用于快速阅读主要的 c 可执行文件声明....

const prog_uint8_t about[] = "Jar of Fireflies\n"
        "Design and Implementation by Xander Hudson (jar@synoptic.org)\n"
        "Idea and Inspiration by Kayobi Tierney\n"
        "Special thanks to Katie Horn for getting me to think about 
electronics";
const prog_uint8_t version[] = "$Revision: 1.41 $ $Date: 2007/01/10 
04:35:55 $";

#define LEDS_OFF ~(_BV(PIN_A) | _BV(PIN_B))

#define WATCHDOG_OK  WDTCR |= _BV(WDIE)

uint8_t pickapin (uint8_t);
const Song *pickasong (void);
uint8_t randwaitval (void);
uint8_t randbits (uint8_t);
uint8_t pickmaster (void);
uint8_t randscaleval (void);
void showbootup (void);

volatile uint8_t ch1restcount;
volatile uint8_t ch2restcount;

volatile uint8_t ch1nextnote;
volatile uint8_t ch2nextnote;

volatile uint8_t ch1scale;
volatile uint8_t ch2scale;
volatile uint8_t ch1nextscale;
volatile uint8_t ch2nextscale;

uint8_t mood = 2;
uint16_t mood_count = 30;   // WDT cycles before changing mood

volatile uint8_t masterpinmask;

错误:

   In file included from C:\Program Files         
(x86)\Arduino\libraries\Firefly/firefly.h:12:0,

             from     
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:
C:\Program Files (x86)\Arduino\libraries\Firefly/songs/songs.h:4:11: error: 'prog_uint8_t' does not name a type

 const prog_uint8_t  *notes; 

       ^

In file included from C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:14:0,

             from         
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/bootsong.h:3:7: error: 'prog_uint8_t' does not name a type

const prog_uint8_t bootsongnotes[] = {0, 4, 9, 16, 24, 33, 41, 47, 50, 49, 

   ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/bootsong.h:5:26: error: 'bootsongnotes' was not declared in this scope

 Song bootsong = { sizeof(bootsongnotes), bootsongnotes };

                      ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/bootsong.h:5:42: error: 'bootsongnotes' was not declared in this scope

 Song bootsong = { sizeof(bootsongnotes), bootsongnotes };

                                      ^

In file included from C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:25:0,

             from         
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2a.h:6:7: error: 'prog_uint8_t' does not name a type

const prog_uint8_t song2anotes[] = {2, 29, 81, 123, 130, 104, 63, 24, 2, 

   ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2a.h:20:24: error: 'song2anotes' was not declared in this scope

 Song song2a = { sizeof(song2anotes), song2anotes };

                    ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2a.h:20:38: error: 'song2anotes' was not declared in this scope

 Song song2a = { sizeof(song2anotes), song2anotes };

                                  ^

In file included from C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:26:0,

             from 
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2b.h:6:7: error: 'prog_uint8_t' does not name a type

 const prog_uint8_t song2bnotes[] = {1, 31, 89, 126, 119, 85, 42, 6, 1, 1,

   ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2b.h:19:24: error: 'song2bnotes' was not declared in this scope

  Song song2b = { sizeof(song2bnotes), song2bnotes };

                    ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2b.h:19:38: error: 'song2bnotes' was not declared in this scope

Song song2b = { sizeof(song2bnotes), song2bnotes };

                                  ^

In file included from C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:27:0,

             from 
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2c.h:6:7: error: 'prog_uint8_t' does not name a type

 const prog_uint8_t song2cnotes[] = {2, 25, 70, 117, 146, 144, 111, 61, 18, 

   ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2c.h:21:24: error: 'song2cnotes' was not declared in this scope

Song song2c = { sizeof(song2cnotes), song2cnotes };

                    ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2c.h:21:38: error: 'song2cnotes' was not declared in this scope

 Song song2c = { sizeof(song2cnotes), song2cnotes };

                                  ^

In file included from C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:28:0,

             from 
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2d.h:6:7: error: 'prog_uint8_t' does not name a type

 const prog_uint8_t song2dnotes[] = {1, 27, 72, 109, 121, 104, 61, 17, 1, 1, 

   ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2d.h:17:24: error: 'song2dnotes' was not declared in this scope

 Song song2d = { sizeof(song2dnotes), song2dnotes };

                    ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2d.h:17:38: error: 'song2dnotes' was not declared in this scope

 Song song2d = { sizeof(song2dnotes), song2dnotes };

                                  ^

In file included from C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:29:0,

             from 
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2e.h:6:7: error: 'prog_uint8_t' does not name a type

const prog_uint8_t song2enotes[] = {1, 26, 73, 116, 131, 115, 80, 39, 8, 

   ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2e.h:21:24: error: 'song2enotes' was not declared in this scope

Song song2e = { sizeof(song2enotes), song2enotes };

                    ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2e.h:21:38: error: 'song2enotes' was not declared in this scope

 Song song2e = { sizeof(song2enotes), song2enotes };

                                  ^

In file included from C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:30:0,

             from 
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2f.h:6:7: error: 'prog_uint8_t' does not name a type

const prog_uint8_t song2fnotes[] = {2, 36, 94, 130, 121, 79, 27, 1, 1, 1, 

   ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2f.h:17:24: error: 'song2fnotes' was not declared in this scope

 Song song2f = { sizeof(song2fnotes), song2fnotes };

                    ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2f.h:17:38: error: 'song2fnotes' was not declared in this scope

 Song song2f = { sizeof(song2fnotes), song2fnotes };

                                  ^

In file included from C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:31:0,

             from 
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2g.h:6:7: error: 'prog_uint8_t' does not name a type

 const prog_uint8_t song2gnotes[] = {2, 42, 99, 121, 96, 42, 3, 1, 1, 1, 1, 

   ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2g.h:14:24: error: 'song2gnotes' was not declared in this scope

 Song song2g = { sizeof(song2gnotes), song2gnotes };

                    ^

C:\Program Files (x86)\Arduino\libraries\Firefly/songs/song2g.h:14:38: error: 'song2gnotes' was not declared in this scope

 Song song2g = { sizeof(song2gnotes), song2gnotes };

                                  ^

In file included from 
C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino:8:0:

C:\Program Files (x86)\Arduino\libraries\Firefly/firefly.h:133:7: error: 
'prog_uint8_t' does not name a type

 const prog_uint8_t bitmasks[] = { 

   ^

 Firefly01:11: error: 'prog_uint8_t' does not name a type

 const prog_uint8_t about[] = "Jar of Fireflies\n"

   ^

Firefly01:15: error: 'prog_uint8_t' does not name a type

  const prog_uint8_t version[] = "$Revision: 1.41 $ $Date: 2007/01/10 04:35:55 $";

   ^

In file included from C:\Users\Andrew\AppData\Local\Arduino15\packages\arduino\hardware\avr.6.21\cores\arduino/Arduino.h:28:0,

             from sketch\Firefly01.ino.cpp:1:

C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino: In function 'int main()':

Firefly01:230: error: 'const Song' has no member named 'notes'

                 temp = pgm_read_byte(&ch1song->notes[ch1noteptr++]);

                                                ^

Firefly01:244: error: 'const Song' has no member named 'notes'

                 temp = pgm_read_byte(&ch2song->notes[ch2noteptr++]);

                                                ^

Firefly01:288: error: 'const Song' has no member named 'notes'

         temp = pgm_read_byte(&ch1song->notes[ch1noteptr++]);

                                        ^

Firefly01:313: error: 'const Song' has no member named 'notes'

         temp = pgm_read_byte(&ch2song->notes[ch2noteptr++]);

                                        ^

C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino: In function 
'void showbootup()':

Firefly01:379: error: 'const Song' has no member named 'notes'

             ch1nextnote = pgm_read_byte(&ch1song->notes[ch1noteptr++]);

                                                   ^

C:\Users\Andrew\Documents\Arduino\Firefly01\Firefly01.ino: In function 'uint8_t randbits(uint8_t)':

Firefly01:485: error: 'bitmasks' was not declared in this scope

 return ((lfsr & 0xFF) & pgm_read_byte(&bitmasks[bits]));    

                                        ^

exit status 1
'prog_uint8_t' does not name a type

// ------------------ 错误结束

一旦为无符号 8/16/32 位 int 减速定义了一种方法,我希望程序能够编译。

如果有人能帮助我更好地理解那就太好了。因为当有人花了很长时间让萤火虫算法变得很好时,我宁愿不编写自己的代码!但是,我愿意学习,所以任何 link 类似这样的东西也会很好。

它已被折旧,但是您应该能够通过在使用 prog_uint8_t

之前添加以下代码来使其正常工作
#define __PROG_TYPES_COMPAT__
#include  <avr/pgmspace.h>

typedef uint8_t PROGMEM prog_uint8_t;

prog_uint8_t

这个 typedef 由 avr-libc 的(非常)旧的 headers 提供。问题是他们在 avr-gcc / avr-g++ 不支持的 typedef 中使用了 __attribute__((__progmem__))progmem 是一个 变量 属性和 不是类型 属性,c.f。 avr-gcc ABI.


#define __PROG_TYPES_COMPAT__
#include  <avr/pgmspace.h>

不是解决方案:虽然它"fixes"构建错误,但它会调用未定义的行为,因为progmem 不是类型属性。这些类型已被弃用是有原因的!


typedef uint8_t PROGMEM prog_uint8_t;

不是解决方案:虽然它"fixes"构建错误,但它会调用未定义的行为,因为progmem 不是类型属性。


typedef uint8_t prog_uint8_t;

不是解决方案:虽然它"fixes"构建错误,objects声明为该类型将位于 RAM 中,因此用于从闪存/程序存储器读取数据的 pgm_read_xxx() 将读取垃圾,因为数据位于错误的地址 space。原则上,您可以使用该 typedef 并使用 vanilla C++ 访问而不是通过 pgm_read_xxx 进行读取,但这不是您想要的,因为引入 PROGMEM 是为了将 const 变量放入闪存中而不是放入 RAM 中。这是因为对于大多数 AVR,.rodata 位于 RAM 而不是闪存中。但是请参阅下面的注释。

那么解决方案是什么?

正确的解决方案是将 #include <avr/pgmspace.h> 定义的 PROGMEM 用于以前使用这些可怕的 prog 类型的所有 object 定义:使用

const uint8_t array_flash[] PROGMEM = { 1, 2 };

而不是不正确的

const prog_uint8_t array_flash[] = { 1, 2 };

由于您使用的是 C++,因此 space 之类的地址 __flash 不可用,我不会深入讨论。

注:有线性地址space的AVR设备。对于此类设备,.rodata 位于闪存中。这意味着对于这样的设备,使用PROGMEM+pgm_read_xxx没有优势;相反,您只是在编写可移植性较差且难以阅读和维护的代码。相反,请使用香草 C++。

这适用的设备系列是 avrtinyavrxmega3,如 avr-gcc documentation 中所列。