Skip to content

Commit 912c6de

Browse files
committed
Minor code re-formatting, get rid of c_str macro usage, bump flipperzero Rust crate versions to latest
1 parent 1c60a25 commit 912c6de

File tree

2 files changed

+52
-38
lines changed

2 files changed

+52
-38
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bench = false
1313
test = false
1414

1515
[dependencies]
16-
flipperzero = "0.11.0"
17-
flipperzero-alloc = "0.11.0"
18-
flipperzero-rt = "0.11.0"
19-
flipperzero-sys = "0.11.0"
16+
flipperzero = "0.14.0"
17+
flipperzero-alloc = "0.14.0"
18+
flipperzero-rt = "0.14.0"
19+
flipperzero-sys = "0.14.0"

src/main.rs

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ struct SerprogData {
2929
running: bool,
3030
}
3131

32-
const RECORD_GUI: *const c_char = c_string!("gui");
33-
const RECORD_CLI: *const c_char = c_string!("cli");
32+
const RECORD_GUI: *const c_char = "gui\0".as_ptr();
33+
const RECORD_CLI: *const c_char = "cli\0".as_ptr();
3434

3535
#[allow(dead_code, non_camel_case_types)]
3636
const S_ACK: u8 = 0x06;
@@ -60,29 +60,45 @@ enum CR1Bits {
6060
#[allow(dead_code, non_camel_case_types)]
6161
// External SPI is on APB2, so the base frequency is 64MHz. The comments reflect this.
6262
enum PrescalerValues {
63-
LL_SPI_BAUDRATEPRESCALER_DIV2 = 0, /* 32MHz */
64-
LL_SPI_BAUDRATEPRESCALER_DIV4 = CR1Bits::SPI_CR1_BR_0 as u32, /* 16MHz */
65-
LL_SPI_BAUDRATEPRESCALER_DIV8 = CR1Bits::SPI_CR1_BR_1 as u32, /* 8MHz */
66-
LL_SPI_BAUDRATEPRESCALER_DIV16 = (CR1Bits::SPI_CR1_BR_1 as u32 | CR1Bits::SPI_CR1_BR_0 as u32), /* 4MHz */
67-
LL_SPI_BAUDRATEPRESCALER_DIV32 = CR1Bits::SPI_CR1_BR_2 as u32, /* 2MHz */
68-
LL_SPI_BAUDRATEPRESCALER_DIV64 = (CR1Bits::SPI_CR1_BR_2 as u32 | CR1Bits::SPI_CR1_BR_0 as u32), /* 1MHz */
69-
LL_SPI_BAUDRATEPRESCALER_DIV128 = (CR1Bits::SPI_CR1_BR_2 as u32 | CR1Bits::SPI_CR1_BR_1 as u32), /* 500KHz */
63+
LL_SPI_BAUDRATEPRESCALER_DIV2 = 0,
64+
/* 32MHz */
65+
LL_SPI_BAUDRATEPRESCALER_DIV4 = CR1Bits::SPI_CR1_BR_0 as u32,
66+
/* 16MHz */
67+
LL_SPI_BAUDRATEPRESCALER_DIV8 = CR1Bits::SPI_CR1_BR_1 as u32,
68+
/* 8MHz */
69+
LL_SPI_BAUDRATEPRESCALER_DIV16 = (CR1Bits::SPI_CR1_BR_1 as u32 | CR1Bits::SPI_CR1_BR_0 as u32),
70+
/* 4MHz */
71+
LL_SPI_BAUDRATEPRESCALER_DIV32 = CR1Bits::SPI_CR1_BR_2 as u32,
72+
/* 2MHz */
73+
LL_SPI_BAUDRATEPRESCALER_DIV64 = (CR1Bits::SPI_CR1_BR_2 as u32 | CR1Bits::SPI_CR1_BR_0 as u32),
74+
/* 1MHz */
75+
LL_SPI_BAUDRATEPRESCALER_DIV128 = (CR1Bits::SPI_CR1_BR_2 as u32 | CR1Bits::SPI_CR1_BR_1 as u32),
76+
/* 500KHz */
7077
LL_SPI_BAUDRATEPRESCALER_DIV256 = (CR1Bits::SPI_CR1_BR_2 as u32
7178
| CR1Bits::SPI_CR1_BR_1 as u32
72-
| CR1Bits::SPI_CR1_BR_0 as u32), /* 250KHz */
79+
| CR1Bits::SPI_CR1_BR_0 as u32),
80+
/* 250KHz */
7381
}
7482

