File: [local] / funnyos / arch / sam7s64 / dev / gpioled.c (download)
Revision 1.5, Sun Dec 16 23:10:08 2007 UTC (16 years, 5 months ago) by nbrk
Branch: MAIN
CVS Tags: HEAD Changes since 1.4: +38 -10 lines
make 'gpioled' provide devctl for manipulating its LEDs.
|
/*
* $Id: gpioled.c,v 1.5 2007/12/16 23:10:08 nbrk Exp $
*/
#include <sys/types.h>
#include <sys/device.h>
#include <sys/gpio.h>
#include <sys/devctl.h>
#include <arch/sam7s64/dev/gpioledvar.h>
#include <libkern/printf.h>
/*
* GPIO LED found on my SAM7-P64 development board.
*/
int gpioled_attach(struct device *, uint32_t, uint8_t);
int gpioled_devctl(struct device *self, uint32_t ctlcmd, void *ctldata);
struct driver gpioled_dr = {
sizeof(struct gpioled_dd),
gpioled_attach,
NULL,
NULL
};
int
gpioled_attach(struct device *self, uint32_t loc, uint8_t flags)
{
struct gpioled_dd *ddp = self->dv_devdata;
/* grab parent's gpio_controller */
ddp->gld_gcp = self->dv_parent->dv_aux;
ddp->gld_pin.gp_pinno = loc; /* PA17 or PA18 please */
ddp->gld_pin.gp_pio = 1; /* PIO mode */
ddp->gld_pin.gp_flags = GPIO_PIN_OUTPUT;
ddp->gld_pin.gp_value = 0; /* LED on */
printf("p64 onboard LED (pio pin %d)\n", ddp->gld_pin.gp_pinno);
/* talk to gpio controller */
ddp->gld_gcp->gc_pinset(ddp->gld_gcp->gc_selfdd, ddp->gld_pin);
devctl_register(self, gpioled_devctl);
return(0);
}
int
gpioled_devctl(struct device *self, uint32_t ctlcmd, void *ctldata)
{
struct gpioled_dd *ddp;
ddp = self->dv_devdata;
switch(ctlcmd) {
case(DCGPIOLED_TOGGLE):
/* toggle LED */
ddp->gld_pin.gp_value = ~ddp->gld_pin.gp_value & 0x01;
/* update us using our gpio controller */
ddp->gld_gcp->gc_pinset(ddp->gld_gcp->gc_selfdd, ddp->gld_pin);
default:
break;
}
return(0);
}