Statistics
| Branch: | Tag: | Revision:

amiro-os / devices / DiWheelDrive / exti.cpp @ dd47d655

History | View | Annotate | Download (2.39 KB)

1
#include <ch.hpp>
2
#include <hal.h>
3

    
4
#include <board.h>
5

    
6
#include "exti.hpp"
7

    
8
volatile uint32_t shutdown_now = 0x00000000u; // = BL_SHUTDOWN_NONE in main.cpp
9

    
10
EXTConfig extcfg = {
11

    
12
  {
13
    /* channel 0 */
14
    {
15
      /* mode */ EXT_CH_MODE_DISABLED,
16
      /* cb   */ NULL,
17
    },
18
    /* channel 1 */
19
    {
20
      /* mode */ EXT_CH_MODE_DISABLED,
21
      /* cb   */ NULL,
22
    },
23
    /* channel 2 */
24
    {
25
      /* mode */ EXT_CH_MODE_DISABLED,
26
      /* cb   */ NULL,
27
    },
28
    /* channel 3 */
29
    {
30
      /* mode */ EXT_CH_MODE_DISABLED,
31
      /* cb   */ NULL,
32
    },
33
    /* channel 4 */
34
    {
35
      /* mode */ EXT_CH_MODE_DISABLED,
36
      /* cb   */ NULL,
37
    },
38
    /* channel 5 */
39
    {
40
      /* mode */ EXT_CH_MODE_DISABLED,
41
      /* cb   */ NULL,
42
    },
43
    /* channel 6 */
44
    {
45
      /* mode */ EXT_CH_MODE_DISABLED,
46
      /* cb   */ NULL,
47
    },
48
    /* channel 7 */
49
    {
50
      /* mode */ EXT_CH_MODE_DISABLED,
51
      /* cb   */ NULL,
52
    },
53
    /* channel 8 */
54
    {
55
      /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_AUTOSTART | EXT_CH_MODE_FALLING_EDGE,
56
      /* cb   */ power_down_cb,
57
    },
58
    /* channel 9 */
59
    {
60
      /* mode */ EXT_CH_MODE_DISABLED,
61
      /* cb   */ NULL,
62
    },
63
    /* channel 10 */
64
    {
65
      /* mode */ EXT_CH_MODE_DISABLED,
66
      /* cb   */ NULL,
67
    },
68
    /* channel 11 */
69
    {
70
      /* mode */ EXT_CH_MODE_DISABLED,
71
      /* cb   */ NULL,
72
    },
73
    /* channel 12 */
74
    {
75
      /* mode */ EXT_CH_MODE_DISABLED,
76
      /* cb   */ NULL,
77
    },
78
    /* channel 13 */
79
    {
80
      /* mode */ EXT_CH_MODE_DISABLED,
81
      /* cb   */ NULL,
82
    },
83
    /* channel 14 */
84
    {
85
      /* mode */ EXT_CH_MODE_DISABLED,
86
      /* cb   */ NULL,
87
    },
88
    /* channel 15 */
89
    {
90
      /* mode */ EXT_CH_MODE_DISABLED,
91
      /* cb   */ NULL,
92
    },
93
    /* channel 16 */
94
    {
95
      /* mode */ EXT_CH_MODE_DISABLED,
96
      /* cb   */ NULL,
97
    },
98
    /* channel 17 */
99
    {
100
      /* mode */ EXT_CH_MODE_DISABLED,
101
      /* cb   */ NULL,
102
    },
103
    /* channel 18 */
104
    {
105
      /* mode */ EXT_CH_MODE_DISABLED,
106
      /* cb   */ NULL,
107
    },
108
  }
109
};
110

    
111
void power_down_cb(EXTDriver *extp, expchannel_t channel) {
112

    
113
  (void) extp;
114
  (void) channel;
115
  // make sure we don't accidentally power down when somebody tries to wake us
116
  if (!palReadPad(GPIOC, GPIOC_SYS_PD_N))
117
    palWritePad(GPIOC, GPIOC_SYS_INT_N, PAL_LOW); // indicate that the module needs some time to shut down
118
    shutdown_now = 5; // = SHUTDOWN_HANDLE_REQUEST in main.cpp
119
}