|
1 | 1 | #define P0 ((struct gpio *) 0x50000000)
|
2 | 2 | #define P1 ((struct gpio *) 0x50000300)
|
3 |
| -#define BUILD_IN_LED_1 13 |
| 3 | + |
| 4 | +#define BUILD_IN_BUTTON_4_PIN 25 |
| 5 | +#define BUILD_IN_BUTTON_3_PIN 24 |
| 6 | +#define BUILD_IN_BUTTON_2_PIN 12 |
| 7 | +#define BUILD_IN_BUTTON_1_PIN 11 |
| 8 | +#define BUILD_IN_LED_1_PIN 13 |
| 9 | +#define BUILD_IN_LED_2_PIN 14 |
| 10 | +#define BUILD_IN_LED_3_PIN 15 |
| 11 | +#define BUILD_IN_LED_4_PIN 16 |
4 | 12 |
|
5 | 13 | enum { GPIO_MODE_INPUT, GPIO_MODE_OUTPUT };
|
6 | 14 | enum { LOW, HIGH };
|
7 | 15 |
|
8 | 16 | struct gpio {
|
9 |
| - volatile uint32_t RESERVED[321], OUT, OUTSET, OUTCLR, IN, DIR, DIRSET, DIRCLR, LATCH, DETECTMODE, PIN_CNF[32]; |
| 17 | + volatile uint32_t RESERVED[321], OUT, OUTSET, OUTCLR, IN, DIR, DIRSET, DIRCLR, LATCH, DETECTMODE, RESERVED_SECOND[118], PIN_CNF[32]; |
10 | 18 | };
|
11 | 19 |
|
12 |
| -void set_gpio_mode(struct gpio * port, int pin, int mode) { |
13 |
| - port->DIR |= mode << pin; |
| 20 | +void set_gpio_mode(struct gpio * port, int pin, int mode, int pull) { |
| 21 | + if (pull == 0) { |
| 22 | + port->PIN_CNF[pin] = mode << 0; |
| 23 | + } |
| 24 | + else { |
| 25 | + port->PIN_CNF[pin] = mode << 0 | pull << 2; |
| 26 | + } |
14 | 27 | }
|
15 | 28 |
|
| 29 | +int gpio_read(struct gpio * port, int pin) { |
| 30 | + uint32_t button = ~(port->IN); |
| 31 | + if (button & (1 << pin)) { |
| 32 | + return 1; |
| 33 | + } |
| 34 | + else { |
| 35 | + return 0; |
| 36 | + } |
| 37 | +} |
16 | 38 | void gpio_write(struct gpio * port, int pin, int value) {
|
17 |
| - if (value == 1) |
18 |
| - port->OUTSET |= 1 << pin; |
19 |
| - else |
20 |
| - port->OUTCLR |= 1 << pin; |
| 39 | + if (value == 0) { |
| 40 | + port->OUTSET = 1 << pin; |
| 41 | + } |
| 42 | + else { |
| 43 | + port->OUTCLR = 1 << pin; |
| 44 | + } |
21 | 45 | }
|
22 | 46 |
|
23 | 47 | static inline void spin(volatile uint32_t count) {
|
|
0 commit comments