speeduino/speeduino/pages.h

102 lines
3.3 KiB
C
Raw Normal View History

#pragma once
#include <Arduino.h>
Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
#include "table3d.h"
/**
* Page count, as defined in the INI file
*/
2022-11-05 15:43:29 -07:00
uint8_t getPageCount(void);
/**
* Page size in bytes
*/
uint16_t getPageSize(byte pageNum /**< [in] The page number */ );
// These are the page numbers that the Tuner Studio serial protocol uses to transverse the different map and config pages.
#define veMapPage 2
#define veSetPage 1 //Note that this and the veMapPage were swapped in Feb 2019 as the 'algorithm' field must be declared in the ini before it's used in the fuel table
#define ignMapPage 3
#define ignSetPage 4//Config Page 2
#define afrMapPage 5
#define afrSetPage 6//Config Page 3
#define boostvvtPage 7
#define seqFuelPage 8
#define canbusPage 9//Config Page 9
#define warmupPage 10 //Config Page 10
#define fuelMap2Page 11
#define wmiMapPage 12
#define progOutsPage 13
#define ignMap2Page 14
#define boostvvtPage2 15
// ============================== Per-byte page access ==========================
/**
* Gets a single value from a page, with data aligned as per the ini file
*/
byte getPageValue( byte pageNum, /**< [in] The page number to retrieve data from. */
uint16_t offset /**< [in] The address in the page that should be returned. This is as per the page definition in the ini. */
);
/**
* Sets a single value from a page, with data aligned as per the ini file
*/
void setPageValue( byte pageNum, /**< [in] The page number to retrieve data from. */
uint16_t offset, /**< [in] The address in the page that should be returned. This is as per the page definition in the ini. */
byte value /**< [in] The new value */
);
// ============================== Page Iteration ==========================
// A logical TS page is actually multiple in memory entities. Allow iteration
// over those entities.
// Type of entity
enum entity_type {
Raw, // A block of memory
Table, // A 3D table
NoEntity, // No entity, but a valid offset
End // The offset was past any known entity for the page
};
// A entity on a logical page.
struct page_iterator_t {
Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
void *pData;
table_type_t table_key;
uint8_t page; // The page the entity belongs to
uint16_t start; // The start position of the entity, in bytes, from the start of the page
uint16_t size; // Size of the entity in bytes
entity_type type;
};
/**
* Initiates iteration over a pages entities.
* Test `entity.type==End` to determine the end of the page.
*/
page_iterator_t page_begin(byte pageNum /**< [in] The page number to iterate over. */);
/**
* Moves the iterator to the next sub-entity on the page
*/
page_iterator_t advance(const page_iterator_t &it /**< [in] The current iterator */);
Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
/**
* Convert page iterator to table value iterator.
*/
table_value_iterator rows_begin(const page_iterator_t &it);
/**
* Convert page iterator to table x axis iterator.
*/
table_axis_iterator x_begin(const page_iterator_t &it);
/**
* Convert page iterator to table x axis iterator.
*/
table_axis_iterator x_rbegin(const page_iterator_t &it);
Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
/**
* Convert page iterator to table y axis iterator.
*/
table_axis_iterator y_begin(const page_iterator_t &it);