|
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 ........
|
|