initial commit. start platformio project
This commit is contained in:
commit
b1e2aecfff
8 changed files with 314 additions and 0 deletions
46
lib/README
Normal file
46
lib/README
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
33
lib/nvm/src/NvmEeprom.cpp
Normal file
33
lib/nvm/src/NvmEeprom.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/** \File NvmEeprom.cpp
|
||||
* \copyright (c) 2025 len0rd
|
||||
* \date 2025-01-09
|
||||
*/
|
||||
#include "NvmEeprom.hpp"
|
||||
#include <cstddef>
|
||||
#include "EEPROM.h"
|
||||
|
||||
bool JoystickAxisCalibration::valid() const {
|
||||
return min < mid < max;
|
||||
}
|
||||
|
||||
void writeNvm(const NonVolatileMemory &nvm)
|
||||
{
|
||||
for (size_t ii = 0; ii < sizeof(NonVolatileMemory); ii++)
|
||||
{
|
||||
EEPROM.write(ii, nvm.rawBytes[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
void writeCalibration(const JoystickCalibration &cal) {
|
||||
NonVolatileMemory nvm = {};
|
||||
nvm.joystickCal = cal;
|
||||
writeNvm(nvm);
|
||||
}
|
||||
|
||||
void readNvm(NonVolatileMemory &nvm)
|
||||
{
|
||||
for (size_t ii = 0; ii < sizeof(NonVolatileMemory); ii++)
|
||||
{
|
||||
nvm.rawBytes[ii] = EEPROM.read(ii);
|
||||
}
|
||||
}
|
||||
44
lib/nvm/src/NvmEeprom.hpp
Normal file
44
lib/nvm/src/NvmEeprom.hpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/** \File NvmEeprom.hpp
|
||||
* \copyright (c) 2025 len0rd
|
||||
* \date 2025-01-09
|
||||
*
|
||||
* Very basic non-volatile memory handler to save and retrieve data
|
||||
* needed by the controller
|
||||
*/
|
||||
#ifndef __NVMEEPROM_H__
|
||||
#define __NVMEEPROM_H__
|
||||
#include <cstdint>
|
||||
|
||||
struct JoystickAxisCalibration
|
||||
{
|
||||
/// Minimum value axis could be
|
||||
uint16_t min;
|
||||
/// average center point of axis
|
||||
uint16_t mid;
|
||||
/// max value axis could be
|
||||
uint16_t max;
|
||||
|
||||
/// Check if the data in this struct makes sense
|
||||
/// Returns true if data might be valid, otherwise false
|
||||
bool valid() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct JoystickCalibration
|
||||
{
|
||||
JoystickAxisCalibration x;
|
||||
JoystickAxisCalibration y;
|
||||
} __attribute__((packed));
|
||||
|
||||
union NonVolatileMemory
|
||||
{
|
||||
JoystickCalibration joystickCal;
|
||||
uint8_t rawBytes[sizeof(JoystickCalibration)] = {};
|
||||
};
|
||||
|
||||
/// @brief Write the provided struct to EEPROM
|
||||
void writeNvm(const NonVolatileMemory &nvm);
|
||||
void writeCalibration(const JoystickCalibration&cal);
|
||||
|
||||
void readNvm(NonVolatileMemory &nvm);
|
||||
|
||||
#endif /* __NVMEEPROM_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue