diff --git a/units/1wire/_ow_api.c b/units/1wire/_ow_api.c index 3ca5d91..ea96635 100644 --- a/units/1wire/_ow_api.c +++ b/units/1wire/_ow_api.c @@ -9,7 +9,6 @@ #define OW_INTERNAL #include "_ow_internal.h" #include "_ow_commands.h" -#include "_ow_checksum.h" #include "_ow_low_level.h" /* Check presence of any devices on the bus */ diff --git a/units/1wire/_ow_checksum.c b/units/1wire/_ow_checksum.c deleted file mode 100644 index 66be8b1..0000000 --- a/units/1wire/_ow_checksum.c +++ /dev/null @@ -1,36 +0,0 @@ -// -// Created by MightyPork on 2018/02/01. -// - -#include "platform.h" - -#define OW_INTERNAL -#include "_ow_checksum.h" - -static inline uint8_t crc8_bits(uint8_t data) -{ - uint8_t crc = 0; - if(data & 1) crc ^= 0x5e; - if(data & 2) crc ^= 0xbc; - if(data & 4) crc ^= 0x61; - if(data & 8) crc ^= 0xc2; - if(data & 0x10) crc ^= 0x9d; - if(data & 0x20) crc ^= 0x23; - if(data & 0x40) crc ^= 0x46; - if(data & 0x80) crc ^= 0x8c; - return crc; -} - -static uint8_t crc8_add(uint8_t cksum, uint8_t byte) -{ - return crc8_bits(byte ^ cksum); -} - -uint8_t ow_checksum(const uint8_t *buff, uint32_t len) -{ - uint8_t cksum = 0; - for(uint32_t i = 0; i < len; i++) { - cksum = crc8_add(cksum, buff[i]); - } - return cksum; -} diff --git a/units/1wire/_ow_checksum.h b/units/1wire/_ow_checksum.h deleted file mode 100644 index fc9ef9a..0000000 --- a/units/1wire/_ow_checksum.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// Created by MightyPork on 2018/02/01. -// - -#ifndef GEX_F072_OW_CHECKSUM_H -#define GEX_F072_OW_CHECKSUM_H - -#ifndef OW_INTERNAL -#error bad include! -#endif - -#include - -/** - * Compute a 1-wire type checksum. - * If the buffer includes the checksum, the result should be 0. - * - * (this function may be used externally, or you can delete the implementation - * from the c file if another implementation is already available) - * - * @param[in] buf - buffer of bytes to verify - * @param[in] len - buffer length - * @return checksum - */ -uint8_t ow_checksum(const uint8_t *buf, uint32_t len); - -#endif //GEX_F072_OW_CHECKSUM_H diff --git a/units/1wire/_ow_init.h b/units/1wire/_ow_init.h deleted file mode 100644 index 7f9cd6e..0000000 --- a/units/1wire/_ow_init.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_OW_INIT_H -#define GEX_F072_OW_INIT_H - -#ifndef OW_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Allocate data structure and set defaults */ -error_t OW_preInit(Unit *unit); - -/** Finalize unit set-up */ -error_t OW_init(Unit *unit); - -/** Tear down the unit */ -void OW_deInit(Unit *unit); - -extern void OW_TimerCb(TimerHandle_t xTimer); - -#endif //GEX_F072_OW_INIT_H diff --git a/units/1wire/_ow_internal.h b/units/1wire/_ow_internal.h index 135c629..7e00a6d 100644 --- a/units/1wire/_ow_internal.h +++ b/units/1wire/_ow_internal.h @@ -27,6 +27,37 @@ struct priv { struct ow_search_state searchState; }; -// Prototypes +/** Allocate data structure and set defaults */ +error_t OW_preInit(Unit *unit); + +/** Load from a binary buffer stored in Flash */ +void OW_loadBinary(Unit *unit, PayloadParser *pp); + +/** Write to a binary buffer for storing in Flash */ +void OW_writeBinary(Unit *unit, PayloadBuilder *pb); + +// ------------------------------------------------------------------------ + +/** Parse a key-value pair from the INI file */ +error_t OW_loadIni(Unit *unit, const char *key, const char *value); + +/** Generate INI file section for the unit */ +void OW_writeIni(Unit *unit, IniWriter *iw); + +// ------------------------------------------------------------------------ + +/** Allocate data structure and set defaults */ +error_t OW_preInit(Unit *unit); + +/** Finalize unit set-up */ +error_t OW_init(Unit *unit); + +/** Tear down the unit */ +void OW_deInit(Unit *unit); + +/** Callback for the FreeRTOS timer used to wait for device ready */ +void OW_TimerCb(TimerHandle_t xTimer); + +// ------------------------------------------------------------------------ #endif //GEX_F072_OW_INTERNAL_H diff --git a/units/1wire/_ow_low_level.c b/units/1wire/_ow_low_level.c index 16e2194..35097d9 100644 --- a/units/1wire/_ow_low_level.c +++ b/units/1wire/_ow_low_level.c @@ -10,6 +10,36 @@ #include "_ow_internal.h" #include "_ow_low_level.h" +static inline uint8_t crc8_bits(uint8_t data) +{ + uint8_t crc = 0; + if(data & 1) crc ^= 0x5e; + if(data & 2) crc ^= 0xbc; + if(data & 4) crc ^= 0x61; + if(data & 8) crc ^= 0xc2; + if(data & 0x10) crc ^= 0x9d; + if(data & 0x20) crc ^= 0x23; + if(data & 0x40) crc ^= 0x46; + if(data & 0x80) crc ^= 0x8c; + return crc; +} + +static uint8_t crc8_add(uint8_t cksum, uint8_t byte) +{ + return crc8_bits(byte ^ cksum); +} + +uint8_t ow_checksum(const uint8_t *buff, uint32_t len) +{ + uint8_t cksum = 0; + for(uint32_t i = 0; i < len; i++) { + cksum = crc8_add(cksum, buff[i]); + } + return cksum; +} + +// ---------------------------------------------- + static inline void ow_pull_high(Unit *unit) { struct priv *priv = unit->data; diff --git a/units/1wire/_ow_low_level.h b/units/1wire/_ow_low_level.h index b8e3dc4..be22df4 100644 --- a/units/1wire/_ow_low_level.h +++ b/units/1wire/_ow_low_level.h @@ -13,6 +13,19 @@ #include "unit_base.h" #include "_ow_low_level.h" +/** + * Compute a 1-wire type checksum. + * If the buffer includes the checksum, the result should be 0. + * + * (this function may be used externally, or you can delete the implementation + * from the c file if another implementation is already available) + * + * @param[in] buf - buffer of bytes to verify + * @param[in] len - buffer length + * @return checksum + */ +uint8_t ow_checksum(const uint8_t *buf, uint32_t len); + /** * Reset the 1-wire bus */ diff --git a/units/1wire/_ow_settings.h b/units/1wire/_ow_settings.h deleted file mode 100644 index ca65bfc..0000000 --- a/units/1wire/_ow_settings.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_OW_SETTINGS_H -#define GEX_F072_OW_SETTINGS_H - -#ifndef OW_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Allocate data structure and set defaults */ -error_t OW_preInit(Unit *unit); - -/** Load from a binary buffer stored in Flash */ -void OW_loadBinary(Unit *unit, PayloadParser *pp); - -/** Write to a binary buffer for storing in Flash */ -void OW_writeBinary(Unit *unit, PayloadBuilder *pb); - -// ------------------------------------------------------------------------ - -/** Parse a key-value pair from the INI file */ -error_t OW_loadIni(Unit *unit, const char *key, const char *value); - -/** Generate INI file section for the unit */ -void OW_writeIni(Unit *unit, IniWriter *iw); - -#endif //GEX_F072_OW_SETTINGS_H diff --git a/units/digital_in/_din_exti.h b/units/digital_in/_din_exti.h deleted file mode 100644 index bbd8003..0000000 --- a/units/digital_in/_din_exti.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_DIN_EXTI_H -#define GEX_F072_DIN_EXTI_H - -#ifndef DIN_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** - * EXTI callback for pin change interrupts - * - * @param arg - the unit is passed here - */ -void DIn_handleExti(void *arg); - -#endif //GEX_F072_DIN_EXTI_H diff --git a/units/digital_in/_din_init.h b/units/digital_in/_din_init.h deleted file mode 100644 index 9bd4832..0000000 --- a/units/digital_in/_din_init.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_DIN_INIT_H -#define GEX_F072_DIN_INIT_H - -#ifndef DIN_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Finalize unit set-up */ -error_t DIn_init(Unit *unit); - -/** Tear down the unit */ -void DIn_deInit(Unit *unit); - -#endif //GEX_F072_DIN_INIT_H diff --git a/units/digital_in/_din_internal.h b/units/digital_in/_din_internal.h index 1fcfa6a..ca010d8 100644 --- a/units/digital_in/_din_internal.h +++ b/units/digital_in/_din_internal.h @@ -28,4 +28,38 @@ struct priv { GPIO_TypeDef *port; }; +/** Allocate data structure and set defaults */ +error_t DIn_preInit(Unit *unit); + +/** Load from a binary buffer stored in Flash */ +void DIn_loadBinary(Unit *unit, PayloadParser *pp); + +/** Write to a binary buffer for storing in Flash */ +void DIn_writeBinary(Unit *unit, PayloadBuilder *pb); + +// ------------------------------------------------------------------------ + +/** Parse a key-value pair from the INI file */ +error_t DIn_loadIni(Unit *unit, const char *key, const char *value); + +/** Generate INI file section for the unit */ +void DIn_writeIni(Unit *unit, IniWriter *iw); + +// ------------------------------------------------------------------------ + +/** Finalize unit set-up */ +error_t DIn_init(Unit *unit); + +/** Tear down the unit */ +void DIn_deInit(Unit *unit); + +// ------------------------------------------------------------------------ + +/** + * EXTI callback for pin change interrupts + * + * @param arg - the unit is passed here + */ +void DIn_handleExti(void *arg); + #endif //GEX_F072_DIN_INTERNAL_H diff --git a/units/digital_in/_din_settings.h b/units/digital_in/_din_settings.h deleted file mode 100644 index b4b8e44..0000000 --- a/units/digital_in/_din_settings.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_DIN_SETTINGS_H -#define GEX_F072_DIN_SETTINGS_H - -#ifndef DIN_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Allocate data structure and set defaults */ -error_t DIn_preInit(Unit *unit); - -/** Load from a binary buffer stored in Flash */ -void DIn_loadBinary(Unit *unit, PayloadParser *pp); - -/** Write to a binary buffer for storing in Flash */ -void DIn_writeBinary(Unit *unit, PayloadBuilder *pb); - -// ------------------------------------------------------------------------ - -/** Parse a key-value pair from the INI file */ -error_t DIn_loadIni(Unit *unit, const char *key, const char *value); - -/** Generate INI file section for the unit */ -void DIn_writeIni(Unit *unit, IniWriter *iw); - -#endif //GEX_F072_DIN_SETTINGS_H diff --git a/units/digital_out/_dout_init.h b/units/digital_out/_dout_init.h deleted file mode 100644 index d70fdb7..0000000 --- a/units/digital_out/_dout_init.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_DOUT_INIT_H -#define GEX_F072_DOUT_INIT_H - -#ifndef DOUT_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Finalize unit set-up */ -error_t DOut_init(Unit *unit); - -/** Tear down the unit */ -void DOut_deInit(Unit *unit); - -#endif //GEX_F072_DOUT_INIT_H diff --git a/units/digital_out/_dout_internal.h b/units/digital_out/_dout_internal.h index c2f03f5..5c1888f 100644 --- a/units/digital_out/_dout_internal.h +++ b/units/digital_out/_dout_internal.h @@ -21,4 +21,29 @@ struct priv { GPIO_TypeDef *port; }; +/** Allocate data structure and set defaults */ +error_t DOut_preInit(Unit *unit); + +/** Load from a binary buffer stored in Flash */ +void DOut_loadBinary(Unit *unit, PayloadParser *pp); + +/** Write to a binary buffer for storing in Flash */ +void DOut_writeBinary(Unit *unit, PayloadBuilder *pb); + +// ------------------------------------------------------------------------ + +/** Parse a key-value pair from the INI file */ +error_t DOut_loadIni(Unit *unit, const char *key, const char *value); + +/** Generate INI file section for the unit */ +void DOut_writeIni(Unit *unit, IniWriter *iw); + +// ------------------------------------------------------------------------ + +/** Finalize unit set-up */ +error_t DOut_init(Unit *unit); + +/** Tear down the unit */ +void DOut_deInit(Unit *unit); + #endif //GEX_F072_DOUT_INTERNAL_H diff --git a/units/digital_out/_dout_settings.h b/units/digital_out/_dout_settings.h deleted file mode 100644 index 2468316..0000000 --- a/units/digital_out/_dout_settings.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_DOUT_SETTINGS_H -#define GEX_F072_DOUT_SETTINGS_H - -#ifndef DOUT_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Allocate data structure and set defaults */ -error_t DOut_preInit(Unit *unit); - -/** Load from a binary buffer stored in Flash */ -void DOut_loadBinary(Unit *unit, PayloadParser *pp); - -/** Write to a binary buffer for storing in Flash */ -void DOut_writeBinary(Unit *unit, PayloadBuilder *pb); - -// ------------------------------------------------------------------------ - -/** Parse a key-value pair from the INI file */ -error_t DOut_loadIni(Unit *unit, const char *key, const char *value); - -/** Generate INI file section for the unit */ -void DOut_writeIni(Unit *unit, IniWriter *iw); - -#endif //GEX_F072_DOUT_SETTINGS_H diff --git a/units/digital_out/unit_dout.c b/units/digital_out/unit_dout.c index 79f465a..04acee4 100644 --- a/units/digital_out/unit_dout.c +++ b/units/digital_out/unit_dout.c @@ -6,8 +6,7 @@ #include "unit_dout.h" #define DOUT_INTERNAL -#include "_dout_settings.h" -#include "_dout_init.h" +#include "_dout_internal.h" enum PinCmd_ { CMD_TEST = 0, @@ -17,8 +16,7 @@ enum PinCmd_ { }; /** Handle a request message */ -static error_t DOut_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, - PayloadParser *pp) +static error_t DOut_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp) { uint16_t packed = pp_u16(pp); diff --git a/units/i2c/_i2c_init.c b/units/i2c/_i2c_init.c index 7bc59b3..2b696fa 100644 --- a/units/i2c/_i2c_init.c +++ b/units/i2c/_i2c_init.c @@ -7,7 +7,6 @@ #define I2C_INTERNAL #include "_i2c_internal.h" -#include "_i2c_init.h" /** Allocate data structure and set defaults */ diff --git a/units/i2c/_i2c_init.h b/units/i2c/_i2c_init.h deleted file mode 100644 index 7b7f4bf..0000000 --- a/units/i2c/_i2c_init.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_I2C_INIT_H -#define GEX_F072_I2C_INIT_H - -#ifndef I2C_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Allocate data structure and set defaults */ -error_t UI2C_preInit(Unit *unit); - -/** Finalize unit set-up */ -error_t UI2C_init(Unit *unit); - -/** Tear down the unit */ -void UI2C_deInit(Unit *unit); - - -#endif //GEX_F072_I2C_INIT_H diff --git a/units/i2c/_i2c_internal.h b/units/i2c/_i2c_internal.h index ad5c19d..9fef32f 100644 --- a/units/i2c/_i2c_internal.h +++ b/units/i2c/_i2c_internal.h @@ -19,10 +19,33 @@ struct priv { uint8_t speed; //!< 0 - Standard, 1 - Fast, 2 - Fast+ I2C_TypeDef *periph; - -// GPIO_TypeDef *port; -// uint32_t ll_pin_scl; -// uint32_t ll_pin_sda; }; +/** Load from a binary buffer stored in Flash */ +void UI2C_loadBinary(Unit *unit, PayloadParser *pp); + +/** Write to a binary buffer for storing in Flash */ +void UI2C_writeBinary(Unit *unit, PayloadBuilder *pb); + +// ------------------------------------------------------------------------ + +/** Parse a key-value pair from the INI file */ +error_t UI2C_loadIni(Unit *unit, const char *key, const char *value); + +/** Generate INI file section for the unit */ +void UI2C_writeIni(Unit *unit, IniWriter *iw); + +// ------------------------------------------------------------------------ + +/** Allocate data structure and set defaults */ +error_t UI2C_preInit(Unit *unit); + +/** Finalize unit set-up */ +error_t UI2C_init(Unit *unit); + +/** Tear down the unit */ +void UI2C_deInit(Unit *unit); + +// ------------------------------------------------------------------------ + #endif //GEX_F072_I2C_INTERNAL_H diff --git a/units/i2c/_i2c_settings.h b/units/i2c/_i2c_settings.h deleted file mode 100644 index 33587f3..0000000 --- a/units/i2c/_i2c_settings.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_I2C_SETTINGS_H -#define GEX_F072_I2C_SETTINGS_H - -#ifndef I2C_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Load from a binary buffer stored in Flash */ -void UI2C_loadBinary(Unit *unit, PayloadParser *pp); - -/** Write to a binary buffer for storing in Flash */ -void UI2C_writeBinary(Unit *unit, PayloadBuilder *pb); - -// ------------------------------------------------------------------------ - -/** Parse a key-value pair from the INI file */ -error_t UI2C_loadIni(Unit *unit, const char *key, const char *value); - -/** Generate INI file section for the unit */ -void UI2C_writeIni(Unit *unit, IniWriter *iw); - -#endif //GEX_F072_I2C_SETTINGS_H diff --git a/units/neopixel/_npx_init.c b/units/neopixel/_npx_init.c index 332f9e3..471aab0 100644 --- a/units/neopixel/_npx_init.c +++ b/units/neopixel/_npx_init.c @@ -7,7 +7,6 @@ #define NPX_INTERNAL #include "_npx_internal.h" -#include "_npx_init.h" #include "ws2812.h" /** Allocate data structure and set defaults */ diff --git a/units/neopixel/_npx_init.h b/units/neopixel/_npx_init.h deleted file mode 100644 index f90146b..0000000 --- a/units/neopixel/_npx_init.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_NPX_INIT_H -#define GEX_F072_NPX_INIT_H - -#ifndef NPX_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Finalize unit set-up */ -error_t Npx_init(Unit *unit); - -/** Tear down the unit */ -void Npx_deInit(Unit *unit); - -#endif //GEX_F072_NPX_INIT_H diff --git a/units/neopixel/_npx_internal.h b/units/neopixel/_npx_internal.h index eb171bb..e3c875c 100644 --- a/units/neopixel/_npx_internal.h +++ b/units/neopixel/_npx_internal.h @@ -21,4 +21,31 @@ struct priv { GPIO_TypeDef *port; }; +// ------------------------------------------------------------------------ + +/** Allocate data structure and set defaults */ +error_t Npx_preInit(Unit *unit); + +/** Load from a binary buffer stored in Flash */ +void Npx_loadBinary(Unit *unit, PayloadParser *pp); + +/** Write to a binary buffer for storing in Flash */ +void Npx_writeBinary(Unit *unit, PayloadBuilder *pb); + +// ------------------------------------------------------------------------ + +/** Parse a key-value pair from the INI file */ +error_t Npx_loadIni(Unit *unit, const char *key, const char *value); + +/** Generate INI file section for the unit */ +void Npx_writeIni(Unit *unit, IniWriter *iw); + +// ------------------------------------------------------------------------ + +/** Finalize unit set-up */ +error_t Npx_init(Unit *unit); + +/** Tear down the unit */ +void Npx_deInit(Unit *unit); + #endif //GEX_F072_NPX_INTERNAL_H diff --git a/units/neopixel/_npx_settings.c b/units/neopixel/_npx_settings.c index a2b0a12..cbbfbe9 100644 --- a/units/neopixel/_npx_settings.c +++ b/units/neopixel/_npx_settings.c @@ -7,7 +7,6 @@ #define NPX_INTERNAL #include "_npx_internal.h" -#include "_npx_settings.h" /** Load from a binary buffer stored in Flash */ void Npx_loadBinary(Unit *unit, PayloadParser *pp) diff --git a/units/neopixel/_npx_settings.h b/units/neopixel/_npx_settings.h deleted file mode 100644 index 3d175c1..0000000 --- a/units/neopixel/_npx_settings.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_NPX_SETTINGS_H -#define GEX_F072_NPX_SETTINGS_H - -#ifndef NPX_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Allocate data structure and set defaults */ -error_t Npx_preInit(Unit *unit); - -/** Load from a binary buffer stored in Flash */ -void Npx_loadBinary(Unit *unit, PayloadParser *pp); - -/** Write to a binary buffer for storing in Flash */ -void Npx_writeBinary(Unit *unit, PayloadBuilder *pb); - -// ------------------------------------------------------------------------ - -/** Parse a key-value pair from the INI file */ -error_t Npx_loadIni(Unit *unit, const char *key, const char *value); - -/** Generate INI file section for the unit */ -void Npx_writeIni(Unit *unit, IniWriter *iw); - -#endif //GEX_F072_NPX_SETTINGS_H diff --git a/units/neopixel/unit_neopixel.c b/units/neopixel/unit_neopixel.c index 7339c33..abb98cd 100644 --- a/units/neopixel/unit_neopixel.c +++ b/units/neopixel/unit_neopixel.c @@ -6,8 +6,7 @@ #include "unit_neopixel.h" #define NPX_INTERNAL -#include "_npx_settings.h" -#include "_npx_init.h" +#include "_npx_internal.h" enum PinCmd_ { CMD_CLEAR = 0, diff --git a/units/spi/_spi_init.c b/units/spi/_spi_init.c index cc2e252..3a779fd 100644 --- a/units/spi/_spi_init.c +++ b/units/spi/_spi_init.c @@ -7,10 +7,9 @@ #define SPI_INTERNAL #include "_spi_internal.h" -#include "_spi_init.h" /** Allocate data structure and set defaults */ -error_t SPI_preInit(Unit *unit) +error_t USPI_preInit(Unit *unit) { struct priv *priv = unit->data = calloc_ck(1, sizeof(struct priv)); if (priv == NULL) return E_OUT_OF_MEM; @@ -32,7 +31,7 @@ error_t SPI_preInit(Unit *unit) } /** Finalize unit set-up */ -error_t SPI_init(Unit *unit) +error_t USPI_init(Unit *unit) { bool suc = true; struct priv *priv = unit->data; @@ -176,7 +175,7 @@ error_t SPI_init(Unit *unit) } /** Tear down the unit */ -void SPI_deInit(Unit *unit) +void USPI_deInit(Unit *unit) { struct priv *priv = unit->data; diff --git a/units/spi/_spi_init.h b/units/spi/_spi_init.h deleted file mode 100644 index d5a01bb..0000000 --- a/units/spi/_spi_init.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_SPI_INIT_H -#define GEX_F072_SPI_INIT_H - -#ifndef SPI_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Finalize unit set-up */ -error_t SPI_init(Unit *unit); - -/** Tear down the unit */ -void SPI_deInit(Unit *unit); - -#endif //GEX_F072_SPI_INIT_H diff --git a/units/spi/_spi_internal.h b/units/spi/_spi_internal.h index cf46e2e..b1518dc 100644 --- a/units/spi/_spi_internal.h +++ b/units/spi/_spi_internal.h @@ -29,4 +29,31 @@ struct priv { GPIO_TypeDef *ssn_port; }; +// ------------------------------------------------------------------------ + +/** Load from a binary buffer stored in Flash */ +void USPI_loadBinary(Unit *unit, PayloadParser *pp); + +/** Write to a binary buffer for storing in Flash */ +void USPI_writeBinary(Unit *unit, PayloadBuilder *pb); + +// ------------------------------------------------------------------------ + +/** Parse a key-value pair from the INI file */ +error_t USPI_loadIni(Unit *unit, const char *key, const char *value); + +/** Generate INI file section for the unit */ +void USPI_writeIni(Unit *unit, IniWriter *iw); + +// ------------------------------------------------------------------------ + +/** Allocate data structure and set defaults */ +error_t USPI_preInit(Unit *unit); + +/** Finalize unit set-up */ +error_t USPI_init(Unit *unit); + +/** Tear down the unit */ +void USPI_deInit(Unit *unit); + #endif //GEX_F072_SPI_INTERNAL_H diff --git a/units/spi/_spi_settings.c b/units/spi/_spi_settings.c index 527ab80..b0578a6 100644 --- a/units/spi/_spi_settings.c +++ b/units/spi/_spi_settings.c @@ -7,10 +7,9 @@ #define SPI_INTERNAL #include "_spi_internal.h" -#include "_spi_settings.h" /** Load from a binary buffer stored in Flash */ -void SPI_loadBinary(Unit *unit, PayloadParser *pp) +void USPI_loadBinary(Unit *unit, PayloadParser *pp) { struct priv *priv = unit->data; @@ -31,7 +30,7 @@ void SPI_loadBinary(Unit *unit, PayloadParser *pp) } /** Write to a binary buffer for storing in Flash */ -void SPI_writeBinary(Unit *unit, PayloadBuilder *pb) +void USPI_writeBinary(Unit *unit, PayloadBuilder *pb) { struct priv *priv = unit->data; @@ -53,7 +52,7 @@ void SPI_writeBinary(Unit *unit, PayloadBuilder *pb) // ------------------------------------------------------------------------ /** Parse a key-value pair from the INI file */ -error_t SPI_loadIni(Unit *unit, const char *key, const char *value) +error_t USPI_loadIni(Unit *unit, const char *key, const char *value) { bool suc = true; struct priv *priv = unit->data; @@ -94,7 +93,7 @@ error_t SPI_loadIni(Unit *unit, const char *key, const char *value) } /** Generate INI file section for the unit */ -void SPI_writeIni(Unit *unit, IniWriter *iw) +void USPI_writeIni(Unit *unit, IniWriter *iw) { struct priv *priv = unit->data; diff --git a/units/spi/_spi_settings.h b/units/spi/_spi_settings.h deleted file mode 100644 index 829e530..0000000 --- a/units/spi/_spi_settings.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_SPI_SETTINGS_H -#define GEX_F072_SPI_SETTINGS_H - -#ifndef SPI_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Allocate data structure and set defaults */ -error_t SPI_preInit(Unit *unit); - -/** Load from a binary buffer stored in Flash */ -void SPI_loadBinary(Unit *unit, PayloadParser *pp); - -/** Write to a binary buffer for storing in Flash */ -void SPI_writeBinary(Unit *unit, PayloadBuilder *pb); - -// ------------------------------------------------------------------------ - -/** Parse a key-value pair from the INI file */ -error_t SPI_loadIni(Unit *unit, const char *key, const char *value); - -/** Generate INI file section for the unit */ -void SPI_writeIni(Unit *unit, IniWriter *iw); - -#endif //GEX_F072_SPI_SETTINGS_H diff --git a/units/spi/unit_spi.c b/units/spi/unit_spi.c index 267c14e..2f77209 100644 --- a/units/spi/unit_spi.c +++ b/units/spi/unit_spi.c @@ -11,8 +11,6 @@ #define SPI_INTERNAL #include "_spi_internal.h" -#include "_spi_settings.h" -#include "_spi_init.h" // SPI master @@ -73,14 +71,14 @@ const UnitDriver UNIT_SPI = { .name = "SPI", .description = "SPI master", // Settings - .preInit = SPI_preInit, - .cfgLoadBinary = SPI_loadBinary, - .cfgWriteBinary = SPI_writeBinary, - .cfgLoadIni = SPI_loadIni, - .cfgWriteIni = SPI_writeIni, + .preInit = USPI_preInit, + .cfgLoadBinary = USPI_loadBinary, + .cfgWriteBinary = USPI_writeBinary, + .cfgLoadIni = USPI_loadIni, + .cfgWriteIni = USPI_writeIni, // Init - .init = SPI_init, - .deInit = SPI_deInit, + .init = USPI_init, + .deInit = USPI_deInit, // Function .handleRequest = SPI_handleRequest, }; diff --git a/units/template/_tpl_init.c b/units/template/_tpl_init.c index 80c6eb4..355efd7 100644 --- a/units/template/_tpl_init.c +++ b/units/template/_tpl_init.c @@ -7,7 +7,6 @@ #define TPL_INTERNAL #include "_tpl_internal.h" -#include "_tpl_init.h" /** Allocate data structure and set defaults */ error_t TPL_preInit(Unit *unit) diff --git a/units/template/_tpl_init.h b/units/template/_tpl_init.h deleted file mode 100644 index 2afaa62..0000000 --- a/units/template/_tpl_init.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_TPL_INIT_H -#define GEX_F072_TPL_INIT_H - -#ifndef TPL_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Finalize unit set-up */ -error_t TPL_init(Unit *unit); - -/** Tear down the unit */ -void TPL_deInit(Unit *unit); - -#endif //GEX_F072_TPL_INIT_H diff --git a/units/template/_tpl_internal.h b/units/template/_tpl_internal.h index bcfa4fe..a8a72d3 100644 --- a/units/template/_tpl_internal.h +++ b/units/template/_tpl_internal.h @@ -18,4 +18,29 @@ struct priv { // internal state }; +/** Allocate data structure and set defaults */ +error_t TPL_preInit(Unit *unit); + +/** Load from a binary buffer stored in Flash */ +void TPL_loadBinary(Unit *unit, PayloadParser *pp); + +/** Write to a binary buffer for storing in Flash */ +void TPL_writeBinary(Unit *unit, PayloadBuilder *pb); + +// ------------------------------------------------------------------------ + +/** Parse a key-value pair from the INI file */ +error_t TPL_loadIni(Unit *unit, const char *key, const char *value); + +/** Generate INI file section for the unit */ +void TPL_writeIni(Unit *unit, IniWriter *iw); + +// ------------------------------------------------------------------------ + +/** Finalize unit set-up */ +error_t TPL_init(Unit *unit); + +/** Tear down the unit */ +void TPL_deInit(Unit *unit); + #endif //GEX_F072_TPL_INTERNAL_H diff --git a/units/template/_tpl_settings.c b/units/template/_tpl_settings.c index 2a1be82..35ae7c2 100644 --- a/units/template/_tpl_settings.c +++ b/units/template/_tpl_settings.c @@ -7,7 +7,6 @@ #define TPL_INTERNAL #include "_tpl_internal.h" -#include "_tpl_settings.h" /** Load from a binary buffer stored in Flash */ void TPL_loadBinary(Unit *unit, PayloadParser *pp) diff --git a/units/template/_tpl_settings.h b/units/template/_tpl_settings.h deleted file mode 100644 index 79b8911..0000000 --- a/units/template/_tpl_settings.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by MightyPork on 2018/02/03. -// - -#ifndef GEX_F072_TPL_SETTINGS_H -#define GEX_F072_TPL_SETTINGS_H - -#ifndef TPL_INTERNAL -#error bad include! -#endif - -#include "unit_base.h" - -/** Allocate data structure and set defaults */ -error_t TPL_preInit(Unit *unit); - -/** Load from a binary buffer stored in Flash */ -void TPL_loadBinary(Unit *unit, PayloadParser *pp); - -/** Write to a binary buffer for storing in Flash */ -void TPL_writeBinary(Unit *unit, PayloadBuilder *pb); - -// ------------------------------------------------------------------------ - -/** Parse a key-value pair from the INI file */ -error_t TPL_loadIni(Unit *unit, const char *key, const char *value); - -/** Generate INI file section for the unit */ -void TPL_writeIni(Unit *unit, IniWriter *iw); - -#endif //GEX_F072_TPL_SETTINGS_H diff --git a/units/template/unit_tpl.c b/units/template/unit_tpl.c index 566636e..8770354 100644 --- a/units/template/unit_tpl.c +++ b/units/template/unit_tpl.c @@ -7,8 +7,6 @@ #define TPL_INTERNAL #include "_tpl_internal.h" -#include "_tpl_settings.h" -#include "_tpl_init.h" // ------------------------------------------------------------------------ diff --git a/units/usart/_usart_internal.h b/units/usart/_usart_internal.h index 8db5983..243651e 100644 --- a/units/usart/_usart_internal.h +++ b/units/usart/_usart_internal.h @@ -63,9 +63,6 @@ struct priv { volatile bool tx_dma_busy; //!< Flag that the Tx DMA request is ongoing }; -/** Allocate data structure and set defaults */ -error_t UUSART_preInit(Unit *unit); - // ------------------------------------------------------------------------ /** Load from a binary buffer stored in Flash */ @@ -84,6 +81,9 @@ void UUSART_writeIni(Unit *unit, IniWriter *iw); // ------------------------------------------------------------------------ +/** Allocate data structure and set defaults */ +error_t UUSART_preInit(Unit *unit); + /** Tear down the unit */ void UUSART_deInit(Unit *unit);