-
Notifications
You must be signed in to change notification settings - Fork 0
/
nand-core.c
53 lines (47 loc) · 940 Bytes
/
nand-core.c
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
/*
* Copyright (C) 2023 Gijun Oh
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#include <stdio.h>
#include "nand.h"
#include "nand-utils.h"
int nand_init(void)
{
int i;
if (wiringPiSetup() == -1) {
return 1;
}
// configure the command pins
for (i = 21; i < 28; i++) {
if (i == NAND_R_B) {
pinMode(i, INPUT);
} else {
pinMode(i, OUTPUT);
if (i == NAND_CE || i == NAND_RE || i == NAND_WE ||
i == NAND_WP) {
nand_digital_write(i, 1);
} else {
nand_digital_write(i, 0);
}
}
}
// configure the data pins
for (i = 0; i < 8; i++) {
pinMode(i, OUTPUT);
nand_digital_write(i, 0);
}
nand_enable_chip();
#ifdef NAND_ENABLE_RESET
// reset the chip
nand_send_command(0xff);
nand_wait_busy();
#endif
return 0;
}
void nand_free(void)
{
nand_disable_chip();
}