Skip to content

Commit 864b7a7

Browse files
author
Purva Yeshi
committed
Improve code formatting and documentation
1 parent 1d030d6 commit 864b7a7

File tree

3 files changed

+84
-36
lines changed

3 files changed

+84
-36
lines changed

libraries/EEPROM/EEPROM.h

+27-30
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,35 @@ namespace arduino {
2020

2121
class ZephyrEEPROM {
2222
public:
23-
/* Constructor */
24-
ZephyrEEPROM() = default;
25-
26-
/* Initialize the NVS storage (mounts the NVS file system) */
27-
int nvs_init(void);
28-
29-
30-
/*
31-
* Write data to NVS
32-
*
33-
* Parameters:
34-
* - id: Unique identifier for the data
35-
* - data: Pointer to the data to write
36-
* - data_len: Length of the data to write
37-
*/
38-
int write_data(uint16_t id, const void *data, size_t data_len);
39-
40-
41-
/*
42-
* Read data from NVS
43-
*
44-
* Parameters:
45-
* - id: Unique identifier for the data
46-
* - data: Pointer to buffer where the data will be read into
47-
* - max_len: Maximum length of data to read
48-
*/
49-
int read_data(uint16_t id, void *data, size_t max_len);
50-
23+
/* Constructor */
24+
ZephyrEEPROM() = default;
25+
26+
/* Initialize the NVS storage (mounts the NVS file system) */
27+
int nvs_init(void);
28+
29+
/*
30+
* Write data to NVS
31+
*
32+
* Parameters:
33+
* - id: Unique identifier for the data
34+
* - data: Pointer to the data to write
35+
* - data_len: Length of the data to write
36+
*/
37+
int write_data(uint16_t id, const void *data, size_t data_len);
38+
39+
/*
40+
* Read data from NVS
41+
*
42+
* Parameters:
43+
* - id: Unique identifier for the data
44+
* - data: Pointer to buffer where the data will be read into
45+
* - max_len: Maximum length of data to read
46+
*/
47+
int read_data(uint16_t id, void *data, size_t max_len);
5148

5249
private:
53-
/* NVS file system structure used for managing flash memory */
54-
struct nvs_fs fs;
50+
/* NVS file system structure used for managing flash memory */
51+
struct nvs_fs fs;
5552
};
5653

5754
}

samples/eeprom_operations/README.rst

+53-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,60 @@
11
.. _eeprom_operations:
22

3+
.. _eeprom_operations:
4+
35
EEPROM Operations
4-
###############
6+
#################
57

68
Overview
79
********
810

9-
A sample that reads data from flash memory, as well as writes data to flash memory.
11+
Read and write data from flash memory using this sample.
12+
13+
Prerequisites and Setup
14+
***********************
15+
16+
Use any board that supports Zephyr RTOS.
17+
This example uses **BeagleConnect Freedom**.
18+
19+
For setup, refer to the `documentation <https://docs.beagle.cc/boards/beagleconnect/freedom/demos-and-tutorials/using-arduino-zephyr-template.html#setup-arduino-workspace>`_.
20+
21+
Build and Test
22+
**************
23+
24+
Follow these steps to set up and run the sample in the `arduino-workspace` directory:
25+
26+
1. **Set up the virtual environment:**
27+
28+
.. code-block:: bash
29+
30+
source .venv/bin/activate
31+
32+
2. **Build the EEPROM operations sample:**
33+
34+
.. code-block:: bash
35+
36+
west build -b beagleconnect_freedom modules/lib/Arduino-Zephyr-API/samples/eeprom_operations -p
37+
38+
3. **Flash the code after connecting BeagleConnect Freedom to your device:**
39+
40+
.. code-block:: bash
41+
42+
west flash
43+
44+
4. **Open the serial console to view the output:**
45+
46+
.. code-block:: bash
47+
48+
tio /dev/ttyACM0
49+
50+
Sample Output
51+
*************
52+
53+
Run the code and observe the following output:
54+
55+
.. code-block:: text
56+
57+
Serial communication initialized
58+
NVS initialized
59+
Data written successfully
60+
Data read: 1234

samples/eeprom_operations/src/app.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
87
#include <Arduino.h>
98
#include "EEPROM.h"
109

1110
void setup() {
11+
12+
int data = 1234; // Example data to store
13+
int read_data = 0;
14+
1215
/* Initialize serial communication */
1316
Serial.begin(115200);
1417
while (!Serial) {
15-
1618
; /* Wait for serial port to connect (needed for boards with native USB) */
1719
}
1820
Serial.println("Serial communication initialized");
@@ -25,15 +27,13 @@ void setup() {
2527
Serial.println("NVS initialized");
2628

2729
/* Write data to EEPROM */
28-
int data = 1234; // Example data to store
2930
if (EEPROM.write_data(1, &data, sizeof(data)) < 0) {
3031
Serial.println("Failed to write data");
3132
} else {
3233
Serial.println("Data written successfully");
3334
}
3435

3536
/* Read data from EEPROM */
36-
int read_data = 0;
3737
if (EEPROM.read_data(1, &read_data, sizeof(read_data)) > 0) {
3838
Serial.print("Data read: ");
3939
Serial.println(read_data);

0 commit comments

Comments
 (0)