diff --git a/src/ec/ite/espi.c b/src/ec/ite/espi.c index f74a5a7..0ad66d5 100644 --- a/src/ec/ite/espi.c +++ b/src/ec/ite/espi.c @@ -39,27 +39,30 @@ struct VirtualWire __code VW_HOST_C10 = VIRTUAL_WIRE(47, 0); enum VirtualWireState vw_get(struct VirtualWire *vw) __critical { uint8_t index = *vw->index; - switch ((index >> vw->shift) & VWS_HIGH) { - case VWS_LOW: - return VWS_LOW; - case VWS_HIGH: - return VWS_HIGH; - default: + if (index & vw->valid_mask) { + if (index & vw->data_mask) { + return VWS_HIGH; + } else { + return VWS_LOW; + } + } else { return VWS_INVALID; } } void vw_set(struct VirtualWire *vw, enum VirtualWireState state) __critical { uint8_t index = *vw->index; - index &= ~(VWS_HIGH << vw->shift); switch (state) { case VWS_LOW: - index |= VWS_LOW << vw->shift; + index &= ~vw->data_mask; + index |= vw->valid_mask; break; case VWS_HIGH: - index |= VWS_HIGH << vw->shift; + index |= vw->data_mask; + index |= vw->valid_mask; break; default: + index &= ~vw->valid_mask; break; } *vw->index = index; diff --git a/src/ec/ite/include/ec/espi.h b/src/ec/ite/include/ec/espi.h index 25ddb20..079df60 100644 --- a/src/ec/ite/include/ec/espi.h +++ b/src/ec/ite/include/ec/espi.h @@ -9,13 +9,15 @@ struct VirtualWire { volatile uint8_t __xdata *index; - uint8_t shift; + uint8_t data_mask; + uint8_t valid_mask; }; // clang-format off #define VIRTUAL_WIRE(INDEX, SHIFT) { \ .index = &VWIDX ## INDEX, \ - .shift = SHIFT, \ + .data_mask = BIT(SHIFT), \ + .valid_mask = BIT(SHIFT + 4), \ } // clang-format on