+/EE445L

embedded systems

git clone https://git.julia.blue/+/EE445L

jspspikeGot gpio working054ef41

master
1.6 KiB42 linesraw
1#include "tm4c123gh6pm.h"
2#include <stdint.h>
3
4void (*input_handler)(int alarm, int tedit, int up, int down);
5
6void init_interrupts() {
7    SYSCTL_RCGCGPIO_R |= 0x00000002;
8    GPIO_PORTB_DIR_R &= ~0x0F; // (c) make PF4 in (built-in button)
9    GPIO_PORTB_AFSEL_R &= ~0x0F;      //     disable alt funct on PF4
10    GPIO_PORTB_DEN_R |= 0x0F;         //     enable digital I/O on PF4
11    GPIO_PORTB_PCTL_R &= ~0x0000FFFF; // configure PF4 as GPIO
12    GPIO_PORTB_AMSEL_R = 0;           //     disable analog functionality on PF
13    GPIO_PORTB_PUR_R |= 0x0F;         //     enable weak pull-up on PF4
14    GPIO_PORTB_IS_R &= ~0x0F;         // (d) PF4 is edge-sensitive
15    GPIO_PORTB_IBE_R &= ~0x0F;        //     PF4 is not both edges
16    GPIO_PORTB_IEV_R &= ~0x0F;        //     PF4 falling edge event
17    GPIO_PORTB_ICR_R = 0x0F;          // (e) clear flag4
18    GPIO_PORTB_IM_R |= 0x0F; // (f) arm interrupt on PF4 *** No IME bit as
19                             // mentioned in Book ***
20    NVIC_PRI0_R = (NVIC_PRI0_R & 0xFFFF00FF) | 0x0000A000; // (g) priority 5
21    NVIC_EN0_R |= 0x00000002;
22}
23
24void gpio_portb_handler() {
25    //GPIO_PORTB_ICR_R = 0x0F;
26
27    int alarm = GPIO_PORTB_DATA_R & 0x01;
28    int tedit = GPIO_PORTB_DATA_R & 0x02;
29    int up = GPIO_PORTB_DATA_R & 0x04;
30    int down = GPIO_PORTB_DATA_R & 0x08;
31
32    input_handler(alarm, tedit, up, down);
33}
34
35void init_input(void (*handler)(int, int, int, int)) {
36    //init_interrupts();
37    SYSCTL_RCGCGPIO_R |= 0x00000002;
38    GPIO_PORTB_DIR_R &= ~0x0F;
39    GPIO_PORTB_DEN_R |= 0x0F;
40    GPIO_PORTB_PDR_R |= 0x0F;
41    input_handler = handler;
42}