mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-08-21 12:44:37 +03:00
77 lines
2.2 KiB
COBOL
77 lines
2.2 KiB
COBOL
#pypp 0
|
|
#include "kernel.hh"
|
|
|
|
#define REG32(addr) *((volatile unsigned int *)(addr))
|
|
|
|
#define GPIO_BASE 0xB0010000
|
|
|
|
#define __gpio_port_data(p) ( REG_GPIO_GPDR(p) )
|
|
|
|
#define GPIO_GPSLR(n) (GPIO_BASE + (0x10 + (n)*0x30))
|
|
#define GPIO_GPSUR(n) (GPIO_BASE + (0x14 + (n)*0x30))
|
|
#define GPIO_GPFLR(n) (GPIO_BASE + (0x18 + (n)*0x30))
|
|
#define GPIO_GPFUR(n) (GPIO_BASE + (0x1c + (n)*0x30))
|
|
|
|
#define GPIO_GPDR(n) (GPIO_BASE + (0x00 + (n)*0x30))
|
|
|
|
#define REG_GPIO_GPSLR(n) REG32(GPIO_GPSLR((n)))
|
|
#define REG_GPIO_GPSUR(n) REG32(GPIO_GPSUR((n)))
|
|
#define REG_GPIO_GPFLR(n) REG32(GPIO_GPFLR((n)))
|
|
#define REG_GPIO_GPFUR(n) REG32(GPIO_GPFUR((n)))
|
|
|
|
#define REG_GPIO_GPDR(n) REG32(GPIO_GPDR((n)))
|
|
|
|
static void __gpio_port_as_gpiofn (unsigned p, unsigned o, unsigned fn):
|
|
unsigned int tmp;
|
|
if o < 16:
|
|
tmp = REG_GPIO_GPSLR(p)
|
|
tmp &= ~(3 << ((o) << 1))
|
|
REG_GPIO_GPSLR(p) = tmp
|
|
tmp = REG_GPIO_GPFLR(p)
|
|
tmp &= ~(3 << ((o) << 1))
|
|
tmp |= fn << ((o) << 1)
|
|
REG_GPIO_GPFLR(p) = tmp
|
|
else:
|
|
tmp = REG_GPIO_GPSUR(p)
|
|
tmp &= ~(3 << (((o) - 16) << 1))
|
|
REG_GPIO_GPSUR(p) = tmp
|
|
tmp = REG_GPIO_GPFUR(p)
|
|
tmp &= ~(3 << (((o) - 16) << 1))
|
|
tmp |= fn << (((o) - 16) << 1)
|
|
REG_GPIO_GPFUR(p) = tmp
|
|
|
|
static void __gpio_port_as_output (unsigned p, unsigned o):
|
|
__gpio_port_as_gpiofn (p, o, 1)
|
|
static void __gpio_port_as_input (unsigned p, unsigned o):
|
|
__gpio_port_as_gpiofn (p, o, 0)
|
|
static void __gpio_as_output (unsigned n):
|
|
__gpio_port_as_output(n / 32, n % 32)
|
|
static void __gpio_as_input (unsigned n):
|
|
__gpio_port_as_input(n / 32, n % 32)
|
|
static void __gpio_set_pin (unsigned n):
|
|
__gpio_port_data (n / 32) |= (1 << (n % 32))
|
|
static void __gpio_clear_pin (unsigned n):
|
|
__gpio_port_data (n / 32) &= ~(1 << (n % 32))
|
|
|
|
#define CAPSLOCKLED_IO 27
|
|
#define NUMLOCKLED_IO 86
|
|
#define NETWORK_IO 9
|
|
#define LIGHT 105
|
|
|
|
void led (bool one, bool two, bool three):
|
|
__gpio_as_output (CAPSLOCKLED_IO)
|
|
__gpio_as_output (NUMLOCKLED_IO)
|
|
__gpio_as_output (NETWORK_IO)
|
|
if one:
|
|
__gpio_clear_pin (NUMLOCKLED_IO)
|
|
else:
|
|
__gpio_set_pin (NUMLOCKLED_IO)
|
|
if two:
|
|
__gpio_clear_pin (CAPSLOCKLED_IO)
|
|
else:
|
|
__gpio_set_pin (CAPSLOCKLED_IO)
|
|
if three:
|
|
__gpio_clear_pin (NETWORK_IO)
|
|
else:
|
|
__gpio_set_pin (NETWORK_IO)
|