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

ref: 02e7e4dfbf77f0e6aac3abd7ab75632233c347e0 stm32h747i-disco-usb-image-viewer/src/exti.c -rw-r--r-- 1.7 KiB
02e7e4df — Rutherther docs: add documentation comments to most functions 5 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
#include <stdint.h>
#include <stdlib.h>

#include "exti.h"
#include "registers.h"
#include "stm32h747xx.h"

exti_t *exti_init(EXTI_TypeDef *exti, SYSCFG_TypeDef *syscfg) {
  exti_t* exti_periph = (exti_t*)malloc(sizeof(exti_t));

  exti_periph->exti = exti;
  exti_periph->syscfg = syscfg;

  return exti_periph;
}

void exti_external_interrupt(exti_t *exti, uint8_t line, uint8_t gpio) {
  // TODOA; general
  uint8_t index = line >> 2;
  uint8_t pos = (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, uint8_t line) {
  reg_write_bits_pos(&exti->exti->RTSR1, 1, line, 1);
  reg_write_bits_pos(&exti->exti->FTSR1, 0, line, 1);
  reg_write_bits_pos(&exti->exti->IMR1, 1, line, 1);
}

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

void exti_disable_interrupt(exti_t *exti, uint8_t line) {
  reg_write_bits_pos(&exti->exti->IMR1, 0, 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_nvic_setup(exti_t *exti, uint8_t line) {
  IRQn_Type idx = exti_irq_idx(line);
  NVIC_SetPriority(idx, 2);
  NVIC_EnableIRQ(idx);
}
Do not follow this link