summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/valves.h
diff options
context:
space:
mode:
Diffstat (limited to 'pressure_control/firmware/valves.h')
-rw-r--r--pressure_control/firmware/valves.h75
1 files changed, 59 insertions, 16 deletions
diff --git a/pressure_control/firmware/valves.h b/pressure_control/firmware/valves.h
index ddc043e..977120e 100644
--- a/pressure_control/firmware/valves.h
+++ b/pressure_control/firmware/valves.h
@@ -26,14 +26,19 @@ enum valves_type {
VALVES_2MAG, /* One magnet for opening; one magnet for closing the valve. */
};
+struct valve_coil {
+ uint16_t ddr;
+ uint16_t port;
+ uint8_t bitmask;
+};
+
struct valves {
uint8_t type; /* enum valves_type */
- uint16_t ddr; /* DDRx */
- uint16_t port; /* PORTx */
- uint8_t bit_0_open; /* Pin for opening valve 0. */
- uint8_t bit_0_close; /* Pin for closing valve 0. */
- uint8_t bit_1_open; /* Pin for opening valve 1. */
- uint8_t bit_1_close; /* Pin for closing valve 1. */
+
+ struct valve_coil open0; /* Coil for opening valve 0 */
+ struct valve_coil close0; /* Coil for closing valve 0 */
+ struct valve_coil open1; /* Coil for opening valve 1 */
+ struct valve_coil close1; /* Coil for closing valve 1 */
uint8_t current_global_state; /* enum valves_global_state */
bool need_switch_to_idle; /* Need transition to VALVE_STATE_IDLE. */
@@ -42,16 +47,54 @@ struct valves {
uint16_t state_force_threshold; /* Threshold for forcing the valve state */
};
-#define DEFINE_VALVE(name, _type, portid, bit0_open, bit0_close, bit1_open, bit1_close, force_thres) \
- struct valves name = { \
- .type = _type, \
- .ddr = _SFR_ADDR(DDR##portid), \
- .port = _SFR_ADDR(PORT##portid), \
- .bit_0_open = bit0_open, \
- .bit_0_close = bit0_close, \
- .bit_1_open = bit1_open, \
- .bit_1_close = bit1_close, \
- .state_force_threshold = force_thres, \
+#define DEFINE_VALVE_1MAG(name, \
+ port_0open, bit_0open, \
+ port_1open, bit_1open, \
+ force_thres) \
+ struct valves name = { \
+ .type = VALVES_2MAG, \
+ .state_force_threshold = force_thres, \
+ .open0 = { \
+ .ddr = _SFR_ADDR(DDR##port_0open), \
+ .port = _SFR_ADDR(PORT##port_0open), \
+ .bitmask = (1 << (bit_0open)), \
+ }, \
+ .open1 = { \
+ .ddr = _SFR_ADDR(DDR##port_1open), \
+ .port = _SFR_ADDR(PORT##port_1open), \
+ .bitmask = (1 << (bit_1open)), \
+ }, \
+ }
+
+#define DEFINE_VALVE_2MAG(name, \
+ port_0open, bit_0open, \
+ port_0close, bit_0close, \
+ port_1open, bit_1open, \
+ port_1close, bit_1close, \
+ force_thres) \
+ struct valves name = { \
+ .type = VALVES_2MAG, \
+ .state_force_threshold = force_thres, \
+ .open0 = { \
+ .ddr = _SFR_ADDR(DDR##port_0open), \
+ .port = _SFR_ADDR(PORT##port_0open), \
+ .bitmask = (1 << (bit_0open)), \
+ }, \
+ .close0 = { \
+ .ddr = _SFR_ADDR(DDR##port_0close), \
+ .port = _SFR_ADDR(PORT##port_0close), \
+ .bitmask = (1 << (bit_0close)), \
+ }, \
+ .open1 = { \
+ .ddr = _SFR_ADDR(DDR##port_1open), \
+ .port = _SFR_ADDR(PORT##port_1open), \
+ .bitmask = (1 << (bit_1open)), \
+ }, \
+ .close1 = { \
+ .ddr = _SFR_ADDR(DDR##port_1close), \
+ .port = _SFR_ADDR(PORT##port_1close), \
+ .bitmask = (1 << (bit_1close)), \
+ }, \
}
#define VALVE_TOGGLE_MSEC 10
bues.ch cgit interface