Skip to content

Commit

Permalink
add support for fully static memory allocation
Browse files Browse the repository at this point in the history
this is breaking API change.
  • Loading branch information
dernasherbrezon committed Aug 5, 2024
1 parent 4ccb5e0 commit cb0168e
Show file tree
Hide file tree
Showing 25 changed files with 467 additions and 498 deletions.
51 changes: 25 additions & 26 deletions examples/receive_fsk/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//#define DIO1 35
//#define DIO2 34

sx127x *device = NULL;
sx127x device;
TaskHandle_t handle_interrupt;
int total_packets_received = 0;
static const char *TAG = "sx127x";
Expand Down Expand Up @@ -100,39 +100,38 @@ void app_main() {
spi_device_handle_t spi_device;
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi_device));
ESP_ERROR_CHECK(sx127x_create(spi_device, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, device));
ESP_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, &device));
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, &device));
uint8_t syncWord[] = {0x12, 0xAD};
ESP_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NONE, 0, 0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_NRZ, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_VARIABLE, 255, device));
ESP_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NONE, 0, 0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_NRZ, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_VARIABLE, 255, &device));
ESP_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(&device));

sx127x_rx_set_callback(rx_callback, device);
sx127x_rx_set_callback(rx_callback, &device);

BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, device, 2, &handle_interrupt, xPortGetCoreID());
BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID());
if (task_code != pdPASS) {
ESP_LOGE(TAG, "can't create task %d", task_code);
sx127x_destroy(device);
return;
}

gpio_install_isr_service(0);
setup_gpio_interrupts((gpio_num_t) DIO0, device);
setup_gpio_interrupts((gpio_num_t) DIO1, device);
setup_gpio_interrupts((gpio_num_t) DIO2, device);
setup_gpio_interrupts((gpio_num_t) DIO0, &device);
setup_gpio_interrupts((gpio_num_t) DIO1, &device);
setup_gpio_interrupts((gpio_num_t) DIO2, &device);

ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device));
}
49 changes: 24 additions & 25 deletions examples/receive_fsk_beacon/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//#define DIO1 35
//#define DIO2 34

sx127x *device = NULL;
sx127x device;
TaskHandle_t handle_interrupt;
int total_packets_received = 0;
static const char *TAG = "sx127x";
Expand Down Expand Up @@ -98,38 +98,37 @@ void app_main() {
spi_device_handle_t spi_device;
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi_device));
ESP_ERROR_CHECK(sx127x_create(spi_device, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, device));
ESP_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, &device));
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, &device));
uint8_t syncWord[] = {0x12, 0xAD};
ESP_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NONE, 0, 0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_NRZ, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_FIXED, 6, device));
ESP_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NONE, 0, 0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_NRZ, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_FIXED, 6, &device));
ESP_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, &device));

sx127x_rx_set_callback(rx_callback, device);
sx127x_rx_set_callback(rx_callback, &device);

BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, device, 2, &handle_interrupt, xPortGetCoreID());
BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID());
if (task_code != pdPASS) {
ESP_LOGE(TAG, "can't create task %d", task_code);
sx127x_destroy(device);
return;
}

gpio_install_isr_service(0);
setup_gpio_interrupts((gpio_num_t)DIO0, device);
setup_gpio_interrupts((gpio_num_t)DIO1, device);
setup_gpio_interrupts((gpio_num_t)DIO2, device);
setup_gpio_interrupts((gpio_num_t)DIO0, &device);
setup_gpio_interrupts((gpio_num_t)DIO1, &device);
setup_gpio_interrupts((gpio_num_t)DIO2, &device);

ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device));
}
49 changes: 24 additions & 25 deletions examples/receive_fsk_filtered/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//#define DIO1 35
//#define DIO2 34

sx127x *device = NULL;
sx127x device;
TaskHandle_t handle_interrupt;
int total_packets_received = 0;
static const char *TAG = "sx127x";
Expand Down Expand Up @@ -90,38 +90,37 @@ void app_main() {
spi_device_handle_t spi_device;
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi_device));
ESP_ERROR_CHECK(sx127x_create(spi_device, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, device));
ESP_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, &device));
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, &device));
uint8_t syncWord[] = {0x12, 0xAD};
ESP_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NODE_AND_BROADCAST, 0x11, 0x00, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_NRZ, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_VARIABLE, 255, device));
ESP_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NODE_AND_BROADCAST, 0x11, 0x00, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_NRZ, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_VARIABLE, 255, &device));
ESP_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, &device));

sx127x_rx_set_callback(rx_callback, device);
sx127x_rx_set_callback(rx_callback, &device);

BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, device, 2, &handle_interrupt, xPortGetCoreID());
BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID());
if (task_code != pdPASS) {
ESP_LOGE(TAG, "can't create task %d", task_code);
sx127x_destroy(device);
return;
}

gpio_install_isr_service(0);
setup_gpio_interrupts((gpio_num_t)DIO0, device);
setup_gpio_interrupts((gpio_num_t)DIO1, device);
setup_gpio_interrupts((gpio_num_t)DIO2, device);
setup_gpio_interrupts((gpio_num_t)DIO0, &device);
setup_gpio_interrupts((gpio_num_t)DIO1, &device);
setup_gpio_interrupts((gpio_num_t)DIO2, &device);

ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device));
}
49 changes: 24 additions & 25 deletions examples/receive_fsk_fixed/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//#define DIO1 35
//#define DIO2 34

sx127x *device = NULL;
sx127x device;
TaskHandle_t handle_interrupt;
int total_packets_received = 0;
static const char *TAG = "sx127x";
Expand Down Expand Up @@ -90,38 +90,37 @@ void app_main() {
spi_device_handle_t spi_device;
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &dev_cfg, &spi_device));
ESP_ERROR_CHECK(sx127x_create(spi_device, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, device));
ESP_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, &device));
ESP_ERROR_CHECK(sx127x_set_frequency(437200012, &device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, &device));
uint8_t syncWord[] = {0x12, 0xAD};
ESP_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NONE, 0, 0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_SCRAMBLED, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_FIXED, 2047, device));
ESP_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NONE, 0, 0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_SCRAMBLED, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_FIXED, 2047, &device));
ESP_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, &device));
ESP_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, &device));

sx127x_rx_set_callback(rx_callback, device);
sx127x_rx_set_callback(rx_callback, &device);

BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, device, 2, &handle_interrupt, xPortGetCoreID());
BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID());
if (task_code != pdPASS) {
ESP_LOGE(TAG, "can't create task %d", task_code);
sx127x_destroy(device);
return;
}

gpio_install_isr_service(0);
setup_gpio_interrupts((gpio_num_t)DIO0, device);
setup_gpio_interrupts((gpio_num_t)DIO1, device);
setup_gpio_interrupts((gpio_num_t)DIO2, device);
setup_gpio_interrupts((gpio_num_t)DIO0, &device);
setup_gpio_interrupts((gpio_num_t)DIO1, &device);
setup_gpio_interrupts((gpio_num_t)DIO2, &device);

ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device));
ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device));
}
48 changes: 24 additions & 24 deletions examples/receive_fsk_raspberrypi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,30 +185,30 @@ int main() {
int max_speed = 4000000;
LINUX_ERROR_CHECK(ioctl(spi_device_fd, SPI_IOC_WR_MAX_SPEED_HZ, &max_speed));

sx127x *device = NULL;
sx127x device;
LINUX_ERROR_CHECK(sx127x_create(&spi_device_fd, &device));
LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, device));
LINUX_ERROR_CHECK(sx127x_set_frequency(437200000, device));
LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, device));
LINUX_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, device));
LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_SLEEP, SX127x_MODULATION_FSK, &device));
LINUX_ERROR_CHECK(sx127x_set_frequency(437200000, &device));
LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_bitrate(4800.0, &device));
LINUX_ERROR_CHECK(sx127x_fsk_set_fdev(5000.0, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_auto(true, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_afc_bandwidth(20000.0, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_bandwidth(5000.0, &device));
uint8_t syncWord[] = {0x12, 0xAD};
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NONE, 0, 0, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_NRZ, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_VARIABLE, 255, device));
LINUX_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(device));

sx127x_rx_set_callback(rx_callback, device);
LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, device));

return setup_and_wait_for_interrupt(device);
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_syncword(syncWord, 2, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_address_filtering(SX127X_FILTER_NONE, 0, 0, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_packet_encoding(SX127X_NRZ, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_packet_format(SX127X_VARIABLE, 255, &device));
LINUX_ERROR_CHECK(sx127x_fsk_set_data_shaping(SX127X_BT_0_5, SX127X_PA_RAMP_10, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_set_crc(SX127X_CRC_CCITT, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_trigger(SX127X_RX_TRIGGER_RSSI_PREAMBLE, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_rssi_config(SX127X_8, 0, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_set_preamble_detector(true, 2, 0x0A, &device));
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(&device));

sx127x_rx_set_callback(rx_callback, &device);
LINUX_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device));

return setup_and_wait_for_interrupt(&device);
}
Loading

0 comments on commit cb0168e

Please sign in to comment.