Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentação do código #6

Merged
merged 71 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
c07b219
:busts_in_silhouette: Add Code of Conduct
LucasHaug Oct 7, 2020
0d07d50
:page_facing_up: Add License
LucasHaug Oct 7, 2020
11e7863
:pencil: Add doxyfile and :art: css for generated doc
LucasHaug Oct 10, 2020
f0a1349
:see_no_evil: Add .gitignore
LucasHaug Oct 10, 2020
9b13a70
:memo: Update README
LucasHaug Oct 10, 2020
bc79a2b
:art: Update badges
LucasHaug Oct 10, 2020
abff2c0
:busts_in_silhouette: Add contributors
LucasHaug Oct 10, 2020
9691113
:busts_in_silhouette: Add @Berbardo as a contributor
LucasHaug Oct 10, 2020
4ca7043
:see_no_evil: Update .gitignore
LucasHaug Oct 18, 2020
f469e49
:truck: Create assets folder and move files
LucasHaug Oct 18, 2020
e24b68c
:pencil: Update hw config in README
LucasHaug Oct 18, 2020
96f43eb
:camera: Add hw config images
LucasHaug Oct 18, 2020
2101d36
:pencil: Add cube configuration to the README
LucasHaug Oct 19, 2020
e6c3cdf
:pencil: Update how to use the library
LucasHaug Oct 20, 2020
277167f
:art: Fix emoji
LucasHaug Oct 20, 2020
ccdcac7
:pencil: Add `rf24_delay` to the README
LucasHaug Oct 20, 2020
2bde415
:pencil: Fix spelling
LucasHaug Oct 20, 2020
a5507d0
:bug: Fix forgotten CSN
LucasHaug Oct 21, 2020
a415005
:pencil: Add initializing subsection
LucasHaug Oct 21, 2020
c07dac2
:pencil: Add detail about the tutorial
LucasHaug Oct 21, 2020
82e90c4
:pencil: Fix spelling
LucasHaug Oct 21, 2020
eb8d2c3
:pencil: Add transmissor tutorial
LucasHaug Oct 22, 2020
30fa304
:pencil: Add receiver text
LucasHaug Oct 22, 2020
aa6a743
:pencil: Fix spelling
LucasHaug Oct 22, 2020
be0a8d3
:bug: Add debug infos
LucasHaug Oct 30, 2020
69bf3aa
:art: Change emoji
LucasHaug Oct 30, 2020
732b23c
:art: Add formatting section
LucasHaug Oct 30, 2020
be38347
:sparkles: Add uncrustify
LucasHaug Oct 30, 2020
79fd1d6
:pencil: Update formatting section
LucasHaug Oct 30, 2020
d1b3c5a
:busts_in_silhouette: Add Contributing
LucasHaug Oct 30, 2020
f25b046
:truck: Rename Contributing in pt
LucasHaug Oct 30, 2020
a717b0d
:globe_with_meridians: Translate contributing
LucasHaug Oct 31, 2020
cba34de
:pencil: Fix links and gramatic
LucasHaug Oct 31, 2020
bec7d0f
:truck: Add README pt-br
LucasHaug Oct 31, 2020
7ba9387
:pencil2: Add README
LucasHaug Oct 31, 2020
0f5f651
:pencil: Add default all-contributors message
LucasHaug Oct 31, 2020
00ea236
:pencil: Update README index
LucasHaug Oct 31, 2020
047e6ba
:globe_with_meridians: Translate README
LucasHaug Oct 31, 2020
c319bd8
:pencil: Fix links and gramatics
LucasHaug Oct 31, 2020
6265f49
:pencil: Update code documentation
LucasHaug Oct 31, 2020
700afdb
:recycle: Refactor code
LucasHaug Oct 31, 2020
644b497
:pencil: Update documentation
LucasHaug Oct 31, 2020
27070ce
:memo: Update READMEs
LucasHaug Oct 31, 2020
f28f0b0
:wrench: Add uncrustify.cfg
LucasHaug Oct 31, 2020
bf031e9
:art: Format files
LucasHaug Oct 31, 2020
f306729
:art: Format rf24_debug manually
LucasHaug Oct 31, 2020
d2cf06e
:see_no_evil: Add newline to .gitignore
LucasHaug Oct 31, 2020
ab62cef
:memo: Update comments
LucasHaug Oct 31, 2020
a90d6e4
:pencil: Fix spelling
LucasHaug Oct 31, 2020
463b5cb
:pencil: Fix README section title
LucasHaug Oct 31, 2020
92ae46c
:recycle: Change bit shift macro
LucasHaug Oct 31, 2020
84105fb
:recycle: Remove magic numbers
LucasHaug Oct 31, 2020
df278dc
Update CONTRIBUTING.md
LucasHaug Oct 31, 2020
bda5a82
Update CONTRIBUTING.md
LucasHaug Oct 31, 2020
49760dd
Update CONTRIBUTING.md
LucasHaug Oct 31, 2020
79f13ca
Update CONTRIBUTING.md
LucasHaug Oct 31, 2020
834bf30
Update README.md
LucasHaug Oct 31, 2020
541fcba
:ok_hand: Update README and Contributing
LucasHaug Oct 31, 2020
e69a643
:busts_in_silhouette: Update @d-nery as a contributor
LucasHaug Oct 31, 2020
a765ce3
:busts_in_silhouette: Update @lucastrschneider as a contributor
LucasHaug Oct 31, 2020
9dea2b3
:ok_hand: Fix spelling and code consistency
LucasHaug Oct 31, 2020
6644fd4
:pencil: Correct grammar
LucasHaug Oct 31, 2020
f7bfbe4
Update CONTRIBUTING.md
LucasHaug Nov 5, 2020
1bc6473
:pencil: Fix spelling in README
LucasHaug Nov 25, 2020
aacafed
:pencil: Fix spelling in CONTRIBUTING
LucasHaug Nov 25, 2020
4b24438
:pencil: :brazil: Correct spelling in README and CONTRIBUTING
LucasHaug Nov 25, 2020
9505d5c
:pencil: Correct spelling
LucasHaug Nov 25, 2020
49fa4d6
:busts_in_silhouette: Update @FelipeGdM as a contributor
LucasHaug Nov 25, 2020
f16d498
:pencil: Add assets folder to README
LucasHaug Nov 26, 2020
a277f01
:pencil: Correct spelling
LucasHaug Nov 26, 2020
5a42775
:pencil: Correct grammar
LucasHaug Nov 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Para a versão em PT-BR 🇧🇷 desse documento, [veja aqui](CONTRIBUTING.pt-br

First of all, thanks for your interest! We really appreciate the participation of the community! ✨

Here we describe a set of guidelines when contributing to the VSS simulation. These are not strict rules, so use your best judgment, and in case you have questions, contact us on [email protected].
Here we describe a set of guidelines when contributing to STM32RF24. These are not strict rules, so use your best judgment, and in case you have questions, contact us on [email protected].

Please note that this project is released with a [Contributor Code of Conduct](./CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.

Expand Down Expand Up @@ -56,7 +56,7 @@ A few recomendations:

## Styleguide 💄

### Formatação do código
### Code formatting

The code is formatted following specific rules, for more information on how to ensure that your code is formatted correctly, see the [🎨 Formatting](./README.md#-formatting) section on the README.

Expand All @@ -69,7 +69,7 @@ There are some guidelines for organizing C code that should be followed.

― Harold Abelson, Structure and Interpretation of Computer Programs

#### Scopes
#### Variables and functions scopes

Always reduce the scopes of the to the minimum possible, avoiding global, external and static variables, giving preference to local variables. The same is ture for functions, do not create public functions if they are only to be used within a file, leave them private.
LucasHaug marked this conversation as resolved.
Show resolved Hide resolved
LucasHaug marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -94,17 +94,13 @@ For more naming tips, see the article ["How To Create Meaningful Names In Code"]

#### Variable types

Make coherent choices for your variable types and your functions return types, besides its parameters, for examples, do not use `float` if your variable is a unit counter.

Make a consistent choice for the types of variables and types of return of functions, in addition to their parameters, for example, do not use `float` if your variable will be a unit counter.

Além disso, para variáveis inteiras faça distinção entre `signed` e `unsigned` e especifique seu tamanho em bits, isso garante mais controle sobre os valores que cada variável pode ter, como também otimiza a ocupação da memória. Para isso utilize a biblioteca `stdint.h`, podendo assim, por exemplo, se utilizar os tipos `uint8_t` para inteiros de 8 bits sem sinal e `int16_t` para inteiros de 16 bits com sinal.
Make coherent choices for your variable types and your functions return and parameters types. For examples, do not use `float` if your variable is a unit counter.

Besides that, for integer variables, distinguish between `signed` and `unsigned` and specify their size in bits, this ensures more control over the values that each variable can have, as well as optimizes the memory occupation. To do this, use the `stdint.h` library, than, for example, you can use the types `uint8_t` for unsigned 8-bit integers and `int16_t` for signed 16-bit integers.

#### Magic numbers/Constants

Avoid [magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)) in your code, in addition to obscuring the understanding of it, they also make maintenance difficult. To solve this, use constants defined with `#define` at the beginning of your code.
Avoid [magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)) in your code. In addition to decreasing readability, they also make maintenance difficult. To solve this, use constants defined with `#define` at the beginning of your code.

### Git commit messages

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.pt-br.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Existem algumas diretrizes de organização de código em C que devem seguidas.

― Harold Abelson, Structure and Interpretation of Computer Programs

#### Escopos
#### Escopos de variáveis e funções

Reduza sempre os escopos das variáveis ao menor possível, evitando variáveis globais, externas e estáticas, dando preferência para variáveis locais. O mesmo é válido para funções, não crie funções públicas se elas so forem ser usadas dentro de um arquivo, deixe elas privadas.

Expand Down Expand Up @@ -98,7 +98,7 @@ Além disso, para variáveis inteiras faça distinção entre `signed` e `unsign

#### Números mágicos/Constantes

Evite [números mágicos](https://pt.wikipedia.org/wiki/N%C3%BAmero_m%C3%A1gico_(programa%C3%A7%C3%A3o_de_sistemas)) no meio do código, além de eles obscurecerem o entendimento do mesmo, também dificultam a manutenção. Para contornar isso, utilize constantes definidas com `#define` no ínicio do seu código.
Evite [números mágicos](https://pt.wikipedia.org/wiki/N%C3%BAmero_m%C3%A1gico_(programa%C3%A7%C3%A3o_de_sistemas)) no meio do código. Além de eles dificultarem a leitura do mesmo, também dificultam a manutenção. Para contornar isso, utilize constantes definidas com `#define` no ínicio do seu código.
LucasHaug marked this conversation as resolved.
Show resolved Hide resolved

### Menssagens de commit

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Para a versão em PT-BR 🇧🇷 desse documento, [veja aqui](./README.pt-br.md)

## 🎉 Intro

This repository contains a library to handle Nordic Semiconductor's radio frequency module nRF24L01, whose datasheet can be viewed [here](docs/Nordic_Semiconductor-NRF24L01-datasheet.pdf), when using the microcontrollers of the [STM32] family [STM32](https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html).
This repository contains a library to handle Nordic Semiconductor's radio frequency module nRF24L01, whose datasheet can be viewed [here](docs/Nordic_Semiconductor-NRF24L01-datasheet.pdf), when using the microcontrollers of the [STM32](https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html) family.

This library was made to be used as a submodule in the [STM32ProjectTemplate](https://github.com/ThundeRatz/STM32ProjectTemplate).

Expand All @@ -60,7 +60,7 @@ sudo apt install uncrustify
On Windows, download the .zip from [SourceForge](https://sourceforge.net/projects/uncrustify/files/). Add the location of the executable in the `PATH` environment variable.


## 📦 Adding a submodule
## 📦 Git Submodules

As stated, this library functions as a submodule. In this way, it is easier to choose the version of the library that will be used in the project, also allowing its development in parallel.

Expand Down Expand Up @@ -147,7 +147,7 @@ To configure your hardware, you must first analyze the pinout of the nRF24L01 mo

![nRF24L01 Module's Pinout](./assets/img/nrf24l01_pinout.png)

The module uses SPI (Serial Protocol Interface) to communicate with the microcontroller (to learn more about SPI, I recommend this article [here](https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi/all) from Sparkfun), so four pins are required for this communication, SCK, MISO, MOSI and CSN. The CSN is a GPIO pin, while the others are dedicated pins.
The module uses SPI (Serial Protocol Interface) to communicate with the microcontroller (to learn more about SPI, we recommend this article [here](https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi/all) from Sparkfun), so four pins are required for this communication, SCK, MISO, MOSI and CSN. The CSN is a GPIO pin, while the others are dedicated pins.

In addition, a GPIO pin connected to the CE (Chip Enable) is needed, which is used to control the module, enabling the transition between the states of the module's finite state machine.

Expand Down Expand Up @@ -391,7 +391,7 @@ if ((device_status = rf24_available(p_dev, NULL)) == RF24_SUCCESS) {

### 🐛 Debugging

To debug your code it is possible to use the functions of the file `rf24_debug.c/.h`, but for this it is also necessary to define a `printf` function. For ease of use, I recommend adding the [SEGGER_RTT](https://github.com/ThundeRatz/SEGGER_RTT) to the project. After adding it, having called the debugging functions in your code, to see what is being "printed" by the functions, run in the terminal, being at the root of your project:
To debug your code it is possible to use the functions of the file `rf24_debug.c/.h`, but for this it is also necessary to define a `printf` function. For ease of use, we recommend adding the [SEGGER_RTT](https://github.com/ThundeRatz/SEGGER_RTT) to the project. After adding it, having called the debugging functions in your code, to see what is being "printed" by the functions, run in the terminal, being at the root of your project:

```C
make rtt
Expand Down
4 changes: 3 additions & 1 deletion inc/rf24.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef enum rf24_status {
RF24_BUFFER_TOO_SMALL = 5,
RF24_INTERRUPT_NOT_CLEARED = 6,
RF24_INVALID_PARAMETERS = 7,
RF24_UNKNOWN_ERRO = 8,
RF24_UNKNOWN_ERROR = 8,
} rf24_status_t;

/**
Expand Down Expand Up @@ -151,6 +151,8 @@ rf24_status_t rf24_set_channel(rf24_dev_t* p_dev, uint8_t ch);
* @param p_dev Pointer to rf24 device.
*
* @return Channel value.
* @retval 0xFF Returns 0xFF when got an error, because
* channel value can't be bigger than 125.
*/
uint8_t rf24_get_channel(rf24_dev_t* p_dev);

Expand Down
43 changes: 30 additions & 13 deletions src/rf24.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,28 @@
*/
#define MAX_NUM_OF_PIPES 6

/**
* @brief Error value for status register.
*
* @note Bit 7 only allows 0, so 0xFF represents an erro value.
LucasHaug marked this conversation as resolved.
Show resolved Hide resolved
*/
#define STATUS_REG_ERROR_VALUE 0xFF

/**
* @brief Error value for channel.
*
* @note The max channel value is 125, so 0xFF represents an erro value.
*/
#define CHANNEL_ERROR_VALUE 0xFF

/*****************************************
* Private Macros
*****************************************/

#define BIT_SHIFT_LEFT(bits) (1 << (bits))
/**
* @brief Get bit value
*/
#define _BV(num) (1 << (num))

/*****************************************
* Private Variables
Expand Down Expand Up @@ -175,9 +192,9 @@ rf24_status_t rf24_init(rf24_dev_t* p_dev) {
}

if (dev_status == RF24_SUCCESS) {
// If setup is 0 or ff then there was no response from module
// If setup is 0x00 or 0xFF then there was no response from module
LucasHaug marked this conversation as resolved.
Show resolved Hide resolved
if ((rf_setup_reg.value == 0) || (rf_setup_reg.value == 0xFF)) {
dev_status = RF24_UNKNOWN_ERRO;
dev_status = RF24_UNKNOWN_ERROR;
}
}

Expand Down Expand Up @@ -253,7 +270,7 @@ uint8_t rf24_get_channel(rf24_dev_t* p_dev) {
dev_status = (platform_status == RF24_PLATFORM_SUCCESS) ? (RF24_SUCCESS) : (RF24_ERROR_CONTROL_INTERFACE);

if (dev_status != RF24_SUCCESS) {
return 0xFF; // Invalid value, meaning error
return CHANNEL_ERROR_VALUE;
}

return reg.rf_ch;
Expand Down Expand Up @@ -319,7 +336,7 @@ rf24_status_t rf24_set_datarate(rf24_dev_t* p_dev, rf24_datarate_t datarate) {

if (dev_status == RF24_SUCCESS) {
if (temp_reg != reg_rf_setup.value) {
dev_status = RF24_UNKNOWN_ERRO;
dev_status = RF24_UNKNOWN_ERROR;
}
}
}
Expand Down Expand Up @@ -352,7 +369,7 @@ rf24_status_t rf24_set_output_power(rf24_dev_t* p_dev, rf24_output_power_t outpu

if (dev_status == RF24_SUCCESS) {
if (temp_reg != reg_rf_setup.value) {
dev_status = RF24_UNKNOWN_ERRO;
dev_status = RF24_UNKNOWN_ERROR;
}
}
}
Expand Down Expand Up @@ -439,7 +456,7 @@ rf24_status_t rf24_open_reading_pipe(rf24_dev_t* p_dev, uint8_t pipe_number, uin
}

if (dev_status == RF24_SUCCESS) {
reg_en_rx_addr.value |= BIT_SHIFT_LEFT(m_child_pipe_enable[pipe_number]);
reg_en_rx_addr.value |= _BV(m_child_pipe_enable[pipe_number]);
platform_status = rf24_platform_write_reg8(&(p_dev->platform_setup), NRF24L01_REG_EN_RXADDR,
reg_en_rx_addr.value);
dev_status = (platform_status == RF24_PLATFORM_SUCCESS) ? (RF24_SUCCESS) : (RF24_ERROR_CONTROL_INTERFACE);
Expand All @@ -461,7 +478,7 @@ rf24_status_t rf24_close_reading_pipe(rf24_dev_t* p_dev, uint8_t pipe_number) {
}

if (dev_status == RF24_SUCCESS) {
reg_en_rx_addr.value &= (~BIT_SHIFT_LEFT(m_child_pipe_enable[pipe_number]));
reg_en_rx_addr.value &= (~_BV(m_child_pipe_enable[pipe_number]));
platform_status = rf24_platform_write_reg8(&(p_dev->platform_setup), NRF24L01_REG_EN_RXADDR,
reg_en_rx_addr.value);
dev_status = (platform_status == RF24_PLATFORM_SUCCESS) ? (RF24_SUCCESS) : (RF24_ERROR_CONTROL_INTERFACE);
Expand All @@ -481,8 +498,8 @@ rf24_status_t rf24_start_listening(rf24_dev_t* p_dev) {
platform_status = rf24_platform_read_reg8(&(p_dev->platform_setup), NRF24L01_REG_CONFIG, &(reg_config.value));
dev_status = (platform_status == RF24_PLATFORM_SUCCESS) ? (RF24_SUCCESS) : (RF24_ERROR_CONTROL_INTERFACE);

reg_config.value |= BIT_SHIFT_LEFT(PRIM_RX);
reg_status.value = (BIT_SHIFT_LEFT(RX_DR) | BIT_SHIFT_LEFT(TX_DS) | BIT_SHIFT_LEFT(MAX_RT));
reg_config.value |= _BV(PRIM_RX);
reg_status.value = (_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT));

if (dev_status == RF24_SUCCESS) {
platform_status = rf24_platform_write_reg8(&(p_dev->platform_setup), NRF24L01_REG_CONFIG, reg_config.value);
Expand Down Expand Up @@ -559,7 +576,7 @@ rf24_status_t rf24_stop_listening(rf24_dev_t* p_dev) {
dev_status = (platform_status == RF24_PLATFORM_SUCCESS) ? (RF24_SUCCESS) : (RF24_ERROR_CONTROL_INTERFACE);

if (dev_status == RF24_SUCCESS) {
reg_config.value &= (~BIT_SHIFT_LEFT(PRIM_RX));
reg_config.value &= (~_BV(PRIM_RX));
platform_status = rf24_platform_write_reg8(&(p_dev->platform_setup), NRF24L01_REG_CONFIG, reg_config.value);
dev_status = (platform_status == RF24_PLATFORM_SUCCESS) ? (RF24_SUCCESS) : (RF24_ERROR_CONTROL_INTERFACE);
}
Expand All @@ -570,7 +587,7 @@ rf24_status_t rf24_stop_listening(rf24_dev_t* p_dev) {
platform_status =
rf24_platform_read_reg8(&(p_dev->platform_setup), NRF24L01_REG_EN_RXADDR, &(reg_en_rx_addr.value));
dev_status = (platform_status == RF24_PLATFORM_SUCCESS) ? (RF24_SUCCESS) : (RF24_ERROR_CONTROL_INTERFACE);
reg_en_rx_addr.value |= BIT_SHIFT_LEFT(m_child_pipe_enable[0]);
reg_en_rx_addr.value |= _BV(m_child_pipe_enable[0]);

if (dev_status == RF24_SUCCESS) {
platform_status = rf24_platform_write_reg8(&(p_dev->platform_setup), NRF24L01_REG_EN_RXADDR,
Expand Down Expand Up @@ -713,7 +730,7 @@ nrf24l01_reg_status_t rf24_get_status(rf24_dev_t* p_dev) {
rf24_platform_status_t platform_status = rf24_platform_get_status(&(p_dev->platform_setup), &status_reg);

if (platform_status != RF24_PLATFORM_SUCCESS) {
status_reg.value = 0xFF; // Bit 7 only allows 0, so 0xFF represents an erro value.
status_reg.value = STATUS_REG_ERROR_VALUE;
}

return status_reg;
Expand Down