diff options
author | inmarket <andrewh@inmarket.com.au> | 2013-05-25 01:26:52 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2013-05-25 01:26:52 +1000 |
commit | 7fbfde42aabbcd30cffba2fba35158236c0a6c6c (patch) | |
tree | e85c90a4f21974b706315d64209021e0b2bde764 /include/gmisc/gmisc.h | |
parent | 42006a67b5ccfd86f30d8a91cc474681c437eaf6 (diff) | |
download | uGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.tar.gz uGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.tar.bz2 uGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.zip |
GOS module, for operating system independance
GMISC fast floating point trig
GMISC fast fixed point trig
Diffstat (limited to 'include/gmisc/gmisc.h')
-rw-r--r-- | include/gmisc/gmisc.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/include/gmisc/gmisc.h b/include/gmisc/gmisc.h index bf1aa498..21eb2bbe 100644 --- a/include/gmisc/gmisc.h +++ b/include/gmisc/gmisc.h @@ -37,6 +37,32 @@ typedef enum ArrayDataFormat_e { ARRAY_DATA_16BITUNSIGNED = 16, ARRAY_DATA_16BITSIGNED = 17, } ArrayDataFormat; +/** + * @brief The type for a fixed point type. + * @details The top 16 bits are the integer component, the bottom 16 bits are the real component. + */ +typedef int32_t fixed; + +/** + * @brief Macros to convert to and from a fixed point. + * @{ + */ +#define FIXED(x) ((fixed)(x)<<16) /* @< integer to fixed */ +#define NONFIXED(x) ((x)>>16) /* @< fixed to integer */ +#define FP2FIXED(x) ((fixed)((x)*65536.0)) /* @< floating point to fixed */ +#define FIXED2FP(x) ((double)(x)/65536.0) /* @< fixed to floating point */ +/* @} */ + +/** + * @brief The famous number pi + */ +#define PI 3.1415926535897932384626433832795028841971693993751 + +/** + * @brief pi as a fixed point + */ +#define FIXED_PI FP2FIXED(PI) + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -85,6 +111,76 @@ extern "C" { #endif #endif +#if GMISC_NEED_FASTTRIG || defined(__DOXYGEN__) + extern const double sintabledouble[]; + + /** + * @brief Fast Table Based Trig functions + * @return A double in the range -1.0 .. 0.0 .. 1.0 + * + * @param[in] degrees The angle in degrees (not radians) + * + * @note These functions use degrees rather than radians to describe the angle. + * + * @api + * @{ + */ + double fsin(int degrees); + double fcos(int degrees); + /** @} + * + * @brief Fast Table Based Trig functions + * @return A double in the range -1.0 .. 0.0 .. 1.0 + * + * @param[in] degrees The angle in degrees 0 .. 359 + * + * @note These functions use degrees rather than radians to describe the angle. + * @note These functions are super fast but require the parameter to be in range. + * Use the lowercase functions if the parameter may not be in range or if a + * required trig function is not supported in this form. + * + * @api + * @{ + */ + #define FSIN(degrees) sintabledouble[degrees]; + /** @} */ +#endif + +#if GMISC_NEED_FIXEDTRIG || defined(__DOXYGEN__) + extern const fixed sintablefixed[]; + + /** + * @brief Fast Table Based Trig functions + * @return A fixed point in the range -1.0 .. 0.0 .. 1.0 + * + * @param[in] degrees The angle in degrees (not radians) + * + * @note These functions use degrees rather than radians to describe the angle. + * + * @api + * @{ + */ + fixed ffsin(int degrees); + fixed ffcos(int degrees); + /** @} + * + * @brief Fast Table Based Trig functions + * @return A fixed point in the range -1.0 .. 0.0 .. 1.0 + * + * @param[in] degrees The angle in degrees 0 .. 359 + * + * @note These functions use degrees rather than radians to describe the angle. + * @note These functions are super fast but require the parameter to be in range. + * Use the lowercase functions if the parameter may not be in range or if a + * required trig function is not supported in this form. + * + * @api + * @{ + */ + #define FFSIN(degrees) sintablefixed[degrees]; + /** @} */ +#endif + #ifdef __cplusplus } #endif |