fixes, and use the new rsc parsing for some unit pins
This commit is contained in:
@@ -18,9 +18,7 @@ void OW_loadBinary(Unit *unit, PayloadParser *pp)
|
||||
|
||||
priv->port_name = pp_char(pp);
|
||||
priv->pin_number = pp_u8(pp);
|
||||
if (version >= 1) {
|
||||
priv->parasitic = pp_bool(pp);
|
||||
}
|
||||
priv->parasitic = pp_bool(pp);
|
||||
}
|
||||
|
||||
/** Write to a binary buffer for storing in Flash */
|
||||
@@ -28,7 +26,7 @@ void OW_writeBinary(Unit *unit, PayloadBuilder *pb)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
pb_u8(pb, 1); // version
|
||||
pb_u8(pb, 0); // version
|
||||
|
||||
pb_char(pb, priv->port_name);
|
||||
pb_u8(pb, priv->pin_number);
|
||||
|
||||
@@ -20,15 +20,10 @@ void DIn_loadBinary(Unit *unit, PayloadParser *pp)
|
||||
priv->pins = pp_u16(pp);
|
||||
priv->pulldown = pp_u16(pp);
|
||||
priv->pullup = pp_u16(pp);
|
||||
|
||||
if (version >= 1) {
|
||||
priv->trig_rise = pp_u16(pp);
|
||||
priv->trig_fall = pp_u16(pp);
|
||||
priv->trig_holdoff = pp_u16(pp);
|
||||
}
|
||||
if (version >= 2) {
|
||||
priv->def_auto = pp_u16(pp);
|
||||
}
|
||||
priv->trig_rise = pp_u16(pp);
|
||||
priv->trig_fall = pp_u16(pp);
|
||||
priv->trig_holdoff = pp_u16(pp);
|
||||
priv->def_auto = pp_u16(pp);
|
||||
}
|
||||
|
||||
/** Write to a binary buffer for storing in Flash */
|
||||
@@ -36,7 +31,7 @@ void DIn_writeBinary(Unit *unit, PayloadBuilder *pb)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
pb_u8(pb, 2); // version
|
||||
pb_u8(pb, 0); // version
|
||||
|
||||
pb_char(pb, priv->port_name);
|
||||
pb_u16(pb, priv->pins);
|
||||
|
||||
@@ -18,14 +18,11 @@ void UFCAP_loadBinary(Unit *unit, PayloadParser *pp)
|
||||
|
||||
priv->conf.signal_pname = pp_char(pp);
|
||||
priv->conf.signal_pnum = pp_u8(pp);
|
||||
|
||||
if (version >= 1) {
|
||||
priv->conf.active_level = pp_bool(pp);
|
||||
priv->conf.dfilter = pp_u8(pp);
|
||||
priv->conf.direct_presc = pp_u8(pp);
|
||||
priv->conf.direct_msec = pp_u16(pp);
|
||||
priv->conf.startmode = (enum fcap_opmode) pp_u8(pp);
|
||||
}
|
||||
priv->conf.active_level = pp_bool(pp);
|
||||
priv->conf.dfilter = pp_u8(pp);
|
||||
priv->conf.direct_presc = pp_u8(pp);
|
||||
priv->conf.direct_msec = pp_u16(pp);
|
||||
priv->conf.startmode = (enum fcap_opmode) pp_u8(pp);
|
||||
}
|
||||
|
||||
/** Write to a binary buffer for storing in Flash */
|
||||
@@ -33,12 +30,10 @@ void UFCAP_writeBinary(Unit *unit, PayloadBuilder *pb)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
pb_u8(pb, 1); // version
|
||||
pb_u8(pb, 0); // version
|
||||
|
||||
pb_char(pb, priv->conf.signal_pname);
|
||||
pb_u8(pb, priv->conf.signal_pnum);
|
||||
|
||||
// V1
|
||||
pb_bool(pb, priv->conf.active_level);
|
||||
pb_u8(pb, priv->conf.dfilter);
|
||||
pb_u8(pb, priv->conf.direct_presc);
|
||||
|
||||
@@ -20,10 +20,7 @@ void UI2C_loadBinary(Unit *unit, PayloadParser *pp)
|
||||
priv->anf = pp_bool(pp);
|
||||
priv->dnf = pp_u8(pp);
|
||||
priv->speed = pp_u8(pp);
|
||||
|
||||
if (version >= 1) {
|
||||
priv->remap = pp_u8(pp);
|
||||
}
|
||||
priv->remap = pp_u8(pp);
|
||||
}
|
||||
|
||||
/** Write to a binary buffer for storing in Flash */
|
||||
@@ -31,7 +28,7 @@ void UI2C_writeBinary(Unit *unit, PayloadBuilder *pb)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
pb_u8(pb, 1); // version
|
||||
pb_u8(pb, 0); // version
|
||||
|
||||
pb_u8(pb, priv->periph_num);
|
||||
pb_bool(pb, priv->anf);
|
||||
|
||||
@@ -16,7 +16,7 @@ error_t UU_Npx_Clear(Unit *unit)
|
||||
CHECK_TYPE(unit, &UNIT_NEOPIXEL);
|
||||
|
||||
struct priv *priv = unit->data;
|
||||
ws2812_clear(priv->port, priv->ll_pin, priv->pixels);
|
||||
ws2812_clear(priv->port, priv->ll_pin, priv->cfg.pixels);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ error_t UU_Npx_Load(Unit *unit, const uint8_t *packed_rgb, uint32_t nbytes)
|
||||
CHECK_TYPE(unit, &UNIT_NEOPIXEL);
|
||||
|
||||
struct priv *priv = unit->data;
|
||||
if (nbytes != 3*priv->pixels) return E_BAD_COUNT;
|
||||
ws2812_load_raw(priv->port, priv->ll_pin, packed_rgb, priv->pixels);
|
||||
if (nbytes != 3*priv->cfg.pixels) return E_BAD_COUNT;
|
||||
ws2812_load_raw(priv->port, priv->ll_pin, packed_rgb, priv->cfg.pixels);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ static error_t load_u32(Unit *unit, const uint8_t *bytes, uint32_t nbytes, bool
|
||||
CHECK_TYPE(unit, &UNIT_NEOPIXEL);
|
||||
|
||||
struct priv *priv = unit->data;
|
||||
if (nbytes != 4*priv->pixels) return E_BAD_COUNT;
|
||||
ws2812_load_sparse(priv->port, priv->ll_pin, bytes, priv->pixels, bige);
|
||||
if (nbytes != 4*priv->cfg.pixels) return E_BAD_COUNT;
|
||||
ws2812_load_sparse(priv->port, priv->ll_pin, bytes, priv->cfg.pixels, bige);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,6 @@ error_t UU_Npx_GetCount(Unit *unit, uint16_t *count)
|
||||
CHECK_TYPE(unit, &UNIT_NEOPIXEL);
|
||||
|
||||
struct priv *priv = unit->data;
|
||||
*count = priv->pixels;
|
||||
*count = priv->cfg.pixels;
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,8 @@ error_t Npx_preInit(Unit *unit)
|
||||
if (priv == NULL) return E_OUT_OF_MEM;
|
||||
|
||||
// some defaults
|
||||
priv->pin_number = 0;
|
||||
priv->port_name = 'A';
|
||||
priv->pixels = 1;
|
||||
priv->cfg.pin = R_PA0;
|
||||
priv->cfg.pixels = 1;
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
@@ -30,13 +29,9 @@ error_t Npx_init(Unit *unit)
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
// --- Parse config ---
|
||||
priv->ll_pin = hw_pin2ll(priv->pin_number, &suc);
|
||||
priv->port = hw_port2periph(priv->port_name, &suc);
|
||||
Resource rsc = rsc_portpin2rsc(priv->port_name, priv->pin_number, &suc);
|
||||
suc = hw_pinrsc2ll(priv->cfg.pin, &priv->port, &priv->ll_pin);
|
||||
if (!suc) return E_BAD_CONFIG;
|
||||
|
||||
// --- Claim resources ---
|
||||
TRY(rsc_claim(unit, rsc));
|
||||
TRY(rsc_claim(unit, priv->cfg.pin));
|
||||
|
||||
// --- Init hardware ---
|
||||
LL_GPIO_SetPinMode(priv->port, priv->ll_pin, LL_GPIO_MODE_OUTPUT);
|
||||
@@ -45,7 +40,7 @@ error_t Npx_init(Unit *unit)
|
||||
|
||||
// clear strip
|
||||
|
||||
ws2812_clear(priv->port, priv->ll_pin, priv->pixels);
|
||||
ws2812_clear(priv->port, priv->ll_pin, priv->cfg.pixels);
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
|
||||
/** Private data structure */
|
||||
struct priv {
|
||||
char port_name;
|
||||
uint8_t pin_number;
|
||||
uint16_t pixels;
|
||||
struct {
|
||||
Resource pin;
|
||||
uint16_t pixels;
|
||||
} cfg;
|
||||
|
||||
uint32_t ll_pin;
|
||||
GPIO_TypeDef *port;
|
||||
|
||||
@@ -13,9 +13,8 @@ void Npx_loadBinary(Unit *unit, PayloadParser *pp)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
priv->port_name = pp_char(pp);
|
||||
priv->pin_number = pp_u8(pp);
|
||||
priv->pixels = pp_u16(pp);
|
||||
priv->cfg.pin = (Resource) pp_u8(pp);
|
||||
priv->cfg.pixels = pp_u16(pp);
|
||||
}
|
||||
|
||||
/** Write to a binary buffer for storing in Flash */
|
||||
@@ -23,9 +22,8 @@ void Npx_writeBinary(Unit *unit, PayloadBuilder *pb)
|
||||
{
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
pb_char(pb, priv->port_name);
|
||||
pb_u8(pb, priv->pin_number);
|
||||
pb_u16(pb, priv->pixels);
|
||||
pb_u8(pb, priv->cfg.pin);
|
||||
pb_u16(pb, priv->cfg.pixels);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -37,10 +35,10 @@ error_t Npx_loadIni(Unit *unit, const char *key, const char *value)
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
if (streq(key, "pin")) {
|
||||
suc = cfg_portpin_parse(value, &priv->port_name, &priv->pin_number);
|
||||
priv->cfg.pin = cfg_pinrsc_parse(value, &suc);
|
||||
}
|
||||
else if (streq(key, "pixels")) {
|
||||
priv->pixels = cfg_u16_parse(value, &suc);
|
||||
priv->cfg.pixels = cfg_u16_parse(value, &suc);
|
||||
}
|
||||
else {
|
||||
return E_BAD_KEY;
|
||||
@@ -56,8 +54,8 @@ void Npx_writeIni(Unit *unit, IniWriter *iw)
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
iw_comment(iw, "Data pin");
|
||||
iw_entry(iw, "pin", "%c%d", priv->port_name, priv->pin_number);
|
||||
iw_entry(iw, "pin", cfg_pinrsc_encode(priv->cfg.pin));
|
||||
|
||||
iw_comment(iw, "Number of pixels");
|
||||
iw_entry(iw, "pixels", "%d", priv->pixels);
|
||||
iw_entry(iw, "pixels", "%d", priv->cfg.pixels);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ error_t UU_SIPO_Write(Unit *unit, const uint8_t *buffer, uint16_t buflen, uint16
|
||||
// buffer contains data for the individual data pins, back to back as AAA BBB CCC (whole bytes)
|
||||
const uint8_t data_width = priv->data_width;
|
||||
const uint16_t bytelen = buflen / data_width;
|
||||
const uint16_t mask = priv->data_pins;
|
||||
const uint16_t mask = priv->cfg.data_pins;
|
||||
|
||||
uint8_t offsets[16];
|
||||
for (int i=0; i<16; i++) offsets[i] = (uint8_t) (bytelen * i);
|
||||
@@ -61,7 +61,7 @@ error_t UU_SIPO_Write(Unit *unit, const uint8_t *buffer, uint16_t buflen, uint16
|
||||
priv->data_port->BSRR = spread | (((~spread) & mask) << 16);
|
||||
|
||||
// Shift clock pulse
|
||||
send_pulse(priv->shift_pol, priv->shift_port, priv->shift_ll);
|
||||
send_pulse(priv->cfg.shift_pol, priv->shift_port, priv->shift_ll);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ error_t UU_SIPO_Write(Unit *unit, const uint8_t *buffer, uint16_t buflen, uint16
|
||||
uint16_t spread = pinmask_spread(terminal_data, mask);
|
||||
priv->data_port->BSRR = spread | (((~spread) & mask) << 16);
|
||||
|
||||
send_pulse(priv->store_pol, priv->store_port, priv->store_ll);
|
||||
send_pulse(priv->cfg.store_pol, priv->store_port, priv->store_ll);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
#pragma GCC pop_options
|
||||
@@ -80,8 +80,8 @@ error_t UU_SIPO_DirectData(Unit *unit, uint16_t data_packed)
|
||||
CHECK_TYPE(unit, &UNIT_SIPO);
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
uint16_t spread = pinmask_spread(data_packed, priv->data_pins);
|
||||
priv->data_port->BSRR = spread | (((~spread) & priv->data_pins) << 16);
|
||||
uint16_t spread = pinmask_spread(data_packed, priv->cfg.data_pins);
|
||||
priv->data_port->BSRR = spread | (((~spread) & priv->cfg.data_pins) << 16);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ error_t UU_SIPO_DirectClear(Unit *unit)
|
||||
{
|
||||
CHECK_TYPE(unit, &UNIT_SIPO);
|
||||
struct priv *priv = unit->data;
|
||||
send_pulse(priv->clear_pol, priv->clear_port, priv->clear_ll);
|
||||
send_pulse(priv->cfg.clear_pol, priv->clear_port, priv->clear_ll);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ error_t UU_SIPO_DirectShift(Unit *unit)
|
||||
{
|
||||
CHECK_TYPE(unit, &UNIT_SIPO);
|
||||
struct priv *priv = unit->data;
|
||||
send_pulse(priv->shift_pol, priv->shift_port, priv->shift_ll);
|
||||
send_pulse(priv->cfg.shift_pol, priv->shift_port, priv->shift_ll);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -105,6 +105,6 @@ error_t UU_SIPO_DirectStore(Unit *unit)
|
||||
{
|
||||
CHECK_TYPE(unit, &UNIT_SIPO);
|
||||
struct priv *priv = unit->data;
|
||||
send_pulse(priv->store_pol, priv->store_port, priv->store_ll);
|
||||
send_pulse(priv->cfg.store_pol, priv->store_port, priv->store_ll);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
+21
-34
@@ -14,20 +14,17 @@ error_t USIPO_preInit(Unit *unit)
|
||||
struct priv *priv = unit->data = calloc_ck(1, sizeof(struct priv));
|
||||
if (priv == NULL) return E_OUT_OF_MEM;
|
||||
|
||||
priv->store_pname = 'A';
|
||||
priv->store_pnum = 0;
|
||||
priv->store_pol = true;
|
||||
priv->cfg.pin_store = R_PA0;
|
||||
priv->cfg.store_pol = true;
|
||||
|
||||
priv->shift_pname = 'A';
|
||||
priv->shift_pnum = 1;
|
||||
priv->shift_pol = true;
|
||||
priv->cfg.pin_shift = R_PA1;
|
||||
priv->cfg.shift_pol = true;
|
||||
|
||||
priv->clear_pname = 'A';
|
||||
priv->clear_pnum = 2;
|
||||
priv->clear_pol = false;
|
||||
priv->cfg.pin_clear = R_PA2;
|
||||
priv->cfg.clear_pol = false;
|
||||
|
||||
priv->data_pname = 'A';
|
||||
priv->data_pins = (1<<3);
|
||||
priv->cfg.data_pname = 'A';
|
||||
priv->cfg.data_pins = (1<<3);
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
@@ -39,33 +36,23 @@ error_t USIPO_init(Unit *unit)
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
// --- Parse config ---
|
||||
priv->store_ll = hw_pin2ll(priv->store_pnum, &suc);
|
||||
priv->store_port = hw_port2periph(priv->store_pname, &suc);
|
||||
Resource store_rsc = rsc_portpin2rsc(priv->store_pname, priv->store_pnum, &suc);
|
||||
suc &= hw_pinrsc2ll(priv->cfg.pin_store, &priv->store_port, &priv->store_ll);
|
||||
suc &= hw_pinrsc2ll(priv->cfg.pin_shift, &priv->shift_port, &priv->shift_ll);
|
||||
suc &= hw_pinrsc2ll(priv->cfg.pin_clear, &priv->clear_port, &priv->clear_ll);
|
||||
if (!suc) return E_BAD_CONFIG;
|
||||
TRY(rsc_claim(unit, store_rsc));
|
||||
|
||||
priv->shift_ll = hw_pin2ll(priv->shift_pnum, &suc);
|
||||
priv->shift_port = hw_port2periph(priv->shift_pname, &suc);
|
||||
Resource shift_rsc = rsc_portpin2rsc(priv->shift_pname, priv->shift_pnum, &suc);
|
||||
if (!suc) return E_BAD_CONFIG;
|
||||
TRY(rsc_claim(unit, shift_rsc));
|
||||
|
||||
priv->clear_ll = hw_pin2ll(priv->clear_pnum, &suc);
|
||||
priv->clear_port = hw_port2periph(priv->clear_pname, &suc);
|
||||
Resource clear_rsc = rsc_portpin2rsc(priv->clear_pname, priv->clear_pnum, &suc);
|
||||
if (!suc) return E_BAD_CONFIG;
|
||||
TRY(rsc_claim(unit, clear_rsc));
|
||||
TRY(rsc_claim(unit, priv->cfg.pin_store));
|
||||
TRY(rsc_claim(unit, priv->cfg.pin_shift));
|
||||
TRY(rsc_claim(unit, priv->cfg.pin_clear));
|
||||
|
||||
// Claim all needed pins
|
||||
TRY(rsc_claim_gpios(unit, priv->data_pname, priv->data_pins));
|
||||
priv->data_port = hw_port2periph(priv->data_pname, &suc);
|
||||
TRY(rsc_claim_gpios(unit, priv->cfg.data_pname, priv->cfg.data_pins));
|
||||
priv->data_port = hw_port2periph(priv->cfg.data_pname, &suc);
|
||||
|
||||
// --- Init hardware ---
|
||||
|
||||
priv->data_width = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (priv->data_pins & (1 << i)) {
|
||||
if (priv->cfg.data_pins & (1 << i)) {
|
||||
uint32_t ll_pin = hw_pin2ll((uint8_t) i, &suc);
|
||||
LL_GPIO_SetPinMode(priv->data_port, ll_pin, LL_GPIO_MODE_OUTPUT);
|
||||
LL_GPIO_SetPinOutputType(priv->data_port, ll_pin, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
@@ -75,7 +62,7 @@ error_t USIPO_init(Unit *unit)
|
||||
}
|
||||
|
||||
// Set the initial state - zeros
|
||||
priv->data_port->ODR &= ~priv->data_pins;
|
||||
priv->data_port->ODR &= ~priv->cfg.data_pins;
|
||||
|
||||
|
||||
// STORE
|
||||
@@ -83,7 +70,7 @@ error_t USIPO_init(Unit *unit)
|
||||
LL_GPIO_SetPinOutputType(priv->store_port, priv->store_ll, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
LL_GPIO_SetPinSpeed(priv->store_port, priv->store_ll, LL_GPIO_SPEED_FREQ_HIGH);
|
||||
|
||||
if (priv->store_pol)
|
||||
if (priv->cfg.store_pol)
|
||||
LL_GPIO_ResetOutputPin(priv->store_port, priv->store_ll);
|
||||
else
|
||||
LL_GPIO_SetOutputPin(priv->store_port, priv->store_ll);
|
||||
@@ -93,7 +80,7 @@ error_t USIPO_init(Unit *unit)
|
||||
LL_GPIO_SetPinOutputType(priv->shift_port, priv->shift_ll, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
LL_GPIO_SetPinSpeed(priv->shift_port, priv->shift_ll, LL_GPIO_SPEED_FREQ_HIGH);
|
||||
|
||||
if (priv->shift_pol)
|
||||
if (priv->cfg.shift_pol)
|
||||
LL_GPIO_ResetOutputPin(priv->shift_port, priv->shift_ll);
|
||||
else
|
||||
LL_GPIO_SetOutputPin(priv->shift_port, priv->shift_ll);
|
||||
@@ -103,7 +90,7 @@ error_t USIPO_init(Unit *unit)
|
||||
LL_GPIO_SetPinOutputType(priv->clear_port, priv->clear_ll, LL_GPIO_OUTPUT_PUSHPULL);
|
||||
LL_GPIO_SetPinSpeed(priv->clear_port, priv->clear_ll, LL_GPIO_SPEED_FREQ_HIGH);
|
||||
|
||||
if (priv->clear_pol)
|
||||
if (priv->cfg.clear_pol)
|
||||
LL_GPIO_ResetOutputPin(priv->clear_port, priv->clear_ll);
|
||||
else
|
||||
LL_GPIO_SetOutputPin(priv->clear_port, priv->clear_ll);
|
||||
|
||||
+11
-12
@@ -13,21 +13,20 @@
|
||||
|
||||
/** Private data structure */
|
||||
struct priv {
|
||||
// settings
|
||||
char store_pname;
|
||||
uint8_t store_pnum;
|
||||
bool store_pol; //!< Store pulse active edge
|
||||
struct {
|
||||
// settings
|
||||
Resource pin_store;
|
||||
bool store_pol; //!< Store pulse active edge
|
||||
|
||||
char shift_pname;
|
||||
uint8_t shift_pnum;
|
||||
bool shift_pol; //!< Shift clock active edge
|
||||
Resource pin_shift;
|
||||
bool shift_pol; //!< Shift clock active edge
|
||||
|
||||
char clear_pname;
|
||||
uint8_t clear_pnum;
|
||||
bool clear_pol; //!< Clear signal active level
|
||||
Resource pin_clear;
|
||||
bool clear_pol; //!< Clear signal active level
|
||||
|
||||
char data_pname;
|
||||
uint16_t data_pins;
|
||||
char data_pname;
|
||||
uint16_t data_pins;
|
||||
} cfg;
|
||||
|
||||
// live fields
|
||||
uint32_t store_ll;
|
||||
|
||||
+32
-38
@@ -16,20 +16,17 @@ void USIPO_loadBinary(Unit *unit, PayloadParser *pp)
|
||||
uint8_t version = pp_u8(pp);
|
||||
(void)version;
|
||||
|
||||
priv->store_pname = pp_char(pp);
|
||||
priv->store_pnum = pp_u8(pp);
|
||||
priv->store_pol = pp_bool(pp);
|
||||
priv->cfg.pin_store = (Resource) pp_u8(pp);
|
||||
priv->cfg.store_pol = pp_bool(pp);
|
||||
|
||||
priv->shift_pname = pp_char(pp);
|
||||
priv->shift_pnum = pp_u8(pp);
|
||||
priv->shift_pol = pp_bool(pp);
|
||||
priv->cfg.pin_shift = (Resource) pp_u8(pp);
|
||||
priv->cfg.shift_pol = pp_bool(pp);
|
||||
|
||||
priv->clear_pname = pp_char(pp);
|
||||
priv->clear_pnum = pp_u8(pp);
|
||||
priv->clear_pol = pp_bool(pp);
|
||||
priv->cfg.pin_clear = (Resource) pp_u8(pp);
|
||||
priv->cfg.clear_pol = pp_bool(pp);
|
||||
|
||||
priv->data_pname = pp_char(pp);
|
||||
priv->data_pins = pp_u16(pp);
|
||||
priv->cfg.data_pname = pp_char(pp);
|
||||
priv->cfg.data_pins = pp_u16(pp);
|
||||
}
|
||||
|
||||
/** Write to a binary buffer for storing in Flash */
|
||||
@@ -39,20 +36,17 @@ void USIPO_writeBinary(Unit *unit, PayloadBuilder *pb)
|
||||
|
||||
pb_u8(pb, 0); // version
|
||||
|
||||
pb_char(pb, priv->store_pname);
|
||||
pb_u8(pb, priv->store_pnum);
|
||||
pb_bool(pb, priv->store_pol);
|
||||
pb_u8(pb, priv->cfg.pin_store);
|
||||
pb_bool(pb, priv->cfg.store_pol);
|
||||
|
||||
pb_char(pb, priv->shift_pname);
|
||||
pb_u8(pb, priv->shift_pnum);
|
||||
pb_bool(pb, priv->shift_pol);
|
||||
pb_u8(pb, priv->cfg.pin_shift);
|
||||
pb_bool(pb, priv->cfg.shift_pol);
|
||||
|
||||
pb_char(pb, priv->clear_pname);
|
||||
pb_u8(pb, priv->clear_pnum);
|
||||
pb_bool(pb, priv->clear_pol);
|
||||
pb_u8(pb, priv->cfg.pin_clear);
|
||||
pb_bool(pb, priv->cfg.clear_pol);
|
||||
|
||||
pb_char(pb, priv->data_pname);
|
||||
pb_u16(pb, priv->data_pins);
|
||||
pb_char(pb, priv->cfg.data_pname);
|
||||
pb_u16(pb, priv->cfg.data_pins);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -64,30 +58,30 @@ error_t USIPO_loadIni(Unit *unit, const char *key, const char *value)
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
if (streq(key, "store-pin")) {
|
||||
suc = cfg_portpin_parse(value, &priv->store_pname, &priv->store_pnum);
|
||||
priv->cfg.pin_store = cfg_pinrsc_parse(value, &suc);
|
||||
}
|
||||
else if (streq(key, "shift-pin")) {
|
||||
suc = cfg_portpin_parse(value, &priv->shift_pname, &priv->shift_pnum);
|
||||
priv->cfg.pin_shift = cfg_pinrsc_parse(value, &suc);
|
||||
}
|
||||
else if (streq(key, "clear-pin")) {
|
||||
suc = cfg_portpin_parse(value, &priv->clear_pname, &priv->clear_pnum);
|
||||
priv->cfg.pin_clear = cfg_pinrsc_parse(value, &suc);
|
||||
}
|
||||
|
||||
else if (streq(key, "store-pol")) {
|
||||
priv->store_pol = cfg_bool_parse(value, &suc);
|
||||
priv->cfg.store_pol = cfg_bool_parse(value, &suc);
|
||||
}
|
||||
else if (streq(key, "shift-pol")) {
|
||||
priv->shift_pol = cfg_bool_parse(value, &suc);
|
||||
priv->cfg.shift_pol = cfg_bool_parse(value, &suc);
|
||||
}
|
||||
else if (streq(key, "clear-pol")) {
|
||||
priv->clear_pol = cfg_bool_parse(value, &suc);
|
||||
priv->cfg.clear_pol = cfg_bool_parse(value, &suc);
|
||||
}
|
||||
|
||||
else if (streq(key, "data-port")) {
|
||||
suc = cfg_port_parse(value, &priv->data_pname);
|
||||
suc = cfg_port_parse(value, &priv->cfg.data_pname);
|
||||
}
|
||||
else if (streq(key, "data-pins")) {
|
||||
priv->data_pins = cfg_pinmask_parse(value, &suc);
|
||||
priv->cfg.data_pins = cfg_pinmask_parse(value, &suc);
|
||||
}
|
||||
|
||||
else {
|
||||
@@ -104,19 +98,19 @@ void USIPO_writeIni(Unit *unit, IniWriter *iw)
|
||||
struct priv *priv = unit->data;
|
||||
|
||||
iw_comment(iw, "Shift pin & its active edge (1-rising,0-falling)");
|
||||
iw_entry(iw, "shift-pin", "%c%d", priv->shift_pname, priv->shift_pnum);
|
||||
iw_entry(iw, "shift-pol", "%d", priv->shift_pol);
|
||||
iw_entry(iw, "shift-pin", cfg_pinrsc_encode(priv->cfg.pin_shift));
|
||||
iw_entry(iw, "shift-pol", "%d", priv->cfg.shift_pol);
|
||||
|
||||
iw_comment(iw, "Store pin & its active edge");
|
||||
iw_entry(iw, "store-pin", "%c%d", priv->store_pname, priv->store_pnum);
|
||||
iw_entry(iw, "store-pol", "%d", priv->store_pol);
|
||||
iw_entry(iw, "store-pin", cfg_pinrsc_encode(priv->cfg.pin_store));
|
||||
iw_entry(iw, "store-pol", "%d", priv->cfg.store_pol);
|
||||
|
||||
iw_comment(iw, "Clear pin & its active level");
|
||||
iw_entry(iw, "clear-pin", "%c%d", priv->clear_pname, priv->clear_pnum);
|
||||
iw_entry(iw, "clear-pol", "%d", priv->clear_pol);
|
||||
iw_entry(iw, "clear-pin", cfg_pinrsc_encode(priv->cfg.pin_clear));
|
||||
iw_entry(iw, "clear-pol", "%d", priv->cfg.clear_pol);
|
||||
|
||||
iw_comment(iw, "Data port and pins");
|
||||
iw_entry(iw, "data-port", "%c", priv->data_pname);
|
||||
iw_entry(iw, "data-pins", "%s", cfg_pinmask_encode(priv->data_pins, unit_tmp512, true));
|
||||
iw_entry(iw, "data-port", "%c", priv->cfg.data_pname);
|
||||
iw_entry(iw, "data-pins", cfg_pinmask_encode(priv->cfg.data_pins, unit_tmp512, true));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user