unleashed-firmware/lib/ST25RFAL002/platform.c
あく 37d7870e52
[FL-1666] Bootloader: info screen when we going to DFU. FuriHal: port SPI to LL. Cleanup. (#634)
* FuriHal: port spi to ll. Bootloader: add spi and display.
* Makefile: rollback disabled freertos introspection
* FuriHal: spi lock asserts. F6: minor cleanup port sdcard shenanigans to furi_hal_gpio.
* SdCard: port missing bits to furi-hal-gpio
* FuriHal: fix broken RX in SPI, update SPI API usage. RFAL: more asserts in SPI platform code.
* GUI: clear canvas on start. FuriHal: no pullup on radio spi bus.
* FuriHal: use check instead of assert in spi lock routines
* FuriHal: remove timeouts
* SdHal: add guard time to SDCARD CS PIN control.
* FuriHal: proper name for SPI device reconfigure routine. SdHal: one more enterprise delay and better documentation.
* Bootloader: update DFU text and add image.
* FuriHal: drop unused ST HAL modules.
* SdHal: fixed swapped hal_gpio_init_ex arguments
* SpiHal: fixed swapped hal_gpio_init_ex arguments
* IrdaHal: use hal_gpio_init instead of hal_gpio_init_ex
* RfidHal: fixed swapped hal_gpio_init_ex arguments

Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-08-12 11:48:05 +03:00

80 lines
2.5 KiB
C

#include "platform.h"
#include <assert.h>
#include <main.h>
#include <furi.h>
#include <furi-hal-spi.h>
static osThreadAttr_t platform_irq_thread_attr;
static volatile osThreadId_t platform_irq_thread_id = NULL;
static volatile PlatformIrqCallback platform_irq_callback = NULL;
static FuriHalSpiDevice* platform_st25r3916 = NULL;
static const GpioPin pin = {ST25R_INT_PORT, ST25R_INT_PIN};
void nfc_isr(void* _ctx) {
if(platform_irq_callback
&& platformGpioIsHigh(ST25R_INT_PORT, ST25R_INT_PIN)) {
osThreadFlagsSet(platform_irq_thread_id, 0x1);
}
}
void platformIrqWorker() {
while(1) {
uint32_t flags = osThreadFlagsWait(0x1, osFlagsWaitAny, osWaitForever);
if (flags & 0x1) {
platform_irq_callback();
}
}
}
void platformEnableIrqCallback() {
hal_gpio_init(&pin, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
hal_gpio_enable_int_callback(&pin);
}
void platformDisableIrqCallback() {
hal_gpio_init(&pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
hal_gpio_disable_int_callback(&pin);
}
void platformSetIrqCallback(PlatformIrqCallback callback) {
platform_irq_callback = callback;
platform_irq_thread_attr.name = "rfal_irq_worker";
platform_irq_thread_attr.stack_size = 1024;
platform_irq_thread_attr.priority = osPriorityISR;
platform_irq_thread_id = osThreadNew(platformIrqWorker, NULL, &platform_irq_thread_attr);
hal_gpio_add_int_callback(&pin, nfc_isr, NULL);
// Disable interrupt callback as the pin is shared between 2 apps
// It is enabled in rfalLowPowerModeStop()
hal_gpio_disable_int_callback(&pin);
}
HAL_StatusTypeDef platformSpiTxRx(const uint8_t *txBuf, uint8_t *rxBuf, uint16_t len) {
furi_assert(platform_st25r3916);
bool ret = false;
if (txBuf && rxBuf) {
ret = furi_hal_spi_bus_trx(platform_st25r3916->bus, (uint8_t*)txBuf, rxBuf, len, 1000);
} else if (txBuf) {
ret = furi_hal_spi_bus_tx(platform_st25r3916->bus, (uint8_t*)txBuf, len, 1000);
} else if (rxBuf) {
ret = furi_hal_spi_bus_rx(platform_st25r3916->bus, (uint8_t*)rxBuf, len, 1000);
}
if(!ret) {
asm("bkpt 1");
return HAL_ERROR;
} else {
return HAL_OK;
}
}
void platformProtectST25RComm() {
furi_assert(platform_st25r3916 == NULL);
platform_st25r3916 = (FuriHalSpiDevice*)furi_hal_spi_device_get(FuriHalSpiDeviceIdNfc);
}
void platformUnprotectST25RComm() {
furi_assert(platform_st25r3916);
furi_hal_spi_device_return(platform_st25r3916);
platform_st25r3916 = NULL;
}