please choosego to mobile | Continue to access the PC version
View: 4205|Reply: 1

Alternative to WiringPi GPIO programming for 2G-IOT and i96 OPi boards.

[Copy link]

1

threads

10

posts

59

credits

Registered member

Rank: 2

credits
59
Published in 2021-4-26 20:53:23 | Show all floors |Read mode
Edited by vaton at 2021-4-28 06:10

I have found a nice descriptoin of the direct GPIO programming in this article:
  https://titanwolf.org/Network/Ar ... 23c7a4b31#gsc.tab=0 (Make full use of Orange Pi 2G-IOT GPIO).

Needed some investigation, but seems to work.

Essential is this code:

#define RDA_CONFIG_REGS 0x11a09000
volatile struct config_regs {
  uint32_t chip_id;
  uint32_t build_version;
  uint32_t bb_gpio_mode;       // enable/disable GPIO_C
  uint32_t ap_gpioa_mode;     // enable/disable GPIO_A
  uint32_t ap_gpiob_mode;     // enable/disable GPIO_B
  uint32_t ap_gpiod_mode;     // enable/disable GPIO_D
}* cfg;

#define GPIOA_BASE 0x20930000
volatile struct pio_cfg {
  uint32_t oen_val;           // read/write mode register
  uint32_t oen_set_out;    // set GPIO(s) to OUT mode
  uint32_t oen_set_in;      // set GPIO(s) to IN mode
  uint32_t val;                 // read/write data register
  uint32_t set;                 // set output(s) HIGH
  uint32_t clr;                  // set output(s) LOW
}* pa;

int main(int argc, char** argv) {
  int mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
  if (mem_fd < 0) {
    perror("can not open/dev/mem");
    exit(EXIT_FAILURE);
  }

  int prot = PROT_READ | PROT_WRITE;
  size_t size = sysconf(_SC_PAGE_SIZE);

  cfg = mmap(NULL, size, prot, MAP_SHARED, mem_fd, RDA_CONFIG_REGS);
  cfg->ap_gpioa_mode |= (1 << 14) | (1 << 15);      // Enable GPIO A14 and GPIO_A15

  pa = mmap(NULL, size, prot, MAP_SHARED, mem_fd, GPIOA_BASE);
  pa->oen_set_out = 1 << 15;        // Setup GPIO A15 as output pin
  pa->clr = 1 << 15;                      // Drive GPIO A15 = LOW
  sleep(1);
  pa->set = 1 << 15;                     // Drive GPIO A15 = HIGH
  return 0;
}

Mising base addresses I have found in the kernel sources (file iomap-rda8810.h):

GPIOC_BASE    0x11A08000
GPIOA_BASE    0x20930000
GPIOB_BASE    0x20931000
GPIOD_BASE    0x20932000

For interrupt and peripherals programming, you will find very handy the full (126 pages) RDA8810 datasheet here:
https://github.com/Testato/IOTph ... Processor.V1.04.pdf .

It is the only full version I have found on internet. Others are preliminary, i.e., almost useless.

It is still unclear whether the same control method as for GPIOA set can be used also for other GPIO sets. I expect it can, just need to check it.

This method allows using as GPIO almost any pin except power, even those on camera connector. Just remember that many GPIO pins have other system functions. Be careful and if you are not sure you can use some pin as GPIO, do not do it. Secure is using just pins marked on the EXPORT header as GPIO. So, you have been warned ........



1

threads

679

posts

1787

credits

Gold member

Rank: 6Rank: 6

credits
1787
Published in 2024-4-7 18:28:57 | Show all floors
Appreciate it intended for giving new messages the matter, When i count on understand far more.        CNPR Pharmaceutical Sales
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list