DMX library

Fork of DMX by Suga koubou

Committer:
okini3939
Date:
Fri Jan 24 06:48:41 2014 +0000
Revision:
13:9841af9ac344
Parent:
12:1f176eee2d28
Child:
14:cef8749fd54d
LPC4088 supported.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 0:cbff6bf41542 1 /*
okini3939 0:cbff6bf41542 2 * DMX512 send/recv library
okini3939 6:9e7b4eeac6ec 3 * Copyright (c) 2013 Hiroshi Suga
okini3939 0:cbff6bf41542 4 * Released under the MIT License: http://mbed.org/license/mit
okini3939 0:cbff6bf41542 5 */
okini3939 0:cbff6bf41542 6
okini3939 7:16d6874076dd 7 /** @file
okini3939 0:cbff6bf41542 8 * @brief DMX512 send/recv
okini3939 0:cbff6bf41542 9 */
okini3939 0:cbff6bf41542 10
okini3939 0:cbff6bf41542 11 #ifndef DMX_H
okini3939 0:cbff6bf41542 12 #define DMX_H
okini3939 0:cbff6bf41542 13
okini3939 0:cbff6bf41542 14 #include "mbed.h"
okini3939 0:cbff6bf41542 15
okini3939 1:f0d988e15810 16 #define DMX_UART_DIRECT
okini3939 0:cbff6bf41542 17
okini3939 0:cbff6bf41542 18 #define DMX_SIZE 512
okini3939 9:e687f321c428 19 #define DMX_TIME_BREAK 100 // 100us (88us-1s)
okini3939 9:e687f321c428 20 #define DMX_TIME_MAB 10 // 10us (8us-1s)
okini3939 9:e687f321c428 21 #define DMX_TIME_BETWEEN 10 // 10us (0-1s)
okini3939 9:e687f321c428 22 #define DMX_START_CODE 0
okini3939 0:cbff6bf41542 23
okini3939 0:cbff6bf41542 24 enum DMX_MODE {
okini3939 0:cbff6bf41542 25 DMX_MODE_BEGIN,
okini3939 0:cbff6bf41542 26 DMX_MODE_START,
okini3939 0:cbff6bf41542 27 DMX_MODE_BREAK,
okini3939 0:cbff6bf41542 28 DMX_MODE_MAB,
okini3939 0:cbff6bf41542 29 DMX_MODE_DATA,
okini3939 0:cbff6bf41542 30 DMX_MODE_ERROR,
okini3939 4:dd0544c80096 31 DMX_MODE_STOP,
okini3939 0:cbff6bf41542 32 };
okini3939 0:cbff6bf41542 33
okini3939 0:cbff6bf41542 34 /** DMX512 class (sender/client)
okini3939 0:cbff6bf41542 35 */
okini3939 0:cbff6bf41542 36 class DMX {
okini3939 0:cbff6bf41542 37 public:
okini3939 0:cbff6bf41542 38 /** init DMX class
okini3939 0:cbff6bf41542 39 * @param p_tx TX serial port (p9, p13, p28)
okini3939 0:cbff6bf41542 40 * @param p_rx RX serial port (p10, p14, p27)
okini3939 0:cbff6bf41542 41 */
okini3939 0:cbff6bf41542 42 DMX (PinName p_tx, PinName p_rx);
okini3939 0:cbff6bf41542 43
okini3939 6:9e7b4eeac6ec 44 /** Send the data
okini3939 6:9e7b4eeac6ec 45 * @param addr DMX data address (0-511)
okini3939 0:cbff6bf41542 46 * @param data DMX data (0-255)
okini3939 0:cbff6bf41542 47 */
okini3939 6:9e7b4eeac6ec 48 void put (int addr, int data);
okini3939 6:9e7b4eeac6ec 49 /** Send the data
okini3939 6:9e7b4eeac6ec 50 * @param buf DMX data buffer
okini3939 6:9e7b4eeac6ec 51 * @param addr DMX data address
okini3939 6:9e7b4eeac6ec 52 * @param len data length
okini3939 6:9e7b4eeac6ec 53 */
okini3939 6:9e7b4eeac6ec 54 void put (unsigned char *buf, int addr = 0, int len = DMX_SIZE);
okini3939 0:cbff6bf41542 55
okini3939 6:9e7b4eeac6ec 56 /** Send the data
okini3939 7:16d6874076dd 57 * @param addr DMX data address (0-511)
okini3939 0:cbff6bf41542 58 * @return DMX data (0-255)
okini3939 0:cbff6bf41542 59 */
okini3939 6:9e7b4eeac6ec 60 int get (int addr);
okini3939 6:9e7b4eeac6ec 61 /** Send the data
okini3939 6:9e7b4eeac6ec 62 * @param buf DMX data buffer
okini3939 6:9e7b4eeac6ec 63 * @param addr DMX data address
okini3939 6:9e7b4eeac6ec 64 * @param len data length
okini3939 6:9e7b4eeac6ec 65 */
okini3939 6:9e7b4eeac6ec 66 void get (unsigned char *buf, int addr = 0, int len = DMX_SIZE);
okini3939 0:cbff6bf41542 67
okini3939 6:9e7b4eeac6ec 68 /** Start DMX send operation
okini3939 4:dd0544c80096 69 */
okini3939 4:dd0544c80096 70 void start ();
okini3939 6:9e7b4eeac6ec 71 /** Stop DMX send operation
okini3939 4:dd0544c80096 72 */
okini3939 4:dd0544c80096 73 void stop ();
okini3939 12:1f176eee2d28 74 /** Clear DMX data
okini3939 12:1f176eee2d28 75 */
okini3939 12:1f176eee2d28 76 void clear ();
okini3939 3:2eb66b4d99bd 77
okini3939 0:cbff6bf41542 78 volatile int is_recived, is_sent;
okini3939 0:cbff6bf41542 79
okini3939 0:cbff6bf41542 80 protected:
okini3939 0:cbff6bf41542 81
okini3939 0:cbff6bf41542 82 void int_timer ();
okini3939 0:cbff6bf41542 83 void int_tx ();
okini3939 0:cbff6bf41542 84 void int_rx ();
okini3939 0:cbff6bf41542 85
okini3939 13:9841af9ac344 86 #if defined(TARGET_LPC1768)
okini3939 13:9841af9ac344 87 RawSerial _dmx;
okini3939 13:9841af9ac344 88 #else
okini3939 5:72039cd4c874 89 Serial _dmx;
okini3939 13:9841af9ac344 90 #endif
okini3939 0:cbff6bf41542 91 Timeout timeout01;
okini3939 6:9e7b4eeac6ec 92 volatile DMX_MODE mode_tx, mode_rx;
okini3939 6:9e7b4eeac6ec 93 volatile int addr_tx, addr_rx;
okini3939 6:9e7b4eeac6ec 94 unsigned char data_tx[DMX_SIZE];
okini3939 6:9e7b4eeac6ec 95 unsigned char data_rx[DMX_SIZE];
okini3939 6:9e7b4eeac6ec 96
okini3939 6:9e7b4eeac6ec 97 private:
okini3939 13:9841af9ac344 98 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
okini3939 8:d4a45bba41d2 99 LPC_UART_TypeDef *_uart;
okini3939 5:72039cd4c874 100 #elif defined(TARGET_LPC11U24)
okini3939 8:d4a45bba41d2 101 LPC_USART_Type *_uart;
stanly88 10:b748aab8404c 102 #elif defined(TARGET_LPC11XX)
stanly88 10:b748aab8404c 103 LPC_UART_TypeDef *_uart;
okini3939 13:9841af9ac344 104 #else
okini3939 13:9841af9ac344 105 #error "this CPU not supported."
okini3939 5:72039cd4c874 106 #endif
okini3939 0:cbff6bf41542 107
okini3939 0:cbff6bf41542 108 };
okini3939 0:cbff6bf41542 109
okini3939 0:cbff6bf41542 110 #endif