/**
* Controlling the Pi Pico GPIO with direct register access (SIO registers + IO Bank 0 registers)
*
* Code example from the Raspberry Pi Pico Deep Pico - The Deep Dive course:
* https://hackaday.io/course/178733-raspberry-pi-pico-and-rp2040-the-deep-dive
*/
/* Enables the SIO function for the given pin, by writing to the relevant CTRL register.
(e.g. GPIO0_CTRL at 0x40014004) */
void enable_sio(int pin) {
uint32_t *PIN_CTRL_REG = (uint32_t*)IO_BANK0_BASE + pin * 2 + 1;
*PIN_CTRL_REG = 5; // 5 = SIO function
}
void setup() {
// Enable the SIO function for pins GP0 to GP7
for (int i = 0; i < 8; i++) {
enable_sio(i);
}
// Enable output on pins GP0 to GP7:
// sio_hw->gpio_oe points to 0xd0000020 (GPIO_OE)
sio_hw->gpio_oe = 0b11111111;
// Set initial pin pattern
// sio_hw->gpio_out points to 0xd0000010 (GPIO_OUT)
sio_hw->gpio_out = 0b10101010;
}
void loop() {
// sio_hw->gpio_togl points to 0xd000001c (GPIO_OUT_XOR)
sio_hw->gpio_togl = 0b11111111;
delay(1000);
}