Skip to content

Commit d3dc37b

Browse files
committed
Use settings pins in emulation
1 parent ae5ca16 commit d3dc37b

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

helpers/mag_helpers.c

+32-23
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
#define TAG "MagHelpers"
44

5-
// Haviv Board - pins gpio_ext_pa7 & gpio_ext_pa6 was swapped.
6-
#define GPIO_PIN_A &gpio_ext_pa7
7-
#define GPIO_PIN_B &gpio_ext_pa6
8-
#define GPIO_PIN_ENABLE &gpio_ext_pa4
9-
#define RFID_PIN_OUT &gpio_rfid_carrier_out
10-
115
#define ZERO_PREFIX 25 // n zeros prefix
126
#define ZERO_BETWEEN 53 // n zeros between tracks
137
#define ZERO_SUFFIX 25 // n zeros suffix
@@ -22,15 +16,15 @@ uint8_t last_value = 2;
2216
void play_halfbit(bool value, MagState* state) {
2317
switch(state->tx) {
2418
case MagTxStateRFID:
25-
furi_hal_gpio_write(RFID_PIN_OUT, value);
19+
furi_hal_gpio_write(&gpio_rfid_carrier_out, value);
2620
/*furi_hal_gpio_write(RFID_PIN_OUT, !value);
2721
furi_hal_gpio_write(RFID_PIN_OUT, value);
2822
furi_hal_gpio_write(RFID_PIN_OUT, !value);
2923
furi_hal_gpio_write(RFID_PIN_OUT, value);*/
3024
break;
3125
case MagTxStateGPIO:
32-
furi_hal_gpio_write(GPIO_PIN_A, value);
33-
furi_hal_gpio_write(GPIO_PIN_B, !value);
26+
furi_hal_gpio_write(mag_state_enum_to_pin(state->pin_input), value);
27+
furi_hal_gpio_write(mag_state_enum_to_pin(state->pin_output), !value);
3428
break;
3529
case MagTxStatePiezo:
3630
furi_hal_gpio_write(&gpio_speaker, value);
@@ -41,7 +35,7 @@ void play_halfbit(bool value, MagState* state) {
4135

4236
break;
4337
case MagTxStateLF_P:
44-
furi_hal_gpio_write(RFID_PIN_OUT, value);
38+
furi_hal_gpio_write(&gpio_rfid_carrier_out, value);
4539
furi_hal_gpio_write(&gpio_speaker, value);
4640

4741
/* // Weaker but cleaner signal
@@ -143,14 +137,14 @@ void tx_init_rfid() {
143137
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
144138
furi_hal_gpio_write(&gpio_nfc_irq_rfid_pull, false);
145139

146-
furi_hal_gpio_init(RFID_PIN_OUT, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
140+
furi_hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
147141

148142
furi_delay_ms(300);
149143
}
150144

151145
void tx_deinit_rfid() {
152146
// reset RFID system
153-
furi_hal_gpio_write(RFID_PIN_OUT, 0);
147+
furi_hal_gpio_write(&gpio_rfid_carrier_out, 0);
154148

155149
furi_hal_rfid_pins_reset();
156150
}
@@ -187,11 +181,23 @@ bool tx_init(MagState* state) {
187181
break;
188182
case MagTxStateGPIO:
189183
// gpio_item_configure_all_pins(GpioModeOutputPushPull);
190-
furi_hal_gpio_init(GPIO_PIN_A, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
191-
furi_hal_gpio_init(GPIO_PIN_B, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
192-
furi_hal_gpio_init(GPIO_PIN_ENABLE, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
193-
194-
furi_hal_gpio_write(GPIO_PIN_ENABLE, 1);
184+
furi_hal_gpio_init(
185+
mag_state_enum_to_pin(state->pin_input),
186+
GpioModeOutputPushPull,
187+
GpioPullNo,
188+
GpioSpeedLow);
189+
furi_hal_gpio_init(
190+
mag_state_enum_to_pin(state->pin_output),
191+
GpioModeOutputPushPull,
192+
GpioPullNo,
193+
GpioSpeedLow);
194+
furi_hal_gpio_init(
195+
mag_state_enum_to_pin(state->pin_enable),
196+
GpioModeOutputPushPull,
197+
GpioPullNo,
198+
GpioSpeedLow);
199+
200+
furi_hal_gpio_write(mag_state_enum_to_pin(state->pin_enable), 1);
195201

196202
// had some issues with ~300; bumped higher temporarily
197203
furi_delay_ms(500);
@@ -226,14 +232,17 @@ bool tx_deinit(MagState* state) {
226232
tx_deinit_rfid();
227233
break;
228234
case MagTxStateGPIO:
229-
furi_hal_gpio_write(GPIO_PIN_A, 0);
230-
furi_hal_gpio_write(GPIO_PIN_B, 0);
231-
furi_hal_gpio_write(GPIO_PIN_ENABLE, 0);
235+
furi_hal_gpio_write(mag_state_enum_to_pin(state->pin_input), 0);
236+
furi_hal_gpio_write(mag_state_enum_to_pin(state->pin_output), 0);
237+
furi_hal_gpio_write(mag_state_enum_to_pin(state->pin_enable), 0);
232238

233239
// set back to analog output mode? - YES
234-
furi_hal_gpio_init(GPIO_PIN_A, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
235-
furi_hal_gpio_init(GPIO_PIN_B, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
236-
furi_hal_gpio_init(GPIO_PIN_ENABLE, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
240+
furi_hal_gpio_init(
241+
mag_state_enum_to_pin(state->pin_input), GpioModeAnalog, GpioPullNo, GpioSpeedLow);
242+
furi_hal_gpio_init(
243+
mag_state_enum_to_pin(state->pin_output), GpioModeAnalog, GpioPullNo, GpioSpeedLow);
244+
furi_hal_gpio_init(
245+
mag_state_enum_to_pin(state->pin_enable), GpioModeAnalog, GpioPullNo, GpioSpeedLow);
237246

238247
//gpio_item_configure_all_pins(GpioModeAnalog);
239248
break;

0 commit comments

Comments
 (0)