diff --git a/include/pinproc.h b/include/pinproc.h index 8bcbfd7..99e2c62 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -204,6 +204,7 @@ typedef struct PRDriverState { uint8_t patterOnTime; uint8_t patterOffTime; bool_t patterEnable; + bool_t futureEnable; } PRDriverState; typedef struct PRDriverAuxCommand { @@ -256,6 +257,11 @@ PINPROC_API PRResult PRDriverDisable(PRHandle handle, uint8_t driverNum); * This function is provided for convenience. See PRDriverStatePulse() for a full description. */ PINPROC_API PRResult PRDriverPulse(PRHandle handle, uint8_t driverNum, uint8_t milliseconds); +/** + * Pulses the given driver for a number of milliseconds when the hardware reaches a specific timestamp. + * This function is provided for convenience. See PRDriverStatePulse() for a full description. + */ +PINPROC_API PRResult PRDriverFuturePulse(PRHandle handle, uint8_t driverNum, uint8_t milliseconds, uint32_t futureTime); /** * Assigns a repeating schedule to the given driver. * This function is provided for convenience. See PRDriverStateSchedule() for a full description. @@ -316,6 +322,13 @@ PINPROC_API void PRDriverStateDisable(PRDriverState *driverState); * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchUpdateRule() to have any effect. */ PINPROC_API void PRDriverStatePulse(PRDriverState *driverState, uint8_t milliseconds); +/** + * Changes the given #PRDriverState to reflect a future scheduled pulse state. + * @param milliseconds Number of milliseconds to pulse the driver for. + * @param futureTime Value indicating at which HW timestamp the pulse should occur. Currently only the low 10-bits are used. + * @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchUpdateRule() to have any effect. + */ +PINPROC_API void PRDriverStateFuturePulse(PRDriverState *driverState, uint8_t milliseconds, uint32_t futureTime); /** * Changes the given #PRDriverState to reflect a scheduled state. * Assigns a repeating schedule to the given driver. diff --git a/src/PRHardware.cpp b/src/PRHardware.cpp index 3860175..2f2885b 100644 --- a/src/PRHardware.cpp +++ b/src/PRHardware.cpp @@ -142,7 +142,8 @@ int32_t CreateDriverUpdateBurst ( uint32_t * burst, PRDriverState *driver) { burst[2] = (driver->timeslots >> P_ROC_DRIVER_CONFIG_TIMESLOT_SHIFT) | (driver->patterOnTime << P_ROC_DRIVER_CONFIG_PATTER_ON_TIME_SHIFT) | (driver->patterOffTime << P_ROC_DRIVER_CONFIG_PATTER_OFF_TIME_SHIFT) | - (driver->patterEnable << P_ROC_DRIVER_CONFIG_PATTER_ENABLE_SHIFT); + (driver->patterEnable << P_ROC_DRIVER_CONFIG_PATTER_ENABLE_SHIFT) | + (driver->futureEnable << P_ROC_DRIVER_CONFIG_FUTURE_ENABLE_SHIFT); return kPRSuccess; } diff --git a/src/PRHardware.h b/src/PRHardware.h index 616977e..6f18698 100644 --- a/src/PRHardware.h +++ b/src/PRHardware.h @@ -178,6 +178,7 @@ const uint32_t P_ROC_DRIVER_CONFIG_TIMESLOT_SHIFT = 16; const uint32_t P_ROC_DRIVER_CONFIG_PATTER_ON_TIME_SHIFT = 16; const uint32_t P_ROC_DRIVER_CONFIG_PATTER_OFF_TIME_SHIFT = 23; const uint32_t P_ROC_DRIVER_CONFIG_PATTER_ENABLE_SHIFT = 30; +const uint32_t P_ROC_DRIVER_CONFIG_FUTURE_ENABLE_SHIFT = 31; const uint32_t P_ROC_DRIVER_CONFIG_TABLE_DRIVER_NUM_SHIFT = 1; diff --git a/src/pinproc.cpp b/src/pinproc.cpp index dc092ad..3cd153d 100644 --- a/src/pinproc.cpp +++ b/src/pinproc.cpp @@ -193,6 +193,13 @@ PRResult PRDriverPulse(PRHandle handle, uint8_t driverNum, uint8_t milliseconds) PRDriverStatePulse(&driver, milliseconds); return handleAsDevice->DriverUpdateState(&driver); } +PRResult PRDriverFuturePulse(PRHandle handle, uint8_t driverNum, uint8_t milliseconds, uint32_t futureTime) +{ + PRDriverState driver; + handleAsDevice->DriverGetState(driverNum, &driver); + PRDriverStateFuturePulse(&driver, milliseconds, futureTime); + return handleAsDevice->DriverUpdateState(&driver); +} PRResult PRDriverSchedule(PRHandle handle, uint8_t driverNum, uint32_t schedule, uint8_t cycleSeconds, bool_t now) { PRDriverState driver; @@ -279,6 +286,7 @@ void PRDriverStateDisable(PRDriverState *driver) driver->patterOnTime = 0; driver->patterOffTime = 0; driver->patterEnable = false; + driver->futureEnable = false; } void PRDriverStatePulse(PRDriverState *driver, uint8_t milliseconds) { @@ -289,6 +297,18 @@ void PRDriverStatePulse(PRDriverState *driver, uint8_t milliseconds) driver->patterOnTime = 0; driver->patterOffTime = 0; driver->patterEnable = false; + driver->futureEnable = false; +} +void PRDriverStateFuturePulse(PRDriverState *driver, uint8_t milliseconds, uint32_t futureTime) +{ + driver->state = 1; + driver->timeslots = futureTime; + driver->waitForFirstTimeSlot = false; + driver->outputDriveTime = milliseconds; + driver->patterOnTime = 0; + driver->patterOffTime = 0; + driver->patterEnable = false; + driver->futureEnable = true; } void PRDriverStateSchedule(PRDriverState *driver, uint32_t schedule, uint8_t cycleSeconds, bool_t now) { @@ -299,6 +319,7 @@ void PRDriverStateSchedule(PRDriverState *driver, uint32_t schedule, uint8_t cyc driver->patterOnTime = 0; driver->patterOffTime = 0; driver->patterEnable = false; + driver->futureEnable = false; } void PRDriverStatePatter(PRDriverState *driver, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t originalOnTime) { @@ -309,6 +330,7 @@ void PRDriverStatePatter(PRDriverState *driver, uint8_t millisecondsOn, uint8_t driver->patterOnTime = millisecondsOn; driver->patterOffTime = millisecondsOff; driver->patterEnable = true; + driver->futureEnable = false; } void PRDriverStatePulsedPatter(PRDriverState *driver, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t patterTime) @@ -320,6 +342,7 @@ void PRDriverStatePulsedPatter(PRDriverState *driver, uint8_t millisecondsOn, ui driver->patterOnTime = millisecondsOn; driver->patterOffTime = millisecondsOff; driver->patterEnable = true; + driver->futureEnable = false; } uint16_t PRDecode(PRMachineType machineType, const char *str)