~ruther/stm32h747i-disco-usb-image-viewer

ref: d73097e33538bc9b4d5ad1be19e5cba70157f7e4 stm32h747i-disco-usb-image-viewer/firmware/src/exti.c -rw-r--r-- 1.8 KiB
d73097e3 — Rutherther chore: move firmware to firmware/ folder 3 months ago
                                                                                
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
74
75
76
77
78
79
80
#include <stdint.h>
#include <stdlib.h>

#include <stm32h7xx.h>
#include "exti.h"
#include "registers.h"

void exti_init(exti_t* exti, uint8_t line, EXTI_TypeDef *exti_periph, SYSCFG_TypeDef *syscfg) {
  exti->exti = exti_periph;
  exti->syscfg = syscfg;
  exti->line = line;
}

void exti_external_interrupt(exti_t *exti, uint8_t gpio) {
  uint8_t index = exti->line >> 2;
  uint8_t pos = (exti->line & 0x3) * 4;
  volatile uint32_t *exticr = exti->syscfg->EXTICR;
  reg_write_bits_pos(exticr + index, gpio, pos, 0x0F);
}

void exti_rising_interrupt(exti_t *exti) {
  reg_write_bits_pos(&exti->exti->RTSR1, 1, exti->line, 1);
  reg_write_bits_pos(&exti->exti->FTSR1, 0, exti->line, 1);
  reg_write_bits_pos(&exti->exti->IMR1, 1, exti->line, 1);
}

void exti_falling_interrupt(exti_t *exti) {
  reg_write_bits_pos(&exti->exti->FTSR1, 1, exti->line, 1);
  reg_write_bits_pos(&exti->exti->RTSR1, 0, exti->line, 1);
}

void exti_disable_interrupt(exti_t *exti) {
  reg_write_bits_pos(&exti->exti->IMR1, 0, exti->line, 1);
}

IRQn_Type exti_irq_idx(uint8_t line) {
  switch (line) {
  case 0:
    return EXTI0_IRQn;
  case 1:
    return EXTI1_IRQn;
  case 2:
    return EXTI2_IRQn;
  case 3:
    return EXTI3_IRQn;
  case 4:
    return EXTI4_IRQn;
  case 5:
  case 6:
  case 7:
  case 8:
  case 9:
    return EXTI9_5_IRQn;
  case 10:
  case 11:
  case 12:
  case 13:
  case 14:
  case 15:
    return EXTI15_10_IRQn;
  default:
    return -1;
  }
}

void exti_enable_interrupt(exti_t *exti) {
  reg_write_bits_pos(&exti->exti->IMR1, 1, exti->line, 1);

  IRQn_Type idx = exti_irq_idx(exti->line);
  NVIC_SetPriority(idx, 2);
  NVIC_EnableIRQ(idx);
}

uint32_t exti_is_interrupt(exti_t *exti) {
  return exti->exti->PR1 & (EXTI_PR1_PR0 << exti->line);
}

void exti_clear_interrupt(exti_t *exti) {
  exti->exti->PR1 |= (EXTI_PR1_PR0 << exti->line);
}
Do not follow this link