Raspberry Pi GPIO support ========================= RISC OS note: Under RISC OS, the GPIO module provides support in the GPIO_ namespace, the RaspberryPi_ namespace is not supported. In keeping with the BBC Micro style of I/O ports being memory-mapped, if Brandy is able to open /dev/gpiomem for read-write, then it'll mmap() it, and the following code can be used to test whether it's available, and if so, where. SYS "RaspberryPi_GPIOInfo" TO present%,gpiomem% If /dev/gpiomem is available and usable, present% will be set to 1, and gpiomem% set to the base of memory as addressed within Brandy. Otherwise, present% will be set to 0, and gpiomem% to &FFFFFFFF. This will happen every time Matrix Brandy is started. With the exception of the above SYS call, all the other GPIO calls report the error "Raspberry Pi GPIO not available" if present% is 0 (and it wasn't called as an X call). The remaining SYS calls all take the GPIO port number in R0 and the parameter, if required, in R1. Those that return a value do so in R0. The other GPIO calls are: RaspberryPi_GetGPIOPortMode: R0=port Returns a value from 0 to 7: 0: Input 1: Output 2: ALT5 3: ALT4 4: ALT0 5: ALT1 6: ALT2 7: ALT3 RaspberryPi_SetGPIOPortMode: R0=port, R1=mode (as above). RaspberryPi_SetGPIOPortPullUpDownMode: R0=port, R1=mode 0: Off 1: Down 2: Up RaspberryPi_ReadGPIOPort: R0=port. Value returned in R0. RaspberryPi_WriteGPIOPort: R0=port, R1=value As an alternative to the SYS calls, a slightly modified version of BBCSDL's gpiolib.bbc by Richard Russell should also work, with the following change: Replace FN_gpio_setup with the following: DEF FN_gpio_setup LOCAL present% SYS "RaspberryPi_GPIOInfo" TO present%,G% IF present%=0 THEN ERROR 0, "GPIO not present or usable" = G% Also - SOME SWIs from the RISC OS GPIO module are implemented. At this point, the following are: GPIO_GetBoard Returns board model code local to the module in R0, the board type string in R1 and additionally, local to Brandy, the 32-bit model code from /proc/cpuinfo into R2. GPIO_ReadMode: mapped to RaspberryPi_GetGPIOPortMode GPIO_WriteMode: mapped to RaspberryPi_SetGPIOPortMode GPIO_ReadData: mapped to RaspberryPi_ReadGPIOPort GPIO_WriteData: mapped to RaspberryPi_WriteGPIOPort