Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applications/accessor/accessor_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void AccessorApp::run(void) {

AccessorApp::AccessorApp() {
notification = static_cast<NotificationApp*>(furi_record_open(RECORD_NOTIFICATION));
onewire_host = onewire_host_alloc();
onewire_host = onewire_host_alloc(&ibutton_gpio);
furi_hal_power_enable_otg();
}

Expand Down
2 changes: 1 addition & 1 deletion applications/ibutton/ibutton_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void onewire_cli_print_usage() {

static void onewire_cli_search(Cli* cli) {
UNUSED(cli);
OneWireHost* onewire = onewire_host_alloc();
OneWireHost* onewire = onewire_host_alloc(&ibutton_gpio);
uint8_t address[8];
bool done = false;

Expand Down
46 changes: 1 addition & 45 deletions firmware/targets/f7/furi_hal/furi_hal_ibutton.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <furi_hal_ibutton.h>
#include <furi_hal_interrupt.h>
#include <furi_hal_onewire.h>
#include <furi_hal_resources.h>

#include <stm32wbxx_ll_tim.h>
Expand Down Expand Up @@ -88,48 +89,3 @@ void furi_hal_ibutton_emulate_stop() {
furi_hal_ibutton->context = NULL;
}
}

void furi_hal_ibutton_start_drive() {
furi_hal_ibutton_pin_high();
furi_hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
}

void furi_hal_ibutton_start_drive_in_isr() {
furi_hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
LL_EXTI_ClearFlag_0_31(ibutton_gpio.pin);
}

void furi_hal_ibutton_start_interrupt() {
furi_hal_ibutton_pin_high();
furi_hal_gpio_init(&ibutton_gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
}

void furi_hal_ibutton_start_interrupt_in_isr() {
furi_hal_gpio_init(&ibutton_gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
LL_EXTI_ClearFlag_0_31(ibutton_gpio.pin);
}

void furi_hal_ibutton_stop() {
furi_hal_ibutton_pin_high();
furi_hal_gpio_init(&ibutton_gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}

void furi_hal_ibutton_add_interrupt(GpioExtiCallback cb, void* context) {
furi_hal_gpio_add_int_callback(&ibutton_gpio, cb, context);
}

void furi_hal_ibutton_remove_interrupt() {
furi_hal_gpio_remove_int_callback(&ibutton_gpio);
}

void furi_hal_ibutton_pin_low() {
furi_hal_gpio_write(&ibutton_gpio, false);
}

void furi_hal_ibutton_pin_high() {
furi_hal_gpio_write(&ibutton_gpio, true);
}

bool furi_hal_ibutton_pin_get_level() {
return furi_hal_gpio_read(&ibutton_gpio);
}
56 changes: 56 additions & 0 deletions firmware/targets/f7/furi_hal/furi_hal_onewire.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <furi_hal_onewire.h>
#include <furi_hal_interrupt.h>
#include <furi_hal_resources.h>

#include <stm32wbxx_ll_tim.h>
#include <stm32wbxx_ll_exti.h>

#include <furi.h>

#define FURI_HAL_IBUTTON_TIMER TIM1
#define FURI_HAL_IBUTTON_TIMER_IRQ FuriHalInterruptIdTim1UpTim16

void furi_hal_onewire_start_drive(const GpioPin* gpio) {
furi_hal_onewire_pin_high(gpio);
furi_hal_gpio_init(gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
}

void furi_hal_onewire_start_drive_in_isr(const GpioPin* gpio) {
furi_hal_gpio_init(gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
LL_EXTI_ClearFlag_0_31(gpio->pin);
}

void furi_hal_onewire_start_interrupt(const GpioPin* gpio) {
furi_hal_onewire_pin_high(gpio);
furi_hal_gpio_init(gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
}

void furi_hal_onewire_start_interrupt_in_isr(const GpioPin* gpio) {
furi_hal_gpio_init(gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
LL_EXTI_ClearFlag_0_31(gpio->pin);
}

void furi_hal_onewire_stop(const GpioPin* gpio) {
furi_hal_onewire_pin_high(gpio);
furi_hal_gpio_init(gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}

void furi_hal_onewire_add_interrupt(const GpioPin* gpio, GpioExtiCallback cb, void* context) {
furi_hal_gpio_add_int_callback(gpio, cb, context);
}

void furi_hal_onewire_remove_interrupt(const GpioPin* gpio) {
furi_hal_gpio_remove_int_callback(gpio);
}

void furi_hal_onewire_pin_low(const GpioPin* gpio) {
furi_hal_gpio_write(gpio, false);
}

void furi_hal_onewire_pin_high(const GpioPin* gpio) {
furi_hal_gpio_write(gpio, true);
}

bool furi_hal_onewire_pin_get_level(const GpioPin* gpio) {
return furi_hal_gpio_read(gpio);
}
12 changes: 6 additions & 6 deletions firmware/targets/f7/furi_hal/furi_hal_rfid.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <furi_hal_rfid.h>
#include <furi_hal_ibutton.h>
#include <furi_hal_interrupt.h>
#include <furi_hal_onewire.h>
#include <furi_hal_resources.h>
#include <furi.h>

Expand Down Expand Up @@ -69,7 +69,7 @@ void furi_hal_rfid_init() {

void furi_hal_rfid_pins_reset() {
// ibutton bus disable
furi_hal_ibutton_stop();
furi_hal_onewire_stop(&ibutton_gpio);

// pulldown rfid antenna
furi_hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
Expand All @@ -86,8 +86,8 @@ void furi_hal_rfid_pins_reset() {

void furi_hal_rfid_pins_emulate() {
// ibutton low
furi_hal_ibutton_start_drive();
furi_hal_ibutton_pin_low();
furi_hal_onewire_start_drive(&ibutton_gpio);
furi_hal_onewire_pin_low(&ibutton_gpio);

// pull pin to timer out
furi_hal_gpio_init_ex(
Expand All @@ -107,8 +107,8 @@ void furi_hal_rfid_pins_emulate() {

void furi_hal_rfid_pins_read() {
// ibutton low
furi_hal_ibutton_start_drive();
furi_hal_ibutton_pin_low();
furi_hal_onewire_start_drive(&ibutton_gpio);
furi_hal_onewire_pin_low(&ibutton_gpio);

// dont pull rfid antenna
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
Expand Down
1 change: 1 addition & 0 deletions firmware/targets/furi_hal_include/furi_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ template <unsigned int N> struct STOP_EXTERNING_ME {};
#include "furi_hal_flash.h"
#include "furi_hal_subghz.h"
#include "furi_hal_vibro.h"
#include "furi_hal_onewire.h"
#include "furi_hal_ibutton.h"
#include "furi_hal_rfid.h"
#include "furi_hal_nfc.h"
Expand Down
56 changes: 0 additions & 56 deletions firmware/targets/furi_hal_include/furi_hal_ibutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,6 @@ void furi_hal_ibutton_emulate_set_next(uint32_t period);

void furi_hal_ibutton_emulate_stop();

/**
* Sets the pin to normal mode (open collector), and sets it to float
*/
void furi_hal_ibutton_start_drive();

/**
* Sets the pin to normal mode (open collector), and clears pin EXTI interrupt.
* Used in EXTI interrupt context.
*/
void furi_hal_ibutton_start_drive_in_isr();

/**
* Sets the pin to interrupt mode (EXTI interrupt on rise or fall), and sets it to float
*/
void furi_hal_ibutton_start_interrupt();

/**
* Sets the pin to interrupt mode (EXTI interrupt on rise or fall), and clears pin EXTI interrupt.
* Used in EXTI interrupt context.
*/
void furi_hal_ibutton_start_interrupt_in_isr();

/**
* Sets the pin to analog mode, and sets it to float
*/
void furi_hal_ibutton_stop();

/**
* Attach interrupt callback to iButton pin
* @param cb callback
* @param context context
*/
void furi_hal_ibutton_add_interrupt(GpioExtiCallback cb, void* context);

/**
* Remove interrupt callback from iButton pin
*/
void furi_hal_ibutton_remove_interrupt();

/**
* Sets the pin to low
*/
void furi_hal_ibutton_pin_low();

/**
* Sets the pin to high (float in iButton pin modes)
*/
void furi_hal_ibutton_pin_high();

/**
* Get pin level
* @return true if level is high
* @return false if level is low
*/
bool furi_hal_ibutton_pin_get_level();

#ifdef __cplusplus
}
#endif
79 changes: 79 additions & 0 deletions firmware/targets/furi_hal_include/furi_hal_onewire.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @file furi_hal_onewire.h
* OneWire HAL API
*/

#pragma once

#include <stdbool.h>
#include <stdint.h>
#include "furi_hal_gpio.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* Sets the pin to normal mode (open collector), and sets it to float
* @param gpio
*/
void furi_hal_onewire_start_drive(const GpioPin* gpio);

/**
* Sets the pin to normal mode (open collector), and clears pin EXTI interrupt.
* Used in EXTI interrupt context.
* @param gpio
*/
void furi_hal_onewire_start_drive_in_isr(const GpioPin* gpio);

/**
* Sets the pin to interrupt mode (EXTI interrupt on rise or fall), and sets it to float
* @param gpio
*/
void furi_hal_onewire_start_interrupt(const GpioPin* gpio);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment which EXTI (which pin) can be used as an interrupt.
V9 table from https://docs.google.com/spreadsheets/d/1qAPFTwvMwbTp1hTAtZHlO6jpl9o-fXg49rPIQ1o7JiQ/edit?usp=sharing
(0, 1, 4, 5, 7, 8, 14).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to add this, but I'm not sure what you mean. I'm not that initimate with electronics.

Are you saying all pins on A..H are interrupt-capable if they're on EXTI{0,1,4,5,7,8,14} and all others are not?

I.e.:

/*
 * Sets the pin to interrupt mode (EXTI interrupt on rise or fall), and sets it to float
 * The following pins are valid:
 * gpio_infrared_rx, gpio_display_rst_n, gpio_ext_pc0, gpio_subghz_cs (EXTI0),
 * gpio_cc1101_g0, gpio_display_di, gpio_ext_pc1, gpio_spi_d_sck (EXTI1),
 * ... etc ...

?

I have no idea what I'm typing here, so I could be off by a mile 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @DrZlo13 : any hint is appreciated :)


/**
* Sets the pin to interrupt mode (EXTI interrupt on rise or fall), and clears pin EXTI interrupt.
* Used in EXTI interrupt context.
* @param gpio
*/
void furi_hal_onewire_start_interrupt_in_isr(const GpioPin* gpio);

/**
* Sets the pin to analog mode, and sets it to float
* @param gpio
*/
void furi_hal_onewire_stop(const GpioPin* gpio);

/**
* Attach interrupt callback to OneWire pin
* @param cb callback
* @param context context
*/
void furi_hal_onewire_add_interrupt(const GpioPin* gpio, GpioExtiCallback cb, void* context);

/**
* Remove interrupt callback from OneWire pin
*/
void furi_hal_onewire_remove_interrupt(const GpioPin* gpio);

/**
* Sets the pin to low
*/
void furi_hal_onewire_pin_low(const GpioPin* gpio);

/**
* Sets the pin to high (float in OneWire pin modes)
*/
void furi_hal_onewire_pin_high(const GpioPin* gpio);

/**
* Get pin level
* @return true if level is high
* @return false if level is low
*/
bool furi_hal_onewire_pin_get_level(const GpioPin* gpio);

#ifdef __cplusplus
}
#endif
4 changes: 2 additions & 2 deletions lib/one_wire/ibutton/ibutton_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ iButtonWorker* ibutton_worker_alloc() {
iButtonWorker* worker = malloc(sizeof(iButtonWorker));
worker->key_p = NULL;
worker->key_data = malloc(ibutton_key_get_max_size());
worker->host = onewire_host_alloc();
worker->slave = onewire_slave_alloc();
worker->host = onewire_host_alloc(&ibutton_gpio);
worker->slave = onewire_slave_alloc(&ibutton_gpio);
worker->writer = ibutton_writer_alloc(worker->host);
worker->device = onewire_device_alloc(0, 0, 0, 0, 0, 0, 0, 0);
worker->messages = furi_message_queue_alloc(1, sizeof(iButtonMessage));
Expand Down
11 changes: 8 additions & 3 deletions lib/one_wire/ibutton/ibutton_worker_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ void ibutton_worker_emulate_timer_cb(void* context) {
LevelDuration level =
protocol_dict_encoder_yield(worker->protocols, worker->protocol_to_encode);

const GpioPin* gpio_pin = onewire_host_get_gpio_pin(worker->host);

furi_hal_ibutton_emulate_set_next(level_duration_get_duration(level));

if(level_duration_get_level(level)) {
furi_hal_ibutton_pin_high();
furi_hal_onewire_pin_high(gpio_pin);
} else {
furi_hal_ibutton_pin_low();
furi_hal_onewire_pin_low(gpio_pin);
}
}

Expand All @@ -252,6 +254,8 @@ void ibutton_worker_emulate_timer_start(iButtonWorker* worker) {
const uint8_t* key_id = ibutton_key_get_data_p(worker->key_p);
const uint8_t key_size = ibutton_key_get_max_size();

const GpioPin* gpio_pin;

switch(ibutton_key_get_type(worker->key_p)) {
case iButtonKeyDS1990:
return;
Expand All @@ -267,7 +271,8 @@ void ibutton_worker_emulate_timer_start(iButtonWorker* worker) {
protocol_dict_set_data(worker->protocols, worker->protocol_to_encode, key_id, key_size);
protocol_dict_encoder_start(worker->protocols, worker->protocol_to_encode);

furi_hal_ibutton_start_drive();
gpio_pin = onewire_host_get_gpio_pin(worker->host);
furi_hal_onewire_start_drive(gpio_pin);
furi_hal_ibutton_emulate_start(0, ibutton_worker_emulate_timer_cb, worker);
}

Expand Down
Loading