ADC skeleton

adc
Ondřej Hruška 7 years ago
parent 611b38c5e6
commit 538a4876b2
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 11
      units/adc/_adc_api.c
  2. 49
      units/adc/_adc_init.c
  3. 46
      units/adc/_adc_internal.h
  4. 58
      units/adc/_adc_settings.c
  5. 43
      units/adc/unit_adc.c
  6. 16
      units/adc/unit_adc.h
  7. 1
      units/digital_in/_din_exti.c
  8. 2
      units/i2c/unit_i2c.c
  9. 4
      units/spi/unit_spi.c
  10. 6
      units/template/_tpl_init.c
  11. 14
      units/template/_tpl_internal.h
  12. 8
      units/template/_tpl_settings.c
  13. 23
      units/template/unit_tpl.c
  14. 36
      units/template/unit_tpl.h

@ -0,0 +1,11 @@
//
// Created by MightyPork on 2018/02/03.
//
#include "platform.h"
#include "unit_base.h"
#include "unit_adc.h"
#define ADC_INTERNAL
#include "_adc_internal.h"

@ -0,0 +1,49 @@
//
// Created by MightyPork on 2018/02/03.
//
#include "platform.h"
#include "unit_base.h"
#define ADC_INTERNAL
#include "_adc_internal.h"
/** Allocate data structure and set defaults */
error_t UADC_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 UADC_init(Unit *unit)
{
bool suc = true;
struct priv *priv = unit->data;
//
return E_SUCCESS;
}
/** Tear down the unit */
void UADC_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,46 @@
//
// Created by MightyPork on 2018/02/03.
//
#ifndef GEX_F072_ADC_INTERNAL_H
#define GEX_F072_ADC_INTERNAL_H
#ifndef ADC_INTERNAL
#error bad include!
#endif
#include "unit_base.h"
/** Private data structure */
struct priv {
// settings
// internal state
};
/** Allocate data structure and set defaults */
error_t UADC_preInit(Unit *unit);
/** Load from a binary buffer stored in Flash */
void UADC_loadBinary(Unit *unit, PayloadParser *pp);
/** Write to a binary buffer for storing in Flash */
void UADC_writeBinary(Unit *unit, PayloadBuilder *pb);
// ------------------------------------------------------------------------
/** Parse a key-value pair from the INI file */
error_t UADC_loadIni(Unit *unit, const char *key, const char *value);
/** Generate INI file section for the unit */
void UADC_writeIni(Unit *unit, IniWriter *iw);
// ------------------------------------------------------------------------
/** Finalize unit set-up */
error_t UADC_init(Unit *unit);
/** Tear down the unit */
void UADC_deInit(Unit *unit);
#endif //GEX_F072_ADC_INTERNAL_H

@ -0,0 +1,58 @@
//
// Created by MightyPork on 2018/02/03.
//
#include "platform.h"
#include "unit_base.h"
#define ADC_INTERNAL
#include "_adc_internal.h"
/** Load from a binary buffer stored in Flash */
void UADC_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 UADC_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 UADC_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 UADC_writeIni(Unit *unit, IniWriter *iw)
{
struct priv *priv = unit->data;
//
}

@ -0,0 +1,43 @@
//
// Created by MightyPork on 2017/11/25.
//
#include "unit_base.h"
#include "unit_adc.h"
#define ADC_INTERNAL
#include "_adc_internal.h"
// ------------------------------------------------------------------------
enum TplCmd_ {
//
};
/** Handle a request message */
static error_t UADC_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
{
switch (command) {
default:
return E_UNKNOWN_COMMAND;
}
}
// ------------------------------------------------------------------------
/** Unit template */
const UnitDriver UNIT_ADC = {
.name = "ADC",
.description = "Template unit",
// Settings
.preInit = UADC_preInit,
.cfgLoadBinary = UADC_loadBinary,
.cfgWriteBinary = UADC_writeBinary,
.cfgLoadIni = UADC_loadIni,
.cfgWriteIni = UADC_writeIni,
// Init
.init = UADC_init,
.deInit = UADC_deInit,
// Function
.handleRequest = UADC_handleRequest,
};

@ -0,0 +1,16 @@
//
// Created by MightyPork on 2017/11/25.
//
// Digital input unit; single or multiple pin read access on one port (A-F)
//
#ifndef U_TPL_H
#define U_TPL_H
#include "unit.h"
extern const UnitDriver UNIT_ADC;
// UU_ prototypes
#endif //U_TPL_H

