Skip to content

Commit 45eef6a

Browse files
committed
Use sync-code to manage code
1 parent d50ff65 commit 45eef6a

28 files changed

+220
-290
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ jobs:
1414
test:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v4
17+
- uses: actions/checkout@v6
1818
- uses: dtolnay/rust-toolchain@stable
1919
with:
2020
targets: thumbv7m-none-eabi
21-
- uses: actions/setup-python@v5
21+
- uses: actions/setup-python@v6
2222
with:
2323
python-version: "3.13"
24-
- run: python scripts/sync_code.py --check
2524
- run: cargo build --release --features=stm32f100,xC
26-
- run: python scripts/build.py build --release
27-
- run: python scripts/build.py clippy
28-
- run: python scripts/build.py test
29-
- run: python scripts/build.py build --example=f103c8
25+
- run: python3.13 scripts/build.py build --release
26+
- run: python3.13 scripts/build.py clippy
27+
- run: python3.13 scripts/build.py test
28+
- run: python3.13 scripts/build.py build --example=f103c8
3029

3130
publish:
3231
needs: test
@@ -35,7 +34,7 @@ jobs:
3534
permissions:
3635
id-token: write # Required for OIDC token exchange
3736
steps:
38-
- uses: actions/checkout@v4
37+
- uses: actions/checkout@v6
3938
- uses: dtolnay/rust-toolchain@stable
4039
with:
4140
targets: thumbv7m-none-eabi

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
name = "stm32f1-hal"
1010
readme = "README.md"
1111
repository = "https://github.com/mcu-rust/stm32f1-hal"
12-
version = "0.2.2"
12+
version = "0.3.0"
1313

1414
[package.metadata.docs.rs]
1515
features = ["stm32f103", "xG"]
@@ -49,6 +49,9 @@
4949
rtic = ["dep:rtic-monotonic"]
5050
std = []
5151

52+
[build-dependencies]
53+
sync-code = "0.1.1"
54+
5255
[dependencies]
5356
bitflags = "2.9"
5457
cfg-if = "1.0"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Below are the design principles.
1111
2. Concise is not equal to simple.
1212
- Fewer lines of code do not necessarily mean easier to read and understand.
1313

14-
Therefore, if a module is quite complex, I would not use a macro + generic approach, as it is too difficult to read.
14+
Therefore, if a module is quite complex, I would not use a `macro` + `generic` approach, as it is too difficult to read.
1515

