Skip to content

Commit 6ab56ba

Browse files
committed
Extracted morse specific library code into separate module.
1 parent 410cf03 commit 6ab56ba

File tree

2 files changed

+891
-17
lines changed

2 files changed

+891
-17
lines changed

boards/neo_trinkey/examples/morse_queues.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// const INTERVAL: u16 = 100u16; // Controls the speed of morse code generation
22

3-
mod morse_queues {
3+
pub mod morse_queues {
44
const CHAR_QUEUE_LENTGH: usize = 1024;
55
const STATE_QUEUE_LENGTH: usize = 32;
66

7-
struct CharQueue {
7+
pub struct CharQueue {
88
queue: [char; CHAR_QUEUE_LENTGH],
99
length: usize,
1010
write_position: usize,
1111
read_position: usize,
1212
}
1313

14-
struct PinControlQueue {
14+
pub struct PinControlQueue {
1515
queue: [PinControlDescriptor; STATE_QUEUE_LENGTH],
1616
length: usize,
1717
write_position: usize,
@@ -161,12 +161,12 @@ mod morse_queues {
161161
read_position: 0,
162162
};
163163

164-
struct PinControlDescriptor {
164+
pub struct PinControlDescriptor {
165165
pin_state: bool,
166166
duration: u8,
167167
}
168168

169-
fn push_dot() {
169+
pub fn push_dot() {
170170
let dot = PinControlDescriptor {
171171
pin_state: true,
172172
duration: 1,
@@ -179,7 +179,7 @@ mod morse_queues {
179179
push_state(interval);
180180
}
181181

182-
fn push_dash() {
182+
pub fn push_dash() {
183183
let dash = PinControlDescriptor {
184184
pin_state: true,
185185
duration: 3,
@@ -192,15 +192,15 @@ mod morse_queues {
192192
push_state(interval);
193193
}
194194

195-
fn push_space() {
195+
pub fn push_space() {
196196
let space = PinControlDescriptor {
197197
pin_state: false,
198198
duration: 7,
199199
};
200200
push_state(space);
201201
}
202202

203-
fn push_letter_interval() {
203+
pub fn push_letter_interval() {
204204
let space = PinControlDescriptor {
205205
pin_state: false,
206206
duration: 3,
@@ -211,7 +211,7 @@ mod morse_queues {
211211
static mut COUNT_DOWN: u8 = 0;
212212
static mut CURRENT_PIN_STATE: bool = false;
213213

214-
fn get_next_state() -> bool {
214+
pub fn get_next_state() -> bool {
215215
let mut pin_state: bool;
216216
unsafe {
217217
if COUNT_DOWN <= 0 {
@@ -228,7 +228,7 @@ mod morse_queues {
228228
}
229229
}
230230

231-
fn push_char(letter: char) {
231+
pub fn push_char(letter: char) {
232232
unsafe {
233233
let index = CHAR_QUEUE.write_position as usize;
234234
let queue = &mut CHAR_QUEUE;
@@ -238,7 +238,7 @@ mod morse_queues {
238238
}
239239
}
240240

241-
fn pop_char() -> char {
241+
pub fn pop_char() -> char {
242242
unsafe {
243243
if CHAR_QUEUE.length == 0 {
244244
return '\r'; // Use CR to indicate empty queue
@@ -250,7 +250,7 @@ mod morse_queues {
250250
}
251251
}
252252

253-
fn push_state(state: PinControlDescriptor) {
253+
pub fn push_state(state: PinControlDescriptor) {
254254
unsafe {
255255
let index = PIN_CONTROL_QUEUE.write_position as usize;
256256
let queue = &mut PIN_CONTROL_QUEUE;
@@ -261,7 +261,7 @@ mod morse_queues {
261261
}
262262
}
263263

264-
fn pop_state() -> PinControlDescriptor {
264+
pub fn pop_state() -> PinControlDescriptor {
265265
unsafe {
266266
if PIN_CONTROL_QUEUE.length == 0 {
267267
return PinControlDescriptor {
@@ -280,7 +280,7 @@ mod morse_queues {
280280
}
281281
}
282282

283-
fn emit_morse_letter(letter: char) {
283+
pub fn emit_morse_letter(letter: char) {
284284
let downcased_letter = letter.to_ascii_lowercase(); // Add support for Latin 1 later.
285285
match downcased_letter {
286286
'a' => {
@@ -694,13 +694,13 @@ mod morse_queues {
694694
}
695695
}
696696

697-
fn emit_morse_dot() {
697+
pub fn emit_morse_dot() {
698698
push_dot();
699699
}
700-
fn emit_morse_dash() {
700+
pub fn emit_morse_dash() {
701701
push_dash();
702702
}
703-
fn emit_morse_space() {
703+
pub fn emit_morse_space() {
704704
push_space();
705705
}
706706
}

0 commit comments

Comments
 (0)