LX32DMX

Declared In:

Introduction

LX32DMX is a driver for sending or receiving DMX using an ESP32's UART2.

LX32DMX output mode continuously sends DMX once its interrupts have been enabled using startOutput().
Use setSlot() to set the level value for a particular DMX dimmer/address/channel.
DMX output uses the ESP32's UART2 TX pin (GPIO17).

LX32DMX input mode receives DMX using the ESP32's UART2 RX pin (GPIO16)
LX32DMX continuously updates its DMX buffer once its interrupts have been enabled using startInput()
and DMX data is received by UART2.
Use getSlot() to read the level value for a particular DMX dimmer/address/channel.

LX32DMX input requires replacing the uart hardware abstraction files to allow breaks to be converted
to SLIP encoded serial to divide the incoming DMX serial into packets.

LX32DMX is used with a single instance called ESP32DMX.



Member Functions

clearSlots

zero buffer including slot[0] which is start code

dmxData

provides direct access to data array

getSlot

reads the value of a slot/address/channel

receiveInterruptHandler

UART receive interrupt handler

setDataReceivedCallback

Function called when DMX frame has been read

setDirectionPin

optional utility sets the pin used to control driver chip's DE (data enable) line, HIGH for output, LOW for input.

setMaxSlots

Sets the number of slots (aka addresses or channels) sent per DMX frame.

setSlot

Sets the output value of a slot Note:slot[0] is DMX start code!

startInput

starts interrupt that continuously reads DMX data

startOutput

starts interrupt that continuously sends DMX output

stop

disables transmission and tx interrupt

txEmptyInterruptHandler

UART tx empty interrupt handler


clearSlots


zero buffer including slot[0] which is start code

public

void LX32DMX::clearSlots ( void);

dmxData


provides direct access to data array

public

uint8_t* dmxData( void);
Return Value

pointer to dmx array


getSlot


reads the value of a slot/address/channel

public

uint8_t getSlot ( int slot);
Return Value

level (0-255)

Discussion

NOTE: Data is not double buffered. So a complete single frame is not guaranteed. The ISR continuously reads the next frame into the buffer


receiveInterruptHandler


UART receive interrupt handler

public

void receiveInterruptHandler( uint8_t c);

setDataReceivedCallback


Function called when DMX frame has been read

public

void setDataReceivedCallback( LXRecvCallback callback);
Discussion

Sets a pointer to a function that is called on the break after a DMX frame has been received. Whatever happens in this function should be quick! Best used to set a flag that is polled outside of ISR for available data.


setDirectionPin


optional utility sets the pin used to control driver chip's DE (data enable) line, HIGH for output, LOW for input.

public

void setDirectionPin( uint8_t pin );
Parameters
pin

to be automatically set for input/output direction


setMaxSlots


Sets the number of slots (aka addresses or channels) sent per DMX frame.

public

void setMaxSlots ( int slot);
Parameters
slot

the highest slot number (~24 to 512)

Discussion

defaults to 512 or DMX_MAX_SLOTS and should be no less DMX_MIN_SLOTS slots. The DMX standard specifies min break to break time no less than 1024 usecs. At 44 usecs per slot ~= 24


setSlot


Sets the output value of a slot Note:slot[0] is DMX start code!

public

void setSlot ( int slot, uint8_t value);
Parameters
slot

number of the slot aka address or channel (1-512)

value

level (0-255)


startInput


starts interrupt that continuously reads DMX data

public

void startInput( void );
Discussion

sets up baud rate, bits and parity, sets globals accessed in ISR, enables transmission and tx interrupt


startOutput


starts interrupt that continuously sends DMX output

public

void startOutput( void );
Discussion

Sets up baud rate, bits and parity, sets globals accessed in ISR, enables transmission and tx interrupt.


stop


disables transmission and tx interrupt

public

void stop( void );

txEmptyInterruptHandler


UART tx empty interrupt handler

public

void txEmptyInterruptHandler( void);

Member Data

_current_slot

number of dmx slots ~24 to 512

_direction_pin

pin used to control direction of output driver chip

_dmx_state

represents phase of sending dmx packet data/break/etc used to change baud settings

_dmxData

Array of dmx data including start code

_idle_count

count of idle interrupts

_interrupt_status

true when ISR is enabled

_receive_callback

Pointer to receive callback function

_slots

number of dmx slots ~24 to 512


_current_slot


number of dmx slots ~24 to 512

private

uint16_t _current_slot;

_direction_pin


pin used to control direction of output driver chip

private

uint8_t _direction_pin;

_dmx_state


represents phase of sending dmx packet data/break/etc used to change baud settings

private

uint8_t _dmx_state;

_dmxData


Array of dmx data including start code

private

uint8_t _dmxData[DMX_MAX_SLOTS+1];

_idle_count


count of idle interrupts

private

uint8_t _idle_count;

_interrupt_status


true when ISR is enabled

private

uint8_t _interrupt_status;

_receive_callback


Pointer to receive callback function

private

LXRecvCallback _receive_callback;

_slots


number of dmx slots ~24 to 512

private

uint16_t _slots;