summaryrefslogtreecommitdiff
path: root/board/it8380dev/board.c
blob: 401a221c4439888d8bb77d94f207e2a4d8073e7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
/* IT8380 development board configuration */

#include "common.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "registers.h"
#include "task.h"
#include "util.h"

/* Test GPIO interrupt function that toggles one LED. */
void test_interrupt(enum gpio_signal signal)
{
	static int busy_state;

	/* toggle LED */
	busy_state = !busy_state;
	gpio_set_level(GPIO_BUSY_LED, busy_state);
}

#include "gpio_list.h"

/* Initialize board. */
static void board_init(void)
{
	gpio_enable_interrupt(GPIO_START_SW);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);

/*****************************************************************************/
/* Console commands */

void display_7seg(uint8_t val)
{
	int i;
	static const uint8_t digits[16] = {
		0xc0, 0xf9, 0xa8, 0xb0,
		0x99, 0x92, 0x82, 0xf8,
		0x80, 0x98, 0x88, 0x83,
		0xc6, 0xa1, 0x86, 0x8e,
	};

	for (i = 0; i < 7; i++)
		gpio_set_level(GPIO_H_LED0 + i, digits[val >> 4] & (1 << i));
	for (i = 0; i < 7; i++)
		gpio_set_level(GPIO_L_LED0 + i, digits[val & 0xf] & (1 << i));
}

static int command_7seg(int argc, char **argv)
{
	uint8_t val;
	char *e;

	if (argc != 2)
		return EC_ERROR_PARAM_COUNT;

	val = strtoi(argv[1], &e, 16);
	if (*e)
		return EC_ERROR_PARAM1;

	ccprintf("display 0x%02x\n", val);
	display_7seg(val);

	return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(seg7, command_7seg,
			"<hex>",
			"Print 8-bit value on 7-segment display",
			NULL);