add LED control function

Command-line to turn LEDs on the board on or off.

Also, modified .gitignore to be emacs-friendly.
This commit is contained in:
bunnie 2014-09-15 04:57:19 +00:00
parent 5f181600c9
commit 49c2130545
5 changed files with 49 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/build /build
*.swp *.swp
*.swo *.swo
*~

View file

@ -16,6 +16,7 @@ SRC_C = \
cmd-reboot.c \ cmd-reboot.c \
cmd-sleep.c \ cmd-sleep.c \
cmd-spi.c \ cmd-spi.c \
cmd-led.c \
emi.c \ emi.c \
irq.c \ irq.c \
main.c \ main.c \

27
cmd-led.c Normal file
View file

@ -0,0 +1,27 @@
#include <string.h>
#include "bionic.h"
#include "memio.h"
#include "printf.h"
#include "serial.h"
#include "fernvale-kbd.h"
int cmd_led(int argc, char **argv)
{
uint32_t state;
if (argc < 1) {
printf("Usage: led [1 = on, 0 = off]\n");
return -1;
}
state = _strtoul(argv[0], NULL, 0);
if( state ) {
*((volatile uint32_t *) BIG_LED_ADDR) = BIG_LED_ON;
} else {
*((volatile uint32_t *) BIG_LED_ADDR) = BIG_LED_OFF;
}
return 0;
}

14
include/fernvale-kbd.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef __FV_KBD_H__
#define __FV_KBD_H__
/// The BIG_LED is a 60mA drive-capable open-drain switch
/// it's useful for driving circuits such as an array of LEDs
/// used to illuminate a keyboard, hence its inclusion in the
/// keyboard section. However, on PCBs with no keyboard, it's
/// simply a big LED driver.
#define BIG_LED_ADDR (0xA0700000 + 0x0C80)
#define BIG_LED_ON (0x3)
#define BIG_LED_OFF (0x0)
#endif /* __FV_KBD_H__ */

6
main.c
View file

@ -339,6 +339,7 @@ extern int cmd_poke(int argc, char **argv);
extern int cmd_spi(int argc, char **argv); extern int cmd_spi(int argc, char **argv);
extern int cmd_swi(int argc, char **argv); extern int cmd_swi(int argc, char **argv);
extern int cmd_reboot(int argc, char **argv); extern int cmd_reboot(int argc, char **argv);
extern int cmd_led(int argc, char **argv);
static const struct { static const struct {
int (*func)(int argc, char **argv); int (*func)(int argc, char **argv);
@ -390,6 +391,11 @@ static const struct {
.name = "swi", .name = "swi",
.help = "Generate software interrupt", .help = "Generate software interrupt",
}, },
{
.func = cmd_led,
.name = "led",
.help = "Turn the on-board LED on or off",
},
}; };
int cmd_help(int argc, char **argv) int cmd_help(int argc, char **argv)