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
//! Low-level hardware abstraction crate (aka a Peripheral Access Crate) for the Nintendo 64 console.
//!
//! Unlike typical PACs, this API is not generated via svd2rust, as it doesn't support the architecture
//! and the N64 contains features not found on microcontrollers.
//!
//! Additionally, all parts of the API are freely accessible without any concept of ownership. It is
//! very likely that software running on the N64 may require shared access to various parts of the
//! hardware. Forcing developers to pass around a reference to the entire PAC decreases usability,
//! and is not necessarily unsafe.
//!
//! # Safety
//! Functions in this PAC are marked unsafe if the operation itself could actively cause unexpected
//! or undefined behavior, such as an exception or other form of failure.
//!
//! It is possible that a write or read-modify-write operation could be unsafe, but only if used in
//! an async environment or when the same register is accessed from both regular code and from
//! within an interrupt handler. The PAC is not responsible for either situation.
//!
//! # Memory Mapped Registers
//! There are three destinct methods for accessing and modifying these registers.
//!
//! ##### Const raw pointers
//! Every known register is defined as a const `*mut u32` in the [`memory`] module.
//! ```
//! use n64_pac::memory::VI_CTRL;
//!
//! let mut value = unsafe { VI_CTRL.read_volatile() };
//! value |= 0x00000003;
//! unsafe { VI_CTRL.write_volatile(value); }
//! ```
//!
//! ##### Local RegisterBlock wrapper
//! This form of access provides a wrapped mutable reference (`&'static mut`) to a peripheral's RegisterBlock.
//! The RegisterBlock is a struct representation of the registers in memory for the given peripheral.
//!
//! You do not create the RegisterBlock directly, instead use the wrapper struct named after the
//! peripheral you are accessing. (e.g. use [`vi::VideoInterface`] for the [`vi`] module/peripheral.
//! ```
//! use n64_pac::vi::{ColorDepth, VideoInterface};
//!
//! let vi = VideoInterface::new();
//! let mut value = vi.ctrl.read();
//! value.set_depth(ColorDepth::BPP32);
//! vi.ctrl.write(value);
//! ```
//! For read-modify-write operations, a `modify()` function is also available:
//! ```
//! use n64_pac::vi::{ColorDepth, VideoInterface};
//!
//! let vi = VideoInterface::new();
//! vi.ctrl.modify(|reg| reg.with_depth(ColorDepth::BPP32));
//! ```
//! When the wrapper goes out of scope, the _reference_ will be dropped. The static lifetime attached
//! to the reference only indicates that the "data" (memory mapped registers) it points to will live forever.
//!
//! ##### Static RegisterBlock wrapper functions
//! As an alternative to creating a local variable like above, there are static functions that will
//! implicitly create the RegisterBlock wrapper.
//! ```
//! use n64_pac::vi;
//! use n64_pac::vi::ColorDepth;
//!
//! let mut value = vi::ctrl();
//! value.set_depth(ColorDepth::BPP32);
//! vi::set_ctrl(value);
//! ```
//! For read-modify-write operations, a `modify()` function is also available:
//! ```
//! use n64_pac::vi;
//! use n64_pac::vi::ColorDepth;
//!
//! vi::modify_ctrl(|reg| reg.with_depth(ColorDepth::BPP32));
//! ```
//!
//! # CPU Configuration Registers
//! These registers are not mapped to memory, and instead require special assembly instructions to access.
//!
//! To access these registers, there are static functions available in modules [`cp0`] and [`cp1`].
//! ```
//! use n64_pac::cp0;
//!
//! let mut value = cp0::status();
//! value.set_ie(true);
//! cp0::set_status(value);
//! ```
//! For read-modify-write operations, a `modify()` function is also available:
//! ```
//! use n64_pac::cp0;
//!
//! cp0::modify_status(|reg| reg.with_ie(true));
//! ```
//!
;
;
;