Skip to content

Commit

Permalink
cleanup max number of registers
Browse files Browse the repository at this point in the history
it's actually 0x70
  • Loading branch information
dernasherbrezon committed Jul 27, 2024
1 parent 5d89dfc commit 62ee963
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion debug_registers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ make
First, obtain sx127x registers. It can be done using ```sx127x_dump_registers``` function.

```c
uint8_t registers[0x80];
uint8_t registers[MAX_NUMBER_OF_REGISTERS];
sx127x_dump_registers(registers, device);
for (int i = 0; i < sizeof(registers); i++) {
if (i != 0) {
Expand Down
5 changes: 3 additions & 2 deletions include/sx127x.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>

#define MAX_PACKET_SIZE 256
#define MAX_PACKET_SIZE 255
#define MAX_PACKET_SIZE_FSK_FIXED 2047
#define MAX_NUMBER_OF_REGISTERS 0x70

#define SX127X_OK 0 /*!< esp_err_t value indicating success (no error) */
#define SX127X_ERR_NO_MEM 0x101 /*!< Out of memory */
Expand Down Expand Up @@ -452,7 +453,7 @@ int sx127x_lora_set_implicit_header(sx127x_implicit_header_t *header, sx127x *de
*
* Output all internal registers in the current mode. Can be useful for debugging and troubleshooting.
*
* @param output Pre-allocated array where the values will be written. Should be at least 0x80 length.
* @param output Pre-allocated array where the values will be written. Should be at least MAX_NUMBER_OF_REGISTERS length.
* @param device Pointer to variable to hold the device handle
* @return
* - SX127X_ERR_INVALID_ARG if parameter is invalid
Expand Down
10 changes: 5 additions & 5 deletions src/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ int sx127x_dump_registers(uint8_t *output, sx127x *device) {
//Reading from 0x00 register will actually read from fifo
//skip it
output[0] = 0x00;
return sx127x_spi_read_buffer(0x01, output + 1, 0x7F, device->spi_device);
return sx127x_spi_read_buffer(0x01, output + 1, MAX_NUMBER_OF_REGISTERS - 1, device->spi_device);
}

void sx127x_tx_set_callback(void (*tx_callback)(sx127x *), sx127x *device) {
Expand Down Expand Up @@ -883,7 +883,7 @@ int sx127x_fsk_ook_tx_set_for_transmission_with_remaining(uint16_t data_length,

int sx127x_fsk_ook_tx_set_for_transmission(uint8_t *data, uint16_t data_length, sx127x *device) {
CHECK_FSK_OOK_MODULATION(device);
if (device->fsk_ook_format == SX127X_VARIABLE && data_length > 255) {
if (device->fsk_ook_format == SX127X_VARIABLE && data_length > MAX_PACKET_SIZE) {
return SX127X_ERR_INVALID_ARG;
}
if (device->fsk_ook_format == SX127X_FIXED && data_length > MAX_PACKET_SIZE_FSK_FIXED) {
Expand All @@ -902,7 +902,7 @@ int sx127x_fsk_ook_tx_set_for_transmission(uint8_t *data, uint16_t data_length,

int sx127x_fsk_ook_tx_set_for_transmission_with_address(uint8_t *data, uint16_t data_length, uint8_t address_to, sx127x *device) {
CHECK_FSK_OOK_MODULATION(device);
if (device->fsk_ook_format == SX127X_VARIABLE && data_length > 254) {
if (device->fsk_ook_format == SX127X_VARIABLE && data_length > (MAX_PACKET_SIZE - 1)) {
return SX127X_ERR_INVALID_ARG;
}
if (device->fsk_ook_format == SX127X_FIXED && data_length > (MAX_PACKET_SIZE_FSK_FIXED - 1)) {
Expand Down Expand Up @@ -1160,11 +1160,11 @@ int sx127x_fsk_ook_set_crc(sx127x_crc_type_t crc_type, sx127x *device) {

int sx127x_fsk_ook_set_packet_format(sx127x_packet_format_t format, uint16_t max_payload_length, sx127x *device) {
CHECK_FSK_OOK_MODULATION(device);
if (format == SX127X_FIXED && (max_payload_length == 0 || max_payload_length > 2047)) {
if (format == SX127X_FIXED && (max_payload_length == 0 || max_payload_length > MAX_PACKET_SIZE_FSK_FIXED)) {
return SX127X_ERR_INVALID_ARG;
}
// max_payload_length = 2047 in variable packet mode will disable max payload length check
if (format == SX127X_VARIABLE && (max_payload_length == 0 || (max_payload_length > 255 && max_payload_length != 2047))) {
if (format == SX127X_VARIABLE && (max_payload_length == 0 || (max_payload_length > MAX_PACKET_SIZE && max_payload_length != MAX_PACKET_SIZE_FSK_FIXED))) {
return SX127X_ERR_INVALID_ARG;
}
uint8_t msb_bits = ((max_payload_length >> 8) & 0b111);
Expand Down
4 changes: 2 additions & 2 deletions test/test_app/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void wait_for_rx_done() {
}

void print_registers() {
uint8_t registers[0x80];
uint8_t registers[MAX_NUMBER_OF_REGISTERS];
sx127x_dump_registers(registers, fixture->device);
for (int i = 0; i < sizeof(registers); i++) {
if (i != 0) {
Expand All @@ -116,7 +116,7 @@ void print_registers() {
}
TEST_CASE("sx127x_test_fsk_rx_print_registers", "[fsk]") {
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fixture_create_base(&rx_fixture_config, &fixture));
uint8_t registers[0x80];
uint8_t registers[MAX_NUMBER_OF_REGISTERS];
sx127x_dump_registers(registers, fixture->device);
for (int i = 0; i < sizeof(registers); i++) {
if (i != 0) {
Expand Down

0 comments on commit 62ee963

Please sign in to comment.