Serialize output based on a sequence of delay-times in µs. After each delay, the pin is toggled. After the last cycle and last delay the pin is not toggled.
The function works in two modes:
The function works in two modes:
* synchronous - for sub-50 µs resolution, restricted to max. overall duration,
* asynchrounous - synchronous operation with less granularity but virtually unrestricted duration.
...
...
@@ -89,7 +89,7 @@ Note that the synchronous variant (no or nil `callback` parameter) function bloc
#### Parameters
-`pin` pin to use, IO index
-`start_level` level to start on, either `gpio.HIGH` or `gpio.LOW`
-`delay_times` an array of delay times in µs between each toggle of the gpio pin.
-`delay_times` an array of delay times in µs between each toggle of the gpio pin.
-`cycle_num` an optional number of times to run through the sequence. (default is 1)
-`callback` an optional callback function or number, if present the function returns immediately and goes asynchronous.
...
...
@@ -122,8 +122,8 @@ This function is not available if GPIO_INTERRUPT_ENABLE was undefined at compile
#### Parameters
-`pin`**1-12**, pin to trigger on, IO index. Note that pin 0 does not support interrupts.
edges*, *low level*, and *high level* trigger modes respectivey. If the type is "none" or omitted
then the callback function is removed and the interrupt is disabled.
-`callback_function(level, when, eventcount)` callback function when trigger occurs. The level of the specified pin
at the interrupt passed as the first parameter to the callback. The timestamp of the event is passed
...
...
@@ -182,3 +182,167 @@ gpio.write(pin, gpio.HIGH)
#### See also
-[`gpio.mode()`](#gpiomode)
-[`gpio.read()`](#gpioread)
## gpio.pulse
This covers a set of APIs that allow generation of pulse trains with accurate timing on
multiple pins. It is similar to the `serout` API, but can handle multiple pins and has better
timing control.
The basic idea is to build a `gpio.pulse` object and then control it with methods on that object. Only one `gpio.pulse`
object can be active at a time. The object is built from an array of tables where each inner table represents
an action to take and the time to delay before moving to the next action.
One of the uses for this is to generate bipolar impulse for driving clock movements where you want (say) a pulse on Pin 1 on the even
second, and a pulse on Pin 2 on the odd second. `:getstate` and `:adjust` can be used to keep the pulse synchronized to the
RTC clock (that is itself synchronized with NTP).
!!! Configuration
This feature is only available if `LUA_USE_MODULES_GPIO_PULSE` is defined at build time.
## gpio.pulse.build
This builds the `gpio.pulse` object from the supplied argument -- which is a table as described below.
#### Syntax
`gpio.pulse.build(table)`
#### Parameter
`table` this is view as an array of instructions. Each instruction is represented by a table as follows:
- All numeric keys are considered to be pin numbers. The values of each are the value to be set onto the respective GPIO line. For example `{ [1] = gpio.HIGH }` would set pin 1 to be high. Note this that is the pin number and *not* the GPIO number. Multiple pins can be
set at the same time.
-`delay` specifies the number of microseconds after setting the pin values to wait until moving to the next state. The actual delay may be longer than this value depending on whether interrupts are enabled at the end time.
-`min` and `max` can be used to specify (along with `delay`) that this time can be varied. If one time interval overruns, then the extra time will be deducted from a time period which has a `min` or `max` specified. The actual time can also be adjusted with the `:adjust` API below.
-`count` and `loop` allow simple looping. When a state with `count` and `loop` is completed, the next state is at `loop` (provided that `count` has not decremented to zero). The first state is state 1.