7583
#[repr(u32)]
7684
#[allow(dead_code, non_camel_case_types)]
7785
enum PrescalerValuesInHz {
78-
LL_SPI_BAUDRATEPRESCALER_DIV2 = 32000000, /* 32MHz */
79-
LL_SPI_BAUDRATEPRESCALER_DIV4 = 16000000, /* 16MHz */
80-
LL_SPI_BAUDRATEPRESCALER_DIV8 = 8000000, /* 8MHz */
81-
LL_SPI_BAUDRATEPRESCALER_DIV16 = 4000000, /* 4MHz */
82-
LL_SPI_BAUDRATEPRESCALER_DIV32 = 2000000, /* 2MHz */
83-
LL_SPI_BAUDRATEPRESCALER_DIV64 = 1000000, /* 1MHz */
84-
LL_SPI_BAUDRATEPRESCALER_DIV128 = 500000, /* 500KHz */
85-
LL_SPI_BAUDRATEPRESCALER_DIV256 = 250000, /* 250KHz */
86+
LL_SPI_BAUDRATEPRESCALER_DIV2 = 32000000,
87+
/* 32MHz */
88+
LL_SPI_BAUDRATEPRESCALER_DIV4 = 16000000,
89+
/* 16MHz */
90+
LL_SPI_BAUDRATEPRESCALER_DIV8 = 8000000,
91+
/* 8MHz */
92+
LL_SPI_BAUDRATEPRESCALER_DIV16 = 4000000,
93+
/* 4MHz */
94+
LL_SPI_BAUDRATEPRESCALER_DIV32 = 2000000,
95+
/* 2MHz */
96+
LL_SPI_BAUDRATEPRESCALER_DIV64 = 1000000,
97+
/* 1MHz */
98+
LL_SPI_BAUDRATEPRESCALER_DIV128 = 500000,
99+
/* 500KHz */
100+
LL_SPI_BAUDRATEPRESCALER_DIV256 = 250000,
101+
/* 250KHz */
86102
}
87103

88104
#[repr(u8)]
@@ -136,17 +152,16 @@ const WORKER_ALL_CDC_EVENTS: u32 = WorkerEvents::CdcRx as u32
136152
| WorkerEvents::CdcTxStream as u32
137153
| WorkerEvents::CdcTx as u32;
138154

139-
fn main(args: *mut u8) -> i32 {
155+
fn main(args: Option<&CStr>) -> i32 {
140156
unsafe {
141157
_entry(args)
142158
}
143159
}
144160

145-
unsafe fn _entry(_args: *mut u8) -> i32 {
161+
unsafe fn _entry(_args: Option<&CStr>) -> i32 {
146162
let mut state = SerprogData {
147163
view_port: view_port_alloc(),
148-
event_queue: furi_message_queue_alloc(8, size_of::<InputEvent>() as u32)
149-
as *mut FuriMessageQueue,
164+
event_queue: furi_message_queue_alloc(8, size_of::<InputEvent>() as u32),
150165
trx_thread: 0 as *mut FuriThread,
151166
worker_thread: 0 as *mut FuriThread,
152167
rx_stream: furi_stream_buffer_alloc(5 * CDC_DATA_SZ, 1),
@@ -217,26 +232,26 @@ unsafe fn _entry(_args: *mut u8) -> i32 {
217232
Some(draw_callback),
218233
state.view_port as *mut c_void,
219234
);
220-
view_port_input_callback_set(state.view_port, Some(input_callback), state.event_queue);
235+
view_port_input_callback_set(state.view_port, Some(input_callback), state.event_queue as *mut c_void);
221236

222237
let gui: *mut Gui = furi_record_open(RECORD_GUI) as *mut Gui;
223-
gui_add_view_port(gui, state.view_port, GuiLayer_GuiLayerFullscreen);
238+
gui_add_view_port(gui, state.view_port, GuiLayerFullscreen);
224239

225240
let mut event: MaybeUninit<InputEvent> = MaybeUninit::uninit();
226-
241+
227242
while state.running {
228243
if furi_message_queue_get(
229244
state.event_queue,
230-
event.as_mut_ptr() as *mut InputEvent as *mut c_void,
245+
event.as_mut_ptr() as *mut c_void,
231246
100,
232-
) == FuriStatus_FuriStatusOk
247+
) == FuriStatusOk
233248
{
234249
let event = event.assume_init();
235-
if event.type_ == InputType_InputTypePress || event.type_ == InputType_InputTypeRepeat
250+
if event.type_ == InputTypePress || event.type_ == InputTypeRepeat
236251
{
237252
#[allow(non_upper_case_globals)]
238253
match event.key {
239-
InputKey_InputKeyBack => {
254+
InputKeyBack => {
240255
state.running = false;
241256
break;
242257
}
@@ -298,17 +313,17 @@ unsafe fn set_spi_baud_rate(handle: &mut FuriHalSpiBusHandle, prescaler_value: u
298313

299314
pub unsafe extern "C" fn input_callback(
300315
input_event: *mut InputEvent,
301-
event_queue: *mut FuriMessageQueue,
316+
event_queue: *mut c_void,
302317
) {
303318
furi_message_queue_put(
304-
event_queue,
319+
event_queue as *mut FuriMessageQueue,
305320
input_event as *mut c_void,
306321
FURI_FLAG_WAIT_FOREVER,
307322
);
308323
}
309324

310325
pub unsafe extern "C" fn draw_callback(canvas: *mut Canvas, _context: *mut c_void) {
311-
canvas_draw_str(canvas, 39, 31, c_string!("SPI flasher"));
326+
canvas_draw_str(canvas, 39, 31, "SPI Flasher\0".as_ptr());
312327
}
313328

314329
unsafe fn usb_process_packet(state: &mut SerprogData) {
@@ -677,8 +692,7 @@ pub unsafe extern "C" fn vcp_on_cdc_control_line(_context: *mut c_void, _state:
677692
pub unsafe extern "C" fn vcp_on_line_config(
678693
_context: *mut c_void,
679694
_config: *mut usb_cdc_line_coding,
680-
) {
681-
}
695+
) {}
682696

683697
unsafe fn furi_create_thread(
684698
thread_name: String,

0 commit comments

Comments
 (0)