1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-16 18:13:49 +01:00

Merge pull request #9296 from maribu/lpc2387

cpu/lpc2387: Various fixes for GPIO driver
This commit is contained in:
Andreas "Paul" Pauli 2018-06-21 19:28:53 +02:00 committed by GitHub
commit 1aaeecf5b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 25 deletions

View File

@ -39,12 +39,22 @@ extern "C" {
* @brief Fast GPIO register definition struct * @brief Fast GPIO register definition struct
*/ */
typedef struct { typedef struct {
__IO uint32_t DIR; /**< he */ /** @brief Direction: Output if corresponding bit is set, otherwise input */
uint32_t _reserved[3]; /**< really */ __IO uint32_t DIR;
__IO uint32_t MASK; /**< wants */ /** @brief 12 bytes of reseved memory we don't need to access */
__IO uint32_t PIN; /**< to */ uint32_t _reserved[3];
__IO uint32_t SET; /**< know */ /** @brief Set bits to ignore corresponding bits when accessing `PIN`, `SET`
__IO uint32_t CLR; /**< everything */ * or `CLR` register of this port
*/
__IO uint32_t MASK;
/** @brief The current state of each pin of this port is accessible here
* (regardless of direction): If bit is set input is high
*/
__IO uint32_t PIN;
/** @brief Output pins are set to high by setting the corresponding bit */
__IO uint32_t SET;
/** @brief Output pins are set to low by setting the corresponding bit */
__IO uint32_t CLR;
} FIO_PORT_t; } FIO_PORT_t;
#define FIO_PORTS ((FIO_PORT_t*)FIO_BASE_ADDR) #define FIO_PORTS ((FIO_PORT_t*)FIO_BASE_ADDR)
@ -54,7 +64,7 @@ typedef struct {
int gpio_init_mux(unsigned pin, unsigned mux); int gpio_init_mux(unsigned pin, unsigned mux);
void gpio_init_states(void); void gpio_init_states(void);
#define GPIO_PIN(port, pin) (port*32 + pin) #define GPIO_PIN(port, pin) (port<<5 | pin)
#ifndef DOXYGEN #ifndef DOXYGEN
#define HAVE_GPIO_FLANK_T #define HAVE_GPIO_FLANK_T

View File

@ -67,18 +67,19 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
{ {
unsigned _pin = pin & 31; unsigned _pin = pin & 31;
unsigned port = pin >> 5; unsigned port = pin >> 5;
if (mode != GPIO_OUT) {
return -1;
}
FIO_PORT_t *_port = &FIO_PORTS[port]; FIO_PORT_t *_port = &FIO_PORTS[port];
/* set mask */
_port->MASK = ~(0x1<<_pin);
/* set direction */ /* set direction */
_port->DIR = ~0; switch (mode){
case GPIO_OUT:
_port->DIR |= 1<<_pin;
break;
case GPIO_IN:
_port->DIR &= ~(1<<_pin);
break;
default:
return -1;
}
gpio_init_mux(pin, 0); gpio_init_mux(pin, 0);
@ -88,13 +89,13 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
int gpio_init_mux(unsigned pin, unsigned mux) int gpio_init_mux(unsigned pin, unsigned mux)
{ {
(void) mux; (void) mux;
unsigned _pin = pin & 31; unsigned pos = (pin & 0xf) << 1;
PINSEL[pin>>4] &= ~(0x1 << (_pin*2)); PINSEL[pin>>4] &= ~(0x3 << pos);
return 0; return 0;
} }
int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
gpio_cb_t cb, void *arg) gpio_cb_t cb, void *arg)
{ {
(void)mode; (void)mode;
@ -222,8 +223,7 @@ int gpio_read(gpio_t pin)
unsigned _pin = pin & 31; unsigned _pin = pin & 31;
unsigned port = pin >> 5; unsigned port = pin >> 5;
FIO_PORT_t *_port = &FIO_PORTS[port]; FIO_PORT_t *_port = &FIO_PORTS[port];
_port->MASK = ~(1<<_pin); return (_port->PIN & (1 << _pin)) != 0;
return _port->PIN != 0;
} }
void gpio_set(gpio_t pin) void gpio_set(gpio_t pin)
@ -231,8 +231,7 @@ void gpio_set(gpio_t pin)
unsigned _pin = pin & 31; unsigned _pin = pin & 31;
unsigned port = pin >> 5; unsigned port = pin >> 5;
FIO_PORT_t *_port = &FIO_PORTS[port]; FIO_PORT_t *_port = &FIO_PORTS[port];
_port->MASK = ~(1<<_pin); _port->SET = 1 << _pin;
_port->SET = ~0;
} }
void gpio_clear(gpio_t pin) void gpio_clear(gpio_t pin)
@ -240,8 +239,7 @@ void gpio_clear(gpio_t pin)
unsigned _pin = pin & 31; unsigned _pin = pin & 31;
unsigned port = pin >> 5; unsigned port = pin >> 5;
FIO_PORT_t *_port = &FIO_PORTS[port]; FIO_PORT_t *_port = &FIO_PORTS[port];
_port->MASK = ~(1<<_pin); _port->CLR = 1 << _pin;
_port->CLR = ~0;
} }
void gpio_toggle(gpio_t dev) void gpio_toggle(gpio_t dev)