[FL-1146] GD0 self-test
This commit is contained in:
@@ -18,7 +18,10 @@ const size_t input_pins_count = sizeof(input_pins) / sizeof(InputPin);
|
||||
|
||||
const GpioPin vibro_gpio = {.port = VIBRO_GPIO_Port, .pin = VIBRO_Pin};
|
||||
const GpioPin ibutton_gpio = {.port = iBTN_GPIO_Port, .pin = iBTN_Pin};
|
||||
const GpioPin cc1101_g0_gpio = {.port = CC1101_G0_GPIO_Port, .pin = CC1101_G0_Pin};
|
||||
|
||||
const GpioPin gpio_cc1101_g0 = {.port = CC1101_G0_GPIO_Port, .pin = CC1101_G0_Pin};
|
||||
const GpioPin gpio_rf_sw_0 = {.port = RF_SW_0_GPIO_Port, .pin = RF_SW_0_Pin};
|
||||
const GpioPin gpio_rf_sw_1 = {.port = RF_SW_1_GPIO_Port, .pin = RF_SW_1_Pin};
|
||||
|
||||
const GpioPin gpio_subghz_cs = {.port = CC1101_CS_GPIO_Port, .pin = CC1101_CS_Pin};
|
||||
const GpioPin gpio_display_cs = {.port = DISPLAY_CS_GPIO_Port, .pin = DISPLAY_CS_Pin};
|
||||
|
@@ -55,7 +55,10 @@ extern const size_t input_pins_count;
|
||||
|
||||
extern const GpioPin vibro_gpio;
|
||||
extern const GpioPin ibutton_gpio;
|
||||
extern const GpioPin cc1101_g0_gpio;
|
||||
|
||||
extern const GpioPin gpio_cc1101_g0;
|
||||
extern const GpioPin gpio_rf_sw_0;
|
||||
extern const GpioPin gpio_rf_sw_1;
|
||||
|
||||
extern const GpioPin gpio_subghz_cs;
|
||||
extern const GpioPin gpio_display_cs;
|
||||
|
@@ -1,10 +1,11 @@
|
||||
#include "api-hal-subghz.h"
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
|
||||
#include <api-hal-gpio.h>
|
||||
#include <api-hal-spi.h>
|
||||
#include <api-hal-resources.h>
|
||||
#include <furi.h>
|
||||
#include <cc1101.h>
|
||||
#include <stdio.h>
|
||||
#include "main.h"
|
||||
|
||||
static const uint8_t api_hal_subghz_preset_ook_async_regs[][2] = {
|
||||
/* Base setting */
|
||||
@@ -37,17 +38,24 @@ static const uint8_t api_hal_subghz_preset_2fsk_packet_patable[8] = {
|
||||
};
|
||||
|
||||
void api_hal_subghz_init() {
|
||||
LL_GPIO_SetPinMode(RF_SW_0_GPIO_Port, RF_SW_0_Pin, LL_GPIO_MODE_OUTPUT);
|
||||
LL_GPIO_SetPinSpeed(RF_SW_0_GPIO_Port, RF_SW_0_Pin, LL_GPIO_SPEED_FREQ_LOW);
|
||||
LL_GPIO_SetPinOutputType(RF_SW_0_GPIO_Port, RF_SW_0_Pin, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
LL_GPIO_SetPinMode(RF_SW_1_GPIO_Port, RF_SW_1_Pin, LL_GPIO_MODE_OUTPUT);
|
||||
LL_GPIO_SetPinSpeed(RF_SW_1_GPIO_Port, RF_SW_1_Pin, LL_GPIO_SPEED_FREQ_LOW);
|
||||
LL_GPIO_SetPinOutputType(RF_SW_1_GPIO_Port, RF_SW_1_Pin, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
hal_gpio_init(&gpio_rf_sw_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_init(&gpio_rf_sw_1, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
// Reset and shutdown
|
||||
cc1101_reset(device);
|
||||
cc1101_write_reg(device, CC1101_IOCFG0, 0x2E); // High impedance 3-state
|
||||
// Prepare GD0 for power on self test
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
// GD0 low
|
||||
cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
while(hal_gpio_read(&gpio_cc1101_g0) != false);
|
||||
// GD0 high
|
||||
cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
while(hal_gpio_read(&gpio_cc1101_g0) != true);
|
||||
// Reset GD0 to floating state
|
||||
cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
// Turn off oscillator
|
||||
cc1101_shutdown(device);
|
||||
api_hal_spi_device_return(device);
|
||||
}
|
||||
@@ -164,18 +172,18 @@ uint32_t api_hal_subghz_set_frequency(uint32_t value) {
|
||||
|
||||
void api_hal_subghz_set_path(ApiHalSubGhzPath path) {
|
||||
if (path == ApiHalSubGhzPath1) {
|
||||
LL_GPIO_ResetOutputPin(RF_SW_0_GPIO_Port, RF_SW_0_Pin);
|
||||
LL_GPIO_SetOutputPin(RF_SW_1_GPIO_Port, RF_SW_1_Pin);
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
hal_gpio_write(&gpio_rf_sw_1, 1);
|
||||
} else if (path == ApiHalSubGhzPath2) {
|
||||
LL_GPIO_SetOutputPin(RF_SW_0_GPIO_Port, RF_SW_0_Pin);
|
||||
LL_GPIO_ResetOutputPin(RF_SW_1_GPIO_Port, RF_SW_1_Pin);
|
||||
hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
hal_gpio_write(&gpio_rf_sw_1, 0);
|
||||
} else if (path == ApiHalSubGhzPath3) {
|
||||
LL_GPIO_SetOutputPin(RF_SW_0_GPIO_Port, RF_SW_0_Pin);
|
||||
LL_GPIO_SetOutputPin(RF_SW_1_GPIO_Port, RF_SW_1_Pin);
|
||||
hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
hal_gpio_write(&gpio_rf_sw_1, 1);
|
||||
} else if (path == ApiHalSubGhzPathIsolate) {
|
||||
LL_GPIO_ResetOutputPin(RF_SW_0_GPIO_Port, RF_SW_0_Pin);
|
||||
LL_GPIO_ResetOutputPin(RF_SW_1_GPIO_Port, RF_SW_1_Pin);
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
hal_gpio_write(&gpio_rf_sw_1, 0);
|
||||
} else {
|
||||
|
||||
furi_check(0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user