Add support new target MCU: LPC1114FN28 or LPC11XX

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 
00016 #define DMX_UART_DIRECT
00017 
00018 #define DMX_SIZE 512
00019 #define DMX_TIME_BREAK 100 // 100us (88us-1s)
00020 #define DMX_TIME_MAB 10 // 10us (8us-1s)
00021 #define DMX_TIME_BETWEEN 10 // 10us (0-1s)
00022 #define DMX_START_CODE 0
00023 
00024 enum DMX_MODE {
00025     DMX_MODE_BEGIN,
00026     DMX_MODE_START,
00027     DMX_MODE_BREAK,
00028     DMX_MODE_MAB,
00029     DMX_MODE_DATA,
00030     DMX_MODE_ERROR,
00031     DMX_MODE_STOP,
00032 };
00033 
00034 /** DMX512 class (sender/client)
00035  */
00036 class DMX {
00037 public:
00038     /** init DMX class
00039      * @param p_tx TX serial port (p9, p13, p28)
00040      * @param p_rx RX serial port (p10, p14, p27)
00041      */
00042     DMX (PinName p_tx, PinName p_rx); 
00043 
00044     /** Send the data
00045      * @param addr DMX data address (0-511)
00046      * @param data DMX data (0-255)
00047      */
00048     void put (int addr, int data);
00049     /** Send the data
00050      * @param buf DMX data buffer
00051      * @param addr DMX data address
00052      * @param len data length
00053      */
00054     void put (unsigned char *buf, int addr = 0, int len = DMX_SIZE);
00055 
00056     /** Send the data
00057      * @param addr DMX data address (0-511)
00058      * @return DMX data (0-255)
00059      */
00060     int get (int addr);
00061     /** Send the data
00062      * @param buf DMX data buffer
00063      * @param addr DMX data address
00064      * @param len data length
00065      */
00066     void get (unsigned char *buf, int addr = 0, int len = DMX_SIZE);
00067 
00068     /** Start DMX send operation
00069      */
00070     void start ();
00071     /** Stop DMX send operation
00072      */
00073     void stop ();
00074 
00075     volatile int is_recived, is_sent;
00076 
00077 protected:
00078 
00079     void int_timer ();
00080     void int_tx ();
00081     void int_rx ();
00082 
00083     Serial _dmx;
00084     Timeout timeout01;
00085     volatile DMX_MODE mode_tx, mode_rx;
00086     volatile int addr_tx, addr_rx;
00087     unsigned char data_tx[DMX_SIZE];
00088     unsigned char data_rx[DMX_SIZE];
00089 
00090 private:
00091 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
00092     LPC_UART_TypeDef *_uart;
00093 #elif defined(TARGET_LPC11U24)
00094     LPC_USART_Type *_uart;
00095 #elif defined(TARGET_LPC11XX)
00096     LPC_UART_TypeDef *_uart;
00097 #endif
00098 
00099 };
00100 
00101 #endif