2010-08-13 14:46:38 +03:00
|
|
|
/*
|
|
|
|
* f32x/gpio.h - Really primitive S3C244x GPIO access. Ports B-H only.
|
|
|
|
*
|
|
|
|
* Written 2008 by Werner Almesberger
|
|
|
|
* Copyright 2008 Werner Almesberger
|
|
|
|
*
|
|
|
|
* 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ports are numbered 0 = A, 1 = B, ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GPIO_H
|
|
|
|
#define GPIO_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
|
|
volatile uint32_t *mem;
|
|
|
|
|
|
|
|
|
|
|
|
#define port_dat(port) mem[port*4+1]
|
|
|
|
#define port_con(port) mem[port*4]
|
|
|
|
|
|
|
|
|
|
|
|
static inline void gpio_high(unsigned port, unsigned bit)
|
|
|
|
{
|
2010-10-21 16:05:26 +03:00
|
|
|
port_dat(port) |= 1 << bit;
|
2010-08-13 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void gpio_low(unsigned port, unsigned bit)
|
|
|
|
{
|
2010-10-21 16:05:26 +03:00
|
|
|
port_dat(port) &= ~(1 << bit);
|
2010-08-13 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void gpio_set(unsigned port, unsigned bit, int value)
|
|
|
|
{
|
2010-10-21 16:05:26 +03:00
|
|
|
if (value)
|
|
|
|
gpio_high(port, bit);
|
|
|
|
else
|
|
|
|
gpio_low(port, bit);
|
2010-08-13 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int gpio_get(unsigned port, unsigned bit)
|
|
|
|
{
|
2010-10-21 16:05:26 +03:00
|
|
|
return (port_dat(port) >> bit) & 1;
|
2010-08-13 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void gpio_output(unsigned port, unsigned bit)
|
|
|
|
{
|
2010-10-21 16:05:26 +03:00
|
|
|
port_con(port) = (port_con(port) & ~(3 << bit*2)) | (1 << bit*2);
|
2010-08-13 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void gpio_input(unsigned port, unsigned bit)
|
|
|
|
{
|
2010-10-21 16:05:26 +03:00
|
|
|
port_con(port) &= ~(3 << bit*2);
|
2010-08-13 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gpio_init(void);
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* !GPIO_H */
|