added the template unit

sipo
Ondřej Hruška 6 years ago
parent 8643d16989
commit 2006936c21
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      units/template/!README.TXT
  2. 11
      units/template/_tpl_api.c
  3. 50
      units/template/_tpl_init.c
  4. 20
      units/template/_tpl_init.h
  5. 21
      units/template/_tpl_internal.h
  6. 59
      units/template/_tpl_settings.c
  7. 31
      units/template/_tpl_settings.h
  8. 58
      units/template/unit_tpl.c
  9. 42
      units/template/unit_tpl.h

@ -0,0 +1,2 @@
This is a template unit, used for reference when creating new units.
It is not registered into the unit registry, and cannot be instantiated.

@ -0,0 +1,11 @@
//
// Created by MightyPork on 2018/02/03.
//
#include "platform.h"
#include "unit_base.h"
#include "unit_tpl.h"
#define TPL_INTERNAL
#include "_tpl_internal.h"

@ -0,0 +1,50 @@
//
// Created by MightyPork on 2018/02/03.
//
#include "platform.h"
#include "unit_base.h"
#define TPL_INTERNAL
#include "_tpl_internal.h"
#include "_tpl_init.h"
/** Allocate data structure and set defaults */
error_t TPL_preInit(Unit *unit)
{
struct priv *priv = unit->data = calloc_ck(1, sizeof(struct priv));
if (priv == NULL) return E_OUT_OF_MEM;
//
return E_SUCCESS;
}
/** Finalize unit set-up */
error_t TPL_init(Unit *unit)
{
bool suc = true;
struct priv *priv = unit->data;
//
return E_SUCCESS;
}
/** Tear down the unit */
void TPL_deInit(Unit *unit)
{
struct priv *priv = unit->data;
// de-init peripherals
if (unit->status == E_SUCCESS ) {
//
}
// Release all resources, deinit pins
rsc_teardown(unit);
// Free memory
free_ck(unit->data);
}

@ -0,0 +1,20 @@
//
// 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

@ -0,0 +1,21 @@
//
// Created by MightyPork on 2018/02/03.
//
#ifndef GEX_F072_TPL_INTERNAL_H
#define GEX_F072_TPL_INTERNAL_H
#ifndef TPL_INTERNAL
#error bad include!
#endif
#include "unit_base.h"
/** Private data structure */
struct priv {
// settings
// internal state
};
#endif //GEX_F072_TPL_INTERNAL_H

@ -0,0 +1,59 @@
//
// Created by MightyPork on 2018/02/03.
//
#include "platform.h"
#include "unit_base.h"
#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)
{
struct priv *priv = unit->data;
uint8_t version = pp_u8(pp);
(void)version;
//
}
/** Write to a binary buffer for storing in Flash */
void TPL_writeBinary(Unit *unit, PayloadBuilder *pb)
{
struct priv *priv = unit->data;
pb_u8(pb, 0); // version
//
}
// ------------------------------------------------------------------------
/** Parse a key-value pair from the INI file */
error_t TPL_loadIni(Unit *unit, const char *key, const char *value)
{
bool suc = true;
struct priv *priv = unit->data;
if (false) {
//
}
else {
return E_BAD_KEY;
}
if (!suc) return E_BAD_VALUE;
return E_SUCCESS;
}
/** Generate INI file section for the unit */
void TPL_writeIni(Unit *unit, IniWriter *iw)
{
struct priv *priv = unit->data;
//
}

@ -0,0 +1,31 @@
//
// 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

@ -0,0 +1,58 @@
//
// Created by MightyPork on 2017/11/25.
//
#include "unit_base.h"
#include "unit_tpl.h"
#define TPL_INTERNAL
#include "_tpl_internal.h"
#include "_tpl_settings.h"
#include "_tpl_init.h"
// ------------------------------------------------------------------------
enum TplCmd_ {
//
};
/** Handle a request message */
static error_t TPL_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
{
switch (command) {
default:
return E_UNKNOWN_COMMAND;
}
}
// ------------------------------------------------------------------------
/**
* Handle update-tick (if configured in init)
*
* @param unit
*/
static void TPL_updateTick(Unit *unit)
{
//
}
// ------------------------------------------------------------------------
/** Unit template */
const UnitDriver UNIT_TPL = {
.name = "TPL",
.description = "Template unit",
// Settings
.preInit = TPL_preInit,
.cfgLoadBinary = TPL_loadBinary,
.cfgWriteBinary = TPL_writeBinary,
.cfgLoadIni = TPL_loadIni,
.cfgWriteIni = TPL_writeIni,
// Init
.init = TPL_init,
.deInit = TPL_deInit,
// Function
.handleRequest = TPL_handleRequest,
.updateTick = TPL_updateTick,
};

@ -0,0 +1,42 @@
//
// Created by MightyPork on 2017/11/25.
//
// Digital input unit; single or multiple pin read access on one port (A-F)
//
#ifndef U_DIN_H
#define U_DIN_H
#include "unit.h"
extern const UnitDriver UNIT_DIN;
/**
* Read pins
*
* @param unit - unit instance
* @param packed - output; the packed (right aligned) bits representing the pins, highest to lowest, are written here.
* @return success
*/
error_t UU_DI_Read(Unit *unit, uint16_t *packed);
/**
* Arm pins for trigger generation
*
* @param unit - unit instance
* @param arm_single_packed - packed bit map of pins to arm for single trigger
* @param arm_auto_packed - packed bit map of pins to arm for auto trigger (repeated)
* @return success
*/
error_t UU_DI_Arm(Unit *unit, uint16_t arm_single_packed, uint16_t arm_auto_packed);
/**
* Dis-arm pins to not generate events
*
* @param unit - unit instance
* @param disarm_packed - packed bit map of pins to dis-arm
* @return success
*/
error_t UU_DI_DisArm(Unit *unit, uint16_t disarm_packed);
#endif //U_DIN_H
Loading…
Cancel
Save