16-
Instead, I use a synchronization script to manage duplicate code across peripherals and a script to generate code for GPIO alternate function remapping.
16+
Instead, I use [sync-code](https://crates.io/crates/sync-code) to manage duplicate code across peripherals and a script to generate code for GPIO alternate function remapping.
1717

1818
## Note
1919
This project is still in its early stages, with only a few features completed.

build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
fn main() {
2+
sync_code::Builder::new()
3+
.add("src/uart/usart2.rs", "src/uart/usart1.rs")
4+
.add("src/uart/usart3.rs", "src/uart/usart1.rs")
5+
.add("src/uart/uart4.rs", "src/uart/usart1.rs")
6+
.add("src/uart/uart5.rs", "src/uart/uart4.rs")
7+
.add("src/timer/timer2.rs", "src/timer/timer1.rs")
8+
.add("src/timer/timer3.rs", "src/timer/timer2.rs")
9+
.add("src/timer/timer4.rs", "src/timer/timer2.rs")
10+
.add("src/timer/timer5.rs", "src/timer/timer2.rs")
11+
.add("src/timer/timer6.rs", "src/timer/timer1.rs")
12+
.add("src/timer/timer7.rs", "src/timer/timer6.rs")
13+
.add("src/timer/timer8.rs", "src/timer/timer1.rs")
14+
.add("src/timer/timer9.rs", "src/timer/timer1.rs")
15+
.add("src/timer/timer10.rs", "src/timer/timer1.rs")
16+
.add("src/timer/timer11.rs", "src/timer/timer10.rs")
17+
.add("src/timer/timer12.rs", "src/timer/timer9.rs")
18+
.add("src/timer/timer13.rs", "src/timer/timer10.rs")
19+
.add("src/timer/timer14.rs", "src/timer/timer10.rs")
20+
.add("src/timer/timer15.rs", "src/timer/timer9.rs")
21+
.add("src/timer/timer16.rs", "src/timer/timer10.rs")
22+
.add("src/timer/timer17.rs", "src/timer/timer10.rs")
23+
.sync();
24+
}

scripts/build.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import subprocess
55

66
from base import green
7-
from sync_code import sync_all
87

98

109
def run_cmd(cmd: list[str]) -> None:
@@ -20,8 +19,6 @@ def main() -> int:
2019
parser.add_argument("-e", "--examples", type=str, nargs="*")
2120
opts = parser.parse_args()
2221

23-
sync_all()
24-
2522
cmd = ["cargo", opts.cmd]
2623

2724
if opts.examples:

scripts/sync_code.py

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/timer/timer1.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type TimerX = pac::TIM1;
22
type Width = u16;
33

4-
// sync begin
4+
// $sync begin
55

66
use super::*;
77
use crate::{Mcu, pac};
@@ -132,9 +132,9 @@ impl GeneralTimer for TimerX {
132132
#[inline(always)]
133133
fn stop_in_debug(&mut self, state: bool) {
134134
let dbg = unsafe { DBG::steal() };
135-
// sync dbg_t1
135+
// $sync dbg_t1
136136
dbg.cr().modify(|_, w| w.dbg_tim1_stop().bit(state));
137-
// sync dbg_end
137+
// $sync dbg_end
138138
}
139139

140140
#[inline(always)]
@@ -143,15 +143,15 @@ impl GeneralTimer for TimerX {
143143
}
144144
}
145145

146-
// sync pwm
146+
// $sync pwm
147147
// PWM ------------------------------------------------------------------------
148148

149149
impl TimerWithPwm for TimerX {
150150
fn stop_pwm(&mut self) {
151151
self.disable_counter();
152152
}
153153

154-
// sync start_pwm_aoe
154+
// $sync start_pwm_aoe
155155

156156
#[inline(always)]
157157
fn start_pwm(&mut self) {
@@ -161,7 +161,7 @@ impl TimerWithPwm for TimerX {
161161
self.enable_counter();
162162
}
163163

164-
// sync pwm_cfg_4
164+
// $sync pwm_cfg_4
165165

166166
#[inline(always)]
167167
fn preload_output_channel_in_mode(&mut self, channel: Channel, mode: PwmMode) {
@@ -208,7 +208,7 @@ impl TimerWithPwm for TimerX {
208208
}
209209
}
210210

211-
// sync pwm_ch1
211+
// $sync pwm_ch1
212212
// PWM Channels ---------------------------------------------------------------
213213

214214
impl TimerWithPwm1Ch for TimerX {
@@ -228,7 +228,7 @@ impl TimerWithPwm1Ch for TimerX {
228228
}
229229
}
230230

231-
// sync pwm_ch2
231+
// $sync pwm_ch2
232232

233233
impl TimerWithPwm2Ch for TimerX {
234234
#[inline(always)]
@@ -247,7 +247,7 @@ impl TimerWithPwm2Ch for TimerX {
247247
}
248248
}
249249

250-
// sync pwm_ch4
250+
// $sync pwm_ch4
251251

252252
impl TimerWithPwm3Ch for TimerX {
253253
#[inline(always)]
@@ -285,15 +285,15 @@ impl TimerWithPwm4Ch for TimerX {
285285

286286
// Other ----------------------------------------------------------------------
287287

288-
// sync master
288+
// $sync master
289289
impl MasterTimer for TimerX {
290290
#[inline(always)]
291291
fn master_mode(&mut self, mode: MasterMode) {
292292
self.cr2().modify(|_, w| w.mms().variant(mode.into()));
293293
}
294294
}
295295

296-
// sync dir
296+
// $sync dir
297297

298298
impl TimerDirection for TimerX {
299299
#[inline(always)]
@@ -303,7 +303,7 @@ impl TimerDirection for TimerX {
303303
}
304304
}
305305

306-
// sync RTIC
306+
// $sync RTIC
307307
#[cfg(feature = "rtic")]
308308
mod timer_rtic {
309309
use super::*;
@@ -406,7 +406,7 @@ mod timer_rtic {
406406
}
407407
}
408408

409-
// sync end
409+
// $sync end
410410

411411
use pac::tim1::cr2::MMS;
412412
impl From<MasterMode> for MMS {

src/timer/timer10.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
type TimerX = pac::TIM10;
33
type Width = u16;
44

5-
// sync begin
5+
// $sync begin
66

77
use super::*;
88
use crate::{Mcu, pac};
@@ -133,10 +133,10 @@ impl GeneralTimer for TimerX {
133133
#[inline(always)]
134134
fn stop_in_debug(&mut self, state: bool) {
135135
let dbg = unsafe { DBG::steal() };
136-
// sync dbg_t10
136+
// $sync dbg_t10
137137
//TODO: restore these timers once stm32-rs has been updated
138138
// dbg.cr().modify(|_, w| w.dbg_tim10_stop().bit(state));
139-
// sync dbg_end
139+
// $sync dbg_end
140140
}
141141

142142
#[inline(always)]
@@ -145,23 +145,23 @@ impl GeneralTimer for TimerX {
145145
}
146146
}
147147

148-
// sync pwm
148+
// $sync pwm
149149
// PWM ------------------------------------------------------------------------
150150

151151
impl TimerWithPwm for TimerX {
152152
fn stop_pwm(&mut self) {
153153
self.disable_counter();
154154
}
155155

156-
// sync start_pwm
156+
// $sync start_pwm
157157

158158
#[inline(always)]
159159
fn start_pwm(&mut self) {
160160
self.reset_counter();
161161
self.enable_counter();
162162
}
163163

164-
// sync pwm_cfg_1
164+
// $sync pwm_cfg_1
165165

166166
#[inline(always)]
167167
fn preload_output_channel_in_mode(&mut self, channel: Channel, mode: PwmMode) {
@@ -180,7 +180,7 @@ impl TimerWithPwm for TimerX {
180180
}
181181
}
182182

183-
// sync pwm_ch1
183+
// $sync pwm_ch1
184184
// PWM Channels ---------------------------------------------------------------
185185

186186
impl TimerWithPwm1Ch for TimerX {
@@ -200,4 +200,4 @@ impl TimerWithPwm1Ch for TimerX {
200200
}
201201
}
202202

203-
// sync end
203+
// $sync end

0 commit comments

Comments
 (0)