62 lines
1.2 KiB
C
62 lines
1.2 KiB
C
|
/*! \file gpio.c
|
||
|
* \author tkl
|
||
|
* \date Feb 13, 2012
|
||
|
* \brief Source file of the architecture independent gpio driver.
|
||
|
*/
|
||
|
#include <stddef.h>
|
||
|
#include "gpio.h"
|
||
|
|
||
|
int gpio_open(const struct gpio *device)
|
||
|
{
|
||
|
if(device == NULL)
|
||
|
return -1;
|
||
|
|
||
|
gpio_fp_open_t open = device->fp->open;
|
||
|
return open(device->arch_dep_device);
|
||
|
}
|
||
|
|
||
|
int gpio_close(const struct gpio *device)
|
||
|
{
|
||
|
if(device == NULL)
|
||
|
return -1;
|
||
|
|
||
|
gpio_fp_close_t close = device->fp->close;
|
||
|
return close(device->arch_dep_device);
|
||
|
}
|
||
|
|
||
|
char gpio_read(const struct gpio *device)
|
||
|
{
|
||
|
if(device == NULL)
|
||
|
return 0;
|
||
|
|
||
|
gpio_fp_read_t read = device->fp->read;
|
||
|
return read(device->arch_dep_device);
|
||
|
}
|
||
|
|
||
|
void gpio_write(const struct gpio *device, char byte)
|
||
|
{
|
||
|
if(device == NULL)
|
||
|
return;
|
||
|
|
||
|
gpio_fp_write_t write = device->fp->write;
|
||
|
write(device->arch_dep_device, byte);
|
||
|
}
|
||
|
|
||
|
void gpio_toggle(const struct gpio *device) {
|
||
|
if(device == NULL)
|
||
|
return;
|
||
|
|
||
|
gpio_fp_toggle_t toggle = device->fp->toggle;
|
||
|
toggle(device->arch_dep_device);
|
||
|
}
|
||
|
|
||
|
int gpio_set_exti_callback(const struct gpio *device, const void *callback,
|
||
|
const void *param)
|
||
|
{
|
||
|
if((device == NULL) || (callback == NULL))
|
||
|
return -1;
|
||
|
|
||
|
gpio_fp_set_cb_t set_cb = device->fp->set_cb;
|
||
|
return set_cb(device->arch_dep_device, callback, param);
|
||
|
}
|