@ -8,7 +8,6 @@
#define DIN_INTERNAL
#include "_din_internal.h"
#include "_din_exti.h"
/**
* Send a trigger event to master (called on the message queue thread).

@ -10,8 +10,6 @@
// I2C master
#define I2C_INTERNAL
#include "_i2c_internal.h"
#include "_i2c_settings.h"
#include "_i2c_init.h"
enum PinCmd_ {
CMD_TEST = 0,

@ -20,7 +20,7 @@ enum PinCmd_ {
};
/** Handle a request message */
static error_t SPI_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
static error_t USPI_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
{
uint8_t slave;
uint16_t slaves;
@ -80,5 +80,5 @@ const UnitDriver UNIT_SPI = {
.init = USPI_init,
.deInit = USPI_deInit,
// Function
.handleRequest = SPI_handleRequest,
.handleRequest = USPI_handleRequest,
};

@ -9,7 +9,7 @@
#include "_tpl_internal.h"
/** Allocate data structure and set defaults */
error_t TPL_preInit(Unit *unit)
error_t UTPL_preInit(Unit *unit)
{
struct priv *priv = unit->data = calloc_ck(1, sizeof(struct priv));
if (priv == NULL) return E_OUT_OF_MEM;
@ -20,7 +20,7 @@ error_t TPL_preInit(Unit *unit)
}
/** Finalize unit set-up */
error_t TPL_init(Unit *unit)
error_t UTPL_init(Unit *unit)
{
bool suc = true;
struct priv *priv = unit->data;
@ -32,7 +32,7 @@ error_t TPL_init(Unit *unit)
/** Tear down the unit */
void TPL_deInit(Unit *unit)
void UTPL_deInit(Unit *unit)
{
struct priv *priv = unit->data;

@ -19,28 +19,28 @@ struct priv {
};
/** Allocate data structure and set defaults */
error_t TPL_preInit(Unit *unit);
error_t UTPL_preInit(Unit *unit);
/** Load from a binary buffer stored in Flash */
void TPL_loadBinary(Unit *unit, PayloadParser *pp);
void UTPL_loadBinary(Unit *unit, PayloadParser *pp);
/** Write to a binary buffer for storing in Flash */
void TPL_writeBinary(Unit *unit, PayloadBuilder *pb);
void UTPL_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);
error_t UTPL_loadIni(Unit *unit, const char *key, const char *value);
/** Generate INI file section for the unit */
void TPL_writeIni(Unit *unit, IniWriter *iw);
void UTPL_writeIni(Unit *unit, IniWriter *iw);
// ------------------------------------------------------------------------
/** Finalize unit set-up */
error_t TPL_init(Unit *unit);
error_t UTPL_init(Unit *unit);
/** Tear down the unit */
void TPL_deInit(Unit *unit);
void UTPL_deInit(Unit *unit);
#endif //GEX_F072_TPL_INTERNAL_H

@ -9,7 +9,7 @@
#include "_tpl_internal.h"
/** Load from a binary buffer stored in Flash */
void TPL_loadBinary(Unit *unit, PayloadParser *pp)
void UTPL_loadBinary(Unit *unit, PayloadParser *pp)
{
struct priv *priv = unit->data;
@ -20,7 +20,7 @@ void TPL_loadBinary(Unit *unit, PayloadParser *pp)
}
/** Write to a binary buffer for storing in Flash */
void TPL_writeBinary(Unit *unit, PayloadBuilder *pb)
void UTPL_writeBinary(Unit *unit, PayloadBuilder *pb)
{
struct priv *priv = unit->data;
@ -32,7 +32,7 @@ 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)
error_t UTPL_loadIni(Unit *unit, const char *key, const char *value)
{
bool suc = true;
struct priv *priv = unit->data;
@ -49,7 +49,7 @@ 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)
void UTPL_writeIni(Unit *unit, IniWriter *iw)
{
struct priv *priv = unit->data;

@ -15,7 +15,8 @@ enum TplCmd_ {
};
/** Handle a request message */
static error_t TPL_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
static error_t UTPL_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command,
PayloadParser *pp)
{
switch (command) {
default:
@ -30,7 +31,7 @@ static error_t TPL_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Pa
*
* @param unit
*/
static void TPL_updateTick(Unit *unit)
static void UTPL_updateTick(Unit *unit)
{
//
}
@ -42,15 +43,15 @@ 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,
.preInit = UTPL_preInit,
.cfgLoadBinary = UTPL_loadBinary,
.cfgWriteBinary = UTPL_writeBinary,
.cfgLoadIni = UTPL_loadIni,
.cfgWriteIni = UTPL_writeIni,
// Init
.init = TPL_init,
.deInit = TPL_deInit,
.init = UTPL_init,
.deInit = UTPL_deInit,
// Function
.handleRequest = TPL_handleRequest,
.updateTick = TPL_updateTick,
.handleRequest = UTPL_handleRequest,
.updateTick = UTPL_updateTick,
};

@ -4,39 +4,13 @@
// Digital input unit; single or multiple pin read access on one port (A-F)
//
#ifndef U_DIN_H
#define U_DIN_H
#ifndef U_TPL_H
#define U_TPL_H
#include "unit.h"
extern const UnitDriver UNIT_DIN;
extern const UnitDriver UNIT_TPL;
/**
* 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);
// UU_ prototypes
/**
* 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
#endif //U_TPL_H

Loading…
Cancel
Save