Skip to content

Does not compile for RP2040 (SREG was not declared) #7

Open

Description

@RenaKunisaki
Arduino: 1.8.19 (Linux), Board: "Raspberry Pi Pico, 2MB (no FS), 120 MHz, Small (-Os) (standard), Disabled, Disabled, Disabled, Disabled, Disabled, None, Adafruit TinyUSB, IPv4 Only, Default (UF2)"

In file included from /home/rena/projects/micros/arduino/ToneGen/ToneGen.ino:4:
/home/rena/Arduino/libraries/BasicEncoder/BasicEncoder.h: In member function 'int8_t BasicEncoder::get_change()':
/home/rena/Arduino/libraries/BasicEncoder/BasicEncoder.h:91:20: error: 'SREG' was not declared in this scope
   91 |     uint8_t sreg = SREG;  // save the current interrupt enable flag
      |                    ^~~~
/home/rena/Arduino/libraries/BasicEncoder/BasicEncoder.h: In member function 'int BasicEncoder::get_count()':
/home/rena/Arduino/libraries/BasicEncoder/BasicEncoder.h:114:20: error: 'SREG' was not declared in this scope
  114 |     uint8_t sreg = SREG;  // save the current interrupt enable flag
      |                    ^~~~
/home/rena/Arduino/libraries/BasicEncoder/BasicEncoder.h: In member function 'void BasicEncoder::reset()':
/home/rena/Arduino/libraries/BasicEncoder/BasicEncoder.h:122:20: error: 'SREG' was not declared in this scope
  122 |     uint8_t sreg = SREG;  // save the current interrupt enable flag
      |                    ^~~~

Activity

  1. micromouseonline commented on Dec 24, 2024

    @micromouseonline
    Owner

    Sorry. The library was only written for the ATmega328 processor to fulfil a particular need.

    I have added a note to the readme. which should probably always have been there.

  2. RenaKunisaki commented on Dec 26, 2024

    @RenaKunisaki
    Author

    It looks like all you need to make it work on any Arduino board is:

    - uint8_t sreg = SREG;
    /* ... function body ... */
    - SREG = sreg;  // restore the previous interrupt enable flag state
    + interrupts();
  3. micromouseonline commented on Dec 26, 2024

    @micromouseonline
    Owner

    SREG is a hardware register on the ATmega328. Here it is used to control the interrupt enable status.

  4. RenaKunisaki commented on Jan 7, 2025

    @RenaKunisaki
    Author

    Just making that change lets it work for me.

  5. micromouseonline commented on Jan 7, 2025

    @micromouseonline
    Owner

    It may appear to work but is likely fail at some point because you would not then be preventing an interrupt while you read the pins. Reading encoders is very time sensitive.

    I would suggest you searcgh for an encoder library that specifically supports the RP2040. This one does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions