DMX library

Fork of DMX by Suga koubou

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DMX.h Source File

DMX.h

Go to the documentation of this file.
00001 /*
00002  * DMX512 send/recv library
00003  * Copyright (c) 2013 Hiroshi Suga
00004  * Released under the MIT License: http://mbed.org/license/mit
00005  */
00006 
00007 /** @file
00008  * @brief DMX512 send/recv
00009  */
00010  
00011 #ifndef DMX_H
00012 #define DMX_H
00013 
00014 #include "mbed.h"
00015 #include "RawSerial.h"
00016 
00017 #define DMX_UART_DIRECT
00018 
00019 #define DMX_SIZE 512
00020 #define DMX_TIME_BREAK 100 // 100us (88us-1s)
00021 #define DMX_TIME_MAB 10 // 10us (8us-1s)
00022 #define DMX_TIME_BETWEEN 200 // 10us (0-1s)
00023 #define DMX_START_CODE 0
00024 
00025 enum DMX_MODE {
00026     DMX_MODE_BEGIN,
00027     DMX_MODE_START,
00028     DMX_MODE_BREAK,
00029     DMX_MODE_MAB,
00030     DMX_MODE_DATA,
00031     DMX_MODE_ERROR,
00032     DMX_MODE_STOP,
00033 };
00034 
00035 /** DMX512 class (sender/client)
00036  */
00037 class DMX {
00038 public:
00039     /** init DMX class
00040      * @param p_tx TX serial port (p9, p13, p28)
00041      * @param p_rx RX serial port (p10, p14, p27)
00042      */
00043     DMX (PinName p_tx, PinName p_rx); 
00044 
00045     /** Send the data
00046      * @param addr DMX data address (0-511)
00047      * @param data DMX data (0-255)
00048      */
00049     void put (int addr, int data);
00050     /** Send the data
00051      * @param buf DMX data buffer
00052      * @param addr DMX data address
00053      * @param len data length
00054      */
00055     void put (unsigned char *buf, int addr = 0, int len = DMX_SIZE);
00056 
00057     /** Send the data
00058      * @param addr DMX data address (0-511)
00059      * @return DMX data (0-255)
00060      */
00061     int get (int addr);
00062     /** Send the data
00063      * @param buf DMX data buffer
00064      * @param addr DMX data address
00065      * @param len data length
00066      */
00067     void get (unsigned char *buf, int addr = 0, int len = DMX_SIZE);
00068 
00069     /** Start DMX send operation
00070      */
00071     void start ();
00072     /** Stop DMX send operation
00073      */
00074     void stop ();
00075     /** Clear DMX data
00076      */
00077     void clear ();
00078 
00079     volatile int is_recived, is_sent;
00080 
00081 protected:
00082 
00083     void int_timer ();
00084     void int_tx ();
00085     void int_rx ();
00086 
00087 //    Serial _dmx;
00088     RawSerial _dmx;
00089     Timeout timeout01;
00090     volatile DMX_MODE mode_tx, mode_rx;
00091     volatile int addr_tx, addr_rx;
00092     unsigned char data_tx[DMX_SIZE];
00093     unsigned char data_rx[DMX_SIZE];
00094 
00095 private:
00096 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
00097     LPC_UART_TypeDef *_uart;
00098 #elif defined(TARGET_LPC11UXX)
00099     LPC_USART_Type *_uart;
00100 #elif defined(TARGET_LPC11XX)
00101     LPC_UART_TypeDef *_uart;
00102 #elif defined(TARGET_LPC1347)
00103     LPC_USART_Type *_uart;
00104 #else
00105 #error "this CPU not supported."
00106 #endif
00107 
00108 };
00109 
00110 #endif