Skip to content

Commit

Permalink
sync raspberrypi example with esp
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Jul 5, 2024
1 parent 432ffda commit 82fac14
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions examples/receive_fsk_raspberrypi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
// Correspond to SPI0 with chip select pin CE0 (GPIO8) on RaspberryPI
#define SPI_DEVICE "/dev/spidev0.0"
#define GPIO_DEVICE "/dev/gpiochip0"
// GPIO 27
#define GPIO_DIO1_PIN 13
#define GPIO_DIO2_PIN 19
#define GPIO_DIO3_PIN 26
#define GPIO_DIO0_PIN 27
#define GPIO_RESET_PIN 6
#define GPIO_POLL_TIMEOUT -1

#define LINUX_ERROR_CHECK(x) \
Expand Down Expand Up @@ -91,7 +94,7 @@ int reset_sx127x() {
return EXIT_FAILURE;
}
struct gpiohandle_request rq;
rq.lineoffsets[0] = 6;
rq.lineoffsets[0] = GPIO_RESET_PIN;
rq.lines = 1;
rq.flags = GPIOHANDLE_REQUEST_OUTPUT;
strcpy(rq.consumer_label, "sx127x_reset");
Expand All @@ -117,7 +120,7 @@ int setup_and_wait_for_interrupt(sx127x *device) {
perror("unable to open device");
return EXIT_FAILURE;
}
uint8_t gpios[] = {27, 13, 19, 26};
uint8_t gpios[] = {GPIO_DIO0_PIN, GPIO_DIO1_PIN, GPIO_DIO2_PIN, GPIO_DIO3_PIN};
int gpios_length = sizeof(gpios);
struct pollfd pfd[4];
for (int i = 0; i < gpios_length; i++) {
Expand Down Expand Up @@ -180,14 +183,12 @@ int main() {
sx127x *device = NULL;
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_opmod(SX127x_MODE_STANDBY, SX127x_MODULATION_FSK, device));
LINUX_ERROR_CHECK(sx127x_set_frequency(437200000, device));
// perform calibration for the selected frequency
LINUX_ERROR_CHECK(sx127x_fsk_ook_rx_calibrate(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(10000.0, 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));
Expand All @@ -196,7 +197,7 @@ int main() {
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_PREAMBLE, 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));

Expand Down

0 comments on commit 82fac14

Please sign in to comment.