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

Feature/eeprom update #49

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
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
86 changes: 83 additions & 3 deletions src/content/firmware.md
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,22 @@ SPI.transfer(val);
```
Where the parameter `val`, can is the byte to send out over the SPI bus.

### transfer(void*, void*, size_t, std::function)

For transferring large bytes of transfer the above function uses DMA to speed up SPI data transfer and at the same time allows you to run code in parallel of the data transmission. The function initialises, configures and enables the DMA peripheral’s channel and stream for the selected SPI peripheral for both TX(Output) and RX(Input) and initiates the data transfer. If a user callback function is passed then the same would be called after completion of DMA transfer. This results in asynchronous filling up of RX buffer after which the DMA transfer is disabled till the transfer function is called again. If NULL is passed as a callback then the result is synchronous i.e. transfer function would wait till the receipt of response from the slave.

```C++
// SYNTAX
SPI.transfer(tx_buffer, rx_buffer, length, myFunction)
```

Parameters:

- `tx_buffer`: array of Tx bytes that needs to be filled by the user before starting the spi transfer
- `rx_buffer`: array of Rx bytes that would be filled by the slave using the DMA scheme.
- `length`: size of data bytes that needs to be transferred
- `myFunction`: user specified function callback that would be called after completion of spi dma transfer.

Wire
----

Expand Down Expand Up @@ -3109,15 +3125,15 @@ from the cloud, and setting the seed is left to up you.
EEPROM
----

The EEPROM emulator allocates 100 bytes of the Spark Core's built-in flash memory to act as EEPROM. Unlike "true EEPROM, flash doesn't suffer from write "wear". The EEPROM functions can be used to store small amounts of data in flash that will persist even after the Core resets after a deep sleep.
The EEPROM emulator allocates `2048 bytes on Photon` & `100 bytes on Core` of the device's built-in flash memory to act as EEPROM. Unlike "true EEPROM, flash doesn't suffer from write "wear". The EEPROM functions can be used to store small amounts of data in flash that will persist even after the Core resets after a deep sleep.


### read()
Read a byte of data from the emulated EEPROM.

`read(address)`

`address` is the address (int) of the EERPOM location (0-99) to read
`address` is the address (int) of the EERPOM location to read

```C++
// EXAMPLE USAGE
Expand All @@ -3131,7 +3147,7 @@ Write a byte of data to the emulated EEPROM.

`write(address, value)`

`address` is the address (int) of the EERPOM location (0-99) to write to
`address` is the address (int) of the EERPOM location to write to
`value` is the byte data (uint8_t) to write

```C++
Expand All @@ -3142,6 +3158,70 @@ uint8_t val = 0x45;
EEPROM.write(addr, val);
```

### update()
This method is similar to `EEPROM.write()` however this method will only write data if the cell contents pointed to by `address` is different to `value`. This method can help prevent unnecessary wear on the EEPROM cells.

`update(address, value)`

`address` is the address (int) of the EERPOM location that needs to be updated
`value` is the byte data (uint8_t) to write

```C++
// EXAMPLE USAGE
// Update a byte value to the second byte of EEPROM
int addr = 1;
uint8_t val = 0x45;
EEPROM.update(addr, val);
```

### get()
This function will retrieve any object from the EEPROM. Two parameters are needed to call this function. The first is an int containing the address from where the object needs to be read, and the second is the object you would like to read.

`get(address, object)`

`address` is the address (int) of the EERPOM location
`object` is the object data that would be read

```C++
// EXAMPLE USAGE
// Read a custom object from EEPROM addres
int addr = 10;
float fValue = 0.00f;
EEPROM.get(addr, fValue);

struct MyObject{
float field1;
byte field2;
char name[10];
};
MyObject myObj;
EEPROM.get(addr, myObj);
```

### put()
This function will write any object to the EEPROM. Two parameters are needed to call this function. The first is an int containing the address that is to be written, and the second is the object you would like to write.

`put(address, object)`

`address` is the address (int) of the EERPOM location to write to
`object` is the object data to write

```C++
// EXAMPLE USAGE
// Write a object value to the EEPROM address
int addr = 10;
float fValue = 123.456f;
EEPROM.put(addr, fValue);

struct MyObject{
float field1;
byte field2;
char name[10];
};
MyObject myObj = {12.34f, 25, "Test!"}
EEPROM.put(addr, myObj);
```

Advanced: System Modes
=====

Expand Down