summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/arm_atsam/d51_util.h
blob: 7a35f7989f7c88ddb2beae296321fb52781f8190 (plain)
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
/*
Copyright 2018 Massdrop Inc.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _D51_UTIL_H_
#define _D51_UTIL_H_

#include "samd51j18a.h"

//TODO: PS: Should bring these ports out to keyboard level configuration

//Debug LED PA27
#define led_ena REG_PORT_DIRSET0 = 0x08000000 //PA27 Output
#define led_on  REG_PORT_OUTSET0 = 0x08000000 //PA27 High
#define led_off REG_PORT_OUTCLR0 = 0x08000000 //PA27 Low

//Debug Port PB30
#define m15_ena REG_PORT_DIRSET1 = 0x40000000 //PB30 Output
#define m15_on  REG_PORT_OUTSET1 = 0x40000000 //PB30 High
#define m15_off REG_PORT_OUTCLR1 = 0x40000000 //PB30 Low

//Debug Port PB23
#define m27_ena REG_PORT_DIRSET1 = 0x800000 //PB23 Output
#define m27_on  REG_PORT_OUTSET1 = 0x800000 //PB23 High
#define m27_off REG_PORT_OUTCLR1 = 0x800000 //PB23 Low

//Debug Port PB31
#define m28_ena REG_PORT_DIRSET1 = 0x80000000 //PB31 Output
#define m28_on  REG_PORT_OUTSET1 = 0x80000000 //PB31 High
#define m28_off REG_PORT_OUTCLR1 = 0x80000000 //PB31 Low

#define m15_loop(M15X) {uint8_t M15L=M15X; while(M15L--){m15_on;CLK_delay_us(1);m15_off;}}

void m15_print(uint32_t x);
void dled_print(uint32_t x, uint8_t long_pause);

void debug_code_init(void);
void debug_code_disable(void);

#ifdef DEBUG_BOOT_TRACING

#define DBGC(n) debug_code = n

extern volatile uint32_t debug_code;

enum debug_code_list {
    DC_UNSET = 0,
    DC_CLK_INIT_BEGIN,
    DC_CLK_INIT_COMPLETE,
    DC_CLK_SET_I2C1_FREQ_BEGIN,
    DC_CLK_SET_I2C1_FREQ_COMPLETE,
    DC_CLK_SET_I2C0_FREQ_BEGIN,
    DC_CLK_SET_I2C0_FREQ_COMPLETE,
    DC_CLK_SET_SPI_FREQ_BEGIN,
    DC_CLK_SET_SPI_FREQ_COMPLETE,
    DC_CLK_ENABLE_TIMEBASE_BEGIN,
    DC_CLK_ENABLE_TIMEBASE_SYNC_ENABLE,
    DC_CLK_ENABLE_TIMEBASE_SYNC_SWRST_1,
    DC_CLK_ENABLE_TIMEBASE_SYNC_SWRST_2,
    DC_CLK_ENABLE_TIMEBASE_TC4_BEGIN,
    DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_DISABLE,
    DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_1,
    DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_SWRST_2,
    DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CLTRB,
    DC_CLK_ENABLE_TIMEBASE_TC4_SYNC_CC0,
    DC_CLK_ENABLE_TIMEBASE_TC4_COMPLETE,
    DC_CLK_ENABLE_TIMEBASE_TC5_BEGIN,
    DC_CLK_ENABLE_TIMEBASE_TC5_SYNC_DISABLE,
    DC_CLK_ENABLE_TIMEBASE_TC5_SYNC_SWRST_1,
    DC_CLK_ENABLE_TIMEBASE_TC5_SYNC_SWRST_2,
    DC_CLK_ENABLE_TIMEBASE_TC5_SYNC_CLTRB,
    DC_CLK_ENABLE_TIMEBASE_TC5_COMPLETE,
    DC_CLK_ENABLE_TIMEBASE_TC0_BEGIN,
    DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_DISABLE,
    DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_1,
    DC_CLK_ENABLE_TIMEBASE_TC0_SYNC_SWRST_2,
    DC_CLK_ENABLE_TIMEBASE_TC0_COMPLETE,
    DC_CLK_ENABLE_TIMEBASE_EVSYS_BEGIN,
    DC_CLK_ENABLE_TIMEBASE_EVSYS_COMPLETE,
    DC_CLK_ENABLE_TIMEBASE_COMPLETE,
    DC_CLK_SET_GCLK_FREQ_BEGIN,
    DC_CLK_SET_GCLK_FREQ_SYNC_1,
    DC_CLK_SET_GCLK_FREQ_SYNC_2,
    DC_CLK_SET_GCLK_FREQ_SYNC_3,
    DC_CLK_SET_GCLK_FREQ_SYNC_4,
    DC_CLK_SET_GCLK_FREQ_SYNC_5,
    DC_CLK_SET_GCLK_FREQ_COMPLETE,
    DC_CLK_INIT_OSC_BEGIN,
    DC_CLK_INIT_OSC_SYNC_1,
    DC_CLK_INIT_OSC_SYNC_2,
    DC_CLK_INIT_OSC_SYNC_3,
    DC_CLK_INIT_OSC_SYNC_4,
    DC_CLK_INIT_OSC_SYNC_5,
    DC_CLK_INIT_OSC_COMPLETE,
    DC_CLK_RESET_TIME_BEGIN,
    DC_CLK_RESET_TIME_COMPLETE,
    DC_CLK_OSC_INIT_BEGIN,
    DC_CLK_OSC_INIT_XOSC0_SYNC,
    DC_CLK_OSC_INIT_DPLL_SYNC_DISABLE,
    DC_CLK_OSC_INIT_DPLL_SYNC_RATIO,
    DC_CLK_OSC_INIT_DPLL_SYNC_ENABLE,
    DC_CLK_OSC_INIT_DPLL_WAIT_LOCK,
    DC_CLK_OSC_INIT_DPLL_WAIT_CLKRDY,
    DC_CLK_OSC_INIT_GCLK_SYNC_GENCTRL0,
    DC_CLK_OSC_INIT_COMPLETE,
    DC_SPI_INIT_BEGIN,
    DC_SPI_WRITE_DRE,
    DC_SPI_WRITE_TXC_1,
    DC_SPI_WRITE_TXC_2,
    DC_SPI_SYNC_ENABLING,
    DC_SPI_INIT_COMPLETE,
    DC_PORT_DETECT_INIT_BEGIN,
    DC_PORT_DETECT_INIT_FAILED,
    DC_PORT_DETECT_INIT_COMPLETE,
    DC_USB_RESET_BEGIN,
    DC_USB_RESET_COMPLETE,
    DC_USB_SET_HOST_BY_VOLTAGE_BEGIN,
    DC_USB_SET_HOST_5V_LOW_WAITING,
    DC_USB_SET_HOST_BY_VOLTAGE_COMPLETE,
    DC_USB_CONFIGURE_BEGIN,
    DC_USB_CONFIGURE_GET_SERIAL,
    DC_USB_CONFIGURE_COMPLETE,
    DC_USB_WRITE2422_BLOCK_BEGIN,
    DC_USB_WRITE2422_BLOCK_SYNC_SYSOP,
    DC_USB_WRITE2422_BLOCK_COMPLETE,
    DC_ADC0_CLOCK_INIT_BEGIN,
    DC_ADC0_CLOCK_INIT_COMPLETE,
    DC_ADC0_INIT_BEGIN,
    DC_ADC0_SWRST_SYNCING_1,
    DC_ADC0_SWRST_SYNCING_2,
    DC_ADC0_AVGCTRL_SYNCING_1,
    DC_ADC0_AVGCTRL_SYNCING_2,
    DC_ADC0_SAMPCTRL_SYNCING_1,
    DC_ADC0_ENABLE_SYNCING_1,
    DC_ADC0_INIT_COMPLETE,
    DC_I2C0_INIT_BEGIN,
    DC_I2C0_INIT_SYNC_ENABLING,
    DC_I2C0_INIT_SYNC_SYSOP,
    DC_I2C0_INIT_WAIT_IDLE,
    DC_I2C0_INIT_COMPLETE,
    DC_I2C1_INIT_BEGIN,
    DC_I2C1_INIT_SYNC_ENABLING,
    DC_I2C1_INIT_SYNC_SYSOP,
    DC_I2C1_INIT_WAIT_IDLE,
    DC_I2C1_INIT_COMPLETE,
    DC_I2C3733_INIT_CONTROL_BEGIN,
    DC_I2C3733_INIT_CONTROL_COMPLETE,
    DC_I2C3733_INIT_DRIVERS_BEGIN,
    DC_I2C3733_INIT_DRIVERS_COMPLETE,
    DC_I2C_DMAC_LED_INIT_BEGIN,
    DC_I2C_DMAC_LED_INIT_COMPLETE,
    DC_I2C3733_CONTROL_SET_BEGIN,
    DC_I2C3733_CONTROL_SET_COMPLETE,
    DC_LED_MATRIX_INIT_BEGIN,
    DC_LED_MATRIX_INIT_COMPLETE,
    DC_USB2422_INIT_BEGIN,
    DC_USB2422_INIT_WAIT_5V_LOW,
    DC_USB2422_INIT_OSC_SYNC_DISABLING,
    DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_1,
    DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_2,
    DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_3,
    DC_USB2422_INIT_OSC_SYNC_DFLLCTRLB_4,
    DC_USB2422_INIT_OSC_SYNC_DFLLMUL,
    DC_USB2422_INIT_OSC_SYNC_ENABLING,
    DC_USB2422_INIT_USB_SYNC_SWRST,
    DC_USB2422_INIT_USB_WAIT_SWRST,
    DC_USB2422_INIT_USB_SYNC_ENABLING,
    DC_USB2422_INIT_COMPLETE,
    DC_MAIN_UDC_START_BEGIN,
    DC_MAIN_UDC_START_COMPLETE,
    DC_MAIN_CDC_INIT_BEGIN,
    DC_MAIN_CDC_INIT_COMPLETE,
    /* Never change the order of error codes! Only add codes to end! */
};

#else

#define DBGC(n) {}

#endif //DEBUG_BOOT_TRACING

#endif //_D51_UTIL_H_