@@ -36,96 +36,95 @@ pub(crate) fn expand_bind_interrupt(keyboard_config: &KeyboardConfig, item_mod:
3636}
3737
3838pub ( crate ) fn bind_interrupt_default ( keyboard_config : & KeyboardConfig ) -> TokenStream2 {
39- if let Some ( usb_info) = keyboard_config. communication . get_usb_info ( ) {
40- let interrupt_name = format_ident ! ( "{}" , usb_info. interrupt_name) ;
41- let peripheral_name = format_ident ! ( "{}" , usb_info. peripheral_name) ;
42- match keyboard_config. chip . series {
43- crate :: ChipSeries :: Stm32 => {
44- if !keyboard_config. chip . has_usb ( ) {
45- return quote ! { } ;
46- }
47-
39+ match keyboard_config. chip . series {
40+ crate :: ChipSeries :: Stm32 => {
41+ if let Some ( usb_info) = keyboard_config. communication . get_usb_info ( ) {
42+ let interrupt_name = format_ident ! ( "{}" , usb_info. interrupt_name) ;
43+ let peripheral_name = format_ident ! ( "{}" , usb_info. peripheral_name) ;
4844 quote ! {
4945 use :: embassy_stm32:: bind_interrupts;
5046 bind_interrupts!( struct Irqs {
5147 #interrupt_name => :: embassy_stm32:: usb:: InterruptHandler <:: embassy_stm32:: peripherals:: #peripheral_name>;
5248 } ) ;
5349 }
50+ } else {
51+ quote ! { }
5452 }
55- crate :: ChipSeries :: Nrf52 => {
56- let saadc_interrupt = if let Some ( BleConfig {
57- enabled : true ,
58- battery_adc_pin : Some ( _adc_pin) ,
59- charge_state : _,
60- charge_led : _,
61- adc_divider_measured : _,
62- adc_divider_total : _,
63- } ) = keyboard_config. communication . get_ble_config ( )
64- {
65- Some ( quote ! {
66- SAADC => :: embassy_nrf:: saadc:: InterruptHandler ;
67- } )
68- } else {
69- None
70- } ;
71- let interrupt_binding = if keyboard_config. chip . has_usb ( ) {
72- quote ! {
73- #interrupt_name => :: embassy_nrf:: usb:: InterruptHandler <:: embassy_nrf:: peripherals:: #peripheral_name>;
74- #saadc_interrupt
75- RNG => :: embassy_nrf:: rng:: InterruptHandler <:: embassy_nrf:: peripherals:: RNG >;
76- EGU0_SWI0 => :: nrf_sdc:: mpsl:: LowPrioInterruptHandler ;
77- CLOCK_POWER => :: nrf_sdc:: mpsl:: ClockInterruptHandler , :: embassy_nrf:: usb:: vbus_detect:: InterruptHandler ;
78- RADIO => :: nrf_sdc:: mpsl:: HighPrioInterruptHandler ;
79- TIMER0 => :: nrf_sdc:: mpsl:: HighPrioInterruptHandler ;
80- RTC0 => :: nrf_sdc:: mpsl:: HighPrioInterruptHandler ;
81- }
82- } else {
83- quote ! { #saadc_interrupt }
84- } ;
53+ }
54+ crate :: ChipSeries :: Nrf52 => {
55+ let saadc_interrupt = if let Some ( BleConfig {
56+ enabled : true ,
57+ battery_adc_pin : Some ( _adc_pin) ,
58+ charge_state : _,
59+ charge_led : _,
60+ adc_divider_measured : _,
61+ adc_divider_total : _,
62+ } ) = keyboard_config. communication . get_ble_config ( )
63+ {
64+ quote ! { SAADC => :: embassy_nrf:: saadc:: InterruptHandler ; }
65+ } else {
66+ quote ! { }
67+ } ;
68+ let usb_and_clock_interrupt = if let Some ( usb_info) = keyboard_config. communication . get_usb_info ( ) {
69+ let interrupt_name = format_ident ! ( "{}" , usb_info. interrupt_name) ;
70+ let peripheral_name = format_ident ! ( "{}" , usb_info. peripheral_name) ;
8571 quote ! {
86- use :: embassy_nrf:: bind_interrupts;
87- bind_interrupts!( struct Irqs {
88- #interrupt_binding
89- } ) ;
72+ #interrupt_name => :: embassy_nrf:: usb:: InterruptHandler <:: embassy_nrf:: peripherals:: #peripheral_name>;
73+ CLOCK_POWER => :: nrf_sdc:: mpsl:: ClockInterruptHandler , :: embassy_nrf:: usb:: vbus_detect:: InterruptHandler ;
74+ }
75+ } else {
76+ quote ! { CLOCK_POWER => :: nrf_sdc:: mpsl:: ClockInterruptHandler ; }
77+ } ;
78+ quote ! {
79+ use :: embassy_nrf:: bind_interrupts;
80+ bind_interrupts!( struct Irqs {
81+ #saadc_interrupt
82+ #usb_and_clock_interrupt
83+ RNG => :: embassy_nrf:: rng:: InterruptHandler <:: embassy_nrf:: peripherals:: RNG >;
84+ EGU0_SWI0 => :: nrf_sdc:: mpsl:: LowPrioInterruptHandler ;
85+ RADIO => :: nrf_sdc:: mpsl:: HighPrioInterruptHandler ;
86+ TIMER0 => :: nrf_sdc:: mpsl:: HighPrioInterruptHandler ;
87+ RTC0 => :: nrf_sdc:: mpsl:: HighPrioInterruptHandler ;
88+ } ) ;
9089
91- #[ :: embassy_executor:: task]
92- async fn mpsl_task( mpsl: & ' static :: nrf_sdc:: mpsl:: MultiprotocolServiceLayer <' static >) -> ! {
93- mpsl. run( ) . await
94- }
95- /// How many outgoing L2CAP buffers per link
96- const L2CAP_TXQ : u8 = 3 ;
90+ #[ :: embassy_executor:: task]
91+ async fn mpsl_task( mpsl: & ' static :: nrf_sdc:: mpsl:: MultiprotocolServiceLayer <' static >) -> ! {
92+ mpsl. run( ) . await
93+ }
94+ /// How many outgoing L2CAP buffers per link
95+ const L2CAP_TXQ : u8 = 3 ;
9796
98- /// How many incoming L2CAP buffers per link
99- const L2CAP_RXQ : u8 = 3 ;
97+ /// How many incoming L2CAP buffers per link
98+ const L2CAP_RXQ : u8 = 3 ;
10099
101- /// Size of L2CAP packets
102- const L2CAP_MTU : usize = 72 ;
103- fn build_sdc<' d, const N : usize >(
104- p: :: nrf_sdc:: Peripherals <' d>,
105- rng: & ' d mut :: embassy_nrf:: rng:: Rng <:: embassy_nrf:: peripherals:: RNG >,
106- mpsl: & ' d :: nrf_sdc:: mpsl:: MultiprotocolServiceLayer ,
107- mem: & ' d mut :: nrf_sdc:: Mem <N >,
108- ) -> Result <:: nrf_sdc:: SoftdeviceController <' d>, :: nrf_sdc:: Error > {
109- :: nrf_sdc:: Builder :: new( ) ?
110- . support_adv( ) ?
111- . support_peripheral( ) ?
112- . peripheral_count( 1 ) ?
113- . buffer_cfg( L2CAP_MTU as u8 , L2CAP_MTU as u8 , L2CAP_TXQ , L2CAP_RXQ ) ?
114- . build( p, rng, mpsl, mem)
115- }
100+ /// Size of L2CAP packets
101+ const L2CAP_MTU : usize = 72 ;
102+ fn build_sdc<' d, const N : usize >(
103+ p: :: nrf_sdc:: Peripherals <' d>,
104+ rng: & ' d mut :: embassy_nrf:: rng:: Rng <:: embassy_nrf:: peripherals:: RNG >,
105+ mpsl: & ' d :: nrf_sdc:: mpsl:: MultiprotocolServiceLayer ,
106+ mem: & ' d mut :: nrf_sdc:: Mem <N >,
107+ ) -> Result <:: nrf_sdc:: SoftdeviceController <' d>, :: nrf_sdc:: Error > {
108+ :: nrf_sdc:: Builder :: new( ) ?
109+ . support_adv( ) ?
110+ . support_peripheral( ) ?
111+ . peripheral_count( 1 ) ?
112+ . buffer_cfg( L2CAP_MTU as u8 , L2CAP_MTU as u8 , L2CAP_TXQ , L2CAP_RXQ ) ?
113+ . build( p, rng, mpsl, mem)
116114 }
117115 }
118- crate :: ChipSeries :: Rp2040 => {
119- quote ! {
120- use :: embassy_rp:: bind_interrupts;
121- bind_interrupts!( struct Irqs {
122- #interrupt_name => :: embassy_rp:: usb:: InterruptHandler <:: embassy_rp:: peripherals:: #peripheral_name>;
123- } ) ;
124- }
116+ }
117+ crate :: ChipSeries :: Rp2040 => {
118+ let usb_info = keyboard_config. communication . get_usb_info ( ) . unwrap ( ) ;
119+ let interrupt_name = format_ident ! ( "{}" , usb_info. interrupt_name) ;
120+ let peripheral_name = format_ident ! ( "{}" , usb_info. peripheral_name) ;
121+ quote ! {
122+ use :: embassy_rp:: bind_interrupts;
123+ bind_interrupts!( struct Irqs {
124+ #interrupt_name => :: embassy_rp:: usb:: InterruptHandler <:: embassy_rp:: peripherals:: #peripheral_name>;
125+ } ) ;
125126 }
126- crate :: ChipSeries :: Esp32 => quote ! { } ,
127127 }
128- } else {
129- quote ! { }
128+ crate :: ChipSeries :: Esp32 => quote ! { } ,
130129 }
131130}
0 commit comments