/*
* This file is part of open_agb_firm
* Copyright (C) 2021 derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "types.h"
#include "arm11/drivers/gpio.h"
#define GPIO_EDGE_FALLING (0u)
#define GPIO_EDGE_RISING (1u<<1)
#define GPIO_IRQ_ENABLE (1u<<2)
static vu16 *const g_datRegs[5] = {(vu16*)®_GPIO1_DAT, (vu16*)®_GPIO2_DAT,
®_GPIO2_DAT2, ®_GPIO3_DAT, ®_GPIO3_DAT2};
void GPIO_config(Gpio gpio, u8 cfg)
{
const u8 regIdx = gpio & 7u;
const u8 pinNum = gpio>>3;
// GPIO1 and GPIO3_DAT2 are not configurable.
if(regIdx == 1)
{
u32 reg = REG_GPIO2 & ~((1u<<24 | 1u<<16 | 1u<<8)<>3;
if(regIdx > 4) return 0;
return *g_datRegs[regIdx]>>pinNum & 1u;
}
void GPIO_write(Gpio gpio, u8 val)
{
const u8 regIdx = gpio & 7u;
const u8 pinNum = gpio>>3;
if(regIdx == 0 || regIdx > 4) return;
u16 tmp = *g_datRegs[regIdx];
tmp = (tmp & ~(1u<