aboutsummaryrefslogtreecommitdiff
path: root/fdl/ch573/gpio.fdl
blob: bab481a5e667431309398f0da2067bfd5a862a96 (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import "ch573/common.fdl";

/** Package for */
package ch573.gpio {

  location sys_base = 0x4000_1000;
  location gpio_base = 0x4000_1018;

  location gpio_port_a_base = 0x4000_10A0;
  location gpio_port_b_base = 0x4000_10C0;

  using ch573.common;

  bits pd_drv_t : enum(1) {
    [[ c: unqualified ]]
    PD_DRV_DRIVE = 0,

    [[ c: unqualified ]]
    PD_DRV_OPEN_DRAIN = 1,
  };

  /** Gpio port type. */
  type gpio_port_t : struct {
    /** Port direction register. */
    reg (32) : struct {
       dir : enum(1) {
         [[ c: unqualified ]]
         DIR_OUT = 1,

         [[ c: unqualified ]]
         DIR_IN = 0,
       } [16];
       reserved(16);
    };

    /** Pin input register. */
    reg pin(32) : struct {
      in : bit_t[16];
      reserved(16);
    };

    /** Pin output register. */
    reg (32) : struct {
      out : bit_t[16];
      reserved(16);
    };

    /** Data reset register. */
    reg clr(32);

    /** Pull-up resistor configuration. */
    reg (32) : struct {
      pu : enable_t[16];
      reserved(16);
    };

    /** pull-down/drive configuration register. */
    reg (32) : struct {
      pd_drv : pd_drv_t[16];
      reserved(16);
    };
  };

  /** Gpio Type. */
  type gpio_t : struct {
    /** Function pin remapping register. */
    reg pin_alternate(16) : struct {
      /** 
       * TMR0 function pin mapping selection bit:
       *
       *  1: TMR0_/PWM0_/CAP0_ is mapped to PB[23]
       *  0: TMR0_/PWM0_/CAP0_ is mapped to PA[9]
       */
      rw pin_tmr0 : bit_t;

      /**
       * TMR1 function pin mapping selection bit:
       *
       *  1: TMR1_/PWM1_/CAP1_ is mapped to PB[10];
       *  0: TMR1/PWM1/CAP1 is mapped to PA[10].
       */
      rw pin_tmr1 : bit_t;

      /**
       * TMR2 function pin mapping selection bit:
       *
       *  1: TMR2_/PWM2_/CAP2_ is mapped to PB[11];
       *  0: TMR2/PWM2/CAP2 is mapped to PA[11].
       */
      rw pin_tmr2 : bit_t;

      reserved(1);

      /**
       * UART0 function pin mapping selection bit:
       *
       *  1: RXD0_/TXD0_ is mapped to PA[15]/PA[14];
       *  0: RXD0/TXD0 is mapped to PB[4]/PB[7].
       */
      rw pin_uart0 : bit_t;

      /**
       * UART1 function pin mapping selection bit:
       *
       *  1: RXD1_/TXD1_ is mapped to PB[12]/PB[13];
       *  0: RXD1/TXD1 is mapped to PA[8]/PA[9].
       */
      rw pin_uart1 : bit_t;

      reserved(2);

      /**
       * SPI0 function pin mapping selection bit:
       *
       *  1: SCK0_/SCS_/MOSI_/MISO_ is mapped to PB[12]/PB[13]/PB[14]/PB[15];
       *  0: SCK0/SCS/MOSI/MISO is mapped to PA[12]/PA[13]/PA[14]/PA[15].
       */
      rw pin_spi0 : bit_t;

      reserved(7);

    };

    /** Peripheral analog pin configuration register. */
    reg pin_analog_ie(16) : struct {
      reserved(6);

      pin_usb_dp_pu : bit_t;

      /**
       * USB pin enable:
       *
       *   1: PB10-11 are USB communication pins;
       *   0: PB10-11 are not used for USB communication.
       */
      pin_usb_ie : bit_t;
      
      /**
       * ADC/TKEY 8/9 channel pin digital input disable:
       *
       *   1: Disable PB0/PB6 digital input to save power consumption;
       *   0: Enable digital input.
       */
      pin_adc8_9_ie : bit_t;

      /**
       * ADC/TKEY 0 channel pin digital input disable:
       *
       *   1: Disable PA4 digital input to save power consumption;
       *   0: Enable digital input.
       */
      pin_adc0_ie : bit_t;

      /**
       * ADC/TKEY 1 channel pin digital input disable:
       *
       *   1: Disable PA5 digital input to save power consumption;
       *   0: Enable digital input.
       */
      pin_adc1_ie : bit_t;
      
      /**
       * ADC/TKEY 12 channel pin digital input disable:
       *
       *   1: Disable the PA8 digital input to save power consumption;
       *   0: Enable digital input.
       */
      pin_adc12_ie : bit_t;

      /**
       * ADC/TKEY 13 channel pin digital input disable:
       *
       *   1: Disable PA9 digital input to save power consumption;
       *   0: Enable digital input.
       */
      pin_adc13_ie : bit_t;

      /**
       * 32KHz crystal LSE pin digital input disable:
       *
       *   1: Disable PA10-11 digital input to save power consumption;
       *   0: Enable digital input.
       */
      pin_xt32k_ie : bit_t;

      /**
       * ADC/TKEY 2/3 channel pin digital input disable:
       *
       *   1: Disable PA12-13 digital input to save power consumption;
       *   0: Enable digital input.
       */
      pin_adc2_3_ie : bit_t;

      /**
       * ADC/TKEY 4/5 channel pin digital input disable:
       *
       *   1: Disable PA14-15 digital input to save power consumption;
       *   0: Enable digital input.
       */
      pin_adc4_5_ie : bit_t;
    };

    /** Port A interrupt enable register. */
    reg pa_interrupt_enable(16);

    /** Port B interrupt enable register. */
    reg pb_interrupt_enable(16);

    /** Port A interrupt mode configure register. */
    reg pa_interrupt_mode(16);

    /** Port B interrupt mode configure register. */
    reg pb_interrupt_mode(16);

    /** Port A interrupt flag register. */
    reg pa_interrupt_flag(16);

    /** Port B interrupt flag register. */
    reg pb_interrupt_flag(16);
  };

  instance gpio at gpio_base : gpio_t;
  instance gpio_port_a at gpio_port_a_base : gpio_port_t;
  instance gpio_port_b at gpio_port_b_base : gpio_port_t;
};